This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Bunch of doc patches from Stas; plus regen.
[perl5.git] / handy.h
1 /*    handy.h
2  *
3  *    Copyright (c) 1991-2002, Larry Wall
4  *
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.
7  *
8  */
9
10 #if !defined(__STDC__)
11 #ifdef NULL
12 #undef NULL
13 #endif
14 #ifndef I286
15 #  define NULL 0
16 #else
17 #  define NULL 0L
18 #endif
19 #endif
20
21 #define Null(type) ((type)NULL)
22
23 /*
24 =head1 Handy Values
25
26 =for apidoc AmU||Nullch 
27 Null character pointer.
28
29 =for apidoc AmU||Nullsv
30 Null SV pointer.
31
32 =cut
33 */
34
35 #define Nullch Null(char*)
36 #define Nullfp Null(PerlIO*)
37 #define Nullsv Null(SV*)
38
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
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 */
53 /* bool is built-in for g++-2.6.3 and later, which might be used
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
56    also defines _G_HAVE_BOOL for both gcc and g++, but only g++
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
60 */
61 #ifdef __GNUG__         /* GNU g++ has bool built-in */
62 #  ifndef HAS_BOOL
63 #    define HAS_BOOL 1
64 #  endif
65 #endif
66
67 /* The NeXT dynamic loader headers will not build with the bool macro
68    So declare them now to clear confusion.
69 */
70 #if defined(NeXT) || defined(__NeXT__)
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 */
78 #endif /* NeXT || __NeXT__ */
79
80 #ifndef HAS_BOOL
81 # if defined(UTS) || defined(VMS)
82 #  define bool int
83 # else
84 #  define bool char
85 # endif
86 # define HAS_BOOL 1
87 #endif
88
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
98
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.
102
103    Similarly, there is no guarantee that I16 and U16 have exactly 16
104    bits.
105
106    For dealing with issues that may arise from various 32/64-bit
107    systems, we will ask Configure to check out
108
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).
116
117 */
118
119 #ifdef I_INTTYPES /* e.g. Linux has int64_t without <inttypes.h> */
120 #   include <inttypes.h>
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
129 #endif
130
131 typedef I8TYPE I8;
132 typedef U8TYPE U8;
133 typedef I16TYPE I16;
134 typedef U16TYPE U16;
135 typedef I32TYPE I32;
136 typedef U32TYPE U32;
137 #ifdef PERL_CORE
138 #   ifdef HAS_QUAD
139 typedef I64TYPE I64;
140 typedef U64TYPE U64;
141 #   endif
142 #endif /* PERL_CORE */
143
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
158 #   endif
159 #endif
160
161 /* Mention I8SIZE, U8SIZE, I16SIZE, U16SIZE, I32SIZE, U32SIZE,
162    I64SIZE, and U64SIZE here so that metaconfig pulls them in. */
163
164 #if defined(UINT8_MAX) && defined(INT16_MAX) && defined(INT32_MAX)
165
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
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
176 #define I32_MAX INT32_MAX
177 #define I32_MIN INT32_MIN
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
183 #define U32_MIN UINT32_MIN
184
185 #else
186
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. */
189 #define U8_MAX PERL_UCHAR_MAX
190 #define U8_MIN PERL_UCHAR_MIN
191
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
196
197 #if LONGSIZE > 4
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
202 #else
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
207 #endif
208
209 #endif
210
211 /* log(2) is pretty close to  0.30103, just in case anyone is grepping for it */
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
216 #define Ctl(ch) ((ch) & 037)
217
218 /*
219 =head1 Miscellaneous Functions
220
221 =for apidoc Am|bool|strNE|char* s1|char* s2
222 Test two strings to see if they are different.  Returns true or
223 false.
224
225 =for apidoc Am|bool|strEQ|char* s1|char* s2
226 Test two strings to see if they are equal.  Returns true or false.
227
228 =for apidoc Am|bool|strLT|char* s1|char* s2
229 Test two strings to see if the first, C<s1>, is less than the second,
230 C<s2>.  Returns true or false.
231
232 =for apidoc Am|bool|strLE|char* s1|char* s2
233 Test two strings to see if the first, C<s1>, is less than or equal to the
234 second, C<s2>.  Returns true or false.
235
236 =for apidoc Am|bool|strGT|char* s1|char* s2
237 Test two strings to see if the first, C<s1>, is greater than the second,
238 C<s2>.  Returns true or false.
239
240 =for apidoc Am|bool|strGE|char* s1|char* s2
241 Test two strings to see if the first, C<s1>, is greater than or equal to
242 the second, C<s2>.  Returns true or false.
243
244 =for apidoc Am|bool|strnNE|char* s1|char* s2|STRLEN len
245 Test two strings to see if they are different.  The C<len> parameter
246 indicates the number of bytes to compare.  Returns true or false. (A
247 wrapper for C<strncmp>).
248
249 =for apidoc Am|bool|strnEQ|char* s1|char* s2|STRLEN len
250 Test two strings to see if they are equal.  The C<len> parameter indicates
251 the number of bytes to compare.  Returns true or false. (A wrapper for
252 C<strncmp>).
253
254 =cut
255 */
256
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))
265
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
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
287 #ifdef HAS_SETLOCALE  /* XXX Is there a better test for this? */
288 #  ifndef CTYPE256
289 #    define CTYPE256
290 #  endif
291 #endif
292
293 /*
294
295 =head1 Character classes
296
297 =for apidoc Am|bool|isALNUM|char ch
298 Returns a boolean indicating whether the C C<char> is an ASCII alphanumeric
299 character (including underscore) or digit.
300
301 =for apidoc Am|bool|isALPHA|char ch
302 Returns a boolean indicating whether the C C<char> is an ASCII alphabetic
303 character.
304
305 =for apidoc Am|bool|isSPACE|char ch
306 Returns a boolean indicating whether the C C<char> is whitespace.
307
308 =for apidoc Am|bool|isDIGIT|char ch
309 Returns a boolean indicating whether the C C<char> is an ASCII
310 digit.
311
312 =for apidoc Am|bool|isUPPER|char ch
313 Returns a boolean indicating whether the C C<char> is an uppercase
314 character.
315
316 =for apidoc Am|bool|isLOWER|char ch
317 Returns a boolean indicating whether the C C<char> is a lowercase
318 character.
319
320 =for apidoc Am|char|toUPPER|char ch
321 Converts the specified character to uppercase.
322
323 =for apidoc Am|char|toLOWER|char ch
324 Converts the specified character to lowercase.
325
326 =cut
327 */
328
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')
334 #define isPSXSPC(c)     (isSPACE(c) || (c) == '\v')
335 #define isBLANK(c)      ((c) == ' ' || (c) == '\t')
336 #define isDIGIT(c)      ((c) >= '0' && (c) <= '9')
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)
341 #   define isALNUMC(c)  isalnum(c)
342 #   define isASCII(c)   isascii(c)
343 #   define isCNTRL(c)   iscntrl(c)
344 #   define isGRAPH(c)   isgraph(c)
345 #   define isPRINT(c)   isprint(c)
346 #   define isPUNCT(c)   ispunct(c)
347 #   define isXDIGIT(c)  isxdigit(c)
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')
353 #   define isALNUMC(c)  (isALPHA(c) || isDIGIT(c))
354 #   define isASCII(c)   ((c) <= 127)
355 #   define isCNTRL(c)   ((c) < ' ' || (c) == 127)
356 #   define isGRAPH(c)   (isALNUM(c) || isPUNCT(c))
357 #   define isPRINT(c)   (((c) > 32 && (c) < 127) || (c) == ' ')
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'))
360 #   define toUPPER(c)   (isLOWER(c) ? (c) - ('a' - 'A') : (c))
361 #   define toLOWER(c)   (isUPPER(c) ? (c) + ('a' - 'A') : (c))
362 #endif
363
364 #ifdef USE_NEXT_CTYPE
365
366 #  define isALNUM_LC(c) \
367         (NXIsAlNum((unsigned int)(c)) || (char)(c) == '_')
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))
375 #  define isALNUMC_LC(c)        NXIsAlNum((unsigned int)(c))
376 #  define isCNTRL_LC(c)         NXIsCntrl((unsigned int)(c))
377 #  define isGRAPH_LC(c)         NXIsGraph((unsigned int)(c))
378 #  define isPRINT_LC(c)         NXIsPrint((unsigned int)(c))
379 #  define isPUNCT_LC(c)         NXIsPunct((unsigned int)(c))
380 #  define toUPPER_LC(c)         NXToUpper((unsigned int)(c))
381 #  define toLOWER_LC(c)         NXToLower((unsigned int)(c))
382
383 #else /* !USE_NEXT_CTYPE */
384
385 #  if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
386
387 #    define isALNUM_LC(c)   (isalnum((unsigned char)(c)) || (char)(c) == '_')
388 #    define isIDFIRST_LC(c) (isalpha((unsigned char)(c)) || (char)(c) == '_')
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))
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))
397 #    define isPRINT_LC(c)       isprint((unsigned char)(c))
398 #    define isPUNCT_LC(c)       ispunct((unsigned char)(c))
399 #    define toUPPER_LC(c)       toupper((unsigned char)(c))
400 #    define toLOWER_LC(c)       tolower((unsigned char)(c))
401
402 #  else
403
404 #    define isALNUM_LC(c)       (isascii(c) && (isalnum(c) || (c) == '_'))
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))
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))
414 #    define isPRINT_LC(c)       (isascii(c) && isprint(c))
415 #    define isPUNCT_LC(c)       (isascii(c) && ispunct(c))
416 #    define toUPPER_LC(c)       toupper(c)
417 #    define toLOWER_LC(c)       tolower(c)
418
419 #  endif
420 #endif /* USE_NEXT_CTYPE */
421
422 #define isPSXSPC_LC(c)          (isSPACE_LC(c) || (c) == '\v')
423 #define isBLANK_LC(c)           isBLANK(c) /* could be wrong */
424
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)
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)
436 #define isPRINT_uni(c)          is_uni_print(c)
437 #define isPUNCT_uni(c)          is_uni_punct(c)
438 #define isXDIGIT_uni(c)         is_uni_xdigit(c)
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)
442 #define toFOLD_uni(c,s,l)       to_uni_fold(c,s,l)
443
444 #define isPSXSPC_uni(c)         (isSPACE_uni(c) ||(c) == '\f')
445 #define isBLANK_uni(c)          isBLANK(c) /* could be wrong */
446
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))
459
460 #define isPSXSPC_LC_uni(c)      (isSPACE_LC_uni(c) ||(c) == '\f')
461 #define isBLANK_LC_uni(c)       isBLANK(c) /* could be wrong */
462
463 #define isALNUM_utf8(p)         is_utf8_alnum(p)
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))
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)
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)
477 #define isPRINT_utf8(p)         is_utf8_print(p)
478 #define isPUNCT_utf8(p)         is_utf8_punct(p)
479 #define isXDIGIT_utf8(p)        is_utf8_xdigit(p)
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)
483
484 #define isPSXSPC_utf8(c)        (isSPACE_utf8(c) ||(c) == '\f')
485 #define isBLANK_utf8(c)         isBLANK(c) /* could be wrong */
486
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))
499
500 #define isPSXSPC_LC_utf8(c)     (isSPACE_LC_utf8(c) ||(c) == '\f')
501 #define isBLANK_LC_utf8(c)      isBLANK(c) /* could be wrong */
502
503 #ifdef EBCDIC
504 #  define toCTRL(c)     Perl_ebcdic_control(c)
505 #else
506   /* This conversion works both ways, strangely enough. */
507 #  define toCTRL(c)    (toUPPER(c) ^ 64)
508 #endif
509
510 /* Line numbers are unsigned, 16 bits. */
511 typedef U16 line_t;
512 #ifdef lint
513 #define NOLINE ((line_t)0)
514 #else
515 #define NOLINE ((line_t) 65535)
516 #endif
517
518
519 /*
520 =head1 SV Manipulation Functions
521
522 =for apidoc Am|SV*|NEWSV|int id|STRLEN len
523 Creates a new SV.  A non-zero C<len> parameter indicates the number of
524 bytes of preallocated string space the SV should have.  An extra byte for a
525 tailing NUL is also reserved.  (SvPOK is not set for the SV even if string
526 space is allocated.)  The reference count for the new SV is set to 1.
527 C<id> is an integer id between 0 and 1299 (used to identify leaks).
528
529 =head1 Memory Management
530
531 =for apidoc Am|void|New|int id|void* ptr|int nitems|type
532 The 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
535 The XSUB-writer's interface to the C C<malloc> function, with
536 cast.
537
538 =for apidoc Am|void|Newz|int id|void* ptr|int nitems|type
539 The XSUB-writer's interface to the C C<malloc> function.  The allocated
540 memory is zeroed with C<memzero>.
541
542 =for apidoc Am|void|Renew|void* ptr|int nitems|type
543 The XSUB-writer's interface to the C C<realloc> function.
544
545 =for apidoc Am|void|Renewc|void* ptr|int nitems|type|cast
546 The XSUB-writer's interface to the C C<realloc> function, with
547 cast.
548
549 =for apidoc Am|void|Safefree|void* ptr
550 The XSUB-writer's interface to the C C<free> function.
551
552 =for apidoc Am|void|Move|void* src|void* dest|int nitems|type
553 The XSUB-writer's interface to the C C<memmove> function.  The C<src> is the
554 source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
555 the type.  Can do overlapping moves.  See also C<Copy>.
556
557 =for apidoc Am|void|Copy|void* src|void* dest|int nitems|type
558 The XSUB-writer's interface to the C C<memcpy> function.  The C<src> is the
559 source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
560 the type.  May fail on overlapping copies.  See also C<Move>.
561
562 =for apidoc Am|void|Zero|void* dest|int nitems|type
563
564 The XSUB-writer's interface to the C C<memzero> function.  The C<dest> is the
565 destination, 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
568 This is an architecture-independent macro to copy one structure to another.
569
570 =for apidoc Am|void|Poison|void* dest|int nitems|type
571
572 Fill up memory with a pattern (byte 0xAB over and over again) that
573 hopefully catches attempts to access uninitialized memory.
574
575 =cut */
576
577 #ifndef lint
578
579 #define NEWSV(x,len)    newSV(len)
580
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))
590
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))
594
595 #define Poison(d,n,t)   (void)memset((char*)(d), 0xAB, (n) * sizeof(t))
596
597 #else /* lint */
598
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 *))
603 #define Move(s,d,n,t)
604 #define Copy(s,d,n,t)
605 #define Zero(d,n,t)
606 #define Poison(d,n,t)
607 #define Safefree(d)     (d) = (d)
608
609 #endif /* lint */
610
611 #ifdef USE_STRUCT_COPY
612 #define StructCopy(s,d,t) (*((t*)(d)) = *((t*)(s)))
613 #else
614 #define StructCopy(s,d,t) Copy(s,d,1,t)
615 #endif
616
617 #ifdef NEED_VA_COPY
618 # ifdef va_copy
619 #  define Perl_va_copy(s, d) va_copy(d, s)
620 # else
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
626 # endif
627 #endif
628