~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
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 by brian
clean slate
19
20
/* This is the include file that should be included 'first' in every C file. */
21
243.1.11 by Jay Pipes
* Added include guards in a couple places, and removed unecessary
22
#ifndef DRIZZLE_SERVER_GLOBAL_H
23
#define DRIZZLE_SERVER_GLOBAL_H
1 by brian
clean slate
24
25
#if defined(i386) && !defined(__i386__)
26
#define __i386__
27
#endif
28
988.2.1 by Trond Norbye
Undefine _FILE_OFFSET_BITS on Solaris before trying to include config.h
29
#if defined(__sun) && defined(_FILE_OFFSET_BITS)
30
#undef _FILE_OFFSET_BITS
31
#endif
32
549 by Monty Taylor
Took gettext.h out of header files.
33
#include <config.h>
1 by brian
clean slate
34
481.1.9 by Monty Taylor
Added autoconf tests for location of cstdint and cinttypes. Use those in C++ programs now, so that we don't have to define _STDC_LIMIT_MACROS, etc by hand. Stop, in fact, defining those by hand.
35
#if defined(__cplusplus)
481.1.13 by Monty Taylor
Added tests for C99 math extensions for cmath.
36
481.1.9 by Monty Taylor
Added autoconf tests for location of cstdint and cinttypes. Use those in C++ programs now, so that we don't have to define _STDC_LIMIT_MACROS, etc by hand. Stop, in fact, defining those by hand.
37
# include CSTDINT_H
38
# include CINTTYPES_H
481.1.13 by Monty Taylor
Added tests for C99 math extensions for cmath.
39
# include <cstdio>
40
# include <cstdlib>
41
# include <cstddef>
42
# include <cassert>
43
# include <cerrno>
670.1.11 by Monty Taylor
Merged from Toru.
44
# include <sstream>
919.2.22 by Monty Taylor
Fixed the latest stuff on Solaris.
45
# if defined(HAVE_MEMORY)
46
#  include <memory>
47
# endif
48
# if defined(HAVE_TR1_MEMORY)
49
#  include <tr1/memory>
50
# endif
51
# if defined(HAVE_BOOST_SHARED_PTR_HPP)
52
#  include <boost/shared_ptr.hpp>
53
# endif
481.1.13 by Monty Taylor
Added tests for C99 math extensions for cmath.
54
#else
55
# include <stdint.h>
56
# include <inttypes.h>
57
# include <stdio.h>
58
# include <stdlib.h>
59
# include <stddef.h>
60
# include <errno.h>        /* Recommended by debian */
61
/*
62
  A lot of our programs uses asserts, so better to always include it
63
*/
64
# include <assert.h>
65
66
#endif // __cplusplus
67
919.2.14 by Monty Taylor
Use math.h instead of cmath... one of these days...
68
#include <math.h>
69
612.2.13 by Monty Taylor
Work on removing global.h from headers that should be installed.
70
#ifndef EOVERFLOW
71
#define EOVERFLOW 84
72
#endif
73
815.1.6 by Monty Taylor
Some tweaks to get timegm working on Solaris.
74
779.3.47 by Monty Taylor
Fixed solaris fixes on linux.
75
#if TIME_WITH_SYS_TIME
76
# include <sys/time.h>
77
# include <time.h>
78
#else
79
# if HAVE_SYS_TIME_H
80
#  include <sys/time.h>
81
# else
82
#  include <time.h>
83
# endif
84
#endif
815.1.6 by Monty Taylor
Some tweaks to get timegm working on Solaris.
85
86
919.2.22 by Monty Taylor
Fixed the latest stuff on Solaris.
87
#if defined(__cplusplus)
88
# if !defined(SHARED_PTR_NAMESPACE)
89
#  error SHARED_PTR_NAMESPACE not defined, configure error!
90
# endif
923.2.5 by Monty Taylor
Turned shared_ptr check into a warning. Want to leave the check and report in so we can start to figure out where this will or won't be a problem moving forward.
91
# if defined(SHARED_PTR_NAMESPACE)
960.2.6 by Monty Taylor
Turned off shared_ptr in global.h. *doh*
92
//We aren't using this yet - don't actually put in code yet.
93
//using SHARED_PTR_NAMESPACE::shared_ptr;
923.2.5 by Monty Taylor
Turned shared_ptr check into a warning. Want to leave the check and report in so we can start to figure out where this will or won't be a problem moving forward.
94
# endif
923.2.1 by Monty Taylor
Merged from Solaris.
95
#endif /* defined(SHARED_PTR_NAMESPACE) */
919.2.22 by Monty Taylor
Fixed the latest stuff on Solaris.
96
481.1.15 by Monty Taylor
Removed time.h and sys/time.h from global.h.
97
/*
1 by brian
clean slate
98
  Temporary solution to solve bug#7156. Include "sys/types.h" before
99
  the thread headers, else the function madvise() will not be defined
100
*/
101
#if defined(HAVE_SYS_TYPES_H) && ( defined(sun) || defined(__sun) )
102
#include <sys/types.h>
103
#endif
104
316 by Brian Aker
First pass of new sql_db.cc work
105
398.1.10 by Monty Taylor
Actually removed VOID() this time.
106
#include <pthread.h>    /* AIX must have this included first */
107
108
#define _REENTRANT  1  /* Threads requires reentrant code */
1 by brian
clean slate
109
110
#ifdef HAVE_LIMITS_H
111
#include <limits.h>
112
#endif
113
114
#ifdef HAVE_SYS_TYPES_H
115
#include <sys/types.h>
116
#endif
117
#ifdef HAVE_FCNTL_H
118
#include <fcntl.h>
119
#endif
481.1.13 by Monty Taylor
Added tests for C99 math extensions for cmath.
120
1 by brian
clean slate
121
#ifdef HAVE_UNISTD_H
122
#include <unistd.h>
123
#endif
124
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
125
236.1.12 by Monty Taylor
Add global include of sys/stat.h.
126
#ifdef HAVE_SYS_STAT_H
127
# include <sys/stat.h>
128
#endif
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
129
240.1.6 by Toru Maesaka
removed mystring dependencies from libdrizzle.c
130
/* Declared in int2str() */
131
extern char _dig_vec_upper[];
132
extern char _dig_vec_lower[];
133
937.2.6 by Stewart Smith
make set_if_bigger typesafe for C and C++. Fix up everywhere.
134
#ifdef __cplusplus
135
template <class T> void set_if_bigger(T &a, const T &b)
136
{
137
  if (a < b)
138
    a=b;
139
}
140
141
template <class T> void set_if_smaller(T &a, const T &b)
142
{
143
  if (a > b)
144
    a=b;
145
}
146
#else
147
#ifdef __GNUC__
148
#define set_if_bigger(a,b) do {                 \
149
  const typeof(a) _a = (a);                     \
