Top   Types   Functions   Classes   Options   Index   Sources 

erwin/defs.h


   1  /* -*- Mode: C -*- */
   2  /*
   3   * Author: Henrik Theiling
   4   * Description: Basic definitions for the Erwin library
   5   *
   6   * @@Begin: Licencing and Copying@@
   7   *
   8   * Copyright (c) Henrik Theiling
   9   * Licence Version 2, Special Version for Erwin.
  10   *
  11   * The term 'this software' used in the following, additional to its
  12   * usual usage, also includes the instantiated source files generated by
  13   * tools of this package.
  14   *
  15   * This software is provided 'as-is', without warranty of any kind,
  16   * express or implied.  In no event will the authors or copyright holders
  17   * be held liable for any damages arising from the use of this software.
  18   *
  19   * Permission is granted to anyone to use this software for any purpose,
  20   * including commercial applications, and to alter it and redistribute it
  21   * freely, subject to the following restrictions:
  22   *
  23   * 1. The origin of this software must not be misrepresented; you must
  24   * not claim that you wrote the original software. If you use this
  25   * software in a product, an acknowledgment in the product documentation
  26   * would be appreciated.
  27   *
  28   * 2. Altered source versions must be plainly marked as such, and must
  29   * not be misrepresented as being the original software.
  30   *
  31   * 3. You must not use any of the names of the authors or copyright
  32   * holders of the original software for advertising or publicity
  33   * pertaining to distribution without specific, written prior permission.
  34   *
  35   * 4. If you change this software and redistribute parts or all of it in
  36   * any form, you must make the source code of the altered version of this
  37   * software available.  As an exception, files that were generated by
  38   * tools of this package may be used freely, including modification.
  39   *
  40   * 5. This notice must not be removed or altered from any source
  41   * distribution.
  42   *
  43   * This licence is governed by the Laws of Germany.  Disputes shall be
  44   * settled by Saarbruecken City Court.
  45   *
  46   * @@End: Licencing and Copying@@
  47   *
  48   * Great help for #define: http://predef.sourceforge.net/
  49   *
  50   */
  51  #ifdef ERWIN_DEBUG_INCLUDE
  52  #warning "Including defs.h."
  53  #endif
  54  
  55  #ifndef Global_ERWIN_DEFS_H
  56  #define Global_ERWIN_DEFS_H
  57  
  58  #ifdef ERWIN_DEBUG_INCLUDE
  59  #  warning "First inclusion of defs.h."
  60  #endif
  61  
  62  --INCLUDE-FORWARDS--
  63  
  64  #ifdef Global_ERWIN_ADAM_NAME
  65  
  66  #include <GlobalP_ADAM.h>
  67  
  68  #COPYDEF ERWIN_VERSION
  69  #COPYDEF ERWIN_CPP_ONLY
  70  #COPYDEF ERWIN_DEFAULT_ASSERTION_FAILED_HANDLER
  71  #COPYDEF ERWIN_ERROR_PRINT
  72  #COPYDEF ERWIN_ERROR_STREAM
  73  #COPYDEF ERWIN_EXPORT
  74  #COPYDEF ERWIN_INLINE_PERHAPS
  75  #COPYDEF ERWIN_OPTIMISE_SIZE
  76  #COPYDEF ERWIN_RAND_MAX
  77  #COPYDEF ERWIN_NEED_DET_RANDOM
  78  #COPYDEF ERWIN_RANDOM
  79  #COPYDEF ERWIN_RANDOM_FUNC
  80  #COPYDEF ERWIN_THREAD_SAFE
  81  #COPYDEF ERWIN_TCALLOC
  82  #COPYDEF ERWIN_TMALLOC
  83  #COPYDEF ERWIN_TO_BOOL
  84  #COPYDEF ERWIN_TREALLOC_ARRAY
  85  #COPYDEF ERWIN_TREALLOC_ATOMS
  86  #COPYDEF ERWIN_TFREE
  87  #COPYDEF BOOL_DEFINED
  88  #COPYDEF ERWIN_FALSE
  89  #COPYDEF ERWIN_TRUE
  90  #COPYDEF ERWIN_EXPLICIT
  91  #COPYDEF ERWIN_USE_EXPLICIT
  92  #COPYDEF ERWIN_USE_MUTABLE
  93  #COPYDEF ERWIN_MUTABLE
  94  
  95  #else /* !defined(Global_ERWIN_ADAM_NAME) */
  96  
  97  #define Global_ERWIN_VERSION(X,Y,Z) (((X) * 1000000UL) | ((Y) * 10000UL) | (Z))
  98  
  99  /* Compatibility #defines */
 100  #define ?Global_ERWIN_COMPAT_VERSION_CODE Global_ERWIN_VERSION(999,0,0)
 101  
 102  #if !defined(Global_ERWINMM_COMPAT1)
 103  #  if Global_ERWIN_COMPAT_VERSION_CODE < Global_ERWIN_VERSION(2,0,0)
 104  #    define Global_ERWIN_COMPAT1 1
 105  #  endif
 106  #endif
 107  
 108  #if !defined(Global_ERWIN_COMPAT_2_0_228)
 109  #  if defined(Global_ERWINMM_COMPAT1) || Global_ERWIN_COMPAT_VERSION_CODE <= Global_ERWIN_VERSION(2,0,228)
 110  #    define Global_ERWIN_COMPAT_2_0_228 1
 111  #  endif
 112  #endif
 113  
 114  #if !defined(Global_ERWIN_COMPAT_2_0_236)
 115  #  if defined(Global_ERWIN_COMPAT_2_0_228) || Global_ERWIN_COMPAT_VERSION_CODE <= Global_ERWIN_VERSION(2,0,236)
 116  #    define Global_ERWIN_COMPAT_2_0_236 1
 117  #  endif
 118  #endif
 119  
 120  #if !defined(Global_ERWIN_COMPAT_2_0_241)
 121  #  if defined(Global_ERWIN_COMPAT_2_0_236) || Global_ERWIN_COMPAT_VERSION_CODE <= Global_ERWIN_VERSION(2,0,241)
 122  #    define Global_ERWIN_COMPAT_2_0_241 1
 123  #  endif
 124  #endif
 125  
 126  #if !defined(Global_ERWIN_COMPAT_2_0_249)
 127  #  if defined(Global_ERWIN_COMPAT_2_0_241) || Global_ERWIN_COMPAT_VERSION_CODE <= Global_ERWIN_VERSION(2,0,249)
 128  #    define Global_ERWIN_COMPAT_2_0_249 1
 129  #  endif
 130  #endif
 131  
 132  #if !defined(Global_ERWIN_COMPAT_2_0_250)
 133  #  if defined(Global_ERWIN_COMPAT_2_0_249) || Global_ERWIN_COMPAT_VERSION_CODE <= Global_ERWIN_VERSION(2,0,250)
 134  #    define Global_ERWIN_COMPAT_2_0_250 1
 135  #  endif
 136  #endif
 137  
 138  #if !defined(Global_ERWIN_COMPAT_2_0_260)
 139  #  if defined(Global_ERWIN_COMPAT_2_0_250) || Global_ERWIN_COMPAT_VERSION_CODE <= Global_ERWIN_VERSION(2,0,260)
 140  #    define Global_ERWIN_COMPAT_2_0_260 1
 141  #  endif
 142  #endif
 143  
 144  #if !defined(Global_ERWIN_COMPAT_2_0_264)
 145  #  if defined(Global_ERWIN_COMPAT_2_0_260) || Global_ERWIN_COMPAT_VERSION_CODE <= Global_ERWIN_VERSION(2,0,264)
 146  #    define Global_ERWIN_COMPAT_2_0_264 1
 147  #  endif
 148  #endif
 149  
 150  
 151  /* C++ hack for some compilers */
 152  #if defined(cplusplus) && !defined(__cplusplus)
 153  #  define __cplusplus 1
 154  #endif
 155  
 156  #if defined(c_plusplus) && !defined(__cplusplus)
 157  #  define __cplusplus 1
 158  #endif
 159  
 160  /* Is this MSVC?  We re-decide that here now, ignoring the -DERWIN_DOS that might
 161   * already be defined. */
 162  #undef ERWIN_MSVC
 163  #if defined(_MSC_VER)
 164  #  define ERWIN_MSVC 1
 165  #endif
 166  
 167  #undef ERWIN_DOS
 168  #if defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
 169  #  define ERWIN_DOS
 170  #endif
 171  
 172  /* ********************************************************************** */
 173  /* #define ERWIN_IGNORE_BROKEN_MS_COMPILER 0 */
 174  /*
 175   * By default, do not ignore a broken MS compiler, but disable some
 176   * functions instead.
 177   */
 178  #define ?ERWIN_IGNORE_BROKEN_MS_COMPILER 0
 179  
 180  /* Is this (Open)Watcom C?
 181   */
 182  #undef ERWIN_WATCOM
 183  #if defined(__WATCOMC__)
 184  #  define ERWIN_WATCOM 1
 185  #endif
 186  
 187  
 188  /* GNU C checks (before config.h is included because of #undef inline) */
 189  #ifdef __GNUC__
 190  
 191  #  undef inline
 192  
 193  #  if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
 194  #    define ERWIN_GNUC_V27X
 195  #  endif
 196  #  if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
 197  #    define ERWIN_GNUC_V28X
 198  #  endif
 199  #  if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 9)
 200  #    define ERWIN_GNUC_V29X
 201  #  endif
 202  #  if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 0)
 203  #    define ERWIN_GNUC_V30X
 204  #  endif
 205  #  if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
 206  #    define ERWIN_GNUC_V31X
 207  #  endif
 208  #  if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
 209  #    define ERWIN_GNUC_V32X
 210  #  endif
 211  #  if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
 212  #    define ERWIN_GNUC_V33X
 213  #  endif
 214  #  if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
 215  #    define ERWIN_GNUC_V34X
 216  #  endif
 217  #  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 0)
 218  #    define ERWIN_GNUC_V40X
 219  #  endif
 220  #  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
 221  #    define ERWIN_GNUC_V41X
 222  #  endif
 223  #  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
 224  #    define ERWIN_GNUC_V42X
 225  #  endif
 226  #  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
 227  #    define ERWIN_GNUC_V43X
 228  #  endif
 229  
 230  #  ifndef ERWIN_NO_ASM
 231  #    ifdef __i386__
 232  #      if defined(ERWIN_GNUC_V29X)
 233  #         define ERWIN_GNUC_I386_ASM_NEW
 234  #      elif defined(ERWIN_GNUC_V27X)
 235  #         define ERWIN_GNUC_I386_ASM_OLD
 236  #      endif
 237  #    endif
 238  #  endif
 239  
 240  #  ifndef ERWIN_NO_ASM
 241  #    if defined(__ppc__) || defined(__powerpc__)
 242  #      if defined(ERWIN_GNUC_V29X)
 243  #         define ERWIN_GNUC_PPC_ASM_NEW
 244  #      endif
 245  #    endif
 246  #  endif
 247  
 248  #  ifndef ERWIN_NO_ASM
 249  #    ifdef __x86_64__
 250  #      if defined(ERWIN_GNUC_V29X)
 251  #         define ERWIN_GNUC_X86_64_ASM_NEW
 252  #      endif
 253  #    endif
 254  #  endif
 255  
 256  #endif /* defined(__GNUC__) */
 257  
 258  #if 1
 259  #  define ?ERWIN_64BIT
 260        /* Deprecated.  Use SIZEOF_VOIDP oder SIZEOF_LONG or whatever instead of
 261         * this coarse-grained thing. */
 262  #else
 263  #  error "This is code is to be deleted."
 264  #  if defined(__LP64__)  || defined(__alpha__)  || defined(__ia64__)   || defined(__ppc64__)  || defined(__s390x__)  || defined(__x86_64__)
 265  #    define ERWIN_64BIT 1
 266  #  else
 267  #    define ERWIN_64BIT 0
 268  #  endif
 269  #endif
 270  
 271  #define ?ERWIN_ARCH_FAST_MUL 1
 272     /* FIXME: make this a configure test, or set it per architecture. */
 273  
 274  #ifdef ERWIN_GNUC_V30X
 275  #  define ?ERWIN_EXPECT(X,Y)   __builtin_expect(X,Y)
 276  #endif
 277  
 278  #define ?ERWIN_EXPECT(X,Y) (X)
 279  
 280  #define ?ERWIN_LIKELY(X) ERWIN_EXPECT(!!(X), 1)
 281     /* 'I think condition X is true.' */
 282     /* Use as follows:
 283      *     if (ERWIN_LIKELY(x > 5)) {
 284      *        ...
 285      *     }
 286      *     else {
 287      *        ...
 288      *     }
 289      * The macro casts to bool (by using '!') so you can use it with pointers, too.
 290      */
 291  
 292  #define ?ERWIN_UNLIKELY(X) ERWIN_EXPECT(!!(X), 0)
 293     /* 'I think condition X is false.' */
 294  
 295  /* Decide which configure file we need */
 296  #ifdef ERWIN_DOS
 297  
 298  #  include <limits.h>
 299  #  include <stdlib.h>
 300  
 301  /* MSVC */
 302  #  ifdef ERWIN_MSVC
 303  
 304  #    ifndef ERWIN_NO_ASM
 305  #      ifdef _M_IX86
 306  #        define ERWIN_MSVC_I386_ASM
 307  #      endif
 308  #    endif
 309  
 310  #    ifdef Global_ERWIN_COMPILING
 311  #      include "--INCPREF2B--erwin/confmsvc.h"
 312  #    else
 313  #      include <--INCPREF2B--erwin/confmsvc.h>
 314  #    endif
 315  
 316  #    define ?Global_ERWIN_OPTIMISE      1
 317  #    define ?Global_ERWIN_OPTIMISE_SIZE 1
 318  
 319  #  endif /* defined(ERWIN_MSVC) */
 320  
 321  /* Watcom */
 322  #  ifdef ERWIN_WATCOM
 323  
 324  #    ifndef ERWIN_NO_ASM
 325  #      ifdef _M_IX86
 326  #        define ERWIN_WATCOM_I386_ASM
 327  #      endif
 328  #    endif
 329  
 330  #    ifdef Global_ERWIN_COMPILING
 331  #      include "--INCPREF2B--erwin/confwtcm.h"
 332  #    else
 333  #      include <--INCPREF2B--erwin/confwtcm.h>
 334  #    endif
 335  
 336  #    define ?Global_ERWIN_OPTIMISE      1
 337  #    define ?Global_ERWIN_OPTIMISE_SIZE 1
 338  
 339  #  endif /* defined(ERWIN_WATCOM) */
 340  
 341  /* djgpp */
 342  #  ifdef ERWIN_CROSS
 343  #    ifdef Global_ERWIN_COMPILING
 344  #      include "--INCPREF2B--erwin/confdj.h"
 345  #    else
 346  #      include <--INCPREF2B--erwin/confdj.h>
 347  #    endif
 348  
 349  #    define ?Global_ERWIN_OPTIMISE      1
 350  #    define ?Global_ERWIN_OPTIMISE_SIZE 1
 351  
 352  #  endif /* defined(ERWIN_CROSS) */
 353  
 354  #else /* defined(ERWIN_DOS) */
 355  
 356  #define ERWIN_UNIX 1
 357  
 358  /* Unix compilers configured via configure script: */
 359  #  ifdef Global_ERWIN_COMPILING
 360  #    include "--INCPREF2B--erwin/config.h"
 361  #  else
 362  #    include <--INCPREF2B--erwin/config.h>
 363  #  endif
 364  
 365  #  ifdef HAVE_LIMITS_H
 366  #    include <limits.h>
 367  #  endif
 368  
 369  #  ifdef HAVE_STDLIB_H
 370  #    include <stdlib.h>
 371  #  endif
 372  
 373  #endif /* defined(ERWIN_DOS) */
 374  
 375  /* Some very simple settings wrt. Win/Unix path issues. */
 376  #define ?ERWIN_PATH_SEP '/'
 377  #define ?ERWIN_PATH_SEP_STR "/"
 378  #define ?ERWIN_DIR_LIST_SEP ':'
 379  #define ?ERWIN_DIR_LIST_SEP_STR ":"
 380  #define ?ERWIN_GLOBAL_CONF_DIR "/etc"
 381  #define ?ERWIN_GLOBAL_CONF_EXT ".conf"
 382  #define ?ERWIN_LOCAL_CONF_PREFIX "."
 383  #define ?ERWIN_LOCAL_CONF_EXT "rc"
 384  
 385  /* Does the compiler know `long long'?
 386   *
 387   * Note: this must *not* be any of the types char,short,int,long, since in C++, we
 388   *       must be able to overlong functions with int, long, and ERWIN_LONG_LONG,
 389   *       so we need distinct types.
 390   */
 391  #ifndef ERWIN_LONG_LONG
 392  #  ifdef SIZEOF_LONG_LONG
 393  #    if SIZEOF_LONG_LONG > 0
 394  
 395  #      define ERWIN_LONG_LONG         long long
 396  
 397  #      define ERWIN_LL_AUX2(X)        X ## LL
 398  #      define ERWIN_LL_AUX(X)         ERWIN_LL_AUX2(X)
 399  #      define ERWIN_LL(X)             ERWIN_LL_AUX(X)
 400  
 401  #      define ERWIN_ULL_AUX2(X)       X ## ULL
 402  #      define ERWIN_ULL_AUX(X)        ERWIN_ULL_AUX2(X)
 403  #      define ERWIN_ULL(X)            ERWIN_ULL_AUX(X)
 404  
 405  #      define ERWIN_SIZEOF_LONG_LONG  SIZEOF_LONG_LONG
 406  
 407  #      define ERWIN_LONG_LONG_V2      1
 408  #    endif
 409  #  endif
 410  #endif
 411  
 412  #define ERWIN_L_AUX2(X)         X ## L
 413  #define ERWIN_L_AUX(X)          ERWIN_L_AUX2(X)
 414  #define ERWIN_L(X)              ERWIN_L_AUX(X)
 415  
 416  #define ERWIN_UL_AUX2(X)        X ## UL
 417  #define ERWIN_UL_AUX(X)         ERWIN_UL_AUX2(X)
 418  #define ERWIN_UL(X)             ERWIN_UL_AUX(X)
 419  
 420  #define ERWIN_F_AUX2(X)         X ## F
 421  #define ERWIN_F_AUX(X)          ERWIN_F_AUX2(X)
 422  #define ERWIN_F(X)              ERWIN_F_AUX(X)
 423  
 424  /* Check whether we have int64_t but no long long.
 425   * (E.g. gcc with -ansi) */
 426  #if !defined(ERWIN_LONG_LONG) && defined(SIZEOF_UINT64_T) && defined(SIZEOF_INT64_T) && defined(__INT64_C) && defined(__UINT64_C)
 427  #  ifdef HAVE_STDINT_H
 428  #    define __STDC_CONSTANT_MACROS 1
 429  #    include <inttypes.h>
 430       /* FIXME:  We should use u?int(8|16|32|64) for ERWIN_[SU](8|16|32|64) if
 431        *         available so that the definitions are consistent with the
 432        *         system definitions.
 433        * FIXME2: This requires that inttypes.h is included all the time.  Think
 434        *         about whether that is good or not.
 435        */
 436  #  endif
 437  #  define ERWIN_LONG_LONG          int64_t
 438  #  define ERWIN_UNSIGNED_LONG_LONG uint64_t
 439  #  define ERWIN_LL_AUX(X)          INT64_C(X)
 440  #  define ERWIN_LL(X)              ERWIN_LL_AUX(X)
 441  #  define ERWIN_ULL_AUX(X)         UINT64_C(X)
 442  #  define ERWIN_ULL(X)             ERWIN_ULL_AUX(X)
 443  #  define ERWIN_SIZEOF_LONG_LONG   SIZEOF_INT64_T
 444  #  define ERWIN_LONG_LONG_V2       1
 445  #endif
 446  
 447  /* Unsigned type */
 448  #  define ?ERWIN_UNSIGNED_LONG_LONG unsigned ??ERWIN_LONG_LONG
 449  
 450  /* Check for old Erwin headers included before and repair the
 451   * situation by adding a definition for ERWIN_SIZEOF_LONG_LONG: */
 452  #if !defined(ERWIN_LONG_LONG_V2) && !defined(ERWIN_SIZEOF_LONG_LONG)
 453  #  ifdef __GNUC__
 454  #    warning "There is an old Erwin header file somewhere included before.  Trying to repair."
 455  #  endif
 456  #  define ERWIN_SIZEOF_LONG_LONG  SIZEOF_LONG_LONG
 457  #  define ERWIN_LONG_LONG_V2      1
 458  #endif
 459  
 460  
 461  #if SIZEOF_LONG_DOUBLE > 0
 462  #  define ?ERWIN_LONG_DOUBLE long double
 463  #endif
 464  
 465  
 466  /* We might still not be allowed to use 64 bit ints. */
 467  #if defined(__STRICT_ANSI__) || !defined(CONFIG_WITH_LONG_LONG)
 468  #  undef ERWIN_LONG_LONG
 469  #  undef ERWIN_UNSIGNED_LONG_LONG
 470  #  undef ERWIN_LONG_DOUBLE
 471  #endif
 472  
 473  
 474  #define ?ERWIN_SIGNED_LONG_LONG ??ERWIN_LONG_LONG
 475  
 476  /* Prefer ERWIN_LONG_LONG for 64 bit int, so that 32 bit and 64 bit machines
 477   * are likely to have the same definitions for all ERWIN_(S|U)(8|16|32|64)
 478   * types.  This will hopefully make life easier.  (This contradicts the
 479   * definitions of glibc's (u)int64_t, however.)
 480   */
 481  /* FIXME: Make ERWIN_S64 and ERWIN_U64 usable as C++ style cast.  We currently
 482   *        don't do that because the fallback definition of ERWIN_UNSIGNED_LONG_LONG
 483   *        requires ERWIN_LONG_LONG to be a macro, not a typedef.  Therefore,
 484   *        making both macros be typedefs would break downward compatibility (unless
 485   *        we implement a hack with typedef + #undef + #define...).
 486   */
 487  
 488  #if defined(ERWIN_S32) && !defined(ERWIN_S32_C)
 489  #  ifdef __GNUC__
 490  #    warning "There is an old Erwin header file somewhere included before.  Trying to repair."
 491  #  endif
 492  #  undef ERWIN_S8
 493  #  undef ERWIN_U8
 494  #  undef ERWIN_S16
 495  #  undef ERWIN_U16
 496  #  undef ERWIN_S32
 497  #  undef ERWIN_U32
 498  #  undef ERWIN_S64
 499  #  undef ERWIN_U64
 500  #endif
 501  
 502  #if 0
 503  #if defined(ERWIN_S32) && !defined(ERWIN_UNSIGNED_SHORT)
 504  #  ifdef __GNUC__
 505  #    warning "There is an old Erwin header file somewhere included before.  Trying to repair."
 506  #  endif
 507  #  undef ERWIN_S8
 508  #  undef ERWIN_U8
 509  #  undef ERWIN_S16
 510  #  undef ERWIN_U16
 511  #  undef ERWIN_S32
 512  #  undef ERWIN_U32
 513  #  undef ERWIN_S64
 514  #  undef ERWIN_U64
 515  #endif
 516  #endif
 517  
 518  #ifndef ERWIN_S32
 519  /* Ensure that the ERWIN_[SU]... macros can be used in C++ style casts and still
 520   * be shown in compiler messages as the underlying type they really are. */
 521  typedef unsigned char  ERWIN_UNSIGNED_CHAR;
 522  typedef signed char    ERWIN_SIGNED_CHAR;
 523  typedef unsigned short ERWIN_UNSIGNED_SHORT;
 524  typedef unsigned long  ERWIN_UNSIGNED_LONG;
 525  #endif
 526  
 527  #ifndef ERWIN_S64
 528  #if defined(ERWIN_SIZEOF_LONG_LONG) && ERWIN_SIZEOF_LONG_LONG == 8 && defined(ERWIN_LONG_LONG)
 529  #  define ERWIN_S64                ERWIN_LONG_LONG
 530  #  define ERWIN_U64                ERWIN_UNSIGNED_LONG_LONG
 531  #  define ERWIN_S64_C              ERWIN_LL
 532  #  define ERWIN_U64_C              ERWIN_ULL
 533  #  define ?ERWIN_S64_TYPE_INFO     ERWIN_LONG_LONG_TYPE_INFO
 534  #  define ?ERWIN_U64_TYPE_INFO     ERWIN_UNSIGNED_LONG_LONG_TYPE_INFO
 535  #  define ?Global_ERWIN_S64_CMP    Global_ERWIN_LONG_LONG_CMP
 536  #  define ?Global_ERWIN_U64_CMP    Global_ERWIN_UNSIGNED_LONG_LONG_CMP
 537  #  define ?Global_ERWIN_S64_HASH   Global_ERWIN_LONG_LONG_HASH
 538  #  define ?Global_ERWIN_U64_HASH   Global_ERWIN_UNSIGNED_LONG_LONG_HASH
 539  #elif SIZEOF_INT == 8
 540  #  define ERWIN_S64                int
 541  #  define ERWIN_U64                unsigned
 542  #  define ERWIN_S64_C(X)           X
 543  #  define ERWIN_U64_C(X)           X
 544  #  define ?ERWIN_S64_TYPE_INFO     int_TYPE_INFO
 545  #  define ?ERWIN_U64_TYPE_INFO     unsigned_TYPE_INFO
 546  #  define ?Global_ERWIN_S64_CMP    Global_INT_CMP
 547  #  define ?Global_ERWIN_U64_CMP    Global_UNSIGNED_CMP
 548  #  define ?Global_ERWIN_S64_HASH   Global_INT_HASH
 549  #  define ?Global_ERWIN_U64_HASH   Global_UNSIGNED_HASH
 550  #elif SIZEOF_LONG == 8
 551  #  define ERWIN_S64                long
 552  #  define ERWIN_U64                ERWIN_UNSIGNED_LONG
 553  #  define ERWIN_S64_C              ERWIN_L
 554  #  define ERWIN_U64_C              ERWIN_UL
 555  #  define ?ERWIN_S64_TYPE_INFO     long_TYPE_INFO
 556  #  define ?ERWIN_U64_TYPE_INFO     unsigned_long_TYPE_INFO
 557  #  define ?Global_ERWIN_S64_CMP    Global_LONG_CMP
 558  #  define ?Global_ERWIN_U64_CMP    Global_UNSIGNED_LONG_CMP
 559  #  define ?Global_ERWIN_S64_HASH   Global_LONG_HASH
 560  #  define ?Global_ERWIN_U64_HASH   Global_UNSIGNED_LONG_HASH
 561  #elif SIZEOF_LONG_LONG == 8 && defined(ERWIN_LONG_LONG)
 562  #  define ERWIN_S64                ERWIN_LONG_LONG
 563  #  define ERWIN_U64                ERWIN_UNSIGNED_LONG_LONG
 564  #  define ERWIN_S64_C              ERWIN_LL
 565  #  define ERWIN_U64_C              ERWIN_ULL
 566  #  define ?ERWIN_S64_TYPE_INFO     long_long_TYPE_INFO
 567  #  define ?ERWIN_U64_TYPE_INFO     unsigned_long_long_TYPE_INFO
 568  #  define ?Global_ERWIN_S64_CMP    Global_LONG_LONG_CMP
 569  #  define ?Global_ERWIN_U64_CMP    Global_UNSIGNED_LONG_LONG_CMP
 570  #  define ?Global_ERWIN_S64_HASH   Global_LONG_LONG_HASH
 571  #  define ?Global_ERWIN_U64_HASH   Global_UNSIGNED_LONG_LONG_HASH
 572  #endif
 573  #endif /* ERWIN_S64 */
 574  
 575  #ifndef ERWIN_S32
 576  #if SIZEOF_INT == 4
 577  #  define ERWIN_S32                int
 578  #  define ERWIN_U32                unsigned
 579  #  define ERWIN_S32_C(X)           X
 580  #  define ERWIN_U32_C(X)           X
 581  #  define ?ERWIN_S32_TYPE_INFO     int_TYPE_INFO
 582  #  define ?ERWIN_U32_TYPE_INFO     unsigned_TYPE_INFO
 583  #  define ?Global_ERWIN_S32_CMP    Global_INT_CMP
 584  #  define ?Global_ERWIN_U32_CMP    Global_UNSIGNED_CMP
 585  #  define ?Global_ERWIN_S32_HASH   Global_INT_HASH
 586  #  define ?Global_ERWIN_U32_HASH   Global_UNSIGNED_HASH
 587  #elif SIZEOF_LONG == 4
 588  #  define ERWIN_S32                long
 589  #  define ERWIN_U32                ERWIN_UNSIGNED_LONG
 590  #  define ERWIN_S32_C              ERWIN_L
 591  #  define ERWIN_U32_C              ERWIN_UL
 592  #  define ?ERWIN_S32_TYPE_INFO     long_TYPE_INFO
 593  #  define ?ERWIN_U32_TYPE_INFO     unsigned_long_TYPE_INFO
 594  #  define ?Global_ERWIN_S32_CMP    Global_LONG_CMP
 595  #  define ?Global_ERWIN_U32_CMP    Global_UNSIGNED_LONG_CMP
 596  #  define ?Global_ERWIN_S32_HASH   Global_LONG_HASH
 597  #  define ?Global_ERWIN_U32_HASH   Global_UNSIGNED_LONG_HASH
 598  #endif
 599  #endif /* ERWIN_S32 */
 600  
 601  #ifndef ERWIN_S16
 602  #if SIZEOF_SHORT == 2
 603  #  define ERWIN_S16                short
 604  #  define ERWIN_U16                ERWIN_UNSIGNED_SHORT
 605  #  define ?ERWIN_S16_TYPE_INFO     short_TYPE_INFO
 606  #  define ?ERWIN_U16_TYPE_INFO     unsigned_short_TYPE_INFO
 607  #  define ?Global_ERWIN_S16_CMP    Global_SHORT_CMP
 608  #  define ?Global_ERWIN_U16_CMP    Global_UNSIGNED_SHORT_CMP
 609  #  define ?Global_ERWIN_S16_HASH   Global_SHORT_HASH
 610  #  define ?Global_ERWIN_U16_HASH   Global_UNSIGNED_SHORT_HASH
 611  #elif SIZEOF_INT == 2
 612  #  define ERWIN_S16                int
 613  #  define ERWIN_U16                unsigned
 614  #  define ?ERWIN_S16_TYPE_INFO     int_TYPE_INFO
 615  #  define ?ERWIN_U16_TYPE_INFO     unsigned_int_TYPE_INFO
 616  #  define ?Global_ERWIN_S16_CMP    Global_INT_CMP
 617  #  define ?Global_ERWIN_U16_CMP    Global_UNSIGNED_CMP
 618  #  define ?Global_ERWIN_S16_HASH   Global_INT_HASH
 619  #  define ?Global_ERWIN_U16_HASH   Global_UNSIGNED_HASH
 620  #endif
 621  #endif /* ERWIN_S16 */
 622  
 623  #ifndef ERWIN_S8
 624  #define ERWIN_S8                   ERWIN_SIGNED_CHAR
 625  #define ERWIN_U8                   ERWIN_UNSIGNED_CHAR
 626  #define ?ERWIN_S8_TYPE_INFO        signed_char_TYPE_INFO
 627  #define ?ERWIN_U8_TYPE_INFO        unsigned_char_TYPE_INFO
 628  #define ?Global_ERWIN_S8_CMP       Global_SIGNED_CHAR_CMP
 629  #define ?Global_ERWIN_U8_CMP       Global_UNSIGNED_CHAR_CMP
 630  #define ?Global_ERWIN_S8_HASH      Global_SIGNED_CHAR_HASH
 631  #define ?Global_ERWIN_U8_HASH      Global_UNSIGNED_CHAR_HASH
 632  #endif /* ERWIN_S8 */
 633  
 634  /* NOTE: We cannot handle sizeof(void(*)()) != sizeof(void*). */
 635  #if SIZEOF_VOIDP <= SIZEOF_INT
 636  #  define ERWIN_PTRINT             unsigned
 637  #  define ?ERWIN_PTRINT_TYPE_INFO  unsigned_TYPE_INFO
 638  #  define ?Global_PTRINT_CMP       Global_UNSIGNED_CMP
 639  #  define ?Global_PTRINT_EQUAL     Global_UNSIGNED_EQUAL
 640  #  define ?Global_PTRINT_HASH      Global_UNSIGNED_HASH
 641  #elif SIZEOF_VOIDP <= SIZEOF_LONG
 642  #  define ERWIN_PTRINT             ERWIN_UNSIGNED_LONG
 643  #  define ?ERWIN_PTRINT_TYPE_INFO  unsigned_long_TYPE_INFO
 644  #  define ?Global_PTRINT_CMP       Global_UNSIGNED_LONG_CMP
 645  #  define ?Global_PTRINT_EQUAL     Global_UNSIGNED_LONG_EQUAL
 646  #  define ?Global_PTRINT_HASH      Global_UNSIGNED_LONG_HASH
 647  #elif defined(ERWIN_UNSIGNED_LONG_LONG) && SIZEOF_VOIDP <= ERWIN_SIZEOF_LONG_LONG
 648  #  define ERWIN_PTRINT             ERWIN_UNSIGNED_LONG_LONG
 649  #  define ?ERWIN_PTRINT_TYPE_INFO  unsigned_long_long_TYPE_INFO
 650  #  define ?Global_PTRINT_CMP       Global_UNSIGNED_LONG_LONG_CMP
 651  #  define ?Global_PTRINT_EQUAL     Global_UNSIGNED_LONG_LONG_EQUAL
 652  #  define ?Global_PTRINT_HASH      Global_UNSIGNED_LONG_LONG_HASH
 653  #else
 654  #  error "Unable to define ERWIN_PTRINT: sizeof(void*) is larger than any known integer type"
 655  #endif
 656  
 657  /* For some macros that need the byte size, not the bit size: */
 658  #define ?ERWIN_UB1 ERWIN_U8
 659  #define ?ERWIN_UB2 ERWIN_U16
 660  #define ?ERWIN_UB4 ERWIN_U32
 661  #define ?ERWIN_UB8 ??ERWIN_U64
 662  #define ?ERWIN_SB1 ERWIN_S8
 663  #define ?ERWIN_SB2 ERWIN_S16
 664  #define ?ERWIN_SB4 ERWIN_S32
 665  #define ?ERWIN_SB8 ??ERWIN_S64
 666  
 667  #ifndef ERWIN_WCHAR_T
 668  #  if SIZEOF_WCHAR_T > 0
 669  #    define ERWIN_WCHAR_T wchar_t
 670  #  elif SIZEOF__WCHAR_T > 0
 671  #    define ERWIN_WCHAR_T _wchar_t
 672  #  elif SIZEOF___WCHAR_T > 0
 673  #    define ERWIN_WCHAR_T __wchar_t
 674  #  elif SIZEOF_INT >= 32
 675  #    define ERWIN_WCHAR_T int
 676  #  elif SIZEOF_LONG >= 32
 677  #    define ERWIN_WCHAR_T long
 678  #  endif
 679  #endif
 680  
 681  #ifndef ERWIN_WINT_T
 682  #  if SIZEOF_WINT_T > 0
 683  #    define ERWIN_WINT_T wint_t
 684  #  elif SIZEOF__WINT_T > 0
 685  #    define ERWIN_WINT_T _wint_t
 686  #  elif SIZEOF___WINT_T > 0
 687  #    define ERWIN_WINT_T __wint_t
 688  #  elif SIZEOF_INT >= 32
 689  #    define ERWIN_WINT_T int
 690  #  elif SIZEOF_LONG >= 32
 691  #    define ERWIN_WINT_T long
 692  #  endif
 693  #endif
 694  
 695  #if defined(ERWIN_WCHAR_T) && defined(ERWIN_WINT_T) && defined(HAVE_WCRTOMB) && HAVE_WCRTOMB && defined(MB_CUR_MAX)
 696  #  define ?ERWIN_WIDE_CHARACTERS 1
 697  #endif
 698  
 699  /* Pretend we can handle CHAR_BIT != 8.  This is in preparation for times
 700   * when we do support such architectures: */
 701  #if defined(CHAR_BIT)
 702  #  define ERWIN_CHAR_BIT CHAR_BIT
 703  #elif defined(CHARBITS)
 704  #  define ERWIN_CHAR_BIT CHARBITS
 705  #elif defined(BITSPERBYTE)
 706  #  define ERWIN_CHAR_BIT BITSPERBYTE
 707  #else
 708  #  define ERWIN_CHAR_BIT 8
 709  #endif
 710  
 711  #define ERWIN_BIT_SIZEOF(X) (sizeof(X) * ERWIN_CHAR_BIT)
 712  
 713  /* But we really can't, so fail if CHAR_BIT != 8: */
 714  #if ERWIN_CHAR_BIT != 8
 715  #   error "We currently do not support CHAR_BIT != 8."
 716  #endif
 717  
 718  /* Define Global_ERWIN_EXPLICIT to be empty or 'explicit'. */
 719  #if defined(__cplusplus) && defined(HAVE_WORKING_EXPLICIT)
 720  #  define Global_ERWIN_EXPLICIT     explicit
 721  #  define Global_ERWIN_USE_EXPLICIT 1
 722  #else
 723  #  define Global_ERWIN_EXPLICIT
 724  #  define Global_ERWIN_USE_EXPLICIT 0
 725  #endif
 726  
 727  /* Define Global_ERWIN_MUTABLE to be empty or 'mutable'. */
 728  #if defined(__cplusplus) && defined(HAVE_WORKING_MUTABLE)
 729  #  define Global_ERWIN_MUTABLE     mutable
 730  #  define Global_ERWIN_USE_MUTABLE 1
 731  #else
 732  #  define Global_ERWIN_MUTABLE
 733  #  define Global_ERWIN_USE_MUTABLE 0
 734  #endif
 735  
 736  
 737  /* Attribute feature of GNU C. */
 738  #ifndef GNUC_ATTRIBUTE
 739  #  if defined(ERWIN_GNUC_V27X) && !defined(ERWIN_NO_CC_EXTENSIONS)
 740  #    define GNUC_ATTRIBUTE(X) __attribute__(X)
 741     /*
 742      * #  ifdef  __cplusplus
 743      * #    define ERWIN_WEAK_STORAGE
 744      * #    define ERWIN_LINK_WEAK    __attribute__((weak))
 745      * #  else
 746      * #    define ERWIN_WEAK_STORAGE
 747      * #    define ERWIN_LINK_WEAK    __attribute__((weak))
 748      * #  endif
 749      */
 750  #  else
 751  #    define GNUC_ATTRIBUTE(X)
 752  #  endif
 753  #endif /* !defined(GNUC_ATTRIBUTE) */
 754  
 755  #ifdef ERWIN_GNUC_V30X
 756  #  define ?GNUC_ATTRIBUTE_V30(X)  GNUC_ATTRIBUTE(X)
 757  #endif
 758  #define ?GNUC_ATTRIBUTE_V30(X)
 759  
 760  #ifdef ERWIN_GNUC_V31X
 761  #  define ?GNUC_ATTRIBUTE_V31(X)  GNUC_ATTRIBUTE(X)
 762  #endif
 763  #define ?GNUC_ATTRIBUTE_V31(X)
 764  
 765  #ifdef ERWIN_GNUC_V32X
 766  #  define ?GNUC_ATTRIBUTE_V32(X)  GNUC_ATTRIBUTE(X)
 767  #endif
 768  #define ?GNUC_ATTRIBUTE_V32(X)
 769  
 770  #ifdef ERWIN_GNUC_V33X
 771  #  define ?GNUC_ATTRIBUTE_V33(X)  GNUC_ATTRIBUTE(X)
 772  #endif
 773  #define ?GNUC_ATTRIBUTE_V33(X)
 774  
 775  #ifdef ERWIN_GNUC_V34X
 776  #  define ?GNUC_ATTRIBUTE_V34(X)  GNUC_ATTRIBUTE(X)
 777  #endif
 778  #define ?GNUC_ATTRIBUTE_V34(X)
 779  
 780  #ifdef ERWIN_GNUC_V40X
 781  #  define ?GNUC_ATTRIBUTE_V40(X)  GNUC_ATTRIBUTE(X)
 782  #endif
 783  #define ?GNUC_ATTRIBUTE_V40(X)
 784  
 785  #ifdef ERWIN_GNUC_V41X
 786  #  define ?GNUC_ATTRIBUTE_V41(X)  GNUC_ATTRIBUTE(X)
 787  #endif
 788  #define ?GNUC_ATTRIBUTE_V41(X)
 789  
 790  #ifdef ERWIN_GNUC_V42X
 791  #  define ?GNUC_ATTRIBUTE_V42(X)  GNUC_ATTRIBUTE(X)
 792  #endif
 793  #define ?GNUC_ATTRIBUTE_V42(X)
 794  
 795  #ifdef ERWIN_GNUC_V43X
 796  #  define ?GNUC_ATTRIBUTE_V43(X)  GNUC_ATTRIBUTE(X)
 797  #endif
 798  #define ?GNUC_ATTRIBUTE_V43(X)
 799  
 800  #if defined(__linux__) && (defined(__i386__) || defined (__x86_64__))
 801  #  define ?GNUC_ATTRIBUTE_V34_X86_LINUX(X)  GNUC_ATTRIBUTE_V34(X)
 802  #endif
 803  #define ?GNUC_ATTRIBUTE_V34_X86_LINUX(X)
 804  
 805  #define ?ATTR_ALWAYS_INLINE               GNUC_ATTRIBUTE_V31((__always_inline__))
 806  #define ?ATTR_CONST                       GNUC_ATTRIBUTE((__const__))
 807  #define ?ATTR_DEPRECATED                  GNUC_ATTRIBUTE_V31((__deprecated__))
 808  #define ?ATTR_FLATTEN                     GNUC_ATTRIBUTE_V41((__flatten__))
 809  #define ?ATTR_FORMAT(A)                   GNUC_ATTRIBUTE((__format__ A))
 810  #define ?ATTR_FORMAT_PRINTF(A,B)          GNUC_ATTRIBUTE((__format__(__printf__,A,B)))
 811  #define ?ATTR_FORMAT_VPRINTF(A)           GNUC_ATTRIBUTE((__format__(__printf__,A,0)))
 812  #define ?ATTR_MALLOC                      GNUC_ATTRIBUTE_V30((__malloc__))
 813  #define ?ATTR_MAY_ALIAS                   GNUC_ATTRIBUTE_V33((__may_alias__))
 814  #define ?ATTR_NOINLINE                    GNUC_ATTRIBUTE_V31((__noinline__))
 815  #define ?ATTR_NONNULL(A)                  GNUC_ATTRIBUTE_V33((__nonnull__ A))
 816  #define ?ATTR_NORETURN                    GNUC_ATTRIBUTE((__noreturn__))
 817  #define ?ATTR_PURE                        GNUC_ATTRIBUTE_V30((__pure__))
 818  #define ?ATTR_SECTION(X)                  GNUC_ATTRIBUTE_V34_X86_LINUX((__section__(X)))
 819  #define ?ATTR_UNUSED                      GNUC_ATTRIBUTE_V30((__unused__))
 820  #define ?ATTR_FUNC_UNUSED                 GNUC_ATTRIBUTE_V30((__unused__))
 821  #define ?ATTR_TYPE_UNUSED                 GNUC_ATTRIBUTE_V30((__unused__))
 822  #define ?ATTR_VARIABLE_UNUSED             GNUC_ATTRIBUTE((__unused__))
 823  #define ?ATTR_USED                        GNUC_ATTRIBUTE_V31((__used__))
 824  #define ?ATTR_WARN_UNUSED_RESULT          GNUC_ATTRIBUTE_V33((__warn_unused_result__))
 825  #define ?ATTR_WEAK                        GNUC_ATTRIBUTE((__weak__))
 826  
 827  /* FIXME: Continue with the macro definitions for GNU attributes. */
 828  
 829  #define ?ATTR_ERRNO_PURE
 830     /* This is just a marker for the developper to show that this function
 831      * would be pure, if it did not set the errno as a side effect.  It
 832      * is there to remind us of a suboptimal design (from the compiler's
 833      * POV)... */
 834  
 835  
 836  #if defined(HAVE_STRERROR_R)
 837  #  define ?ERWIN_GET_STRERRNO(S,N) ((void)(strerror_r(errno,S,N)))
 838  #endif
 839  
 840  #ifndef Global_ERWIN_THREAD_SAFE
 841  #  if defined ERWIN_MSVC || defined ERWIN_WATCOM
 842  #    define ?ERWIN_STRERRNO     (_strerror(NULL))
 843  #  else
 844  #    define ?ERWIN_STRERRNO     (strerror(errno))
 845  #  endif
 846  #endif
 847  
 848  #ifdef HAVE_STRNCPY
 849  #  define ?ERWIN_GET_STRERRNO(S,N) ((void)strncpy(S,??ERWIN_STRERRNO,N))
 850  #endif
 851  
 852  
 853  #ifndef ERWIN_INLINE
 854  #  if defined(__cplusplus)
 855  #    define ERWIN_INLINE inline
 856  #  elif defined(ERWIN_GNUC_V27X) && !defined(ERWIN_NO_CC_EXTENSIONS)
 857  #    define ERWIN_INLINE __inline__
 858  #  elif defined(ERWIN_GNUC_V27X) && defined(__STRICT_ANSI__)
 859  #    define ERWIN_INLINE __inline__
 860  #  elif defined(ERWIN_MSVC) && !defined(ERWIN_NO_CC_EXTENSIONS)
 861  #    define ERWIN_INLINE _inline
 862  #  elif defined(ERWIN_WATCOM) && !defined(ERWIN_NO_CC_EXTENSIONS)
 863  #    define ERWIN_INLINE _inline
 864  #  else
 865  #    define ERWIN_INLINE inline
 866       /* This line looks strange.  But note that `inline' might be re-defined
 867        * by the configure script in config.h if the name is different or if it is
 868        * not working. */
 869  #  endif
 870  #endif
 871  
 872  /*
 873   * GCC's ({ }) feature is deprecated since it does not work well with all versions
 874   * of the compiler.  Actually, the following defined are there for compatibility
 875   * only.  You should use do{ ... }while(0) literally. */
 876  #ifndef ERWIN_BEGIN_GROUP
 877  #  define ERWIN_BEGIN_GROUP  do{
 878  #  define ERWIN_END_GROUP    }while(0)
 879  #endif
 880  
 881  /* Well, this might not be defined on every platform */
 882  #ifdef PATH_MAX
 883  #  define ?ERWIN_PATH_MAX PATH_MAX
 884  #else
 885  #  define ?ERWIN_PATH_MAX 256
 886  #endif
 887  
 888  /* Switch on thread safety in if obviously necessary.  There are two typical system
 889   * #defines that indicate that thread safety is requested.
 890   *
 891   * There is currently only one thing that might not be thread safe: the global
 892   * errno values for the data structures.  We are currently thinking about an
 893   * implementation that does not have them at all (so you need to check the return
 894   * values), but it is not easily implemented since the errno values are used
 895   * internally.
 896   */
 897  #if defined(_REENTRANT) || defined(_THREAD_SAFE)
 898  #  define ?Global_ERWIN_THREAD_SAFE 1
 899  #endif
 900  
 901  /* We do not switch on thread safety just because a possible implementation
 902   * is requested.  Those macro defines are meant to be set for a given
 903   * architecture to give a hint which method is the best to implement thread
 904   * safety:
 905   *
 906   * #if defined(Global_ERWIN_USE_PTHREAD) && Global_ERWIN_USE_PTHREAD
 907   * #  define ?Global_ERWIN_THREAD_SAFE 1
 908   * #endif
 909   * #if defined(Global_ERWIN_USE_THREAD_KEYWORD) && Global_ERWIN_USE_THREAD_KEYWORD
 910   * #  define ?Global_ERWIN_THREAD_SAFE 1
 911   * #endif
 912   */
 913  
 914  /* The preferred way to compile thread safe: we use the __thread keyword.
 915   * There is a nice configure test for this, so we usually find out
 916   * whether it is available.
 917   *
 918   * This is the most elegant and probably efficient method, so it is
 919   * preferred over other methods.  It is currently not supported
 920   * by all platforms (notably Mac OS X), but we will try to define this
 921   * such that it will be autodetected in many cases.
 922   *
 923   * Despite the configure check, the user can disable __thread by defining
 924   * Global_ERWIN_USE_THREAD_KEYWORD to 0.  Setting that variable to 1 does
 925   * not force the usage of __thread, but requests it when possible (i.e.,
 926   * if we know that it works).  If you want to use __thread if possible
 927   * and otherwise use pthread (i.e., you know it works), you have to
 928   * define both macros to 1 (i.e., also Global_ERWIN_USE_PTHREAD).
 929   *
 930   * Current macro logic:
 931   *
 932   * THREAD_SAFE USE_THREAD_KEYWORD USE_PTHREAD What happens?
 933   *
 934   * undef       whatever           whatever    no thread safety
 935   *
 936   * defined     undef or 1         undef       __thread if HAVE_THREAD_KEYWORD,
 937   *                                            otherwise pthread if available,
 938   *                                            otherwise manual impl.
 939   *
 940   * defined     undef or 1         0           __thread if HAVE_THREAD_KEYWORD,
 941   *                                            otherwise manual impl.
 942   *
 943   * defined     0                  undef or 1  pthread if available,
 944   *                                            otherwise manual impl.
 945   *
 946   * defined     0                  0           manual impl.
 947   *
 948   * defined     1                  1           __thread if HAVE_THREAD_KEYWORD,
 949   *                                            pthread otherwise
 950   *
 951   * ('manual impl.' means that there is no global _errno, but each object
 952   * has its own errno member.  This is quite inefficient...)
 953   */
 954  /* if __thread does *not* work, we will not use it: */
 955  #ifndef HAVE_THREAD_KEYWORD
 956  #  define !Global_ERWIN_USE_THREAD_KEYWORD 0
 957  #endif
 958  /* do not use __thread keyword if pthread is explicitly requested instead: */
 959  #if defined(Global_ERWIN_USE_PTHREAD) && Global_ERWIN_USE_PTHREAD
 960  #  define ?Global_ERWIN_USE_THREAD_KEYWORD 0
 961  #endif
 962  /* if __thread does work, we try to use it only if thread safety is requested: */
 963  #if defined(HAVE_THREAD_KEYWORD) && defined(Global_ERWIN_THREAD_SAFE)
 964  #  define ?Global_ERWIN_USE_THREAD_KEYWORD 1
 965  #endif
 966  /* Otherwise, __thread is not used: */
 967  #define ?Global_ERWIN_USE_THREAD_KEYWORD 0
 968  
 969  
 970  /* The __thread keyword might not actually be '__thread' (e.g. MSVC): */
 971  #ifdef HAVE_THREAD_KEYWORD
 972  #  define ?ERWIN_THREAD_KEYWORD __thread
 973  #else
 974  #  define ?ERWIN_THREAD_KEYWORD
 975  #endif
 976  
 977  /* Have another convenince macro to be __thread or empty. */
 978  #if Global_ERWIN_USE_THREAD_KEYWORD
 979  #  define ?Global_ERWIN_THREAD_LOCAL ERWIN_THREAD_KEYWORD
 980  #else
 981  #  define ?Global_ERWIN_THREAD_LOCAL
 982  #endif
 983  
 984  
 985  /* And now for pthreads, another method to compile thread safe.
 986   * If we know it works, so can set HAVE_PTHRAD to 1 if it not
 987   * set otherwise.
 988   *
 989   * We might add a configure check to see whether pthreads work.
 990   */
 991  #if defined(__APPLE__) && defined(__MACH__)
 992  #  define ?Global_ERWIN_USE_PTHREAD 1
 993  #endif
 994  /* By default, we will not try to use it: */
 995  #define ?Global_ERWIN_USE_PTHREAD 0
 996  
 997  /* Only incled <pthread.h> for the implementation, and only use it if we are
 998   * not using the __thread keyword, and, of course, if thread safety is requested:
 999   */
