~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/global.h

  • Committer: Brian Aker
  • Date: 2008-08-12 03:12:57 UTC
  • Revision ID: brian@tangent.org-20080812031257-ln3uk87y1r22byeg
First pass of new sql_db.cc work

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000-2003 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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 */
19
15
 
20
16
/* This is the include file that should be included 'first' in every C file. */
21
17
 
22
18
#ifndef DRIZZLE_SERVER_GLOBAL_H
23
19
#define DRIZZLE_SERVER_GLOBAL_H
24
20
 
 
21
#define HAVE_REPLICATION
 
22
#define HAVE_EXTERNAL_CLIENT
 
23
 
 
24
/*
 
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.
 
28
 
 
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
 
31
  InnoDB's use.
 
32
*/
 
33
#define INNODB_COMPATIBILITY_HOOKS
 
34
 
 
35
/* to make command line shorter we'll define USE_PRAGMA_INTERFACE here */
 
36
#ifdef USE_PRAGMA_IMPLEMENTATION
 
37
#define USE_PRAGMA_INTERFACE
 
38
#endif
 
39
 
25
40
#if defined(i386) && !defined(__i386__)
26
41
#define __i386__
27
42
#endif
28
43
 
 
44
/* Macros to make switching between C and C++ mode easier */
 
45
#ifdef __cplusplus
 
46
#define C_MODE_START    extern "C" {
 
47
#define C_MODE_END      }
 
48
#else
 
49
#define C_MODE_START
 
50
#define C_MODE_END
 
51
#endif
 
52
 
29
53
#include "config.h"
30
54
 
 
55
/* Make it easier to add conditionl code for windows */
 
56
#define IF_WIN(A,B) (B)
 
57
 
 
58
/*
 
59
  The macros below are borrowed from include/linux/compiler.h in the
 
60
  Linux kernel. Use them to indicate the likelyhood of the truthfulness
 
61
  of a condition. This serves two purposes - newer versions of gcc will be
 
62
  able to optimize for branch predication, which could yield siginficant
 
63
  performance gains in frequently executed sections of the code, and the
 
64
  other reason to use them is for documentation
 
65
*/
 
66
 
 
67
#if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
 
68
#define __builtin_expect(x, expected_value) (x)
 
69
#endif
 
70
 
 
71
#define likely(x)       __builtin_expect((x),1)
 
72
#define unlikely(x)     __builtin_expect((x),0)
 
73
 
 
74
 
 
75
/*
 
76
  The macros below are useful in optimising places where it has been
 
77
  discovered that cache misses stall the process and where a prefetch
 
78
  of the cache line can improve matters. This is available in GCC 3.1.1
 
79
  and later versions.
 
80
  PREFETCH_READ says that addr is going to be used for reading and that
 
81
  it is to be kept in caches if possible for a while
 
82
  PREFETCH_WRITE also says that the item to be cached is likely to be
 
83
  updated.
 
84
  The *LOCALITY scripts are also available for experimentation purposes
 
85
  mostly and should only be used if they are verified to improve matters.
 
86
  For more input see GCC manual (available in GCC 3.1.1 and later)
 
87
*/
 
88
 
 
89
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
 
90
#define PREFETCH_READ(addr) __builtin_prefetch(addr, 0, 3)
 
91
#define PREFETCH_WRITE(addr) \
 
92
  __builtin_prefetch(addr, 1, 3)
 
93
#define PREFETCH_READ_LOCALITY(addr, locality) \
 
94
  __builtin_prefetch(addr, 0, locality)
 
95
#define PREFETCH_WRITE_LOCALITY(addr, locality) \
 
96
  __builtin_prefetch(addr, 1, locality)
 
97
#else
 
98
#define PREFETCH_READ(addr)
 
99
#define PREFETCH_READ_LOCALITY(addr, locality)
 
100
#define PREFETCH_WRITE(addr)
 
101
#define PREFETCH_WRITE_LOCALITY(addr, locality)
 
102
#endif
 
103
 
 
104
/*
 
105
  now let's figure out if inline functions are supported
 
106
  autoconf defines 'inline' to be empty, if not
 
107
*/
 
108
#if defined(inline)
 
109
#define HAVE_INLINE
 
110
#endif
 
111
/* helper macro for "instantiating" inline functions */
 
112
#define STATIC_INLINE static inline
 
113
 
 
114
/*
 
115
  The following macros are used to control inlining a bit more than
 
116
  usual. These macros are used to ensure that inlining always or
 
117
  never occurs (independent of compilation mode).
 
118
  For more input see GCC manual (available in GCC 3.1.1 and later)
 
119
*/
 
120
 
 
121
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
 
122
#define ALWAYS_INLINE __attribute__ ((always_inline))
 
123
#define NEVER_INLINE __attribute__ ((noinline))
 
124
#else
 
125
#define ALWAYS_INLINE
 
126
#define NEVER_INLINE
 
127
#endif
 
128
 
 
129
/*
 
130
 *   Disable __attribute__ for non GNU compilers, since we're using them
 
131
 *     only to either generate or suppress warnings.
 
132
 *     */
 
133
#ifndef __attribute__
 
134
# if !defined(__GNUC__)
 
135
#  define __attribute__(A)
 
136
# endif
 
137
#endif
 
138
 
 
139
 
 
140
/* Fix problem with S_ISLNK() on Linux */
 
141
#if defined(TARGET_OS_LINUX) || defined(__GLIBC__)
 
142
#undef  _GNU_SOURCE
 
143
#define _GNU_SOURCE 1
 
144
#endif
 
145
 
 
146
 
31
147
/*
32
148
  Temporary solution to solve bug#7156. Include "sys/types.h" before
33
149
  the thread headers, else the function madvise() will not be defined
36
152
#include <sys/types.h>
37
153
#endif
38
154
 
 
155
#ifdef HAVE_THREADS_WITHOUT_SOCKETS
 
156
/* MIT pthreads does not work with unix sockets */
 
157
#undef HAVE_SYS_UN_H
 
158
#endif
 
159
 
 
160
#define __EXTENSIONS__ 1        /* We want some extension */
 
161
#ifndef __STDC_EXT__
 
162
#define __STDC_EXT__ 1          /* To get large file support on hpux */
 
163
#endif
 
164
 
39
165
#if defined(HAVE_STDINT_H)
 
166
/* Need to include this _before_ stdlib, so that all defines are right */
 
167
/* We are mixing C and C++, so we wan the C limit macros in the C++ too */
 
