1
/* Copyright (C) 2000-2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* This is the include file that should be included 'first' in every C file. */
21
#define HAVE_REPLICATION
22
#define HAVE_EXTERNAL_CLIENT
25
InnoDB depends on some MySQL internals which other plugins should not
26
need. This is because of InnoDB's foreign key support, "safe" binlog
27
truncation, and other similar legacy features.
29
We define accessors for these internals unconditionally, but do not
30
expose them in mysql/plugin.h. They are declared in ha_innodb.h for
33
#define INNODB_COMPATIBILITY_HOOKS
35
/* to make command line shorter we'll define USE_PRAGMA_INTERFACE here */
36
#ifdef USE_PRAGMA_IMPLEMENTATION
37
#define USE_PRAGMA_INTERFACE
40
#if defined(i386) && !defined(__i386__)
44
/* Macros to make switching between C and C++ mode easier */
46
#define C_MODE_START extern "C" {
54
#if defined(__cplusplus) && defined(inline)
55
#undef inline /* fix configure problem */
58
/* Make it easier to add conditionl code for windows */
59
#define IF_WIN(A,B) (B)
61
/* Some defines to avoid ifdefs in the code */
64
#define NETWARE_SET_SCREEN_MODE(A)
69
The macros below are borrowed from include/linux/compiler.h in the
70
Linux kernel. Use them to indicate the likelyhood of the truthfulness
71
of a condition. This serves two purposes - newer versions of gcc will be
72
able to optimize for branch predication, which could yield siginficant
73
performance gains in frequently executed sections of the code, and the
74
other reason to use them is for documentation
77
#if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
78
#define __builtin_expect(x, expected_value) (x)
81
#define likely(x) __builtin_expect((x),1)
82
#define unlikely(x) __builtin_expect((x),0)
86
The macros below are useful in optimising places where it has been
87
discovered that cache misses stall the process and where a prefetch
88
of the cache line can improve matters. This is available in GCC 3.1.1
90
PREFETCH_READ says that addr is going to be used for reading and that
91
it is to be kept in caches if possible for a while
92
PREFETCH_WRITE also says that the item to be cached is likely to be
94
The *LOCALITY scripts are also available for experimentation purposes
95
mostly and should only be used if they are verified to improve matters.
96
For more input see GCC manual (available in GCC 3.1.1 and later)
99
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
100
#define PREFETCH_READ(addr) __builtin_prefetch(addr, 0, 3)
101
#define PREFETCH_WRITE(addr) \
102
__builtin_prefetch(addr, 1, 3)
103
#define PREFETCH_READ_LOCALITY(addr, locality) \
104
__builtin_prefetch(addr, 0, locality)
105
#define PREFETCH_WRITE_LOCALITY(addr, locality) \
106
__builtin_prefetch(addr, 1, locality)
108
#define PREFETCH_READ(addr)
109
#define PREFETCH_READ_LOCALITY(addr, locality)
110
#define PREFETCH_WRITE(addr)
111
#define PREFETCH_WRITE_LOCALITY(addr, locality)
115
The following macro is used to ensure that code often used in most
116
SQL statements and definitely for parts of the SQL processing are
117
kept in a code segment by itself. This has the advantage that the
118
risk of common code being overlapping in caches of the CPU is less.
119
This can be a cause of big performance problems.
120
Routines should be put in this category with care and when they are
121
put there one should also strive to make as much of the error handling
122
as possible (or uncommon code of the routine) to execute in a
123
separate method to avoid moving to much code to this code segment.
125
It is very easy to use, simply add HOT_METHOD at the end of the
126
function declaration.
127
For more input see GCC manual (available in GCC 2.95 and later)
130
#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94)
132
__attribute__ ((section ("hot_code_section")))
138
The following macro is used to ensure that popular global variables
139
are located next to each other to avoid that they contend for the
142
It is very easy to use, simply add HOT_DATA at the end of the declaration
143
of the variable, the variable must be initialised because of the way
144
that linker works so a declaration using HOT_DATA should look like:
145
uint global_hot_data HOT_DATA = 0;
146
For more input see GCC manual (available in GCC 2.95 and later)
149
#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94)
151
__attribute__ ((section ("hot_data_section")))
157
now let's figure out if inline functions are supported
158
autoconf defines 'inline' to be empty, if not
163
/* helper macro for "instantiating" inline functions */
164
#define STATIC_INLINE static inline
167
The following macros are used to control inlining a bit more than
168
usual. These macros are used to ensure that inlining always or
169
never occurs (independent of compilation mode).
170
For more input see GCC manual (available in GCC 3.1.1 and later)
173
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
174
#define ALWAYS_INLINE __attribute__ ((always_inline))
175
#define NEVER_INLINE __attribute__ ((noinline))
177
#define ALWAYS_INLINE
182
/* Fix problem with S_ISLNK() on Linux */
183
#if defined(TARGET_OS_LINUX) || defined(__GLIBC__)
185
#define _GNU_SOURCE 1
189
Temporary solution to solve bug#7156. Include "sys/types.h" before
190
the thread headers, else the function madvise() will not be defined
192
#if defined(HAVE_SYS_TYPES_H) && ( defined(sun) || defined(__sun) )
193
#include <sys/types.h>
196
#ifdef HAVE_THREADS_WITHOUT_SOCKETS
197
/* MIT pthreads does not work with unix sockets */
201
#define __EXTENSIONS__ 1 /* We want some extension */
203
#define __STDC_EXT__ 1 /* To get large file support on hpux */
207
Solaris 9 include file <sys/feature_tests.h> refers to X/Open document
209
System Interfaces and Headers, Issue 5
211
saying we should define _XOPEN_SOURCE=500 to get POSIX.1c prototypes,
212
but apparently other systems (namely FreeBSD) don't agree.
214
On a newer Solaris 10, the above file recognizes also _XOPEN_SOURCE=600.
215
Furthermore, it tests that if a program requires older standard
216
(_XOPEN_SOURCE<600 or _POSIX_C_SOURCE<200112L) it cannot be
217
run on a new compiler (that defines _STDC_C99) and issues an #error.
218
It's also an #error if a program requires new standard (_XOPEN_SOURCE=600
219
or _POSIX_C_SOURCE=200112L) and a compiler does not define _STDC_C99.
221
To add more to this mess, Sun Studio C compiler defines _STDC_C99 while
222
C++ compiler does not!
224
So, in a desperate attempt to get correct prototypes for both
225
C and C++ code, we define either _XOPEN_SOURCE=600 or _XOPEN_SOURCE=500
226
depending on the compiler's announced C standard support.
228
Cleaner solutions are welcome.
231
#if __STDC_VERSION__ - 0 >= 199901L
232
#define _XOPEN_SOURCE 600
234
#define _XOPEN_SOURCE 500
238
#ifndef _POSIX_PTHREAD_SEMANTICS
239
#define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */
242
#define _REENTRANT 1 /* Some thread libraries require this */
244
#if !defined(_THREAD_SAFE) && !defined(_AIX)
245
#define _THREAD_SAFE /* Required for OSF1 */
248
#include <pthread.h> /* AIX must have this included first */
250
#define _REENTRANT 1 /* Threads requires reentrant code */
252
/* Go around some bugs in different OS and compilers */
254
#if defined(HAVE_BROKEN_INLINE) && !defined(__cplusplus)
259
/* gcc/egcs issues */
261
#if defined(__GNUC) && defined(__EXCEPTIONS)
262
#error "Please add -fno-exceptions to CXXFLAGS and reconfigure/recompile"
280
#ifdef HAVE_SYS_TYPES_H
281
#include <sys/types.h>
286
#ifdef HAVE_SYS_TIMEB_H
287
#include <sys/timeb.h> /* Avoid warnings on SCO */
289
#if TIME_WITH_SYS_TIME
290
# include <sys/time.h>
294
# include <sys/time.h>
298
#endif /* TIME_WITH_SYS_TIME */
302
#if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA)
310
#include <errno.h> /* Recommended by debian */
311
/* We need the following to go around a problem with openssl on solaris */
312
#if defined(HAVE_CRYPT_H)
316
#if defined(HAVE_STDINT_H)
317
/* We are mixing C and C++, so we wan the C limit macros in the C++ too */
318
#define __STDC_LIMIT_MACROS
321
#if defined(HAVE_STDBOOL_H)
327
A lot of our programs uses asserts, so better to always include it
328
This also fixes a problem when people uses DBUG_ASSERT without including
333
/* an assert that works at compile-time. only for constant expression */
335
#define compile_time_assert(X) do { } while(0)
337
#define compile_time_assert(X) \
340
char compile_time_assert[(X) ? 1 : -1] \
341
__attribute__ ((unused)); \
345
/* Declare madvise where it is not declared for C++, like Solaris */
346
#if HAVE_MADVISE && !defined(HAVE_DECL_MADVISE) && defined(__cplusplus)
347
extern "C" int madvise(void *addr, size_t len, int behav);
350
/* We can not live without the following defines */
352
#define USE_MYFUNC 1 /* Must use syscall indirection */
353
#define MASTER 1 /* Compile without unireg */
354
#define ENGLISH 1 /* Messages in English */
355
#define POSIX_MISTAKE 1 /* regexp: Fix stupid spec error */
356
#define USE_REGEX 1 /* We want the use the regex library */
357
/* Do not define for ultra sparcs */
358
#define USE_BMOVE512 1 /* Use this unless system bmove is faster */
360
#define QUOTE_ARG(x) #x /* Quote argument (before cpp) */
361
#define STRINGIFY_ARG(x) QUOTE_ARG(x) /* Quote argument, after cpp */
362
/* Does the system remember a signal handler after a signal ? */
363
#ifndef HAVE_BSD_SIGNALS
364
#define DONT_REMEMBER_SIGNAL
367
/* Define void to stop lint from generating "null effekt" comments */
368
#ifndef DONT_DEFINE_VOID
371
#define VOID(X) (__void__ = (int) (X))
376
#endif /* DONT_DEFINE_VOID */
378
#if !defined(HAVE_UINT)
381
typedef unsigned int uint;
382
typedef unsigned short ushort;
385
#define CMP_NUM(a,b) (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
386
#define sgn(a) (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
387
#define swap_variables(t, a, b) { register t dummy; dummy= a; a= b; b= dummy; }
388
#define test(a) ((a) ? 1 : 0)
389
#define set_if_bigger(a,b) do { if ((a) < (b)) (a)=(b); } while(0)
390
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
391
#define test_all_bits(a,b) (((a) & (b)) == (b))
392
#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
393
#define array_elements(A) ((uint32_t) (sizeof(A)/sizeof(A[0])))
395
#define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5))
398
/* Define some general constants */
400
#define TRUE (1) /* Logical true */
401
#define FALSE (0) /* Logical false */
404
#if defined(__GNUC__)
405
#define function_volatile volatile
406
#define my_reinterpret_cast(A) reinterpret_cast<A>
407
#define my_const_cast(A) const_cast<A>
409
# define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
411
#elif !defined(my_reinterpret_cast)
412
#define my_reinterpret_cast(A) (A)
413
#define my_const_cast(A) (A)
416
#include <my_attribute.h>
418
/* From old s-system.h */
421
Support macros for non ansi & other old compilers. Since such
422
things are no longer supported we do nothing. We keep then since
423
some of our code may still be needed to upgrade old customers.
425
#define _VARARGS(X) X
426
#define _STATIC_VARARGS(X) X
429
/* The DBUG_ON flag always takes precedence over default DBUG_OFF */
430
#if defined(DBUG_ON) && defined(DBUG_OFF)
434
/* We might be forced to turn debug off, if not turned off already */
435
#if (defined(FORCE_DBUG_OFF) || defined(_lint)) && !defined(DBUG_OFF)
444
#define MIN_ARRAY_SIZE 0 /* Zero or One. Gcc allows zero*/
445
#define ASCII_BITS_USED 8 /* Bit char used */
447
/* Some types that is different between systems */
449
typedef int File; /* File descriptor */
450
#ifndef Socket_defined
451
typedef int my_socket; /* File descriptor for sockets */
452
#define INVALID_SOCKET -1
454
/* Type for fuctions that handles signals */
455
#define sig_handler RETSIGTYPE
457
typedef void (*sig_return)(void);/* Returns type from signal */
459
#if defined(__GNUC__) && !defined(_lint)
460
typedef char pchar; /* Mixed prototypes can take char */
461
typedef char puchar; /* Mixed prototypes can take char */
462
typedef char pbool; /* Mixed prototypes can take char */
463
typedef short pshort; /* Mixed prototypes can take short int */
464
typedef float pfloat; /* Mixed prototypes can take float */
466
typedef int pchar; /* Mixed prototypes can't take char */
467
typedef uint puchar; /* Mixed prototypes can't take char */
468
typedef int pbool; /* Mixed prototypes can't take char */
469
typedef int pshort; /* Mixed prototypes can't take short int */
470
typedef double pfloat; /* Mixed prototypes can't take float */
473
typedef int (*qsort_cmp)(const void *,const void *);
474
typedef int (*qsort_cmp2)(void*, const void *,const void *);
476
#define qsort_t RETQSORTTYPE /* Broken GCC cant handle typedef !!!! */
477
#ifdef HAVE_SYS_SOCKET_H
478
#include <sys/socket.h>
480
typedef SOCKET_SIZE_TYPE size_socket;
482
#ifndef SOCKOPT_OPTLEN_TYPE
483
#define SOCKOPT_OPTLEN_TYPE size_socket
486
/* file create flags */
488
#ifndef O_SHARE /* Probably not windows */
489
#define O_SHARE 0 /* Flag to my_open for shared files */
493
#define O_BINARY 0 /* Flag to my_open for binary files */
497
#define FILE_BINARY O_BINARY /* Flag to my_fopen for binary streams */
500
#define F_TO_EOF 0L /* Param to lockf() to lock rest of file */
503
#define O_TEMPORARY 0
505
#ifndef O_SHORT_LIVED
506
#define O_SHORT_LIVED 0
512
/* #define USE_RECORD_LOCK */
514
/* Unsigned types supported by the compiler */
515
#define UNSINT8 /* unsigned int8 (char) */
516
#define UNSINT16 /* unsigned int16 */
517
#define UNSINT32 /* unsigned int32 */
519
/* General constants */
520
#define SC_MAXWIDTH 256 /* Max width of screen (for error messages) */
521
#define FN_LEN 256 /* Max file name len */
522
#define FN_HEADLEN 253 /* Max length of filepart of file name */
523
#define FN_EXTLEN 20 /* Max length of extension (part of FN_LEN) */
524
#define FN_REFLEN 512 /* Max length of full path-name */
525
#define FN_EXTCHAR '.'
526
#define FN_HOMELIB '~' /* ~/ is used as abbrev for home dir */
527
#define FN_CURLIB '.' /* ./ is used as abbrev for current dir */
528
#define FN_PARENTDIR ".." /* Parent directory; Must be a string */
531
#define FN_LIBCHAR '/'
532
#define FN_ROOTDIR "/"
534
#define MY_NFILE 64 /* This is only used to save filenames */
535
#ifndef OS_FILE_LIMIT
536
#define OS_FILE_LIMIT 65535
539
/* #define EXT_IN_LIBNAME */
540
/* #define FN_NO_CASE_SENCE */
541
/* #define FN_UPPER_CASE TRUE */
544
Io buffer size; Must be a power of 2 and a multiple of 512. May be
545
smaller what the disk page size. This influences the speed of the
546
isam btree library. eg to big to slow.
550
How much overhead does malloc have. The code often allocates
551
something like 1024-MALLOC_OVERHEAD bytes
553
#define MALLOC_OVERHEAD 8
555
/* get memory in huncs */
556
#define ONCE_ALLOC_INIT (uint) (4096-MALLOC_OVERHEAD)
557
/* Typical record cash */
558
#define RECORD_CACHE_SIZE (uint) (64*1024-MALLOC_OVERHEAD)
559
/* Typical key cash */
560
#define KEY_CACHE_SIZE (uint) (8*1024*1024-MALLOC_OVERHEAD)
561
/* Default size of a key cache block */
562
#define KEY_CACHE_BLOCK_SIZE (uint) 1024
565
/* Some things that this system doesn't have */
567
#define NO_HASH /* Not needed anymore */
569
/* Some defines of functions for portability */
571
#undef remove /* Crashes MySQL on SCO 5.0.0 */
572
#define closesocket(A) close(A)
573
#ifndef ulonglong2double
574
#define ulonglong2double(A) ((double) (ulonglong) (A))
575
#define my_off_t2double(A) ((double) (my_off_t) (A))
579
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
581
#define ulong_to_double(X) ((double) (ulong) (X))
582
#define SET_STACK_SIZE(X) /* Not needed on real machines */
584
#ifndef STACK_DIRECTION
585
#error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
588
#if !defined(HAVE_STRTOK_R)
589
#define strtok_r(A,B,C) strtok((A),(B))
593
#if defined(INT64_MAX)
594
#define LONGLONG_MAX INT64_MAX
597
#if defined(INT64_MIN)
598
#define LONGLONG_MIN INT64_MIN
601
#if !defined(ULONGLONG_MAX)
602
/* First check for ANSI C99 definition: */
603
#if defined(UINT64_MAX)
604
#define ULONGLONG_MAX UINT64_MAX
606
#define ULONGLONG_MAX ((uint64_t)(~0ULL))
608
#endif /* !defined(ULONGLONG_MAX)*/
610
#define INT_MIN32 (~0x7FFFFFFFL)
611
#define INT_MAX32 0x7FFFFFFFL
612
#define UINT_MAX32 0xFFFFFFFFL
613
#define INT_MIN24 (~0x007FFFFF)
614
#define INT_MAX24 0x007FFFFF
615
#define UINT_MAX24 0x00FFFFFF
616
#define INT_MIN16 (~0x7FFF)
617
#define INT_MAX16 0x7FFF
618
#define UINT_MAX16 0xFFFF
619
#define INT_MIN8 (~0x7F)
620
#define INT_MAX8 0x7F
621
#define UINT_MAX8 0xFF
626
#if !defined(FLT_MIN)
627
#define FLT_MIN ((float)1.40129846432481707e-45)
629
#if !defined(FLT_MAX)
630
#define FLT_MAX ((float)3.40282346638528860e+38)
634
/* From limits.h instead */
636
#define DBL_MIN 4.94065645841246544e-324
639
#define DBL_MAX 1.79769313486231470e+308
642
#define SIZE_T_MAX ~((size_t) 0)
647
#define isfinite(x) finite(x)
649
#define finite(x) (1.0 / fabs(x) > 0.0)
650
#endif /* HAVE_FINITE */
651
#endif /* isfinite */
654
#define isnan(x) ((x) != (x))
658
/* isinf() can be used in both C and C++ code */
659
#define my_isinf(X) isinf(X)
661
#define my_isinf(X) (!isfinite(X) && !isnan(X))
664
/* Define missing math constants. */
666
#define M_PI 3.14159265358979323846
669
#define M_E 2.7182818284590452354
672
#define M_LN2 0.69314718055994530942
676
Max size that must be added to a so that we know Size to make
679
#if SIZEOF_CHARP == 4
680
typedef int32_t my_ptrdiff_t;
682
typedef int64_t my_ptrdiff_t;
685
#define MY_ALIGN(A,L) (((A) + (L) - 1) & ~((L) - 1))
686
#define ALIGN_SIZE(A) MY_ALIGN((A),sizeof(double))
687
/* Size to make adressable obj. */
688
#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
689
/* Offset of field f in structure t */
690
#define OFFSET(t, f) ((size_t)(char *)&((t *)0)->f)
691
#define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size)
692
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B))
694
#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
695
#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
698
Custom version of standard offsetof() macro which can be used to get
699
offsets of members in class for non-POD types (according to the current
700
version of C++ standard offsetof() macro can't be used in such cases and
701
attempt to do so causes warnings to be emitted, OTOH in many cases it is
702
still OK to assume that all instances of the class has the same offsets
703
for the same members).
705
This is temporary solution which should be removed once File_parser class
706
and related routines are refactored.
709
#define my_offsetof(TYPE, MEMBER) \
710
((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
712
#define NullS (char *) 0
716
/* Typdefs for easyier portability */
719
typedef unsigned char uchar; /* Short for unsigned char */
723
typedef signed char int8; /* Signed integer >= 8 bits */
726
typedef unsigned char uint8; /* Unsigned integer >= 8 bits */
732
typedef unsigned short uint16;
739
typedef unsigned int uint32;
741
#elif SIZEOF_LONG == 4
746
typedef unsigned long uint32;
749
#error Neither int or long is of 4 bytes width
752
#if !defined(HAVE_ULONG) && !defined(__USE_MISC)
753
typedef uint32_t ulong; /* Short for unsigned long */
755
#ifndef longlong_defined
757
Using [unsigned] long long is preferable as [u]longlong because we use
758
[unsigned] long long unconditionally in many places,
759
for example in constants with [U]LL suffix.
761
typedef uint64_t ulonglong; /* ulong or unsigned long long */
762
typedef int64_t longlong;
766
typedef int64_t int64;
769
typedef uint64_t uint64;
772
typedef uint64_t my_ulonglong;
774
#if SIZEOF_CHARP == SIZEOF_INT
776
#elif SIZEOF_CHARP == SIZEOF_LONG
778
#elif SIZEOF_CHARP == SIZEOF_LONG_LONG
779
typedef long long intptr;
781
#error sizeof(void *) is neither sizeof(int) nor sizeof(long) nor sizeof(long long)
784
#define MY_ERRPTR ((void*)(intptr)1)
787
typedef ulonglong my_off_t;
789
typedef unsigned long my_off_t;
791
#define MY_FILEPOS_ERROR (~(my_off_t) 0)
793
typedef off_t os_off_t;
795
#define socket_errno errno
796
#define closesocket(A) close(A)
797
#define SOCKET_EINTR EINTR
798
#define SOCKET_EAGAIN EAGAIN
799
#define SOCKET_ETIMEDOUT SOCKET_EINTR
800
#define SOCKET_EWOULDBLOCK EWOULDBLOCK
801
#define SOCKET_EADDRINUSE EADDRINUSE
802
#define SOCKET_ENFILE ENFILE
803
#define SOCKET_EMFILE EMFILE
805
typedef uint8 int7; /* Most effective integer 0 <= x <= 127 */
806
typedef short int15; /* Most effective integer 0 <= x <= 32767 */
807
typedef int myf; /* Type of MyFlags in my_funcs */
808
typedef char my_bool; /* Small bool */
809
#if !defined(bool) && (!defined(HAVE_BOOL) || !defined(__cplusplus))
810
typedef char bool; /* Ordinary boolean values 0 1 */
812
/* Macros for converting *constants* to the right type */
813
#define INT8(v) (int8) (v)
814
#define INT16(v) (int16) (v)
815
#define INT32(v) (int32) (v)
816
#define MYF(v) (myf) (v)
819
Sometimes we want to make sure that the variable is not put into
820
a register in debugging mode so we can see its value in the core
824
#define dbug_volatile volatile
826
#define dbug_volatile
829
/* Defines for time function */
830
#define SCALE_SEC 100
831
#define SCALE_USEC 10000
832
#define MY_HOW_OFTEN_TO_ALARM 2 /* How often we want info on screen */
833
#define MY_HOW_OFTEN_TO_WRITE 1000 /* How often we want info on screen */
838
Define-funktions for reading and storing in machine independent format
842
/* Optimized store functions for Intel x86 */
843
#if defined(__i386__)
844
#define sint2korr(A) (*((int16 *) (A)))
845
#define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \
846
(((uint32) 255L << 24) | \
847
(((uint32) (uchar) (A)[2]) << 16) |\
848
(((uint32) (uchar) (A)[1]) << 8) | \
849
((uint32) (uchar) (A)[0])) : \
850
(((uint32) (uchar) (A)[2]) << 16) |\
851
(((uint32) (uchar) (A)[1]) << 8) | \
852
((uint32) (uchar) (A)[0])))
853
#define sint4korr(A) (*((long *) (A)))
854
#define uint2korr(A) (*((uint16 *) (A)))
855
#if defined(HAVE_purify)
856
#define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
857
(((uint32) ((uchar) (A)[1])) << 8) +\
858
(((uint32) ((uchar) (A)[2])) << 16))
863
Please, note, uint3korr reads 4 bytes (not 3) !
864
It means, that you have to provide enough allocated space !
866
#define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF)
867
#endif /* HAVE_purify */
868
#define uint4korr(A) (*((uint32 *) (A)))
869
#define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
870
(((uint32) ((uchar) (A)[1])) << 8) +\
871
(((uint32) ((uchar) (A)[2])) << 16) +\
872
(((uint32) ((uchar) (A)[3])) << 24)) +\
873
(((ulonglong) ((uchar) (A)[4])) << 32))
874
#define uint6korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) + \
875
(((uint32) ((uchar) (A)[1])) << 8) + \
876
(((uint32) ((uchar) (A)[2])) << 16) + \
877
(((uint32) ((uchar) (A)[3])) << 24)) + \
878
(((ulonglong) ((uchar) (A)[4])) << 32) + \
879
(((ulonglong) ((uchar) (A)[5])) << 40))
880
#define uint8korr(A) (*((ulonglong *) (A)))
881
#define sint8korr(A) (*((longlong *) (A)))
882
#define int2store(T,A) *((uint16*) (T))= (uint16) (A)
883
#define int3store(T,A) do { *(T)= (uchar) ((A));\
884
*(T+1)=(uchar) (((uint) (A) >> 8));\
885
*(T+2)=(uchar) (((A) >> 16)); } while (0)
886
#define int4store(T,A) *((long *) (T))= (long) (A)
887
#define int5store(T,A) do { *(T)= (uchar)((A));\
888
*((T)+1)=(uchar) (((A) >> 8));\
889
*((T)+2)=(uchar) (((A) >> 16));\
890
*((T)+3)=(uchar) (((A) >> 24)); \
891
*((T)+4)=(uchar) (((A) >> 32)); } while(0)
892
#define int6store(T,A) do { *(T)= (uchar)((A)); \
893
*((T)+1)=(uchar) (((A) >> 8)); \
894
*((T)+2)=(uchar) (((A) >> 16)); \
895
*((T)+3)=(uchar) (((A) >> 24)); \
896
*((T)+4)=(uchar) (((A) >> 32)); \
897
*((T)+5)=(uchar) (((A) >> 40)); } while(0)
898
#define int8store(T,A) *((ulonglong *) (T))= (ulonglong) (A)
904
#define doubleget(V,M) \
905
do { doubleget_union _tmp; \
906
_tmp.m[0] = *((long*)(M)); \
907
_tmp.m[1] = *(((long*) (M))+1); \
908
(V) = _tmp.v; } while(0)
909
#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
910
*(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
912
#define float4get(V,M) do { *((float *) &(V)) = *((float*) (M)); } while(0)
913
#define float8get(V,M) doubleget((V),(M))
914
#define float4store(V,M) memcpy((uchar*) V,(uchar*) (&M),sizeof(float))
915
#define floatstore(T,V) memcpy((uchar*)(T), (uchar*)(&V),sizeof(float))
916
#define floatget(V,M) memcpy((uchar*) &V,(uchar*) (M),sizeof(float))
917
#define float8store(V,M) doublestore((V),(M))
921
We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines
924
#define sint2korr(A) (int16) (((int16) ((uchar) (A)[0])) +\
925
((int16) ((int16) (A)[1]) << 8))
926
#define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \
927
(((uint32) 255L << 24) | \
928
(((uint32) (uchar) (A)[2]) << 16) |\
929
(((uint32) (uchar) (A)[1]) << 8) | \
930
((uint32) (uchar) (A)[0])) : \
931
(((uint32) (uchar) (A)[2]) << 16) |\
932
(((uint32) (uchar) (A)[1]) << 8) | \
933
((uint32) (uchar) (A)[0])))
934
#define sint4korr(A) (int32) (((int32) ((uchar) (A)[0])) +\
935
(((int32) ((uchar) (A)[1]) << 8)) +\
936
(((int32) ((uchar) (A)[2]) << 16)) +\
937
(((int32) ((int16) (A)[3]) << 24)))
938
#define sint8korr(A) (longlong) uint8korr(A)
939
#define uint2korr(A) (uint16) (((uint16) ((uchar) (A)[0])) +\
940
((uint16) ((uchar) (A)[1]) << 8))
941
#define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
942
(((uint32) ((uchar) (A)[1])) << 8) +\
943
(((uint32) ((uchar) (A)[2])) << 16))
944
#define uint4korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
945
(((uint32) ((uchar) (A)[1])) << 8) +\
946
(((uint32) ((uchar) (A)[2])) << 16) +\
947
(((uint32) ((uchar) (A)[3])) << 24))
948
#define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
949
(((uint32) ((uchar) (A)[1])) << 8) +\
950
(((uint32) ((uchar) (A)[2])) << 16) +\
951
(((uint32) ((uchar) (A)[3])) << 24)) +\
952
(((ulonglong) ((uchar) (A)[4])) << 32))
953
#define uint6korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) + \
954
(((uint32) ((uchar) (A)[1])) << 8) + \
955
(((uint32) ((uchar) (A)[2])) << 16) + \
956
(((uint32) ((uchar) (A)[3])) << 24)) + \
957
(((ulonglong) ((uchar) (A)[4])) << 32) + \
958
(((ulonglong) ((uchar) (A)[5])) << 40))
959
#define uint8korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
960
(((uint32) ((uchar) (A)[1])) << 8) +\
961
(((uint32) ((uchar) (A)[2])) << 16) +\
962
(((uint32) ((uchar) (A)[3])) << 24)) +\
963
(((ulonglong) (((uint32) ((uchar) (A)[4])) +\
964
(((uint32) ((uchar) (A)[5])) << 8) +\
965
(((uint32) ((uchar) (A)[6])) << 16) +\
966
(((uint32) ((uchar) (A)[7])) << 24))) <<\
968
#define int2store(T,A) do { uint def_temp= (uint) (A) ;\
969
*((uchar*) (T))= (uchar)(def_temp); \
970
*((uchar*) (T)+1)=(uchar)((def_temp >> 8)); \
972
#define int3store(T,A) do { /*lint -save -e734 */\
973
*((uchar*)(T))=(uchar) ((A));\
974
*((uchar*) (T)+1)=(uchar) (((A) >> 8));\
975
*((uchar*)(T)+2)=(uchar) (((A) >> 16)); \
976
/*lint -restore */} while(0)
977
#define int4store(T,A) do { *((char *)(T))=(char) ((A));\
978
*(((char *)(T))+1)=(char) (((A) >> 8));\
979
*(((char *)(T))+2)=(char) (((A) >> 16));\
980
*(((char *)(T))+3)=(char) (((A) >> 24)); } while(0)
981
#define int5store(T,A) do { *((char *)(T))= (char)((A)); \
982
*(((char *)(T))+1)= (char)(((A) >> 8)); \
983
*(((char *)(T))+2)= (char)(((A) >> 16)); \
984
*(((char *)(T))+3)= (char)(((A) >> 24)); \
985
*(((char *)(T))+4)= (char)(((A) >> 32)); \
987
#define int6store(T,A) do { *((char *)(T))= (char)((A)); \
988
*(((char *)(T))+1)= (char)(((A) >> 8)); \
989
*(((char *)(T))+2)= (char)(((A) >> 16)); \
990
*(((char *)(T))+3)= (char)(((A) >> 24)); \
991
*(((char *)(T))+4)= (char)(((A) >> 32)); \
992
*(((char *)(T))+5)= (char)(((A) >> 40)); \
994
#define int8store(T,A) do { uint def_temp= (uint) (A), def_temp2= (uint) ((A) >> 32); \
995
int4store((T),def_temp); \
996
int4store((T+4),def_temp2); } while(0)
997
#ifdef WORDS_BIGENDIAN
998
#define float4store(T,A) do { *(T)= ((uchar *) &A)[3];\
999
*((T)+1)=(char) ((uchar *) &A)[2];\
1000
*((T)+2)=(char) ((uchar *) &A)[1];\
1001
*((T)+3)=(char) ((uchar *) &A)[0]; } while(0)
1003
#define float4get(V,M) do { float def_temp;\
1004
((uchar*) &def_temp)[0]=(M)[3];\
1005
((uchar*) &def_temp)[1]=(M)[2];\
1006
((uchar*) &def_temp)[2]=(M)[1];\
1007
((uchar*) &def_temp)[3]=(M)[0];\
1008
(V)=def_temp; } while(0)
1009
#define float8store(T,V) do { *(T)= ((uchar *) &V)[7];\
1010
*((T)+1)=(char) ((uchar *) &V)[6];\
1011
*((T)+2)=(char) ((uchar *) &V)[5];\
1012
*((T)+3)=(char) ((uchar *) &V)[4];\
1013
*((T)+4)=(char) ((uchar *) &V)[3];\
1014
*((T)+5)=(char) ((uchar *) &V)[2];\
1015
*((T)+6)=(char) ((uchar *) &V)[1];\
1016
*((T)+7)=(char) ((uchar *) &V)[0]; } while(0)
1018
#define float8get(V,M) do { double def_temp;\
1019
((uchar*) &def_temp)[0]=(M)[7];\
1020
((uchar*) &def_temp)[1]=(M)[6];\
1021
((uchar*) &def_temp)[2]=(M)[5];\
1022
((uchar*) &def_temp)[3]=(M)[4];\
1023
((uchar*) &def_temp)[4]=(M)[3];\
1024
((uchar*) &def_temp)[5]=(M)[2];\
1025
((uchar*) &def_temp)[6]=(M)[1];\
1026
((uchar*) &def_temp)[7]=(M)[0];\
1027
(V) = def_temp; } while(0)
1029
#define float4get(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(float))
1030
#define float4store(V,M) memcpy_fixed((uchar*) V,(uchar*) (&M),sizeof(float))
1032
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
1033
#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((uchar *) &V)[4];\
1034
*(((char*)T)+1)=(char) ((uchar *) &V)[5];\
1035
*(((char*)T)+2)=(char) ((uchar *) &V)[6];\
1036
*(((char*)T)+3)=(char) ((uchar *) &V)[7];\
1037
*(((char*)T)+4)=(char) ((uchar *) &V)[0];\
1038
*(((char*)T)+5)=(char) ((uchar *) &V)[1];\
1039
*(((char*)T)+6)=(char) ((uchar *) &V)[2];\
1040
*(((char*)T)+7)=(char) ((uchar *) &V)[3]; }\
1042
#define doubleget(V,M) do { double def_temp;\
1043
((uchar*) &def_temp)[0]=(M)[4];\
1044
((uchar*) &def_temp)[1]=(M)[5];\
1045
((uchar*) &def_temp)[2]=(M)[6];\
1046
((uchar*) &def_temp)[3]=(M)[7];\
1047
((uchar*) &def_temp)[4]=(M)[0];\
1048
((uchar*) &def_temp)[5]=(M)[1];\
1049
((uchar*) &def_temp)[6]=(M)[2];\
1050
((uchar*) &def_temp)[7]=(M)[3];\
1051
(V) = def_temp; } while(0)
1052
#endif /* __FLOAT_WORD_ORDER */
1054
#define float8get(V,M) doubleget((V),(M))
1055
#define float8store(V,M) doublestore((V),(M))
1056
#endif /* WORDS_BIGENDIAN */
1058
#endif /* __i386__ */
1061
Macro for reading 32-bit integer from network byte order (big-endian)
1062
from unaligned memory location.
1064
#define int4net(A) (int32) (((uint32) ((uchar) (A)[3])) |\
1065
(((uint32) ((uchar) (A)[2])) << 8) |\
1066
(((uint32) ((uchar) (A)[1])) << 16) |\
1067
(((uint32) ((uchar) (A)[0])) << 24))
1069
Define-funktions for reading and storing in machine format from/to
1070
short/long to/from some place in memory V should be a (not
1071
register) variable, M is a pointer to byte
1074
#ifdef WORDS_BIGENDIAN
1076
#define ushortget(V,M) do { V = (uint16) (((uint16) ((uchar) (M)[1]))+\
1077
((uint16) ((uint16) (M)[0]) << 8)); } while(0)
1078
#define shortget(V,M) do { V = (short) (((short) ((uchar) (M)[1]))+\
1079
((short) ((short) (M)[0]) << 8)); } while(0)
1080
#define longget(V,M) do { int32 def_temp;\
1081
((uchar*) &def_temp)[0]=(M)[0];\
1082
((uchar*) &def_temp)[1]=(M)[1];\
1083
((uchar*) &def_temp)[2]=(M)[2];\
1084
((uchar*) &def_temp)[3]=(M)[3];\
1085
(V)=def_temp; } while(0)
1086
#define ulongget(V,M) do { uint32 def_temp;\
1087
((uchar*) &def_temp)[0]=(M)[0];\
1088
((uchar*) &def_temp)[1]=(M)[1];\
1089
((uchar*) &def_temp)[2]=(M)[2];\
1090
((uchar*) &def_temp)[3]=(M)[3];\
1091
(V)=def_temp; } while(0)
1092
#define shortstore(T,A) do { uint def_temp=(uint) (A) ;\
1093
*(((char*)T)+1)=(char)(def_temp); \
1094
*(((char*)T)+0)=(char)(def_temp >> 8); } while(0)
1095
#define longstore(T,A) do { *(((char*)T)+3)=((A));\
1096
*(((char*)T)+2)=(((A) >> 8));\
1097
*(((char*)T)+1)=(((A) >> 16));\
1098
*(((char*)T)+0)=(((A) >> 24)); } while(0)
1100
#define floatget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(float))
1101
#define floatstore(T,V) memcpy_fixed((uchar*) (T),(uchar*)(&V),sizeof(float))
1102
#define doubleget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(double))
1103
#define doublestore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(double))
1104
#define longlongget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(ulonglong))
1105
#define longlongstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(ulonglong))
1109
#define ushortget(V,M) do { V = uint2korr(M); } while(0)
1110
#define shortget(V,M) do { V = sint2korr(M); } while(0)
1111
#define longget(V,M) do { V = sint4korr(M); } while(0)
1112
#define ulongget(V,M) do { V = uint4korr(M); } while(0)
1113
#define shortstore(T,V) int2store(T,V)
1114
#define longstore(T,V) int4store(T,V)
1116
#define floatstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) (&V),sizeof(float))
1117
#define floatget(V,M) memcpy_fixed((uchar*) &V, (uchar*) (M), sizeof(float))
1120
#define doubleget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(double))
1121
#define doublestore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(double))
1122
#endif /* doubleget */
1123
#define longlongget(V,M) memcpy_fixed((uchar*) &V,(uchar*) (M),sizeof(ulonglong))
1124
#define longlongstore(T,V) memcpy_fixed((uchar*) (T),(uchar*) &V,sizeof(ulonglong))
1126
#endif /* WORDS_BIGENDIAN */
1128
/* sprintf does not always return the number of bytes :- */
1129
#ifdef SPRINTF_RETURNS_INT
1130
#define my_sprintf(buff,args) sprintf args
1132
#ifdef SPRINTF_RETURNS_PTR
1133
#define my_sprintf(buff,args) ((int)(sprintf args - buff))
1135
#define my_sprintf(buff,args) ((ulong) sprintf args, (ulong) strlen(buff))
1139
#if defined(HAVE_CHARSET_utf8mb3) || defined(HAVE_CHARSET_utf8mb4)
1140
#define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8"
1142
#define MYSQL_UNIVERSAL_CLIENT_CHARSET MYSQL_DEFAULT_CHARSET_NAME
1146
#if defined(HAVE_DLFCN_H)
1151
/* FreeBSD 2.2.2 does not define RTLD_NOW) */
1156
#ifndef HAVE_DLERROR
1157
#define dlerror() ""
1162
* Include standard definitions of operator new and delete.
1168
/* Length of decimal number represented by INT32. */
1169
#define MY_INT32_NUM_DECIMAL_DIGITS 11
1171
/* Length of decimal number represented by INT64. */
1172
#define MY_INT64_NUM_DECIMAL_DIGITS 21
1178
/* Define some useful general macros (should be done after all headers). */
1180
#define max(a, b) ((a) > (b) ? (a) : (b))
1181
#define min(a, b) ((a) < (b) ? (a) : (b))
1184
Only Linux is known to need an explicit sync of the directory to make sure a
1185
file creation/deletion/renaming in(from,to) this directory durable.
1187
#ifdef TARGET_OS_LINUX
1188
#define NEED_EXPLICIT_SYNC_DIR 1
1191
#endif /* my_global_h */