~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to include/my_global.h

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
#ifdef __cplusplus
69
69
#define C_MODE_START    extern "C" {
70
70
#define C_MODE_END      }
 
71
#define STATIC_CAST(TYPE) static_cast<TYPE>
71
72
#else
72
73
#define C_MODE_START
73
74
#define C_MODE_END
 
75
#define STATIC_CAST(TYPE) (TYPE)
74
76
#endif
75
77
 
76
78
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
156
158
#define __builtin_expect(x, expected_value) (x)
157
159
#endif
158
160
 
159
 
#define likely(x)       __builtin_expect((x),1)
160
 
#define unlikely(x)     __builtin_expect((x),0)
161
 
 
 
161
/**
 
162
  The semantics of builtin_expect() are that
 
163
  1) its two arguments are long
 
164
  2) it's likely that they are ==
 
165
  Those of our likely(x) are that x can be bool/int/longlong/pointer.
 
166
*/
 
167
#define likely(x)       __builtin_expect(((x) != 0),1)
 
168
#define unlikely(x)     __builtin_expect(((x) != 0),0)
162
169
 
163
170
/*
164
171
  The macros below are useful in optimising places where it has been
410
417
#ifndef stdin
411
418
#include <stdio.h>
412
419
#endif
 
420
#include <stdarg.h>
413
421
#ifdef HAVE_STDLIB_H
414
422
#include <stdlib.h>
415
423
#endif
431
439
#ifdef HAVE_FCNTL_H
432
440
#include <fcntl.h>
433
441
#endif
 
442
#ifdef HAVE_SYS_STAT_H
 
443
#include <sys/stat.h>
 
444
#endif
434
445
#ifdef HAVE_SYS_TIMEB_H
435
446
#include <sys/timeb.h>                          /* Avoid warnings on SCO */
436
447
#endif
538
549
#define DONT_REMEMBER_SIGNAL
539
550
#endif
540
551
 
541
 
/* Define void to stop lint from generating "null effekt" comments */
542
 
#ifndef DONT_DEFINE_VOID
543
 
#ifdef _lint
544
 
int     __void__;
545
 
#define VOID(X)         (__void__ = (int) (X))
546
 
#else
547
 
#undef VOID
548
 
#define VOID(X)         (X)
549
 
#endif
550
 
#endif /* DONT_DEFINE_VOID */
551
 
 
552
552
#if defined(_lint) || defined(FORCE_INIT_OF_VARS)
553
553
#define LINT_INIT(var)  var=0                   /* No uninitialize-warning */
554
554
#else
570
570
 
571
571
#define CMP_NUM(a,b)    (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
572
572
#define sgn(a)          (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
573
 
#define swap_variables(t, a, b) { register t dummy; dummy= a; a= b; b= dummy; }
 
573
#define swap_variables(t, a, b) { t swap_dummy; swap_dummy= a; a= b; b= swap_dummy; }
574
574
#define test(a)         ((a) ? 1 : 0)
575
575
#define set_if_bigger(a,b)  do { if ((a) < (b)) (a)=(b); } while(0)
576
576
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
577
577
#define test_all_bits(a,b) (((a) & (b)) == (b))
578
578
#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
579
579
#define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
 
580
 
580
581
#ifndef HAVE_RINT
581
 
#define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5))
582
 
#endif
 
582
/**
 
583
  All integers up to this number can be represented exactly as double precision
 
584
  values (DBL_MANT_DIG == 53 for IEEE 754 hardware).
 
585
*/
 
586
#define MAX_EXACT_INTEGER ((1LL << DBL_MANT_DIG) - 1)
 
587
 
 
588
/**
 
589
  rint(3) implementation for platforms that do not have it.
 
590
  Always rounds to the nearest integer with ties being rounded to the nearest
 
591
  even integer to mimic glibc's rint() behavior in the "round-to-nearest"
 
592
  FPU mode. Hardware-specific optimizations are possible (frndint on x86).
 
593
  Unlike this implementation, hardware will also honor the FPU rounding mode.
 
594
*/
 
595
 
 
596
static inline double rint(double x)
 
597
{
 
598
  double f, i;
 
599
  f = modf(x, &i);
 
600
 
 
601
  /*
 
602
    All doubles with absolute values > MAX_EXACT_INTEGER are even anyway,
 
603
    no need to check it.
 
604
  */
 
605
  if (x > 0.0)
 
606
    i += (double) ((f > 0.5) || (f == 0.5 &&
 
607
                                 i <= (double) MAX_EXACT_INTEGER &&
 
608
                                 (longlong) i % 2));
 
609
  else
 
610
    i -= (double) ((f < -0.5) || (f == -0.5 &&
 
611
                                  i >= (double) -MAX_EXACT_INTEGER &&
 
612
                                  (longlong) i % 2));
 
613
  return i;
 
614
}
 
615
#endif /* HAVE_RINT */
583
616
 
