3 * Copyright (c) 1991-1997, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
10 #if !defined(__STDC__)
21 #define Null(type) ((type)NULL)
22 #define Nullch Null(char*)
23 #define Nullfp Null(PerlIO*)
24 #define Nullsv Null(SV*)
36 /* XXX Configure ought to have a test for a boolean type, if I can
37 just figure out all the headers such a test needs.
38 Andy Dougherty August 1996
40 /* bool is built-in for g++-2.6.3, which might be used for an extension.
41 If the extension includes <_G_config.h> before this file then
42 _G_HAVE_BOOL will be properly set. If, however, the extension includes
43 this file first, then you will have to manually set -DHAS_BOOL in
44 your command line to avoid a conflict.
54 /* The NeXT dynamic loader headers will not build with the bool macro
55 So declare them now to clear confusion.
60 typedef enum bool { FALSE = 0, TRUE = 1 } bool;
64 # endif /* !HAS_BOOL */
68 # if defined(UTS) || defined(VMS)
75 /* XXX A note on the perl source internal type system. The
76 original intent was that I32 be *exactly* 32 bits.
78 Currently, we only guarantee that I32 is *at least* 32 bits.
79 Specifically, if int is 64 bits, then so is I32. (This is the case
80 for the Cray.) This has the advantage of meshing nicely with
81 standard library calls (where we pass an I32 and the library is
82 expecting an int), but the disadvantage that an I32 is not 32 bits.
83 Andy Dougherty August 1996
85 In the future, we may perhaps want to think about something like
99 For the moment, these are mentioned here so metaconfig will
100 construct Configure to figure out the various sizes.
104 typedef unsigned char U8;
105 /* I8_MAX and I8_MIN constants are not defined, as I8 is an ambiguous type.
106 Please search CHAR_MAX in perl.h for further details. */
107 #define U8_MAX PERL_UCHAR_MAX
108 #define U8_MIN PERL_UCHAR_MIN
111 typedef unsigned short U16;
112 #define I16_MAX PERL_SHORT_MAX
113 #define I16_MIN PERL_SHORT_MIN
114 #define U16_MAX PERL_USHORT_MAX
115 #define U16_MIN PERL_USHORT_MIN
117 #if BYTEORDER > 0x4321
119 typedef unsigned int U32;
120 # define I32_MAX PERL_INT_MAX
121 # define I32_MIN PERL_INT_MIN
122 # define U32_MAX PERL_UINT_MAX
123 # define U32_MIN PERL_UINT_MIN
126 typedef unsigned long U32;
127 # define I32_MAX PERL_LONG_MAX
128 # define I32_MIN PERL_LONG_MIN
129 # define U32_MAX PERL_ULONG_MAX
130 # define U32_MIN PERL_ULONG_MIN
133 #define BIT_DIGITS(N) (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */
134 #define TYPE_DIGITS(T) BIT_DIGITS(sizeof(T) * 8)
135 #define TYPE_CHARS(T) (TYPE_DIGITS(T) + 2) /* sign, NUL */
137 #define Ctl(ch) ((ch) & 037)
139 #define strNE(s1,s2) (strcmp(s1,s2))
140 #define strEQ(s1,s2) (!strcmp(s1,s2))
141 #define strLT(s1,s2) (strcmp(s1,s2) < 0)
142 #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
143 #define strGT(s1,s2) (strcmp(s1,s2) > 0)
144 #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
145 #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
146 #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
149 # define memNE(s1,s2,l) (memcmp(s1,s2,l))
150 # define memEQ(s1,s2,l) (!memcmp(s1,s2,l))
152 # define memNE(s1,s2,l) (bcmp(s1,s2,l))
153 # define memEQ(s1,s2,l) (!bcmp(s1,s2,l))
159 * Unfortunately, the introduction of locales means that we
160 * can't trust isupper(), etc. to tell the truth. And when
161 * it comes to /\w+/ with tainting enabled, we *must* be able
162 * to trust our character classes.
164 * Therefore, the default tests in the text of Perl will be
165 * independent of locale. Any code that wants to depend on
166 * the current locale will use the tests that begin with "lc".
169 #ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */
175 #define isALNUM(c) (isALPHA(c) || isDIGIT(c) || (c) == '_')
176 #define isIDFIRST(c) (isALPHA(c) || (c) == '_')
177 #define isALPHA(c) (isUPPER(c) || isLOWER(c))
179 ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) =='\r' || (c) == '\f')
180 #define isDIGIT(c) ((c) >= '0' && (c) <= '9')
181 #define isUPPER(c) ((c) >= 'A' && (c) <= 'Z')
182 #define isLOWER(c) ((c) >= 'a' && (c) <= 'z')
183 #define isPRINT(c) (((c) > 32 && (c) < 127) || isSPACE(c))
184 #define toUPPER(c) (isLOWER(c) ? (c) - ('a' - 'A') : (c))
185 #define toLOWER(c) (isUPPER(c) ? (c) + ('a' - 'A') : (c))
187 #ifdef USE_NEXT_CTYPE
189 # define isALNUM_LC(c) \
190 (NXIsAlpha((unsigned int)(c)) || NXIsDigit((unsigned int)(c)) || \
192 # define isIDFIRST_LC(c) \
193 (NXIsAlpha((unsigned int)(c)) || (char)(c) == '_')
194 # define isALPHA_LC(c) NXIsAlpha((unsigned int)(c))
195 # define isSPACE_LC(c) NXIsSpace((unsigned int)(c))
196 # define isDIGIT_LC(c) NXIsDigit((unsigned int)(c))
197 # define isUPPER_LC(c) NXIsUpper((unsigned int)(c))
198 # define isLOWER_LC(c) NXIsLower((unsigned int)(c))
199 # define isPRINT_LC(c) NXIsPrint((unsigned int)(c))
200 # define toUPPER_LC(c) NXToUpper((unsigned int)(c))
201 # define toLOWER_LC(c) NXToLower((unsigned int)(c))
203 #else /* !USE_NEXT_CTYPE */
204 # if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
206 # define isALNUM_LC(c) \
207 (isalpha((unsigned char)(c)) || \
208 isdigit((unsigned char)(c)) || (char)(c) == '_')
209 # define isIDFIRST_LC(c) (isalpha((unsigned char)(c)) || (char)(c) == '_')
210 # define isALPHA_LC(c) isalpha((unsigned char)(c))
211 # define isSPACE_LC(c) isspace((unsigned char)(c))
212 # define isDIGIT_LC(c) isdigit((unsigned char)(c))
213 # define isUPPER_LC(c) isupper((unsigned char)(c))
214 # define isLOWER_LC(c) islower((unsigned char)(c))
215 # define isPRINT_LC(c) isprint((unsigned char)(c))
216 # define toUPPER_LC(c) toupper((unsigned char)(c))
217 # define toLOWER_LC(c) tolower((unsigned char)(c))
221 # define isALNUM_LC(c) \
222 (isascii(c) && (isalpha(c) || isdigit(c) || (c) == '_'))
223 # define isIDFIRST_LC(c) (isascii(c) && (isalpha(c) || (c) == '_'))
224 # define isALPHA_LC(c) (isascii(c) && isalpha(c))
225 # define isSPACE_LC(c) (isascii(c) && isspace(c))
226 # define isDIGIT_LC(c) (isascii(c) && isdigit(c))
227 # define isUPPER_LC(c) (isascii(c) && isupper(c))
228 # define isLOWER_LC(c) (isascii(c) && islower(c))
229 # define isPRINT_LC(c) (isascii(c) && isprint(c))
230 # define toUPPER_LC(c) toupper(c)
231 # define toLOWER_LC(c) tolower(c)
234 #endif /* USE_NEXT_CTYPE */
236 /* This conversion works both ways, strangely enough. */
237 #define toCTRL(c) (toUPPER(c) ^ 64)
239 /* Line numbers are unsigned, 16 bits. */
242 #define NOLINE ((line_t)0)
244 #define NOLINE ((line_t) 65535)
247 /* XXX LEAKTEST doesn't really work in perl5. There are direct calls to
248 safemalloc() in the source, so LEAKTEST won't pick them up.
249 Further, if you try LEAKTEST, you'll also end up calling
250 Safefree, which might call safexfree() on some things that weren't
251 malloced with safexmalloc. The correct "fix" to this, if anyone
252 is interested, is to ensure that all calls go through the New and
254 --Andy Dougherty August 1996
260 #define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n)*sizeof(t))))
261 #define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n)*sizeof(t))))
262 #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n)*sizeof(t)))), \
263 memzero((char*)(v), (n)*sizeof(t))
264 #define Renew(v,n,t) \
265 (v = (t*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))
266 #define Renewc(v,n,t,c) \
267 (v = (c*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))
268 #define Safefree(d) safefree((Malloc_t)(d))
269 #define NEWSV(x,len) newSV(len)
273 #define New(x,v,n,t) (v = (t*)safexmalloc((x),(MEM_SIZE)((n)*sizeof(t))))
274 #define Newc(x,v,n,t,c) (v = (c*)safexmalloc((x),(MEM_SIZE)((n)*sizeof(t))))
275 #define Newz(x,v,n,t) (v = (t*)safexmalloc((x),(MEM_SIZE)((n)*sizeof(t)))), \
276 memzero((char*)(v), (n)*sizeof(t))
277 #define Renew(v,n,t) \
278 (v = (t*)safexrealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))
279 #define Renewc(v,n,t,c) \
280 (v = (c*)safexrealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))
281 #define Safefree(d) safexfree((Malloc_t)d)
282 #define NEWSV(x,len) newSV(x,len)
284 #define MAXXCOUNT 1400
285 long xcount[MAXXCOUNT];
286 long lastxcount[MAXXCOUNT];
288 #endif /* LEAKTEST */
290 #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
291 #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
292 #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
296 #define New(x,v,n,s) (v = Null(s *))
297 #define Newc(x,v,n,s,c) (v = Null(s *))
298 #define Newz(x,v,n,s) (v = Null(s *))
299 #define Renew(v,n,s) (v = Null(s *))
300 #define Move(s,d,n,t)
301 #define Copy(s,d,n,t)
303 #define Safefree(d) (d) = (d)
307 #ifdef USE_STRUCT_COPY
308 #define StructCopy(s,d,t) (*((t*)(d)) = *((t*)(s)))
310 #define StructCopy(s,d,t) Copy(s,d,1,t)