PageRenderTime 68ms CodeModel.GetById 43ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/mysql/include/mysql/my_global.h

http://ghostcb.googlecode.com/
C++ Header | 1530 lines | 1086 code | 164 blank | 280 comment | 98 complexity | 1194f68dc5a7bc77e579f86f36d22132 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file