MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
my_global.h
1 /*
2  Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16 
17 #ifndef MY_GLOBAL_INCLUDED
18 #define MY_GLOBAL_INCLUDED
19 
20 /* This is the include file that should be included 'first' in every C file. */
21 
22 /* Client library users on Windows need this macro defined here. */
23 #if !defined(__WIN__) && defined(_WIN32)
24 #define __WIN__
25 #endif
26 
27 /*
28  InnoDB depends on some MySQL internals which other plugins should not
29  need. This is because of InnoDB's foreign key support, "safe" binlog
30  truncation, and other similar legacy features.
31 
32  We define accessors for these internals unconditionally, but do not
33  expose them in mysql/plugin.h. They are declared in ha_innodb.h for
34  InnoDB's use.
35 */
36 #define INNODB_COMPATIBILITY_HOOKS
37 
38 #ifdef __CYGWIN__
39 /* We use a Unix API, so pretend it's not Windows */
40 #undef WIN
41 #undef WIN32
42 #undef _WIN
43 #undef _WIN32
44 #undef _WIN64
45 #undef __WIN__
46 #undef __WIN32__
47 #define HAVE_ERRNO_AS_DEFINE
48 #endif /* __CYGWIN__ */
49 
50 #if defined(i386) && !defined(__i386__)
51 #define __i386__
52 #endif
53 
54 /* Macros to make switching between C and C++ mode easier */
55 #ifdef __cplusplus
56 #define C_MODE_START extern "C" {
57 #define C_MODE_END }
58 #else
59 #define C_MODE_START
60 #define C_MODE_END
61 #endif
62 
63 #ifdef __cplusplus
64 #define CPP_UNNAMED_NS_START namespace {
65 #define CPP_UNNAMED_NS_END }
66 #endif
67 
68 #include <my_config.h>
69 
70 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
71 #define HAVE_PSI_INTERFACE
72 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
73 
74 /* Make it easier to add conditional code in _expressions_ */
75 #ifdef __WIN__
76 #define IF_WIN(A,B) A
77 #else
78 #define IF_WIN(A,B) B
79 #endif
80 
81 #ifdef HAVE_purify
82 #define IF_PURIFY(A,B) A
83 #else
84 #define IF_PURIFY(A,B) B
85 #endif
86 
87 #ifndef EMBEDDED_LIBRARY
88 #ifdef WITH_NDB_BINLOG
89 #define HAVE_NDB_BINLOG 1
90 #endif
91 #endif /* !EMBEDDED_LIBRARY */
92 
93 #ifndef EMBEDDED_LIBRARY
94 #define HAVE_REPLICATION
95 #define HAVE_EXTERNAL_CLIENT
96 #endif
97 
98 #if defined (_WIN32)
99 /*
100  off_t is 32 bit long. We do not use C runtime functions
101  with off_t but native Win32 file IO APIs, that work with
102  64 bit offsets.
103 */
104 #undef SIZEOF_OFF_T
105 #define SIZEOF_OFF_T 8
106 
107 /*
108  Prevent inclusion of Windows GDI headers - they define symbol
109  ERROR that conflicts with mysql headers.
110 */
111 #ifndef NOGDI
112 #define NOGDI
113 #endif
114 
115 /* Include common headers.*/
116 #include <winsock2.h>
117 #include <ws2tcpip.h> /* SOCKET */
118 #include <io.h> /* access(), chmod() */
119 #include <process.h> /* getpid() */
120 
121 #define sleep(a) Sleep((a)*1000)
122 
123 /* Define missing access() modes. */
124 #define F_OK 0
125 #define W_OK 2
126 #define R_OK 4 /* Test for read permission. */
127 
128 /* Define missing file locking constants. */
129 #define F_RDLCK 1
130 #define F_WRLCK 2
131 #define F_UNLCK 3
132 #define F_TO_EOF 0x3FFFFFFF
133 
134 /* Shared memory and named pipe connections are supported. */
135 #define HAVE_SMEM 1
136 #define HAVE_NAMED_PIPE 1
137 #define shared_memory_buffer_length 16000
138 #define default_shared_memory_base_name "MYSQL"
139 #endif /* _WIN32*/
140 
141 
142 /* Workaround for _LARGE_FILES and _LARGE_FILE_API incompatibility on AIX */
143 #if defined(_AIX) && defined(_LARGE_FILE_API)
144 #undef _LARGE_FILE_API
145 #endif
146 
147 /*
148  The macros below are used to allow build of Universal/fat binaries of
149  MySQL and MySQL applications under darwin.
150 */
151 #if defined(__APPLE__) && defined(__MACH__)
152 # undef SIZEOF_CHARP
153 # undef SIZEOF_SHORT
154 # undef SIZEOF_INT
155 # undef SIZEOF_LONG
156 # undef SIZEOF_LONG_LONG
157 # undef SIZEOF_OFF_T
158 # undef WORDS_BIGENDIAN
159 # define SIZEOF_SHORT 2
160 # define SIZEOF_INT 4
161 # define SIZEOF_LONG_LONG 8
162 # define SIZEOF_OFF_T 8
163 # if defined(__i386__) || defined(__ppc__)
164 # define SIZEOF_CHARP 4
165 # define SIZEOF_LONG 4
166 # elif defined(__x86_64__) || defined(__ppc64__)
167 # define SIZEOF_CHARP 8
168 # define SIZEOF_LONG 8
169 # else
170 # error Building FAT binary for an unknown architecture.
171 # endif
172 # if defined(__ppc__) || defined(__ppc64__)
173 # define WORDS_BIGENDIAN
174 # endif
175 #endif /* defined(__APPLE__) && defined(__MACH__) */
176 
177 
178 /*
179  The macros below are borrowed from include/linux/compiler.h in the
180  Linux kernel. Use them to indicate the likelyhood of the truthfulness
181  of a condition. This serves two purposes - newer versions of gcc will be
182  able to optimize for branch predication, which could yield siginficant
183  performance gains in frequently executed sections of the code, and the
184  other reason to use them is for documentation
185 */
186 
187 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
188 #define __builtin_expect(x, expected_value) (x)
189 #endif
190 
191 #define likely(x) __builtin_expect((x),1)
192 #define unlikely(x) __builtin_expect((x),0)
193 
194 /* Fix problem with S_ISLNK() on Linux */
195 #if defined(TARGET_OS_LINUX) || defined(__GLIBC__)
196 #undef _GNU_SOURCE
197 #define _GNU_SOURCE 1
198 #endif
199 
200 /*
201  Temporary solution to solve bug#7156. Include "sys/types.h" before
202  the thread headers, else the function madvise() will not be defined
203 */
204 #if defined(HAVE_SYS_TYPES_H) && ( defined(sun) || defined(__sun) )
205 #include <sys/types.h>
206 #endif
207 
208 #ifdef HAVE_THREADS_WITHOUT_SOCKETS
209 /* MIT pthreads does not work with unix sockets */
210 #undef HAVE_SYS_UN_H
211 #endif
212 
213 #define __EXTENSIONS__ 1 /* We want some extension */
214 #ifndef __STDC_EXT__
215 #define __STDC_EXT__ 1 /* To get large file support on hpux */
216 #endif
217 
218 /*
219  Solaris 9 include file <sys/feature_tests.h> refers to X/Open document
220 
221  System Interfaces and Headers, Issue 5
222 
223  saying we should define _XOPEN_SOURCE=500 to get POSIX.1c prototypes,
224  but apparently other systems (namely FreeBSD) don't agree.
225 
226  On a newer Solaris 10, the above file recognizes also _XOPEN_SOURCE=600.
227  Furthermore, it tests that if a program requires older standard
228  (_XOPEN_SOURCE<600 or _POSIX_C_SOURCE<200112L) it cannot be
229  run on a new compiler (that defines _STDC_C99) and issues an #error.
230  It's also an #error if a program requires new standard (_XOPEN_SOURCE=600
231  or _POSIX_C_SOURCE=200112L) and a compiler does not define _STDC_C99.
232 
233  To add more to this mess, Sun Studio C compiler defines _STDC_C99 while
234  C++ compiler does not!
235 
236  So, in a desperate attempt to get correct prototypes for both
237  C and C++ code, we define either _XOPEN_SOURCE=600 or _XOPEN_SOURCE=500
238  depending on the compiler's announced C standard support.
239 
240  Cleaner solutions are welcome.
241 */
242 #ifdef __sun
243 #if __STDC_VERSION__ - 0 >= 199901L
244 #define _XOPEN_SOURCE 600
245 #else
246 #define _XOPEN_SOURCE 500
247 #endif
248 #endif
249 
250 #if !defined(__WIN__)
251 #ifndef _POSIX_PTHREAD_SEMANTICS
252 #define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */
253 #endif
254 
255 #if !defined(SCO)
256 #define _REENTRANT 1 /* Some thread libraries require this */
257 #endif
258 #if !defined(_THREAD_SAFE) && !defined(_AIX)
259 #define _THREAD_SAFE /* Required for OSF1 */
260 #endif
261 #if defined(HPUX10) || defined(HPUX11)
262 C_MODE_START /* HPUX needs this, signal.h bug */
263 #include <pthread.h>
264 C_MODE_END
265 #else
266 #include <pthread.h> /* AIX must have this included first */
267 #endif
268 #if !defined(SCO) && !defined(_REENTRANT)
269 #define _REENTRANT 1 /* Threads requires reentrant code */
270 #endif
271 #endif /* !defined(__WIN__) */
272 
273 /* Go around some bugs in different OS and compilers */
274 #ifdef _AIX /* By soren@t.dk */
275 #define _H_STRINGS
276 #define _SYS_STREAM_H
277 /* #define _AIX32_CURSES */ /* XXX: this breaks AIX 4.3.3 (others?). */
278 #define ulonglong2double(A) my_ulonglong2double(A)
279 #define my_off_t2double(A) my_ulonglong2double(A)
280 C_MODE_START
281 inline double my_ulonglong2double(unsigned long long A) { return (double A); }
282 C_MODE_END
283 #endif /* _AIX */
284 
285 #ifdef HAVE_BROKEN_SNPRINTF /* HPUX 10.20 don't have this defined */
286 #undef HAVE_SNPRINTF
287 #endif
288 #ifdef HAVE_BROKEN_PREAD
289 /*
290  pread()/pwrite() are not 64 bit safe on HP-UX 11.0 without
291  installing the kernel patch PHKL_20349 or greater
292 */
293 #undef HAVE_PREAD
294 #undef HAVE_PWRITE
295 #endif
296 
297 #ifdef UNDEF_HAVE_INITGROUPS /* For AIX 4.3 */
298 #undef HAVE_INITGROUPS
299 #endif
300 
301 #if defined(_lint) && !defined(lint)
302 #define lint
303 #endif
304 #if SIZEOF_LONG_LONG > 4 && !defined(_LONG_LONG)
305 #define _LONG_LONG 1 /* For AIX string library */
306 #endif
307 
308 #ifndef stdin
309 #include <stdio.h>
310 #endif
311 #include <stdarg.h>
312 #ifdef HAVE_STDLIB_H
313 #include <stdlib.h>
314 #endif
315 #ifdef HAVE_STDDEF_H
316 #include <stddef.h>
317 #endif
318 
319 #include <math.h>
320 #ifdef HAVE_LIMITS_H
321 #include <limits.h>
322 #endif
323 #ifdef HAVE_FLOAT_H
324 #include <float.h>
325 #endif
326 #ifdef HAVE_FENV_H
327 #include <fenv.h> /* For fesetround() */
328 #endif
329 
330 #ifdef HAVE_SYS_TYPES_H
331 #include <sys/types.h>
332 #endif
333 #ifdef HAVE_FCNTL_H
334 #include <fcntl.h>
335 #endif
336 #ifdef HAVE_SYS_TIMEB_H
337 #include <sys/timeb.h> /* Avoid warnings on SCO */
338 #endif
339 #if TIME_WITH_SYS_TIME
340 # include <sys/time.h>
341 # include <time.h>
342 #else
343 # if HAVE_SYS_TIME_H
344 # include <sys/time.h>
345 # else
346 # include <time.h>
347 # endif
348 #endif /* TIME_WITH_SYS_TIME */
349 #ifdef HAVE_UNISTD_H
350 #include <unistd.h>
351 #endif
352 #if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA)
353 #undef HAVE_ALLOCA
354 #undef HAVE_ALLOCA_H
355 #endif
356 #ifdef HAVE_ALLOCA_H
357 #include <alloca.h>
358 #endif
359 
360 #include <errno.h> /* Recommended by debian */
361 /* We need the following to go around a problem with openssl on solaris */
362 #if defined(HAVE_CRYPT_H)
363 #include <crypt.h>
364 #endif
365 
366 /*
367  A lot of our programs uses asserts, so better to always include it
368  This also fixes a problem when people uses DBUG_ASSERT without including
369  assert.h
370 */
371 #include <assert.h>
372 
373 /* an assert that works at compile-time. only for constant expression */
374 #ifdef _some_old_compiler_that_does_not_understand_the_construct_below_
375 #define compile_time_assert(X) do { } while(0)
376 #else
377 #define compile_time_assert(X) \
378  do \
379  { \
380  typedef char compile_time_assert[(X) ? 1 : -1] __attribute__((unused)); \
381  } while(0)
382 #endif
383 
384 /* Go around some bugs in different OS and compilers */
385 #if defined (HPUX11) && defined(_LARGEFILE_SOURCE)
386 #ifndef _LARGEFILE64_SOURCE
387 #define _LARGEFILE64_SOURCE
388 #endif
389 #endif
390 
391 #if defined(_HPUX_SOURCE) && defined(HAVE_SYS_STREAM_H)
392 #include <sys/stream.h> /* HPUX 10.20 defines ulong here. UGLY !!! */
393 #define HAVE_ULONG
394 #endif
395 #if defined(HPUX10) && defined(_LARGEFILE64_SOURCE)
396 /* Fix bug in setrlimit */
397 #undef setrlimit
398 #define setrlimit cma_setrlimit64
399 #endif
400 /* Declare madvise where it is not declared for C++, like Solaris */
401 #if HAVE_MADVISE && !HAVE_DECL_MADVISE && defined(__cplusplus)
402 extern "C" int madvise(void *addr, size_t len, int behav);
403 #endif
404 
405 #define QUOTE_ARG(x) #x /* Quote argument (before cpp) */
406 #define STRINGIFY_ARG(x) QUOTE_ARG(x) /* Quote argument, after cpp */
407 
408 /* Paranoid settings. Define I_AM_PARANOID if you are paranoid */
409 #ifdef I_AM_PARANOID
410 #define DONT_ALLOW_USER_CHANGE 1
411 #define DONT_USE_MYSQL_PWD 1
412 #endif
413 
414 /* Does the system remember a signal handler after a signal ? */
415 #if !defined(HAVE_BSD_SIGNALS) && !defined(HAVE_SIGACTION)
416 #define SIGNAL_HANDLER_RESET_ON_DELIVERY
417 #endif
418 
419 /*
420  Deprecated workaround for false-positive uninitialized variables
421  warnings. Those should be silenced using tool-specific heuristics.
422 
423  Enabled by default for g++ due to the bug referenced below.
424 */
425 #if defined(_lint) || defined(FORCE_INIT_OF_VARS) || \
426  (defined(__GNUC__) && defined(__cplusplus))
427 #define LINT_INIT(var) var= 0
428 #else
429 #define LINT_INIT(var)
430 #endif
431 
432 #ifndef SO_EXT
433 #ifdef _WIN32
434 #define SO_EXT ".dll"
435 #elif defined(__APPLE__)
436 #define SO_EXT ".dylib"
437 #else
438 #define SO_EXT ".so"
439 #endif
440 #endif
441 
442 /*
443  Suppress uninitialized variable warning without generating code.
444 
445  The _cplusplus is a temporary workaround for C++ code pending a fix
446  for a g++ bug (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34772).
447 */
448 #if defined(_lint) || defined(FORCE_INIT_OF_VARS) || \
449  defined(__cplusplus) || !defined(__GNUC__)
450 #define UNINIT_VAR(x) x= 0
451 #else
452 /* GCC specific self-initialization which inhibits the warning. */
453 #define UNINIT_VAR(x) x= x
454 #endif
455 
456 #if !defined(HAVE_UINT)
457 #undef HAVE_UINT
458 #define HAVE_UINT
459 typedef unsigned int uint;
460 typedef unsigned short ushort;
461 #endif
462 
463 #define swap_variables(t, a, b) { t dummy; dummy= a; a= b; b= dummy; }
464 #define test(a) ((a) ? 1 : 0)
465 #define set_if_bigger(a,b) do { if ((a) < (b)) (a)=(b); } while(0)
466 #define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
467 #define test_all_bits(a,b) (((a) & (b)) == (b))
468 #define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0])))
469 
470 /* Define some general constants */
471 #ifndef TRUE
472 #define TRUE (1) /* Logical true */
473 #define FALSE (0) /* Logical false */
474 #endif
475 
476 #include <my_compiler.h>
477 
478 /* The DBUG_ON flag always takes precedence over default DBUG_OFF */
479 #if defined(DBUG_ON) && defined(DBUG_OFF)
480 #undef DBUG_OFF
481 #endif
482 
483 /* We might be forced to turn debug off, if not turned off already */
484 #if (defined(FORCE_DBUG_OFF) || defined(_lint)) && !defined(DBUG_OFF)
485 # define DBUG_OFF
486 # ifdef DBUG_ON
487 # undef DBUG_ON
488 # endif
489 #endif
490 
491 /* Some types that is different between systems */
492 
493 typedef int File; /* File descriptor */
494 #ifdef _WIN32
495 typedef SOCKET my_socket;
496 #else
497 typedef int my_socket; /* File descriptor for sockets */
498 #define INVALID_SOCKET -1
499 #endif
500 /* Type for fuctions that handles signals */
501 #define sig_handler RETSIGTYPE
502 C_MODE_START
503 typedef void (*sig_return)();/* Returns type from signal */
504 C_MODE_END
505 #if defined(__GNUC__) && !defined(_lint)
506 typedef char pchar; /* Mixed prototypes can take char */
507 typedef char puchar; /* Mixed prototypes can take char */
508 typedef char pbool; /* Mixed prototypes can take char */
509 typedef short pshort; /* Mixed prototypes can take short int */
510 typedef float pfloat; /* Mixed prototypes can take float */
511 #else
512 typedef int pchar; /* Mixed prototypes can't take char */
513 typedef uint puchar; /* Mixed prototypes can't take char */
514 typedef int pbool; /* Mixed prototypes can't take char */
515 typedef int pshort; /* Mixed prototypes can't take short int */
516 typedef double pfloat; /* Mixed prototypes can't take float */
517 #endif
518 C_MODE_START
519 typedef int (*qsort_cmp)(const void *,const void *);
520 typedef int (*qsort_cmp2)(const void*, const void *,const void *);
521 C_MODE_END
522 #define qsort_t RETQSORTTYPE /* Broken GCC cant handle typedef !!!! */
523 #ifdef HAVE_SYS_SOCKET_H
524 #include <sys/socket.h>
525 #endif
526 typedef SOCKET_SIZE_TYPE size_socket;
527 
528 #ifndef SOCKOPT_OPTLEN_TYPE
529 #define SOCKOPT_OPTLEN_TYPE size_socket
530 #endif
531 
532 /* file create flags */
533 
534 #ifndef O_SHARE /* Probably not windows */
535 #define O_SHARE 0 /* Flag to my_open for shared files */
536 #ifndef O_BINARY
537 #define O_BINARY 0 /* Flag to my_open for binary files */
538 #endif
539 #ifndef FILE_BINARY
540 #define FILE_BINARY O_BINARY /* Flag to my_fopen for binary streams */
541 #endif
542 #ifdef HAVE_FCNTL
543 #define HAVE_FCNTL_LOCK
544 #define F_TO_EOF 0L /* Param to lockf() to lock rest of file */
545 #endif
546 #endif /* O_SHARE */
547 
548 #ifndef O_TEMPORARY
549 #define O_TEMPORARY 0
550 #endif
551 #ifndef O_SHORT_LIVED
552 #define O_SHORT_LIVED 0
553 #endif
554 #ifndef O_NOFOLLOW
555 #define O_NOFOLLOW 0
556 #endif
557 
558 /* additional file share flags for win32 */
559 #ifdef __WIN__
560 #define _SH_DENYRWD 0x110 /* deny read/write mode & delete */
561 #define _SH_DENYWRD 0x120 /* deny write mode & delete */
562 #define _SH_DENYRDD 0x130 /* deny read mode & delete */
563 #define _SH_DENYDEL 0x140 /* deny delete only */
564 #endif /* __WIN__ */
565 
566 
567 /* General constants */
568 #define FN_LEN 256 /* Max file name len */
569 #define FN_HEADLEN 253 /* Max length of filepart of file name */
570 #define FN_EXTLEN 20 /* Max length of extension (part of FN_LEN) */
571 #define FN_REFLEN 512 /* Max length of full path-name */
572 #define FN_EXTCHAR '.'
573 #define FN_HOMELIB '~' /* ~/ is used as abbrev for home dir */
574 #define FN_CURLIB '.' /* ./ is used as abbrev for current dir */
575 #define FN_PARENTDIR ".." /* Parent directory; Must be a string */
576 
577 #ifdef _WIN32
578 #define FN_LIBCHAR '\\'
579 #define FN_LIBCHAR2 '/'
580 #define FN_DIRSEP "/\\" /* Valid directory separators */
581 #define FN_EXEEXT ".exe"
582 #define FN_SOEXT ".dll"
583 #define FN_ROOTDIR "\\"
584 #define FN_DEVCHAR ':'
585 #define FN_NETWORK_DRIVES /* Uses \\ to indicate network drives */
586 #define FN_NO_CASE_SENCE /* Files are not case-sensitive */
587 #else
588 #define FN_LIBCHAR '/'
589 #define FN_LIBCHAR2 '/'
590 #define FN_DIRSEP "/" /* Valid directory separators */
591 #define FN_EXEEXT ""
592 #define FN_SOEXT ".so"
593 #define FN_ROOTDIR "/"
594 #endif
595 
596 /*
597  MY_FILE_MIN is Windows speciality and is used to quickly detect
598  the mismatch of CRT and mysys file IO usage on Windows at runtime.
599  CRT file descriptors can be in the range 0-2047, whereas descriptors returned
600  by my_open() will start with 2048. If a file descriptor with value less then
601  MY_FILE_MIN is passed to mysys IO function, chances are it stemms from
602  open()/fileno() and not my_open()/my_fileno.
603 
604  For Posix, mysys functions are light wrappers around libc, and MY_FILE_MIN
605  is logically 0.
606 */
607 
608 #ifdef _WIN32
609 #define MY_FILE_MIN 2048
610 #else
611 #define MY_FILE_MIN 0
612 #endif
613 
614 /*
615  MY_NFILE is the default size of my_file_info array.
616 
617  It is larger on Windows, because it all file handles are stored in my_file_info
618  Default size is 16384 and this should be enough for most cases.If it is not
619  enough, --max-open-files with larger value can be used.
620 
621  For Posix , my_file_info array is only used to store filenames for
622  error reporting and its size is not a limitation for number of open files.
623 */
624 #ifdef _WIN32
625 #define MY_NFILE (16384 + MY_FILE_MIN)
626 #else
627 #define MY_NFILE 64
628 #endif
629 
630 #ifndef OS_FILE_LIMIT
631 #define OS_FILE_LIMIT UINT_MAX
632 #endif
633 
634 /*
635  Io buffer size; Must be a power of 2 and a multiple of 512. May be
636  smaller what the disk page size. This influences the speed of the
637  isam btree library. eg to big to slow.
638 */
639 #define IO_SIZE 4096
640 /*
641  How much overhead does malloc have. The code often allocates
642  something like 1024-MALLOC_OVERHEAD bytes
643 */
644 #define MALLOC_OVERHEAD 8
645 
646  /* get memory in huncs */
647 #define ONCE_ALLOC_INIT (uint) (4096-MALLOC_OVERHEAD)
648  /* Typical record cash */
649 #define RECORD_CACHE_SIZE (uint) (64*1024-MALLOC_OVERHEAD)
650  /* Typical key cash */
651 #define KEY_CACHE_SIZE (uint) (8*1024*1024)
652  /* Default size of a key cache block */
653 #define KEY_CACHE_BLOCK_SIZE (uint) 1024
654 
655 
656  /* Some things that this system doesn't have */
657 
658 #ifdef _WIN32
659 #define NO_DIR_LIBRARY /* Not standard dir-library */
660 #endif
661 
662 /* Some defines of functions for portability */
663 
664 #undef remove /* Crashes MySQL on SCO 5.0.0 */
665 #ifndef __WIN__
666 #define closesocket(A) close(A)
667 #endif
668 
669 #if (_MSC_VER)
670 #if !defined(_WIN64)
671 inline double my_ulonglong2double(unsigned long long value)
672 {
673  long long nr=(long long) value;
674  if (nr >= 0)
675  return (double) nr;
676  return (18446744073709551616.0 + (double) nr);
677 }
678 #define ulonglong2double my_ulonglong2double
679 #define my_off_t2double my_ulonglong2double
680 #endif /* _WIN64 */
681 inline unsigned long long my_double2ulonglong(double d)
682 {
683  double t= d - (double) 0x8000000000000000ULL;
684 
685  if (t >= 0)
686  return ((unsigned long long) t) + 0x8000000000000000ULL;
687  return (unsigned long long) d;
688 }
689 #define double2ulonglong my_double2ulonglong
690 #endif
691 
692 #ifndef ulonglong2double
693 #define ulonglong2double(A) ((double) (ulonglong) (A))
694 #define my_off_t2double(A) ((double) (my_off_t) (A))
695 #endif
696 #ifndef double2ulonglong
697 #define double2ulonglong(A) ((ulonglong) (double) (A))
698 #endif
699 
700 #ifndef offsetof
701 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
702 #endif
703 #define ulong_to_double(X) ((double) (ulong) (X))
704 
705 #ifndef STACK_DIRECTION
706 #error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
707 #endif
708 
709 #if !defined(HAVE_STRTOK_R)
710 #define strtok_r(A,B,C) strtok((A),(B))
711 #endif
712 
713 /* This is from the old m-machine.h file */
714 
715 #if SIZEOF_LONG_LONG > 4
716 #define HAVE_LONG_LONG 1
717 #endif
718 
719 /*
720  Some pre-ANSI-C99 systems like AIX 5.1 and Linux/GCC 2.95 define
721  ULONGLONG_MAX, LONGLONG_MIN, LONGLONG_MAX; we use them if they're defined.
722 */
723 
724 #if defined(HAVE_LONG_LONG) && !defined(LONGLONG_MIN)
725 #define LONGLONG_MIN ((long long) 0x8000000000000000LL)
726 #define LONGLONG_MAX ((long long) 0x7FFFFFFFFFFFFFFFLL)
727 #endif
728 
729 #if defined(HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)
730 /* First check for ANSI C99 definition: */
731 #ifdef ULLONG_MAX
732 #define ULONGLONG_MAX ULLONG_MAX
733 #else
734 #define ULONGLONG_MAX ((unsigned long long)(~0ULL))
735 #endif
736 #endif /* defined (HAVE_LONG_LONG) && !defined(ULONGLONG_MAX)*/
737 
738 #define INT_MIN64 (~0x7FFFFFFFFFFFFFFFLL)
739 #define INT_MAX64 0x7FFFFFFFFFFFFFFFLL
740 #define INT_MIN32 (~0x7FFFFFFFL)
741 #define INT_MAX32 0x7FFFFFFFL
742 #define UINT_MAX32 0xFFFFFFFFL
743 #define INT_MIN24 (~0x007FFFFF)
744 #define INT_MAX24 0x007FFFFF
745 #define UINT_MAX24 0x00FFFFFF
746 #define INT_MIN16 (~0x7FFF)
747 #define INT_MAX16 0x7FFF
748 #define UINT_MAX16 0xFFFF
749 #define INT_MIN8 (~0x7F)
750 #define INT_MAX8 0x7F
751 #define UINT_MAX8 0xFF
752 
753 /* From limits.h instead */
754 #ifndef DBL_MIN
755 #define DBL_MIN 4.94065645841246544e-324
756 #define FLT_MIN ((float)1.40129846432481707e-45)
757 #endif
758 #ifndef DBL_MAX
759 #define DBL_MAX 1.79769313486231470e+308
760 #define FLT_MAX ((float)3.40282346638528860e+38)
761 #endif
762 #ifndef SIZE_T_MAX
763 #define SIZE_T_MAX (~((size_t) 0))
764 #endif
765 
766 #ifndef isfinite
767 #ifdef HAVE_FINITE
768 #define isfinite(x) finite(x)
769 #else
770 #define finite(x) (1.0 / fabs(x) > 0.0)
771 #endif /* HAVE_FINITE */
772 #endif /* isfinite */
773 
774 #include <math.h>
775 #ifndef HAVE_ISNAN
776 #define isnan(x) ((x) != (x))
777 #endif
778 C_MODE_START
779 extern double my_double_isnan(double x);
780 C_MODE_END
781 
782 #ifdef HAVE_ISINF
783 /* Check if C compiler is affected by GCC bug #39228 */
784 #if !defined(__cplusplus) && defined(HAVE_BROKEN_ISINF)
785 /* Force store/reload of the argument to/from a 64-bit double */
786 static inline double my_isinf(double x)
787 {
788  volatile double t= x;
789  return isinf(t);
790 }
791 #else
792 /* System-provided isinf() is available and safe to use */
793 #define my_isinf(X) isinf(X)
794 #endif
795 #else /* !HAVE_ISINF */
796 #define my_isinf(X) (!finite(X) && !isnan(X))
797 #endif
798 
799 /* Define missing math constants. */
800 #ifndef M_PI
801 #define M_PI 3.14159265358979323846
802 #endif
803 #ifndef M_E
804 #define M_E 2.7182818284590452354
805 #endif
806 #ifndef M_LN2
807 #define M_LN2 0.69314718055994530942
808 #endif
809 
810 /*
811  Max size that must be added to a so that we know Size to make
812  adressable obj.
813 */
814 #if SIZEOF_CHARP == 4
815 typedef long my_ptrdiff_t;
816 #else
817 typedef long long my_ptrdiff_t;
818 #endif
819 
820 #define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
821 #define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double))
822 /* Size to make adressable obj. */
823 #define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size)
824 #define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B))
825 
826 /*
827  Custom version of standard offsetof() macro which can be used to get
828  offsets of members in class for non-POD types (according to the current
829  version of C++ standard offsetof() macro can't be used in such cases and
830  attempt to do so causes warnings to be emitted, OTOH in many cases it is
831  still OK to assume that all instances of the class has the same offsets
832  for the same members).
833 
834  This is temporary solution which should be removed once File_parser class
835  and related routines are refactored.
836 */
837 
838 #define my_offsetof(TYPE, MEMBER) \
839  ((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
840 
841 #define NullS (char *) 0
842 
843 #ifdef STDCALL
844 #undef STDCALL
845 #endif
846 
847 #ifdef _WIN32
848 #define STDCALL __stdcall
849 #else
850 #define STDCALL
851 #endif
852 
853 /* Typdefs for easyier portability */
854 
855 #ifndef HAVE_UCHAR
856 typedef unsigned char uchar; /* Short for unsigned char */
857 #endif
858 
859 #ifndef HAVE_INT8
860 typedef signed char int8; /* Signed integer >= 8 bits */
861 #endif
862 #ifndef HAVE_UINT8
863 typedef unsigned char uint8; /* Unsigned integer >= 8 bits */
864 #endif
865 #ifndef HAVE_INT16
866 typedef short int16;
867 #endif
868 #ifndef HAVE_UINT16
869 typedef unsigned short uint16;
870 #endif
871 #if SIZEOF_INT == 4
872 #ifndef HAVE_INT32
873 typedef int int32;
874 #endif
875 #ifndef HAVE_UINT32
876 typedef unsigned int uint32;
877 #endif
878 #elif SIZEOF_LONG == 4
879 #ifndef HAVE_INT32
880 typedef long int32;
881 #endif
882 #ifndef HAVE_UINT32
883 typedef unsigned long uint32;
884 #endif
885 #else
886 #error Neither int or long is of 4 bytes width
887 #endif
888 
889 #if !defined(HAVE_ULONG) && !defined(__USE_MISC)
890 typedef unsigned long ulong; /* Short for unsigned long */
891 #endif
892 #ifndef longlong_defined
893 /*
894  Using [unsigned] long long is preferable as [u]longlong because we use
895  [unsigned] long long unconditionally in many places,
896  for example in constants with [U]LL suffix.
897 */
898 #if defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == 8
899 typedef unsigned long long int ulonglong; /* ulong or unsigned long long */
900 typedef long long int longlong;
901 #else
902 typedef unsigned long ulonglong; /* ulong or unsigned long long */
903 typedef long longlong;
904 #endif
905 #endif
906 #ifndef HAVE_INT64
907 typedef longlong int64;
908 #endif
909 #ifndef HAVE_UINT64
910 typedef ulonglong uint64;
911 #endif
912 
913 #if defined(NO_CLIENT_LONG_LONG)
914 typedef unsigned long my_ulonglong;
915 #elif defined (__WIN__)
916 typedef unsigned __int64 my_ulonglong;
917 #else
918 typedef unsigned long long my_ulonglong;
919 #endif
920 
921 #if SIZEOF_CHARP == SIZEOF_INT
922 typedef int intptr;
923 #elif SIZEOF_CHARP == SIZEOF_LONG
924 typedef long intptr;
925 #elif SIZEOF_CHARP == SIZEOF_LONG_LONG
926 typedef long long intptr;
927 #else
928 #error sizeof(void *) is neither sizeof(int) nor sizeof(long) nor sizeof(long long)
929 #endif
930 
931 #define MY_ERRPTR ((void*)(intptr)1)
932 
933 #if defined(_WIN32)
934 typedef unsigned long long my_off_t;
935 typedef unsigned long long os_off_t;
936 #else
937 typedef off_t os_off_t;
938 #if SIZEOF_OFF_T > 4
939 typedef ulonglong my_off_t;
940 #else
941 typedef unsigned long my_off_t;
942 #endif
943 #endif /*_WIN32*/
944 #define MY_FILEPOS_ERROR (~(my_off_t) 0)
945 
946 /*
947  TODO Convert these to use Bitmap class.
948  */
949 typedef ulonglong table_map; /* Used for table bits in join */
950 typedef ulonglong nesting_map; /* Used for flags of nesting constructs */
951 
952 #if defined(__WIN__)
953 #define socket_errno WSAGetLastError()
954 #define SOCKET_EINTR WSAEINTR
955 #define SOCKET_EAGAIN WSAEINPROGRESS
956 #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
957 #define SOCKET_EADDRINUSE WSAEADDRINUSE
958 #define SOCKET_ETIMEDOUT WSAETIMEDOUT
959 #define SOCKET_ECONNRESET WSAECONNRESET
960 #define SOCKET_ENFILE ENFILE
961 #define SOCKET_EMFILE EMFILE
962 #else /* Unix */
963 #define socket_errno errno
964 #define closesocket(A) close(A)
965 #define SOCKET_EINTR EINTR
966 #define SOCKET_EAGAIN EAGAIN
967 #define SOCKET_EWOULDBLOCK EWOULDBLOCK
968 #define SOCKET_EADDRINUSE EADDRINUSE
969 #define SOCKET_ETIMEDOUT ETIMEDOUT
970 #define SOCKET_ECONNRESET ECONNRESET
971 #define SOCKET_ENFILE ENFILE
972 #define SOCKET_EMFILE EMFILE
973 #endif
974 
975 typedef int myf; /* Type of MyFlags in my_funcs */
976 typedef char my_bool; /* Small bool */
977 
978 /* Macros for converting *constants* to the right type */
979 #define MYF(v) (myf) (v)
980 
981 #ifndef LL
982 #ifdef HAVE_LONG_LONG
983 #define LL(A) A ## LL
984 #else
985 #define LL(A) A ## L
986 #endif
987 #endif
988 
989 #ifndef ULL
990 #ifdef HAVE_LONG_LONG
991 #define ULL(A) A ## ULL
992 #else
993 #define ULL(A) A ## UL
994 #endif
995 #endif
996 
997 /*
998  Defines to make it possible to prioritize register assignments. No
999  longer that important with modern compilers.
1000 */
1001 #ifndef USING_X
1002 #define reg1 register
1003 #define reg2 register
1004 #define reg3 register
1005 #define reg4 register
1006 #define reg5 register
1007 #define reg6 register
1008 #define reg7 register
1009 #define reg8 register
1010 #define reg9 register
1011 #define reg10 register
1012 #define reg11 register
1013 #define reg12 register
1014 #define reg13 register
1015 #define reg14 register
1016 #define reg15 register
1017 #define reg16 register
1018 #endif
1019 
1020 /* Some helper macros */
1021 #define YESNO(X) ((X) ? "yes" : "no")
1022 
1023 #define MY_HOW_OFTEN_TO_ALARM 2 /* How often we want info on screen */
1024 #define MY_HOW_OFTEN_TO_WRITE 1000 /* How often we want info on screen */
1025 
1026 #include <my_byteorder.h>
1027 
1028 #ifdef HAVE_CHARSET_utf8
1029 #define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8"
1030 #else
1031 #define MYSQL_UNIVERSAL_CLIENT_CHARSET MYSQL_DEFAULT_CHARSET_NAME
1032 #endif
1033 
1034 #if defined(EMBEDDED_LIBRARY) && !defined(HAVE_EMBEDDED_PRIVILEGE_CONTROL)
1035 #define NO_EMBEDDED_ACCESS_CHECKS
1036 #endif
1037 
1038 #if defined(_WIN32)
1039 #define dlsym(lib, name) (void*)GetProcAddress((HMODULE)lib, name)
1040 #define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0)
1041 #define dlclose(lib) FreeLibrary((HMODULE)lib)
1042 #ifndef HAVE_DLOPEN
1043 #define HAVE_DLOPEN
1044 #endif
1045 #endif
1046 
1047 #ifdef HAVE_DLOPEN
1048 #if defined(HAVE_DLFCN_H)
1049 #include <dlfcn.h>
1050 #endif
1051 #endif
1052 
1053 #ifndef HAVE_DLERROR
1054 #ifdef _WIN32
1055 #define DLERROR_GENERATE(errmsg, error_number) \
1056  char win_errormsg[2048]; \
1057  if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, \
1058  0, error_number, 0, win_errormsg, 2048, NULL)) \
1059  { \
1060  char *ptr; \
1061  for (ptr= &win_errormsg[0] + strlen(win_errormsg) - 1; \
1062  ptr >= &win_errormsg[0] && strchr("\r\n\t\0x20", *ptr); \
1063  ptr--) \
1064  *ptr= 0; \
1065  errmsg= win_errormsg; \
1066  } \
1067  else \
1068  errmsg= ""
1069 #define dlerror() ""
1070 #define dlopen_errno GetLastError()
1071 #else /* _WIN32 */
1072 #define dlerror() "No support for dynamic loading (static build?)"
1073 #define DLERROR_GENERATE(errmsg, error_number) errmsg= dlerror()
1074 #define dlopen_errno errno
1075 #endif /* _WIN32 */
1076 #else /* HAVE_DLERROR */
1077 #define DLERROR_GENERATE(errmsg, error_number) errmsg= dlerror()
1078 #define dlopen_errno errno
1079 #endif /* HAVE_DLERROR */
1080 
1081 
1082 /*
1083  * Include standard definitions of operator new and delete.
1084  */
1085 #ifdef __cplusplus
1086 #include <new>
1087 #endif
1088 
1089 /* Length of decimal number represented by INT32. */
1090 #define MY_INT32_NUM_DECIMAL_DIGITS 11U
1091 
1092 /* Length of decimal number represented by INT64. */
1093 #define MY_INT64_NUM_DECIMAL_DIGITS 21U
1094 
1095 /* Define some useful general macros (should be done after all headers). */
1096 #define MY_MAX(a, b) ((a) > (b) ? (a) : (b))
1097 #define MY_MIN(a, b) ((a) < (b) ? (a) : (b))
1098 
1099 /*
1100  Only Linux is known to need an explicit sync of the directory to make sure a
1101  file creation/deletion/renaming in(from,to) this directory durable.
1102 */
1103 #ifdef TARGET_OS_LINUX
1104 #define NEED_EXPLICIT_SYNC_DIR 1
1105 #else
1106 /*
1107  On linux default rwlock scheduling policy is good enough for
1108  waiting_threads.c, on other systems use our special implementation
1109  (which is slower).
1110 
1111  QQ perhaps this should be tested in configure ? how ?
1112 */
1113 #define WT_RWLOCKS_USE_MUTEXES 1
1114 #endif
1115 
1116 #if !defined(__cplusplus) && !defined(bool)
1117 #define bool In_C_you_should_use_my_bool_instead()
1118 #endif
1119 
1120 /* Provide __func__ macro definition for platforms that miss it. */
1121 #if __STDC_VERSION__ < 199901L
1122 # if __GNUC__ >= 2
1123 # define __func__ __FUNCTION__
1124 # else
1125 # define __func__ "<unknown>"
1126 # endif
1127 #elif defined(_MSC_VER)
1128 # if _MSC_VER < 1300
1129 # define __func__ "<unknown>"
1130 # else
1131 # define __func__ __FUNCTION__
1132 # endif
1133 #elif defined(__BORLANDC__)
1134 # define __func__ __FUNC__
1135 #else
1136 # define __func__ "<unknown>"
1137 #endif
1138 
1139 #ifndef HAVE_RINT
1140 
1144 #define MAX_EXACT_INTEGER ((1LL << DBL_MANT_DIG) - 1)
1145 
1154 static inline double rint(double x)
1155 {
1156  double f, i;
1157  f = modf(x, &i);
1158  /*
1159  All doubles with absolute values > MAX_EXACT_INTEGER are even anyway,
1160  no need to check it.
1161  */
1162  if (x > 0.0)
1163  i += (double) ((f > 0.5) || (f == 0.5 &&
1164  i <= (double) MAX_EXACT_INTEGER &&
1165  (longlong) i % 2));
1166  else
1167  i -= (double) ((f < -0.5) || (f == -0.5 &&
1168  i >= (double) -MAX_EXACT_INTEGER &&
1169  (longlong) i % 2));
1170  return i;
1171 }
1172 #endif /* HAVE_RINT */
1173 
1174 /*
1175  MYSQL_PLUGIN_IMPORT macro is used to export mysqld data
1176  (i.e variables) for usage in storage engine loadable plugins.
1177  Outside of Windows, it is dummy.
1178 */
1179 #ifndef MYSQL_PLUGIN_IMPORT
1180 #if (defined(_WIN32) && defined(MYSQL_DYNAMIC_PLUGIN))
1181 #define MYSQL_PLUGIN_IMPORT __declspec(dllimport)
1182 #else
1183 #define MYSQL_PLUGIN_IMPORT
1184 #endif
1185 #endif
1186 
1187 #include <my_dbug.h>
1188 
1189 /* Defines that are unique to the embedded version of MySQL */
1190 
1191 #ifdef EMBEDDED_LIBRARY
1192 
1193 /* Things we don't need in the embedded version of MySQL */
1194 /* TODO HF add #undef HAVE_VIO if we don't want client in embedded library */
1195 
1196 #undef HAVE_OPENSSL
1197 #undef HAVE_SMEM /* No shared memory */
1198 
1199 #endif /* EMBEDDED_LIBRARY */
1200 
1201 
1202 enum loglevel {
1203  ERROR_LEVEL= 0,
1204  WARNING_LEVEL= 1,
1205  INFORMATION_LEVEL= 2
1206 };
1207 
1208 
1209 /*
1210  Visual Studio before the version 2010 did not have lldiv_t.
1211  In Visual Studio 2010, _MSC_VER is defined as 1600.
1212 */
1213 #if defined(_MSC_VER) && (_MSC_VER < 1600)
1214 typedef struct
1215 {
1216  long long int quot; /* Quotient. */
1217  long long int rem; /* Remainder. */
1218 } lldiv_t;
1219 #endif
1220 
1221 #endif // MY_GLOBAL_INCLUDED