168
/* Enable some extra C99 extensions */
 
169
#undef _STDINT_H
 
170
#define __STDC_LIMIT_MACROS
 
171
#define __STDC_FORMAT_MACROS
40
172
#include <stdint.h>
 
173
#include <inttypes.h>
41
174
#else
42
175
#error "You must have stdint!"
43
176
#endif
44
177
 
45
 
#if defined(HAVE_INTTYPES_H)
46
 
#include <inttypes.h>
 
178
 
 
179
/*
 
180
  Solaris 9 include file <sys/feature_tests.h> refers to X/Open document
 
181
 
 
182
    System Interfaces and Headers, Issue 5
 
183
 
 
184
  saying we should define _XOPEN_SOURCE=500 to get POSIX.1c prototypes,
 
185
  but apparently other systems (namely FreeBSD) don't agree.
 
186
 
 
187
  On a newer Solaris 10, the above file recognizes also _XOPEN_SOURCE=600.
 
188
  Furthermore, it tests that if a program requires older standard
 
189
  (_XOPEN_SOURCE<600 or _POSIX_C_SOURCE<200112L) it cannot be
 
190
  run on a new compiler (that defines _STDC_C99) and issues an #error.
 
191
  It's also an #error if a program requires new standard (_XOPEN_SOURCE=600
 
192
  or _POSIX_C_SOURCE=200112L) and a compiler does not define _STDC_C99.
 
193
 
 
194
  To add more to this mess, Sun Studio C compiler defines _STDC_C99 while
 
195
  C++ compiler does not!
 
196
 
 
197
  So, in a desperate attempt to get correct prototypes for both
 
198
  C and C++ code, we define either _XOPEN_SOURCE=600 or _XOPEN_SOURCE=500
 
199
  depending on the compiler's announced C standard support.
 
200
 
 
201
  Cleaner solutions are welcome.
 
202
*/
 
203
#ifdef __sun
 
204
#if __STDC_VERSION__ - 0 >= 199901L
 
205
#define _XOPEN_SOURCE 600
47
206
#else
48
 
#error "You must have inttypes!"
49
 
#endif
50
 
 
51
 
#include <pthread.h>    /* AIX must have this included first */
52
 
 
53
 
#define _REENTRANT  1  /* Threads requires reentrant code */
54
 
 
 
207
#define _XOPEN_SOURCE 500
 
208
#endif
 
209
#endif
 
210
 
 
211
#ifndef _POSIX_PTHREAD_SEMANTICS
 
212
#define _POSIX_PTHREAD_SEMANTICS /* We want posix threads */
 
213
#endif
 
214
 
 
215
#define _REENTRANT      1       /* Some thread libraries require this */
 
216
 
 
217
#if !defined(_THREAD_SAFE) && !defined(_AIX)
 
218
#define _THREAD_SAFE            /* Required for OSF1 */
 
219
#endif
 
220
 
 
221
#include <pthread.h>            /* AIX must have this included first */
 
222
 
 
223
#define _REENTRANT      1       /* Threads requires reentrant code */
 
224
 
 
225
/* Go around some bugs in different OS and compilers */
 
226
 
 
227
#if defined(HAVE_BROKEN_INLINE) && !defined(__cplusplus)
 
228
#undef inline
 
229
#define inline
 
230
#endif
55
231
 
56
232
/* gcc/egcs issues */
57
233
 
81
257
#include <fcntl.h>
82
258
#endif
83
259
#ifdef HAVE_SYS_TIMEB_H
84
 
#include <sys/timeb.h>        /* Avoid warnings on SCO */
 
260
#include <sys/timeb.h>                          /* Avoid warnings on SCO */
85
261
#endif
86
262
#if TIME_WITH_SYS_TIME
87
263
# include <sys/time.h>
104
280
#include <alloca.h>
105
281
#endif
106
282
 
107
 
#include <errno.h>        /* Recommended by debian */
 
283
#include <errno.h>                              /* Recommended by debian */
108
284
 
109
285
#if defined(HAVE_STDBOOL_H)
110
286
#include <stdbool.h>
119
295
*/
120
296
#include <assert.h>
121
297
 
 
298
/* an assert that works at compile-time. only for constant expression */
 
299
#ifndef __GNUC__
 
300
#define compile_time_assert(X)  do { } while(0)
 
301
#else
 
302
#define compile_time_assert(X)                                  \
 
303
  do                                                            \
 
304
  {                                                             \
 
305
    char compile_time_assert[(X) ? 1 : -1]                      \
 
306
                             __attribute__ ((unused));          \
 
307
  } while(0)
 
308
#endif
 
309
 
 
310
/* Declare madvise where it is not declared for C++, like Solaris */
 
311
#if HAVE_MADVISE && !defined(HAVE_DECL_MADVISE) && defined(__cplusplus)
 
312
extern "C" int madvise(void *addr, size_t len, int behav);
 
313
#endif
 
314
 
 
315
/* We can not live without the following defines */
 
316
 
 
317
#define USE_MYFUNC 1            /* Must use syscall indirection */
 
318
#define MASTER 1                /* Compile without unireg */
 
319
#define ENGLISH 1               /* Messages in English */
 
320
#define POSIX_MISTAKE 1         /* regexp: Fix stupid spec error */
 
321
 
 
322
#define QUOTE_ARG(x)            #x      /* Quote argument (before cpp) */
 
323
#define STRINGIFY_ARG(x) QUOTE_ARG(x)   /* Quote argument, after cpp */
 
324
/* Does the system remember a signal handler after a signal ? */
 
325
#ifndef HAVE_BSD_SIGNALS
 
326
#define DONT_REMEMBER_SIGNAL
 
327
#endif
 
328
 
 
329
/* Define void to stop lint from generating "null effekt" comments */
 
330
#ifndef DONT_DEFINE_VOID
 
331
#ifdef _lint
 
332
int     __void__;
 
333
#define VOID(X)         (__void__ = (int) (X))
 
334
#else
 
335
#undef VOID
 
336
#define VOID(X)         (X)
 
337
#endif
 
338
#endif /* DONT_DEFINE_VOID */
 
339
 
122
340
#if !defined(HAVE_UINT)
123
341
#undef HAVE_UINT
124
342
#define HAVE_UINT
130
348
extern char _dig_vec_upper[];
131
349
extern char _dig_vec_lower[];
132
350
 
133
 
#if defined(__cplusplus)
134
 
