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