3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999,
4 * 2000, 2001, 2002, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
11 #if !defined(__STDC__)
22 #define Null(type) ((type)NULL)
27 =for apidoc AmU||Nullch
28 Null character pointer.
30 =for apidoc AmU||Nullsv
36 #define Nullch Null(char*)
37 #define Nullfp Null(PerlIO*)
38 #define Nullsv Null(SV*)
50 /* XXX Configure ought to have a test for a boolean type, if I can
51 just figure out all the headers such a test needs.
52 Andy Dougherty August 1996
54 /* bool is built-in for g++-2.6.3 and later, which might be used
55 for extensions. <_G_config.h> defines _G_HAVE_BOOL, but we can't
56 be sure _G_config.h will be included before this file. _G_config.h
57 also defines _G_HAVE_BOOL for both gcc and g++, but only g++
58 actually has bool. Hence, _G_HAVE_BOOL is pretty useless for us.
59 g++ can be identified by __GNUG__.
60 Andy Dougherty February 2000
62 #ifdef __GNUG__ /* GNU g++ has bool built-in */
68 /* The NeXT dynamic loader headers will not build with the bool macro
69 So declare them now to clear confusion.
71 #if defined(NeXT) || defined(__NeXT__)
74 typedef enum bool { FALSE = 0, TRUE = 1 } bool;
78 # endif /* !HAS_BOOL */
79 #endif /* NeXT || __NeXT__ */
82 # if defined(UTS) || defined(VMS)
90 /* XXX A note on the perl source internal type system. The
91 original intent was that I32 be *exactly* 32 bits.
93 Currently, we only guarantee that I32 is *at least* 32 bits.
94 Specifically, if int is 64 bits, then so is I32. (This is the case
95 for the Cray.) This has the advantage of meshing nicely with
96 standard library calls (where we pass an I32 and the library is
97 expecting an int), but the disadvantage that an I32 is not 32 bits.
98 Andy Dougherty August 1996
100 There is no guarantee that there is *any* integral type with
101 exactly 32 bits. It is perfectly legal for a system to have
102 sizeof(short) == sizeof(int) == sizeof(long) == 8.
104 Similarly, there is no guarantee that I16 and U16 have exactly 16
107 For dealing with issues that may arise from various 32/64-bit
108 systems, we will ask Configure to check out
110 SHORTSIZE == sizeof(short)
111 INTSIZE == sizeof(int)
112 LONGSIZE == sizeof(long)
113 LONGLONGSIZE == sizeof(long long) (if HAS_LONG_LONG)
114 PTRSIZE == sizeof(void *)
115 DOUBLESIZE == sizeof(double)
116 LONG_DOUBLESIZE == sizeof(long double) (if HAS_LONG_DOUBLE).
120 #ifdef I_INTTYPES /* e.g. Linux has int64_t without <inttypes.h> */
121 # include <inttypes.h>
122 # ifdef INT32_MIN_BROKEN
124 # define INT32_MIN (-2147483647-1)
126 # ifdef INT64_MIN_BROKEN
128 # define INT64_MIN (-9223372036854775807LL-1)
143 #endif /* PERL_CORE */
145 #if defined(HAS_QUAD) && defined(USE_64_BIT_INT)
146 # ifndef UINT64_C /* usually from <inttypes.h> */
147 # if defined(HAS_LONG_LONG) && QUADKIND == QUAD_IS_LONG_LONG
148 # define INT64_C(c) CAT2(c,LL)
149 # define UINT64_C(c) CAT2(c,ULL)
151 # if LONGSIZE == 8 && QUADKIND == QUAD_IS_LONG
152 # define INT64_C(c) CAT2(c,L)
153 # define UINT64_C(c) CAT2(c,UL)
155 # define INT64_C(c) ((I64TYPE)(c))
156 # define UINT64_C(c) ((U64TYPE)(c))
162 /* Mention I8SIZE, U8SIZE, I16SIZE, U16SIZE, I32SIZE, U32SIZE,
163 I64SIZE, and U64SIZE here so that metaconfig pulls them in. */
165 #if defined(UINT8_MAX) && defined(INT16_MAX) && defined(INT32_MAX)
167 /* I8_MAX and I8_MIN constants are not defined, as I8 is an ambiguous type.
168 Please search CHAR_MAX in perl.h for further details. */
169 #define U8_MAX UINT8_MAX
170 #define U8_MIN UINT8_MIN
172 #define I16_MAX INT16_MAX
173 #define I16_MIN INT16_MIN
174 #define U16_MAX UINT16_MAX
175 #define U16_MIN UINT16_MIN
177 #define I32_MAX INT32_MAX
178 #define I32_MIN INT32_MIN
179 #ifndef UINT32_MAX_BROKEN /* e.g. HP-UX with gcc messes this up */
180 # define U32_MAX UINT32_MAX
182 # define U32_MAX 4294967295U
184 #define U32_MIN UINT32_MIN
188 /* I8_MAX and I8_MIN constants are not defined, as I8 is an ambiguous type.
189 Please search CHAR_MAX in perl.h for further details. */
190 #define U8_MAX PERL_UCHAR_MAX
191 #define U8_MIN PERL_UCHAR_MIN
193 #define I16_MAX PERL_SHORT_MAX
194 #define I16_MIN PERL_SHORT_MIN
195 #define U16_MAX PERL_USHORT_MAX
196 #define U16_MIN PERL_USHORT_MIN
199 # define I32_MAX PERL_INT_MAX
200 # define I32_MIN PERL_INT_MIN
201 # define U32_MAX PERL_UINT_MAX
202 # define U32_MIN PERL_UINT_MIN
204 # define I32_MAX PERL_LONG_MAX
205 # define I32_MIN PERL_LONG_MIN
206 # define U32_MAX PERL_ULONG_MAX
207 # define U32_MIN PERL_ULONG_MIN
212 /* log(2) is pretty close to 0.30103, just in case anyone is grepping for it */
213 #define BIT_DIGITS(N) (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */
214 #define TYPE_DIGITS(T) BIT_DIGITS(sizeof(T) * 8)
215 #define TYPE_CHARS(T) (TYPE_DIGITS(T) + 2) /* sign, NUL */
217 #define Ctl(ch) ((ch) & 037)
220 =head1 Miscellaneous Functions
222 =for apidoc Am|bool|strNE|char* s1|char* s2
223 Test two strings to see if they are different. Returns true or
226 =for apidoc Am|bool|strEQ|char* s1|char* s2
227 Test two strings to see if they are equal. Returns true or false.
229 =for apidoc Am|bool|strLT|char* s1|char* s2
230 Test two strings to see if the first, C<s1>, is less than the second,
231 C<s2>. Returns true or false.
233 =for apidoc Am|bool|strLE|char* s1|char* s2
234 Test two strings to see if the first, C<s1>, is less than or equal to the
235 second, C<s2>. Returns true or false.
237 =for apidoc Am|bool|strGT|char* s1|char* s2
238 Test two strings to see if the first, C<s1>, is greater than the second,
239 C<s2>. Returns true or false.
241 =for apidoc Am|bool|strGE|char* s1|char* s2
242 Test two strings to see if the first, C<s1>, is greater than or equal to
243 the second, C<s2>. Returns true or false.
245 =for apidoc Am|bool|strnNE|char* s1|char* s2|STRLEN len
246 Test two strings to see if they are different. The C<len> parameter
247 indicates the number of bytes to compare. Returns true or false. (A
248 wrapper for C<strncmp>).
250 =for apidoc Am|bool|strnEQ|char* s1|char* s2|STRLEN len
251 Test two strings to see if they are equal. The C<len> parameter indicates
252 the number of bytes to compare. Returns true or false. (A wrapper for
258 #define strNE(s1,s2) (strcmp(s1,s2))
259 #define strEQ(s1,s2) (!strcmp(s1,s2))
260 #define strLT(s1,s2) (strcmp(s1,s2) < 0)
261 #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
262 #define strGT(s1,s2) (strcmp(s1,s2) > 0)
263 #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
264 #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
265 #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
268 # define memNE(s1,s2,l) (memcmp(s1,s2,l))
269 # define memEQ(s1,s2,l) (!memcmp(s1,s2,l))
271 # define memNE(s1,s2,l) (bcmp(s1,s2,l))
272 # define memEQ(s1,s2,l) (!bcmp(s1,s2,l))
278 * Unfortunately, the introduction of locales means that we
279 * can't trust isupper(), etc. to tell the truth. And when
280 * it comes to /\w+/ with tainting enabled, we *must* be able
281 * to trust our character classes.
283 * Therefore, the default tests in the text of Perl will be
284 * independent of locale. Any code that wants to depend on
285 * the current locale will use the tests that begin with "lc".
288 #ifdef HAS_SETLOCALE /* XXX Is there a better test for this? */
296 =head1 Character classes
298 =for apidoc Am|bool|isALNUM|char ch
299 Returns a boolean indicating whether the C C<char> is an ASCII alphanumeric
300 character (including underscore) or digit.
302 =for apidoc Am|bool|isALPHA|char ch
303 Returns a boolean indicating whether the C C<char> is an ASCII alphabetic
306 =for apidoc Am|bool|isSPACE|char ch
307 Returns a boolean indicating whether the C C<char> is whitespace.
309 =for apidoc Am|bool|isDIGIT|char ch
310 Returns a boolean indicating whether the C C<char> is an ASCII
313 =for apidoc Am|bool|isUPPER|char ch
314 Returns a boolean indicating whether the C C<char> is an uppercase
317 =for apidoc Am|bool|isLOWER|char ch
318 Returns a boolean indicating whether the C C<char> is a lowercase
321 =for apidoc Am|char|toUPPER|char ch
322 Converts the specified character to uppercase.
324 =for apidoc Am|char|toLOWER|char ch
325 Converts the specified character to lowercase.
330 #define isALNUM(c) (isALPHA(c) || isDIGIT(c) || (c) == '_')
331 #define isIDFIRST(c) (isALPHA(c) || (c) == '_')
332 #define isALPHA(c) (isUPPER(c) || isLOWER(c))
334 ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) =='\r' || (c) == '\f')
335 #define isPSXSPC(c) (isSPACE(c) || (c) == '\v')
336 #define isBLANK(c) ((c) == ' ' || (c) == '\t')
337 #define isDIGIT(c) ((c) >= '0' && (c) <= '9')
339 /* In EBCDIC we do not do locales: therefore() isupper() is fine. */
340 # define isUPPER(c) isupper(c)
341 # define isLOWER(c) islower(c)
342 # define isALNUMC(c) isalnum(c)
343 # define isASCII(c) isascii(c)
344 # define isCNTRL(c) iscntrl(c)
345 # define isGRAPH(c) isgraph(c)
346 # define isPRINT(c) isprint(c)
347 # define isPUNCT(c) ispunct(c)
348 # define isXDIGIT(c) isxdigit(c)
349 # define toUPPER(c) toupper(c)
350 # define toLOWER(c) tolower(c)
352 # define isUPPER(c) ((c) >= 'A' && (c) <= 'Z')
353 # define isLOWER(c) ((c) >= 'a' && (c) <= 'z')
354 # define isALNUMC(c) (isALPHA(c) || isDIGIT(c))
355 # define isASCII(c) ((c) <= 127)
356 # define isCNTRL(c) ((c) < ' ' || (c) == 127)
357 # define isGRAPH(c) (isALNUM(c) || isPUNCT(c))
358 # define isPRINT(c) (((c) > 32 && (c) < 127) || (c) == ' ')
359 # define isPUNCT(c) (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64) || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126))
360 # define isXDIGIT(c) (isdigit(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
361 # define toUPPER(c) (isLOWER(c) ? (c) - ('a' - 'A') : (c))
362 # define toLOWER(c) (isUPPER(c) ? (c) + ('a' - 'A') : (c))
365 #ifdef USE_NEXT_CTYPE
367 # define isALNUM_LC(c) \
368 (NXIsAlNum((unsigned int)(c)) || (char)(c) == '_')
369 # define isIDFIRST_LC(c) \
370 (NXIsAlpha((unsigned int)(c)) || (char)(c) == '_')
371 # define isALPHA_LC(c) NXIsAlpha((unsigned int)(c))
372 # define isSPACE_LC(c) NXIsSpace((unsigned int)(c))
373 # define isDIGIT_LC(c) NXIsDigit((unsigned int)(c))
374 # define isUPPER_LC(c) NXIsUpper((unsigned int)(c))
375 # define isLOWER_LC(c) NXIsLower((unsigned int)(c))
376 # define isALNUMC_LC(c) NXIsAlNum((unsigned int)(c))
377 # define isCNTRL_LC(c) NXIsCntrl((unsigned int)(c))
378 # define isGRAPH_LC(c) NXIsGraph((unsigned int)(c))
379 # define isPRINT_LC(c) NXIsPrint((unsigned int)(c))
380 # define isPUNCT_LC(c) NXIsPunct((unsigned int)(c))
381 # define toUPPER_LC(c) NXToUpper((unsigned int)(c))
382 # define toLOWER_LC(c) NXToLower((unsigned int)(c))
384 #else /* !USE_NEXT_CTYPE */
386 # if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
388 # define isALNUM_LC(c) (isalnum((unsigned char)(c)) || (char)(c) == '_')
389 # define isIDFIRST_LC(c) (isalpha((unsigned char)(c)) || (char)(c) == '_')
390 # define isALPHA_LC(c) isalpha((unsigned char)(c))
391 # define isSPACE_LC(c) isspace((unsigned char)(c))
392 # define isDIGIT_LC(c) isdigit((unsigned char)(c))
393 # define isUPPER_LC(c) isupper((unsigned char)(c))
394 # define isLOWER_LC(c) islower((unsigned char)(c))
395 # define isALNUMC_LC(c) isalnum((unsigned char)(c))
396 # define isCNTRL_LC(c) iscntrl((unsigned char)(c))
397 # define isGRAPH_LC(c) isgraph((unsigned char)(c))
398 # define isPRINT_LC(c) isprint((unsigned char)(c))
399 # define isPUNCT_LC(c) ispunct((unsigned char)(c))
400 # define toUPPER_LC(c) toupper((unsigned char)(c))
401 # define toLOWER_LC(c) tolower((unsigned char)(c))
405 # define isALNUM_LC(c) (isascii(c) && (isalnum(c) || (c) == '_'))
406 # define isIDFIRST_LC(c) (isascii(c) && (isalpha(c) || (c) == '_'))
407 # define isALPHA_LC(c) (isascii(c) && isalpha(c))
408 # define isSPACE_LC(c) (isascii(c) && isspace(c))
409 # define isDIGIT_LC(c) (isascii(c) && isdigit(c))
410 # define isUPPER_LC(c) (isascii(c) && isupper(c))
411 # define isLOWER_LC(c) (isascii(c) && islower(c))
412 # define isALNUMC_LC(c) (isascii(c) && isalnum(c))
413 # define isCNTRL_LC(c) (isascii(c) && iscntrl(c))
414 # define isGRAPH_LC(c) (isascii(c) && isgraph(c))
415 # define isPRINT_LC(c) (isascii(c) && isprint(c))
416 # define isPUNCT_LC(c) (isascii(c) && ispunct(c))
417 # define toUPPER_LC(c) toupper(c)
418 # define toLOWER_LC(c) tolower(c)
421 #endif /* USE_NEXT_CTYPE */
423 #define isPSXSPC_LC(c) (isSPACE_LC(c) || (c) == '\v')
424 #define isBLANK_LC(c) isBLANK(c) /* could be wrong */
426 #define isALNUM_uni(c) is_uni_alnum(c)
427 #define isIDFIRST_uni(c) is_uni_idfirst(c)
428 #define isALPHA_uni(c) is_uni_alpha(c)
429 #define isSPACE_uni(c) is_uni_space(c)
430 #define isDIGIT_uni(c) is_uni_digit(c)
431 #define isUPPER_uni(c) is_uni_upper(c)
432 #define isLOWER_uni(c) is_uni_lower(c)
433 #define isALNUMC_uni(c) is_uni_alnumc(c)
434 #define isASCII_uni(c) is_uni_ascii(c)
435 #define isCNTRL_uni(c) is_uni_cntrl(c)
436 #define isGRAPH_uni(c) is_uni_graph(c)
437 #define isPRINT_uni(c) is_uni_print(c)
438 #define isPUNCT_uni(c) is_uni_punct(c)
439 #define isXDIGIT_uni(c) is_uni_xdigit(c)
440 #define toUPPER_uni(c,s,l) to_uni_upper(c,s,l)
441 #define toTITLE_uni(c,s,l) to_uni_title(c,s,l)
442 #define toLOWER_uni(c,s,l) to_uni_lower(c,s,l)
443 #define toFOLD_uni(c,s,l) to_uni_fold(c,s,l)
445 #define isPSXSPC_uni(c) (isSPACE_uni(c) ||(c) == '\f')
446 #define isBLANK_uni(c) isBLANK(c) /* could be wrong */
448 #define isALNUM_LC_uvchr(c) (c < 256 ? isALNUM_LC(c) : is_uni_alnum_lc(c))
449 #define isIDFIRST_LC_uvchr(c) (c < 256 ? isIDFIRST_LC(c) : is_uni_idfirst_lc(c))
450 #define isALPHA_LC_uvchr(c) (c < 256 ? isALPHA_LC(c) : is_uni_alpha_lc(c))
451 #define isSPACE_LC_uvchr(c) (c < 256 ? isSPACE_LC(c) : is_uni_space_lc(c))
452 #define isDIGIT_LC_uvchr(c) (c < 256 ? isDIGIT_LC(c) : is_uni_digit_lc(c))
453 #define isUPPER_LC_uvchr(c) (c < 256 ? isUPPER_LC(c) : is_uni_upper_lc(c))
454 #define isLOWER_LC_uvchr(c) (c < 256 ? isLOWER_LC(c) : is_uni_lower_lc(c))
455 #define isALNUMC_LC_uvchr(c) (c < 256 ? isALNUMC_LC(c) : is_uni_alnumc_lc(c))
456 #define isCNTRL_LC_uvchr(c) (c < 256 ? isCNTRL_LC(c) : is_uni_cntrl_lc(c))
457 #define isGRAPH_LC_uvchr(c) (c < 256 ? isGRAPH_LC(c) : is_uni_graph_lc(c))
458 #define isPRINT_LC_uvchr(c) (c < 256 ? isPRINT_LC(c) : is_uni_print_lc(c))
459 #define isPUNCT_LC_uvchr(c) (c < 256 ? isPUNCT_LC(c) : is_uni_punct_lc(c))
461 #define isPSXSPC_LC_uni(c) (isSPACE_LC_uni(c) ||(c) == '\f')
462 #define isBLANK_LC_uni(c) isBLANK(c) /* could be wrong */
464 #define isALNUM_utf8(p) is_utf8_alnum(p)
465 /* The ID_Start of Unicode is quite limiting: it assumes a L-class
466 * character (meaning that you cannot have, say, a CJK character).
467 * Instead, let's allow ID_Continue but not digits. */
468 #define isIDFIRST_utf8(p) (is_utf8_idcont(p) && !is_utf8_digit(p))
469 #define isALPHA_utf8(p) is_utf8_alpha(p)
470 #define isSPACE_utf8(p) is_utf8_space(p)
471 #define isDIGIT_utf8(p) is_utf8_digit(p)
472 #define isUPPER_utf8(p) is_utf8_upper(p)
473 #define isLOWER_utf8(p) is_utf8_lower(p)
474 #define isALNUMC_utf8(p) is_utf8_alnumc(p)
475 #define isASCII_utf8(p) is_utf8_ascii(p)
476 #define isCNTRL_utf8(p) is_utf8_cntrl(p)
477 #define isGRAPH_utf8(p) is_utf8_graph(p)
478 #define isPRINT_utf8(p) is_utf8_print(p)
479 #define isPUNCT_utf8(p) is_utf8_punct(p)
480 #define isXDIGIT_utf8(p) is_utf8_xdigit(p)
481 #define toUPPER_utf8(p,s,l) to_utf8_upper(p,s,l)
482 #define toTITLE_utf8(p,s,l) to_utf8_title(p,s,l)
483 #define toLOWER_utf8(p,s,l) to_utf8_lower(p,s,l)
485 #define isPSXSPC_utf8(c) (isSPACE_utf8(c) ||(c) == '\f')
486 #define isBLANK_utf8(c) isBLANK(c) /* could be wrong */
488 #define isALNUM_LC_utf8(p) isALNUM_LC_uvchr(utf8_to_uvchr(p, 0))
489 #define isIDFIRST_LC_utf8(p) isIDFIRST_LC_uvchr(utf8_to_uvchr(p, 0))
490 #define isALPHA_LC_utf8(p) isALPHA_LC_uvchr(utf8_to_uvchr(p, 0))
491 #define isSPACE_LC_utf8(p) isSPACE_LC_uvchr(utf8_to_uvchr(p, 0))
492 #define isDIGIT_LC_utf8(p) isDIGIT_LC_uvchr(utf8_to_uvchr(p, 0))
493 #define isUPPER_LC_utf8(p) isUPPER_LC_uvchr(utf8_to_uvchr(p, 0))
494 #define isLOWER_LC_utf8(p) isLOWER_LC_uvchr(utf8_to_uvchr(p, 0))
495 #define isALNUMC_LC_utf8(p) isALNUMC_LC_uvchr(utf8_to_uvchr(p, 0))
496 #define isCNTRL_LC_utf8(p) isCNTRL_LC_uvchr(utf8_to_uvchr(p, 0))
497 #define isGRAPH_LC_utf8(p) isGRAPH_LC_uvchr(utf8_to_uvchr(p, 0))
498 #define isPRINT_LC_utf8(p) isPRINT_LC_uvchr(utf8_to_uvchr(p, 0))
499 #define isPUNCT_LC_utf8(p) isPUNCT_LC_uvchr(utf8_to_uvchr(p, 0))
501 #define isPSXSPC_LC_utf8(c) (isSPACE_LC_utf8(c) ||(c) == '\f')
502 #define isBLANK_LC_utf8(c) isBLANK(c) /* could be wrong */
505 # ifdef PERL_IMPLICIT_CONTEXT
506 # define toCTRL(c) Perl_ebcdic_control(aTHX_ c)
508 # define toCTRL Perl_ebcdic_control
511 /* This conversion works both ways, strangely enough. */
512 # define toCTRL(c) (toUPPER(c) ^ 64)
515 /* Line numbers are unsigned, 32 bits. */
518 #define NOLINE ((line_t)0)
520 #define NOLINE ((line_t) 4294967295UL)
525 =head1 SV Manipulation Functions
527 =for apidoc Am|SV*|NEWSV|int id|STRLEN len
528 Creates a new SV. A non-zero C<len> parameter indicates the number of
529 bytes of preallocated string space the SV should have. An extra byte for a
530 tailing NUL is also reserved. (SvPOK is not set for the SV even if string
531 space is allocated.) The reference count for the new SV is set to 1.
532 C<id> is an integer id between 0 and 1299 (used to identify leaks).
534 =head1 Memory Management
536 =for apidoc Am|void|New|int id|void* ptr|int nitems|type
537 The XSUB-writer's interface to the C C<malloc> function.
539 =for apidoc Am|void|Newc|int id|void* ptr|int nitems|type|cast
540 The XSUB-writer's interface to the C C<malloc> function, with
543 =for apidoc Am|void|Newz|int id|void* ptr|int nitems|type
544 The XSUB-writer's interface to the C C<malloc> function. The allocated
545 memory is zeroed with C<memzero>.
547 =for apidoc Am|void|Renew|void* ptr|int nitems|type
548 The XSUB-writer's interface to the C C<realloc> function.
550 =for apidoc Am|void|Renewc|void* ptr|int nitems|type|cast
551 The XSUB-writer's interface to the C C<realloc> function, with
554 =for apidoc Am|void|Safefree|void* ptr
555 The XSUB-writer's interface to the C C<free> function.
557 =for apidoc Am|void|Move|void* src|void* dest|int nitems|type
558 The XSUB-writer's interface to the C C<memmove> 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. Can do overlapping moves. See also C<Copy>.
562 =for apidoc Am|void|Copy|void* src|void* dest|int nitems|type
563 The XSUB-writer's interface to the C C<memcpy> function. The C<src> is the
564 source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
565 the type. May fail on overlapping copies. See also C<Move>.
567 =for apidoc Am|void|Zero|void* dest|int nitems|type
569 The XSUB-writer's interface to the C C<memzero> function. The C<dest> is the
570 destination, C<nitems> is the number of items, and C<type> is the type.
572 =for apidoc Am|void|StructCopy|type src|type dest|type
573 This is an architecture-independent macro to copy one structure to another.
575 =for apidoc Am|void|Poison|void* dest|int nitems|type
577 Fill up memory with a pattern (byte 0xAB over and over again) that
578 hopefully catches attempts to access uninitialized memory.
584 #define NEWSV(x,len) newSV(len)
586 #define New(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n)*sizeof(t))))
587 #define Newc(x,v,n,t,c) (v = (c*)safemalloc((MEM_SIZE)((n)*sizeof(t))))
588 #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n)*sizeof(t)))), \
589 memzero((char*)(v), (n)*sizeof(t))
590 #define Renew(v,n,t) \
591 (v = (t*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))
592 #define Renewc(v,n,t,c) \
593 (v = (c*)saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))
594 #define Safefree(d) safefree((Malloc_t)(d))
596 #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
597 #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
598 #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
600 #define Poison(d,n,t) (void)memset((char*)(d), 0xAB, (n) * sizeof(t))
604 #define New(x,v,n,s) (v = Null(s *))
605 #define Newc(x,v,n,s,c) (v = Null(s *))
606 #define Newz(x,v,n,s) (v = Null(s *))
607 #define Renew(v,n,s) (v = Null(s *))
608 #define Move(s,d,n,t)
609 #define Copy(s,d,n,t)
611 #define Poison(d,n,t)
612 #define Safefree(d) (d) = (d)
616 #ifdef USE_STRUCT_COPY
617 #define StructCopy(s,d,t) (*((t*)(d)) = *((t*)(s)))
619 #define StructCopy(s,d,t) Copy(s,d,1,t)
622 #define C_ARRAY_LENGTH(a) (sizeof(a)/sizeof((a)[0]))
626 # define Perl_va_copy(s, d) va_copy(d, s)
628 # if defined(__va_copy)
629 # define Perl_va_copy(s, d) __va_copy(d, s)
631 # define Perl_va_copy(s, d) Copy(s, d, 1, va_list)