template <class T>
135
 
inline bool test(const T a)
136
 
{
137
 
  return a ? true : false;
138
 
}
139
 
template <class T, class U>
140
 
inline bool test_all_bits(const T a, const U b)
141
 
{
142
 
  return ((a & b) == b);
143
 
}
144
 
#else
145
 
#define test(a)    ((a) ? 1 : 0)
146
 
#define test_all_bits(a,b) (((a) & (b)) == (b))
147
 
#endif
148
 
 
 
351
#define CMP_NUM(a,b)    (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
 
352
#define sgn(a)          (((a) < 0) ? -1 : ((a) > 0) ? 1 : 0)
 
353
#define swap_variables(t, a, b) { register t dummy; dummy= a; a= b; b= dummy; }
 
354
#define test(a)         ((a) ? 1 : 0)
149
355
#define set_if_bigger(a,b)  do { if ((a) < (b)) (a)=(b); } while(0)
150
 
 
151
356
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
 
357
#define test_all_bits(a,b) (((a) & (b)) == (b))
152
358
#define set_bits(type, bit_count) (sizeof(type)*8 <= (bit_count) ? ~(type) 0 : ((((type) 1) << (bit_count)) - (type) 1))
153
 
#define array_elements(A) ((size_t) (sizeof(A)/sizeof(A[0])))
 
359
#define array_elements(A) ((uint32_t) (sizeof(A)/sizeof(A[0])))
 
360
#ifndef HAVE_RINT
 
361
#define rint(A) floor((A)+(((A) < 0)? -0.5 : 0.5))
 
362
#endif
 
363
 
 
364
#if defined(__GNUC__)
 
365
#define function_volatile       volatile
 
366
#define my_reinterpret_cast(A) reinterpret_cast<A>
 
367
#define my_const_cast(A) const_cast<A>
 
368
# ifndef GCC_VERSION
 
369
#  define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
 
370
# endif
 
371
#elif !defined(my_reinterpret_cast)
 
372
#define my_reinterpret_cast(A) (A)
 
373
#define my_const_cast(A) (A)
 
374
#endif
 
375
 
 
376
/* From old s-system.h */
 
377
 
 
378
/*
 
379
  Support macros for non ansi & other old compilers. Since such
 
380
  things are no longer supported we do nothing. We keep then since
 
381
  some of our code may still be needed to upgrade old customers.
 
382
*/
 
383
#define _VARARGS(X) X
 
384
#define _STATIC_VARARGS(X) X
 
385
#define _PC(X)  X
 
386
 
 
387
#define MIN_ARRAY_SIZE  0       /* Zero or One. Gcc allows zero*/
 
388
#define ASCII_BITS_USED 8       /* Bit char used */
154
389
 
155
390
/* Some types that is different between systems */
156
391
 
157
 
typedef int  File;    /* File descriptor */
158
 
 
 
392
typedef int     File;           /* File descriptor */
 
393
/* Type for fuctions that handles signals */
 
394
#define sig_handler RETSIGTYPE
 
395
C_MODE_START
 
396
typedef void    (*sig_return)(void);/* Returns type from signal */
 
397
typedef int     (*qsort_cmp)(const void *,const void *);
 
398
typedef int     (*qsort_cmp2)(void*, const void *,const void *);
 
399
C_MODE_END
 
400
#define qsort_t RETQSORTTYPE    /* Broken GCC cant handle typedef !!!! */
159
401
#ifdef HAVE_SYS_SOCKET_H
160
402
#include <sys/socket.h>
161
403
#endif
 
404
typedef SOCKET_SIZE_TYPE size_socket;
 
405
 
 
406
#ifndef SOCKOPT_OPTLEN_TYPE
 
407
#define SOCKOPT_OPTLEN_TYPE size_socket
 
408
#endif
162
409
 
163
410
/* file create flags */
164
411
 
165
 
#ifndef O_SHARE      /* Probably not windows */
166
 
#define O_SHARE    0  /* Flag to my_open for shared files */
 
412
#ifndef O_SHARE                 /* Probably not windows */
 
413
#define O_SHARE         0       /* Flag to my_open for shared files */
167
414
#endif /* O_SHARE */
168
415
 
169
416
#ifndef O_BINARY
170
 
#define O_BINARY  0  /* Flag to my_open for binary files */
 
417
#define O_BINARY        0       /* Flag to my_open for binary files */
171
418
#endif
172
419
 
173
420
#ifndef FILE_BINARY
174
 
#define FILE_BINARY  O_BINARY /* Flag to my_fopen for binary streams */
 
421
#define FILE_BINARY     O_BINARY /* Flag to my_fopen for binary streams */
175
422
#endif
176
423
 
177
 
#define F_TO_EOF  0L  /* Param to lockf() to lock rest of file */
 
424
#define F_TO_EOF        0L      /* Param to lockf() to lock rest of file */
178
425
 
179
426
#ifndef O_TEMPORARY
180
 
#define O_TEMPORARY  0
 
427
#define O_TEMPORARY     0
181
428
#endif
182
429
#ifndef O_SHORT_LIVED
183
 
#define O_SHORT_LIVED  0
 
430
#define O_SHORT_LIVED   0
184
431
#endif
185
432
#ifndef O_NOFOLLOW
186
433
#define O_NOFOLLOW      0
187
434
#endif
188
435
 
189
 
 
 
436
/* #define USE_RECORD_LOCK      */
 
437
 
 
438
        /* Unsigned types supported by the compiler */
 
439
#define UNSINT8                 /* unsigned int8_t (char) */
 
440
#define UNSINT16                /* unsigned int16_t */
 
441
#define UNSINT32                /* unsigned int32_t */
 
442
 
 
443
        /* General constants */
 
444
#define SC_MAXWIDTH     256     /* Max width of screen (for error messages) */
 
445
#define FN_LEN          256     /* Max file name len */
 
446
#define FN_HEADLEN      253     /* Max length of filepart of file name */
 
447
#define FN_EXTLEN       20      /* Max length of extension (part of FN_LEN) */
 
448
#define FN_REFLEN       512     /* Max length of full path-name */
 
449
#define FN_EXTCHAR      '.'
 
450
#define FN_HOMELIB      '~'     /* ~/ is used as abbrev for home dir */
 
451
#define FN_CURLIB       '.'     /* ./ is used as abbrev for current dir */
 
452
#define FN_PARENTDIR    ".."    /* Parent directory; Must be a string */
190
453
 