584
617
/* Define some general constants */
585
618
#ifndef TRUE
636
669
#  endif
637
670
#endif
638
671
 
 
672
typedef char            my_bool; /* Small bool */
639
673
#include <my_dbug.h>
640
674
 
641
675
#define MIN_ARRAY_SIZE  0       /* Zero or One. Gcc allows zero*/
924
958
#define my_offsetof(TYPE, MEMBER) \
925
959
        ((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
926
960
 
927
 
#define NullS           (char *) 0
 
961
#define NullS           STATIC_CAST(char *)(0)
928
962
/* Nowdays we do not support MessyDos */
929
963
#ifndef NEAR
930
964
#define NEAR                            /* Who needs segments ? */
1019
1053
#endif
1020
1054
 
1021
1055
#define MY_ERRPTR ((void*)(intptr)1)
 
1056
 
1022
1057
#ifdef USE_RAID
1023
1058
/*
1024
1059
  The following is done with a if to not get problems with pre-processors
1040
1075
#else
1041
1076
typedef unsigned long my_off_t;
1042
1077
#endif
1043
 
#define MY_FILEPOS_ERROR        (~(my_off_t) 0)
 
1078
#define MY_FILEPOS_ERROR        (~STATIC_CAST(my_off_t)(0))
1044
1079
#if !defined(__WIN__)
1045
1080
typedef off_t os_off_t;
1046
1081
#endif
1069
1104
typedef uint8           int7;   /* Most effective integer 0 <= x <= 127 */
1070
1105
typedef short           int15;  /* Most effective integer 0 <= x <= 32767 */
1071
1106
typedef int             myf;    /* Type of MyFlags in my_funcs */
1072
 
typedef char            my_bool; /* Small bool */
1073
1107
#if !defined(bool) && (!defined(HAVE_BOOL) || !defined(__cplusplus))
1074
1108
typedef char            bool;   /* Ordinary boolean values 0 1 */
1075
1109
#endif
1077
1111
#define INT8(v)         (int8) (v)
1078
1112
#define INT16(v)        (int16) (v)
1079
1113
#define INT32(v)        (int32) (v)
1080
 
#define MYF(v)          (myf) (v)
 
1114
#define MYF(v)          STATIC_CAST(myf)(v)
1081
1115
 
1082
1116
#ifndef LL
1083
1117
#ifdef HAVE_LONG_LONG
1133
1167
#define SCALE_SEC       100
1134
1168
#define SCALE_USEC      10000
1135
1169
#define MY_HOW_OFTEN_TO_ALARM   2       /* How often we want info on screen */
1136
 
#define MY_HOW_OFTEN_TO_WRITE   1000    /* How often we want info on screen */
1137
 
 
1138
 
 
 
1170
#define MY_HOW_OFTEN_TO_WRITE   10000   /* How often we want info on screen */
1139
1171
 
1140
1172
/*
1141
1173
  Define-funktions for reading and storing in machine independent format
1144
1176
 
1145
1177
/* Optimized store functions for Intel x86 */
1146
1178
#if defined(__i386__) || defined(_WIN32)
1147
 
#define sint2korr(A)    (*((int16 *) (A)))
 
1179
#define sint2korr(A)    (*((const int16 *) (A)))
1148
1180
#define sint3korr(A)    ((int32) ((((uchar) (A)[2]) & 128) ? \
1149
1181
                                  (((uint32) 255L << 24) | \
1150
1182
                                   (((uint32) (uchar) (A)[2]) << 16) |\
1153
1185
                                  (((uint32) (uchar) (A)[2]) << 16) |\
1154
1186
                                  (((uint32) (uchar) (A)[1]) << 8) | \
1155
1187
                                  ((uint32) (uchar) (A)[0])))
1156
 
#define sint4korr(A)    (*((long *) (A)))
1157
 
#define uint2korr(A)    (*((uint16 *) (A)))
 
1188
#define sint4korr(A)    (*((const long *) (A)))
 
1189
#define uint2korr(A)    (*((const uint16 *) (A)))
1158
1190
#if defined(HAVE_purify) && !defined(_WIN32)
1159
1191
#define uint3korr(A)    (uint32) (((uint32) ((uchar) (A)[0])) +\
1160
1192
                                  (((uint32) ((uchar) (A)[1])) << 8) +\
1166
1198
    Please, note, uint3korr reads 4 bytes (not 3) !
1167
1199
    It means, that you have to provide enough allocated space !
1168
1200
*/
1169
 
#define uint3korr(A)    (long) (*((unsigned int *) (A)) & 0xFFFFFF)
 
1201
#define uint3korr(A)    (long) (*((const unsigned int *) (A)) & 0xFFFFFF)
1170
1202
#endif /* HAVE_purify && !_WIN32 */
1171
 
#define uint4korr(A)    (*((uint32 *) (A)))
 
1203
#define uint4korr(A)    (*((const uint32 *) (A)))
1172
1204
#define uint5korr(A)    ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
1173
1205
                                    (((uint32) ((uchar) (A)[1])) << 8) +\
1174
1206
                                    (((uint32) ((uchar) (A)[2])) << 16) +\
1180
1212
                                     (((uint32)    ((uchar) (A)[3])) << 24)) + \
