document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /* Copyright (C) 2000-2003 MySQL AB
  2.  
  3.    This program is free software; you can redistribute it and/or modify
  4.    it under the terms of the GNU General Public License as published by
  5.    the Free Software Foundation; version 2 of the License.
  6.  
  7.    This program is distributed in the hope that it will be useful,
  8.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.    GNU General Public License for more details.
  11.  
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program; if not, write to the Free Software
  14.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  15.  
  16. /* This is the include file that should be included \'first\' in every C file. */
  17.  
  18. #ifndef _global_h
  19. #define _global_h
  20.  
  21. /*
  22.   InnoDB depends on some MySQL internals which other plugins should not
  23.   need.  This is because of InnoDB\'s foreign key support, "safe" binlog
  24.   truncation, and other similar legacy features.
  25.  
  26.   We define accessors for these internals unconditionally, but do not
  27.   expose them in mysql/plugin.h.  They are declared in ha_innodb.h for
  28.   InnoDB\'s use.
  29. */
  30. #define INNODB_COMPATIBILITY_HOOKS
  31.  
  32. #ifdef __CYGWIN__
  33. /* We use a Unix API, so pretend it\'s not Windows */
  34. #undef WIN
  35. #undef WIN32
  36. #undef _WIN
  37. #undef _WIN32
  38. #undef _WIN64
  39. #undef __WIN__
  40. #undef __WIN32__
  41. #define HAVE_ERRNO_AS_DEFINE
  42. #endif /* __CYGWIN__ */
  43.  
  44. #if defined(__QNXNTO__) && !defined(FD_SETSIZE)
  45. #define FD_SETSIZE 1024         /* Max number of file descriptor bits in
  46.                                    fd_set, used when calling \'select\'
  47.                                    Must be defined before including
  48.                                    "sys/select.h" and "sys/time.h"
  49.                                  */
  50. #endif
  51.  
  52.  
  53. /* to make command line shorter we\'ll define USE_PRAGMA_INTERFACE here */
  54. #ifdef USE_PRAGMA_IMPLEMENTATION
  55. #define USE_PRAGMA_INTERFACE
  56. #endif
  57.  
  58. #if defined(i386) && !defined(__i386__)
  59. #define __i386__
  60. #endif
  61.  
  62. /* Macros to make switching between C and C++ mode easier */
  63. #ifdef __cplusplus
  64. #define C_MODE_START    extern "C" {
  65. #define C_MODE_END  }
  66. #define STATIC_CAST(TYPE) static_cast<TYPE>
  67. #else
  68. #define C_MODE_START
  69. #define C_MODE_END
  70. #define STATIC_CAST(TYPE) (TYPE)
  71. #endif
  72.  
  73. #if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(WIN32)
  74. #include <config-win.h>
  75. #else
  76. #include <my_config.h>
  77. #if defined(__cplusplus) && defined(inline)
  78. #undef inline               /* fix configure problem */
  79. #endif
  80. #endif /* _WIN32... */
  81.  
  82. #include <my_charsets.h>
  83.  
  84. /* Make it easier to add conditional code for windows */
  85. #ifdef __WIN__
  86. #define IF_WIN(A,B) (A)
  87. #else
  88. #define IF_WIN(A,B) (B)
  89. #endif
  90.  
  91. #ifndef EMBEDDED_LIBRARY
  92. #ifdef WITH_NDB_BINLOG
  93. #define HAVE_NDB_BINLOG 1
  94. #endif
  95. #endif /* !EMBEDDED_LIBRARY */
  96.  
  97. #ifndef EMBEDDED_LIBRARY
  98. #define HAVE_REPLICATION
  99. #define HAVE_EXTERNAL_CLIENT
  100. #endif
  101.  
  102. /* Some defines to avoid ifdefs in the code */
  103. #ifndef NETWARE_YIELD
  104. #define NETWARE_YIELD
  105. #define NETWARE_SET_SCREEN_MODE(A)
  106. #endif
  107.  
  108. /* Workaround for _LARGE_FILES and _LARGE_FILE_API incompatibility on AIX */
  109. #if defined(_AIX) && defined(_LARGE_FILE_API)
  110. #undef _LARGE_FILE_API
  111. #endif
  112.  
  113. /*
  114.   The macros below are used to allow build of Universal/fat binaries of
  115.   MySQL and MySQL applications under darwin.
  116. */
  117. #if defined(__APPLE__) && defined(__MACH__)
  118. #  undef SIZEOF_CHARP
  119. #  undef SIZEOF_SHORT
  120. #  undef SIZEOF_INT
  121. #  undef SIZEOF_LONG
  122. #  undef SIZEOF_LONG_LONG
  123. #  undef SIZEOF_OFF_T
  124. #  undef WORDS_BIGENDIAN
  125. #  define SIZEOF_SHORT 2
  126. #  define SIZEOF_INT 4
  127. #  define SIZEOF_LONG_LONG 8
  128. #  define SIZEOF_OFF_T 8
  129. #  if defined(__i386__) || defined(__ppc__)
  130. #    define SIZEOF_CHARP 4
  131. #    define SIZEOF_LONG 4
  132. #  elif defined(__x86_64__) || defined(__ppc64__)
  133. #    define SIZEOF_CHARP 8
  134. #    define SIZEOF_LONG 8
  135. #  else
  136. #    error Building FAT binary for an unknown architecture.
  137. #  endif
  138. #  if defined(__ppc__) || defined(__ppc64__)
  139. #    define WORDS_BIGENDIAN
  140. #  endif
  141. #endif /* defined(__APPLE__) && defined(__MACH__) */
  142.  
  143.  
  144. /*
  145.   The macros below are borrowed from include/linux/compiler.h in the
  146.   Linux kernel. Use them to indicate the likelyhood of the truthfulness
  147.   of a condition. This serves two purposes - newer versions of gcc will be
  148.   able to optimize for branch predication, which could yield siginficant
  149.   performance gains in frequently executed sections of the code, and the
  150.   other reason to use them is for documentation
  151. */
  152.  
  153. #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
  154. #define __builtin_expect(x, expected_value) (x)
  155. #endif
  156.  
  157. /**
  158.   The semantics of builtin_expect() are that
  159.   1) its two arguments are long
  160.   2) it\'s likely that they are ==
  161.   Those of our likely(x) are that x can be bool/int/longlong/pointer.
  162. */
  163. #define likely(x)   __builtin_expect(((x) != 0),1)
  164. #define unlikely(x) __builtin_expect(((x) != 0),0)
  165.  
  166. /*
  167.   The macros below are useful in optimising places where it has been
  168.   discovered that cache misses stall the process and where a prefetch
  169.   of the cache line can improve matters. This is available in GCC 3.1.1
  170.   and later versions.
  171.   PREFETCH_READ says that addr is going to be used for reading and that
  172.   it is to be kept in caches if possible for a while
  173.   PREFETCH_WRITE also says that the item to be cached is likely to be
  174.   updated.
  175.   The *LOCALITY scripts are also available for experimentation purposes
  176.   mostly and should only be used if they are verified to improve matters.
  177.   For more input see GCC manual (available in GCC 3.1.1 and later)
  178. */
  179.  
  180. #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
  181. #define PREFETCH_READ(addr) __builtin_prefetch(addr, 0, 3)
  182. #define PREFETCH_WRITE(addr) \\
  183.   __builtin_prefetch(addr, 1, 3)
  184. #define PREFETCH_READ_LOCALITY(addr, locality) \\
  185.   __builtin_prefetch(addr, 0, locality)
  186. #define PREFETCH_WRITE_LOCALITY(addr, locality) \\
  187.   __builtin_prefetch(addr, 1, locality)
  188. #else
  189. #define PREFETCH_READ(addr)
  190. #define PREFETCH_READ_LOCALITY(addr, locality)
  191. #define PREFETCH_WRITE(addr)
  192. #define PREFETCH_WRITE_LOCALITY(addr, locality)
  193. #endif
  194.  
  195. /*
  196.   The following macro is used to ensure that code often used in most
  197.   SQL statements and definitely for parts of the SQL processing are
  198.   kept in a code segment by itself. This has the advantage that the
  199.   risk of common code being overlapping in caches of the CPU is less.
  200.   This can be a cause of big performance problems.
  201.   Routines should be put in this category with care and when they are
  202.   put there one should also strive to make as much of the error handling
  203.   as possible (or uncommon code of the routine) to execute in a
  204.   separate method to avoid moving to much code to this code segment.
  205.  
  206.   It is very easy to use, simply add HOT_METHOD at the end of the
  207.   function declaration.
  208.   For more input see GCC manual (available in GCC 2.95 and later)
  209. */
  210.  
  211. #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94)
  212. #define HOT_METHOD \\
  213.   __attribute__ ((section ("hot_code_section")))
  214. #else
  215. #define HOT_METHOD
  216. #endif
  217.  
  218. /*
  219.   The following macro is used to ensure that popular global variables
  220.   are located next to each other to avoid that they contend for the
  221.   same cache lines.
  222.  
  223.   It is very easy to use, simply add HOT_DATA at the end of the declaration
  224.   of the variable, the variable must be initialised because of the way
  225.   that linker works so a declaration using HOT_DATA should look like:
  226.   uint global_hot_data HOT_DATA = 0;
  227.   For more input see GCC manual (available in GCC 2.95 and later)
  228. */
  229.  
  230. #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94)
  231. #define HOT_DATA \\
  232.   __attribute__ ((section ("hot_data_section")))
  233. #else
  234. #define HOT_DATA
  235. #endif
  236.  
  237. /*
  238.   now let\'s figure out if inline functions are supported
  239.   autoconf defines \'inline\' to be empty, if not
  240. */
  241. #define inline_test_1(X)        X ## 1
  242. #define inline_test_2(X)        inline_test_1(X)
  243. #if inline_test_2(inline) != 1
  244. #define HAVE_INLINE
  245. #endif
  246. #undef inline_test_2
  247. #undef inline_test_1
  248. /* helper macro for "instantiating" inline functions */
  249. #define STATIC_INLINE static inline
  250.  
  251. /*
  252.   The following macros are used to control inlining a bit more than
  253.   usual. These macros are used to ensure that inlining always or
  254.   never occurs (independent of compilation mode).
  255.   For more input see GCC manual (available in GCC 3.1.1 and later)
  256. */
  257.  
  258. #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
  259. #define ALWAYS_INLINE __attribute__ ((always_inline))
  260. #define NEVER_INLINE __attribute__ ((noinline))
  261. #else
  262. #define ALWAYS_INLINE
  263. #define NEVER_INLINE
  264. #endif
  265.  
  266.  
  267. /* Fix problem with S_ISLNK() on Linux */
  268. #if defined(TARGET_OS_LINUX) || defined(__GLIBC__)
  269. #undef  _GNU_SOURCE
  270. #define _GNU_SOURCE 1
  271. #endif
  272.  
  273. /*
  274.   Temporary solution to solve bug#7156. Include "sys/types.h" before
  275.   the thread headers, else the function madvise() will not be defined
  276. */
  277. #if defined(HAVE_SYS_TYPES_H) && ( defined(sun) || defined(__sun) )
  278. #include <sys/types.h>
  279. #endif
  280.  
  281. /* The client defines this to avoid all thread code */
  282. #if defined(UNDEF_THREADS_HACK)
  283. #undef THREAD
  284. #undef HAVE_LINUXTHREADS
  285. #undef HAVE_NPTL
  286. #endif
  287.  
  288. #ifdef HAVE_THREADS_WITHOUT_SOCKETS
  289. /* MIT pthreads does not work with unix sockets */
  290. #undef HAVE_SYS_UN_H
  291. #endif
  292.  
  293. #define __EXTENSIONS__ 1    /* We want some extension */
  294. #ifndef __STDC_EXT__
  295. #define __STDC_EXT__ 1          /* To get large file support on hpux */
  296. #endif
  297.  
  298. /*
  299.   Solaris 9 include file <sys/feature_tests.h> refers to X/Open document
  300.  
  301.     System Interfaces and Headers, Issue 5
  302.  
  303.   saying we should define _XOPEN_SOURCE=500 to get POSIX.1c prototypes,
  304.   but apparently other systems (namely FreeBSD) don\'t agree.
  305.  
  306.   On a newer Solaris 10, the above file recognizes also _XOPEN_SOURCE=600.
  307.   Furthermore, it tests that if a program requires older standard
  308.   (_XOPEN_SOURCE<600 or _POSIX_C_SOURCE<200112L) it cannot be
  309.   run on a new compiler (that defines _STDC_C99) and issues an #error.
  310.   It\'s also an #error if a program requires new standard (_XOPEN_SOURCE=600
  311.   or _POSIX_C_SOURCE=200112L) and a compiler does not define _STDC_C99.
  312.  
  313.   To add more to this mess, Sun Studio C compiler defines _STDC_C99 while
  314.   C++ compiler does not!
  315.  
  316.   So, in a desperate attempt to get correct prototypes for both
  317.   C and C++ code, we define either _XOPEN_SOURCE=600 or _XOPEN_SOURCE=500
  318.   depending on the compiler\'s announced C standard support.
  319.  
  320.   Cleaner solutions are welcome.
  321. */
  322. #ifdef __sun
  323. #if __STDC_VERSION__ - 0 >= 199901L
  324. #define _XOPEN_SOURCE 600
  325. #else
  326. #define _XOPEN_SOURCE 500
  327. #endif
  328. #endif
  329.  
  330. #if defined(THREAD) && !defined(__WIN__)
  331. #ifndef _POSIX_PTHREAD_SEMANTICS
  332. #define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */
  333. #endif
  334.  
  335. #if !defined(SCO)
  336. #define _REENTRANT  1   /* Some thread libraries require this */
  337. #endif
  338. #if !defined(_THREAD_SAFE) && !defined(_AIX)
  339. #define _THREAD_SAFE            /* Required for OSF1 */
  340. #endif
  341. #if defined(HPUX10) || defined(HPUX11)
  342. C_MODE_START            /* HPUX needs this, signal.h bug */
  343. #include <pthread.h>
  344. C_MODE_END
  345. #else
  346. #include <pthread.h>        /* AIX must have this included first */
  347. #endif
  348. #if !defined(SCO) && !defined(_REENTRANT)
  349. #define _REENTRANT  1   /* Threads requires reentrant code */
  350. #endif
  351. #endif /* THREAD */
  352.  
  353. /* Go around some bugs in different OS and compilers */
  354. #ifdef _AIX         /* By soren@t.dk */
  355. #define _H_STRINGS
  356. #define _SYS_STREAM_H
  357. /* #define _AIX32_CURSES */ /* XXX: this breaks AIX 4.3.3 (others?). */
  358. #define ulonglong2double(A) my_ulonglong2double(A)
  359. #define my_off_t2double(A)  my_ulonglong2double(A)
  360. C_MODE_START
  361. double my_ulonglong2double(unsigned long long A);
  362. C_MODE_END
  363. #endif /* _AIX */
  364.  
  365. #ifdef HAVE_BROKEN_SNPRINTF /* HPUX 10.20 don\'t have this defined */
  366. #undef HAVE_SNPRINTF
  367. #endif
  368. #ifdef HAVE_BROKEN_PREAD
  369. /*
  370.   pread()/pwrite() are not 64 bit safe on HP-UX 11.0 without
  371.   installing the kernel patch PHKL_20349 or greater
  372. */
  373. #undef HAVE_PREAD
  374. #undef HAVE_PWRITE
  375. #endif
  376. #if defined(HAVE_BROKEN_INLINE) && !defined(__cplusplus)
  377. #undef inline
  378. #define inline
  379. #endif
  380.  
  381. #ifdef UNDEF_HAVE_GETHOSTBYNAME_R       /* For OSF4.x */
  382. #undef HAVE_GETHOSTBYNAME_R
  383. #endif
  384. #ifdef UNDEF_HAVE_INITGROUPS            /* For AIX 4.3 */
  385. #undef HAVE_INITGROUPS
  386. #endif
  387.  
  388. /* gcc/egcs issues */
  389.  
  390. #if defined(__GNUC) && defined(__EXCEPTIONS)
  391. #error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
  392. #endif
  393.  
  394.  
  395. /* Fix a bug in gcc 2.8.0 on IRIX 6.2 */
  396. #if SIZEOF_LONG == 4 && defined(__LONG_MAX__) && (__GNUC__ == 2 && __GNUC_MINOR__ == 8)
  397. #undef __LONG_MAX__             /* Is a longlong value in gcc 2.8.0 ??? */
  398. #define __LONG_MAX__ 2147483647
  399. #endif
  400.  
  401. /* egcs 1.1.2 has a problem with memcpy on Alpha */
  402. #if defined(__GNUC__) && defined(__alpha__) && ! (__GNUC__ > 2 || (__GNUC__ == 2 &&  __GNUC_MINOR__ >= 95))
  403. #define BAD_MEMCPY
  404. #endif
  405.  
  406. #if defined(_lint) && !defined(lint)
  407. #define lint
  408. #endif
  409. #if SIZEOF_LONG_LONG > 4 && !defined(_LONG_LONG)
  410. #define _LONG_LONG 1        /* For AIX string library */
  411. #endif
  412.  
  413. #ifndef stdin
  414. #include <stdio.h>
  415. #endif
  416. #include <stdarg.h>
  417. #ifdef HAVE_STDLIB_H
  418. #include <stdlib.h>
  419. #endif
  420. #ifdef HAVE_STDDEF_H
  421. #include <stddef.h>
  422. #endif
  423.  
  424. #include <math.h>
  425. #ifdef HAVE_LIMITS_H
  426. #include <limits.h>
  427. #endif
  428. #ifdef HAVE_FLOAT_H
  429. #include <float.h>
  430. #endif
  431. #ifdef HAVE_FENV_H
  432. #include <fenv.h> /* For fesetround() */
  433. #endif
  434.  
  435. #ifdef HAVE_SYS_TYPES_H
  436. #include <sys/types.h>
  437. #endif
  438. #ifdef HAVE_FCNTL_H
  439. #include <fcntl.h>
  440. #endif
  441. #ifdef HAVE_SYS_STAT_H
  442. #include <sys/stat.h>
  443. #endif
  444. #ifdef HAVE_SYS_TIMEB_H
  445. #include <sys/timeb.h>              /* Avoid warnings on SCO */
  446. #endif
  447. #if TIME_WITH_SYS_TIME
  448. # include <sys/time.h>
  449. # include <time.h>
  450. #else
  451. # if HAVE_SYS_TIME_H
  452. #  include <sys/time.h>
  453. # else
  454. #  include <time.h>
  455. # endif
  456. #endif /* TIME_WITH_SYS_TIME */
  457. #ifdef HAVE_UNISTD_H
  458. #include <unistd.h>
  459. #endif
  460. #if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA)
  461. #undef HAVE_ALLOCA
  462. #undef HAVE_ALLOCA_H
  463. #endif
  464. #ifdef HAVE_ALLOCA_H
  465. #include <alloca.h>
  466. #endif
  467.  
  468. #include <errno.h>              /* Recommended by debian */
  469. /* We need the following to go around a problem with openssl on solaris */
  470. #if defined(HAVE_CRYPT_H)
  471. #include <crypt.h>
  472. #endif
  473.  
  474. /*
  475.   A lot of our programs uses asserts, so better to always include it
  476.   This also fixes a problem when people uses DBUG_ASSERT without including
  477.   assert.h
  478. */
  479. #include <assert.h>
  480.  
  481. /* an assert that works at compile-time. only for constant expression */
  482. #ifdef _some_old_compiler_that_does_not_understand_the_construct_below_
  483. #define compile_time_assert(X)  do { } while(0)
  484. #else
  485. #define compile_time_assert(X)                                  \\
  486.   do                                                            \\
  487.   {                                                             \\
  488.     typedef char compile_time_assert[(X) ? 1 : -1];             \\
  489.   } while(0)
  490. #endif
  491.  
  492. /* Go around some bugs in different OS and compilers */
  493. #if defined (HPUX11) && defined(_LARGEFILE_SOURCE)
  494. #define _LARGEFILE64_SOURCE
  495. #endif
  496. #if defined(_HPUX_SOURCE) && defined(HAVE_SYS_STREAM_H)
  497. #include <sys/stream.h>     /* HPUX 10.20 defines ulong here. UGLY !!! */
  498. #define HAVE_ULONG
  499. #endif
  500. #if defined(HPUX10) && defined(_LARGEFILE64_SOURCE) && defined(THREAD)
  501. /* Fix bug in setrlimit */
  502. #undef setrlimit
  503. #define setrlimit cma_setrlimit64
  504. #endif
  505. /* Declare madvise where it is not declared for C++, like Solaris */
  506. #if HAVE_MADVISE && !HAVE_DECL_MADVISE && defined(__cplusplus)
  507. extern "C" int madvise(void *addr, size_t len, int behav);
  508. #endif
  509.  
  510. #ifdef __QNXNTO__
  511. /* This has to be after include limits.h */
  512. #define HAVE_ERRNO_AS_DEFINE
  513. #define HAVE_FCNTL_LOCK
  514. #undef  HAVE_FINITE
  515. #undef  LONGLONG_MIN            /* These get wrongly defined in QNX 6.2 */
  516. #undef  LONGLONG_MAX            /* standard system library \'limits.h\' */
  517. #endif
  518.  
  519. /* We can not live without the following defines */
  520.  
  521. #define USE_MYFUNC 1        /* Must use syscall indirection */
  522. #define MASTER 1        /* Compile without unireg */
  523. #define ENGLISH 1       /* Messages in English */
  524. #define POSIX_MISTAKE 1     /* regexp: Fix stupid spec error */
  525. #define USE_REGEX 1     /* We want the use the regex library */
  526. /* Do not define for ultra sparcs */
  527. #define USE_BMOVE512 1      /* Use this unless system bmove is faster */
  528.  
  529. #define QUOTE_ARG(x)        #x  /* Quote argument (before cpp) */
  530. #define STRINGIFY_ARG(x) QUOTE_ARG(x)   /* Quote argument, after cpp */
  531.  
  532. /* Paranoid settings. Define I_AM_PARANOID if you are paranoid */
  533. #ifdef I_AM_PARANOID
  534. #define DONT_ALLOW_USER_CHANGE 1
  535. #define DONT_USE_MYSQL_PWD 1
  536. #endif
  537.  
  538. /* Does the system remember a signal handler after a signal ? */
  539. #ifndef HAVE_BSD_SIGNALS
  540. #define DONT_REMEMBER_SIGNAL
  541. #endif
  542.  
  543. #if defined(_lint) || defined(FORCE_INIT_OF_VARS)
  544. #define LINT_INIT(var)  var=0           /* No uninitialize-warning */
  545. #else
  546. #define LINT_INIT(var)
  547. #endif
  548.  
  549. #if defined(_lint) || defined(FORCE_INIT_OF_VARS) || defined(HAVE_purify)
  550. #define PURIFY_OR_LINT_INIT(var) var=0
  551. #else
  552. #define PURIFY_OR_LINT_INIT(var)
  553. #endif
  554.  
  555. #if !defined(HAVE_UINT)
  556. #undef HAVE_UINT
  557. #define HAVE_UINT
  558. typedef unsigned int uint;
  559. typedef unsigned short ushort;
  560. #endif
  561.  
  562. #define CMP_NUM(a,b)    (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
  563. #define sgn(a)      (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
  564. #define swap_variables(t, a, b) { t swap_dummy; swap_dummy= a; a= b; b= swap_dummy; }
  565. #define test(a)     ((a) ? 1 : 0)
  566. #define set_if_bigger(a,b)  do { if ((a) < (b)) (a)=(b); } while(0)
  567. #define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
  568. #define test_all_bits(a,b) (((a) & (b)) == (b))
  569. #define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
  570. #define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
  571.  
  572. /* Define some general constants */
  573. #ifndef TRUE
  574. #define TRUE        (1) /* Logical true */
  575. #define FALSE       (0) /* Logical false */
  576. #endif
  577.  
  578. #if defined(__GNUC__)
  579. #define function_volatile   volatile
  580. #define my_reinterpret_cast(A) reinterpret_cast<A>
  581. #define my_const_cast(A) const_cast<A>
  582. # ifndef GCC_VERSION
  583. #  define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
  584. # endif
  585. #elif !defined(my_reinterpret_cast)
  586. #define my_reinterpret_cast(A) (A)
  587. #define my_const_cast(A) (A)
  588. #endif
  589.  
  590. #include <my_attribute.h>
  591.  
  592. /*
  593.   Wen using the embedded library, users might run into link problems,
  594.   duplicate declaration of __cxa_pure_virtual, solved by declaring it a
  595.   weak symbol.
  596. */
  597. #if defined(USE_MYSYS_NEW) && ! defined(DONT_DECLARE_CXA_PURE_VIRTUAL)
  598. C_MODE_START
  599. int __cxa_pure_virtual () __attribute__ ((weak));
  600. C_MODE_END
  601. #endif
  602.  
  603. /* From old s-system.h */
  604.  
  605. /*
  606.   Support macros for non ansi & other old compilers. Since such
  607.   things are no longer supported we do nothing. We keep then since
  608.   some of our code may still be needed to upgrade old customers.
  609. */
  610. #define _VARARGS(X) X
  611. #define _STATIC_VARARGS(X) X
  612.  
  613. /* The DBUG_ON flag always takes precedence over default DBUG_OFF */
  614. #if defined(DBUG_ON) && defined(DBUG_OFF)
  615. #undef DBUG_OFF
  616. #endif
  617.  
  618. /* We might be forced to turn debug off, if not turned off already */
  619. #if (defined(FORCE_DBUG_OFF) || defined(_lint)) && !defined(DBUG_OFF)
  620. #  define DBUG_OFF
  621. #  ifdef DBUG_ON
  622. #    undef DBUG_ON
  623. #  endif
  624. #endif
  625.  
  626. typedef char        my_bool; /* Small bool */
  627. #include <my_dbug.h>
  628.  
  629. #define MIN_ARRAY_SIZE  0   /* Zero or One. Gcc allows zero*/
  630. #define ASCII_BITS_USED 8   /* Bit char used */
  631. #define NEAR_F          /* No near function handling */
  632.  
  633. /* Some types that is different between systems */
  634.  
  635. typedef int File;       /* File descriptor */
  636. #ifndef Socket_defined
  637. typedef int my_socket;  /* File descriptor for sockets */
  638. #define INVALID_SOCKET -1
  639. #endif
  640. /* Type for fuctions that handles signals */
  641. #define sig_handler void
  642. C_MODE_START
  643. typedef void    (*sig_return)();/* Returns type from signal */
  644. C_MODE_END
  645. #if defined(__GNUC__) && !defined(_lint)
  646. typedef char    pchar;      /* Mixed prototypes can take char */
  647. typedef char    puchar;     /* Mixed prototypes can take char */
  648. typedef char    pbool;      /* Mixed prototypes can take char */
  649. typedef short   pshort;     /* Mixed prototypes can take short int */
  650. typedef float   pfloat;     /* Mixed prototypes can take float */
  651. #else
  652. typedef int pchar;      /* Mixed prototypes can\'t take char */
  653. typedef uint    puchar;     /* Mixed prototypes can\'t take char */
  654. typedef int pbool;      /* Mixed prototypes can\'t take char */
  655. typedef int pshort;     /* Mixed prototypes can\'t take short int */
  656. typedef double  pfloat;     /* Mixed prototypes can\'t take float */
  657. #endif
  658. C_MODE_START
  659. typedef int (*qsort_cmp)(const void *,const void *);
  660. typedef int (*qsort_cmp2)(void*, const void *,const void *);
  661. C_MODE_END
  662. #define qsort_t RETQSORTTYPE    /* Broken GCC cant handle typedef !!!! */
  663. #ifdef HAVE_SYS_SOCKET_H
  664. #include <sys/socket.h>
  665. #endif
  666.  
  667. /* file create flags */
  668.  
  669. #ifndef O_SHARE         /* Probably not windows */
  670. #define O_SHARE     0   /* Flag to my_open for shared files */
  671. #ifndef O_BINARY
  672. #define O_BINARY    0   /* Flag to my_open for binary files */
  673. #endif
  674. #ifndef FILE_BINARY
  675. #define FILE_BINARY O_BINARY /* Flag to my_fopen for binary streams */
  676. #endif
  677. #ifdef HAVE_FCNTL
  678. #define HAVE_FCNTL_LOCK
  679. #define F_TO_EOF    0L  /* Param to lockf() to lock rest of file */
  680. #endif
  681. #endif /* O_SHARE */
  682.  
  683. #ifndef O_TEMPORARY
  684. #define O_TEMPORARY 0
  685. #endif
  686. #ifndef O_SHORT_LIVED
  687. #define O_SHORT_LIVED   0
  688. #endif
  689. #ifndef O_NOFOLLOW
  690. #define O_NOFOLLOW      0
  691. #endif
  692.  
  693. /* additional file share flags for win32 */
  694. #ifdef __WIN__
  695. #define _SH_DENYRWD     0x110    /* deny read/write mode & delete */
  696. #define _SH_DENYWRD     0x120    /* deny write mode & delete      */
  697. #define _SH_DENYRDD     0x130    /* deny read mode & delete       */
  698. #define _SH_DENYDEL     0x140    /* deny delete only              */
  699. #endif /* __WIN__ */
  700.  
  701.  
  702. /* #define USE_RECORD_LOCK  */
  703.  
  704.     /* Unsigned types supported by the compiler */
  705. #define UNSINT8         /* unsigned int8 (char) */
  706. #define UNSINT16        /* unsigned int16 */
  707. #define UNSINT32        /* unsigned int32 */
  708.  
  709.     /* General constants */
  710. #define FN_LEN      256 /* Max file name len */
  711. #define FN_HEADLEN  253 /* Max length of filepart of file name */
  712. #define FN_EXTLEN   20  /* Max length of extension (part of FN_LEN) */
  713. #define FN_REFLEN   512 /* Max length of full path-name */
  714. #define FN_EXTCHAR  \'.\'
  715. #define FN_HOMELIB  \'~\' /* ~/ is used as abbrev for home dir */
  716. #define FN_CURLIB   \'.\' /* ./ is used as abbrev for current dir */
  717. #define FN_PARENTDIR    ".."    /* Parent directory; Must be a string */
  718.  
  719. #ifndef FN_LIBCHAR
  720. #define FN_LIBCHAR  \'/\'
  721. #define FN_ROOTDIR  "/"
  722. #endif
  723.  
  724. /*
  725.   MY_FILE_MIN is  Windows speciality and is used to quickly detect
  726.   the mismatch of CRT and mysys file IO usage on Windows at runtime.
  727.   CRT file descriptors can be in the range 0-2047, whereas descriptors returned
  728.   by my_open() will start with 2048. If a file descriptor with value less then
  729.   MY_FILE_MIN is passed to mysys IO function, chances are it stemms from
  730.   open()/fileno() and not my_open()/my_fileno.
  731.  
  732.   For Posix,  mysys functions are light wrappers around libc, and MY_FILE_MIN
  733.   is logically 0.
  734. */
  735.  
  736. #ifdef _WIN32
  737. #define MY_FILE_MIN  2048
  738. #else
  739. #define MY_FILE_MIN  0
  740. #endif
  741.  
  742. /*
  743.   MY_NFILE is the default size of my_file_info array.
  744.  
  745.   It is larger on Windows, because it all file handles are stored in my_file_info
  746.   Default size is 16384 and this should be enough for most cases.If it is not
  747.   enough, --max-open-files with larger value can be used.
  748.  
  749.   For Posix , my_file_info array is only used to store filenames for
  750.   error reporting and its size is not a limitation for number of open files.
  751. */
  752. #ifdef _WIN32
  753. #define MY_NFILE (16384 + MY_FILE_MIN)
  754. #else
  755. #define MY_NFILE 64
  756. #endif
  757.  
  758. #ifndef OS_FILE_LIMIT
  759. #define OS_FILE_LIMIT   65535
  760. #endif
  761.  
  762. /* #define EXT_IN_LIBNAME     */
  763. /* #define FN_NO_CASE_SENCE   */
  764. /* #define FN_UPPER_CASE TRUE */
  765.  
  766. /*
  767.   Io buffer size; Must be a power of 2 and a multiple of 512. May be
  768.   smaller what the disk page size. This influences the speed of the
  769.   isam btree library. eg to big to slow.
  770. */
  771. #define IO_SIZE         4096
  772. /*
  773.   How much overhead does malloc have. The code often allocates
  774.   something like 1024-MALLOC_OVERHEAD bytes
  775. */
  776. #ifdef SAFEMALLOC
  777. #define MALLOC_OVERHEAD (8+24+4)
  778. #else
  779. #define MALLOC_OVERHEAD 8
  780. #endif
  781.     /* get memory in huncs */
  782. #define ONCE_ALLOC_INIT     (uint) (4096-MALLOC_OVERHEAD)
  783.     /* Typical record cash */
  784. #define RECORD_CACHE_SIZE   (uint) (64*1024-MALLOC_OVERHEAD)
  785.     /* Typical key cash */
  786. #define KEY_CACHE_SIZE      (uint) (8*1024*1024-MALLOC_OVERHEAD)
  787.     /* Default size of a key cache block  */
  788. #define KEY_CACHE_BLOCK_SIZE    (uint) 1024
  789.  
  790.  
  791.     /* Some things that this system doesn\'t have */
  792.  
  793. #define NO_HASH         /* Not needed anymore */
  794. #ifdef _WIN32
  795. #define NO_DIR_LIBRARY      /* Not standard dir-library */
  796. #endif
  797.  
  798. /* Some defines of functions for portability */
  799.  
  800. #undef remove       /* Crashes MySQL on SCO 5.0.0 */
  801. #ifndef __WIN__
  802. #define closesocket(A)  close(A)
  803. #ifndef ulonglong2double
  804. #define ulonglong2double(A) ((double) (ulonglong) (A))
  805. #define my_off_t2double(A)  ((double) (my_off_t) (A))
  806. #endif
  807. #ifndef double2ulonglong
  808. #define double2ulonglong(A) ((ulonglong) (double) (A))
  809. #endif
  810. #endif
  811.  
  812. #ifndef offsetof
  813. #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
  814. #endif
  815. #define ulong_to_double(X) ((double) (ulong) (X))
  816. #define SET_STACK_SIZE(X)   /* Not needed on real machines */
  817.  
  818. #ifndef STACK_DIRECTION
  819. #error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
  820. #endif
  821.  
  822. #if !defined(HAVE_STRTOK_R)
  823. inline char *strtok_r(char *str, const char *delim, char **saveptr)
  824. {
  825.   return strtok(str,delim);
  826. }
  827. #endif
  828.  
  829. /* This is from the old m-machine.h file */
  830.  
  831. #if SIZEOF_LONG_LONG > 4
  832. #define HAVE_LONG_LONG 1
  833. #endif
  834.  
  835. /*
  836.   Some pre-ANSI-C99 systems like AIX 5.1 and Linux/GCC 2.95 define
  837.   ULONGLONG_MAX, LONGLONG_MIN, LONGLONG_MAX; we use them if they\'re defined.
  838.   Also on Windows we define these constants by hand in config-win.h.
  839. */
  840.  
  841. #if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
  842. #define LONGLONG_MIN    ((long long) 0x8000000000000000LL)
  843. #define LONGLONG_MAX    ((long long) 0x7FFFFFFFFFFFFFFFLL)
  844. #endif
  845.  
  846. #if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)
  847. /* First check for ANSI C99 definition: */
  848. #ifdef ULLONG_MAX
  849. #define ULONGLONG_MAX  ULLONG_MAX
  850. #else
  851. #define ULONGLONG_MAX ((unsigned long long)(~0ULL))
  852. #endif
  853. #endif /* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/
  854.  
  855. #define INT_MIN32       (~0x7FFFFFFFL)
  856. #define INT_MAX32       0x7FFFFFFFL
  857. #define UINT_MAX32      0xFFFFFFFFL
  858. #define INT_MIN24       (~0x007FFFFF)
  859. #define INT_MAX24       0x007FFFFF
  860. #define UINT_MAX24      0x00FFFFFF
  861. #define INT_MIN16       (~0x7FFF)
  862. #define INT_MAX16       0x7FFF
  863. #define UINT_MAX16      0xFFFF
  864. #define INT_MIN8        (~0x7F)
  865. #define INT_MAX8        0x7F
  866. #define UINT_MAX8       0xFF
  867.  
  868. /* From limits.h instead */
  869. #ifndef DBL_MIN
  870. #define DBL_MIN     4.94065645841246544e-324
  871. #define FLT_MIN     ((float)1.40129846432481707e-45)
  872. #endif
  873. #ifndef DBL_MAX
  874. #define DBL_MAX     1.79769313486231470e+308
  875. #define FLT_MAX     ((float)3.40282346638528860e+38)
  876. #endif
  877. #ifndef SIZE_T_MAX
  878. #define SIZE_T_MAX ~((size_t) 0)
  879. #endif
  880.  
  881. #ifndef isfinite
  882. #ifdef HAVE_FINITE
  883. #define isfinite(x) finite(x)
  884. #else
  885. #define finite(x) (1.0 / fabs(x) > 0.0)
  886. #endif /* HAVE_FINITE */
  887. #endif /* isfinite */
  888.  
  889. #ifndef HAVE_ISNAN
  890. #define isnan(x) ((x) != (x))
  891. #endif
  892.  
  893. #ifdef HAVE_ISINF
  894. /* Check if C compiler is affected by GCC bug #39228 */
  895. #if !defined(__cplusplus) && defined(HAVE_BROKEN_ISINF)
  896. /* Force store/reload of the argument to/from a 64-bit double */
  897. static inline double my_isinf(double x)
  898. {
  899.   volatile double t= x;
  900.   return isinf(t);
  901. }
  902. #else
  903. /* System-provided isinf() is available and safe to use */
  904. #define my_isinf(X) isinf(X)
  905. #endif
  906. #else /* !HAVE_ISINF */
  907. #define my_isinf(X) (!finite(X) && !isnan(X))
  908. #endif
  909.  
  910. /* Define missing math constants. */
  911. #ifndef M_PI
  912. #define M_PI 3.14159265358979323846
  913. #endif
  914. #ifndef M_E
  915. #define M_E 2.7182818284590452354
  916. #endif
  917. #ifndef M_LN2
  918. #define M_LN2 0.69314718055994530942
  919. #endif
  920.  
  921. /*
  922.   Max size that must be added to a so that we know Size to make
  923.   adressable obj.
  924. */
  925. #if SIZEOF_CHARP == 4
  926. typedef long        my_ptrdiff_t;
  927. #else
  928. typedef long long   my_ptrdiff_t;
  929. #endif
  930.  
  931. #define MY_ALIGN(A,L)   (((A) + (L) - 1) & ~((L) - 1))
  932. #define ALIGN_SIZE(A)   MY_ALIGN((A),sizeof(double))
  933. /* Size to make adressable obj. */
  934. #define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
  935.              /* Offset of field f in structure t */
  936. #define OFFSET(t, f)    ((size_t)(char *)&((t *)0)->f)
  937. #define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size)
  938. #define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B))
  939.  
  940. #define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
  941. #define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
  942.  
  943. /*
  944.   Custom version of standard offsetof() macro which can be used to get
  945.   offsets of members in class for non-POD types (according to the current
  946.   version of C++ standard offsetof() macro can\'t be used in such cases and
  947.   attempt to do so causes warnings to be emitted, OTOH in many cases it is
  948.   still OK to assume that all instances of the class has the same offsets
  949.   for the same members).
  950.  
  951.   This is temporary solution which should be removed once File_parser class
  952.   and related routines are refactored.
  953. */
  954.  
  955. #define my_offsetof(TYPE, MEMBER) \\
  956.         ((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
  957.  
  958. #define NullS       STATIC_CAST(char *)(0)
  959. /* Nowdays we do not support MessyDos */
  960. #ifndef NEAR
  961. #define NEAR                /* Who needs segments ? */
  962. #define FAR             /* On a good machine */
  963. #ifndef HUGE_PTR
  964. #define HUGE_PTR
  965. #endif
  966. #endif
  967. #if defined(__IBMC__) || defined(__IBMCPP__)
  968. /* This was  _System _Export but caused a lot of warnings on _AIX43 */
  969. #define STDCALL
  970. #elif !defined( STDCALL)
  971. #define STDCALL
  972. #endif
  973.  
  974. /* Typdefs for easyier portability */
  975.  
  976. #ifndef HAVE_UCHAR
  977. typedef unsigned char   uchar;  /* Short for unsigned char */
  978. #endif
  979.  
  980. #ifndef HAVE_INT8
  981. typedef signed char int8;       /* Signed integer >= 8  bits */
  982. #endif
  983. #ifndef HAVE_UINT8
  984. typedef unsigned char uint8;    /* Unsigned integer >= 8  bits */
  985. #endif
  986. #ifndef HAVE_INT16
  987. typedef short int16;
  988. #endif
  989. #ifndef HAVE_UINT16
  990. typedef unsigned short uint16;
  991. #endif
  992. #if SIZEOF_INT == 4
  993. #ifndef HAVE_INT32
  994. typedef int int32;
  995. #endif
  996. #ifndef HAVE_UINT32
  997. typedef unsigned int uint32;
  998. #endif
  999. #elif SIZEOF_LONG == 4
  1000. #ifndef HAVE_INT32
  1001. typedef long int32;
  1002. #endif
  1003. #ifndef HAVE_UINT32
  1004. typedef unsigned long uint32;
  1005. #endif
  1006. #else
  1007. #error Neither int or long is of 4 bytes width
  1008. #endif
  1009.  
  1010. #if !defined(HAVE_ULONG) && !defined(__USE_MISC)
  1011. typedef unsigned long   ulong;        /* Short for unsigned long */
  1012. #endif
  1013. #ifndef longlong_defined
  1014. /*
  1015.   Using [unsigned] long long is preferable as [u]longlong because we use
  1016.   [unsigned] long long unconditionally in many places,
  1017.   for example in constants with [U]LL suffix.
  1018. */
  1019. #if defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == 8
  1020. typedef unsigned long long int ulonglong; /* ulong or unsigned long long */
  1021. typedef long long int   longlong;
  1022. #else
  1023. typedef unsigned long   ulonglong;    /* ulong or unsigned long long */
  1024. typedef long        longlong;
  1025. #endif
  1026. #endif
  1027. #ifndef HAVE_INT64
  1028. typedef longlong int64;
  1029. #endif
  1030. #ifndef HAVE_UINT64
  1031. typedef ulonglong uint64;
  1032. #endif
  1033.  
  1034. #if defined(NO_CLIENT_LONG_LONG)
  1035. typedef unsigned long my_ulonglong;
  1036. #elif defined (__WIN__)
  1037. typedef unsigned __int64 my_ulonglong;
  1038. #else
  1039. typedef unsigned long long my_ulonglong;
  1040. #endif
  1041.  
  1042. #if SIZEOF_CHARP == SIZEOF_INT
  1043. typedef int intptr;
  1044. #elif SIZEOF_CHARP == SIZEOF_LONG
  1045. typedef long intptr;
  1046. #elif SIZEOF_CHARP == SIZEOF_LONG_LONG
  1047. typedef long long intptr;
  1048. #else
  1049. #error sizeof(void *) is neither sizeof(int) nor sizeof(long) nor sizeof(long long)
  1050. #endif
  1051.  
  1052. #define MY_ERRPTR ((void*)(intptr)1)
  1053.  
  1054. #ifdef USE_RAID
  1055. /*
  1056.   The following is done with a if to not get problems with pre-processors
  1057.   with late define evaluation
  1058. */
  1059. #if SIZEOF_OFF_T == 4
  1060. #define SYSTEM_SIZEOF_OFF_T 4
  1061. #else
  1062. #define SYSTEM_SIZEOF_OFF_T 8
  1063. #endif
  1064. #undef  SIZEOF_OFF_T
  1065. #define SIZEOF_OFF_T        8
  1066. #else
  1067. #define SYSTEM_SIZEOF_OFF_T SIZEOF_OFF_T
  1068. #endif /* USE_RAID */
  1069.  
  1070. #if SIZEOF_OFF_T > 4
  1071. typedef ulonglong my_off_t;
  1072. #else
  1073. typedef unsigned long my_off_t;
  1074. #endif
  1075. #define MY_FILEPOS_ERROR    (~STATIC_CAST(my_off_t)(0))
  1076. #if !defined(__WIN__)
  1077. typedef off_t os_off_t;
  1078. #endif
  1079.  
  1080. #if defined(__WIN__)
  1081. #define socket_errno    WSAGetLastError()
  1082. #define SOCKET_EINTR    WSAEINTR
  1083. #define SOCKET_EAGAIN   WSAEINPROGRESS
  1084. #define SOCKET_ETIMEDOUT WSAETIMEDOUT
  1085. #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
  1086. #define SOCKET_EADDRINUSE WSAEADDRINUSE
  1087. #define SOCKET_ENFILE   ENFILE
  1088. #define SOCKET_EMFILE   EMFILE
  1089. #else /* Unix */
  1090. #define socket_errno    errno
  1091. #define closesocket(A)  close(A)
  1092. #define SOCKET_EINTR    EINTR
  1093. #define SOCKET_EAGAIN   EAGAIN
  1094. #define SOCKET_ETIMEDOUT SOCKET_EINTR
  1095. #define SOCKET_EWOULDBLOCK EWOULDBLOCK
  1096. #define SOCKET_EADDRINUSE EADDRINUSE
  1097. #define SOCKET_ENFILE   ENFILE
  1098. #define SOCKET_EMFILE   EMFILE
  1099. #endif
  1100.  
  1101. typedef uint8       int7;   /* Most effective integer 0 <= x <= 127 */
  1102. typedef short       int15;  /* Most effective integer 0 <= x <= 32767 */
  1103. typedef int     myf;    /* Type of MyFlags in my_funcs */
  1104.         /* Macros for converting *constants* to the right type */
  1105. #define INT8(v)     (int8) (v)
  1106. #define INT16(v)    (int16) (v)
  1107. #define INT32(v)    (int32) (v)
  1108. #define MYF(v)      STATIC_CAST(myf)(v)
  1109.  
  1110. /*
  1111.   Defines to make it possible to prioritize register assignments. No
  1112.   longer that important with modern compilers.
  1113. */
  1114. #ifndef USING_X
  1115. #define reg1 register
  1116. #define reg2 register
  1117. #define reg3 register
  1118. #define reg4 register
  1119. #define reg5 register
  1120. #define reg6 register
  1121. #define reg7 register
  1122. #define reg8 register
  1123. #define reg9 register
  1124. #define reg10 register
  1125. #define reg11 register
  1126. #define reg12 register
  1127. #define reg13 register
  1128. #define reg14 register
  1129. #define reg15 register
  1130. #define reg16 register
  1131. #endif
  1132.  
  1133. /*
  1134.   Sometimes we want to make sure that the variable is not put into
  1135.   a register in debugging mode so we can see its value in the core
  1136. */
  1137.  
  1138. #ifndef DBUG_OFF
  1139. #define dbug_volatile volatile
  1140. #else
  1141. #define dbug_volatile
  1142. #endif
  1143.  
  1144. /* Some helper macros */
  1145. #define YESNO(X) ((X) ? "yes" : "no")
  1146.  
  1147. /* Defines for time function */
  1148. #define SCALE_SEC   100
  1149. #define SCALE_USEC  10000
  1150. #define MY_HOW_OFTEN_TO_ALARM   2   /* How often we want info on screen */
  1151. #define MY_HOW_OFTEN_TO_WRITE   10000   /* How often we want info on screen */
  1152.  
  1153. /*
  1154.   Define-funktions for reading and storing in machine independent format
  1155.   (low byte first)
  1156. */
  1157.  
  1158. /* Optimized store functions for Intel x86 */
  1159. #if defined(__i386__) || defined(_WIN32)
  1160. #define sint2korr(A)    (*((const int16 *) (A)))
  1161. #define sint3korr(A)    ((int32) ((((uchar) (A)[2]) & 128) ? \\
  1162.                   (((uint32) 255L << 24) | \\
  1163.                    (((uint32) (uchar) (A)[2]) << 16) |\\
  1164.                    (((uint32) (uchar) (A)[1]) << 8) | \\
  1165.                    ((uint32) (uchar) (A)[0])) : \\
  1166.                   (((uint32) (uchar) (A)[2]) << 16) |\\
  1167.                   (((uint32) (uchar) (A)[1]) << 8) | \\
  1168.                   ((uint32) (uchar) (A)[0])))
  1169. #define sint4korr(A)    (*((const long *) (A)))
  1170. #define uint2korr(A)    (*((const uint16 *) (A)))
  1171. #if defined(HAVE_purify) && !defined(_WIN32)
  1172. #define uint3korr(A)    (uint32) (((uint32) ((uchar) (A)[0])) +\\
  1173.                   (((uint32) ((uchar) (A)[1])) << 8) +\\
  1174.                   (((uint32) ((uchar) (A)[2])) << 16))
  1175. #else
  1176. /*
  1177.    ATTENTION !
  1178.    
  1179.     Please, note, uint3korr reads 4 bytes (not 3) !
  1180.     It means, that you have to provide enough allocated space !
  1181. */
  1182. #define uint3korr(A)    (long) (*((const unsigned int *) (A)) & 0xFFFFFF)
  1183. #endif /* HAVE_purify && !_WIN32 */
  1184. #define uint4korr(A)    (*((const uint32 *) (A)))
  1185. #define uint5korr(A)    ((ulonglong)(((uint32) ((uchar) (A)[0])) +\\
  1186.                     (((uint32) ((uchar) (A)[1])) << 8) +\\
  1187.                     (((uint32) ((uchar) (A)[2])) << 16) +\\
  1188.                     (((uint32) ((uchar) (A)[3])) << 24)) +\\
  1189.                     (((ulonglong) ((uchar) (A)[4])) << 32))
  1190. #define uint6korr(A)    ((ulonglong)(((uint32)    ((uchar) (A)[0]))          + \\
  1191.                                      (((uint32)    ((uchar) (A)[1])) << 8)   + \\
  1192.                                      (((uint32)    ((uchar) (A)[2])) << 16)  + \\
  1193.                                      (((uint32)    ((uchar) (A)[3])) << 24)) + \\
  1194.                          (((ulonglong) ((uchar) (A)[4])) << 32) +       \\
  1195.                          (((ulonglong) ((uchar) (A)[5])) << 40))
  1196. #define uint8korr(A)    (*((const ulonglong *) (A)))
  1197. #define sint8korr(A)    (*((const longlong *) (A)))
  1198. #define int2store(T,A)  *((uint16*) (T))= (uint16) (A)
  1199. #define int3store(T,A)  do { *(T)=  (uchar) ((A));\\
  1200.                             *(T+1)=(uchar) (((uint) (A) >> 8));\\
  1201.                             *(T+2)=(uchar) (((A) >> 16)); } while (0)
  1202. #define int4store(T,A)  *((long *) (T))= (long) (A)
  1203. #define int5store(T,A)  do { *(T)= (uchar)((A));\\
  1204.                              *((T)+1)=(uchar) (((A) >> 8));\\
  1205.                              *((T)+2)=(uchar) (((A) >> 16));\\
  1206.                              *((T)+3)=(uchar) (((A) >> 24)); \\
  1207.                              *((T)+4)=(uchar) (((A) >> 32)); } while(0)
  1208. #define int6store(T,A)  do { *(T)=    (uchar)((A));          \\
  1209.                              *((T)+1)=(uchar) (((A) >> 8));  \\
  1210.                              *((T)+2)=(uchar) (((A) >> 16)); \\
  1211.                              *((T)+3)=(uchar) (((A) >> 24)); \\
  1212.                              *((T)+4)=(uchar) (((A) >> 32)); \\
  1213.                              *((T)+5)=(uchar) (((A) >> 40)); } while(0)
  1214. #define int8store(T,A)  *((ulonglong *) (T))= (ulonglong) (A)
  1215.  
  1216. typedef union {
  1217.   double v;
  1218.   long m[2];
  1219. } doubleget_union;
  1220. #define doubleget(V,M)  \\
  1221. do { doubleget_union _tmp; \\
  1222.      _tmp.m[0] = *((const long*)(M)); \\
  1223.      _tmp.m[1] = *(((const long*) (M))+1); \\
  1224.      (V) = _tmp.v; } while(0)
  1225. #define doublestore(T,V) do { *((long *) T) = ((const doubleget_union *)&V)->m[0]; \\
  1226.                  *(((long *) T)+1) = ((const doubleget_union *)&V)->m[1]; \\
  1227.                          } while (0)
  1228. #define float4get(V,M)   do { *((float *) &(V)) = *((const float*) (M)); } while(0)
  1229. #define float8get(V,M)   doubleget((V),(M))
  1230. #define float4store(V,M) memcpy((uchar*) V,(const uchar*) (&M),sizeof(float))
  1231. #define floatstore(T,V)  memcpy((uchar*)(T), (const uchar*)(&V),sizeof(float))
  1232. #define floatget(V,M)    memcpy((uchar*) &V,(const uchar*) (M),sizeof(float))
  1233. #define float8store(V,M) doublestore((V),(M))
  1234. #else
  1235.  
  1236. /*
  1237.   We\'re here if it\'s not a IA-32 architecture (Win32 and UNIX IA-32 defines
  1238.   were done before)
  1239. */
  1240. #define sint2korr(A)    (int16) (((int16) ((uchar) (A)[0])) +\\
  1241.                  ((int16) ((int16) (A)[1]) << 8))
  1242. #define sint3korr(A)    ((int32) ((((uchar) (A)[2]) & 128) ? \\
  1243.                   (((uint32) 255L << 24) | \\
  1244.                    (((uint32) (uchar) (A)[2]) << 16) |\\
  1245.                    (((uint32) (uchar) (A)[1]) << 8) | \\
  1246.                    ((uint32) (uchar) (A)[0])) : \\
  1247.                   (((uint32) (uchar) (A)[2]) << 16) |\\
  1248.                   (((uint32) (uchar) (A)[1]) << 8) | \\
  1249.                   ((uint32) (uchar) (A)[0])))
  1250. #define sint4korr(A)    (int32) (((int32) ((uchar) (A)[0])) +\\
  1251.                 (((int32) ((uchar) (A)[1]) << 8)) +\\
  1252.                 (((int32) ((uchar) (A)[2]) << 16)) +\\
  1253.                 (((int32) ((int16) (A)[3]) << 24)))
  1254. #define sint8korr(A)    (longlong) uint8korr(A)
  1255. #define uint2korr(A)    (uint16) (((uint16) ((uchar) (A)[0])) +\\
  1256.                   ((uint16) ((uchar) (A)[1]) << 8))
  1257. #define uint3korr(A)    (uint32) (((uint32) ((uchar) (A)[0])) +\\
  1258.                   (((uint32) ((uchar) (A)[1])) << 8) +\\
  1259.                   (((uint32) ((uchar) (A)[2])) << 16))
  1260. #define uint4korr(A)    (uint32) (((uint32) ((uchar) (A)[0])) +\\
  1261.                   (((uint32) ((uchar) (A)[1])) << 8) +\\
  1262.                   (((uint32) ((uchar) (A)[2])) << 16) +\\
  1263.                   (((uint32) ((uchar) (A)[3])) << 24))
  1264. #define uint5korr(A)    ((ulonglong)(((uint32) ((uchar) (A)[0])) +\\
  1265.                     (((uint32) ((uchar) (A)[1])) << 8) +\\
  1266.                     (((uint32) ((uchar) (A)[2])) << 16) +\\
  1267.                     (((uint32) ((uchar) (A)[3])) << 24)) +\\
  1268.                     (((ulonglong) ((uchar) (A)[4])) << 32))
  1269. #define uint6korr(A)    ((ulonglong)(((uint32)    ((uchar) (A)[0]))          + \\
  1270.                                      (((uint32)    ((uchar) (A)[1])) << 8)   + \\
  1271.                                      (((uint32)    ((uchar) (A)[2])) << 16)  + \\
  1272.                                      (((uint32)    ((uchar) (A)[3])) << 24)) + \\
  1273.                          (((ulonglong) ((uchar) (A)[4])) << 32) +       \\
  1274.                          (((ulonglong) ((uchar) (A)[5])) << 40))
  1275. #define uint8korr(A)    ((ulonglong)(((uint32) ((uchar) (A)[0])) +\\
  1276.                     (((uint32) ((uchar) (A)[1])) << 8) +\\
  1277.                     (((uint32) ((uchar) (A)[2])) << 16) +\\
  1278.                     (((uint32) ((uchar) (A)[3])) << 24)) +\\
  1279.             (((ulonglong) (((uint32) ((uchar) (A)[4])) +\\
  1280.                     (((uint32) ((uchar) (A)[5])) << 8) +\\
  1281.                     (((uint32) ((uchar) (A)[6])) << 16) +\\
  1282.                     (((uint32) ((uchar) (A)[7])) << 24))) <<\\
  1283.                     32))
  1284. #define int2store(T,A)       do { uint def_temp= (uint) (A) ;\\
  1285.                                   *((uchar*) (T))=  (uchar)(def_temp); \\
  1286.                                    *((uchar*) (T)+1)=(uchar)((def_temp >> 8)); \\
  1287.                              } while(0)
  1288. #define int3store(T,A)       do { /*lint -save -e734 */\\
  1289.                                   *((uchar*)(T))=(uchar) ((A));\\
  1290.                                   *((uchar*) (T)+1)=(uchar) (((A) >> 8));\\
  1291.                                   *((uchar*)(T)+2)=(uchar) (((A) >> 16)); \\
  1292.                                   /*lint -restore */} while(0)
  1293. #define int4store(T,A)       do { *((char *)(T))=(char) ((A));\\
  1294.                                   *(((char *)(T))+1)=(char) (((A) >> 8));\\
  1295.                                   *(((char *)(T))+2)=(char) (((A) >> 16));\\
  1296.                                   *(((char *)(T))+3)=(char) (((A) >> 24)); } while(0)
  1297. #define int5store(T,A)       do { *((char *)(T))=     (char)((A));  \\
  1298.                                   *(((char *)(T))+1)= (char)(((A) >> 8)); \\
  1299.                                   *(((char *)(T))+2)= (char)(((A) >> 16)); \\
  1300.                                   *(((char *)(T))+3)= (char)(((A) >> 24)); \\
  1301.                                   *(((char *)(T))+4)= (char)(((A) >> 32)); \\
  1302.                         } while(0)
  1303. #define int6store(T,A)       do { *((char *)(T))=     (char)((A)); \\
  1304.                                   *(((char *)(T))+1)= (char)(((A) >> 8)); \\
  1305.                                   *(((char *)(T))+2)= (char)(((A) >> 16)); \\
  1306.                                   *(((char *)(T))+3)= (char)(((A) >> 24)); \\
  1307.                                   *(((char *)(T))+4)= (char)(((A) >> 32)); \\
  1308.                                   *(((char *)(T))+5)= (char)(((A) >> 40)); \\
  1309.                                 } while(0)
  1310. #define int8store(T,A)       do { uint def_temp= (uint) (A), def_temp2= (uint) ((A) >> 32); \\
  1311.                                   int4store((T),def_temp); \\
  1312.                                   int4store((T+4),def_temp2); } while(0)
  1313. #ifdef WORDS_BIGENDIAN
  1314. #define float4store(T,A) do { *(T)= ((uchar *) &A)[3];\\
  1315.                               *((T)+1)=(char) ((uchar *) &A)[2];\\
  1316.                               *((T)+2)=(char) ((uchar *) &A)[1];\\
  1317.                               *((T)+3)=(char) ((uchar *) &A)[0]; } while(0)
  1318.  
  1319. #define float4get(V,M)   do { float def_temp;\\
  1320.                               ((uchar*) &def_temp)[0]=(M)[3];\\
  1321.                               ((uchar*) &def_temp)[1]=(M)[2];\\
  1322.                               ((uchar*) &def_temp)[2]=(M)[1];\\
  1323.                               ((uchar*) &def_temp)[3]=(M)[0];\\
  1324.                               (V)=def_temp; } while(0)
  1325. #define float8store(T,V) do { *(T)= ((uchar *) &V)[7];\\
  1326.                               *((T)+1)=(char) ((uchar *) &V)[6];\\
  1327.                               *((T)+2)=(char) ((uchar *) &V)[5];\\
  1328.                               *((T)+3)=(char) ((uchar *) &V)[4];\\
  1329.                               *((T)+4)=(char) ((uchar *) &V)[3];\\
  1330.                               *((T)+5)=(char) ((uchar *) &V)[2];\\
  1331.                               *((T)+6)=(char) ((uchar *) &V)[1];\\
  1332.                               *((T)+7)=(char) ((uchar *) &V)[0]; } while(0)
  1333.  
  1334. #define float8get(V,M)   do { double def_temp;\\
  1335.                               ((uchar*) &def_temp)[0]=(M)[7];\\
  1336.                               ((uchar*) &def_temp)[1]=(M)[6];\\
  1337.                               ((uchar*) &def_temp)[2]=(M)[5];\\
  1338.                               ((uchar*) &def_temp)[3]=(M)[4];\\
  1339.                               ((uchar*) &def_temp)[4]=(M)[3];\\
  1340.                               ((uchar*) &def_temp)[5]=(M)[2];\\
  1341.                               ((uchar*) &def_temp)[6]=(M)[1];\\
  1342.                               ((uchar*) &def_temp)[7]=(M)[0];\\
  1343.                               (V) = def_temp; } while(0)
  1344. #else
  1345. #define float4get(V,M)   memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(float))
  1346. #define float4store(V,M) memcpy_fixed((uchar*) V,(uchar*) (&M),sizeof(float))
  1347.  
  1348. #if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
  1349. #define doublestore(T,V) do { *(((char*)T)+0)=(char) ((uchar *) &V)[4];\\
  1350.                               *(((char*)T)+1)=(char) ((uchar *) &V)[5];\\
  1351.                               *(((char*)T)+2)=(char) ((uchar *) &V)[6];\\
  1352.                               *(((char*)T)+3)=(char) ((uchar *) &V)[7];\\
  1353.                               *(((char*)T)+4)=(char) ((uchar *) &V)[0];\\
  1354.                               *(((char*)T)+5)=(char) ((uchar *) &V)[1];\\
  1355.                               *(((char*)T)+6)=(char) ((uchar *) &V)[2];\\
  1356.                               *(((char*)T)+7)=(char) ((uchar *) &V)[3]; }\\
  1357.                          while(0)
  1358. #define doubleget(V,M)   do { double def_temp;\\
  1359.                               ((uchar*) &def_temp)[0]=(M)[4];\\
  1360.                               ((uchar*) &def_temp)[1]=(M)[5];\\
  1361.                               ((uchar*) &def_temp)[2]=(M)[6];\\
  1362.                               ((uchar*) &def_temp)[3]=(M)[7];\\
  1363.                               ((uchar*) &def_temp)[4]=(M)[0];\\
  1364.                               ((uchar*) &def_temp)[5]=(M)[1];\\
  1365.                               ((uchar*) &def_temp)[6]=(M)[2];\\
  1366.                               ((uchar*) &def_temp)[7]=(M)[3];\\
  1367.                               (V) = def_temp; } while(0)
  1368. #endif /* __FLOAT_WORD_ORDER */
  1369.  
  1370. #define float8get(V,M)   doubleget((V),(M))
  1371. #define float8store(V,M) doublestore((V),(M))
  1372. #endif /* WORDS_BIGENDIAN */
  1373.  
  1374. #endif /* __i386__ OR _WIN32 */
  1375.  
  1376. /*
  1377.   Macro for reading 32-bit integer from network byte order (big-endian)
  1378.   from unaligned memory location.
  1379. */
  1380. #define int4net(A)        (int32) (((uint32) ((uchar) (A)[3]))        |\\
  1381.                   (((uint32) ((uchar) (A)[2])) << 8)  |\\
  1382.                   (((uint32) ((uchar) (A)[1])) << 16) |\\
  1383.                   (((uint32) ((uchar) (A)[0])) << 24))
  1384. /*
  1385.   Define-funktions for reading and storing in machine format from/to
  1386.   short/long to/from some place in memory V should be a (not
  1387.   register) variable, M is a pointer to byte
  1388. */
  1389.  
  1390. #ifdef WORDS_BIGENDIAN
  1391.  
  1392. #define ushortget(V,M)  do { V = (uint16) (((uint16) ((uchar) (M)[1]))+\\
  1393.                                  ((uint16) ((uint16) (M)[0]) << 8)); } while(0)
  1394. #define shortget(V,M)   do { V = (short) (((short) ((uchar) (M)[1]))+\\
  1395.                                  ((short) ((short) (M)[0]) << 8)); } while(0)
  1396. #define longget(V,M)    do { int32 def_temp;\\
  1397.                              ((uchar*) &def_temp)[0]=(M)[0];\\
  1398.                              ((uchar*) &def_temp)[1]=(M)[1];\\
  1399.                              ((uchar*) &def_temp)[2]=(M)[2];\\
  1400.                              ((uchar*) &def_temp)[3]=(M)[3];\\
  1401.                              (V)=def_temp; } while(0)
  1402. #define ulongget(V,M)   do { uint32 def_temp;\\
  1403.                             ((uchar*) &def_temp)[0]=(M)[0];\\
  1404.                             ((uchar*) &def_temp)[1]=(M)[1];\\
  1405.                             ((uchar*) &def_temp)[2]=(M)[2];\\
  1406.                             ((uchar*) &def_temp)[3]=(M)[3];\\
  1407.                             (V)=def_temp; } while(0)
  1408. #define shortstore(T,A) do { uint def_temp=(uint) (A) ;\\
  1409.                              *(((char*)T)+1)=(char)(def_temp); \\
  1410.                              *(((char*)T)+0)=(char)(def_temp >> 8); } while(0)
  1411. #define longstore(T,A)  do { *(((char*)T)+3)=((A));\\
  1412.                              *(((char*)T)+2)=(((A) >> 8));\\
  1413.                              *(((char*)T)+1)=(((A) >> 16));\\
  1414.                              *(((char*)T)+0)=(((A) >> 24)); } while(0)
  1415.  
  1416. #define floatget(V,M)    memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(float))
  1417. #define floatstore(T,V)  memcpy_fixed((uchar*) (T),(uchar*)(&V),sizeof(float))
  1418. #define doubleget(V,M)   memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(double))
  1419. #define doublestore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(double))
  1420. #define longlongget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(ulonglong))
  1421. #define longlongstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(ulonglong))
  1422.  
  1423. #else
  1424.  
  1425. #define ushortget(V,M)  do { V = uint2korr(M); } while(0)
  1426. #define shortget(V,M)   do { V = sint2korr(M); } while(0)
  1427. #define longget(V,M)    do { V = sint4korr(M); } while(0)
  1428. #define ulongget(V,M)   do { V = uint4korr(M); } while(0)
  1429. #define shortstore(T,V) int2store(T,V)
  1430. #define longstore(T,V)  int4store(T,V)
  1431. #ifndef floatstore
  1432. #define floatstore(T,V)  memcpy_fixed((uchar*) (T),(uchar*) (&V),sizeof(float))
  1433. #define floatget(V,M)    memcpy_fixed((uchar*) &V, (uchar*) (M), sizeof(float))
  1434. #endif
  1435. #ifndef doubleget
  1436. #define doubleget(V,M)   memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(double))
  1437. #define doublestore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(double))
  1438. #endif /* doubleget */
  1439. #define longlongget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(ulonglong))
  1440. #define longlongstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(ulonglong))
  1441.  
  1442. #endif /* WORDS_BIGENDIAN */
  1443.  
  1444. /* sprintf does not always return the number of bytes :- */
  1445. #ifdef SPRINTF_RETURNS_INT
  1446. #define my_sprintf(buff,args) sprintf args
  1447. #else
  1448. #ifdef SPRINTF_RETURNS_PTR
  1449. #define my_sprintf(buff,args) ((int)(sprintf args - buff))
  1450. #else
  1451. #define my_sprintf(buff,args) ((ulong) sprintf args, (ulong) strlen(buff))
  1452. #endif
  1453. #endif
  1454.  
  1455. #ifndef THREAD
  1456. #define thread_safe_increment(V,L) (V)++
  1457. #define thread_safe_decrement(V,L) (V)--
  1458. #define thread_safe_add(V,C,L)     (V)+=(C)
  1459. #define thread_safe_sub(V,C,L)     (V)-=(C)
  1460. #define statistic_increment(V,L)   (V)++
  1461. #define statistic_decrement(V,L)   (V)--
  1462. #define statistic_add(V,C,L)       (V)+=(C)
  1463. #define statistic_sub(V,C,L)       (V)-=(C)
  1464. #endif
  1465.  
  1466. #if defined(HAVE_CHARSET_utf8mb3) || defined(HAVE_CHARSET_utf8mb4)
  1467. #define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8"
  1468. #else
  1469. #define MYSQL_UNIVERSAL_CLIENT_CHARSET MYSQL_DEFAULT_CHARSET_NAME
  1470. #endif
  1471.  
  1472. #if defined(EMBEDDED_LIBRARY) && !defined(HAVE_EMBEDDED_PRIVILEGE_CONTROL)
  1473. #define NO_EMBEDDED_ACCESS_CHECKS
  1474. #endif
  1475.  
  1476. #ifdef HAVE_DLOPEN
  1477. #if defined(__WIN__)
  1478. #define dlsym(lib, name) GetProcAddress((HMODULE)lib, name)
  1479. #define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0)
  1480. #define dlclose(lib) FreeLibrary((HMODULE)lib)
  1481. #elif defined(HAVE_DLFCN_H)
  1482. #include <dlfcn.h>
  1483. #endif
  1484. #endif
  1485.  
  1486. /* FreeBSD 2.2.2 does not define RTLD_NOW) */
  1487. #ifndef RTLD_NOW
  1488. #define RTLD_NOW 1
  1489. #endif
  1490.  
  1491. #ifndef HAVE_DLERROR
  1492. #define dlerror() ""
  1493. #endif
  1494.  
  1495.  
  1496. #ifndef __NETWARE__
  1497. /*
  1498.  *  Include standard definitions of operator new and delete.
  1499.  */
  1500. #ifdef __cplusplus
  1501. #include <new>
  1502. #endif
  1503. #else
  1504. /*
  1505.  *  Define placement versions of operator new and operator delete since
  1506.  *  we don\'t have <new> when building for Netware.
  1507.  */
  1508. #ifdef __cplusplus
  1509. inline void *operator new(size_t, void *ptr) { return ptr; }
  1510. inline void *operator new[](size_t, void *ptr) { return ptr; }
  1511. inline void  operator delete(void*, void*) { /* Do nothing */ }
  1512. inline void  operator delete[](void*, void*) { /* Do nothing */ }
  1513. #endif
  1514. #endif
  1515.  
  1516. /* Length of decimal number represented by INT32. */
  1517. #define MY_INT32_NUM_DECIMAL_DIGITS 11
  1518.  
  1519. /* Length of decimal number represented by INT64. */
  1520. #define MY_INT64_NUM_DECIMAL_DIGITS 21
  1521.  
  1522. /* Define some useful general macros (should be done after all headers). */
  1523. #if !defined(max)
  1524. #define max(a, b)   ((a) > (b) ? (a) : (b))
  1525. #define min(a, b)   ((a) < (b) ? (a) : (b))
  1526. #endif
  1527. /*
  1528.   Only Linux is known to need an explicit sync of the directory to make sure a
  1529.   file creation/deletion/renaming in(from,to) this directory durable.
  1530. */
  1531. #ifdef TARGET_OS_LINUX
  1532. #define NEED_EXPLICIT_SYNC_DIR 1
  1533. #else
  1534. /*
  1535.   On linux default rwlock scheduling policy is good enough for
  1536.   waiting_threads.c, on other systems use our special implementation
  1537.   (which is slower).
  1538.  
  1539.   QQ perhaps this should be tested in configure ? how ?
  1540. */
  1541. #define WT_RWLOCKS_USE_MUTEXES 1
  1542. #endif
  1543.  
  1544. #if !defined(__cplusplus) && !defined(bool)
  1545. #define bool In_C_you_should_use_my_bool_instead()
  1546. #endif
  1547.  
  1548. /* Provide __func__ macro definition for platforms that miss it. */
  1549. #if __STDC_VERSION__ < 199901L
  1550. #  if __GNUC__ >= 2
  1551. #    define __func__ __FUNCTION__
  1552. #  else
  1553. #    define __func__ "<unknown>"
  1554. #  endif
  1555. #elif defined(_MSC_VER)
  1556. #  if _MSC_VER < 1300
  1557. #    define __func__ "<unknown>"
  1558. #  else
  1559. #    define __func__ __FUNCTION__
  1560. #  endif
  1561. #elif defined(__BORLANDC__)
  1562. #  define __func__ __FUNC__
  1563. #else
  1564. #  define __func__ "<unknown>"
  1565. #endif
  1566.  
  1567. #ifndef HAVE_RINT
  1568. /**
  1569.   All integers up to this number can be represented exactly as double precision
  1570.   values (DBL_MANT_DIG == 53 for IEEE 754 hardware).
  1571. */
  1572. #define MAX_EXACT_INTEGER ((1LL << DBL_MANT_DIG) - 1)
  1573.  
  1574. /**
  1575.   rint(3) implementation for platforms that do not have it.
  1576.   Always rounds to the nearest integer with ties being rounded to the nearest
  1577.   even integer to mimic glibc\'s rint() behavior in the "round-to-nearest"
  1578.   FPU mode. Hardware-specific optimizations are possible (frndint on x86).
  1579.   Unlike this implementation, hardware will also honor the FPU rounding mode.
  1580. */
  1581.  
  1582. static inline double rint(double x)
  1583. {
  1584.   double f, i;
  1585.   f = modf(x, &i);
  1586.  
  1587.   /*
  1588.     All doubles with absolute values > MAX_EXACT_INTEGER are even anyway,
  1589.     no need to check it.
  1590.   */
  1591.   if (x > 0.0)
  1592.     i += (double) ((f > 0.5) || (f == 0.5 &&
  1593.                                  i <= (double) MAX_EXACT_INTEGER &&
  1594.                                  (longlong) i % 2));
  1595.   else
  1596.     i -= (double) ((f < -0.5) || (f == -0.5 &&
  1597.                                   i >= (double) -MAX_EXACT_INTEGER &&
  1598.                                   (longlong) i % 2));
  1599.   return i;
  1600. }
  1601. #endif /* HAVE_RINT */
  1602.  
  1603. /*
  1604.   MYSQL_PLUGIN_IMPORT macro is used to export mysqld data
  1605.   (i.e variables) for usage in storage engine loadable plugins.
  1606.   Outside of Windows, it is dummy.
  1607. */
  1608. #ifndef MYSQL_PLUGIN_IMPORT
  1609. #if (defined(_WIN32) && defined(MYSQL_DYNAMIC_PLUGIN))
  1610. #define MYSQL_PLUGIN_IMPORT __declspec(dllimport)
  1611. #else
  1612. #define MYSQL_PLUGIN_IMPORT
  1613. #endif
  1614. #endif
  1615.  
  1616. #endif /* my_global_h */
');