191
454
#ifndef FN_LIBCHAR
192
 
#define FN_LIBCHAR  '/'
193
 
#define FN_ROOTDIR  "/"
 
455
#define FN_LIBCHAR      '/'
 
456
#define FN_ROOTDIR      "/"
194
457
#endif
195
 
#define MY_NFILE  64  /* This is only used to save filenames */
 
458
#define MY_NFILE        64      /* This is only used to save filenames */
196
459
#ifndef OS_FILE_LIMIT
197
 
#define OS_FILE_LIMIT  65535
 
460
#define OS_FILE_LIMIT   65535
198
461
#endif
199
462
 
 
463
/* #define EXT_IN_LIBNAME     */
 
464
/* #define FN_NO_CASE_SENCE   */
 
465
/* #define FN_UPPER_CASE TRUE */
 
466
 
 
467
/*
 
468
  Io buffer size; Must be a power of 2 and a multiple of 512. May be
 
469
  smaller what the disk page size. This influences the speed of the
 
470
  isam btree library. eg to big to slow.
 
471
*/
 
472
#define IO_SIZE                 4096
200
473
/*
201
474
  How much overhead does malloc have. The code often allocates
202
475
  something like 1024-MALLOC_OVERHEAD bytes
203
476
*/
204
477
#define MALLOC_OVERHEAD 8
205
478
 
206
 
/* get memory in huncs */
207
 
#define ONCE_ALLOC_INIT    (uint) (4096-MALLOC_OVERHEAD)
208
 
/* Typical record cash */
209
 
#define RECORD_CACHE_SIZE  (uint) (64*1024-MALLOC_OVERHEAD)
210
 
/* Typical key cash */
211
 
#define KEY_CACHE_SIZE    (uint) (8*1024*1024-MALLOC_OVERHEAD)
212
 
/* Default size of a key cache block  */
213
 
#define KEY_CACHE_BLOCK_SIZE  (uint) 1024
214
 
 
215
 
 
216
 
/* Some things that this system doesn't have */
 
479
        /* get memory in huncs */
 
480
#define ONCE_ALLOC_INIT         (uint) (4096-MALLOC_OVERHEAD)
 
481
        /* Typical record cash */
 
482
#define RECORD_CACHE_SIZE       (uint) (64*1024-MALLOC_OVERHEAD)
 
483
        /* Typical key cash */
 
484
#define KEY_CACHE_SIZE          (uint) (8*1024*1024-MALLOC_OVERHEAD)
 
485
        /* Default size of a key cache block  */
 
486
#define KEY_CACHE_BLOCK_SIZE    (uint) 1024
 
487
 
 
488
 
 
489
        /* Some things that this system doesn't have */
217
490
 
218
491
/* Some defines of functions for portability */
219
492
 
220
 
#undef remove    /* Crashes MySQL on SCO 5.0.0 */
 
493
#undef remove           /* Crashes MySQL on SCO 5.0.0 */
221
494
#ifndef uint64_t2double
222
495
#define uint64_t2double(A) ((double) (uint64_t) (A))
223
496
#define my_off_t2double(A)  ((double) (my_off_t) (A))
227
500
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
228
501
#endif
229
502
#define ulong_to_double(X) ((double) (ulong) (X))
 
503
#define SET_STACK_SIZE(X)       /* Not needed on real machines */
230
504
 
231
505
#ifndef STACK_DIRECTION
232
506
#error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
249
523
 
250
524
/* From limits.h instead */
251
525
#ifndef DBL_MIN
252
 
#define DBL_MIN    4.94065645841246544e-324
 
526
#define DBL_MIN         4.94065645841246544e-324
253
527
#endif
254
528
#ifndef DBL_MAX
255
 
#define DBL_MAX    1.79769313486231470e+308
 
529
#define DBL_MAX         1.79769313486231470e+308
256
530
#endif
257
531
#ifndef SIZE_T_MAX
258
532
#define SIZE_T_MAX ~((size_t) 0)
259
533
#endif
260
534
 
 
535
#ifndef isfinite
 
536
#ifdef HAVE_FINITE
 
537
#define isfinite(x) finite(x)
 
538
#else
 
539
#define finite(x) (1.0 / fabs(x) > 0.0)
 
540
#endif /* HAVE_FINITE */
 
541
#endif /* isfinite */
 
542
 
 
543
#ifndef HAVE_ISNAN
 
544
#define isnan(x) ((x) != (x))
 
545
#endif
 
546
 
 
547
#ifdef HAVE_ISINF
 
548
/* isinf() can be used in both C and C++ code */
 
549
#define my_isinf(X) isinf(X)
 
550
#else
 
551
#define my_isinf(X) (!isfinite(X) && !isnan(X))
 
552
#endif
261
553
 
262
554
/* Define missing math constants. */
263
555
#ifndef M_PI
275
567
  adressable obj.
276
568
*/
277
569
#if SIZEOF_CHARP == 4
278
 
typedef int32_t    my_ptrdiff_t;
 
570
typedef int32_t         my_ptrdiff_t;
279
571
#else
280
 
typedef int64_t   my_ptrdiff_t;
 
572
typedef int64_t         my_ptrdiff_t;
281
573
#endif
282
574
 
283
 
#define MY_ALIGN(A,L)  (((A) + (L) - 1) & ~((L) - 1))
284
 
#define ALIGN_SIZE(A)  MY_ALIGN((A),sizeof(double))
 
575
#define MY_ALIGN(A,L)   (((A) + (L) - 1) & ~((L) - 1))
 
576
#define ALIGN_SIZE(A)   MY_ALIGN((A),sizeof(double))
285
577
/* Size to make adressable obj. */
286
578
#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
287
 
/* Offset of field f in structure t */
288
 
#define OFFSET(t, f)  ((size_t)(char *)&((t *)0)->f)
289
 
#define ADD_TO_PTR(ptr,size,type) (type) ((unsigned char*) (ptr)+size)
290
 
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((unsigned char*) (A) - (unsigned char*) (B))
 
579
                         /* Offset of field f in structure t */
 
580
#define OFFSET(t, f)    ((size_t)(char *)&((t *)0)->f)
 
581
#define ADD_TO_PTR(ptr,size,type) (type) ((uchar*) (ptr)+size)
 
582
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((uchar*) (A) - (uchar*) (B))
291
583
 