1000  #ifdef Global_ERWIN_THREAD_SAFE
1001  #  ifdef Global_ERWIN_COMPILING
1002  #    if Global_ERWIN_USE_PTHREAD && !Global_ERWIN_USE_THREAD_KEYWORD
1003  #      include <pthread.h>
1004  #    endif
1005  #  endif
1006  
1007  #endif /* Global_ERWIN_THREAD_SAFE */
1008  
1009  
1010  /* Automatically select thread safety if system has that. */
1011  /* Have an easy decision variable to know whether we need to implement errno for
1012   * each object or whether we have a global (possible thread local) version.
1013   *
1014   * This #define must be in sync with map.h, vector.h, list.h.
1015   */
1016  #if !defined(Global_ERWIN_THREAD_SAFE) || Global_ERWIN_USE_THREAD_KEYWORD || Global_ERWIN_USE_PTHREAD
1017  #  define Global_ERWIN_GLOBAL_ERRNO 1
1018  #else
1019  #  define Global_ERWIN_GLOBAL_ERRNO 0
1020  #endif
1021  
1022  
1023  #ifdef Global_ERWIN_COMPAT_2_0_249
1024  #define Global_ERWIN_CPP_ONLY 0
1025  #define BOOL  Global_ERWIN_BOOL
1026  #define TRUE  Global_ERWIN_TRUE
1027  #define FALSE Global_ERWIN_FALSE
1028  #else
1029  #define Global_ERWIN_CPP_ONLY --CPP-ONLY--
1030  #endif
1031  
1032  #if !defined(Global_BOOL_DEFINED) && !defined(Global_ERWIN_BOOL)
1033  
1034  #  define Global_BOOL_DEFINED
1035  
1036  #  if Global_ERWIN_CPP_ONLY
1037  
1038  #  ifndef __cplusplus
1039  #    error  "Please invoke 'untemplatize --init --cpp-lib=0' if you want to compile this with a non-C++ compiler."
1040  #  endif
1041  
1042       /* This helps the compiler generate better code. */
1043       typedef bool Global_ERWIN_BOOL_;
1044  #    define Global_ERWIN_BOOL  Global_ERWIN_BOOL_
1045  #    define Global_ERWIN_FALSE false
1046  #    define Global_ERWIN_TRUE  true
1047  
1048  #  else
1049  
1050       /*
1051        * One possibility would be to use (unsigned) int.
1052        * We use unsigned char.*/
1053       typedef unsigned char Global_erwin_bool_t;
1054  #    define Global_ERWIN_BOOL   Global_erwin_bool_t
1055  #    define Global_ERWIN_FALSE  0
1056  #    define Global_ERWIN_TRUE   1
1057  
1058  #  endif
1059  
1060  #endif
1061  
1062  #ifndef Global_ERWIN_TO_BOOL
1063  #  ifdef __cplusplus
1064  #    define Global_ERWIN_TO_BOOL(X) ((X) ? true : false)
1065  #  else
1066  #    define Global_ERWIN_TO_BOOL(X) ((X) ? Global_ERWIN_TRUE : Global_ERWIN_FALSE)
1067  #  endif
1068  #endif
1069  
1070  #ifdef Global_ERWIN_WEAK_DETERMINISM
1071  #  define Global_ERWIN_REQUIRE_DETERMINISM 1
1072  #endif
1073  
1074  #if defined(Global_ERWIN_REQUIRE_DETERMINISM) || !defined(HAVE_RAND)
1075  #  define Global_ERWIN_RANDOM_FUNC     Global_erwin_det_random
1076  #  define Global_ERWIN_RAND_MAX        0xffffffffUL
1077  #  define Global_ERWIN_NEED_DET_RANDOM 1
1078  #else
1079  #  define Global_ERWIN_RANDOM_FUNC     rand
1080  #  define Global_ERWIN_RAND_MAX        ??RAND_MAX
1081  #endif
1082  
1083  #define ?Global_ERWIN_RANDOM(N) \
1084           ((unsigned long)Global_erwin_hash_into(Global_ERWIN_RANDOM_FUNC(),N))
1085  
1086  #if defined(ERWIN_GNUC_V27X) && !defined(ERWIN_NO_CC_EXTENSIONS)
1087  
1088  #  define ?ERWIN_SUPERFLUOUS_CAST(X,Y)  (Y)
1089  
1090  #  if defined(__OPTIMIZE_SIZE__)
1091  #    define ?Global_ERWIN_OPTIMISE_SIZE 1
1092  #  endif
1093  
1094  #  if defined(__OPTIMIZE__)
1095  
1096  #    define ?Global_ERWIN_OPTIMISE 1
1097  
1098       /* Decide whether we can define 'extern inline' functions in headers.  */
1099  #    define ?ERWIN_EXTERN_INLINE extern ERWIN_INLINE
1100  
1101       /* Decide whether we can use __asm__ on an i386. */
1102  #    if !defined(ERWIN_GNUC_I386_ASM) && !defined(ERWIN_NO_ASM)
1103  #      if defined (ERWIN_GNUC_I386_ASM_OLD) || defined (ERWIN_GNUC_I386_ASM_NEW)
1104  #        define ERWIN_GNUC_I386_ASM 1
1105  #      endif
1106  #    endif
1107  
1108       /* Decide whether we can use __asm__ on a PowerPC.
1109        * Unfortunately, this only works without -ansi on an iBook. */
1110  #    if !defined(ERWIN_GNUC_PPC_ASM) && !defined(ERWIN_NO_ASM)
1111  #      if defined (ERWIN_GNUC_PPC_ASM_NEW) && !defined(__STRICT_ANSI__)
1112  #        define ERWIN_GNUC_PPC_ASM 1
1113  #      endif
1114  #    endif
1115  
1116       /* Decide whether we can use __asm__ on an amd64 (=x64_86). */
1117  #    if !defined(ERWIN_GNUC_X86_64_ASM) && !defined(ERWIN_NO_ASM)
1118  #      if defined (ERWIN_GNUC_X86_64_ASM_NEW)
1119  #        define ERWIN_GNUC_X86_64_ASM 1
1120  #      endif
1121  #    endif
1122  
1123  #  endif
1124  
1125  #else
1126  
1127  #  define ?ERWIN_SUPERFLUOUS_CAST(X,Y)  ((X)(Y))
1128     /* This is for automatic casts that are allowed but that
1129      * some compilers might not like (usually because of `const'
1130      * problems). */
1131  
1132  #endif
1133  
1134  #ifdef ERWIN_EXTERN_INLINE
1135  #  define ?ERWIN_WRAPPER ERWIN_EXTERN_INLINE
1136  #else
1137  #  define ?ERWIN_WRAPPER ERWIN_STATIC_INLINE
1138  #endif
1139  
1140  
1141  #define ?ERWIN_CONCAT_TOKEN_AUX2(A,B) A ## B
1142  #define ?ERWIN_CONCAT_TOKEN_AUX(A,B)  ERWIN_CONCAT_TOKEN_AUX2(A,B)
1143  #define ?ERWIN_CONCAT_TOKEN(A,B)      ERWIN_CONCAT_TOKEN_AUX(A,B)
1144  
1145  #define ?ERWIN_STR_AUX2(X)            #X
1146  #define ?ERWIN_STR_AUX(X)             ERWIN_STR_AUX2(X)
1147  #define ?ERWIN_STR(X)                 ERWIN_STR_AUX(X)
1148  
1149  #define ?ERWIN_GENSYM(A)              ERWIN_CONCAT_TOKEN(A,__LINE__)
1150  
1151  #define ?ERWIN_CONCAT(A,B)            ERWIN_CONCAT_TOKEN(A,B)
1152  
1153    /* BEGIN LISP */
1154    /* (setf (long-float-digits) 200) */
1155  #define ?ERWIN_GOLDEN_RATIO                 0.6180339887498948482045868343656381177203
1156    /* (setq ERWIN_GOLDEN_RATIO  (/ 2 (1+ (sqrt 5L0)))) */
1157  
1158  #define ?ERWIN_GOLDEN_RATIO_SHL_32_RAW      2654435769
1159  #define ?ERWIN_GOLDEN_RATIO_SHL_32_INT_RAW  -1640531527
1160  #define ?ERWIN_GOLDEN_RATIO_SHL_32          ERWIN_UL(ERWIN_GOLDEN_RATIO_SHL_32_RAW)
1161  #define ?ERWIN_GOLDEN_RATIO_SHL_32_INT      ERWIN_L(ERWIN_GOLDEN_RATIO_SHL_32_INT_RAW)
1162    /* (setq ERWIN_GOLDEN_RATIO_SHL_32     (floor (* (expt 2 32) ERWIN_GOLDEN_RATIO))) */
1163    /* (setq ERWIN_GOLDEN_RATIO_SHL_32_INT (- ERWIN_GOLDEN_RATIO_SHL_32 (expt 2 32)))  */
1164  
1165  #define ?ERWIN_GOLDEN_RATIO_SHL_64_RAW      11400714819323198485
1166  #define ?ERWIN_GOLDEN_RATIO_SHL_64_INT_RAW  -7046029254386353131
1167  #define ?ERWIN_GOLDEN_RATIO_SHL_64          ERWIN_ULL(ERWIN_GOLDEN_RATIO_SHL_64_RAW)
1168  #define ?ERWIN_GOLDEN_RATIO_SHL_64_INT      ERWIN_ULL(ERWIN_GOLDEN_RATIO_SHL_64_INT_RAW)
1169    /* (setq ERWIN_GOLDEN_RATIO_SHL_64     (floor (* (expt 2 64) ERWIN_GOLDEN_RATIO))) */
1170    /* (setq ERWIN_GOLDEN_RATIO_SHL_64_INT (- ERWIN_GOLDEN_RATIO_SHL_64 (expt 2 64)))  */
1171  
1172  #define ?ERWIN_GOLDEN_RATIO_APPROX          0.61803398863412439823150634765625
1173    /* (setq ERWIN_GOLDEN_RATIO_APPROX  (* 1L0 (/ ERWIN_GOLDEN_RATIO_SHL_32 (expt 2 32)))) */
1174  
1175  #define ?ERWIN_GOLDEN_RATIO_APPROX_64       0.6180339887498948481529999210426495892534
1176    /* (setq ERWIN_GOLDEN_RATIO_APPROX_64  (* 1L0 (/ ERWIN_GOLDEN_RATIO_SHL_64 (expt 2 64)))) */
1177    /* END LISP */
1178  
1179  
1180  #define ?ERWIN_EPSILON                1e-8
1181  
1182  /* ********************************************************************** */
1183  /* #define Global_ERWIN_HASH_STRENGTH  2 */
1184  /* This can have one of the following values:
1185   *
1186   *   0 - the weakest method: needs no additional data and is not really
1187   *       good.  Only use this when memory is short.
1188   *
1189   *   1 - allocates 1kB of randomised data and hashes the lower
1190   *       8 bits of all data types.  Sufficient for most purposes.
1191   *
1192   *   2 - like 1, but hashes up to 32 bits of each data type.
1193   *       This is the default.  You can try to check whether method 1
1194   *       is faster.  The hash function surely is, but due to weaker
1195   *       distribution, the hash performance in general may decrease
1196   *       in some rare cases (though it is expected that 1 is also a
1197   *       good method).
1198   *
1199   *   3 - like 2, but allocates 4kB of random data to have four different
1200   *       random tables for each byte in longer integer data types.  Also,
1201   *       the string hashing functions make use of all four tables.  This is
1202   *       the strongest, yet slowest method that also uses the most memory.
1203   *       It is usually overkill to use this.
1204   */
1205  
1206  #define ?Global_ERWIN_HASH_STRENGTH  2
1207  
1208  /*
1209   * Preprocessor boolean values.  Will be used when stage0 is working
1210   * (probably in erwin-2.1.x) */
1211  #define ERWIN_THE_BOOL_VALUE_       1
1212  #define ERWIN_THE_BOOL_VALUE_0      0
1213  #define ERWIN_THE_BOOL_VALUE_1      1
1214  #define ERWIN_THE_BOOL_VALUE_no     0
1215  #define ERWIN_THE_BOOL_VALUE_yes    1
1216  #define ERWIN_THE_BOOL_VALUE_false  0
1217  #define ERWIN_THE_BOOL_VALUE_true   1
1218  #define ERWIN_THE_BOOL_VALUE_NO     0
1219  #define ERWIN_THE_BOOL_VALUE_YES    1
1220  #define ERWIN_THE_BOOL_VALUE_FALSE  0
1221  #define ERWIN_THE_BOOL_VALUE_TRUE   1
1222  
1223  #ifndef NDEBUG
1224  #  define ERWIN_THE_BOOL_VALUE_NDEBUG  0
1225  #  define ERWIN_THE_BOOL_VALUE_DEBUG   1
1226  #else
1227  #  define ERWIN_THE_BOOL_VALUE_NDEBUG  1
1228  #  define ERWIN_THE_BOOL_VALUE_DEBUG   0
1229  #endif
1230  
1231  #ifdef RELEASE
1232  #  define ERWIN_THE_BOOL_VALUE_NRELEASE  0
1233  #  define ERWIN_THE_BOOL_VALUE_RELEASE   1
1234  #else
1235  #  define ERWIN_THE_BOOL_VALUE_NRELEASE  1
1236  #  define ERWIN_THE_BOOL_VALUE_RELEASE   0
1237  #endif
1238  
1239  #ifndef ERWIN_BOOL_VALUE
1240  #  define ERWIN_BOOL_VALUE_AUX2(X) ERWIN_THE_BOOL_VALUE_##X
1241  #  define ERWIN_BOOL_VALUE_AUX(X)  ERWIN_BOOL_VALUE_AUX2(X)
1242  #  define ERWIN_BOOL_VALUE(X)      ERWIN_BOOL_VALUE_AUX(X)
1243  #endif
1244  
1245  /* Check how to optimise (this works at least for GNU C) */
1246  #define ?Global_ERWIN_OPTIMISE      0
1247  #define ?Global_ERWIN_OPTIMISE_SIZE 0
1248  
1249  #define ?ERWIN_STATIC_INLINE static ERWIN_INLINE
1250  
1251  #if Global_ERWIN_OPTIMISE_SIZE
1252  #  define ?ERWIN_STATIC_INLINE_SPEED static
1253  #else
1254  #  define ?ERWIN_STATIC_INLINE_SPEED ERWIN_STATIC_INLINE
1255  #endif
1256  /* This is thought to be an indicator that a function is declared static inline
1257   * because we want to speed up execution.
1258   */
1259  
1260  #define ?ERWIN_STATIC_INLINE_ONCE ERWIN_STATIC_INLINE
1261  /* This is thought to be an indicator that a function is declared static inline
1262   * because it is used only once.  Then this may be inlined even if we are optimising
1263   * for size.  Well, of course, only if the compiler throws the static version of
1264   * the function away. */
1265  
1266  
1267  /* Another strange definition.  Again, see maptest2.cpp for details. */
1268  #define ?ERWIN_FLOAT_VOLATILE volatile
1269  
1270  /*
1271   * Memory management for C.
1272   * When the data structures are compiled with C++, the C++ family of
1273   * functions is used if possible (only maps and lists use the C++
1274   * things, since vectors have strange data structures that shrink
1275   * and grow, so realloc is used.  This poses constraints on the
1276   * contained data, of course.  Further, maps use the calloc function
1277   * for the hash table of pointers instead of TNEWARR.
1278   */
1279  
1280  #define ?Global_ERWIN_TMUL_OR_NULL(TYPE,COUNT,EXPR) \
1281          (ERWIN_LIKELY(Global_erwin_mul_ok(COUNT,sizeof(TYPE))) ? ((TYPE*)(EXPR)) : ((TYPE*)NULL))
1282  
1283  #ifndef Global_ERWIN_TMALLOC
1284     /* NOTE:
1285      *    The allocation interface has changed, since it was totally wrong
1286      *    before version 2.1.66203.  It only worked with the default
1287      *    interface.  If you changed the memory management, please excuse
1288      *    any inconveniences if having to fix your code now, but
1289      *    I simply *had* to fix bugs.  The code is fixed in a way that
1290      *    the compiler will throw errors so you'll see how to fix this.
1291      *
1292      *    Functions that add basic functionality similar to that of clib,
1293      *    do not use the following functions, but instead malloc() and free()
1294      *    just as the clib itself.
1295      *
1296      *    The following functions use malloc():
1297      *        Global_string_dup()        - returns pointer to caller
1298      *        Global_string_n_dup()      - returns pointer to caller
1299      *        Global_erwin_merge_sort()  - allocates temporary memory freed
1300      *                                     before returning to caller
1301      *
1302      *    The following functions use free():
1303      *        Global_erwin_merge_sort()
1304      *
1305      *    All other basic functions do *not* allocate memory.
1306      *
1307      *    The interface defined here will provide the memory allocator
1308      *    with as many information as Erwin has, e.g. the old size
1309      *    in realloc, which might come in handy, or the number of
1310      *    elements in an array-delete.  Of course, you may discard
1311      *    any of these if you don't need them.
1312      *
1313      *    All data structure functions use the following interface:
1314      */
1315  
1316  /* Use the default implementation for operator new/operator delete: */
1317  #define ?Global_ERWIN_DEFAULT_NEW_DELETE 1
1318  
1319  /* For non-resizable types: */
1320  /* These must handle byte sizes and TYPE may be 'void'.  They are not
1321   * necessarily used for allocating single TYPE objects, but may be
1322   * used for arrays, too.  The constraint is that the resulting array
1323   * is not resizable.
1324   */
1325  #  define Global_ERWIN_TMALLOC(TYPE,SIZE)             (TYPE*)(malloc (SIZE))
1326  #  define Global_ERWIN_TCALLOC(TYPE,SIZE)             (TYPE*)(calloc (1, SIZE))
1327  #  define Global_ERWIN_TFREE(PTR,TYPE,SIZE)           free(PTR)
1328  
1329  /* For resizable types (arrays of things): */
1330  /* Note: when compiling for C and C++, these will be used for
1331   * resizing vectors, so the copy constructors are *not* invoked.
1332   * Copy constructors are only invoked when compiling exclusively
1333   * for C++.
1334   */
1335  #  define Global_ERWIN_TMALLOC_ARRAY(TYPE,COUNT) \
1336            Global_ERWIN_TMUL_OR_NULL (TYPE, COUNT, malloc (COUNT * sizeof(TYPE)))
1337  
1338     /* We do not trust calloc's int overflow detection.
1339      * FIXME: We should check this in configure. */
1340  #  define Global_ERWIN_TCALLOC_ARRAY(TYPE,COUNT) \
1341            Global_ERWIN_TMUL_OR_NULL (TYPE, COUNT, calloc (COUNT, sizeof(TYPE)))
1342  
1343  #  define Global_ERWIN_TREALLOC_ARRAY(PTR,TYPE,NEWCOUNT,OLDCOUNT) \
1344            Global_ERWIN_TMUL_OR_NULL (TYPE, NEWCOUNT, realloc(PTR,NEWCOUNT * sizeof(TYPE)))
1345  
1346  #  undef  Global_ERWIN_TCREALLOC_ARRAY /*(PTR,TYPE,NEWCOUNT,OLDCOUNT)*/
1347         /* not available in standard libc, so use default implemented below. */
1348  
1349  #  define  Global_ERWIN_TFREE_ARRAY(PTR)  free(PTR)
1350  
1351  /* And the same especially for C++ (where there is neither realloc
1352   * nor clear by default). */
1353  /* non-resizable */
1354  /* This is used to implement the 'operator new', 'operator new[]', 'operator delete',
1355   * 'operator delete[]' (if you do not the default implementation, where these
1356   * macros are not used at all.
1357   */
1358  #  define Global_ERWIN_TNEW(TYPE,SIZE)                (TYPE*)(::operator new(SIZE))
1359  #  undef  Global_ERWIN_TCNEW /*(TYPE,COUNT)*/
1360  #  define Global_ERWIN_TDELETE(PTR,TYPE,SIZE)         ::operator delete(PTR)
1361  
1362  /* resizable */
1363  /* The TNEW_ARRAY should invoke the constructor if there is one.  Note that if
1364   * compiling for C, this function will not be used, so storing C++ types
1365   * with constructors in vectors that need that is only supported when compiling
1366   * Erwin in C++. (There is a hack to still do it: oType_CONSTRUCTOR.).
1367   *
1368   * Also note that TCNEW_ARRAY is only invoked for pointer types.  If it is not
1369   * defined, TNEW_ARRAY will be used and the memory cleared with memset or bzero.
1370   * This is the same behaviour as with TCALLOC_ARRAY and TMALLOC_ARRAY.
1371   */
1372  #  define Global_ERWIN_TNEW_ARRAY(TYPE,COUNT)         new TYPE[COUNT]
1373  #  undef  Global_ERWIN_TCNEW_ARRAY /*(TYPE,COUNT)*/
1374  
1375  #  undef  Global_ERWIN_TRENEW_ARRAY /*(PTR,TYPE,NEWCOUNT,OLDCOUNT)*/
1376  #  undef  Global_ERWIN_TCRENEW_ARRAY /*(PTR,TYPE,NEWCOUNT,OLDCOUNT)*/
1377      /* The C++ standard does not have a concept of reallocation in C++,
1378       * so it is more efficient to use C-style allocation here.
1379       */
1380  
1381  #  define Global_ERWIN_TDELETE_ARRAY(PTR)             delete[] PTR
1382      /* Note: because TDELETE_ARRAY may be invoked by the user (indirectly,
1383       *       anyway), we cannot pass the element count here: we just don't
1384       *       know in all cases.  Internally, we know, be the user should
1385       *       not be required to know.
1386       */
1387  
1388     /* If you decide to use a different menory interfac, a minimal interface must have
1389      * at least the following functions:
1390      *   - Global_ERWIN_TMALLOC
1391      *   - Global_ERWIN_TFREE
1392      *   - Global_ERWIN_TMALLOC_ARRAY
1393      *   - Global_ERWIN_TFREE_ARRAY
1394      *
1395      * There are no default implementations for the _ARRAY macros, because
1396      * Global_ERWIN_TFREE_ARRAY does not have enough parameters to be implemented
1397      * correctly with Global_ERWIN_TFREE in all cases.
1398      *
1399      * All other functions are optional, but there are certain constraints that have
1400      * to be fulfilled if you want to define more than the above four functions:
1401      *
1402      * If you define Global_ERWIN_TNEW, you must at least define Global_ERWIN_TMALLOC
1403      * (and the other mandatory functions), and also Global_ERWIN_TDELETE,
1404      * Global_ERWIN_TNEW_ARRAY, Global_ERWIN_TDELETE_ARRAY.
1405      *
1406      * If you define Global_ERWIN_TMALLOC_ATOMS, you must at least define
1407      * Global_ERWIN_TMALLOC (and the other mandatory functions) and
1408      * Global_ERWIN_TFREE_ATOMS.
1409      *
1410      * If you define Global_ERWIN_TNEW_ATOMS, you must at least define
1411      * Global_ERWIN_TNEW (and all the macros that macro requires to be defined) and
1412      * Global_ERWIN_TDELETE_ATOMS.
1413      *
1414      * Default implementations are used if you do not implement some functions:
1415      *
1416      * The C++ family will be implemented using the C family, unless you define
1417      * Global_ERWIN_TNEW, in which case no default implementation will be used
1418      * for any of the C++ macros.
1419      *
1420      * The _ATOMS family will be implemented using the _ARRAY family, unless you
1421      * define Global_ERWIN_TNEW_ATOMS, in which case no default implementation
1422      * is used at all for any _ATOMS macro.
1423      *
1424      * The clearing macros (TCALLOC*, TCNEW*, TCREALLOC*, TCRENEW*), if missing,
1425      * will be implemented using the non-clearing macros.
1426      *
1427      * The C++ functions are used for internal data structures only if compiling
1428      * with C++.  If they are not defined, the same set as for C is used.  This will
1429      * include the realloc functions, which might cause problems for vectors of objects,
1430      * because the copy constructor will not be called in this case.  If unsure whether
1431      * it works, do provide Global_ERWIN_TNEW and Global_ERWIN_TDELETE (and maybe more)
1432      * to avoid the implementation using the C style functions.
1433      *
1434      * If you define your own allocator functions, the C++ implementation of the data
1435      * structures will define an operator new and operator delete to use your allocators.
1436      * If you do not want this, define Global_ERWIN_DEFAULT_NEW_DELETE to 1.
1437      *
1438      * Functionality:
1439      *  +-----------------+---------------+-----------------------------------------------+
1440      *  |! C              |! C++          |! Description                                  |
1441      *  +-----------------+---------------+-----------------------------------------------+
1442      *  | TMALLOC         | TNEW          | allocate non-resizable memory of a given size |
1443      *  +-----------------+---------------+-----------------------------------------------+
1444      *  | TCALLOC         | TCNEW         | like TMALLOC/TNEW, but memory is 0-filled     |
1445      *  +-----------------+---------------+-----------------------------------------------+
1446      *  | TFREE           | TDELETE       | delete one element of the given type          |
1447      *  +-----------------+---------------+-----------------------------------------------+
1448      *  | TMALLOC_ARRAY   | TNEW_ARRAY    | allocate an array of elements of the given    |
1449      *  |                 |               | type                                          |
1450      *  +-----------------+---------------+-----------------------------------------------+
1451      *  | TCALLOC_ARRAY   | TCNEW_ARRAY   | like TMALLOC_ARRAY/TNEW_ARRAY, but memory is  |
1452      *  |                 |               | filled with 0                                 |
1453      *  +-----------------+---------------+-----------------------------------------------+
1454      *  | TREALLOC_ARRAY  | TRENEW_ARRAY  | reallocate an array of elements of a given    |
1455      *  |                 |               | type                                          |
1456      *  +-----------------+---------------+-----------------------------------------------+
1457      *  | TCREALLOC_ARRAY | TCRENEW_ARRAY | like TREALLOC_ARRAY/TRENEW_ARRAY, but new     |
1458      *  |                 |               | memory is filled with 0                       |
1459      *  +-----------------+---------------+-----------------------------------------------+
1460      *  | TFREE_ARRAY     | TDELETE_ARRAY | delete an array of elements of the given type |
1461      *  +-----------------+---------------+-----------------------------------------------+
1462      *
1463      * Further, there is TMALLOC_ATOMS, TCALLOC_ATOMS, TREALLOC_ATOMS, TCREALLOC_ATOMS, and
1464      * TFREE_ATOMS etc., and the corresponding functions for C++, which are just like
1465      * the _ARRAY variants,  but ensure that no pointers will be stored in the allocated
1466      * memory.  This might be important for garbage collectors.  The _ATOMS macros,
1467      * default to the _ARRAY macros, if TMALLOC_ATOMS is not defined.  If it is defined,
1468      * you have to provide all the other _ATOMS functions you wish to use.
1469      *
1470      * Note that standard C++ interface does not provide implementations for TCNEW and
1471      * TRENEW_ARRAY, since the C++ way of allocation does not provide them.
1472      *
1473      * - TREALLOC_ARRAY/TRENEW_ARRAY:
1474      *       if defined, vectors will probably perform more efficiently.
1475      *
1476      *       Note that for TRENEW_ARRAY, invoking copy constructors correctly
1477      *       might be tricky (there is a reason why C++ only defines new[] and
1478      *       delete[] but nothing like realloc()).
1479      *
1480      * - TCALLOC/TCNEW:
1481      *       if defined, maps will probably perform more efficiently.
1482      *
1483      * - TCREALLOC_ARRAY/TCRENEW_ARRAY:
1484      *       if defined, nothing currently changes.
1485      *
1486      * If TMALLOC_ARRAY/TNEW_ARRAY is NOT defined, the implementations of maps and vectors
1487      * become less efficient, because a new type for each used element size will have to
1488      * be used.  The structures will only resize in factors of 2 in that case, so the
1489      * realloc triggering will be less fine-grained.
1490      *
1491      * Note: When compiling under C++ with the standard settings, you can force the
1492      * usage of C memory management for vectors by #defining VECTOR_..._USE_C_MM.
1493      * This will probably make the implementation more efficient.
1494      * See vector_..._u.h.
1495      *
1496      * Note: The top level structs that are created for a data structure will
1497      *     be allocated either with the C functions, or by yourself by using
1498      *     the new/delete operators.  Be aware that you cannot mix construction/
1499      *     destruction of C and C++ on the same data structure although the
1500      *     structure can otherwise be used in both languages.
1501      */
1502  
1503  #else /* defined(Global_ERWIN_TMALLOC) */
1504     /* See if someone has programmed an  old interface: */
1505  
1506  #  ifdef Global_ERWIN_FREE
1507  
1508  #    error "Please fix your memory management macros for new version of Erwin."
1509         /* Old interface: FREE is now TFREE.  Without another layer of
1510          * macros, we cannot make a wrapper.  Assumingly no one has
1511          * ever uses this interface so far, so simply generate an error
1512          * until someone complains. */
1513  
1514  #  endif
1515  
1516  #endif  /* defined(Global_ERWIN_TMALLOC) */
1517  
1518  
1519  #define ?Global_ERWIN_PTR_ASSIGN(P,Q)  ((P)=(Q))
1520     /* This can be overridded and used for debugging, e.g. using Boehm's GC_PTR_STORE.
1521      *
1522      * Note: this must be an expression, so no do{...}while(0) is allowed!
1523      *
1524      * Although this macro does not need to be properly parenthesized as macros usually
1525      * need to be, it is a good custom to still do that.
1526      */
1527  
1528  
1529  /* Nicer wrappers around the bare interface: */
1530  
1531  /* The following are used by the implementations of the data structures.
1532   * The definitions may change, so do not use yourself.
1533   *
1534   * Only use C++ function if the library is exclusively for C++.  Otherwise,
1535   * we must use C allocation, since some data structures may be passed to
1536   * the user, e.g. the internal vector of vectors in _as_array_detach().
1537   * This must be freeable with free() in C.
1538   *
1539   * I'm affraid this change (2.0.64631) affects the API.
1540   *
1541   * The raw macros are not expected to contain a correct macro structure, so
1542   * we use many parens and do{}while() to ensure one in own internal macros.
1543   */
1544  
1545  /* If not available, implement the clearing functions using the helper erwin_memset0() (base.c)
1546   * It is assumed that the multiplication constraints have been checked already (whether
1547   * (C)*sizeof(T) overflows or not).
1548   */
1549  
1550  /* Have nice TCLEAR macros: */
1551  #define ?Global_ERWIN_TCLEAR(T,P,S) \
1552                 ((T*)Global_erwin_memset0((void*)(P), 0, S))
1553  
1554  #define ?Global_ERWIN_TCLEAR_ARRAY(T,P,N,O) \
1555                 ((T*)Global_erwin_memset0((void*)(P), (O)*sizeof(T), (N)*sizeof(T)))
1556  
1557  
1558  /* For C: */
1559  #define ?Global_ERWIN_TCALLOC(T,S) \
1560                 Global_ERWIN_TCLEAR(T, ??Global_ERWIN_TMALLOC(T,S), S)
1561  
1562  #define ?Global_ERWIN_TCALLOC_ARRAY(T,C) \
1563                 Global_ERWIN_TCLEAR_ARRAY(T, ??Global_ERWIN_TMALLOC_ARRAY(T,C), C, 0)
1564  
1565  #define ?Global_ERWIN_TCREALLOC_ARRAY(P,T,N,O) \
1566                 Global_ERWIN_TCLEAR_ARRAY(T, ??Global_ERWIN_TREALLOC_ARRAY(P,T,N,O), N, O)
1567  
1568  
1569  /* For C++: */
1570  #define ?Global_ERWIN_TCNEW(T,S) \
1571                 Global_ERWIN_TCLEAR(T, ??Global_ERWIN_TNEW(T,S), S)
1572  
1573  #define ?Global_ERWIN_TCNEW_ARRAY(T,C) \
1574                 Global_ERWIN_TCLEAR_ARRAY(T, ??Global_ERWIN_TNEW_ARRAY(T,C), C, 0)
1575  
1576  #define ?Global_ERWIN_TCRENEW_ARRAY(P,T,N,O) \
1577                 Global_ERWIN_TCLEAR_ARRAY(T, ??Global_ERWIN_TRENEW_ARRAY(P,T,N,O), N, O)
1578  
1579  
1580  #ifndef Global_ERWIN_TMALLOC_ATOMS
1581  /* Use _ARRAY as default for _ATOMS: */
1582  
1583  #define ?Global_ERWIN_TMALLOC_ATOMS    ??Global_ERWIN_TMALLOC_ARRAY
1584  #define ?Global_ERWIN_TCALLOC_ATOMS    ??Global_ERWIN_TCALLOC_ARRAY
1585  #define ?Global_ERWIN_TREALLOC_ATOMS   ??Global_ERWIN_TREALLOC_ARRAY
1586  #define ?Global_ERWIN_TRECALLOC_ATOMS  ??Global_ERWIN_TRECALLOC_ARRAY
1587  #define ?Global_ERWIN_TFREE_ATOMS      ??Global_ERWIN_TFREE_ARRAY
1588  
1589  #define ?Global_ERWIN_TNEW_ATOMS       ??Global_ERWIN_TNEW_ARRAY
1590  #define ?Global_ERWIN_TCNEW_ATOMS      ??Global_ERWIN_TCNEW_ARRAY
1591  #define ?Global_ERWIN_TRENEW_ATOMS     ??Global_ERWIN_TRENEW_ARRAY
1592  #define ?Global_ERWIN_TRECNEW_ATOMS    ??Global_ERWIN_TRECNEW_ARRAY
1593  #define ?Global_ERWIN_TDELETE_ATOMS    ??Global_ERWIN_TDELETE_ARRAY
1594  
1595  #endif
1596  
1597  
1598  #if defined(__cplusplus) && defined(Global_ERWIN_TNEW) && Global_ERWIN_CPP_ONLY && !defined(Global_ERWIN_C_MM)
1599  
1600  #  define Global_ERWIN_THING_NEW(T,S)              (Global_ERWIN_TNEW(T,(S)))
1601  #  define Global_ERWIN_THING_CNEW(T,S)             (??Global_ERWIN_TCNEW(T,(S)))
1602  #  define Global_ERWIN_THING_DELETE(P,T,S)         do{ Global_ERWIN_TDELETE((P),T,(S)); }while(0)
1603  
1604  #  define Global_ERWIN_THING_NEW_ARRAY(T,C)        (Global_ERWIN_TNEW_ARRAY(T,(C)))
1605  #  define Global_ERWIN_THING_CNEW_ARRAY(T,C)       (??Global_ERWIN_TCNEW_ARRAY(T,(C)))
1606  #  define Global_ERWIN_THING_RENEW_ARRAY(P,T,N,O)  (??Global_ERWIN_TRENEW_ARRAY((P),T,(N),(O)))
1607  #  define Global_ERWIN_THING_CRENEW_ARRAY(P,T,N,O) (??Global_ERWIN_TCRENEW_ARRAY((P),T,(N),(O)))
1608  #  define Global_ERWIN_THING_DELETE_ARRAY(P)       do{ Global_ERWIN_TDELETE_ARRAY((P)); }while(0)
1609  
1610  #  define Global_ERWIN_THING_NEW_ATOMS(T,C)        (Global_ERWIN_TNEW_ATOMS(T,(C)))
1611  #  define Global_ERWIN_THING_CNEW_ATOMS(T,C)       (??Global_ERWIN_TCNEW_ATOMS(T,(C)))
1612  #  define Global_ERWIN_THING_RENEW_ATOMS(P,T,N,O)  (??Global_ERWIN_TRENEW_ATOMS((P),T,(N),(O)))
1613  #  define Global_ERWIN_THING_CRENEW_ATOMS(P,T,N,O) (??Global_ERWIN_TCRENEW_ATOMS((P),T,(N),(O)))
1614  #  define Global_ERWIN_THING_DELETE_ATOMS(P)       do{ Global_ERWIN_TDELETE_ATOMS((P)); }while(0)
1615  
1616  #else
1617  
1618  #  define Global_ERWIN_THING_NEW(T,S)              (Global_ERWIN_TMALLOC(T,(S)))
1619  #  define Global_ERWIN_THING_CNEW(T,S)             (??Global_ERWIN_TCALLOC(T,(S)))
1620  #  define Global_ERWIN_THING_DELETE(P,T,S)         do{ Global_ERWIN_TFREE((P),T,(S)); }while(0)
1621  
1622  #  define Global_ERWIN_THING_NEW_ARRAY(T,C)        (Global_ERWIN_TMALLOC_ARRAY(T,(C)))
1623  #  define Global_ERWIN_THING_CNEW_ARRAY(T,C)       (??Global_ERWIN_TCALLOC_ARRAY(T,(C)))
1624  #  define Global_ERWIN_THING_RENEW_ARRAY(P,T,N,O)  (??Global_ERWIN_TREALLOC_ARRAY((P),T,(N),(O)))
1625  #  define Global_ERWIN_THING_CRENEW_ARRAY(P,T,N,O) (??Global_ERWIN_TCREALLOC_ARRAY((P),T,(N),(O)))
1626  #  define Global_ERWIN_THING_DELETE_ARRAY(P)       do{ Global_ERWIN_TFREE_ARRAY((P)); }while(0)
1627  
1628  #  define Global_ERWIN_THING_NEW_ATOMS(T,C)        (Global_ERWIN_TMALLOC_ATOMS(T,(C)))
1629  #  define Global_ERWIN_THING_CNEW_ATOMS(T,C)       (??Global_ERWIN_TCALLOC_ATOMS(T,(C)))
1630  #  define Global_ERWIN_THING_RENEW_ATOMS(P,T,N,O)  (??Global_ERWIN_TREALLOC_ATOMS((P),T,(N),(O)))
1631  #  define Global_ERWIN_THING_CRENEW_ATOMS(P,T,N,O) (??Global_ERWIN_TCREALLOC_ATOMS((P),T,(N),(O)))
1632  #  define Global_ERWIN_THING_DELETE_ATOMS(P)       do{ Global_ERWIN_TFREE_ATOMS((P)); }while(0)
1633  
1634  #endif
1635  
1636  
1637  /* The raw macros are not expected to contain a correct macro structure, so
1638   * we use many parens and do{}while() to ensure one in own internal macros. */
1639  #define Global_ERWIN_TMALLOC1(T)              (Global_ERWIN_TMALLOC(T,sizeof(T)))
1640  #define Global_ERWIN_TCALLOC1(T)              (Global_ERWIN_TCALLOC(T,sizeof(T)))
1641  #define Global_ERWIN_TFREE1(P,T)              do{ Global_ERWIN_TFREE((P),T,sizeof(T)); }while(0)
1642  
1643  
1644  #define Global_ERWIN_TNEW1(T)                 (Global_ERWIN_TNEW(T,sizeof(T)))
1645  #define Global_ERWIN_TCNEW1(T)                (Global_ERWIN_TCNEW(T,sizeof(T)))
1646  #define Global_ERWIN_TDELETE1(P,T)            do{ Global_ERWIN_TDELETE((P),T,sizeof(T)); }while(0)
1647  
1648  /* The _THING_ macros already wrap the raw macros, so they do have a correct macro structure. */
1649  #define Global_ERWIN_THING_NEW1(T)            Global_ERWIN_THING_NEW(T,sizeof(T))
1650  #define Global_ERWIN_THING_CNEW1(T)           Global_ERWIN_THING_CNEW(T,sizeof(T))
1651  #define Global_ERWIN_THING_DELETE1(P,T)       Global_ERWIN_THING_DELETE(P,T,sizeof(T))
1652  
1653  
1654  #if defined(Global_ERWIN_TNEW)
1655  #  define Global_ERWIN_PREFER_TNEW     Global_ERWIN_TNEW
1656  #  define Global_ERWIN_PREFER_TDELETE  Global_ERWIN_TDELETE
1657  #else
1658  #  define Global_ERWIN_PREFER_TNEW     Global_ERWIN_TMALLOC
1659  #  define Global_ERWIN_PREFER_TDELETE  Global_ERWIN_TFREE
1660  #endif
1661  
1662  
1663  #define Global_ERWIN_SET_PTR(X,Y)  ((void)(Global_ERWIN_PTR_ASSIGN((X),(Y))))
1664  
1665  
1666  #define ?Global_ERWIN_DEFAULT_NEW_DELETE 0
1667  
1668  /*
1669   * Decide the storage class */
1670  #ifdef Global_ERWIN_INLINE_FUNCTIONS
1671  #  define ?Global_ERWIN_INLINE_PERHAPS ERWIN_INLINE
1672  #else
1673  #  define ?Global_ERWIN_INLINE_PERHAPS
1674  #endif /* defined(Global_ERWIN_INLINE_FUNCTIONS) */
1675  
1676  #ifndef NDEBUG
1677  #  define ?ERWIN_CAST_INLINING 0
1678             /* quick compilation */
1679  # else
1680  #  define ?ERWIN_CAST_INLINING 1
1681             /* quick program */
1682  #endif
1683  
1684  #ifdef Global_ERWIN_STATIC
1685  #  define ?Global_ERWIN_EXPORT static Global_ERWIN_INLINE_PERHAPS
1686  #else
1687  #  define ?Global_ERWIN_EXPORT extern Global_ERWIN_INLINE_PERHAPS
1688  #endif /* defined(Global_ERWIN_STATIC) */
1689  
1690  #if defined(__GNUC__) && defined(__cplusplus)
1691  #  if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
1692  #    define ERWIN_REINTERPRET_CAST(TYPE,VALUE)  (reinterpret_cast<TYPE>(VALUE))
1693  #    define ERWIN_STATIC_CAST(TYPE,VALUE)       (static_cast<TYPE>(VALUE))
1694  #    define ERWIN_CONST_CAST(TYPE,VALUE)        (const_cast<TYPE>(VALUE))
1695  #  endif
1696  #endif
1697  
1698  #define ?ERWIN_REINTERPRET_CAST(TYPE,VALUE) ((TYPE)(VALUE))
1699  #define ?ERWIN_STATIC_CAST(TYPE,VALUE)      ((TYPE)(VALUE))
1700  #define ?ERWIN_CONST_CAST(TYPE,VALUE)       ((TYPE)(VALUE))
1701  
1702  #if defined(_MSC_VER) && (_MSC_VER >= 1300)
1703  #  define ERWIN_FUNCTION         __FUNCTION__
1704  #  define ERWIN_PRETTY_FUNCTION  __FUNCSIG__
1705  #elif defined(__GNUC__)
1706  #  define ERWIN_FUNCTION         __FUNCTION__
1707  #  define ERWIN_PRETTY_FUNCTION  __PRETTY_FUNCTION__
1708  #endif
1709  
1710  #define ?ERWIN_FUNCTION         "<unknown function>"
1711  #define ?ERWIN_PRETTY_FUNCTION  ERWIN_FUNCTION
1712  
1713  #ifndef Global_ERWIN_ERROR_STREAM
1714  #  define Global_ERWIN_ERROR_STREAM stderr
1715  #endif
1716  
1717  #ifndef Global_ERWIN_ERROR_PRINT
1718  #  define Global_ERWIN_ERROR_PRINT fprintf
1719  #endif
1720  
1721  #ifdef __cplusplus
1722  #  define ERWIN_IF_CXX(X) X
1723  #  define ERWIN_IF_C(X)
1724  #else
1725  #  define ERWIN_IF_CXX(X)
1726  #  define ERWIN_IF_C(X)   X
1727  #endif
1728  
1729  /* Write numbers in binary format in C.  We implement it byte-wise: */
1730  
1731  /* Version 1: arbitrary arguments, including non-literals: */
1732  #define ERWIN_BIN1_RAW(X)                           \
1733          (                                           \
1734              (((X) & 0x00000001u) ? 0x01u : 0x00u) | \
1735              (((X) & 0x00000010u) ? 0x02u : 0x00u) | \
1736              (((X) & 0x00000100u) ? 0x04u : 0x00u) | \
1737              (((X) & 0x00001000u) ? 0x08u : 0x00u) | \
1738              (((X) & 0x00010000u) ? 0x10u : 0x00u) | \
1739              (((X) & 0x00100000u) ? 0x20u : 0x00u) | \
1740              (((X) & 0x01000000u) ? 0x40u : 0x00u) | \
1741              (((X) & 0x10000000u) ? 0x80u : 0x00u)   \
1742          )
1743  
1744  #define ERWIN_BIN2_RAW(XH,XL)           (ERWIN_BIN1_RAW(XL)      + (ERWIN_BIN1_RAW(XH)      << 8))
1745  #define ERWIN_BIN4_RAW(XHH,XHL,XLH,XLL) (ERWIN_BIN2_RAW(XLH,XLL) + (ERWIN_BIN2_RAW(XHH,XHL) << 16))
1746  
1747  /* For constants without the 0x prefix: */
1748  #define ERWIN_BIN1(X)               ERWIN_BIN1_RAW(0x##X)
1749  #define ERWIN_BIN2(XH,XL)           ERWIN_BIN2_RAW(0x##XH, 0x##XL)
1750  #define ERWIN_BIN4(XHH,XHL,XLH,XLL) ERWIN_BIN4_RAW(0x##XHH, 0x##XHL, 0x##XLH, 0x##XLL)
1751  
1752  #define ERWIN_XCHG(TYPE,A,B) \
1753          do{ TYPE ERWIN_GENSYM(e_xchg)= (A); (A)= (B); (B)= ERWIN_GENSYM(e_xchg); }while(0)
1754  
1755  #define ERWIN_PTR_TYPEDEFS(X)          \
1756          typedef X * X##_p;             \
1757          typedef X const * X##_const_p;
1758  
1759  #define ERWIN_KIND_TYPEDEFS(KIND,X)  \
1760          typedef KIND _##X X;         \
1761          ERWIN_PTR_TYPEDEFS(X)
1762  
1763  #define ERWIN_DEFAULT_ARG(X) ERWIN_IF_CXX(= X)
1764  
1765  #define ERWIN_IDENTITY(X)        X
1766  
1767  #define ERWIN_IS_POWER2(X)       (((X) > 0) && (((X) & ((X)-1)) == 0))
1768          /* Note: X is used multiple times! */
1769  
1770  #define ERWIN_POWER2(TYPE,N)     (((TYPE)1) << (N))
1771  
1772  #define ERWIN_BITS0(TYPE,N)      ((~((TYPE)0)) << (N))
1773  #define ERWIN_BITS1(TYPE,N)      (~ERWIN_BITS0(TYPE,N))
1774  
1775  #define ERWIN_BITS1_2(TYPE,N,M)  ((~((~((TYPE)0)) << (N))) << (M))
1776  #define ERWIN_BITS0_2(TYPE,N,M)  (~ERWIN_BITS1_2(TYPE,N,M))
1777  
1778  /* offsetof() is a problem and in fact, so is finding the slot offset
1779   * in general in C++: */
1780  #ifndef __cplusplus
1781  #    define Global_ERWIN_SIZEOF_MEMBER(Container,slot) \
1782                    sizeof(((Container*)0)->slot)
1783  
1784  #    define Global_ERWIN_OFFSETOF(Container,slot)       \
1785                    (((char *)&(((Container*)0)->slot)) - \
1786                    ((char *)(Container*)0))
1787  
1788  #else
1789  #    define Global_ERWIN_SIZEOF_MEMBER(Container,slot) \
1790                    sizeof(((Container*)&Global_erwin_init)->slot)
1791  
1792  #    define Global_ERWIN_OFFSETOF(Container,slot)                                              \
1793                    ((&reinterpret_cast<char volatile const &>(((Container*)&Global_erwin_init)->slot)) - \
1794                     ((char const *)(Container*)&Global_erwin_init))
1795  
1796     /* When using the normal C method or the offsetof() macro, this generates
1797      * warnings for no obvious reason.  I *know* that the offset is
1798      * computable.  What's the correct way to compute it then?  The obvious
1799      * way seems to violate the C++ standard.  The system offsetof() macro
1800      * is also implemented in that obvious way.  Strange language specs...
1801      *
1802      * We cannot use '(Container*)0', either.  Oh my!  So much superfluous work
1803      * this stupid warning triggers off.
1804      */
1805  
1806  /* Another implementation I found:
1807   * #define offsetof(TYPE, MEMBER)                              \
1808   *   (__offsetof__ (reinterpret_cast <size_t>                  \
1809   *                  (&reinterpret_cast <const volatile char &> \
1810   *                   (static_cast<TYPE *> (0)->MEMBER))))
1811   *
1812   * Does this also warn about 'NULL'?
1813   */
1814  
1815  #endif
1816  
1817  
1818  /* ********************************************************************** */
1819  /* #define Global_ERWIN_TYPE_INFO 0 */
1820  /*
1821   * Whether to include Erwin type info.  See erwin/typeinfo.h for the
1822   * definitions.
1823   */
1824  #define ?Global_ERWIN_TYPE_INFO 0
1825  
1826  /* ********************************************************************** */
1827  /* #define ALL_ERWIN_SPLIT    1 */
1828  /* #define Global_ERWIN_SPLIT 1 */
1829  /*
1830   * This is also available for each data structure.
1831   *
1832   * Whether to put the functions in different sections to help
1833   * the linker simplify the resulting program.  For GCC, you
1834   * need -Wl,--gc-sections to remove unused sections.
1835   *
1836   * The value of this variable may be:
1837   *
1838   *   0: link traditionally, don't try to fiddle with sections
1839   *   1: make a separate section for each function
1840   *
1841   * The default depends on the optimisation strategy and on whether
1842   * we're doing a release or a debug build.
1843   */
1844  
1845  #define ?Global_ERWIN_SPLIT ??ALL_ERWIN_SPLIT
1846  
1847  #if Global_ERWIN_OPTIMISE
1848  #  define ?Global_ERWIN_SPLIT 1
1849  #endif
1850  #define ?Global_ERWIN_SPLIT 0
1851  
1852  /* Little vs. big endian.  We call in 'LBF': low byte first
1853   * or 'HBF': high byte first, for simplicity. */
1854  /* Note that PDP_ENDIAN is currently not supported here. */
1855  
1856  /* The Erwin byte order macro ERWIN_BYTE_ORDER shows how 32 bit ints are stored:
1857   * when 0x03020100 is stored, then n is stored at byte with index
1858   * ((ERWIN_BYTE_ORDER >> (n*4)) & 0xf) for n \n {0,1,2,3}
1859   *
1860   * So for
1861   *    union {
1862   *      ERWIN_U32 one;
1863   *      ERWIN_U8  many[4];
1864   *    } x;
1865   *
1866   * it holds that:
1867   *      (x.one         & 0xff) == x.many[ ERWIN_INDEX_BYTE(ERWIN_BYTE_ORDER,0) ]
1868   *   && ((x.one >> 8)  & 0xff) == x.many[ ERWIN_INDEX_BYTE(ERWIN_BYTE_ORDER,1) ]
1869   *   && ((x.one >> 16) & 0xff) == x.many[ ERWIN_INDEX_BYTE(ERWIN_BYTE_ORDER,2) ]
1870   *   && ((x.one >> 24) & 0xff) == x.many[ ERWIN_INDEX_BYTE(ERWIN_BYTE_ORDER,3) ]
1871   *
1872   * So you can extract a word in a given byte order with:
1873   *
1874   *     ERWIN_U8 byte[4];
1875   *     ...
1876   *     ERWIN_U32 x=  (((ERWIN_U32)(byte[ERWIN_INDEX_BYTE(byte_order,0)]))      ) |
1877   *                   (((ERWIN_U32)(byte[ERWIN_INDEX_BYTE(byte_order,1)])) <<  8) |
1878   *                   (((ERWIN_U32)(byte[ERWIN_INDEX_BYTE(byte_order,2)])) << 16) |
1879   *                   (((ERWIN_U32)(byte[ERWIN_INDEX_BYTE(byte_order,3)])) << 24);
1880   *
1881   * Likewise, you can extract the nth byte from a word:
1882   *     ERWIN_U32 x;
1883   *     ERWIN_U8  byte[4];
1884   *
1885   *     byte[0]= (x >> (ERWIN_INDEX_BYTE(byte_order,0) << 3)) & 0xff;
1886   *     byte[1]= (x >> (ERWIN_INDEX_BYTE(byte_order,1) << 3)) & 0xff;
1887   *     byte[2]= (x >> (ERWIN_INDEX_BYTE(byte_order,2) << 3)) & 0xff;
1888   *     byte[3]= (x >> (ERWIN_INDEX_BYTE(byte_order,3) << 3)) & 0xff;
1889   *
1890   * where byte_order \n { ERWIN_LBF, ERWIN_HBF }
1891   *
1892   * Byte orders for 16 bits can be obtained by using (X & 0x11) on the
1893   * byte order constants, e.g. (ERWIN_LBF & 0x11) is a 16-bit byte
1894   * order and can be used with ERWIN_INDEX_BYTE, too.
1895   *
1896   * Generic byte orders for 64 bits are currently not supported, so
1897   * for ERWIN_LBF and ERWIN_HBF you have to program special cases.
1898   */
1899  
1900  #define ERWIN_INDEX_BYTE(ORDER,N) (((ORDER) >> ((N) << 2)) & 0xf)
1901  
1902  #define ERWIN_MAKE_BYTE_ORDER(I0,I1,I2,I3)                    \
1903              ((I0) | ((I1) << 4) | ((I2) << 8) | ((I3) << 12))
1904  
1905  #define ERWIN_LBF 0x3210
1906  #define ERWIN_HBF 0x0123
1907  
1908  #define ERWIN_LITTLE_ENDIAN ERWIN_LBF
1909  #define ERWIN_BIG_ENDIAN    ERWIN_HBF
1910  
1911  /* #define ERWIN_PDP_ENDIAN  0x1032   ?? */
1912  /* #define ERWIN_PDP_ENDIAN  0x2301   ?? */
1913  
1914  #if defined(WORDS_BIGENDIAN)
1915  #  define ?ERWIN_BYTE_ORDER ERWIN_HBF
1916  #  ifdef WORDS_LITTLEENDIAN
1917  #    error "Both WORDS_BIGENDIAN and WORDS_LITTLEENDIAN are defined."
1918  #  endif
1919  #elif defined(WORDS_LITTLEENDIAN)
1920  #  define ?ERWIN_BYTE_ORDER ERWIN_LBF
1921  #endif
1922  
1923  #ifndef ERWIN_BYTE_ORDER
1924  
1925  /* Try to find out byte order by preprocessor macros for architectures: */
1926  /** LBF **/
1927  /* x86 and amd64: */
1928  #  define ERWIN_X86_ENDIAN  ERWIN_LBF
1929  #  if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(_M_X64)
1930  #    define ERWIN_BYTE_ORDER  ERWIN_X86_ENDIAN
1931  #  elif defined(__i386__) || defined(__i386) || defined(_M_IX86)
1932  #    define ERWIN_BYTE_ORDER  ERWIN_X86_ENDIAN
1933  #  endif
1934  
1935  /** HBF **/
1936  /* Sparc: */
1937  #  define ERWIN_SPARC_ENDIAN  ERWIN_HBF
1938  #  if defined(__sparc__) || defined(__sparc)
1939  #    define ERWIN_BYTE_ORDER  ERWIN_SPARC_ENDIAN
1940  #  endif
1941  
1942  /* PPC: */
1943  #  define ERWIN_PPC_ENDIAN  ERWIN_HBF
1944  #  if defined(__powerpc__) || defined(__powerpc) || defined(_M_PPC)
1945  #    define ERWIN_BYTE_ORDER  ERWIN_PPC_ENDIAN
1946  #  endif
1947  
1948  #endif /* !defined(ERWIN_BYTE_ORDER) */
1949  
1950  /* **** */
1951  
1952  #ifdef HAVE_LIBERROR
1953  #  define Global_ERWIN_ABORT err_crash
1954  #else
1955  #  define Global_ERWIN_ABORT abort
1956  #endif
1957  
1958  #ifndef Global_ERWIN_DEFAULT_ASSERTION_FAILED_HANDLER
1959  #  define Global_ERWIN_DEFAULT_ASSERTION_FAILED_HANDLER(FL,I,FU,A) \
1960      ((void)(Global_erwin_assertion_is_fatal ? (Global_ERWIN_ABORT(), 0) : 0))
1961  #endif
1962  
1963  #ifdef Global_ERWIN_COMPILING
1964  #  include "--INCPREF2B--erwin/asm.h"
1965  #else
1966  #  include <--INCPREF2B--erwin/asm.h>
1967  #endif
1968  
1969  #endif /* defined(Global_ERWIN_ADAM_NAME */
1970  
1971  #endif /* Global_ERWIN_DEFS_H */

Index

Stoppt die Vorratsdatenspeicherung
November 26th, 2007
Comments? Suggestions? Corrections? You can drop me a line.
zpentrabvagiktu@theiling.de
Schwerpunktpraxis