1*0Sstevel@tonic-gate /* handy.h 2*0Sstevel@tonic-gate * 3*0Sstevel@tonic-gate * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999, 4*0Sstevel@tonic-gate * 2000, 2001, 2002, 2004, by Larry Wall and others 5*0Sstevel@tonic-gate * 6*0Sstevel@tonic-gate * You may distribute under the terms of either the GNU General Public 7*0Sstevel@tonic-gate * License or the Artistic License, as specified in the README file. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate */ 10*0Sstevel@tonic-gate 11*0Sstevel@tonic-gate #if !defined(__STDC__) 12*0Sstevel@tonic-gate #ifdef NULL 13*0Sstevel@tonic-gate #undef NULL 14*0Sstevel@tonic-gate #endif 15*0Sstevel@tonic-gate #ifndef I286 16*0Sstevel@tonic-gate # define NULL 0 17*0Sstevel@tonic-gate #else 18*0Sstevel@tonic-gate # define NULL 0L 19*0Sstevel@tonic-gate #endif 20*0Sstevel@tonic-gate #endif 21*0Sstevel@tonic-gate 22*0Sstevel@tonic-gate #define Null(type) ((type)NULL) 23*0Sstevel@tonic-gate 24*0Sstevel@tonic-gate /* 25*0Sstevel@tonic-gate =head1 Handy Values 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate =for apidoc AmU||Nullch 28*0Sstevel@tonic-gate Null character pointer. 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate =for apidoc AmU||Nullsv 31*0Sstevel@tonic-gate Null SV pointer. 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate =cut 34*0Sstevel@tonic-gate */ 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate #define Nullch Null(char*) 37*0Sstevel@tonic-gate #define Nullfp Null(PerlIO*) 38*0Sstevel@tonic-gate #define Nullsv Null(SV*) 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate #ifdef TRUE 41*0Sstevel@tonic-gate #undef TRUE 42*0Sstevel@tonic-gate #endif 43*0Sstevel@tonic-gate #ifdef FALSE 44*0Sstevel@tonic-gate #undef FALSE 45*0Sstevel@tonic-gate #endif 46*0Sstevel@tonic-gate #define TRUE (1) 47*0Sstevel@tonic-gate #define FALSE (0) 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate /* XXX Configure ought to have a test for a boolean type, if I can 51*0Sstevel@tonic-gate just figure out all the headers such a test needs. 52*0Sstevel@tonic-gate Andy Dougherty August 1996 53*0Sstevel@tonic-gate */ 54*0Sstevel@tonic-gate /* bool is built-in for g++-2.6.3 and later, which might be used 55*0Sstevel@tonic-gate for extensions. <_G_config.h> defines _G_HAVE_BOOL, but we can't 56*0Sstevel@tonic-gate be sure _G_config.h will be included before this file. _G_config.h 57*0Sstevel@tonic-gate also defines _G_HAVE_BOOL for both gcc and g++, but only g++ 58*0Sstevel@tonic-gate actually has bool. Hence, _G_HAVE_BOOL is pretty useless for us. 59*0Sstevel@tonic-gate g++ can be identified by __GNUG__. 60*0Sstevel@tonic-gate Andy Dougherty February 2000 61*0Sstevel@tonic-gate */ 62*0Sstevel@tonic-gate #ifdef __GNUG__ /* GNU g++ has bool built-in */ 63*0Sstevel@tonic-gate # ifndef HAS_BOOL 64*0Sstevel@tonic-gate # define HAS_BOOL 1 65*0Sstevel@tonic-gate # endif 66*0Sstevel@tonic-gate #endif 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate /* The NeXT dynamic loader headers will not build with the bool macro 69*0Sstevel@tonic-gate So declare them now to clear confusion. 70*0Sstevel@tonic-gate */ 71*0Sstevel@tonic-gate #if defined(NeXT) || defined(__NeXT__) 72*0Sstevel@tonic-gate # undef FALSE 73*0Sstevel@tonic-gate # undef TRUE 74*0Sstevel@tonic-gate typedef enum bool { FALSE = 0, TRUE = 1 } bool; 75*0Sstevel@tonic-gate # define ENUM_BOOL 1 76*0Sstevel@tonic-gate # ifndef HAS_BOOL 77*0Sstevel@tonic-gate # define HAS_BOOL 1 78*0Sstevel@tonic-gate # endif /* !HAS_BOOL */ 79*0Sstevel@tonic-gate #endif /* NeXT || __NeXT__ */ 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate #ifndef HAS_BOOL 82*0Sstevel@tonic-gate # if defined(UTS) || defined(VMS) 83*0Sstevel@tonic-gate # define bool int 84*0Sstevel@tonic-gate # else 85*0Sstevel@tonic-gate # define bool char 86*0Sstevel@tonic-gate # endif 87*0Sstevel@tonic-gate # define HAS_BOOL 1 88*0Sstevel@tonic-gate #endif 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate /* XXX A note on the perl source internal type system. The 91*0Sstevel@tonic-gate original intent was that I32 be *exactly* 32 bits. 92*0Sstevel@tonic-gate 93*0Sstevel@tonic-gate Currently, we only guarantee that I32 is *at least* 32 bits. 94*0Sstevel@tonic-gate Specifically, if int is 64 bits, then so is I32. (This is the case 95*0Sstevel@tonic-gate for the Cray.) This has the advantage of meshing nicely with 96*0Sstevel@tonic-gate standard library calls (where we pass an I32 and the library is 97*0Sstevel@tonic-gate expecting an int), but the disadvantage that an I32 is not 32 bits. 98*0Sstevel@tonic-gate Andy Dougherty August 1996 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate There is no guarantee that there is *any* integral type with 101*0Sstevel@tonic-gate exactly 32 bits. It is perfectly legal for a system to have 102*0Sstevel@tonic-gate sizeof(short) == sizeof(int) == sizeof(long) == 8. 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate Similarly, there is no guarantee that I16 and U16 have exactly 16 105*0Sstevel@tonic-gate bits. 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate For dealing with issues that may arise from various 32/64-bit 108*0Sstevel@tonic-gate systems, we will ask Configure to check out 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gate SHORTSIZE == sizeof(short) 111*0Sstevel@tonic-gate INTSIZE == sizeof(int) 112*0Sstevel@tonic-gate LONGSIZE == sizeof(long) 113*0Sstevel@tonic-gate LONGLONGSIZE == sizeof(long long) (if HAS_LONG_LONG) 114*0Sstevel@tonic-gate PTRSIZE == sizeof(void *) 115*0Sstevel@tonic-gate DOUBLESIZE == sizeof(double) 116*0Sstevel@tonic-gate LONG_DOUBLESIZE == sizeof(long double) (if HAS_LONG_DOUBLE). 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate */ 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate #ifdef I_INTTYPES /* e.g. Linux has int64_t without <inttypes.h> */ 121*0Sstevel@tonic-gate # include <inttypes.h> 122*0Sstevel@tonic-gate # ifdef INT32_MIN_BROKEN 123*0Sstevel@tonic-gate # undef INT32_MIN 124*0Sstevel@tonic-gate # define INT32_MIN (-2147483647-1) 125*0Sstevel@tonic-gate # endif 126*0Sstevel@tonic-gate # ifdef INT64_MIN_BROKEN 127*0Sstevel@tonic-gate # undef INT64_MIN 128*0Sstevel@tonic-gate # define INT64_MIN (-9223372036854775807LL-1) 129*0Sstevel@tonic-gate # endif 130*0Sstevel@tonic-gate #endif 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate typedef I8TYPE I8; 133*0Sstevel@tonic-gate typedef U8TYPE U8; 134*0Sstevel@tonic-gate typedef I16TYPE I16; 135*0Sstevel@tonic-gate typedef U16TYPE U16; 136*0Sstevel@tonic-gate typedef I32TYPE I32; 137*0Sstevel@tonic-gate typedef U32TYPE U32; 138*0Sstevel@tonic-gate #ifdef PERL_CORE 139*0Sstevel@tonic-gate # ifdef HAS_QUAD 140*0Sstevel@tonic-gate typedef I64TYPE I64; 141*0Sstevel@tonic-gate typedef U64TYPE U64; 142*0Sstevel@tonic-gate # endif 143*0Sstevel@tonic-gate #endif /* PERL_CORE */ 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate #if defined(HAS_QUAD) && defined(USE_64_BIT_INT) 146*0Sstevel@tonic-gate # ifndef UINT64_C /* usually from <inttypes.h> */ 147*0Sstevel@tonic-gate # if defined(HAS_LONG_LONG) && QUADKIND == QUAD_IS_LONG_LONG 148*0Sstevel@tonic-gate # define INT64_C(c) CAT2(c,LL) 149*0Sstevel@tonic-gate # define UINT64_C(c) CAT2(c,ULL) 150*0Sstevel@tonic-gate # else 151*0Sstevel@tonic-gate # if LONGSIZE == 8 && QUADKIND == QUAD_IS_LONG 152*0Sstevel@tonic-gate # define INT64_C(c) CAT2(c,L) 153*0Sstevel@tonic-gate # define UINT64_C(c) CAT2(c,UL) 154*0Sstevel@tonic-gate # else 155*0Sstevel@tonic-gate # define INT64_C(c) ((I64TYPE)(c)) 156*0Sstevel@tonic-gate # define UINT64_C(c) ((U64TYPE)(c)) 157*0Sstevel@tonic-gate # endif 158*0Sstevel@tonic-gate # endif 159*0Sstevel@tonic-gate # endif 160*0Sstevel@tonic-gate #endif 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate /* Mention I8SIZE, U8SIZE, I16SIZE, U16SIZE, I32SIZE, U32SIZE, 163*0Sstevel@tonic-gate I64SIZE, and U64SIZE here so that metaconfig pulls them in. */ 164*0Sstevel@tonic-gate 165*0Sstevel@tonic-gate #if defined(UINT8_MAX) && defined(INT16_MAX) && defined(INT32_MAX) 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate /* I8_MAX and I8_MIN constants are not defined, as I8 is an ambiguous type. 168*0Sstevel@tonic-gate Please search CHAR_MAX in perl.h for further details. */ 169*0Sstevel@tonic-gate #define U8_MAX UINT8_MAX 170*0Sstevel@tonic-gate #define U8_MIN UINT8_MIN 171*0Sstevel@tonic-gate 172*0Sstevel@tonic-gate #define I16_MAX INT16_MAX 173*0Sstevel@tonic-gate #define I16_MIN INT16_MIN 174*0Sstevel@tonic-gate #define U16_MAX UINT16_MAX 175*0Sstevel@tonic-gate #define U16_MIN UINT16_MIN 176*0Sstevel@tonic-gate 177*0Sstevel@tonic-gate #define I32_MAX INT32_MAX 178*0Sstevel@tonic-gate #define I32_MIN INT32_MIN 179*0Sstevel@tonic-gate #ifndef UINT32_MAX_BROKEN /* e.g. HP-UX with gcc messes this up */ 180*0Sstevel@tonic-gate # define U32_MAX UINT32_MAX 181*0Sstevel@tonic-gate #else 182*0Sstevel@tonic-gate # define U32_MAX 4294967295U 183*0Sstevel@tonic-gate #endif 184*0Sstevel@tonic-gate #define U32_MIN UINT32_MIN 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate #else 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate /* I8_MAX and I8_MIN constants are not defined, as I8 is an ambiguous type. 189*0Sstevel@tonic-gate Please search CHAR_MAX in perl.h for further details. */ 190*0Sstevel@tonic-gate #define U8_MAX PERL_UCHAR_MAX 191*0Sstevel@tonic-gate #define U8_MIN PERL_UCHAR_MIN 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate #define I16_MAX PERL_SHORT_MAX 194*0Sstevel@tonic-gate #define I16_MIN PERL_SHORT_MIN 195*0Sstevel@tonic-gate #define U16_MAX PERL_USHORT_MAX 196*0Sstevel@tonic-gate #define U16_MIN PERL_USHORT_MIN 197*0Sstevel@tonic-gate 198*0Sstevel@tonic-gate #if LONGSIZE > 4 199*0Sstevel@tonic-gate # define I32_MAX PERL_INT_MAX 200*0Sstevel@tonic-gate # define I32_MIN PERL_INT_MIN 201*0Sstevel@tonic-gate # define U32_MAX PERL_UINT_MAX 202*0Sstevel@tonic-gate # define U32_MIN PERL_UINT_MIN 203*0Sstevel@tonic-gate #else 204*0Sstevel@tonic-gate # define I32_MAX PERL_LONG_MAX 205*0Sstevel@tonic-gate # define I32_MIN PERL_LONG_MIN 206*0Sstevel@tonic-gate # define U32_MAX PERL_ULONG_MAX 207*0Sstevel@tonic-gate # define U32_MIN PERL_ULONG_MIN 208*0Sstevel@tonic-gate #endif 209*0Sstevel@tonic-gate 210*0Sstevel@tonic-gate #endif 211*0Sstevel@tonic-gate 212*0Sstevel@tonic-gate /* log(2) is pretty close to 0.30103, just in case anyone is grepping for it */ 213*0Sstevel@tonic-gate #define BIT_DIGITS(N) (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */ 214*0Sstevel@tonic-gate #define TYPE_DIGITS(T) BIT_DIGITS(sizeof(T) * 8) 215*0Sstevel@tonic-gate #define TYPE_CHARS(T) (TYPE_DIGITS(T) + 2) /* sign, NUL */ 216*0Sstevel@tonic-gate 217*0Sstevel@tonic-gate #define Ctl(ch) ((ch) & 037) 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate /* 220*0Sstevel@tonic-gate =head1 Miscellaneous Functions 221*0Sstevel@tonic-gate 222*0Sstevel@tonic-gate =for apidoc Am|bool|strNE|char* s1|char* s2 223*0Sstevel@tonic-gate Test two strings to see if they are different. Returns true or 224*0Sstevel@tonic-gate false. 225*0Sstevel@tonic-gate 226*0Sstevel@tonic-gate =for apidoc Am|bool|strEQ|char* s1|char* s2 227*0Sstevel@tonic-gate Test two strings to see if they are equal. Returns true or false. 228*0Sstevel@tonic-gate 229*0Sstevel@tonic-gate =for apidoc Am|bool|strLT|char* s1|char* s2 230*0Sstevel@tonic-gate Test two strings to see if the first, C<s1>, is less than the second, 231*0Sstevel@tonic-gate C<s2>. Returns true or false. 232*0Sstevel@tonic-gate 233*0Sstevel@tonic-gate =for apidoc Am|bool|strLE|char* s1|char* s2 234*0Sstevel@tonic-gate Test two strings to see if the first, C<s1>, is less than or equal to the 235*0Sstevel@tonic-gate second, C<s2>. Returns true or false. 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate =for apidoc Am|bool|strGT|char* s1|char* s2 238*0Sstevel@tonic-gate Test two strings to see if the first, C<s1>, is greater than the second, 239*0Sstevel@tonic-gate C<s2>. Returns true or false. 240*0Sstevel@tonic-gate 241*0Sstevel@tonic-gate =for apidoc Am|bool|strGE|char* s1|char* s2 242*0Sstevel@tonic-gate Test two strings to see if the first, C<s1>, is greater than or equal to 243*0Sstevel@tonic-gate the second, C<s2>. Returns true or false. 244*0Sstevel@tonic-gate 245*0Sstevel@tonic-gate =for apidoc Am|bool|strnNE|char* s1|char* s2|STRLEN len 246*0Sstevel@tonic-gate Test two strings to see if they are different. The C<len> parameter 247*0Sstevel@tonic-gate indicates the number of bytes to compare. Returns true or false. (A 248*0Sstevel@tonic-gate wrapper for C<strncmp>). 249*0Sstevel@tonic-gate 250*0Sstevel@tonic-gate =for apidoc Am|bool|strnEQ|char* s1|char* s2|STRLEN len 251*0Sstevel@tonic-gate Test two strings to see if they are equal. The C<len> parameter indicates 252*0Sstevel@tonic-gate the number of bytes to compare. Returns true or false. (A wrapper for 253*0Sstevel@tonic-gate C<strncmp>). 254*0Sstevel@tonic-gate 255*0Sstevel@tonic-gate =cut 256*0Sstevel@tonic-gate */ 257*0Sstevel@tonic-gate 258*0Sstevel@tonic-gate #define strNE(s1,s2) (strcmp(s1,s2)) 259*0Sstevel@tonic-gate #define strEQ(s1,s2) (!strcmp(s1,s2)) 260*0Sstevel@tonic-gate #define strLT(s1,s2) (strcmp(s1,s2) < 0) 261*0Sstevel@tonic-gate #define strLE(s1,s2) (strcmp(s1,s2) <= 0) 262*0Sstevel@tonic-gate #define strGT(s1,s2) (strcmp(s1,s2) > 0) 263*0Sstevel@tonic-gate #define strGE(s1,s2) (strcmp(s1,s2) >= 0) 264*0Sstevel@tonic-gate #define strnNE(s1,s2,l) (strncmp(s1,s2,l)) 265*0Sstevel@tonic-gate #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l)) 266*0Sstevel@tonic-gate 267*0Sstevel@tonic-gate #ifdef HAS_MEMCMP 268*0Sstevel@tonic-gate # define memNE(s1,s2,l) (memcmp(s1,s2,l)) 269*0Sstevel@tonic-gate # define memEQ(s1,s2,l) (!memcmp(s1,s2,l)) 270*0Sstevel@tonic-gate #else 271*0Sstevel@tonic-gate # define memNE(s1,s2,l) (bcmp(s1,s2,l)) 272*0Sstevel@tonic-gate # define memEQ(s1,s2,l) (!bcmp(s1,s2,l)) 273*0Sstevel@tonic-gate #endif 274*0Sstevel@tonic-gate 275*0Sstevel@tonic-gate /* 276*0Sstevel@tonic-gate * Character classes. 277*0Sstevel@tonic-gate * 278*0Sstevel@tonic-gate * Unfortunately, the introduction of locales means that we 279*0Sstevel@tonic-gate * can't trust isupper(), etc. to tell the truth. And when 280*0Sstevel@tonic-gate * it comes to /\w+/ with tainting enabled, we *must* be able 281*0Sstevel@tonic-gate * to trust our character classes. 282*0Sstevel@tonic-gate * 283*0Sstevel@tonic-gate * Therefore, the default tests in the text of Perl will be 284*0Sstevel@tonic-gate * independent of locale. Any code that wants to depend on 285*0Sstevel@tonic-gate * the current locale will use the tests that begin with "lc". 286*0Sstevel@tonic-gate */ 287*0Sstevel@tonic-gate 288*0Sstevel@tonic-gate #ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */ 289*0Sstevel@tonic-gate # ifndef CTYPE256 290*0Sstevel@tonic-gate # define CTYPE256 291*0Sstevel@tonic-gate # endif 292*0Sstevel@tonic-gate #endif 293*0Sstevel@tonic-gate 294*0Sstevel@tonic-gate /* 295*0Sstevel@tonic-gate 296*0Sstevel@tonic-gate =head1 Character classes 297*0Sstevel@tonic-gate 298*0Sstevel@tonic-gate =for apidoc Am|bool|isALNUM|char ch 299*0Sstevel@tonic-gate Returns a boolean indicating whether the C C<char> is an ASCII alphanumeric 300*0Sstevel@tonic-gate character (including underscore) or digit. 301*0Sstevel@tonic-gate 302*0Sstevel@tonic-gate =for apidoc Am|bool|isALPHA|char ch 303*0Sstevel@tonic-gate Returns a boolean indicating whether the C C<char> is an ASCII alphabetic 304*0Sstevel@tonic-gate character. 305*0Sstevel@tonic-gate 306*0Sstevel@tonic-gate =for apidoc Am|bool|isSPACE|char ch 307*0Sstevel@tonic-gate Returns a boolean indicating whether the C C<char> is whitespace. 308*0Sstevel@tonic-gate 309*0Sstevel@tonic-gate =for apidoc Am|bool|isDIGIT|char ch 310*0Sstevel@tonic-gate Returns a boolean indicating whether the C C<char> is an ASCII 311*0Sstevel@tonic-gate digit. 312*0Sstevel@tonic-gate 313*0Sstevel@tonic-gate =for apidoc Am|bool|isUPPER|char ch 314*0Sstevel@tonic-gate Returns a boolean indicating whether the C C<char> is an uppercase 315*0Sstevel@tonic-gate character. 316*0Sstevel@tonic-gate 317*0Sstevel@tonic-gate =for apidoc Am|bool|isLOWER|char ch 318*0Sstevel@tonic-gate Returns a boolean indicating whether the C C<char> is a lowercase 319*0Sstevel@tonic-gate character. 320*0Sstevel@tonic-gate 321*0Sstevel@tonic-gate =for apidoc Am|char|toUPPER|char ch 322*0Sstevel@tonic-gate Converts the specified character to uppercase. 323*0Sstevel@tonic-gate 324*0Sstevel@tonic-gate =for apidoc Am|char|toLOWER|char ch 325*0Sstevel@tonic-gate Converts the specified character to lowercase. 326*0Sstevel@tonic-gate 327*0Sstevel@tonic-gate =cut 328*0Sstevel@tonic-gate */ 329*0Sstevel@tonic-gate 330*0Sstevel@tonic-gate #define isALNUM(c) (isALPHA(c) || isDIGIT(c) || (c) == '_') 331*0Sstevel@tonic-gate #define isIDFIRST(c) (isALPHA(c) || (c) == '_') 332*0Sstevel@tonic-gate #define isALPHA(c) (isUPPER(c) || isLOWER(c)) 333*0Sstevel@tonic-gate #define isSPACE(c) \ 334*0Sstevel@tonic-gate ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) =='\r' || (c) == '\f') 335*0Sstevel@tonic-gate #define isPSXSPC(c) (isSPACE(c) || (c) == '\v') 336*0Sstevel@tonic-gate #define isBLANK(c) ((c) == ' ' || (c) == '\t') 337*0Sstevel@tonic-gate #define isDIGIT(c) ((c) >= '0' && (c) <= '9') 338*0Sstevel@tonic-gate #ifdef EBCDIC 339*0Sstevel@tonic-gate /* In EBCDIC we do not do locales: therefore() isupper() is fine. */ 340*0Sstevel@tonic-gate # define isUPPER(c) isupper(c) 341*0Sstevel@tonic-gate # define isLOWER(c) islower(c) 342*0Sstevel@tonic-gate # define isALNUMC(c) isalnum(c) 343*0Sstevel@tonic-gate # define isASCII(c) isascii(c) 344*0Sstevel@tonic-gate # define isCNTRL(c) iscntrl(c) 345*0Sstevel@tonic-gate # define isGRAPH(c) isgraph(c) 346*0Sstevel@tonic-gate # define isPRINT(c) isprint(c) 347*0Sstevel@tonic-gate # define isPUNCT(c) ispunct(c) 348*0Sstevel@tonic-gate # define isXDIGIT(c) isxdigit(c) 349*0Sstevel@tonic-gate # define toUPPER(c) toupper(c) 350*0Sstevel@tonic-gate # define toLOWER(c) tolower(c) 351*0Sstevel@tonic-gate #else 352*0Sstevel@tonic-gate # define isUPPER(c) ((c) >= 'A' && (c) <= 'Z') 353*0Sstevel@tonic-gate # define isLOWER(c) ((c) >= 'a' && (c) <= 'z') 354*0Sstevel@tonic-gate # define isALNUMC(c) (isALPHA(c) || isDIGIT(c)) 355*0Sstevel@tonic-gate # define isASCII(c) ((c) <= 127) 356*0Sstevel@tonic-gate # define isCNTRL(c) ((c) < ' ' || (c) == 127) 357*0Sstevel@tonic-gate # define isGRAPH(c) (isALNUM(c) || isPUNCT(c)) 358*0Sstevel@tonic-gate # define isPRINT(c) (((c) > 32 && (c) < 127) || (c) == ' ') 359*0Sstevel@tonic-gate # define isPUNCT(c) (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64) || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126)) 360*0Sstevel@tonic-gate # define isXDIGIT(c) (isDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) 361*0Sstevel@tonic-gate # define toUPPER(c) (isLOWER(c) ? (c) - ('a' - 'A') : (c)) 362*0Sstevel@tonic-gate # define toLOWER(c) (isUPPER(c) ? (c) + ('a' - 'A') : (c)) 363*0Sstevel@tonic-gate #endif 364*0Sstevel@tonic-gate 365*0Sstevel@tonic-gate #ifdef USE_NEXT_CTYPE 366*0Sstevel@tonic-gate 367*0Sstevel@tonic-gate # define isALNUM_LC(c) \ 368*0Sstevel@tonic-gate (NXIsAlNum((unsigned int)(c)) || (char)(c) == '_') 369*0Sstevel@tonic-gate # define isIDFIRST_LC(c) \ 370*0Sstevel@tonic-gate (NXIsAlpha((unsigned int)(c)) || (char)(c) == '_') 371*0Sstevel@tonic-gate # define isALPHA_LC(c) NXIsAlpha((unsigned int)(c)) 372*0Sstevel@tonic-gate # define isSPACE_LC(c) NXIsSpace((unsigned int)(c)) 373*0Sstevel@tonic-gate # define isDIGIT_LC(c) NXIsDigit((unsigned int)(c)) 374*0Sstevel@tonic-gate # define isUPPER_LC(c) NXIsUpper((unsigned int)(c)) 375*0Sstevel@tonic-gate # define isLOWER_LC(c) NXIsLower((unsigned int)(c)) 376*0Sstevel@tonic-gate # define isALNUMC_LC(c) NXIsAlNum((unsigned int)(c)) 377*0Sstevel@tonic-gate # define isCNTRL_LC(c) NXIsCntrl((unsigned int)(c)) 378*0Sstevel@tonic-gate # define isGRAPH_LC(c) NXIsGraph((unsigned int)(c)) 379*0Sstevel@tonic-gate # define isPRINT_LC(c) NXIsPrint((unsigned int)(c)) 380*0Sstevel@tonic-gate # define isPUNCT_LC(c) NXIsPunct((unsigned int)(c)) 381*0Sstevel@tonic-gate # define toUPPER_LC(c) NXToUpper((unsigned int)(c)) 382*0Sstevel@tonic-gate # define toLOWER_LC(c) NXToLower((unsigned int)(c)) 383*0Sstevel@tonic-gate 384*0Sstevel@tonic-gate #else /* !USE_NEXT_CTYPE */ 385*0Sstevel@tonic-gate 386*0Sstevel@tonic-gate # if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII)) 387*0Sstevel@tonic-gate 388*0Sstevel@tonic-gate # define isALNUM_LC(c) (isalnum((unsigned char)(c)) || (char)(c) == '_') 389*0Sstevel@tonic-gate # define isIDFIRST_LC(c) (isalpha((unsigned char)(c)) || (char)(c) == '_') 390*0Sstevel@tonic-gate # define isALPHA_LC(c) isalpha((unsigned char)(c)) 391*0Sstevel@tonic-gate # define isSPACE_LC(c) isspace((unsigned char)(c)) 392*0Sstevel@tonic-gate # define isDIGIT_LC(c) isdigit((unsigned char)(c)) 393*0Sstevel@tonic-gate # define isUPPER_LC(c) isupper((unsigned char)(c)) 394*0Sstevel@tonic-gate # define isLOWER_LC(c) islower((unsigned char)(c)) 395*0Sstevel@tonic-gate # define isALNUMC_LC(c) isalnum((unsigned char)(c)) 396*0Sstevel@tonic-gate # define isCNTRL_LC(c) iscntrl((unsigned char)(c)) 397*0Sstevel@tonic-gate # define isGRAPH_LC(c) isgraph((unsigned char)(c)) 398*0Sstevel@tonic-gate # define isPRINT_LC(c) isprint((unsigned char)(c)) 399*0Sstevel@tonic-gate # define isPUNCT_LC(c) ispunct((unsigned char)(c)) 400*0Sstevel@tonic-gate # define toUPPER_LC(c) toupper((unsigned char)(c)) 401*0Sstevel@tonic-gate # define toLOWER_LC(c) tolower((unsigned char)(c)) 402*0Sstevel@tonic-gate 403*0Sstevel@tonic-gate # else 404*0Sstevel@tonic-gate 405*0Sstevel@tonic-gate # define isALNUM_LC(c) (isascii(c) && (isalnum(c) || (c) == '_')) 406*0Sstevel@tonic-gate # define isIDFIRST_LC(c) (isascii(c) && (isalpha(c) || (c) == '_')) 407*0Sstevel@tonic-gate # define isALPHA_LC(c) (isascii(c) && isalpha(c)) 408*0Sstevel@tonic-gate # define isSPACE_LC(c) (isascii(c) && isspace(c)) 409*0Sstevel@tonic-gate # define isDIGIT_LC(c) (isascii(c) && isdigit(c)) 410*0Sstevel@tonic-gate # define isUPPER_LC(c) (isascii(c) && isupper(c)) 411*0Sstevel@tonic-gate # define isLOWER_LC(c) (isascii(c) && islower(c)) 412*0Sstevel@tonic-gate # define isALNUMC_LC(c) (isascii(c) && isalnum(c)) 413*0Sstevel@tonic-gate # define isCNTRL_LC(c) (isascii(c) && iscntrl(c)) 414*0Sstevel@tonic-gate # define isGRAPH_LC(c) (isascii(c) && isgraph(c)) 415*0Sstevel@tonic-gate # define isPRINT_LC(c) (isascii(c) && isprint(c)) 416*0Sstevel@tonic-gate # define isPUNCT_LC(c) (isascii(c) && ispunct(c)) 417*0Sstevel@tonic-gate # define toUPPER_LC(c) toupper(c) 418*0Sstevel@tonic-gate # define toLOWER_LC(c) tolower(c) 419*0Sstevel@tonic-gate 420*0Sstevel@tonic-gate # endif 421*0Sstevel@tonic-gate #endif /* USE_NEXT_CTYPE */ 422*0Sstevel@tonic-gate 423*0Sstevel@tonic-gate #define isPSXSPC_LC(c) (isSPACE_LC(c) || (c) == '\v') 424*0Sstevel@tonic-gate #define isBLANK_LC(c) isBLANK(c) /* could be wrong */ 425*0Sstevel@tonic-gate 426*0Sstevel@tonic-gate #define isALNUM_uni(c) is_uni_alnum(c) 427*0Sstevel@tonic-gate #define isIDFIRST_uni(c) is_uni_idfirst(c) 428*0Sstevel@tonic-gate #define isALPHA_uni(c) is_uni_alpha(c) 429*0Sstevel@tonic-gate #define isSPACE_uni(c) is_uni_space(c) 430*0Sstevel@tonic-gate #define isDIGIT_uni(c) is_uni_digit(c) 431*0Sstevel@tonic-gate #define isUPPER_uni(c) is_uni_upper(c) 432*0Sstevel@tonic-gate #define isLOWER_uni(c) is_uni_lower(c) 433*0Sstevel@tonic-gate #define isALNUMC_uni(c) is_uni_alnumc(c) 434*0Sstevel@tonic-gate #define isASCII_uni(c) is_uni_ascii(c) 435*0Sstevel@tonic-gate #define isCNTRL_uni(c) is_uni_cntrl(c) 436*0Sstevel@tonic-gate #define isGRAPH_uni(c) is_uni_graph(c) 437*0Sstevel@tonic-gate #define isPRINT_uni(c) is_uni_print(c) 438*0Sstevel@tonic-gate #define isPUNCT_uni(c) is_uni_punct(c) 439*0Sstevel@tonic-gate #define isXDIGIT_uni(c) is_uni_xdigit(c) 440*0Sstevel@tonic-gate #define toUPPER_uni(c,s,l) to_uni_upper(c,s,l) 441*0Sstevel@tonic-gate #define toTITLE_uni(c,s,l) to_uni_title(c,s,l) 442*0Sstevel@tonic-gate #define toLOWER_uni(c,s,l) to_uni_lower(c,s,l) 443*0Sstevel@tonic-gate #define toFOLD_uni(c,s,l) to_uni_fold(c,s,l) 444*0Sstevel@tonic-gate 445*0Sstevel@tonic-gate #define isPSXSPC_uni(c) (isSPACE_uni(c) ||(c) == '\f') 446*0Sstevel@tonic-gate #define isBLANK_uni(c) isBLANK(c) /* could be wrong */ 447*0Sstevel@tonic-gate 448*0Sstevel@tonic-gate #define isALNUM_LC_uvchr(c) (c < 256 ? isALNUM_LC(c) : is_uni_alnum_lc(c)) 449*0Sstevel@tonic-gate #define isIDFIRST_LC_uvchr(c) (c < 256 ? isIDFIRST_LC(c) : is_uni_idfirst_lc(c)) 450*0Sstevel@tonic-gate #define isALPHA_LC_uvchr(c) (c < 256 ? isALPHA_LC(c) : is_uni_alpha_lc(c)) 451*0Sstevel@tonic-gate #define isSPACE_LC_uvchr(c) (c < 256 ? isSPACE_LC(c) : is_uni_space_lc(c)) 452*0Sstevel@tonic-gate #define isDIGIT_LC_uvchr(c) (c < 256 ? isDIGIT_LC(c) : is_uni_digit_lc(c)) 453*0Sstevel@tonic-gate #define isUPPER_LC_uvchr(c) (c < 256 ? isUPPER_LC(c) : is_uni_upper_lc(c)) 454*0Sstevel@tonic-gate #define isLOWER_LC_uvchr(c) (c < 256 ? isLOWER_LC(c) : is_uni_lower_lc(c)) 455*0Sstevel@tonic-gate #define isALNUMC_LC_uvchr(c) (c < 256 ? isALNUMC_LC(c) : is_uni_alnumc_lc(c)) 456*0Sstevel@tonic-gate #define isCNTRL_LC_uvchr(c) (c < 256 ? isCNTRL_LC(c) : is_uni_cntrl_lc(c)) 457*0Sstevel@tonic-gate #define isGRAPH_LC_uvchr(c) (c < 256 ? isGRAPH_LC(c) : is_uni_graph_lc(c)) 458*0Sstevel@tonic-gate #define isPRINT_LC_uvchr(c) (c < 256 ? isPRINT_LC(c) : is_uni_print_lc(c)) 459*0Sstevel@tonic-gate #define isPUNCT_LC_uvchr(c) (c < 256 ? isPUNCT_LC(c) : is_uni_punct_lc(c)) 460*0Sstevel@tonic-gate 461*0Sstevel@tonic-gate #define isPSXSPC_LC_uni(c) (isSPACE_LC_uni(c) ||(c) == '\f') 462*0Sstevel@tonic-gate #define isBLANK_LC_uni(c) isBLANK(c) /* could be wrong */ 463*0Sstevel@tonic-gate 464*0Sstevel@tonic-gate #define isALNUM_utf8(p) is_utf8_alnum(p) 465*0Sstevel@tonic-gate /* The ID_Start of Unicode is quite limiting: it assumes a L-class 466*0Sstevel@tonic-gate * character (meaning that you cannot have, say, a CJK character). 467*0Sstevel@tonic-gate * Instead, let's allow ID_Continue but not digits. */ 468*0Sstevel@tonic-gate #define isIDFIRST_utf8(p) (is_utf8_idcont(p) && !is_utf8_digit(p)) 469*0Sstevel@tonic-gate #define isALPHA_utf8(p) is_utf8_alpha(p) 470*0Sstevel@tonic-gate #define isSPACE_utf8(p) is_utf8_space(p) 471*0Sstevel@tonic-gate #define isDIGIT_utf8(p) is_utf8_digit(p) 472*0Sstevel@tonic-gate #define isUPPER_utf8(p) is_utf8_upper(p) 473*0Sstevel@tonic-gate #define isLOWER_utf8(p) is_utf8_lower(p) 474*0Sstevel@tonic-gate #define isALNUMC_utf8(p) is_utf8_alnumc(p) 475*0Sstevel@tonic-gate #define isASCII_utf8(p) is_utf8_ascii(p) 476*0Sstevel@tonic-gate #define isCNTRL_utf8(p) is_utf8_cntrl(p) 477*0Sstevel@tonic-gate #define isGRAPH_utf8(p) is_utf8_graph(p) 478*0Sstevel@tonic-gate #define isPRINT_utf8(p) is_utf8_print(p) 479*0Sstevel@tonic-gate #define isPUNCT_utf8(p) is_utf8_punct(p) 480*0Sstevel@tonic-gate #define isXDIGIT_utf8(p) is_utf8_xdigit(p) 481*0Sstevel@tonic-gate #define toUPPER_utf8(p,s,l) to_utf8_upper(p,s,l) 482*0Sstevel@tonic-gate #define toTITLE_utf8(p,s,l) to_utf8_title(p,s,l) 483*0Sstevel@tonic-gate #define toLOWER_utf8(p,s,l) to_utf8_lower(p,s,l) 484*0Sstevel@tonic-gate 485*0Sstevel@tonic-gate #define isPSXSPC_utf8(c) (isSPACE_utf8(c) ||(c) == '\f') 486*0Sstevel@tonic-gate #define isBLANK_utf8(c) isBLANK(c) /* could be wrong */ 487*0Sstevel@tonic-gate 488*0Sstevel@tonic-gate #define isALNUM_LC_utf8(p) isALNUM_LC_uvchr(utf8_to_uvchr(p, 0)) 489*0Sstevel@tonic-gate #define isIDFIRST_LC_utf8(p) isIDFIRST_LC_uvchr(utf8_to_uvchr(p, 0)) 490*0Sstevel@tonic-gate #define isALPHA_LC_utf8(p) isALPHA_LC_uvchr(utf8_to_uvchr(p, 0)) 491*0Sstevel@tonic-gate #define isSPACE_LC_utf8(p) isSPACE_LC_uvchr(utf8_to_uvchr(p, 0)) 492*0Sstevel@tonic-gate #define isDIGIT_LC_utf8(p) isDIGIT_LC_uvchr(utf8_to_uvchr(p, 0)) 493*0Sstevel@tonic-gate #define isUPPER_LC_utf8(p) isUPPER_LC_uvchr(utf8_to_uvchr(p, 0)) 494*0Sstevel@tonic-gate #define isLOWER_LC_utf8(p) isLOWER_LC_uvchr(utf8_to_uvchr(p, 0)) 495*0Sstevel@tonic-gate #define isALNUMC_LC_utf8(p) isALNUMC_LC_uvchr(utf8_to_uvchr(p, 0)) 496*0Sstevel@tonic-gate #define isCNTRL_LC_utf8(p) isCNTRL_LC_uvchr(utf8_to_uvchr(p, 0)) 497*0Sstevel@tonic-gate #define isGRAPH_LC_utf8(p) isGRAPH_LC_uvchr(utf8_to_uvchr(p, 0)) 498*0Sstevel@tonic-gate #define isPRINT_LC_utf8(p) isPRINT_LC_uvchr(utf8_to_uvchr(p, 0)) 499*0Sstevel@tonic-gate #define isPUNCT_LC_utf8(p) isPUNCT_LC_uvchr(utf8_to_uvchr(p, 0)) 500*0Sstevel@tonic-gate 501*0Sstevel@tonic-gate #define isPSXSPC_LC_utf8(c) (isSPACE_LC_utf8(c) ||(c) == '\f') 502*0Sstevel@tonic-gate #define isBLANK_LC_utf8(c) isBLANK(c) /* could be wrong */ 503*0Sstevel@tonic-gate 504*0Sstevel@tonic-gate #ifdef EBCDIC 505*0Sstevel@tonic-gate # ifdef PERL_IMPLICIT_CONTEXT 506*0Sstevel@tonic-gate # define toCTRL(c) Perl_ebcdic_control(aTHX_ c) 507*0Sstevel@tonic-gate # else 508*0Sstevel@tonic-gate # define toCTRL Perl_ebcdic_control 509*0Sstevel@tonic-gate # endif 510*0Sstevel@tonic-gate #else 511*0Sstevel@tonic-gate /* This conversion works both ways, strangely enough. */ 512*0Sstevel@tonic-gate # define toCTRL(c) (toUPPER(c) ^ 64) 513*0Sstevel@tonic-gate #endif 514*0Sstevel@tonic-gate 515*0Sstevel@tonic-gate /* Line numbers are unsigned, 32 bits. */ 516*0Sstevel@tonic-gate typedef U32 line_t; 517*0Sstevel@tonic-gate #ifdef lint 518*0Sstevel@tonic-gate #define NOLINE ((line_t)0) 519*0Sstevel@tonic-gate #else 520*0Sstevel@tonic-gate #define NOLINE ((line_t) 4294967295UL) 521*0Sstevel@tonic-gate #endif 522*0Sstevel@tonic-gate 523*0Sstevel@tonic-gate 524*0Sstevel@tonic-gate /* 525*0Sstevel@tonic-gate =head1 SV Manipulation Functions 526*0Sstevel@tonic-gate 527*0Sstevel@tonic-gate =for apidoc Am|SV*|NEWSV|int id|STRLEN len 528*0Sstevel@tonic-gate Creates a new SV. A non-zero C<len> parameter indicates the number of 529*0Sstevel@tonic-gate bytes of preallocated string space the SV should have. An extra byte for a 530*0Sstevel@tonic-gate tailing NUL is also reserved. (SvPOK is not set for the SV even if string 531*0Sstevel@tonic-gate space is allocated.) The reference count for the new SV is set to 1. 532*0Sstevel@tonic-gate C<id> is an integer id between 0 and 1299 (used to identify leaks). 533*0Sstevel@tonic-gate 534*0Sstevel@tonic-gate =head1 Memory Management 535*0Sstevel@tonic-gate 536*0Sstevel@tonic-gate =for apidoc Am|void|New|int id|void* ptr|int nitems|type 537*0Sstevel@tonic-gate The XSUB-writer's interface to the C C<malloc> function. 538*0Sstevel@tonic-gate 539*0Sstevel@tonic-gate =for apidoc Am|void|Newc|int id|void* ptr|int nitems|type|cast 540*0Sstevel@tonic-gate The XSUB-writer's interface to the C C<malloc> function, with 541*0Sstevel@tonic-gate cast. 542*0Sstevel@tonic-gate 543*0Sstevel@tonic-gate =for apidoc Am|void|Newz|int id|void* ptr|int nitems|type 544*0Sstevel@tonic-gate The XSUB-writer's interface to the C C<malloc> function. The allocated 545*0Sstevel@tonic-gate memory is zeroed with C<memzero>. 546*0Sstevel@tonic-gate 547*0Sstevel@tonic-gate =for apidoc Am|void|Renew|void* ptr|int nitems|type 548*0Sstevel@tonic-gate The XSUB-writer's interface to the C C<realloc> function. 549*0Sstevel@tonic-gate 550*0Sstevel@tonic-gate =for apidoc Am|void|Renewc|void* ptr|int nitems|type|cast 551*0Sstevel@tonic-gate The XSUB-writer's interface to the C C<realloc> function, with 552*0Sstevel@tonic-gate cast. 553*0Sstevel@tonic-gate 554*0Sstevel@tonic-gate =for apidoc Am|void|Safefree|void* ptr 555*0Sstevel@tonic-gate The XSUB-writer's interface to the C C<free> function. 556*0Sstevel@tonic-gate 557*0Sstevel@tonic-gate =for apidoc Am|void|Move|void* src|void* dest|int nitems|type 558*0Sstevel@tonic-gate The XSUB-writer's interface to the C C<memmove> function. The C<src> is the 559*0Sstevel@tonic-gate source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is 560*0Sstevel@tonic-gate the type. Can do overlapping moves. See also C<Copy>. 561*0Sstevel@tonic-gate 562*0Sstevel@tonic-gate =for apidoc Am|void|Copy|void* src|void* dest|int nitems|type 563*0Sstevel@tonic-gate The XSUB-writer's interface to the C C<memcpy> function. The C<src> is the 564*0Sstevel@tonic-gate source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is 565*0Sstevel@tonic-gate the type. May fail on overlapping copies. See also C<Move>. 566*0Sstevel@tonic-gate 567*0Sstevel@tonic-gate =for apidoc Am|void|Zero|void* dest|int nitems|type 568*0Sstevel@tonic-gate 569*0Sstevel@tonic-gate The XSUB-writer's interface to the C C<memzero> function. The C<dest> is the 570*0Sstevel@tonic-gate destination, C<nitems> is the number of items, and C<type> is the type. 571*0Sstevel@tonic-gate 572*0Sstevel@tonic-gate =for apidoc Am|void|StructCopy|type src|type dest|type 573*0Sstevel@tonic-gate This is an architecture-independent macro to copy one structure to another. 574*0Sstevel@tonic-gate 575*0Sstevel@tonic-gate =for apidoc Am|void|Poison|void* dest|int nitems|type 576*0Sstevel@tonic-gate 577*0Sstevel@tonic-gate Fill up memory with a pattern (byte 0xAB over and over again) that 578*0Sstevel@tonic-gate hopefully catches attempts to access uninitialized memory. 579*0Sstevel@tonic-gate 580*0Sstevel@tonic-gate =cut */ 581*0Sstevel@tonic-gate 582*0Sstevel@tonic-gate #ifndef lint 583*0Sstevel@tonic-gate 584*0Sstevel@tonic-gate #define NEWSV(x,len) newSV(len) 585*0Sstevel@tonic-gate 586*0Sstevel@tonic-gate #ifdef PERL_MALLOC_WRAP 587*0Sstevel@tonic-gate #define MEM_WRAP_CHECK(n,t) \ 588*0Sstevel@tonic-gate (void)((n)>((MEM_SIZE)~0)/sizeof(t)?(Perl_croak_nocontext(PL_memory_wrap),0):0) 589*0Sstevel@tonic-gate #define MEM_WRAP_CHECK_1(n,t,a) \ 590*0Sstevel@tonic-gate (void)((n)>((MEM_SIZE)~0)/sizeof(t)?(Perl_croak_nocontext(a),0):0) 591*0Sstevel@tonic-gate #define MEM_WRAP_CHECK_2(n,t,a,b) \ 592*0Sstevel@tonic-gate (void)((n)>((MEM_SIZE)~0)/sizeof(t)?(Perl_croak_nocontext(a,b),0):0) 593*0Sstevel@tonic-gate 594*0Sstevel@tonic-gate #define New(x,v,n,t) (v = (MEM_WRAP_CHECK(n,t), (t*)safemalloc((MEM_SIZE)((n)*sizeof(t))))) 595*0Sstevel@tonic-gate #define Newc(x,v,n,t,c) (v = (MEM_WRAP_CHECK(n,t), (c*)safemalloc((MEM_SIZE)((n)*sizeof(t))))) 596*0Sstevel@tonic-gate #define Newz(x,v,n,t) (v = (MEM_WRAP_CHECK(n,t), (t*)safemalloc((MEM_SIZE)((n)*sizeof(t))))), \ 597*0Sstevel@tonic-gate memzero((char*)(v), (n)*sizeof(t)) 598*0Sstevel@tonic-gate #define Renew(v,n,t) \ 599*0Sstevel@tonic-gate (v = (MEM_WRAP_CHECK(n,t), (t*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))) 600*0Sstevel@tonic-gate #define Renewc(v,n,t,c) \ 601*0Sstevel@tonic-gate (v = (MEM_WRAP_CHECK(n,t), (c*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))) 602*0Sstevel@tonic-gate #define Safefree(d) safefree((Malloc_t)(d)) 603*0Sstevel@tonic-gate 604*0Sstevel@tonic-gate #define Move(s,d,n,t) (MEM_WRAP_CHECK(n,t), (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))) 605*0Sstevel@tonic-gate #define Copy(s,d,n,t) (MEM_WRAP_CHECK(n,t), (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))) 606*0Sstevel@tonic-gate #define Zero(d,n,t) (MEM_WRAP_CHECK(n,t), (void)memzero((char*)(d), (n) * sizeof(t))) 607*0Sstevel@tonic-gate 608*0Sstevel@tonic-gate #define Poison(d,n,t) (MEM_WRAP_CHECK(n,t), (void)memset((char*)(d), 0xAB, (n) * sizeof(t))) 609*0Sstevel@tonic-gate 610*0Sstevel@tonic-gate #else 611*0Sstevel@tonic-gate 612*0Sstevel@tonic-gate #define MEM_WRAP_CHECK(n,t) 613*0Sstevel@tonic-gate #define MEM_WRAP_CHECK_1(n,t,a) 614*0Sstevel@tonic-gate #define MEM_WRAP_CHECK_2(n,t,a,b) 615*0Sstevel@tonic-gate 616*0Sstevel@tonic-gate #define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n)*sizeof(t)))) 617*0Sstevel@tonic-gate #define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n)*sizeof(t)))) 618*0Sstevel@tonic-gate #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n)*sizeof(t)))), \ 619*0Sstevel@tonic-gate memzero((char*)(v), (n)*sizeof(t)) 620*0Sstevel@tonic-gate #define Renew(v,n,t) \ 621*0Sstevel@tonic-gate (v = (t*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t)))) 622*0Sstevel@tonic-gate #define Renewc(v,n,t,c) \ 623*0Sstevel@tonic-gate (v = (c*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t)))) 624*0Sstevel@tonic-gate #define Safefree(d) safefree((Malloc_t)(d)) 625*0Sstevel@tonic-gate 626*0Sstevel@tonic-gate #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t)) 627*0Sstevel@tonic-gate #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t)) 628*0Sstevel@tonic-gate #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t)) 629*0Sstevel@tonic-gate 630*0Sstevel@tonic-gate #define Poison(d,n,t) (void)memset((char*)(d), 0xAB, (n) * sizeof(t)) 631*0Sstevel@tonic-gate 632*0Sstevel@tonic-gate #endif 633*0Sstevel@tonic-gate 634*0Sstevel@tonic-gate #else /* lint */ 635*0Sstevel@tonic-gate 636*0Sstevel@tonic-gate #define New(x,v,n,s) (v = Null(s *)) 637*0Sstevel@tonic-gate #define Newc(x,v,n,s,c) (v = Null(s *)) 638*0Sstevel@tonic-gate #define Newz(x,v,n,s) (v = Null(s *)) 639*0Sstevel@tonic-gate #define Renew(v,n,s) (v = Null(s *)) 640*0Sstevel@tonic-gate #define Move(s,d,n,t) 641*0Sstevel@tonic-gate #define Copy(s,d,n,t) 642*0Sstevel@tonic-gate #define Zero(d,n,t) 643*0Sstevel@tonic-gate #define Poison(d,n,t) 644*0Sstevel@tonic-gate #define Safefree(d) (d) = (d) 645*0Sstevel@tonic-gate 646*0Sstevel@tonic-gate #endif /* lint */ 647*0Sstevel@tonic-gate 648*0Sstevel@tonic-gate #ifdef USE_STRUCT_COPY 649*0Sstevel@tonic-gate #define StructCopy(s,d,t) (*((t*)(d)) = *((t*)(s))) 650*0Sstevel@tonic-gate #else 651*0Sstevel@tonic-gate #define StructCopy(s,d,t) Copy(s,d,1,t) 652*0Sstevel@tonic-gate #endif 653*0Sstevel@tonic-gate 654*0Sstevel@tonic-gate #define C_ARRAY_LENGTH(a) (sizeof(a)/sizeof((a)[0])) 655*0Sstevel@tonic-gate 656*0Sstevel@tonic-gate #ifdef NEED_VA_COPY 657*0Sstevel@tonic-gate # ifdef va_copy 658*0Sstevel@tonic-gate # define Perl_va_copy(s, d) va_copy(d, s) 659*0Sstevel@tonic-gate # else 660*0Sstevel@tonic-gate # if defined(__va_copy) 661*0Sstevel@tonic-gate # define Perl_va_copy(s, d) __va_copy(d, s) 662*0Sstevel@tonic-gate # else 663*0Sstevel@tonic-gate # define Perl_va_copy(s, d) Copy(s, d, 1, va_list) 664*0Sstevel@tonic-gate # endif 665*0Sstevel@tonic-gate # endif 666*0Sstevel@tonic-gate #endif 667*0Sstevel@tonic-gate 668