292
584
#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
293
585
#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
294
586
 
 
587
/*
 
588
  Custom version of standard offsetof() macro which can be used to get
 
589
  offsets of members in class for non-POD types (according to the current
 
590
  version of C++ standard offsetof() macro can't be used in such cases and
 
591
  attempt to do so causes warnings to be emitted, OTOH in many cases it is
 
592
  still OK to assume that all instances of the class has the same offsets
 
593
  for the same members).
 
594
 
 
595
  This is temporary solution which should be removed once File_parser class
 
596
  and related routines are refactored.
 
597
*/
 
598
 
 
599
#define my_offsetof(TYPE, MEMBER) \
 
600
        ((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
 
601
 
 
602
#define NullS           (char *) 0
 
603
 
295
604
/* Typdefs for easyier portability */
296
605
 
 
606
#ifndef HAVE_UCHAR
 
607
typedef unsigned char   uchar;  /* Short for unsigned char */
 
608
#endif
 
609
 
297
610
#if !defined(HAVE_ULONG) && !defined(__USE_MISC)
298
 
typedef unsigned long ulong;      /* Short for unsigned long */
 
611
typedef unsigned long ulong;              /* Short for unsigned long */
299
612
#endif
300
613
 
 
614
#define MY_ERRPTR ((void*)(intptr)1)
 
615
 
301
616
#if SIZEOF_OFF_T > 4 
302
617
typedef uint64_t my_off_t;
303
618
#else
304
619
typedef unsigned long my_off_t;
305
 
#endif
306
 
#define MY_FILEPOS_ERROR  (~(my_off_t) 0)
 
620
#endif 
 
621
#define MY_FILEPOS_ERROR        (~(my_off_t) 0)
307
622
 
308
623
typedef off_t os_off_t;
309
624
 
310
 
typedef int    myf;  /* Type of MyFlags in my_funcs */
 
625
#define socket_errno    errno
 
626
#define SOCKET_EINTR    EINTR
 
627
#define SOCKET_EAGAIN   EAGAIN
 
628
#define SOCKET_ETIMEDOUT SOCKET_EINTR
 
629
#define SOCKET_EWOULDBLOCK EWOULDBLOCK
 
630
#define SOCKET_EADDRINUSE EADDRINUSE
 
631
#define SOCKET_ENFILE   ENFILE
 
632
#define SOCKET_EMFILE   EMFILE
 
633
 
 
634
typedef uint8_t         int7;   /* Most effective integer 0 <= x <= 127 */
 
635
typedef short           int15;  /* Most effective integer 0 <= x <= 32767 */
 
636
typedef int             myf;    /* Type of MyFlags in my_funcs */
 
637
#if !defined(bool) && (!defined(HAVE_BOOL) || !defined(__cplusplus))
 
638
typedef char            bool;   /* Ordinary boolean values 0 1 */
 
639
#endif
 
640
        /* Macros for converting *constants* to the right type */
 
641
#define INT8(v)         (int8_t) (v)
 
642
#define INT16(v)        (int16_t) (v)
 
643
#define INT32(v)        (int32_t) (v)
311
644
#define MYF(v)          (myf) (v)
312
645
 
313
646
/* Defines for time function */
314
 
#define SCALE_SEC  100
315
 
#define SCALE_USEC  10000
316
 
#define MY_HOW_OFTEN_TO_ALARM  2  /* How often we want info on screen */
317
 
#define MY_HOW_OFTEN_TO_WRITE  1000  /* How often we want info on screen */
318
 
 
 
647
#define SCALE_SEC       100
 
648
#define SCALE_USEC      10000
 
649
#define MY_HOW_OFTEN_TO_ALARM   2       /* How often we want info on screen */
 
650
#define MY_HOW_OFTEN_TO_WRITE   1000    /* How often we want info on screen */
 
651
 
 
652
 
 
653
 
 
654
/*
 
655
  Define-funktions for reading and storing in machine independent format
 
656
  (low byte first)
 
657
*/
 
658
 
 
659
/* Optimized store functions for Intel x86 */
 
660
#if defined(__i386__)
 
661
#define sint2korr(A)    (*((int16_t *) (A)))
 
662
#define sint3korr(A)    ((int32_t) ((((uchar) (A)[2]) & 128) ? \
 
663
                                  (((uint32_t) 255L << 24) | \
 
664
                                   (((uint32_t) (uchar) (A)[2]) << 16) |\
 
665
                                   (((uint32_t) (uchar) (A)[1]) << 8) | \
 
666
                                   ((uint32_t) (uchar) (A)[0])) : \
 
667
                                  (((uint32_t) (uchar) (A)[2]) << 16) |\
 
668
                                  (((uint32_t) (uchar) (A)[1]) << 8) | \
 
669
                                  ((uint32_t) (uchar) (A)[0])))
 
670
#define sint4korr(A)    (*((long *) (A)))
 
671
#define uint2korr(A)    (*((uint16_t *) (A)))
 
672
#if defined(HAVE_purify)
 
673
#define uint3korr(A)    (uint32_t) (((uint32_t) ((uchar) (A)[0])) +\
 
674
                                  (((uint32_t) ((uchar) (A)[1])) << 8) +\
 
675
                                  (((uint32_t) ((uchar) (A)[2])) << 16))
 
676
#else
 
677
/*
 
678
   ATTENTION !
 
679
   
 
680
    Please, note, uint3korr reads 4 bytes (not 3) !
 
681
    It means, that you have to provide enough allocated space !
 
682
*/
 
683
#define uint3korr(A)    (long) (*((unsigned int *) (A)) & 0xFFFFFF)
 
684
#endif /* HAVE_purify */
 
685
#define uint4korr(A)    (*((uint32_t *) (A)))
 
686
#define uint5korr(A)    ((uint64_t)(((uint32_t) ((uchar) (A)[0])) +\
 
687
                                    (((uint32_t) ((uchar) (A)[1])) << 8) +\
 
688
                                    (((uint32_t) ((uchar) (A)[2])) << 16) +\
 
689
                                    (((uint32_t) ((uchar) (A)[3])) << 24)) +\
 
690
                                    (((uint64_t) ((uchar) (A)[4])) << 32))
 
691
#define uint6korr(A)    ((uint64_t)(((uint32_t)    ((uchar) (A)[0]))          + \
 
692
                                     (((uint32_t)    ((uchar) (A)[1])) << 8)   + \
 
693
                                     (((uint32_t)    ((uchar) (A)[2])) << 16)  + \
 
