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