PageRenderTime 32ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/mysql/include/mysql/my_global.h

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