694
                                     (((uint32_t)    ((uchar) (A)[3])) << 24)) + \
 
695
                         (((uint64_t) ((uchar) (A)[4])) << 32) +       \
 
696
                         (((uint64_t) ((uchar) (A)[5])) << 40))
 
697
#define uint8korr(A)    (*((uint64_t *) (A)))
 
698
#define sint8korr(A)    (*((int64_t *) (A)))
 
699
#define int2store(T,A)  *((uint16_t*) (T))= (uint16_t) (A)
 
700
#define int3store(T,A)  do { *(T)=  (uchar) ((A));\
 
701
                            *(T+1)=(uchar) (((uint) (A) >> 8));\
 
702
                            *(T+2)=(uchar) (((A) >> 16)); } while (0)
 
703
#define int4store(T,A)  *((long *) (T))= (long) (A)
 
704
#define int5store(T,A)  do { *(T)= (uchar)((A));\
 
705
                             *((T)+1)=(uchar) (((A) >> 8));\
 
706
                             *((T)+2)=(uchar) (((A) >> 16));\
 
707
                             *((T)+3)=(uchar) (((A) >> 24)); \
 
708
                             *((T)+4)=(uchar) (((A) >> 32)); } while(0)
 
709
#define int6store(T,A)  do { *(T)=    (uchar)((A));          \
 
710
                             *((T)+1)=(uchar) (((A) >> 8));  \
 
711
                             *((T)+2)=(uchar) (((A) >> 16)); \
 
712
                             *((T)+3)=(uchar) (((A) >> 24)); \
 
713
                             *((T)+4)=(uchar) (((A) >> 32)); \
 
714
                             *((T)+5)=(uchar) (((A) >> 40)); } while(0)
 
715
#define int8store(T,A)  *((uint64_t *) (T))= (uint64_t) (A)
 
716
 
 
717
typedef union {
 
718
  double v;
 
719
  long m[2];
 
720
} doubleget_union;
 
721
#define doubleget(V,M)  \
 
722
do { doubleget_union _tmp; \
 
723
     _tmp.m[0] = *((long*)(M)); \
 
724
     _tmp.m[1] = *(((long*) (M))+1); \
 
725
     (V) = _tmp.v; } while(0)
 
726
#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
 
727
                             *(((long *) T)+1) = ((doubleget_union *)&V)->m[1]; \
 
728
                         } while (0)
 
729
#define float4get(V,M)   do { *((float *) &(V)) = *((float*) (M)); } while(0)
 
730
#define float8get(V,M)   doubleget((V),(M))
 
731
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
 
732
#define floatstore(T,V)  memcpy((T), (&V), sizeof(float))
 
733
#define floatget(V,M)    memcpy(&V, (M), sizeof(float))
 
734
#define float8store(V,M) doublestore((V),(M))
 
735
#else
 
736
 
 
737
/*
 
738
  We're here if it's not a IA-32 architecture (Win32 and UNIX IA-32 defines
 
739
  were done before)
 
740
*/
 
741
#define sint2korr(A)    (int16_t) (((int16_t) ((uchar) (A)[0])) +\
 
742
                                 ((int16_t) ((int16_t) (A)[1]) << 8))
 
743
#define sint3korr(A)    ((int32_t) ((((uchar) (A)[2]) & 128) ? \
 
744
                                  (((uint32_t) 255L << 24) | \
 
745
                                   (((uint32_t) (uchar) (A)[2]) << 16) |\
 
746
                                   (((uint32_t) (uchar) (A)[1]) << 8) | \
 
747
                                   ((uint32_t) (uchar) (A)[0])) : \
 
748
                                  (((uint32_t) (uchar) (A)[2]) << 16) |\
 
749
                                  (((uint32_t) (uchar) (A)[1]) << 8) | \
 
750
                                  ((uint32_t) (uchar) (A)[0])))
 
751
#define sint4korr(A)    (int32_t) (((int32_t) ((uchar) (A)[0])) +\
 
752
                                (((int32_t) ((uchar) (A)[1]) << 8)) +\
 
753
                                (((int32_t) ((uchar) (A)[2]) << 16)) +\
 
754
                                (((int32_t) ((int16_t) (A)[3]) << 24)))
 
755
#define sint8korr(A)    (int64_t) uint8korr(A)
 
756
#define uint2korr(A)    (uint16_t) (((uint16_t) ((uchar) (A)[0])) +\
 
757
                                  ((uint16_t) ((uchar) (A)[1]) << 8))
 
758
#define uint3korr(A)    (uint32_t) (((uint32_t) ((uchar) (A)[0])) +\
 
759
                                  (((uint32_t) ((uchar) (A)[1])) << 8) +\
 
760
                                  (((uint32_t) ((uchar) (A)[2])) << 16))
 
761
#define uint4korr(A)    (uint32_t) (((uint32_t) ((uchar) (A)[0])) +\
 
762
                                  (((uint32_t) ((uchar) (A)[1])) << 8) +\
 
763
                                  (((uint32_t) ((uchar) (A)[2])) << 16) +\
 
764
                                  (((uint32_t) ((uchar) (A)[3])) << 24))
 
765
#define uint5korr(A)    ((uint64_t)(((uint32_t) ((uchar) (A)[0])) +\
 
766
                                    (((uint32_t) ((uchar) (A)[1])) << 8) +\
 
767
                                    (((uint32_t) ((uchar) (A)[2])) << 16) +\
 
768
                                    (((uint32_t) ((uchar) (A)[3])) << 24)) +\
 
769
                                    (((uint64_t) ((uchar) (A)[4])) << 32))
 
770
#define uint6korr(A)    ((uint64_t)(((uint32_t)    ((uchar) (A)[0]))          + \
 
771
                                     (((uint32_t)    ((uchar) (A)[1])) << 8)   + \
 
772
                                     (((uint32_t)    ((uchar) (A)[2])) << 16)  + \
 
773
                                     (((uint32_t)    ((uchar) (A)[3])) << 24)) + \
 
774
                         (((uint64_t) ((uchar) (A)[4])) << 32) +       \
 
775
                         (((uint64_t) ((uchar) (A)[5])) << 40))
 
776
#define uint8korr(A)    ((uint64_t)(((uint32_t) ((uchar) (A)[0])) +\
 
777
                                    (((uint32_t) ((uchar) (A)[1])) << 8) +\
 
778
                                    (((uint32_t) ((uchar) (A)[2])) << 16) +\
 