1181
1213
                         (((ulonglong) ((uchar) (A)[4])) << 32) +       \
1182
1214
                         (((ulonglong) ((uchar) (A)[5])) << 40))
1183
 
#define uint8korr(A)    (*((ulonglong *) (A)))
1184
 
#define sint8korr(A)    (*((longlong *) (A)))
 
1215
#define uint8korr(A)    (*((const ulonglong *) (A)))
 
1216
#define sint8korr(A)    (*((const longlong *) (A)))
1185
1217
#define int2store(T,A)  *((uint16*) (T))= (uint16) (A)
1186
1218
#define int3store(T,A)  do { *(T)=  (uchar) ((A));\
1187
1219
                            *(T+1)=(uchar) (((uint) (A) >> 8));\
1206
1238
} doubleget_union;
1207
1239
#define doubleget(V,M)  \
1208
1240
do { doubleget_union _tmp; \
1209
 
     _tmp.m[0] = *((long*)(M)); \
1210
 
     _tmp.m[1] = *(((long*) (M))+1); \
 
1241
     _tmp.m[0] = *((const long*)(M)); \
 
1242
     _tmp.m[1] = *(((const long*) (M))+1); \
1211
1243
     (V) = _tmp.v; } while(0)
1212
 
#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
1213
 
                             *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
 
1244
#define doublestore(T,V) do { *((long *) T) = ((const doubleget_union *)&V)->m[0]; \
 
1245
                             *(((long *) T)+1) = ((const doubleget_union *)&V)->m[1]; \
1214
1246
                         } while (0)
1215
 
#define float4get(V,M)   do { *((float *) &(V)) = *((float*) (M)); } while(0)
 
1247
#define float4get(V,M)   do { *((float *) &(V)) = *((const float*) (M)); } while(0)
1216
1248
#define float8get(V,M)   doubleget((V),(M))
1217
 
#define float4store(V,M) memcpy((uchar*) V,(uchar*) (&M),sizeof(float))
1218
 
#define floatstore(T,V)  memcpy((uchar*)(T), (uchar*)(&V),sizeof(float))
1219
 
#define floatget(V,M)    memcpy((uchar*) &V,(uchar*) (M),sizeof(float))
 
1249
#define float4store(V,M) memcpy((uchar*) V,(const uchar*) (&M),sizeof(float))
 
1250
#define floatstore(T,V)  memcpy((uchar*)(T), (const uchar*)(&V),sizeof(float))
 
1251
#define floatget(V,M)    memcpy((uchar*) &V,(const uchar*) (M),sizeof(float))
1220
1252
#define float8store(V,M) doublestore((V),(M))
1221
1253
#else
1222
1254
 
1479
1511
#define dlerror() ""
1480
1512
#endif
1481
1513
 
 
1514
 
1482
1515
#ifndef __NETWARE__
1483
1516
/*
1484
1517
 *  Include standard definitions of operator new and delete.
1509
1542
#if !defined(max)
1510
1543
#define max(a, b)       ((a) > (b) ? (a) : (b))
1511
1544
#define min(a, b)       ((a) < (b) ? (a) : (b))
 
1545
#endif  
 
1546
/*
 
1547
  Only Linux is known to need an explicit sync of the directory to make sure a
 
1548
  file creation/deletion/renaming in(from,to) this directory durable.
 
1549
*/
 
1550
#ifdef TARGET_OS_LINUX
 
1551
#define NEED_EXPLICIT_SYNC_DIR 1
1512
1552
#endif
1513
1553
 
1514
1554
#if !defined(__cplusplus) && !defined(bool)
1515
1555
#define bool In_C_you_should_use_my_bool_instead()
1516
1556
#endif
1517
1557
 
 
1558
/* Provide __func__ macro definition for platforms that miss it. */
 
1559
#if __STDC_VERSION__ < 199901L
 
1560
#  if __GNUC__ >= 2
 
1561
#    define __func__ __FUNCTION__
 
1562
#  else
 
1563
#    define __func__ "<unknown>"
 
1564
#  endif
 
1565
#elif defined(_MSC_VER)
 
1566
#  if _MSC_VER < 1300
 
1567
#    define __func__ "<unknown>"
 
1568
#  else
 
1569
#    define __func__ __FUNCTION__
 
1570
#  endif
 
1571
#elif defined(__BORLANDC__)
 
1572
#  define __func__ __FUNC__
 
1573
#else
 
1574
#  define __func__ "<unknown>"
 
1575
#endif
 
1576
 
1518
1577
#endif /* my_global_h */