3 * Copyright (c) 1991-2001, 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)
24 =for apidoc AmU||Nullch
25 Null character pointer.
27 =for apidoc AmU||Nullsv
33 #define Nullch Null(char*)
34 #define Nullfp Null(PerlIO*)
35 #define Nullsv Null(SV*)
47 /* XXX Configure ought to have a test for a boolean type, if I can
48 just figure out all the headers such a test needs.
49 Andy Dougherty August 1996
51 /* bool is built-in for g++-2.6.3 and later, which might be used
52 for extensions. <_G_config.h> defines _G_HAVE_BOOL, but we can't
53 be sure _G_config.h will be included before this file. _G_config.h
54 also defines _G_HAVE_BOOL for both gcc and g++, but only g++
55 actually has bool. Hence, _G_HAVE_BOOL is pretty useless for us.
56 g++ can be identified by __GNUG__.
57 Andy Dougherty February 2000
59 #ifdef __GNUG__ /* GNU g++ has bool built-in */
65 /* The NeXT dynamic loader headers will not build with the bool macro
66 So declare them now to clear confusion.
68 #if defined(NeXT) || defined(__NeXT__)
71 typedef enum bool { FALSE = 0, TRUE = 1 } bool;
75 # endif /* !HAS_BOOL */
76 #endif /* NeXT || __NeXT__ */
79 # if defined(UTS) || defined(VMS)
87 /* XXX A note on the perl source internal type system. The
88 original intent was that I32 be *exactly* 32 bits.
90 Currently, we only guarantee that I32 is *at least* 32 bits.
91 Specifically, if int is 64 bits, then so is I32. (This is the case
92 for the Cray.) This has the advantage of meshing nicely with
93 standard library calls (where we pass an I32 and the library is
94 expecting an int), but the disadvantage that an I32 is not 32 bits.
95 Andy Dougherty August 1996
97 There is no guarantee that there is *any* integral type with
98 exactly 32 bits. It is perfectly legal for a system to have
99 sizeof(short) == sizeof(int) == sizeof(long) == 8.
101 Similarly, there is no guarantee that I16 and U16 have exactly 16
104 For dealing with issues that may arise from various 32/64-bit
105 systems, we will ask Configure to check out
107 SHORTSIZE == sizeof(short)
108 INTSIZE == sizeof(int)
109 LONGSIZE == sizeof(long)
110 LONGLONGSIZE == sizeof(long long) (if HAS_LONG_LONG)
111 PTRSIZE == sizeof(void *)
112 DOUBLESIZE == sizeof(double)
113 LONG_DOUBLESIZE == sizeof(long double) (if HAS_LONG_DOUBLE).
117 #ifdef I_INTTYPES /* e.g. Linux has int64_t without <inttypes.h> */
118 # include <inttypes.h>
119 # ifdef INT32_MIN_BROKEN
121 # define INT32_MIN (-2147483647-1)
123 # ifdef INT64_MIN_BROKEN
125 # define INT64_MIN (-9223372036854775807LL-1)
140 #endif /* PERL_CORE */
142 #if defined(HAS_QUAD) && defined(USE_64_BIT_INT)
143 # ifndef UINT64_C /* usually from <inttypes.h> */
144 # if defined(HAS_LONG_LONG) && QUADKIND == QUAD_IS_LONG_LONG
145 # define INT64_C(c) CAT2(c,LL)
146 # define UINT64_C(c) CAT2(c,ULL)
148 # if LONGSIZE == 8 && QUADKIND == QUAD_IS_LONG
149 # define INT64_C(c) CAT2(c,L)
150 # define UINT64_C(c) CAT2(c,UL)
152 # define INT64_C(c) ((I64TYPE)(c))
153 # define UINT64_C(c) ((U64TYPE)(c))
159 /* Mention I8SIZE, U8SIZE, I16SIZE, U16SIZE, I32SIZE, U32SIZE,
160 I64SIZE, and U64SIZE here so that metaconfig pulls them in. */
162 #if defined(UINT8_MAX) && defined(INT16_MAX) && defined(INT32_MAX)
164 /* I8_MAX and I8_MIN constants are not defined, as I8 is an ambiguous type.
165 Please search CHAR_MAX in perl.h for further details. */
166 #define U8_MAX UINT8_MAX
167 #define U8_MIN UINT8_MIN
169 #define I16_MAX INT16_MAX
170 #define I16_MIN INT16_MIN
171 #define U16_MAX UINT16_MAX
172 #define U16_MIN UINT16_MIN
174 #define I32_MAX INT32_MAX
175 #define I32_MIN INT32_MIN
176 #define U32_MAX UINT32_MAX
177 #define U32_MIN UINT32_MIN
181 /* I8_MAX and I8_MIN constants are not defined, as I8 is an ambiguous type.
182 Please search CHAR_MAX in perl.h for further details. */
183 #define U8_MAX PERL_UCHAR_MAX
184 #define U8_MIN PERL_UCHAR_MIN
186 #define I16_MAX PERL_SHORT_MAX
187 #define I16_MIN PERL_SHORT_MIN
188 #define U16_MAX PERL_USHORT_MAX
189 #define U16_MIN PERL_USHORT_MIN
192 # define I32_MAX PERL_INT_MAX
193 # define I32_MIN PERL_INT_MIN
194 # define U32_MAX PERL_UINT_MAX
195 # define U32_MIN PERL_UINT_MIN
197 # define I32_MAX PERL_LONG_MAX
198 # define I32_MIN PERL_LONG_MIN
199 # define U32_MAX PERL_ULONG_MAX
200 # define U32_MIN PERL_ULONG_MIN
205 /* log(2) is pretty close to 0.30103, just in case anyone is grepping for it */
206 #define BIT_DIGITS(N) (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */
207 #define TYPE_DIGITS(T) BIT_DIGITS(sizeof(T) * 8)
208 #define TYPE_CHARS(T) (TYPE_DIGITS(T) + 2) /* sign, NUL */
210 #define Ctl(ch) ((ch) & 037)
213 =for apidoc Am|bool|strNE|char* s1|char* s2
214 Test two strings to see if they are different. Returns true or
217 =for apidoc Am|bool|strEQ|char* s1|char* s2
218 Test two strings to see if they are equal. Returns true or false.
220 =for apidoc Am|bool|strLT|char* s1|char* s2
221 Test two strings to see if the first, C<s1>, is less than the second,
222 C<s2>. Returns true or false.
224 =for apidoc Am|bool|strLE|char* s1|char* s2
225 Test two strings to see if the first, C<s1>, is less than or equal to the
226 second, C<s2>. Returns true or false.
228 =for apidoc Am|bool|strGT|char* s1|char* s2
229 Test two strings to see if the first, C<s1>, is greater than the second,
230 C<s2>. Returns true or false.
232 =for apidoc Am|bool|strGE|char* s1|char* s2
233 Test two strings to see if the first, C<s1>, is greater than or equal to
234 the second, C<s2>. Returns true or false.
236 =for apidoc Am|bool|strnNE|char* s1|char* s2|STRLEN len
237 Test two strings to see if they are different. The C<len> parameter
238 indicates the number of bytes to compare. Returns true or false. (A
239 wrapper for C<strncmp>).
241 =for apidoc Am|bool|strnEQ|char* s1|char* s2|STRLEN len
242 Test two strings to see if they are equal. The C<len> parameter indicates
243 the number of bytes to compare. Returns true or false. (A wrapper for
249 #define strNE(s1,s2) (strcmp(s1,s2))
250 #define strEQ(s1,s2) (!strcmp(s1,s2))
251 #define strLT(s1,s2) (strcmp(s1,s2) < 0)
252 #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
253 #define strGT(s1,s2) (strcmp(s1,s2) > 0)
254 #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
255 #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
256 #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
259 # define memNE(s1,s2,l) (memcmp(s1,s2,l))
260 # define memEQ(s1,s2,l) (!memcmp(s1,s2,l))
262 # define memNE(s1,s2,l) (bcmp(s1,s2,l))
263 # define memEQ(s1,s2,l) (!bcmp(s1,s2,l))
269 * Unfortunately, the introduction of locales means that we
270 * can't trust isupper(), etc. to tell the truth. And when
271 * it comes to /\w+/ with tainting enabled, we *must* be able
272 * to trust our character classes.
274 * Therefore, the default tests in the text of Perl will be
275 * independent of locale. Any code that wants to depend on
276 * the current locale will use the tests that begin with "lc".
279 #ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */
286 =for apidoc Am|bool|isALNUM|char ch
287 Returns a boolean indicating whether the C C<char> is an ASCII alphanumeric
288 character (including underscore) or digit.
290 =for apidoc Am|bool|isALPHA|char ch
291 Returns a boolean indicating whether the C C<char> is an ASCII alphabetic
294 =for apidoc Am|bool|isSPACE|char ch
295 Returns a boolean indicating whether the C C<char> is whitespace.
297 =for apidoc Am|bool|isDIGIT|char ch
298 Returns a boolean indicating whether the C C<char> is an ASCII
301 =for apidoc Am|bool|isUPPER|char ch
302 Returns a boolean indicating whether the C C<char> is an uppercase
305 =for apidoc Am|bool|isLOWER|char ch
306 Returns a boolean indicating whether the C C<char> is a lowercase
309 =for apidoc Am|char|toUPPER|char ch
310 Converts the specified character to uppercase.
312 =for apidoc Am|char|toLOWER|char ch
313 Converts the specified character to lowercase.
318 #define isALNUM(c) (isALPHA(c) || isDIGIT(c) || (c) == '_')
319 #define isIDFIRST(c) (isALPHA(c) || (c) == '_')
320 #define isALPHA(c) (isUPPER(c) || isLOWER(c))
322 ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) =='\r' || (c) == '\f')
323 #define isPSXSPC(c) (isSPACE(c) || (c) == '\v')
324 #define isBLANK(c) ((c) == ' ' || (c) == '\t')
325 #define isDIGIT(c) ((c) >= '0' && (c) <= '9')
327 /* In EBCDIC we do not do locales: therefore() isupper() is fine. */
328 # define isUPPER(c) isupper(c)
329 # define isLOWER(c) islower(c)
330 # define isALNUMC(c) isalnum(c)
331 # define isASCII(c) isascii(c)
332 # define isCNTRL(c) iscntrl(c)
333 # define isGRAPH(c) isgraph(c)
334 # define isPRINT(c) isprint(c)
335 # define isPUNCT(c) ispunct(c)
336 # define isXDIGIT(c) isxdigit(c)
337 # define toUPPER(c) toupper(c)
338 # define toLOWER(c) tolower(c)
340 # define isUPPER(c) ((c) >= 'A' && (c) <= 'Z')
341 # define isLOWER(c) ((c) >= 'a' && (c) <= 'z')
342 # define isALNUMC(c) (isALPHA(c) || isDIGIT(c))
343 # define isASCII(c) ((c) <= 127)
344 # define isCNTRL(c) ((c) < ' ' || (c) == 127)
345 # define isGRAPH(c) (isALNUM(c) || isPUNCT(c))
346 # define isPRINT(c) (((c) > 32 && (c) < 127) || (c) == ' ')
347 # define isPUNCT(c) (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64) || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126))
348 # define isXDIGIT(c) (isdigit(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
349 # define toUPPER(c) (isLOWER(c) ? (c) - ('a' - 'A') : (c))
350 # define toLOWER(c) (isUPPER(c) ? (c) + ('a' - 'A') : (c))
353 #ifdef USE_NEXT_CTYPE
355 # define isALNUM_LC(c) \
356 (NXIsAlNum((unsigned int)(c)) || (char)(c) == '_')
357 # define isIDFIRST_LC(c) \
358 (NXIsAlpha((unsigned int)(c)) || (char)(c) == '_')
359 # define isALPHA_LC(c) NXIsAlpha((unsigned int)(c))
360 # define isSPACE_LC(c) NXIsSpace((unsigned int)(c))
361 # define isDIGIT_LC(c) NXIsDigit((unsigned int)(c))
362 # define isUPPER_LC(c) NXIsUpper((unsigned int)(c))
363 # define isLOWER_LC(c) NXIsLower((unsigned int)(c))
364 # define isALNUMC_LC(c) NXIsAlNum((unsigned int)(c))
365 # define isCNTRL_LC(c) NXIsCntrl((unsigned int)(c))
366 # define isGRAPH_LC(c) NXIsGraph((unsigned int)(c))
367 # define isPRINT_LC(c) NXIsPrint((unsigned int)(c))
368 # define isPUNCT_LC(c) NXIsPunct((unsigned int)(c))
369 # define toUPPER_LC(c) NXToUpper((unsigned int)(c))
370 # define toLOWER_LC(c) NXToLower((unsigned int)(c))
372 #else /* !USE_NEXT_CTYPE */
374 # if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
376 # define isALNUM_LC(c) (isalnum((unsigned char)(c)) || (char)(c) == '_')
377 # define isIDFIRST_LC(c) (isalpha((unsigned char)(c)) || (char)(c) == '_')
378 # define isALPHA_LC(c) isalpha((unsigned char)(c))
379 # define isSPACE_LC(c) isspace((unsigned char)(c))
380 # define isDIGIT_LC(c) isdigit((unsigned char)(c))
381 # define isUPPER_LC(c) isupper((unsigned char)(c))
382 # define isLOWER_LC(c) islower((unsigned char)(c))
383 # define isALNUMC_LC(c) isalnum((unsigned char)(c))
384 # define isCNTRL_LC(c) iscntrl((unsigned char)(c))
385 # define isGRAPH_LC(c) isgraph((unsigned char)(c))
386 # define isPRINT_LC(c) isprint((unsigned char)(c))
387 # define isPUNCT_LC(c) ispunct((unsigned char)(c))
388 # define toUPPER_LC(c) toupper((unsigned char)(c))
389 # define toLOWER_LC(c) tolower((unsigned char)(c))
393 # define isALNUM_LC(c) (isascii(c) && (isalnum(c) || (c) == '_'))
394 # define isIDFIRST_LC(c) (isascii(c) && (isalpha(c) || (c) == '_'))
395 # define isALPHA_LC(c) (isascii(c) && isalpha(c))
396 # define isSPACE_LC(c) (isascii(c) && isspace(c))
397 # define isDIGIT_LC(c) (isascii(c) && isdigit(c))
398 # define isUPPER_LC(c) (isascii(c) && isupper(c))
399 # define isLOWER_LC(c) (isascii(c) && islower(c))
400 # define isALNUMC_LC(c) (isascii(c) && isalnum(c))
401 # define isCNTRL_LC(c) (isascii(c) && iscntrl(c))
402 # define isGRAPH_LC(c) (isascii(c) && isgraph(c))
403 # define isPRINT_LC(c) (isascii(c) && isprint(c))
404 # define isPUNCT_LC(c) (isascii(c) && ispunct(c))
405 # define toUPPER_LC(c) toupper(c)
406 # define toLOWER_LC(c) tolower(c)
409 #endif /* USE_NEXT_CTYPE */
411 #define isPSXSPC_LC(c) (isSPACE_LC(c) || (c) == '\v')
412 #define isBLANK_LC(c) isBLANK(c) /* could be wrong */
414 #define isALNUM_uni(c) is_uni_alnum(c)
415 #define isIDFIRST_uni(c) is_uni_idfirst(c)
416 #define isALPHA_uni(c) is_uni_alpha(c)
417 #define isSPACE_uni(c) is_uni_space(c)
418 #define isDIGIT_uni(c) is_uni_digit(c)
419 #define isUPPER_uni(c) is_uni_upper(c)
420 #define isLOWER_uni(c) is_uni_lower(c)
421 #define isALNUMC_uni(c) is_uni_alnumc(c)
422 #define isASCII_uni(c) is_uni_ascii(c)
423 #define isCNTRL_uni(c) is_uni_cntrl(c)
424 #define isGRAPH_uni(c) is_uni_graph(c)
425 #define isPRINT_uni(c) is_uni_print(c)
426 #define isPUNCT_uni(c) is_uni_punct(c)
427 #define isXDIGIT_uni(c) is_uni_xdigit(c)
428 #define toUPPER_uni(c) to_uni_upper(c)
429 #define toTITLE_uni(c) to_uni_title(c)
430 #define toLOWER_uni(c) to_uni_lower(c)
432 #define isPSXSPC_uni(c) (isSPACE_uni(c) ||(c) == '\f')
433 #define isBLANK_uni(c) isBLANK(c) /* could be wrong */
435 #define isALNUM_LC_uvchr(c) (c < 256 ? isALNUM_LC(c) : is_uni_alnum_lc(c))
436 #define isIDFIRST_LC_uvchr(c) (c < 256 ? isIDFIRST_LC(c) : is_uni_idfirst_lc(c))
437 #define isALPHA_LC_uvchr(c) (c < 256 ? isALPHA_LC(c) : is_uni_alpha_lc(c))
438 #define isSPACE_LC_uvchr(c) (c < 256 ? isSPACE_LC(c) : is_uni_space_lc(c))
439 #define isDIGIT_LC_uvchr(c) (c < 256 ? isDIGIT_LC(c) : is_uni_digit_lc(c))
440 #define isUPPER_LC_uvchr(c) (c < 256 ? isUPPER_LC(c) : is_uni_upper_lc(c))
441 #define isLOWER_LC_uvchr(c) (c < 256 ? isLOWER_LC(c) : is_uni_lower_lc(c))
442 #define isALNUMC_LC_uvchr(c) (c < 256 ? isALNUMC_LC(c) : is_uni_alnumc_lc(c))
443 #define isCNTRL_LC_uvchr(c) (c < 256 ? isCNTRL_LC(c) : is_uni_cntrl_lc(c))
444 #define isGRAPH_LC_uvchr(c) (c < 256 ? isGRAPH_LC(c) : is_uni_graph_lc(c))
445 #define isPRINT_LC_uvchr(c) (c < 256 ? isPRINT_LC(c) : is_uni_print_lc(c))
446 #define isPUNCT_LC_uvchr(c) (c < 256 ? isPUNCT_LC(c) : is_uni_punct_lc(c))
447 #define toUPPER_LC_uvchr(c) (c < 256 ? toUPPER_LC(c) : to_uni_upper_lc(c))
448 #define toTITLE_LC_uvchr(c) (c < 256 ? toUPPER_LC(c) : to_uni_title_lc(c))
449 #define toLOWER_LC_uvchr(c) (c < 256 ? toLOWER_LC(c) : to_uni_lower_lc(c))
451 #define isPSXSPC_LC_uni(c) (isSPACE_LC_uni(c) ||(c) == '\f')
452 #define isBLANK_LC_uni(c) isBLANK(c) /* could be wrong */
454 #define isALNUM_utf8(p) is_utf8_alnum(p)
455 #define isIDFIRST_utf8(p) is_utf8_idfirst(p)
456 #define isALPHA_utf8(p) is_utf8_alpha(p)
457 #define isSPACE_utf8(p) is_utf8_space(p)
458 #define isDIGIT_utf8(p) is_utf8_digit(p)
459 #define isUPPER_utf8(p) is_utf8_upper(p)
460 #define isLOWER_utf8(p) is_utf8_lower(p)
461 #define isALNUMC_utf8(p) is_utf8_alnumc(p)
462 #define isASCII_utf8(p) is_utf8_ascii(p)
463 #define isCNTRL_utf8(p) is_utf8_cntrl(p)
464 #define isGRAPH_utf8(p) is_utf8_graph(p)
465 #define isPRINT_utf8(p) is_utf8_print(p)
466 #define isPUNCT_utf8(p) is_utf8_punct(p)
467 #define isXDIGIT_utf8(p) is_utf8_xdigit(p)
468 #define toUPPER_utf8(p) to_utf8_upper(p)
469 #define toTITLE_utf8(p) to_utf8_title(p)
470 #define toLOWER_utf8(p) to_utf8_lower(p)
472 #define isPSXSPC_utf8(c) (isSPACE_utf8(c) ||(c) == '\f')
473 #define isBLANK_utf8(c) isBLANK(c) /* could be wrong */
475 #define isALNUM_LC_utf8(p) isALNUM_LC_uvchr(utf8_to_uvchr(p, 0))
476 #define isIDFIRST_LC_utf8(p) isIDFIRST_LC_uvchr(utf8_to_uvchr(p, 0))
477 #define isALPHA_LC_utf8(p) isALPHA_LC_uvchr(utf8_to_uvchr(p, 0))
478 #define isSPACE_LC_utf8(p) isSPACE_LC_uvchr(utf8_to_uvchr(p, 0))
479 #define isDIGIT_LC_utf8(p) isDIGIT_LC_uvchr(utf8_to_uvchr(p, 0))
480 #define isUPPER_LC_utf8(p) isUPPER_LC_uvchr(utf8_to_uvchr(p, 0))
481 #define isLOWER_LC_utf8(p) isLOWER_LC_uvchr(utf8_to_uvchr(p, 0))
482 #define isALNUMC_LC_utf8(p) isALNUMC_LC_uvchr(utf8_to_uvchr(p, 0))
483 #define isCNTRL_LC_utf8(p) isCNTRL_LC_uvchr(utf8_to_uvchr(p, 0))
484 #define isGRAPH_LC_utf8(p) isGRAPH_LC_uvchr(utf8_to_uvchr(p, 0))
485 #define isPRINT_LC_utf8(p) isPRINT_LC_uvchr(utf8_to_uvchr(p, 0))
486 #define isPUNCT_LC_utf8(p) isPUNCT_LC_uvchr(utf8_to_uvchr(p, 0))
487 #define toUPPER_LC_utf8(p) toUPPER_LC_uvchr(utf8_to_uvchr(p, 0))
488 #define toTITLE_LC_utf8(p) toTITLE_LC_uvchr(utf8_to_uvchr(p, 0))
489 #define toLOWER_LC_utf8(p) toLOWER_LC_uvchr(utf8_to_uvchr(p, 0))
491 #define isPSXSPC_LC_utf8(c) (isSPACE_LC_utf8(c) ||(c) == '\f')
492 #define isBLANK_LC_utf8(c) isBLANK(c) /* could be wrong */
495 # define toCTRL(c) Perl_ebcdic_control(c)
497 /* This conversion works both ways, strangely enough. */
498 # define toCTRL(c) (toUPPER(c) ^ 64)
501 /* Line numbers are unsigned, 16 bits. */
504 #define NOLINE ((line_t)0)
506 #define NOLINE ((line_t) 65535)
511 XXX LEAKTEST doesn't really work in perl5. There are direct calls to
512 safemalloc() in the source, so LEAKTEST won't pick them up.
513 (The main "offenders" are extensions.)
514 Further, if you try LEAKTEST, you'll also end up calling
515 Safefree, which might call safexfree() on some things that weren't
516 malloced with safexmalloc. The correct "fix" to this, if anyone
517 is interested, is to ensure that all calls go through the New and
519 --Andy Dougherty August 1996
523 =for apidoc Am|SV*|NEWSV|int id|STRLEN len
524 Creates a new SV. A non-zero C<len> parameter indicates the number of
525 bytes of preallocated string space the SV should have. An extra byte for a
526 tailing NUL is also reserved. (SvPOK is not set for the SV even if string
527 space is allocated.) The reference count for the new SV is set to 1.
528 C<id> is an integer id between 0 and 1299 (used to identify leaks).
530 =for apidoc Am|void|New|int id|void* ptr|int nitems|type
531 The XSUB-writer's interface to the C C<malloc> function.
533 =for apidoc Am|void|Newc|int id|void* ptr|int nitems|type|cast
534 The XSUB-writer's interface to the C C<malloc> function, with
537 =for apidoc Am|void|Newz|int id|void* ptr|int nitems|type
538 The XSUB-writer's interface to the C C<malloc> function. The allocated
539 memory is zeroed with C<memzero>.
541 =for apidoc Am|void|Renew|void* ptr|int nitems|type
542 The XSUB-writer's interface to the C C<realloc> function.
544 =for apidoc Am|void|Renewc|void* ptr|int nitems|type|cast
545 The XSUB-writer's interface to the C C<realloc> function, with
548 =for apidoc Am|void|Safefree|void* ptr
549 The XSUB-writer's interface to the C C<free> function.
551 =for apidoc Am|void|Move|void* src|void* dest|int nitems|type
552 The XSUB-writer's interface to the C C<memmove> function. The C<src> is the
553 source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
554 the type. Can do overlapping moves. See also C<Copy>.
556 =for apidoc Am|void|Copy|void* src|void* dest|int nitems|type
557 The XSUB-writer's interface to the C C<memcpy> function. The C<src> is the
558 source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
559 the type. May fail on overlapping copies. See also C<Move>.
561 =for apidoc Am|void|Zero|void* dest|int nitems|type
563 The XSUB-writer's interface to the C C<memzero> function. The C<dest> is the
564 destination, C<nitems> is the number of items, and C<type> is the type.
566 =for apidoc Am|void|StructCopy|type src|type dest|type
567 This is an architecture-independent macro to copy one structure to another.
574 #define NEWSV(x,len) newSV(len)
578 #define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n)*sizeof(t))))
579 #define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n)*sizeof(t))))
580 #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n)*sizeof(t)))), \
581 memzero((char*)(v), (n)*sizeof(t))
582 #define Renew(v,n,t) \
583 (v = (t*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))
584 #define Renewc(v,n,t,c) \
585 (v = (c*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))
586 #define Safefree(d) safefree((Malloc_t)(d))
590 #define New(x,v,n,t) (v = (t*)safexmalloc((x),(MEM_SIZE)((n)*sizeof(t))))
591 #define Newc(x,v,n,t,c) (v = (c*)safexmalloc((x),(MEM_SIZE)((n)*sizeof(t))))
592 #define Newz(x,v,n,t) (v = (t*)safexmalloc((x),(MEM_SIZE)((n)*sizeof(t)))), \
593 memzero((char*)(v), (n)*sizeof(t))
594 #define Renew(v,n,t) \
595 (v = (t*)safexrealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))
596 #define Renewc(v,n,t,c) \
597 (v = (c*)safexrealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))
598 #define Safefree(d) safexfree((Malloc_t)(d))
600 #define MAXXCOUNT 1400
602 #define MAXYCOUNT 16 /* (MAXY_SIZE/4 + 1) */
603 extern long xcount[MAXXCOUNT];
604 extern long lastxcount[MAXXCOUNT];
605 extern long xycount[MAXXCOUNT][MAXYCOUNT];
606 extern long lastxycount[MAXXCOUNT][MAXYCOUNT];
608 #endif /* LEAKTEST */
610 #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
611 #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
612 #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
616 #define New(x,v,n,s) (v = Null(s *))
617 #define Newc(x,v,n,s,c) (v = Null(s *))
618 #define Newz(x,v,n,s) (v = Null(s *))
619 #define Renew(v,n,s) (v = Null(s *))
620 #define Move(s,d,n,t)
621 #define Copy(s,d,n,t)
623 #define Safefree(d) (d) = (d)
627 #ifdef USE_STRUCT_COPY
628 #define StructCopy(s,d,t) (*((t*)(d)) = *((t*)(s)))
630 #define StructCopy(s,d,t) Copy(s,d,1,t)
635 # define Perl_va_copy(s, d) va_copy(d, s)
637 # if defined(__va_copy)
638 # define Perl_va_copy(s, d) __va_copy(d, s)
640 # define Perl_va_copy(s, d) Copy(s, d, 1, va_list)