779
                                    (((uint32_t) ((uchar) (A)[3])) << 24)) +\
 
780
                        (((uint64_t) (((uint32_t) ((uchar) (A)[4])) +\
 
781
                                    (((uint32_t) ((uchar) (A)[5])) << 8) +\
 
782
                                    (((uint32_t) ((uchar) (A)[6])) << 16) +\
 
783
                                    (((uint32_t) ((uchar) (A)[7])) << 24))) <<\
 
784
                                    32))
 
785
#define int2store(T,A)       do { uint def_temp= (uint) (A) ;\
 
786
                                  *((uchar*) (T))=  (uchar)(def_temp); \
 
787
                                   *((uchar*) (T)+1)=(uchar)((def_temp >> 8)); \
 
788
                             } while(0)
 
789
#define int3store(T,A)       do { /*lint -save -e734 */\
 
790
                                  *((uchar*)(T))=(uchar) ((A));\
 
791
                                  *((uchar*) (T)+1)=(uchar) (((A) >> 8));\
 
792
                                  *((uchar*)(T)+2)=(uchar) (((A) >> 16)); \
 
793
                                  /*lint -restore */} while(0)
 
794
#define int4store(T,A)       do { *((char *)(T))=(char) ((A));\
 
795
                                  *(((char *)(T))+1)=(char) (((A) >> 8));\
 
796
                                  *(((char *)(T))+2)=(char) (((A) >> 16));\
 
797
                                  *(((char *)(T))+3)=(char) (((A) >> 24)); } while(0)
 
798
#define int5store(T,A)       do { *((char *)(T))=     (char)((A));  \
 
799
                                  *(((char *)(T))+1)= (char)(((A) >> 8)); \
 
800
                                  *(((char *)(T))+2)= (char)(((A) >> 16)); \
 
801
                                  *(((char *)(T))+3)= (char)(((A) >> 24)); \
 
802
                                  *(((char *)(T))+4)= (char)(((A) >> 32)); \
 
803
                                } while(0)
 
804
#define int6store(T,A)       do { *((char *)(T))=     (char)((A)); \
 
805
                                  *(((char *)(T))+1)= (char)(((A) >> 8)); \
 
806
                                  *(((char *)(T))+2)= (char)(((A) >> 16)); \
 
807
                                  *(((char *)(T))+3)= (char)(((A) >> 24)); \
 
808
                                  *(((char *)(T))+4)= (char)(((A) >> 32)); \
 
809
                                  *(((char *)(T))+5)= (char)(((A) >> 40)); \
 
810
                                } while(0)
 
811
#define int8store(T,A)       do { uint def_temp= (uint) (A), def_temp2= (uint) ((A) >> 32); \
 
812
                                  int4store((T),def_temp); \
 
813
                                  int4store((T+4),def_temp2); } while(0)
 
814
#ifdef WORDS_BIGENDIAN
 
815
#define float4store(T,A) do { *(T)= ((uchar *) &A)[3];\
 
816
                              *((T)+1)=(char) ((uchar *) &A)[2];\
 
817
                              *((T)+2)=(char) ((uchar *) &A)[1];\
 
818
                              *((T)+3)=(char) ((uchar *) &A)[0]; } while(0)
 
819
 
 
820
#define float4get(V,M)   do { float def_temp;\
 
821
                              ((uchar*) &def_temp)[0]=(M)[3];\
 
822
                              ((uchar*) &def_temp)[1]=(M)[2];\
 
823
                              ((uchar*) &def_temp)[2]=(M)[1];\
 
824
                              ((uchar*) &def_temp)[3]=(M)[0];\
 
825
                              (V)=def_temp; } while(0)
 
826
#define float8store(T,V) do { *(T)= ((uchar *) &V)[7];\
 
827
                              *((T)+1)=(char) ((uchar *) &V)[6];\
 
828
                              *((T)+2)=(char) ((uchar *) &V)[5];\
 
829
                              *((T)+3)=(char) ((uchar *) &V)[4];\
 
830
                              *((T)+4)=(char) ((uchar *) &V)[3];\
 
831
                              *((T)+5)=(char) ((uchar *) &V)[2];\
 
832
                              *((T)+6)=(char) ((uchar *) &V)[1];\
 
833
                              *((T)+7)=(char) ((uchar *) &V)[0]; } while(0)
 
834
 
 
835
#define float8get(V,M)   do { double def_temp;\
 
836
                              ((uchar*) &def_temp)[0]=(M)[7];\
 
837
                              ((uchar*) &def_temp)[1]=(M)[6];\
 
838
                              ((uchar*) &def_temp)[2]=(M)[5];\
 
839
                              ((uchar*) &def_temp)[3]=(M)[4];\
 
840
                              ((uchar*) &def_temp)[4]=(M)[3];\
 
841
                              ((uchar*) &def_temp)[5]=(M)[2];\
 
842
                              ((uchar*) &def_temp)[6]=(M)[1];\
 
843
                              ((uchar*) &def_temp)[7]=(M)[0];\
 
844
                              (V) = def_temp; } while(0)
 
845
#else
 
846
#define float4get(V,M)   memcpy(&V, (M), sizeof(float))
 
847
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
 
848
 
 
849
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
 
850
#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((uchar *) &V)[4];\
 
851
                              *(((char*)T)+1)=(char) ((uchar *) &V)[5];\
 
852
                              *(((char*)T)+2)=(char) ((uchar *) &V)[6];\
 
853
                              *(((char*)T)+3)=(char) ((uchar *) &V)[7];\
 
854
                              *(((char*)T)+4)=(char) ((uchar *) &V)[0];\
 
855
                              *(((char*)T)+5)=(char) ((uchar *) &V)[1];\
 
856
                              *(((char*)T)+6)=(char) ((uchar *) &V)[2];\
 
857
                              *(((char*)T)+7)=(char) ((uchar *) &V)[3]; }\
 
858
                         while(0)
 
859
#define doubleget(V,M)   do { double def_temp;\
 
860
                              ((uchar*) &def_temp)[0]=(M)[4];\
 
861
                              ((uchar*) &def_temp)[1]=(M)[5];\
 
862
                              ((uchar*) &def_temp)[2]=(M)[6];\
 
863
                              ((uchar*) &def_temp)[3]=(M)[7];\
 
864
                              ((uchar*) &def_temp)[4]=(M)[0];\
 
865
                              ((uchar*) &def_temp)[5]=(M)[1];\
 
