PageRenderTime 67ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/External/Mysql-5.0/include/my_global.h

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