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