e576bb2002-10-11Martin Nilsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. */
24ddc71998-03-28Henrik Grubbström (Grubba) 
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifndef GLOBAL_H #define GLOBAL_H
cb22561995-10-11Fredrik Hübinette (Hubbe) 
e37d792004-05-10Marcus Agehall /* Mingw32 workarounds */ #if (defined(__WINNT__) || defined(__WIN32__)) && !defined(__NT__)
7fbe091999-05-11Fredrik Hübinette (Hubbe) #define __NT__ #endif
a2326e1998-03-25Per Hedbor #ifndef _LARGEFILE_SOURCE # define _FILE_OFFSET_BITS 64
06530d2018-05-27Marcus Comstedt # define _TIME_BITS 64
a2326e1998-03-25Per Hedbor # define _LARGEFILE_SOURCE
44da7e2004-05-11Henrik Grubbström (Grubba) /* # define _LARGEFILE64_SOURCE 1 */ /* This one is for explicit 64bit. */
a2326e1998-03-25Per Hedbor #endif
90dc921998-06-12Fredrik Noring /* HPUX needs these too... */ #ifndef __STDC_EXT__ # define __STDC_EXT__ #endif /* !__STDC_EXT__ */
ada73b1999-07-15Henrik Grubbström (Grubba) #ifndef _PROTOTYPES # define _PROTOTYPES #endif /* !_PROTOTYPES */
90dc921998-06-12Fredrik Noring 
e31ef42003-03-12Henrik Grubbström (Grubba) /* And Linux wants this one... */ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif /* !_GNU_SOURCE */
b401a52003-05-02Henrik Grubbström (Grubba) #ifdef __NT__
636e852003-04-30Henrik Grubbström (Grubba) /* To get <windows.h> to stop including the entire OS, * we need to define this one. */ #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif
b401a52003-05-02Henrik Grubbström (Grubba) /* We also need to ensure that we get the WIN32 APIs. */ #ifndef WIN32 #define WIN32 100 /* WinNT 1.0 */ #endif
e37d792004-05-10Marcus Agehall 
9630082013-10-03Henrik Grubbström (Grubba) /* We want WinNT 5.0+ API's if available. * * We avoid the WinNT 6.0+ API's for now. */ #if !defined(_WIN32_WINDOWS) || (_WIN32_WINDOWS < 0x5ff)
e37d792004-05-10Marcus Agehall #undef _WIN32_WINDOWS
9630082013-10-03Henrik Grubbström (Grubba) #define _WIN32_WINDOWS 0x05ff
e37d792004-05-10Marcus Agehall #endif
9630082013-10-03Henrik Grubbström (Grubba) #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x5ff)
44da7e2004-05-11Henrik Grubbström (Grubba) #undef _WIN32_WINNT
9630082013-10-03Henrik Grubbström (Grubba) #define _WIN32_WINNT 0x05ff
b3f7ab2009-05-27Henrik Grubbström (Grubba) #endif /* In later versions of the WIN32 SDKs, we also need to define this one. */
9630082013-10-03Henrik Grubbström (Grubba) #if !defined(NTDDI_VERSION) || (NTDDI_VERSION < 0x05ffffff)
b3f7ab2009-05-27Henrik Grubbström (Grubba) #undef NTDDI_VERSION
9630082013-10-03Henrik Grubbström (Grubba) #define NTDDI_VERSION 0x05ffffff
44da7e2004-05-11Henrik Grubbström (Grubba) #endif
e37d792004-05-10Marcus Agehall 
cdd4c82016-04-06Henrik Grubbström (Grubba) #ifdef _MSC_VER /* Microsoft C. * * Version table from * http://stackoverflow.com/questions/70013/how-to-detect-if-im-compiling-code-with-visual-studio-2008 * MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015) * MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013) * MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012) * MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010) * MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008) * MSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005) * MSVC++ 7.1 _MSC_VER == 1310 (Visual Studio 2003) * MSVC++ 7.0 _MSC_VER == 1300 * MSVC++ 6.0 _MSC_VER == 1200 * MSVC++ 5.0 _MSC_VER == 1100 */
c71f412016-04-06Henrik Grubbström (Grubba) #if _MSC_VER <= 1900
cdd4c82016-04-06Henrik Grubbström (Grubba) /* VS 2015 or earlier do not have all C99 keywords... * cf https://msdn.microsoft.com/en-us/library/bw1hbe6y.aspx */ #define inline __inline
3615092016-04-07Henrik Grubbström (Grubba) #if _MSC_VER <= 1800 /* The isnan() macro was added in VS 2015. */ #define isnan(X) _isnan(X)
abadb02016-04-07Henrik Grubbström (Grubba) #endif /* _MSC_VER <= 1800 */ #endif /* _MSC_VER <= 1900 */ #endif /* _MSC_VER */
cdd4c82016-04-06Henrik Grubbström (Grubba) 
c206f42018-04-26Henrik Grubbström (Grubba) /* NB: Defaults to 64. */ #ifndef FD_SETSIZE /* * In reality: almost unlimited actually. */ #define FD_SETSIZE 65536
fc1e9b2018-04-26Henrik Grubbström (Grubba) #endif /* FD_SETSIZE */
c206f42018-04-26Henrik Grubbström (Grubba) 
b401a52003-05-02Henrik Grubbström (Grubba) #endif /* __NT__ */
5267b71995-08-09Fredrik Hübinette (Hubbe) /* * Some structure forward declarations are needed. */ /* This is needed for linux */ #ifdef MALLOC_REPLACED #define NO_FIX_MALLOC #endif
df80042018-03-05Martin Nilsson struct array;
5267b71995-08-09Fredrik Hübinette (Hubbe) struct function;
df80042018-03-05Martin Nilsson struct mapping; struct multiset;
5267b71995-08-09Fredrik Hübinette (Hubbe) struct object;
df80042018-03-05Martin Nilsson struct pike_string; struct program; struct sockaddr;
5267b71995-08-09Fredrik Hübinette (Hubbe) struct svalue;
ee83561998-08-07Henrik Grubbström (Grubba) struct timeval;
df80042018-03-05Martin Nilsson 
ee83561998-08-07Henrik Grubbström (Grubba) 
e37ef22009-03-18Henrik Grubbström (Grubba) #ifndef CONFIGURE_TEST /* machine.h doesn't exist if we're included from a configure test * program. In that case these defines will already be included. */
cdb4782010-05-30Martin Stjernholm  /* Newer autoconf adds the PACKAGE_* defines for us, regardless * whether we want them or not. If we're being included from a module * they will clash, and so we need to ensure the one for the module * survives, either they are defined already or get defined later. * Tedious work.. */ #ifndef PIKE_CORE #ifdef PACKAGE_NAME #define ORIG_PACKAGE_NAME PACKAGE_NAME #undef PACKAGE_NAME #endif #ifdef PACKAGE_TARNAME #define ORIG_PACKAGE_TARNAME PACKAGE_TARNAME #undef PACKAGE_TARNAME #endif #ifdef PACKAGE_VERSION #define ORIG_PACKAGE_VERSION PACKAGE_VERSION #undef PACKAGE_VERSION #endif #ifdef PACKAGE_STRING #define ORIG_PACKAGE_STRING PACKAGE_STRING #undef PACKAGE_STRING #endif #ifdef PACKAGE_BUGREPORT #define ORIG_PACKAGE_BUGREPORT PACKAGE_BUGREPORT #undef PACKAGE_BUGREPORT #endif #ifdef PACKAGE_URL #define ORIG_PACKAGE_URL PACKAGE_URL #undef PACKAGE_URL #endif
314a812015-10-18Martin Nilsson #endif /* PIKE_CORE */
cdb4782010-05-30Martin Stjernholm 
e37ef22009-03-18Henrik Grubbström (Grubba) #include "machine.h"
cdb4782010-05-30Martin Stjernholm  #ifndef PIKE_CORE #undef PACKAGE_NAME #ifdef ORIG_PACKAGE_NAME #define PACKAGE_NAME ORIG_PACKAGE_NAME #undef ORIG_PACKAGE_NAME #endif #undef PACKAGE_TARNAME #ifdef ORIG_PACKAGE_TARNAME #define PACKAGE_TARNAME ORIG_PACKAGE_TARNAME #undef ORIG_PACKAGE_TARNAME #endif #undef PACKAGE_VERSION #ifdef ORIG_PACKAGE_VERSION #define PACKAGE_VERSION ORIG_PACKAGE_VERSION #undef ORIG_PACKAGE_VERSION #endif #undef PACKAGE_STRING #ifdef ORIG_PACKAGE_STRING #define PACKAGE_STRING ORIG_PACKAGE_STRING #undef ORIG_PACKAGE_STRING #endif #undef PACKAGE_BUGREPORT #ifdef ORIG_PACKAGE_BUGREPORT #define PACKAGE_BUGREPORT ORIG_PACKAGE_BUGREPORT #undef ORIG_PACKAGE_BUGREPORT #endif #undef PACKAGE_URL #ifdef ORIG_PACKAGE_URL #define PACKAGE_URL ORIG_PACKAGE_URL #undef ORIG_PACKAGE_URL #endif
314a812015-10-18Martin Nilsson #endif /* PIKE_CORE */
cdb4782010-05-30Martin Stjernholm 
314a812015-10-18Martin Nilsson #endif /* CONFIGURE_TEST */
e37ef22009-03-18Henrik Grubbström (Grubba) 
9a70e12006-08-02Martin Stjernholm /* Some identifiers used as flags in the machine.h defines. */ #define PIKE_YES 1 #define PIKE_NO 2 #define PIKE_UNKNOWN 3 /* We want to use errno later */ #ifdef _SGI_SPROC_THREADS /* Magic define of _SGI_MP_SOURCE above might redefine errno below */ #include <errno.h> #if defined(HAVE_OSERROR) && !defined(errno) #define errno (oserror()) #endif /* HAVE_OSERROR && !errno */ #endif /* _SGI_SPROC_THREADS */ #ifdef HAVE_FUNCTION_ATTRIBUTES #define ATTRIBUTE(X) __attribute__ (X) #else #define ATTRIBUTE(X) #endif #ifdef HAVE_DECLSPEC #define DECLSPEC(X) __declspec(X) #else /* !HAVE_DECLSPEC */ #define DECLSPEC(X) #endif /* HAVE_DECLSPEC */
dc9a912015-09-27Martin Nilsson #ifdef HAS___BUILTIN_EXPECT # define UNLIKELY(X) __builtin_expect( (long)(X), 0 ) # define LIKELY(X) __builtin_expect( (long)(X), 1 )
3d0aa42014-02-25Per Hedbor #else # define UNLIKELY(X) X # define LIKELY(X) X #endif
9282fd2015-09-27Martin Nilsson #ifdef HAS___BUILTIN_UNREACHABLE # define UNREACHABLE(X) __builtin_unreachable() #else # define UNREACHABLE(X) X #endif
e0dfd02016-11-08Arne Goedeke #ifdef HAS___BUILTIN_ASSUME # define STATIC_ASSUME(X) __builtin_assume(X) #else
399e0b2018-06-18Henrik Grubbström (Grubba) # ifdef HAS___BUILTIN_UNREACHABLE # define STATIC_ASSUME(X) do { if (!(X)) UNREACHABLE(0); } while(0) # else # define STATIC_ASSUME(X) # endif
e0dfd02016-11-08Arne Goedeke #endif
b22fe22017-04-18Henrik Grubbström (Grubba) #ifdef HAS___BUILTIN_CONSTANT_P # define STATIC_IS_CONSTANT(X) __builtin_constant_p(X) #else # define STATIC_IS_CONSTANT(X) 0 #endif
9a70e12006-08-02Martin Stjernholm #ifndef HAVE_WORKING_REALLOC_NULL #define realloc(PTR, SZ) pike_realloc(PTR,SZ) #endif /* NOTE: * PIKE_CONCAT doesn't get defined if there isn't any way to * concatenate symbols */ #ifdef HAVE_ANSI_CONCAT #define PIKE_CONCAT(X,Y) X##Y #define PIKE_CONCAT3(X,Y,Z) X##Y##Z #define PIKE_CONCAT4(X,Y,Z,Q) X##Y##Z##Q #else #ifdef HAVE_KR_CONCAT #define PIKE_CONCAT(X,Y) X/**/Y #define PIKE_CONCAT3(X,Y,Z) X/**/Y/**/Z #define PIKE_CONCAT4(X,Y,Z,Q) X/**/Y/**/Z/**/Q #endif /* HAVE_KR_CONCAT */ #endif /* HAVE_ANSI_CONCAT */ #define TOSTR(X) #X #define DEFINETOSTR(X) TOSTR(X)
189fd01997-01-28Fredrik Hübinette (Hubbe) /* * Max number of local variables in a function. * Currently there is no support for more than 256 */ #define MAX_LOCAL 256
f8731a2017-11-04Marcus Comstedt #if defined(i386) || defined(__powerpc__) || defined(__x86_64__) || (defined(__aarch64__) && defined(__ARM_FEATURE_UNALIGNED))
75920f1997-12-28Fredrik Hübinette (Hubbe) #ifndef HANDLES_UNALIGNED_MEMORY_ACCESS #define HANDLES_UNALIGNED_MEMORY_ACCESS #endif
fcca612016-02-11Martin Nilsson #endif /* i386 */
75920f1997-12-28Fredrik Hübinette (Hubbe) 
cb22561995-10-11Fredrik Hübinette (Hubbe) /* AIX requires this to be the first thing in the file. */
44e2942000-08-11Henrik Grubbström (Grubba) #if HAVE_ALLOCA_H # include <alloca.h> # ifdef __GNUC__ # ifdef alloca # undef alloca # endif # define alloca __builtin_alloca
13670c2015-05-25Martin Nilsson # endif
cb22561995-10-11Fredrik Hübinette (Hubbe) #else
44e2942000-08-11Henrik Grubbström (Grubba) # ifdef __GNUC__ # ifdef alloca # undef alloca # endif # define alloca __builtin_alloca
cb22561995-10-11Fredrik Hübinette (Hubbe) # else # ifdef _AIX
b6163c2015-05-08Martin Nilsson #pragma alloca
cb22561995-10-11Fredrik Hübinette (Hubbe) # else # ifndef alloca /* predefined by HP cc +Olibcalls */
44e2942000-08-11Henrik Grubbström (Grubba) void *alloca();
cb22561995-10-11Fredrik Hübinette (Hubbe) # endif # endif # endif
5401b61999-08-06Fredrik Hübinette (Hubbe) #endif
a3d6092004-09-26Marcus Comstedt #ifdef HAVE_DEVICES_TIMER_H /* On AmigaOS, struct timeval is defined in a variety of places and a variety of ways. Making sure <devices/timer.h> is included first brings some amount of order to the chaos. */ #include <devices/timer.h> #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) #include <stdio.h>
c3df542008-10-06Martin Stjernholm #include <stdarg.h>
5267b71995-08-09Fredrik Hübinette (Hubbe) #include <stdlib.h>
1e577b1999-07-15Fredrik Hübinette (Hubbe) #include <stddef.h>
7112872015-10-18Martin Nilsson #include <string.h> #include <limits.h> #include <float.h>
1e577b1999-07-15Fredrik Hübinette (Hubbe) 
75920f1997-12-28Fredrik Hübinette (Hubbe) #ifdef HAVE_MALLOC_H
31c8ed2003-04-17Xavier Beaudouin #if !defined(__FreeBSD__) && !defined(__OpenBSD__)
2139ba2003-04-16Xavier Beaudouin /* FreeBSD and OpenBSD has <malloc.h>, but it just contains a warning... */
75920f1997-12-28Fredrik Hübinette (Hubbe) #include <malloc.h>
31c8ed2003-04-17Xavier Beaudouin #endif /* !__FreeBSD__ && !__OpenBSD */
75920f1997-12-28Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) #ifdef HAVE_UNISTD_H #include <unistd.h> #endif
9aa6fa1997-05-19Fredrik Hübinette (Hubbe) #include <sys/types.h>
419ede1996-11-13Fredrik Hübinette (Hubbe) 
9aa6fa1997-05-19Fredrik Hübinette (Hubbe) #ifdef HAVE_MEMORY_H #include <memory.h>
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif
b4dd8c1999-06-19Fredrik Hübinette (Hubbe) #ifdef HAVE_WINDOWS_H #include <windows.h> #endif
4087a12003-05-01Henrik Grubbström (Grubba) /* Get INT64, INT32, INT16, INT8, et al. */ #include "pike_int_types.h"
2b0d732000-01-09Fredrik Hübinette (Hubbe) 
bed9601997-05-19Fredrik Hübinette (Hubbe) #define SIZE_T unsigned INT32
7e877a2003-04-02Martin Stjernholm #define TYPE_T unsigned int
bed9601997-05-19Fredrik Hübinette (Hubbe) #define TYPE_FIELD unsigned INT16
6d22541998-01-28Fredrik Hübinette (Hubbe) #define B1_T char
bed9601997-05-19Fredrik Hübinette (Hubbe) 
6d22541998-01-28Fredrik Hübinette (Hubbe) #if SIZEOF_SHORT == 2 #define B2_T short #elif SIZEOF_INT == 2 #define B2_T int #endif #if SIZEOF_SHORT == 4 #define B4_T short #elif SIZEOF_INT == 4 #define B4_T int #elif SIZEOF_LONG == 4 #define B4_T long #endif #if SIZEOF_INT == 8 #define B8_T int #elif SIZEOF_LONG == 8 #define B8_T long
3f3e4d2000-08-03Henrik Grubbström (Grubba) #elif (SIZEOF_LONG_LONG - 0) == 8 #define B8_T long long #elif (SIZEOF___INT64 - 0) == 8 #define B8_T __int64
6d22541998-01-28Fredrik Hübinette (Hubbe) #elif SIZEOF_CHAR_P == 8 #define B8_T char * #endif
d7929e2018-01-28Martin Nilsson #if (SIZEOF___INT128 - 0) == 16 #define B16_T __int128
6d22541998-01-28Fredrik Hübinette (Hubbe) #endif
9aa6fa1997-05-19Fredrik Hübinette (Hubbe) 
4087a12003-05-01Henrik Grubbström (Grubba) /* INT_TYPE stuff */ #ifndef MAX_INT_TYPE
fcca612016-02-11Martin Nilsson # ifdef WITH_SHORT_INT
4087a12003-05-01Henrik Grubbström (Grubba)  # define MAX_INT_TYPE SHRT_MAX # define MIN_INT_TYPE SHRT_MIN # define PRINTPIKEINT "h"
7c1a312003-11-07Martin Stjernholm # define INT_ARG_TYPE int
4087a12003-05-01Henrik Grubbström (Grubba) 
fcca612016-02-11Martin Nilsson # elif defined(WITH_INT_INT)
4087a12003-05-01Henrik Grubbström (Grubba)  # define MAX_INT_TYPE INT_MAX # define MIN_INT_TYPE INT_MIN # define PRINTPIKEINT ""
fcca612016-02-11Martin Nilsson # elif defined(WITH_LONG_INT)
4087a12003-05-01Henrik Grubbström (Grubba)  # define MAX_INT_TYPE LONG_MAX # define MIN_INT_TYPE LONG_MIN # define PRINTPIKEINT "l"
fcca612016-02-11Martin Nilsson # elif defined(WITH_LONG_LONG_INT)
4087a12003-05-01Henrik Grubbström (Grubba)  # ifdef LLONG_MAX # define MAX_INT_TYPE LLONG_MAX # define MIN_INT_TYPE LLONG_MIN # else # define MAX_INT_TYPE LONG_LONG_MAX # define MIN_INT_TYPE LONG_LONG_MIN # endif # define PRINTPIKEINT "ll" # endif #endif
7c1a312003-11-07Martin Stjernholm /* INT_ARG_TYPE is a type suitable for argument passing that at least * can hold an INT_TYPE value. */ #ifndef INT_ARG_TYPE #define INT_ARG_TYPE INT_TYPE #endif
4087a12003-05-01Henrik Grubbström (Grubba) #if SIZEOF_INT_TYPE - 0 == 0 # error Unsupported type chosen for native pike integers. #endif #if SIZEOF_INT_TYPE != 4 # define INT_TYPE_INT32_CONVERSION #endif /* FLOAT_TYPE stuff */
fcca612016-02-11Martin Nilsson #ifdef WITH_LONG_DOUBLE_PRECISION_SVALUE
8ae0492003-11-07Martin Stjernholm  # define PIKEFLOAT_MANT_DIG LDBL_MANT_DIG # define PIKEFLOAT_DIG LDBL_DIG # define PIKEFLOAT_MIN_EXP LDBL_MIN_EXP # define PIKEFLOAT_MAX_EXP LDBL_MAX_EXP # define PIKEFLOAT_MIN_10_EXP LDBL_MIN_10_EXP # define PIKEFLOAT_MAX_10_EXP LDBL_MAX_10_EXP # define PIKEFLOAT_MAX LDBL_MAX # define PIKEFLOAT_MIN LDBL_MIN # define PIKEFLOAT_EPSILON LDBL_EPSILON # define PRINTPIKEFLOAT "L"
fcca612016-02-11Martin Nilsson #elif defined(WITH_DOUBLE_PRECISION_SVALUE)
8ae0492003-11-07Martin Stjernholm  # define PIKEFLOAT_MANT_DIG DBL_MANT_DIG # define PIKEFLOAT_DIG DBL_DIG # define PIKEFLOAT_MIN_EXP DBL_MIN_EXP # define PIKEFLOAT_MAX_EXP DBL_MAX_EXP # define PIKEFLOAT_MIN_10_EXP DBL_MIN_10_EXP # define PIKEFLOAT_MAX_10_EXP DBL_MAX_10_EXP # define PIKEFLOAT_MAX DBL_MAX # define PIKEFLOAT_MIN DBL_MIN # define PIKEFLOAT_EPSILON DBL_EPSILON # define PRINTPIKEFLOAT ""
4087a12003-05-01Henrik Grubbström (Grubba) #else
8ae0492003-11-07Martin Stjernholm  # define PIKEFLOAT_MANT_DIG FLT_MANT_DIG # define PIKEFLOAT_DIG FLT_DIG # define PIKEFLOAT_MIN_EXP FLT_MIN_EXP # define PIKEFLOAT_MAX_EXP FLT_MAX_EXP # define PIKEFLOAT_MIN_10_EXP FLT_MIN_10_EXP # define PIKEFLOAT_MAX_10_EXP FLT_MAX_10_EXP # define PIKEFLOAT_MAX FLT_MAX # define PIKEFLOAT_MIN FLT_MIN # define PIKEFLOAT_EPSILON FLT_EPSILON # define PRINTPIKEFLOAT ""
7c1a312003-11-07Martin Stjernholm # define FLOAT_ARG_TYPE double #endif
8ae0492003-11-07Martin Stjernholm 
7c1a312003-11-07Martin Stjernholm /* FLOAT_ARG_TYPE is a type suitable for argument passing that at * least can hold a FLOAT_TYPE value. */ #ifndef FLOAT_ARG_TYPE #define FLOAT_ARG_TYPE FLOAT_TYPE
4087a12003-05-01Henrik Grubbström (Grubba) #endif #if SIZEOF_FLOAT_TYPE - 0 == 0 #error Unsupported type chosen for pike floats. #endif
0e4bb82008-06-29Martin Stjernholm /* Conceptually a char is a 32 bit signed value. Implementationwise * that means that the shorter ones don't have space for the sign bit. */
3e625c1998-10-11Fredrik Hübinette (Hubbe) typedef unsigned char p_wchar0; typedef unsigned INT16 p_wchar1;
0e4bb82008-06-29Martin Stjernholm typedef signed INT32 p_wchar2;
3e625c1998-10-11Fredrik Hübinette (Hubbe) 
9c017b2016-08-20Martin Nilsson enum size_shift { eightbit=0, sixteenbit=1, thirtytwobit=2, };
3ef4661999-02-27Henrik Grubbström (Grubba) typedef struct p_wchar_p {
dcdb232014-08-28Per Hedbor  void *ptr;
9c017b2016-08-20Martin Nilsson  enum size_shift shift;
3ef4661999-02-27Henrik Grubbström (Grubba) } PCHARP;
9aa6fa1997-05-19Fredrik Hübinette (Hubbe) 
be76b02016-02-07Martin Nilsson #define WERR(...) fprintf(stderr,__VA_ARGS__)
ae95031999-04-07Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
74e6b32009-03-15Martin Stjernholm 
ae95031999-04-07Fredrik Hübinette (Hubbe) #define DO_IF_DEBUG(X) X
74e6b32009-03-15Martin Stjernholm #define DO_IF_DEBUG_ELSE(DEBUG, NO_DEBUG) DEBUG
be76b02016-02-07Martin Nilsson #define DWERR(...) WERR(__VA_ARGS__)
74e6b32009-03-15Martin Stjernholm 
c53bb62018-01-28Martin Nilsson /* Control assert() definition in <assert.h> */
60092b2018-01-28Henrik Grubbström (Grubba) #undef NDEBUG
74e6b32009-03-15Martin Stjernholm /* Set of macros to simplify passing __FILE__ and __LINE__ to * functions only in debug mode. */ #define DLOC __FILE__, __LINE__ #define COMMA_DLOC , __FILE__, __LINE__ #define DLOC_DECL const char *dloc_file, int dloc_line #define COMMA_DLOC_DECL , const char *dloc_file, int dloc_line #define DLOC_ARGS dloc_file, dloc_line #define DLOC_ARGS_OPT dloc_file, dloc_line #define COMMA_DLOC_ARGS_OPT , dloc_file, dloc_line
9a8ddb2014-11-16Henrik Grubbström (Grubba) #define USE_DLOC_ARGS() ((void)(DLOC_ARGS_OPT))
74e6b32009-03-15Martin Stjernholm #define DLOC_ENABLED #else /* !PIKE_DEBUG */
ae95031999-04-07Fredrik Hübinette (Hubbe) #define DO_IF_DEBUG(X)
74e6b32009-03-15Martin Stjernholm #define DO_IF_DEBUG_ELSE(DEBUG, NO_DEBUG) NO_DEBUG
be76b02016-02-07Martin Nilsson #define DWERR(...)
60092b2018-01-28Henrik Grubbström (Grubba) #define NDEBUG
74e6b32009-03-15Martin Stjernholm  #define DLOC #define COMMA_DLOC #define DLOC_DECL #define COMMA_DLOC_DECL #define DLOC_ARGS __FILE__, __LINE__ #define DLOC_ARGS_OPT #define COMMA_DLOC_ARGS_OPT
9a8ddb2014-11-16Henrik Grubbström (Grubba) #define USE_DLOC_ARGS()
74e6b32009-03-15Martin Stjernholm  #endif /* !PIKE_DEBUG */
ae95031999-04-07Fredrik Hübinette (Hubbe) 
8072942010-10-10Martin Stjernholm #include <assert.h>
cd9dfa2008-03-29Martin Stjernholm #if defined (PIKE_DEBUG) || defined (DO_PIKE_CLEANUP) #define DO_IF_DEBUG_OR_CLEANUP(X) X #else #define DO_IF_DEBUG_OR_CLEANUP(X) #endif
a8a8132002-09-13Martin Stjernholm #ifdef INTERNAL_PROFILING #define DO_IF_INTERNAL_PROFILING(X) X #else #define DO_IF_INTERNAL_PROFILING(X) #endif
74dfe82012-12-30Jonas Walldén /* Suppress compiler warnings for unused parameters if possible. The mangling of argument name is required to catch when an unused argument later is used without removing the annotation. */
2a84e92014-11-16Henrik Grubbström (Grubba) #ifndef PIKE_UNUSED_ATTRIBUTE
74dfe82012-12-30Jonas Walldén # ifdef __GNUC__
2a84e92014-11-16Henrik Grubbström (Grubba) # define PIKE_UNUSED_ATTRIBUTE __attribute__((unused))
377d052015-05-26Henrik Grubbström (Grubba) # if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) # define PIKE_WARN_UNUSED_RESULT_ATTRIBUTE __attribute__((warn_unused_result)) # else /* GCC < 3.4 */ # define PIKE_WARN_UNUSED_RESULT_ATTRIBUTE # endif
74dfe82012-12-30Jonas Walldén # else
2a84e92014-11-16Henrik Grubbström (Grubba) # define PIKE_UNUSED_ATTRIBUTE
377d052015-05-26Henrik Grubbström (Grubba) # define PIKE_WARN_UNUSED_RESULT_ATTRIBUTE
74dfe82012-12-30Jonas Walldén # endif #endif
2a84e92014-11-16Henrik Grubbström (Grubba) #ifndef PIKE_UNUSED # define PIKE_UNUSED(x) PIKE_CONCAT(x,_UNUSED) PIKE_UNUSED_ATTRIBUTE #endif
03ce312014-10-01Henrik Grubbström (Grubba) #ifndef UNUSED
2a84e92014-11-16Henrik Grubbström (Grubba) # define UNUSED(x) PIKE_UNUSED(x)
03ce312014-10-01Henrik Grubbström (Grubba) #endif
1d4cf12014-08-22Arne Goedeke #ifdef PIKE_DEBUG # define DEBUGUSED(x) x #else
03ce312014-10-01Henrik Grubbström (Grubba) # define DEBUGUSED(x) PIKE_UNUSED(x)
74dfe82012-12-30Jonas Walldén #endif
1d4cf12014-08-22Arne Goedeke #ifdef DEBUG_MALLOC # define DMALLOCUSED(x) x #else
03ce312014-10-01Henrik Grubbström (Grubba) # define DMALLOCUSED(x) PIKE_UNUSED(x)
1d4cf12014-08-22Arne Goedeke #endif
74dfe82012-12-30Jonas Walldén 
89b0112006-07-05Martin Stjernholm /* PMOD_EXPORT exports a function / variable vfsh. */
2ba1a42003-03-29Henrik Grubbström (Grubba) #ifndef PMOD_EXPORT
89b0112006-07-05Martin Stjernholm # if defined (__NT__) && defined (USE_DLL) # ifdef DYNAMIC_MODULE # define PMOD_EXPORT __declspec(dllimport) # else /* A pmod export becomes an import in the dynamic module. This means * that modules can't use PMOD_EXPORT for identifiers they export * themselves, unless they are compiled statically. */ # define PMOD_EXPORT __declspec(dllexport) # endif
4e69ce2012-12-29Jonas Walldén # elif defined(__clang__) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) /* According to Clang source the protected behavior is ELF-specific and not applicable to OS X. */ # define PMOD_EXPORT __attribute__ ((visibility("default")))
bde77e2011-05-01Per Hedbor # elif __GNUC__ >= 4
871b012011-05-02Per Hedbor # ifdef DYNAMIC_MODULE # define PMOD_EXPORT __attribute__ ((visibility("default"))) # else # define PMOD_EXPORT __attribute__ ((visibility("protected"))) # endif
13670c2015-05-25Martin Nilsson # else
89b0112006-07-05Martin Stjernholm # define PMOD_EXPORT # endif #endif
1f21332000-07-28Fredrik Hübinette (Hubbe)  #ifndef PMOD_PROTO #define PMOD_PROTO #endif
343c592004-03-16Martin Stjernholm #ifndef DO_PIKE_CLEANUP
9fb79c2004-09-27Martin Stjernholm #if defined(PURIFY) || defined(__CHECKER__) || defined(DEBUG_MALLOC)
ae95031999-04-07Fredrik Hübinette (Hubbe) #define DO_PIKE_CLEANUP #endif
343c592004-03-16Martin Stjernholm #endif
ae95031999-04-07Fredrik Hübinette (Hubbe) 
5ce64f2009-03-19Henrik Grubbström (Grubba) #ifndef HAVE_STRUCT_IOVEC #define HAVE_STRUCT_IOVEC struct iovec { void *iov_base; size_t iov_len; }; #endif /* !HAVE_STRUCT_IOVEC */
55ff762018-03-23Henrik Grubbström (Grubba) #ifdef HAVE_NON_SCALAR_OFF64_T /* Old Solaris uses unions instead of long long for 64bit values when __STDC__. * * Add some conversion functions for convenience. * * The types longlong_t and u_longlong_t are both from <sys/types.h>. * * Common types that are compatible with longlong_t: * off64_t, blckcnt64_t, offset_t, diskaddr_t * * Common types that are compatible with u_longlong_t: * ino64_t, fsblkcnt64_t, fsfilcnt64_t, u_offset_t, len_t */ static inline INT64 PIKE_UNUSED_ATTRIBUTE pike_longlong_to_int64(longlong_t val) { union { INT64 scalar; longlong_t longlong; } tmp; tmp.longlong = val; return tmp.scalar; } static inline unsigned INT64 PIKE_UNUSED_ATTRIBUTE pike_ulonglong_to_uint64(u_longlong_t val) { union { unsigned INT64 uscalar; u_longlong_t ulonglong; } tmp; tmp.ulonglong = val; return tmp.uscalar; } static inline longlong_t PIKE_UNUSED_ATTRIBUTE pike_int64_to_longlong(INT64 val) { union { INT64 scalar; longlong_t longlong; } tmp; tmp.scalar = val; return tmp.longlong; } static inline u_longlong_t PIKE_UNUSED_ATTRIBUTE pike_uint64_to_ulonglong(unsigned INT64 val) { union { unsigned INT64 uscalar; u_longlong_t ulonglong; } tmp; tmp.uscalar = val; return tmp.ulonglong; } #else /* !HAVE_NON_SCALAR_OFF64_T */ #define pike_longlong_to_int64(VAL) ((INT64)(VAL)) #define pike_ulonglong_to_uint64(VAL) ((unsigned INT64)(VAL)) #define pike_int64_to_longlong(VAL) ((INT64)(VAL)) #define pike_uint64_to_ulonglong(VAL) ((unsigned INT64)(VAL)) #endif /* HAVE_NON_SCALAR_OFF64_T */
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "port.h"
61e9a01998-01-25Fredrik Hübinette (Hubbe) #include "dmalloc.h"
88696e2007-06-18Martin Stjernholm  /* Either this include must go or the include of threads.h in * pike_cpulib.h. Otherwise we get pesky include loops. */ /* #include "pike_cpulib.h" */
5267b71995-08-09Fredrik Hübinette (Hubbe)  #ifdef MALLOC_DECL_MISSING
c6d5bb2016-02-07Martin Nilsson void *malloc (int); void *realloc (void *,int); void free (void *); void *calloc (int,int);
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif #ifdef GETPEERNAME_DECL_MISSING
c6d5bb2016-02-07Martin Nilsson int getpeername (int, struct sockaddr *, int *);
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif #ifdef GETHOSTNAME_DECL_MISSING
c6d5bb2016-02-07Martin Nilsson void gethostname (char *,int);
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif #ifdef POPEN_DECL_MISSING
c6d5bb2016-02-07Martin Nilsson FILE *popen (char *,char *);
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif #ifdef GETENV_DECL_MISSING
c6d5bb2016-02-07Martin Nilsson char *getenv (char *);
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif
21aa9b2000-12-13Fredrik Hübinette (Hubbe) /* If this define is present, error() has been renamed to Pike_error() and * error.h has been renamed to pike_error.h * Expect to see other similar defines in the future. -Hubbe */ #define Pike_error_present
3913502002-06-25Henrik Grubbström (Grubba) /* Compatibility... */ #define USE_PIKE_TYPE 2
d68a072001-02-20Henrik Grubbström (Grubba) 
3a2a732002-04-09Mikael Brandström /* Used in more than one place, better put it here */
ec41312016-02-11Martin Nilsson #ifdef PROFILING
3a2a732002-04-09Mikael Brandström #define DO_IF_PROFILING(X) X #else #define DO_IF_PROFILING(X) #endif
b2630d2004-05-20Henrik Grubbström (Grubba) /* #define PROFILING_DEBUG */ #ifdef PROFILING_DEBUG
ec41312016-02-11Martin Nilsson #define W_PROFILING_DEBUG(...) WERR(__VA_ARGS__)
b2630d2004-05-20Henrik Grubbström (Grubba) #else /* !PROFILING_DEBUG */
ec41312016-02-11Martin Nilsson #define W_PROFILING_DEBIG(...)
b2630d2004-05-20Henrik Grubbström (Grubba) #endif /* PROFILING_DEBUG */
72a9d22017-04-11Henrik Grubbström (Grubba) #ifdef HAVE_C99_STRUCT_LITERAL_EXPR /* This macro is used for eg type-safe struct initializers. */
1134172017-04-11Henrik Grubbström (Grubba) #define CAST_STRUCT_LITERAL(TYPE) (TYPE)
72a9d22017-04-11Henrik Grubbström (Grubba) #else /* Prior to C99 the literal was a special form only valid in * initializers (ie not in general expressions). */
1134172017-04-11Henrik Grubbström (Grubba) #define CAST_STRUCT_LITERAL(TYPE)
72a9d22017-04-11Henrik Grubbström (Grubba) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif