1 /********************************************************************/ 2 /* */ 3 /* common.h Basic type definitions and settings. */ 4 /* Copyright (C) 1989 - 2017 Thomas Mertes */ 5 /* */ 6 /* This file is part of the Seed7 Runtime Library. */ 7 /* */ 8 /* The Seed7 Runtime Library is free software; you can */ 9 /* redistribute it and/or modify it under the terms of the GNU */ 10 /* Lesser General Public License as published by the Free Software */ 11 /* Foundation; either version 2.1 of the License, or (at your */ 12 /* option) any later version. */ 13 /* */ 14 /* The Seed7 Runtime Library is distributed in the hope that it */ 15 /* will be useful, but WITHOUT ANY WARRANTY; without even the */ 16 /* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR */ 17 /* PURPOSE. See the GNU Lesser General Public License for more */ 18 /* details. */ 19 /* */ 20 /* You should have received a copy of the GNU Lesser General */ 21 /* Public License along with this program; if not, write to the */ 22 /* Free Software Foundation, Inc., 51 Franklin Street, */ 23 /* Fifth Floor, Boston, MA 02110-1301, USA. */ 24 /* */ 25 /* Module: Seed7 Runtime Library */ 26 /* File: seed7/src/common.h */ 27 /* Changes: 1992 - 1994, 2005, 2011, 2013, 2014 Thomas Mertes */ 28 /* Content: Basic type definitions and settings. */ 29 /* */ 30 /********************************************************************/ 31 32 #include "config.h" 33 34 #if BIGINT_LIB == BIG_GMP_LIBRARY 35 #include "gmp.h" 36 #endif 37 38 39 #if defined(__cplusplus) || defined(c_plusplus) 40 #define C_PLUS_PLUS 41 #endif 42 43 typedef BOOLTYPE boolType; 44 45 #ifdef FALSE 46 #undef FALSE 47 #endif 48 #define FALSE ((boolType) 0) 49 #ifdef TRUE 50 #undef TRUE 51 #endif 52 #define TRUE ((boolType) 1) 53 54 #define EXTERN extern 55 56 57 #ifdef RENAMED_POSIX_FUNCTIONS 58 #define kbhit _kbhit 59 #define setmode _setmode 60 #define fdopen _fdopen 61 #endif 62 63 64 typedef INT8TYPE int8Type; 65 typedef UINT8TYPE uint8Type; 66 67 #define INT8TYPE_MAX 127 68 #define INT8TYPE_MIN (-128) 69 #define UINT8TYPE_MAX 0xff 70 #define F_D8(width) "%" #width "hhd" 71 #define F_U8(width) "%" #width "hhu" 72 #define F_X8(width) "%" #width "hhx" 73 #define FMT_D8 "%hhd" 74 #define FMT_U8 "%hhu" 75 #define FMT_X8 "%hhx" 76 77 78 typedef INT16TYPE int16Type; 79 typedef UINT16TYPE uint16Type; 80 81 #define INT16TYPE_MAX 32767 82 #define INT16TYPE_MIN (-32768) 83 #define UINT16TYPE_MAX 0xffff 84 #define F_D16(width) "%" #width "hd" 85 #define F_U16(width) "%" #width "hu" 86 #define F_X16(width) "%" #width "hx" 87 #define FMT_D16 "%hd" 88 #define FMT_U16 "%hu" 89 #define FMT_X16 "%hx" 90 91 92 typedef INT32TYPE int32Type; 93 typedef UINT32TYPE uint32Type; 94 95 #define INT32TYPE_MAX INT32_SUFFIX(2147483647) 96 #if TWOS_COMPLEMENT_INTTYPE 97 #define INT32TYPE_MIN (-INT32TYPE_MAX - INT32_SUFFIX(1)) 98 #else 99 #define INT32TYPE_MIN INT32_SUFFIX(-2147483647) 100 #endif 101 #define UINT32TYPE_MAX UINT32_SUFFIX(0xffffffff) 102 103 #define F_D32(width) "%" #width INT32TYPE_FORMAT_LENGTH_MODIFIER "d" 104 #define F_U32(width) "%" #width INT32TYPE_FORMAT_LENGTH_MODIFIER "u" 105 #define F_X32(width) "%" #width INT32TYPE_FORMAT_LENGTH_MODIFIER "x" 106 #define FMT_D32 "%" INT32TYPE_FORMAT_LENGTH_MODIFIER "d" 107 #define FMT_U32 "%" INT32TYPE_FORMAT_LENGTH_MODIFIER "u" 108 #define FMT_X32 "%" INT32TYPE_FORMAT_LENGTH_MODIFIER "x" 109 110 /* INT32TYPE_DECIMAL_SIZE includes space for the sign */ 111 #define INT32TYPE_DECIMAL_SIZE 11 112 /* UINT32TYPE_DECIMAL_SIZE does not need space for a sign */ 113 #define UINT32TYPE_DECIMAL_SIZE 10 114 #define DECIMAL_DIGITS_IN_INT32TYPE 9 115 116 117 #ifdef INT64TYPE 118 typedef INT64TYPE int64Type; 119 typedef UINT64TYPE uint64Type; 120 121 #ifdef INT64TYPE_NO_SUFFIX_BUT_CAST 122 #define INT64TYPE_MAX ((int64Type) 9223372036854775807) 123 #if TWOS_COMPLEMENT_INTTYPE 124 #define INT64TYPE_MIN ((int64Type) (-INT64TYPE_MAX - 1)) 125 #else 126 #define INT64TYPE_MIN ((int64Type) -9223372036854775807) 127 #endif 128 #define UINT64TYPE_MAX ((uint64Type) 0xffffffffffffffff) 129 #else 130 #define INT64TYPE_MAX INT64_SUFFIX(9223372036854775807) 131 #if TWOS_COMPLEMENT_INTTYPE 132 #define INT64TYPE_MIN (-INT64TYPE_MAX - INT64_SUFFIX(1)) 133 #else 134 #define INT64TYPE_MIN INT64_SUFFIX(-9223372036854775807) 135 #endif 136 #define UINT64TYPE_MAX UINT64_SUFFIX(0xffffffffffffffff) 137 #endif 138 139 #define F_D64(width) "%" #width INT64TYPE_FORMAT_LENGTH_MODIFIER "d" 140 #define F_U64(width) "%" #width INT64TYPE_FORMAT_LENGTH_MODIFIER "u" 141 #define F_X64(width) "%" #width INT64TYPE_FORMAT_LENGTH_MODIFIER "x" 142 #define FMT_D64 "%" INT64TYPE_FORMAT_LENGTH_MODIFIER "d" 143 #define FMT_U64 "%" INT64TYPE_FORMAT_LENGTH_MODIFIER "u" 144 #define FMT_X64 "%" INT64TYPE_FORMAT_LENGTH_MODIFIER "x" 145 146 /* INT64TYPE_DECIMAL_SIZE includes space for the sign */ 147 #define INT64TYPE_DECIMAL_SIZE 20 148 /* UINT64TYPE_DECIMAL_SIZE does not need space for a sign */ 149 #define UINT64TYPE_DECIMAL_SIZE 20 150 #define DECIMAL_DIGITS_IN_INT64TYPE 18 151 #endif 152 153 154 #ifdef INT128TYPE 155 typedef INT128TYPE int128Type; 156 typedef UINT128TYPE uint128Type; 157 #endif 158 159 160 #if INTTYPE_SIZE == 32 161 typedef int32Type intType; 162 typedef uint32Type uintType; 163 #define INT_SUFFIX(num) INT32_SUFFIX(num) 164 #define UINT_SUFFIX(num) UINT32_SUFFIX(num) 165 #define INTTYPE_LITERAL_SUFFIX INT32TYPE_LITERAL_SUFFIX 166 #define INTTYPE_MIN INT32TYPE_MIN 167 #define INTTYPE_MAX INT32TYPE_MAX 168 #define UINTTYPE_MAX UINT32TYPE_MAX 169 typedef int16Type halfIntType; 170 typedef uint16Type halfUintType; 171 #ifdef INT64TYPE 172 #define HAS_DOUBLE_INTTYPE 173 typedef int64Type doubleIntType; 174 typedef uint64Type doubleUintType; 175 #endif 176 #define HALF_INTTYPE_MIN INT16TYPE_MIN 177 #define HALF_INTTYPE_MAX INT16TYPE_MAX 178 #define HALF_UINTTYPE_MAX UINT16TYPE_MAX 179 #define F_D(width) F_D32(width) 180 #define F_U(width) F_U32(width) 181 #define F_X(width) F_X32(width) 182 #define FMT_D FMT_D32 183 #define FMT_U FMT_U32 184 #define FMT_X FMT_X32 185 #define INTTYPE_DECIMAL_SIZE INT32TYPE_DECIMAL_SIZE 186 #define DECIMAL_DIGITS_IN_INTTYPE DECIMAL_DIGITS_IN_INT32TYPE 187 #define uintMostSignificantBit uint32MostSignificantBit 188 #define uintLeastSignificantBit uint32LeastSignificantBit 189 #elif INTTYPE_SIZE == 64 190 typedef int64Type intType; 191 typedef uint64Type uintType; 192 #define INT_SUFFIX(num) INT64_SUFFIX(num) 193 #define UINT_SUFFIX(num) UINT64_SUFFIX(num) 194 #define INTTYPE_LITERAL_SUFFIX INT64TYPE_LITERAL_SUFFIX 195 #define INTTYPE_MIN INT64TYPE_MIN 196 #define INTTYPE_MAX INT64TYPE_MAX 197 #define UINTTYPE_MAX UINT64TYPE_MAX 198 typedef int32Type halfIntType; 199 typedef uint32Type halfUintType; 200 #ifdef INT128TYPE 201 #define HAS_DOUBLE_INTTYPE 202 typedef int128Type doubleIntType; 203 typedef uint128Type doubleUintType; 204 #endif 205 #define HALF_INTTYPE_MIN INT32TYPE_MIN 206 #define HALF_INTTYPE_MAX INT32TYPE_MAX 207 #define HALF_UINTTYPE_MAX UINT32TYPE_MAX 208 #define F_D(width) F_D64(width) 209 #define F_U(width) F_U64(width) 210 #define F_X(width) F_X64(width) 211 #define FMT_D FMT_D64 212 #define FMT_U FMT_U64 213 #define FMT_X FMT_X64 214 #define INTTYPE_DECIMAL_SIZE INT64TYPE_DECIMAL_SIZE 215 #define DECIMAL_DIGITS_IN_INTTYPE DECIMAL_DIGITS_IN_INT64TYPE 216 #define uintMostSignificantBit uint64MostSignificantBit 217 #define uintLeastSignificantBit uint64LeastSignificantBit 218 #endif 219 220 221 /* Define intAbs macro that ignores integer overflow. */ 222 #if INTTYPE_SIZE == INT_SIZE 223 #define intAbs(n) abs(n) 224 #elif INTTYPE_SIZE == LONG_SIZE 225 #define intAbs(n) labs(n) 226 #elif defined(LONG_LONG_SIZE) && INTTYPE_SIZE == LONG_LONG_SIZE && HAS_LLABS 227 #define intAbs(n) llabs(n) 228 #elif defined(INT64_SIZE) && INTTYPE_SIZE == INT64_SIZE && HAS_ABS64 229 #define intAbs(n) _abs64(n) 230 #else 231 /* The unsigned value is negated to avoid a signed integer */ 232 /* overflow if the smallest signed integer is negated. */ 233 #define intAbs(n) ((n) < 0 ? (intType) -(uintType) (n) : (n)) 234 #endif 235 236 237 #define BYTE_MIN INT8TYPE_MIN 238 #define BYTE_MAX INT8TYPE_MAX 239 #define UBYTE_MAX UINT8TYPE_MAX 240 241 242 typedef int64Type timeStampType; 243 #define TIMESTAMPTYPE_MIN INT64TYPE_MIN 244 #define TIMESTAMPTYPE_MAX INT64TYPE_MAX 245 #define TIMESTAMPTYPE_SIZE 64 246 247 #if TIME_T_SIZE == 32 248 #define TIME_T_MAX INT32TYPE_MAX 249 #if TIME_T_SIGNED 250 #define TIME_T_ERROR INT32TYPE_MIN 251 #define FMT_T FMT_D32 252 #else 253 #define TIME_T_ERROR UINT32TYPE_MAX 254 #define FMT_T FMT_U32 255 #endif 256 #elif TIME_T_SIZE == 64 257 #define TIME_T_MAX INT64TYPE_MAX 258 #if TIME_T_SIGNED 259 #define TIME_T_ERROR INT64TYPE_MIN 260 #define FMT_T FMT_D64 261 #else 262 #define TIME_T_ERROR UINT64TYPE_MAX 263 #define FMT_T FMT_U64 264 #endif 265 #endif 266 267 268 #ifdef USE_SIMPLE_RANGE_CHECK 269 #define inHalfIntTypeRange(num) ((num) >= HALF_INTTYPE_MIN && (num) <= HALF_INTTYPE_MAX) 270 #else 271 #define inHalfIntTypeRange(num) ((intType) (halfIntType) (num) == (num)) 272 #endif 273 274 #ifdef HAS_DOUBLE_INTTYPE 275 #ifdef USE_SIMPLE_RANGE_CHECK 276 #define inIntTypeRange(num) ((num) >= INTTYPE_MIN && (num) <= INTTYPE_MAX) 277 #else 278 #define inIntTypeRange(num) ((doubleIntType) (intType) (num) == (num)) 279 #endif 280 #endif 281 282 283 #if SHORT_SIZE < INTTYPE_SIZE 284 #ifdef USE_SIMPLE_RANGE_CHECK 285 #define inShortRange(num) ((num) >= SHRT_MIN && (num) <= SHRT_MAX) 286 #else 287 #define inShortRange(num) ((intType) (short int) (num) == (num)) 288 #endif 289 #define castToShort(num) (inShortRange(num) ? (short int) (num) : (raise_error(RANGE_ERROR), (short int) 0)) 290 #else 291 #define inShortRange(num) 1 292 #define castToShort(num) ((short int) (num)) 293 #endif 294 295 #if INT_SIZE < INTTYPE_SIZE 296 #ifdef USE_SIMPLE_RANGE_CHECK 297 #define inIntRange(num) ((num) >= INT_MIN && (num) <= INT_MAX) 298 #else 299 #define inIntRange(num) ((intType) (int) (num) == (num)) 300 #endif 301 #define castToInt(num) (inIntRange(num) ? (int) (num) : (raise_error(RANGE_ERROR), 0)) 302 #else 303 #define inIntRange(num) 1 304 #define castToInt(num) ((int) (num)) 305 #endif 306 307 #if LONG_SIZE < INTTYPE_SIZE 308 #ifdef USE_SIMPLE_RANGE_CHECK 309 #define inLongRange(num) ((num) >= LONG_MIN && (num) <= LONG_MAX) 310 #else 311 #define inLongRange(num) ((intType) (long int) (num) == (num)) 312 #endif 313 #define castToLong(num) (inLongRange(num) ? (long) (num) : (raise_error(RANGE_ERROR), 0)) 314 #else 315 #define inLongRange(num) 1 316 #define castToLong(num) ((long) (num)) 317 #endif 318 319 #if TIME_T_SIGNED 320 #if TIME_T_SIZE < INTTYPE_SIZE 321 #if TIME_T_SIZE == 32 322 #define inTimeTRange(timestamp) ((timestamp) >= INT32TYPE_MIN && (timestamp) <= INT32TYPE_MAX) 323 #elif TIME_T_SIZE == 64 324 #define inTimeTRange(timestamp) ((timestamp) >= INT64TYPE_MIN && (timestamp) <= INT64TYPE_MAX) 325 #endif 326 #else 327 #define inTimeTRange(timestamp) 1 328 #endif 329 #else 330 #if TIME_T_SIZE < INTTYPE_SIZE 331 #if TIME_T_SIZE == 32 332 #define inTimeTRange(timestamp) ((timestamp) >= 0 && (timestamp) <= UINT32TYPE_MAX) 333 #elif TIME_T_SIZE == 64 334 #define inTimeTRange(timestamp) ((timestamp) >= 0 && (timestamp) <= UINT64TYPE_MAX) 335 #endif 336 #else 337 #define inTimeTRange(timestamp) ((timestamp) >= 0) 338 #endif 339 #endif 340 341 /** 342 * Some C compilers do not support switch statements with 64-bit values. 343 * For such compilers the macro castIntTypeForSwitch() is used to cast 344 * the switch value to an int. Note that castIntTypeForSwitch() may 345 * trigger the exception RANGE_ERROR. 346 */ 347 #if SWITCH_WORKS_FOR_INT64TYPE 348 #define castIntTypeForSwitch(num) num 349 #else 350 #define castIntTypeForSwitch(num) castToInt(num) 351 #endif 352 353 354 #if BITSETTYPE_SIZE == 32 355 typedef uint32Type bitSetType; 356 #define bitsetMostSignificantBit uint32MostSignificantBit 357 #define bitsetLeastSignificantBit uint32LeastSignificantBit 358 #define FMT_U_SET FMT_D32 359 #define FMT_D_SET FMT_U32 360 #define FMT_X_SET FMT_X32 361 #elif BITSETTYPE_SIZE == 64 362 typedef uint64Type bitSetType; 363 #define bitsetMostSignificantBit uint64MostSignificantBit 364 #define bitsetLeastSignificantBit uint64LeastSignificantBit 365 #define FMT_U_SET FMT_D64 366 #define FMT_D_SET FMT_U64 367 #define FMT_X_SET FMT_X64 368 #endif 369 370 371 #define FLOAT_MANTISSA_BITS (FLOAT_MANTISSA_SHIFT - 1) 372 #define FLOAT_EXPONENT_AND_SIGN_BITS (FLOAT_SIZE - FLOAT_MANTISSA_BITS ) 373 #define DOUBLE_MANTISSA_BITS (DOUBLE_MANTISSA_SHIFT - 1) 374 #define DOUBLE_EXPONENT_AND_SIGN_BITS (DOUBLE_SIZE - DOUBLE_MANTISSA_BITS) 375 376 #if FLOATTYPE_DOUBLE 377 typedef double floatType; 378 #define FLOATTYPE_SIZE DOUBLE_SIZE 379 #if INT_RANGE_IN_DOUBLE_MAX <= INTTYPE_MAX 380 #define INT_RANGE_IN_FLOATTYPE_MAX INT_RANGE_IN_DOUBLE_MAX 381 #else 382 #define INT_RANGE_IN_FLOATTYPE_MAX INTTYPE_MAX 383 #endif 384 #define FLOATTYPE_TO_INT_CONVERSION_LIMIT DOUBLE_MANTISSA_FACTOR 385 #define FLOATTYPE_MANTISSA_FACTOR DOUBLE_MANTISSA_FACTOR 386 #define FLOATTYPE_MANTISSA_BITS DOUBLE_MANTISSA_BITS 387 #define FLOATTYPE_EXPONENT_AND_SIGN_BITS DOUBLE_EXPONENT_AND_SIGN_BITS 388 #define FLOATTYPE_EXPONENT_OFFSET DOUBLE_EXPONENT_OFFSET 389 #define FMT_E FMT_E_DBL 390 #else 391 typedef float floatType; 392 #define FLOATTYPE_SIZE FLOAT_SIZE 393 #if INT_RANGE_IN_FLOAT_MAX <= INTTYPE_MAX 394 #define INT_RANGE_IN_FLOATTYPE_MAX INT_RANGE_IN_FLOAT_MAX 395 #else 396 #define INT_RANGE_IN_FLOATTYPE_MAX INTTYPE_MAX 397 #endif 398 #define FLOATTYPE_TO_INT_CONVERSION_LIMIT FLOAT_MANTISSA_FACTOR 399 #define FLOATTYPE_MANTISSA_FACTOR FLOAT_MANTISSA_FACTOR 400 #define FLOATTYPE_MANTISSA_BITS FLOAT_MANTISSA_BITS 401 #define FLOATTYPE_EXPONENT_AND_SIGN_BITS FLOAT_EXPONENT_AND_SIGN_BITS 402 #define FLOATTYPE_EXPONENT_OFFSET FLOAT_EXPONENT_OFFSET 403 #define FMT_E FMT_E_FLT 404 #endif 405 406 #define FLOAT_COMPARISON_OKAY (FLOAT_NAN_COMPARISON_OKAY && FLOAT_ZERO_COMPARISON_OKAY) 407 #define POW_FUNCTION_OKAY (POW_OF_NAN_OKAY && POW_OF_ZERO_OKAY && POW_OF_NEGATIVE_OKAY && POW_OF_ONE_OKAY && POW_EXP_NAN_OKAY && POW_EXP_MINUS_INFINITY_OKAY) 408 #define SQRT_FUNCTION_OKAY (SQRT_OF_NAN_OKAY && SQRT_OF_NEGATIVE_OKAY) 409 #define EXP_FUNCTION_OKAY (EXP_OF_NAN_OKAY) 410 #define LOG_FUNCTION_OKAY (LOG_OF_NAN_OKAY && LOG_OF_ZERO_OKAY && LOG_OF_NEGATIVE_OKAY) 411 #define LOG10_FUNCTION_OKAY (LOG10_OF_NAN_OKAY && LOG10_OF_ZERO_OKAY && LOG10_OF_NEGATIVE_OKAY) 412 #define LOG2_FUNCTION_OKAY (HAS_LOG2 && LOG2_OF_NAN_OKAY && LOG2_OF_ZERO_OKAY && LOG2_OF_NEGATIVE_OKAY) 413 #define LDEXP_FUNCTION_OKAY (LDEXP_OF_NAN_OKAY) 414 #define FREXP_FUNCTION_OKAY (FREXP_INFINITY_NAN_OKAY && FREXP_SUBNORMAL_OKAY) 415 #define FMOD_FUNCTION_OKAY (FMOD_DIVIDEND_NAN_OKAY && FMOD_DIVISOR_NAN_OKAY && FMOD_DIVIDEND_INFINITY_OKAY && FMOD_DIVISOR_INFINITY_OKAY && FMOD_DIVISOR_ZERO_OKAY) 416 417 418 typedef uint32Type charType; 419 typedef int32Type scharType; 420 typedef charType strElemType; 421 422 #if POINTER_SIZE == 32 423 typedef uint32Type memSizeType; 424 #define MAX_MEMSIZETYPE 0xFFFFFFFF 425 #define MIN_MEM_INDEX INT32TYPE_MIN 426 #define MAX_MEM_INDEX INT32TYPE_MAX 427 #define F_D_MEM(width) F_D32(width) 428 #define F_U_MEM(width) F_U32(width) 429 #define F_X_MEM(width) F_X32(width) 430 #define FMT_D_MEM FMT_D32 431 #define FMT_U_MEM FMT_U32 432 #define FMT_X_MEM FMT_X32 433 #define MEMSIZETYPE_DECIMAL_SIZE UINT32TYPE_DECIMAL_SIZE 434 #define memSizeMostSignificantBit uint32MostSignificantBit 435 #define memSizeLeastSignificantBit uint32LeastSignificantBit 436 #elif POINTER_SIZE == 64 437 typedef uint64Type memSizeType; 438 #define MAX_MEMSIZETYPE 0xFFFFFFFFFFFFFFFF 439 #define MIN_MEM_INDEX INTTYPE_MIN 440 #define MAX_MEM_INDEX INTTYPE_MAX 441 #define F_D_MEM(width) F_D64(width) 442 #define F_U_MEM(width) F_U64(width) 443 #define F_X_MEM(width) F_X64(width) 444 #define FMT_D_MEM FMT_D64 445 #define FMT_U_MEM FMT_U64 446 #define FMT_X_MEM FMT_X64 447 #define MEMSIZETYPE_DECIMAL_SIZE UINT64TYPE_DECIMAL_SIZE 448 #define memSizeMostSignificantBit uint64MostSignificantBit 449 #define memSizeLeastSignificantBit uint64LeastSignificantBit 450 #endif 451 452 #if OS_OFF_T_SIZE == 32 453 #define F_D_OFF(width) F_D32(width) 454 #define F_U_OFF(width) F_U32(width) 455 #define F_X_OFF(width) F_X32(width) 456 #define FMT_D_OFF FMT_D32 457 #define FMT_U_OFF FMT_U32 458 #define FMT_X_OFF FMT_X32 459 #elif OS_OFF_T_SIZE == 64 460 #define F_D_OFF(width) F_D64(width) 461 #define F_U_OFF(width) F_U64(width) 462 #define F_X_OFF(width) F_X64(width) 463 #define FMT_D_OFF FMT_D64 464 #define FMT_U_OFF FMT_U64 465 #define FMT_X_OFF FMT_X64 466 #else 467 #error "sizeof(os_off_t) is neither 4 nor 8." 468 #endif 469 470 typedef int priorityType; 471 472 /** 473 * NULL_TERMINATION_LEN is the length for the terminating null 474 * char (\0) of a null-terminated string. The null termination 475 * is measured in characters and not in bytes. A null-terminated 476 * wide char string is terminated with one wide null char. 477 * NULL_TERMINATION_LEN can be used for normal null-terminated 478 * strings and for null-terminated wide char strings. 479 */ 480 #define NULL_TERMINATION_LEN 1 481 482 typedef unsigned char ucharType; 483 typedef char *cstriType; 484 typedef unsigned char *ustriType; 485 typedef memSizeType sySizeType; 486 typedef FILE *cFileType; 487 typedef int fileDesType; 488 489 typedef uint16Type wcharType; 490 typedef wcharType *wstriType; 491 typedef const wcharType *const_wstriType; 492 493 typedef int socketType; 494 typedef unsigned int usocketType; 495 496 /* Possible values for SOCKET_LIB: */ 497 #define NO_SOCKETS -1 498 #define UNIX_SOCKETS 1 499 #define WINSOCK_SOCKETS 2 500 501 #if SOCKET_LIB == UNIX_SOCKETS 502 typedef int os_socketType; 503 #elif SOCKET_LIB == WINSOCK_SOCKETS 504 typedef unsigned int os_socketType; 505 #endif 506 507 /* Possible values for DIR_LIB: */ 508 #define NO_DIRECTORY -1 509 #define DIRENT_DIRECTORY 1 510 #define DIRECT_DIRECTORY 2 511 #define DIRDOS_DIRECTORY 3 512 #define DIRWIN_DIRECTORY 4 513 514 /* Possible values for BIGINT_LIB: */ 515 #define NO_BIG_LIBRARY -1 516 #define BIG_RTL_LIBRARY 1 517 #define BIG_GMP_LIBRARY 2 518 519 typedef const char *const_cstriType; 520 typedef const unsigned char *const_ustriType; 521 522 #define MAX_DIV_10 ((intType) (INTTYPE_MAX / 10)) 523 #define MAX_REM_10 ((intType) (INTTYPE_MAX % 10)) 524 525 /* Maximum value of type sySizeType: */ 526 #define MAX_SYMB_LENGTH MAX_MEMSIZETYPE 527 528 #ifndef CLOCKS_PER_SEC 529 #define CLOCKS_PER_SEC 1000000 530 #endif 531 532 #define SOURCE_POSITION(POS_NR) __FILE__, __LINE__ 533 534 535 typedef int errInfoType; 536 537 /* errinfo values: */ 538 #define OKAY_NO_ERROR 0 539 #define MEMORY_ERROR 1 540 #define NUMERIC_ERROR 2 541 #define OVERFLOW_ERROR 3 542 #define RANGE_ERROR 4 543 #define INDEX_ERROR 5 544 #define FILE_ERROR 6 545 #define DATABASE_ERROR 7 546 #define CLOSE_ERROR 8 547 #define ACTION_ERROR 9 548 #define CREATE_ERROR 9 549 #define DESTROY_ERROR 9 550 #define COPY_ERROR 9 551 #define IN_ERROR 9 552 #define VALUE_ERROR 9 553 554 555 #if HAS_SIGSETJMP 556 #define do_setjmp(env) sigsetjmp(env, 1) 557 #define do_longjmp(env, val) siglongjmp(env, val); 558 #define longjmpPosition sigjmp_buf 559 #else 560 #define do_setjmp(env) setjmp(env) 561 #define do_longjmp(env, val) longjmp(env, val); 562 #define longjmpPosition jmp_buf 563 #endif 564 565 #if FORWARD_TERM_CALLS 566 boolType findTermDll (void); 567 #else 568 #define findTermDll() TRUE 569 #endif 570 571 572 /* The macros below compute the array size as memSizeType */ 573 /* value. The computation avoids a signed integer overflow. */ 574 /* The computation fails if max_position is the maximum */ 575 /* positive value of intType and min_position is the maximum */ 576 /* negative value of intType. All calls of the macros must */ 577 /* assure that they are never called with this values. Since */ 578 /* the calls either use data from an existing array or use */ 579 /* 1 as min_position this condition is fulfilled. */ 580 #define arraySize(arr) (memSizeType) ((uintType) (arr)->max_position - (uintType) (arr)->min_position + 1) 581 #define arraySize2(min_position,max_position) (memSizeType) ((uintType) (max_position) - (uintType) (min_position) + 1) 582 #define arrayIndex(arr,pos) (memSizeType) ((uintType) (pos) - (uintType) (arr)->min_position) 583 #define arrayMaxPos(min_position,size) (intType) ((uintType) (min_position) + (uintType) (size) - 1) 584 585 #define bitsetSize(set) (memSizeType) ((uintType) (set)->max_position - (uintType) (set)->min_position + 1) 586 #define bitsetSize2(min_position,max_position) (memSizeType) ((uintType) (max_position) - (uintType) (min_position) + 1) 587 #define bitsetIndex(set,pos) (memSizeType) ((uintType) (pos) - (uintType) (set)->min_position) 588 589 590 typedef struct setStruct *setType; 591 typedef struct striStruct *striType; 592 typedef struct bstriStruct *bstriType; 593 typedef struct fileStruct *fileType; 594 typedef struct pollStruct *pollType; 595 typedef struct winStruct *winType; 596 typedef struct processStruct *processType; 597 typedef struct databaseStruct *databaseType; 598 typedef struct sqlStmtStruct *sqlStmtType; 599 600 typedef const struct setStruct *const_setType; 601 typedef const struct striStruct *const_striType; 602 typedef const struct bstriStruct *const_bstriType; 603 typedef const struct fileStruct *const_fileType; 604 typedef const struct pollStruct *const_pollType; 605 typedef const struct winStruct *const_winType; 606 typedef const struct processStruct *const_processType; 607 typedef const struct databaseStruct *const_databaseType; 608 typedef const struct sqlStmtStruct *const_sqlStmtType; 609 610 typedef struct setStruct { 611 intType min_position; 612 intType max_position; 613 bitSetType bitset[1]; 614 } setRecord; 615 616 typedef struct striStruct { 617 memSizeType size; 618 #if WITH_STRI_CAPACITY 619 memSizeType capacity; 620 #endif 621 #if ALLOW_STRITYPE_SLICES 622 strElemType *mem; 623 strElemType mem1[1]; 624 #else 625 strElemType mem[1]; 626 #endif 627 } striRecord; 628 629 typedef struct bstriStruct { 630 memSizeType size; 631 #if ALLOW_BSTRITYPE_SLICES 632 ucharType *mem; 633 ucharType mem1[1]; 634 #else 635 ucharType mem[1]; 636 #endif 637 } bstriRecord; 638 639 typedef struct fileStruct { 640 cFileType cFile; 641 uintType usage_count; 642 } fileRecord; 643 644 typedef struct pollStruct { 645 #if !EMPTY_STRUCTS_ALLOWED 646 int dummy; 647 #endif 648 } pollRecord; 649 650 typedef struct winStruct { 651 uintType usage_count; 652 /* The rest of the structure is only accessible for the driver */ 653 } winRecord; 654 655 typedef struct processStruct { 656 uintType usage_count; 657 fileType stdIn; 658 fileType stdOut; 659 fileType stdErr; 660 /* The rest of the structure is only accessible for the driver */ 661 } processRecord; 662 663 typedef struct databaseStruct { 664 uintType usage_count; 665 /* The rest of the structure is only accessible for the driver */ 666 } databaseRecord; 667 668 typedef struct sqlStmtStruct { 669 uintType usage_count; 670 /* The rest of the structure is only accessible for the driver */ 671 } sqlStmtRecord; 672 673 typedef struct freeListElemStruct { 674 struct freeListElemStruct *next; 675 } *freeListElemType; 676 677 #define LIST_BUFFER_SIZE 4096 678 679 typedef struct bufferStruct { 680 struct bufferStruct *next; 681 ucharType buffer[LIST_BUFFER_SIZE]; 682 } *bufferList; 683 684 685 #if BIGINT_LIB == BIG_RTL_LIBRARY 686 687 /***************************************/ 688 /* */ 689 /* Define bigIntType for big_rtl.c */ 690 /* */ 691 /***************************************/ 692 693 #define WITH_BIGINT_CAPACITY 1 694 695 #ifdef INT64TYPE 696 #define BIGDIGIT_SIZE 32 697 #else 698 #define BIGDIGIT_SIZE 16 699 #endif 700 701 #if BIGDIGIT_SIZE == 8 702 typedef uint8Type bigDigitType; 703 #elif BIGDIGIT_SIZE == 16 704 typedef uint16Type bigDigitType; 705 #elif BIGDIGIT_SIZE == 32 706 typedef uint32Type bigDigitType; 707 #endif 708 709 typedef struct { 710 memSizeType size; 711 #if WITH_BIGINT_CAPACITY 712 memSizeType capacity; 713 #endif 714 bigDigitType bigdigits[1]; 715 } bigIntRecord; 716 717 typedef bigIntRecord *bigIntType; 718 typedef const bigIntRecord *const_bigIntType; 719 720 721 #elif BIGINT_LIB == BIG_GMP_LIBRARY 722 723 /***************************************/ 724 /* */ 725 /* Define bigIntType for big_gmp.c */ 726 /* */ 727 /***************************************/ 728 729 typedef mpz_ptr bigIntType; 730 typedef mpz_srcptr const_bigIntType; 731 732 733 #endif 734 735 /* Logging */ 736 737 #if LOG_FUNCTIONS_EVERYWHERE || (defined LOG_FUNCTIONS && LOG_FUNCTIONS) 738 #if CHECK_STACK 739 #define logFunction(logStatements) checkStack(TRUE); printf(__FILE__ ": "); logStatements 740 #else 741 #define logFunction(logStatements) printf(__FILE__ ": "); logStatements 742 #endif 743 #define logFunctionResult(logStatements) printf(" --> "); logStatements 744 #define logSignalFunction(logStatements) printf(__FILE__ ": "); logStatements 745 #elif CHECK_STACK 746 #define logFunction(logStatements) checkStack(TRUE) 747 #define logFunctionResult(logStatements) 748 #define logSignalFunction(logStatements) 749 #else 750 #define logFunction(logStatements) 751 #define logFunctionResult(logStatements) 752 #define logSignalFunction(logStatements) 753 #endif 754 755 #define logMessage(logStatements) 756 757 #if VERBOSE_EXCEPTIONS_EVERYWHERE || (defined VERBOSE_EXCEPTIONS && VERBOSE_EXCEPTIONS) 758 #define logError(logStatements) printf(" *** "); logStatements 759 #define logErrorIfTrue(cond, logStatements) if (unlikely(cond)) { logError(logStatements) } 760 #else 761 #define logError(logStatements) 762 #define logErrorIfTrue(cond, logStatements) 763 #endif 764 765 #define ANY_LOG_ACTIVE (LOG_FUNCTIONS || LOG_FUNCTIONS_EVERYWHERE || \ 766 VERBOSE_EXCEPTIONS || VERBOSE_EXCEPTIONS_EVERYWHERE) 767 768 /* Allow to activate selected logging functions by adding X. */ 769 770 #define logFunctionX(logStatements) printf(__FILE__ ": "); logStatements 771 #define logFunctionResultX(logStatements) printf(" --> "); logStatements 772 #define logSignalFunctionX(logStatements) printf(__FILE__ ": "); logStatements 773 #define logMessageX(logStatements) logStatements 774 #define logErrorX(logStatements) printf(" *** "); logStatements 775