150
  const typeof(b) _b = (b);                     \
151
  (void) (&_a == &_b);                          \
152
  if ((a) < (b)) (a)=(b);                       \
153
  } while(0)
154
#define set_if_smaller(a,b) do {                \
155
  const typeof(a) _a = (a);                     \
156
  const typeof(b) _b = (b);                     \
157
  (void) (&_a == &_b);                          \
158
  if ((a) > (b)) (a)=(b);                       \
159
  } while(0)
160
161
#else
1 by brian
clean slate
162
#define set_if_bigger(a,b)  do { if ((a) < (b)) (a)=(b); } while(0)
163
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
937.2.6 by Stewart Smith
make set_if_bigger typesafe for C and C++. Fix up everywhere.
164
#endif
165
#endif
166
465 by Monty Taylor
Made a few macros into template functions.
167
#define array_elements(A) ((size_t) (sizeof(A)/sizeof(A[0])))
1 by brian
clean slate
168
169
/* Some types that is different between systems */
170
398.1.10 by Monty Taylor
Actually removed VOID() this time.
171
typedef int  File;    /* File descriptor */
398.1.9 by Monty Taylor
Cleaned up stuff out of global.h.
172
1 by brian
clean slate
173
#ifdef HAVE_SYS_SOCKET_H
174
#include <sys/socket.h>
175
#endif
176
177
178
#ifndef FN_LIBCHAR
398.1.10 by Monty Taylor
Actually removed VOID() this time.
179
#define FN_LIBCHAR  '/'
180
#define FN_ROOTDIR  "/"
1 by brian
clean slate
181
#endif
398.1.10 by Monty Taylor
Actually removed VOID() this time.
182
#define MY_NFILE  64  /* This is only used to save filenames */
1 by brian
clean slate
183
#ifndef OS_FILE_LIMIT
398.1.10 by Monty Taylor
Actually removed VOID() this time.
184
#define OS_FILE_LIMIT  65535
1 by brian
clean slate
185
#endif
186
187
/*
188
  How much overhead does malloc have. The code often allocates
189
  something like 1024-MALLOC_OVERHEAD bytes
190
*/
191
#define MALLOC_OVERHEAD 8
192
398.1.10 by Monty Taylor
Actually removed VOID() this time.
193
/* get memory in huncs */
895 by Brian Aker
Completion (?) of uint conversion.
194
#define ONCE_ALLOC_INIT    (uint32_t) (4096-MALLOC_OVERHEAD)
398.1.10 by Monty Taylor
Actually removed VOID() this time.
195
/* Typical record cash */
895 by Brian Aker
Completion (?) of uint conversion.
196
#define RECORD_CACHE_SIZE  (uint32_t) (64*1024-MALLOC_OVERHEAD)
398.1.10 by Monty Taylor
Actually removed VOID() this time.
197
/* Typical key cash */
895 by Brian Aker
Completion (?) of uint conversion.
198
#define KEY_CACHE_SIZE    (uint32_t) (8*1024*1024-MALLOC_OVERHEAD)
398.1.10 by Monty Taylor
Actually removed VOID() this time.
199
/* Default size of a key cache block  */
895 by Brian Aker
Completion (?) of uint conversion.
200
#define KEY_CACHE_BLOCK_SIZE  (uint32_t) 1024
398.1.10 by Monty Taylor
Actually removed VOID() this time.
201
202
203
/* Some things that this system doesn't have */
1 by brian
clean slate
204
205
/* Some defines of functions for portability */
206
398.1.10 by Monty Taylor
Actually removed VOID() this time.
207
#undef remove    /* Crashes MySQL on SCO 5.0.0 */
151 by Brian Aker
Ulonglong to uint64_t
208
#ifndef uint64_t2double
209
#define uint64_t2double(A) ((double) (uint64_t) (A))
1 by brian
clean slate
210
#define my_off_t2double(A)  ((double) (my_off_t) (A))
211
#endif
212
213
#ifndef offsetof
214
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
215
#endif
216
#define ulong_to_double(X) ((double) (ulong) (X))
217
218
#ifndef STACK_DIRECTION
219
#error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
220
#endif
221
77.1.24 by Monty Taylor
Removed non-fcntl code and made it a fatal configure error if it's not there.
222
#ifdef HAVE_FLOAT_H
223
#include <float.h>
224
#else
225
#if !defined(FLT_MIN)
226
#define FLT_MIN         ((float)1.40129846432481707e-45)
227
#endif
228
#if !defined(FLT_MAX)
229
#define FLT_MAX         ((float)3.40282346638528860e+38)
230
#endif
231
#endif
232
1 by brian
clean slate
233
/* From limits.h instead */
234
#ifndef DBL_MIN
398.1.10 by Monty Taylor
Actually removed VOID() this time.
235
#define DBL_MIN    4.94065645841246544e-324
1 by brian
clean slate
236
#endif
237
#ifndef DBL_MAX
398.1.10 by Monty Taylor
Actually removed VOID() this time.
238
#define DBL_MAX    1.79769313486231470e+308
1 by brian
clean slate
239
#endif
240
#ifndef SIZE_T_MAX
241
#define SIZE_T_MAX ~((size_t) 0)
242
#endif
243
244
245
/* Define missing math constants. */
246
#ifndef M_PI
247
#define M_PI 3.14159265358979323846
248
#endif
249
#ifndef M_E
250
#define M_E 2.7182818284590452354
251
#endif
252
#ifndef M_LN2
253
#define M_LN2 0.69314718055994530942
254
#endif
255
256
/*
257
  Max size that must be added to a so that we know Size to make
258
  adressable obj.
259
*/
481.1.21 by Monty Taylor
Got rid of some size testing.
260
typedef ptrdiff_t my_ptrdiff_t;
1 by brian
clean slate
261
398.1.10 by Monty Taylor
Actually removed VOID() this time.
262
#define MY_ALIGN(A,L)  (((A) + (L) - 1) & ~((L) - 1))
263
#define ALIGN_SIZE(A)  MY_ALIGN((A),sizeof(double))
1 by brian
clean slate
264
/* Size to make adressable obj. */
265
#define ALIGN_PTR(A, t) ((t*) MY_ALIGN((A),sizeof(t)))
398.1.10 by Monty Taylor
Actually removed VOID() this time.
266
/* Offset of field f in structure t */
267
#define OFFSET(t, f)  ((size_t)(char *)&((t *)0)->f)
481 by Brian Aker
Remove all of uchar.
268
#define ADD_TO_PTR(ptr,size,type) (type) ((unsigned char*) (ptr)+size)
269
#define PTR_BYTE_DIFF(A,B) (my_ptrdiff_t) ((unsigned char*) (A) - (unsigned char*) (B))
1 by brian
clean slate
270
271
#define MY_DIV_UP(A, B) (((A) + (B) - 1) / (B))
272
#define MY_ALIGNED_BYTE_ARRAY(N, S, T) T N[MY_DIV_UP(S, sizeof(T))]
273
274
/* Typdefs for easyier portability */
275
276
#if !defined(HAVE_ULONG) && !defined(__USE_MISC)
398.1.10 by Monty Taylor
Actually removed VOID() this time.
277
typedef unsigned long ulong;      /* Short for unsigned long */
1 by brian
clean slate
278
#endif
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
279
151 by Brian Aker
Ulonglong to uint64_t
280
typedef uint64_t my_off_t;
1 by brian
clean slate
281
656.1.39 by Monty Taylor
Removed my_seek, my_tell, my_fwrite, my_fseek.
282
#if defined(SIZEOF_OFF_T)
283
# if (SIZEOF_OFF_T == 8)
284
#  define OFF_T_MAX (INT64_MAX)
285
# else
286
#  define OFF_T_MAX (INT32_MAX)
287
# endif
288
#endif
1 by brian
clean slate
289
656.1.39 by Monty Taylor
Removed my_seek, my_tell, my_fwrite, my_fseek.
290
#define MY_FILEPOS_ERROR  -1
1 by brian
clean slate
291
292
/* Defines for time function */
398.1.10 by Monty Taylor
Actually removed VOID() this time.
293
#define SCALE_SEC  100
294
#define SCALE_USEC  10000
295
#define MY_HOW_OFTEN_TO_ALARM  2  /* How often we want info on screen */
296
#define MY_HOW_OFTEN_TO_WRITE  1000  /* How often we want info on screen */
1 by brian
clean slate
297
298
299
#if defined(HAVE_CHARSET_utf8mb3) || defined(HAVE_CHARSET_utf8mb4)
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
300
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET "utf8"
1 by brian
clean slate
301
#else
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
302
#define DRIZZLE_UNIVERSAL_CLIENT_CHARSET DRIZZLE_DEFAULT_CHARSET_NAME
1 by brian
clean slate
303
#endif
304
305
#include <dlfcn.h>
306
307
/* FreeBSD 2.2.2 does not define RTLD_NOW) */
308
#ifndef RTLD_NOW
309
#define RTLD_NOW 1
310
#endif
311
398.1.4 by Monty Taylor
Renamed max/min.
312
#define cmax(a, b)       ((a) > (b) ? (a) : (b))
313
#define cmin(a, b)       ((a) < (b) ? (a) : (b))
1 by brian
clean slate
314
722.1.4 by Monty Taylor
Removed all the setting of DEFS everywhere. Use configmake.h to get the values
315
#define DRIZZLE_SERVER
316
1 by brian
clean slate
317
/* Length of decimal number represented by INT32. */
318
#define MY_INT32_NUM_DECIMAL_DIGITS 11
319
320
/* Length of decimal number represented by INT64. */
321
#define MY_INT64_NUM_DECIMAL_DIGITS 21
322
722.1.3 by Monty Taylor
Cleaned up a few build things.
323
#define PROTOCOL_VERSION 10
324
/*
325
  Io buffer size; Must be a power of 2 and
326
  a multiple of 512. May be
327
  smaller what the disk page size. This influences the speed of the
328
  isam btree library. eg to big to slow.
329
*/
330
#define IO_SIZE 4096
331
/* Max file name len */
332
#define FN_LEN 256
333
/* Max length of extension (part of FN_LEN) */
334
#define FN_EXTLEN 20
335
/* Max length of full path-name */
336
#define FN_REFLEN 512
337
/* File extension character */
338
#define FN_EXTCHAR '.'
339
/* ~ is used as abbrev for home dir */
340
#define FN_HOMELIB '~'
341
/* ./ is used as abbrev for current dir */
342
#define FN_CURLIB '.'
343
/* Parent directory; Must be a string */
344
#define FN_PARENTDIR ".."
345
346
/* Quote argument (before cpp) */
347
#ifndef QUOTE_ARG
348
# define QUOTE_ARG(x) #x
349
#endif
350
/* Quote argument, (after cpp) */
351
#ifndef STRINGIFY_ARG
352
# define STRINGIFY_ARG(x) QUOTE_ARG(x)
353
#endif
354
355
/*
356
 * The macros below are borrowed from include/linux/compiler.h in the
357
 * Linux kernel. Use them to indicate the likelyhood of the truthfulness
358
 * of a condition. This serves two purposes - newer versions of gcc will be
359
 * able to optimize for branch predication, which could yield siginficant
360
 * performance gains in frequently executed sections of the code, and the
361
 * other reason to use them is for documentation
362
 */
363
#if !defined(__GNUC__)
364
#define __builtin_expect(x, expected_value) (x)
365
#endif
366
367
#define likely(x)  __builtin_expect((x),1)
368
#define unlikely(x)  __builtin_expect((x),0)
369
370
1 by brian
clean slate
371
/*
372
  Only Linux is known to need an explicit sync of the directory to make sure a
373
  file creation/deletion/renaming in(from,to) this directory durable.
374
*/
375
#ifdef TARGET_OS_LINUX
376
#define NEED_EXPLICIT_SYNC_DIR 1
377
#endif
378
520.4.43 by mordred
A set of Solaris fixes.
379
/* We need to turn off _DTRACE_VERSION if we're not going to use dtrace */
380
#if !defined(HAVE_DTRACE)
381
# undef _DTRACE_VERSION
382
# define _DTRACE_VERSION 0
383
#endif
384
243.1.11 by Jay Pipes
* Added include guards in a couple places, and removed unecessary
385
#endif /* DRIZZLE_SERVER_GLOBAL_H */