866
                              ((uchar*) &def_temp)[6]=(M)[2];\
 
867
                              ((uchar*) &def_temp)[7]=(M)[3];\
 
868
                              (V) = def_temp; } while(0)
 
869
#endif /* __FLOAT_WORD_ORDER */
 
870
 
 
871
#define float8get(V,M)   doubleget((V),(M))
 
872
#define float8store(V,M) doublestore((V),(M))
 
873
#endif /* WORDS_BIGENDIAN */
 
874
 
 
875
#endif /* __i386__ */
 
876
 
 
877
/*
 
878
  Macro for reading 32-bit integer from network byte order (big-endian)
 
879
  from unaligned memory location.
 
880
*/
 
881
#define int4net(A)        (int32_t) (((uint32_t) ((uchar) (A)[3]))        |\
 
882
                                  (((uint32_t) ((uchar) (A)[2])) << 8)  |\
 
883
                                  (((uint32_t) ((uchar) (A)[1])) << 16) |\
 
884
                                  (((uint32_t) ((uchar) (A)[0])) << 24))
 
885
/*
 
886
  Define-funktions for reading and storing in machine format from/to
 
887
  short/long to/from some place in memory V should be a (not
 
888
  register) variable, M is a pointer to byte
 
889
*/
 
890
 
 
891
#ifdef WORDS_BIGENDIAN
 
892
 
 
893
#define ushortget(V,M)  do { V = (uint16_t) (((uint16_t) ((uchar) (M)[1]))+\
 
894
                                 ((uint16_t) ((uint16_t) (M)[0]) << 8)); } while(0)
 
895
#define shortget(V,M)   do { V = (short) (((short) ((uchar) (M)[1]))+\
 
896
                                 ((short) ((short) (M)[0]) << 8)); } while(0)
 
897
#define longget(V,M)    do { int32_t def_temp;\
 
898
                             ((uchar*) &def_temp)[0]=(M)[0];\
 
899
                             ((uchar*) &def_temp)[1]=(M)[1];\
 
900
                             ((uchar*) &def_temp)[2]=(M)[2];\
 
901
                             ((uchar*) &def_temp)[3]=(M)[3];\
 
902
                             (V)=def_temp; } while(0)
 
903
#define ulongget(V,M)   do { uint32_t def_temp;\
 
904
                            ((uchar*) &def_temp)[0]=(M)[0];\
 
905
                            ((uchar*) &def_temp)[1]=(M)[1];\
 
906
                            ((uchar*) &def_temp)[2]=(M)[2];\
 
907
                            ((uchar*) &def_temp)[3]=(M)[3];\
 
908
                            (V)=def_temp; } while(0)
 
909
#define shortstore(T,A) do { uint def_temp=(uint) (A) ;\
 
910
                             *(((char*)T)+1)=(char)(def_temp); \
 
911
                             *(((char*)T)+0)=(char)(def_temp >> 8); } while(0)
 
912
#define longstore(T,A)  do { *(((char*)T)+3)=((A));\
 
913
                             *(((char*)T)+2)=(((A) >> 8));\
 
914
                             *(((char*)T)+1)=(((A) >> 16));\
 
915
                             *(((char*)T)+0)=(((A) >> 24)); } while(0)
 
916
 
 
917
#define floatget(V,M)     memcpy(&V, (M), sizeof(float))
 
918
#define floatstore(T, V)   memcpy((T), (&V), sizeof(float))
 
919
#define doubleget(V, M)   memcpy(&V, (M), sizeof(double))
 
920
#define doublestore(T, V)  memcpy((T), &V, sizeof(double))
 
921
#define int64_tget(V, M)   memcpy(&V, (M), sizeof(uint64_t))
 
922
#define int64_tstore(T, V) memcpy((T), &V, sizeof(uint64_t))
 
923
 
 
924
#else
 
925
 
 
926
#define ushortget(V,M)  do { V = uint2korr(M); } while(0)
 
927
#define shortget(V,M)   do { V = sint2korr(M); } while(0)
 
928
#define longget(V,M)    do { V = sint4korr(M); } while(0)
 
929
#define ulongget(V,M)   do { V = uint4korr(M); } while(0)
 
930
#define shortstore(T,V) int2store(T,V)
 
931
#define longstore(T,V)  int4store(T,V)
 
932
#ifndef floatstore
 
933
#define floatstore(T,V)   memcpy((T), (&V), sizeof(float))
 
934
#define floatget(V,M)     memcpy(&V, (M), sizeof(float))
 
935
#endif
 
936
#ifndef doubleget
 
937
#define doubleget(V, M)   memcpy(&V, (M), sizeof(double))
 
938
#define doublestore(T,V)  memcpy((T), &V, sizeof(double))
 
939
#endif /* doubleget */
 
940
#define int64_tget(V,M)   memcpy(&V, (M), sizeof(uint64_t))
 
941
#define int64_tstore(T,V) memcpy((T), &V, sizeof(uint64_t))
 
942
 
 
943
#endif /* WORDS_BIGENDIAN */
 
944
 
 
945
/* my_sprintf  was here. RIP */
319
946
 
320
947
#if defined(HAVE_CHARSET_utf8mb3) || defined(HAVE_CHARSET_utf8mb4)
321
 
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET "utf8"
 
948
#define MYSQL_UNIVERSAL_CLIENT_CHARSET "utf8"
322
949
#else
323
 
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET DRIZZLE_DEFAULT_CHARSET_NAME
 
950
#define MYSQL_UNIVERSAL_CLIENT_CHARSET MYSQL_DEFAULT_CHARSET_NAME
324
951
#endif
325
952
 
326
953
#include <dlfcn.h>
330
957
#define RTLD_NOW 1
331
958
#endif
332
959
 
333
 
#define cmax(a, b)       ((a) > (b) ? (a) : (b))
334
 
#define cmin(a, b)       ((a) < (b) ? (a) : (b))
 
960
/*
 
961
 *  Include standard definitions of operator new and delete.
 
962
 */
 
963
#ifdef __cplusplus
 
964
#include <new>
 
965
#include <string>
 
966
#include <algorithm>
 
967
using namespace std;
 
968
#endif
 
969
#define max(a, b)       ((a) > (b) ? (a) : (b))
 
970
#define min(a, b)       ((a) < (b) ? (a) : (b))
335
971
 
336
972
/* Length of decimal number represented by INT32. */
337
973
#define MY_INT32_NUM_DECIMAL_DIGITS 11