This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regen/mph.pl - Clean up diagnostics logic, allow DEBUG from env.
[perl5.git] / handy.h
1 /*    handy.h
2  *
3  *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000,
4  *    2001, 2002, 2004, 2005, 2006, 2007, 2008, 2012 by Larry Wall and others
5  *
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.
8  *
9  */
10
11 /* IMPORTANT NOTE: Everything whose name begins with an underscore is for
12  * internal core Perl use only. */
13
14 #ifndef PERL_HANDY_H_ /* Guard against nested #inclusion */
15 #define PERL_HANDY_H_
16
17 #ifndef PERL_CORE
18 #  define Null(type) ((type)NULL)
19
20 /*
21 =for apidoc_section $string
22 =for apidoc AmnU||Nullch
23 Null character pointer.  (No longer available when C<PERL_CORE> is
24 defined.)
25
26 =for apidoc_section $SV
27 =for apidoc AmnU||Nullsv
28 Null SV pointer.  (No longer available when C<PERL_CORE> is defined.)
29
30 =cut
31
32 Below are signatures of functions from config.h which can't easily be gleaned
33 from it, and are very unlikely to change
34
35 =for apidoc_section $signals
36 =for apidoc Am|int|Sigsetjmp|jmp_buf env|int savesigs
37 =for apidoc Am|void|Siglongjmp|jmp_buf env|int val
38
39 =for apidoc_section $filesystem
40 =for apidoc Am|void *|FILE_ptr|FILE * f
41 =for apidoc Am|Size_t|FILE_cnt|FILE * f
42 =for apidoc Am|void *|FILE_base|FILE * f
43 =for apidoc Am|Size_t|FILE_bufsiz|FILE *f
44
45 =for apidoc_section $string
46 =for apidoc Amu|token|CAT2|token x|token y
47 =for apidoc Amu|string|STRINGIFY|token x
48
49 =for apidoc_section $numeric
50 =for apidoc Am|double|Drand01
51 =for apidoc Am|void|seedDrand01|Rand_seed_t x
52 =for apidoc Am|char *|Gconvert|double x|Size_t n|bool t|char * b
53
54 =cut
55 */
56
57 #  define Nullch Null(char*)
58 #  define Nullfp Null(PerlIO*)
59 #  define Nullsv Null(SV*)
60 #endif
61
62 #ifdef TRUE
63 #undef TRUE
64 #endif
65 #ifdef FALSE
66 #undef FALSE
67 #endif
68 #define TRUE (1)
69 #define FALSE (0)
70
71 /*
72 =for apidoc_section $SV
73 =for apidoc Am|void *|MUTABLE_PTR|void * p
74 =for apidoc_item |AV *|MUTABLE_AV|AV * p
75 =for apidoc_item |CV *|MUTABLE_CV|CV * p
76 =for apidoc_item |GV *|MUTABLE_GV|GV * p
77 =for apidoc_item |HV *|MUTABLE_HV|HV * p
78 =for apidoc_item |IO *|MUTABLE_IO|IO * p
79 =for apidoc_item |SV *|MUTABLE_SV|SV * p
80
81 The C<MUTABLE_I<*>>() macros cast pointers to the types shown, in such a way
82 (compiler permitting) that casting away const-ness will give a warning;
83 e.g.:
84
85  const SV *sv = ...;
86  AV *av1 = (AV*)sv;        <== BAD:  the const has been silently
87                                      cast away
88  AV *av2 = MUTABLE_AV(sv); <== GOOD: it may warn
89
90 C<MUTABLE_PTR> is the base macro used to derive new casts.  The other
91 already-built-in ones return pointers to what their names indicate.
92
93 =cut
94  */
95
96 #if defined(PERL_USE_GCC_BRACE_GROUPS)
97 #  define MUTABLE_PTR(p) ({ void *p_ = (p); p_; })
98 #else
99 #  define MUTABLE_PTR(p) ((void *) (p))
100 #endif
101
102 #define MUTABLE_AV(p)   ((AV *)MUTABLE_PTR(p))
103 #define MUTABLE_CV(p)   ((CV *)MUTABLE_PTR(p))
104 #define MUTABLE_GV(p)   ((GV *)MUTABLE_PTR(p))
105 #define MUTABLE_HV(p)   ((HV *)MUTABLE_PTR(p))
106 #define MUTABLE_IO(p)   ((IO *)MUTABLE_PTR(p))
107 #define MUTABLE_SV(p)   ((SV *)MUTABLE_PTR(p))
108
109 #ifndef __cplusplus
110 #  include <stdbool.h>
111 #endif
112
113 /*
114 =for apidoc_section $casting
115 =for apidoc Am|bool|cBOOL|bool expr
116
117 Cast-to-bool.  When Perl was able to be compiled on pre-C99 compilers, a
118 C<(bool)> cast didn't necessarily do the right thing, so this macro was
119 created (and made somewhat complicated to work around bugs in old
120 compilers).  Now, many years later, and C99 is used, this is no longer
121 required, but is kept for backwards compatibility.
122
123 =cut
124 */
125 #define cBOOL(cbool) ((bool) (cbool))
126
127 /* Try to figure out __func__ or __FUNCTION__ equivalent, if any.
128  * XXX Should really be a Configure probe, with HAS__FUNCTION__
129  *     and FUNCTION__ as results.
130  * XXX Similarly, a Configure probe for __FILE__ and __LINE__ is needed. */
131 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined(__SUNPRO_C)) /* C99 or close enough. */
132 #  define FUNCTION__ __func__
133 #elif (defined(__DECC_VER)) /* Tru64 or VMS, and strict C89 being used, but not modern enough cc (in Tur64, -c99 not known, only -std1). */
134 #  define FUNCTION__ ""
135 #else
136 #  define FUNCTION__ __FUNCTION__ /* Common extension. */
137 #endif
138
139 /* XXX A note on the perl source internal type system.  The
140    original intent was that I32 be *exactly* 32 bits.
141
142    Currently, we only guarantee that I32 is *at least* 32 bits.
143    Specifically, if int is 64 bits, then so is I32.  (This is the case
144    for the Cray.)  This has the advantage of meshing nicely with
145    standard library calls (where we pass an I32 and the library is
146    expecting an int), but the disadvantage that an I32 is not 32 bits.
147    Andy Dougherty       August 1996
148
149    There is no guarantee that there is *any* integral type with
150    exactly 32 bits.  It is perfectly legal for a system to have
151    sizeof(short) == sizeof(int) == sizeof(long) == 8.
152
153    Similarly, there is no guarantee that I16 and U16 have exactly 16
154    bits.
155
156    For dealing with issues that may arise from various 32/64-bit
157    systems, we will ask Configure to check out
158
159         SHORTSIZE == sizeof(short)
160         INTSIZE == sizeof(int)
161         LONGSIZE == sizeof(long)
162         LONGLONGSIZE == sizeof(long long) (if HAS_LONG_LONG)
163         PTRSIZE == sizeof(void *)
164         DOUBLESIZE == sizeof(double)
165         LONG_DOUBLESIZE == sizeof(long double) (if HAS_LONG_DOUBLE).
166
167 */
168
169 #ifdef I_INTTYPES /* e.g. Linux has int64_t without <inttypes.h> */
170 #   include <inttypes.h>
171 #   ifdef INT32_MIN_BROKEN
172 #       undef  INT32_MIN
173 #       define INT32_MIN (-2147483647-1)
174 #   endif
175 #   ifdef INT64_MIN_BROKEN
176 #       undef  INT64_MIN
177 #       define INT64_MIN (-9223372036854775807LL-1)
178 #   endif
179 #endif
180
181 typedef I8TYPE I8;
182 typedef U8TYPE U8;
183 typedef I16TYPE I16;
184 typedef U16TYPE U16;
185 typedef I32TYPE I32;
186 typedef U32TYPE U32;
187
188 #ifdef QUADKIND
189 typedef I64TYPE I64;
190 typedef U64TYPE U64;
191 #endif
192
193 /* I8_MAX and I8_MIN constants are not defined, as I8 is an ambiguous type.
194    Please search CHAR_MAX in perl.h for further details. */
195 #ifdef UINT8_MAX
196 #  define U8_MAX UINT8_MAX
197 #else
198 #  define U8_MAX PERL_UCHAR_MAX
199 #endif
200 #ifdef UINT8_MIN
201 #  define U8_MIN UINT8_MIN
202 #else
203 #  define U8_MIN PERL_UCHAR_MIN
204 #endif
205
206 #ifdef INT16_MAX
207 #  define I16_MAX INT16_MAX
208 #else
209 #  define I16_MAX PERL_SHORT_MAX
210 #endif
211 #ifdef INT16_MIN
212 #  define I16_MIN INT16_MIN
213 #else
214 #  define I16_MIN PERL_SHORT_MIN
215 #endif
216 #ifdef UINT16_MAX
217 #  define U16_MAX UINT16_MAX
218 #else
219 #  define U16_MAX PERL_USHORT_MAX
220 #endif
221 #ifdef UINT16_MIN
222 #  define U16_MIN UINT16_MIN
223 #else
224 #  define U16_MIN PERL_USHORT_MIN
225 #endif
226
227 #ifdef INT32_MAX
228 #  define I32_MAX INT32_MAX
229 #elif LONGSIZE > 4
230 #  define I32_MAX PERL_INT_MAX
231 #else
232 #  define I32_MAX PERL_LONG_MAX
233 #endif
234 #ifdef INT32_MIN
235 #  define I32_MIN INT32_MIN
236 #elif LONGSIZE > 4
237 #  define I32_MIN PERL_INT_MIN
238 #else
239 #  define I32_MIN PERL_LONG_MIN
240 #endif
241 #ifdef UINT32_MAX
242 #  ifndef UINT32_MAX_BROKEN /* e.g. HP-UX with gcc messes this up */
243 #    define U32_MAX UINT_MAX
244 #  else
245 #    define U32_MAX 4294967295U
246 #  endif
247 #elif LONGSIZE > 4
248 #  define U32_MAX PERL_UINT_MAX
249 #else
250 #  define U32_MAX PERL_ULONG_MAX
251 #endif
252 #ifdef UINT32_MIN
253 #  define U32_MIN UINT32_MIN
254 #elif LONGSIZE > 4
255 #  define U32_MIN PERL_UINT_MIN
256 #else
257 #  define U32_MIN PERL_ULONG_MIN
258 #endif
259
260 /*
261 =for apidoc_section $integer
262 =for apidoc Ay|| PERL_INT_FAST8_T
263 =for apidoc_item PERL_INT_FAST16_T
264 =for apidoc_item PERL_UINT_FAST8_T
265 =for apidoc_item PERL_UINT_FAST16_T
266
267 These are equivalent to the correspondingly-named C99 typedefs on platforms
268 that have those; they evaluate to C<int> and C<unsigned int> on platforms that
269 don't, so that you can portably take advantage of this C99 feature.
270
271 =cut
272 */
273 #  ifdef I_STDINT
274     typedef  int_fast8_t  PERL_INT_FAST8_T;
275     typedef uint_fast8_t  PERL_UINT_FAST8_T;
276     typedef  int_fast16_t PERL_INT_FAST16_T;
277     typedef uint_fast16_t PERL_UINT_FAST16_T;
278 #  else
279     typedef int           PERL_INT_FAST8_T;
280     typedef unsigned int  PERL_UINT_FAST8_T;
281     typedef int           PERL_INT_FAST16_T;
282     typedef unsigned int  PERL_UINT_FAST16_T;
283 #  endif
284
285 /* log(2) (i.e., log base 10 of 2) is pretty close to 0.30103, just in case
286  * anyone is grepping for it.  So BIT_DIGITS gives the number of decimal digits
287  * required to represent any possible unsigned number containing N bits.
288  * TYPE_DIGITS gives the number of decimal digits required to represent any
289  * possible unsigned number of type T. */
290 #define BIT_DIGITS(N)   (((N)*146)/485 + 1)  /* log10(2) =~ 146/485 */
291 #define TYPE_DIGITS(T)  BIT_DIGITS(sizeof(T) * 8)
292 #define TYPE_CHARS(T)   (TYPE_DIGITS(T) + 2) /* sign, NUL */
293
294 /* Unused by core; should be deprecated */
295 #define Ctl(ch) ((ch) & 037)
296
297 #if defined(PERL_CORE) || defined(PERL_EXT)
298 #  ifndef MIN
299 #    define MIN(a,b) ((a) < (b) ? (a) : (b))
300 #  endif
301 #  ifndef MAX
302 #    define MAX(a,b) ((a) > (b) ? (a) : (b))
303 #  endif
304 #endif
305
306 /* Returns a boolean as to whether the input unsigned number is a power of 2
307  * (2**0, 2**1, etc).  In other words if it has just a single bit set.
308  * If not, subtracting 1 would leave the uppermost bit set, so the & would
309  * yield non-zero */
310 #if defined(PERL_CORE) || defined(PERL_EXT)
311 #  define isPOWER_OF_2(n) ((n) && ((n) & ((n)-1)) == 0)
312 #endif
313
314 /* Returns a mask with the lowest n bits set */
315 #define nBIT_MASK(n) ((UINTMAX_C(1) << (n)) - 1)
316
317 /* The largest unsigned number that will fit into n bits */
318 #define nBIT_UMAX(n)  nBIT_MASK(n)
319
320 /*
321 =for apidoc_section $directives
322 =for apidoc Am||__ASSERT_|bool expr
323
324 This is a helper macro to avoid preprocessor issues, replaced by nothing
325 unless under DEBUGGING, where it expands to an assert of its argument,
326 followed by a comma (hence the comma operator).  If we just used a straight
327 assert(), we would get a comma with nothing before it when not DEBUGGING.
328
329 =cut
330
331 We also use empty definition under Coverity since the __ASSERT_
332 checks often check for things that Really Cannot Happen, and Coverity
333 detects that and gets all excited. */
334
335 #if   defined(DEBUGGING) && !defined(__COVERITY__)                        \
336  && ! defined(PERL_SMALL_MACRO_BUFFER)
337 #   define __ASSERT_(statement)  assert(statement),
338 #else
339 #   define __ASSERT_(statement)
340 #endif
341
342 /*
343 =for apidoc_section $SV
344
345 =for apidoc Ama|SV*|newSVpvs|"literal string"
346 Like C<newSVpvn>, but takes a literal string instead of a
347 string/length pair.
348
349 =for apidoc Ama|SV*|newSVpvs_flags|"literal string"|U32 flags
350 Like C<newSVpvn_flags>, but takes a literal string instead of
351 a string/length pair.
352
353 =for apidoc Ama|SV*|newSVpvs_share|"literal string"
354 Like C<newSVpvn_share>, but takes a literal string instead of
355 a string/length pair and omits the hash parameter.
356
357 =for apidoc Am|void|sv_catpvs_flags|SV* sv|"literal string"|I32 flags
358 Like C<sv_catpvn_flags>, but takes a literal string instead
359 of a string/length pair.
360
361 =for apidoc Am|void|sv_catpvs_nomg|SV* sv|"literal string"
362 Like C<sv_catpvn_nomg>, but takes a literal string instead of
363 a string/length pair.
364
365 =for apidoc Am|void|sv_catpvs|SV* sv|"literal string"
366 Like C<sv_catpvn>, but takes a literal string instead of a
367 string/length pair.
368
369 =for apidoc Am|void|sv_catpvs_mg|SV* sv|"literal string"
370 Like C<sv_catpvn_mg>, but takes a literal string instead of a
371 string/length pair.
372
373 =for apidoc Am|void|sv_setpvs|SV* sv|"literal string"
374 Like C<sv_setpvn>, but takes a literal string instead of a
375 string/length pair.
376
377 =for apidoc Am|void|sv_setpvs_mg|SV* sv|"literal string"
378 Like C<sv_setpvn_mg>, but takes a literal string instead of a
379 string/length pair.
380
381 =for apidoc Am|SV *|sv_setref_pvs|SV *const rv|const char *const classname|"literal string"
382 Like C<sv_setref_pvn>, but takes a literal string instead of
383 a string/length pair.
384
385 =for apidoc_section $string
386
387 =for apidoc Ama|char*|savepvs|"literal string"
388 Like C<savepvn>, but takes a literal string instead of a
389 string/length pair.
390
391 =for apidoc Ama|char*|savesharedpvs|"literal string"
392 A version of C<savepvs()> which allocates the duplicate string in memory
393 which is shared between threads.
394
395 =for apidoc_section $GV
396
397 =for apidoc Am|HV*|gv_stashpvs|"name"|I32 create
398 Like C<gv_stashpvn>, but takes a literal string instead of a
399 string/length pair.
400
401 =for apidoc_section $HV
402
403 =for apidoc Am|SV**|hv_fetchs|HV* tb|"key"|I32 lval
404 Like C<hv_fetch>, but takes a literal string instead of a
405 string/length pair.
406
407 =for apidoc Am|SV**|hv_stores|HV* tb|"key"|SV* val
408 Like C<hv_store>, but takes a literal string instead of a
409 string/length pair
410 and omits the hash parameter.
411
412 =for apidoc_section $lexer
413
414 =for apidoc Amx|void|lex_stuff_pvs|"pv"|U32 flags
415
416 Like L</lex_stuff_pvn>, but takes a literal string instead of
417 a string/length pair.
418
419 =cut
420 */
421
422 #define ASSERT_IS_LITERAL(s) ("" s "")
423
424 /*
425 =for apidoc_section $string
426
427 =for apidoc Amu|pair|STR_WITH_LEN|"literal string"
428
429 Returns two comma separated tokens of the input literal string, and its length.
430 This is convenience macro which helps out in some API calls.
431 Note that it can't be used as an argument to macros or functions that under
432 some configurations might be macros, which means that it requires the full
433 Perl_xxx(aTHX_ ...) form for any API calls where it's used.
434
435 =cut
436 */
437
438 #define STR_WITH_LEN(s)  ASSERT_IS_LITERAL(s), (sizeof(s)-1)
439
440 /* STR_WITH_LEN() shortcuts */
441 #define newSVpvs(str) Perl_newSVpvn(aTHX_ STR_WITH_LEN(str))
442 #define newSVpvs_flags(str,flags)       \
443     Perl_newSVpvn_flags(aTHX_ STR_WITH_LEN(str), flags)
444 #define newSVpvs_share(str) Perl_newSVpvn_share(aTHX_ STR_WITH_LEN(str), 0)
445 #define sv_catpvs_flags(sv, str, flags) \
446     Perl_sv_catpvn_flags(aTHX_ sv, STR_WITH_LEN(str), flags)
447 #define sv_catpvs_nomg(sv, str) \
448     Perl_sv_catpvn_flags(aTHX_ sv, STR_WITH_LEN(str), 0)
449 #define sv_catpvs(sv, str) \
450     Perl_sv_catpvn_flags(aTHX_ sv, STR_WITH_LEN(str), SV_GMAGIC)
451 #define sv_catpvs_mg(sv, str) \
452     Perl_sv_catpvn_flags(aTHX_ sv, STR_WITH_LEN(str), SV_GMAGIC|SV_SMAGIC)
453 #define sv_setpvs(sv, str) Perl_sv_setpvn(aTHX_ sv, STR_WITH_LEN(str))
454 #define sv_setpvs_mg(sv, str) Perl_sv_setpvn_mg(aTHX_ sv, STR_WITH_LEN(str))
455 #define sv_setref_pvs(rv, classname, str) \
456     Perl_sv_setref_pvn(aTHX_ rv, classname, STR_WITH_LEN(str))
457 #define savepvs(str) Perl_savepvn(aTHX_ STR_WITH_LEN(str))
458 #define savesharedpvs(str) Perl_savesharedpvn(aTHX_ STR_WITH_LEN(str))
459 #define gv_stashpvs(str, create) \
460     Perl_gv_stashpvn(aTHX_ STR_WITH_LEN(str), create)
461
462 #define gv_fetchpvs(namebeg, flags, sv_type) \
463     Perl_gv_fetchpvn_flags(aTHX_ STR_WITH_LEN(namebeg), flags, sv_type)
464 #define  gv_fetchpvn  gv_fetchpvn_flags
465 #define sv_catxmlpvs(dsv, str, utf8) \
466     Perl_sv_catxmlpvn(aTHX_ dsv, STR_WITH_LEN(str), utf8)
467
468
469 #define lex_stuff_pvs(pv,flags) Perl_lex_stuff_pvn(aTHX_ STR_WITH_LEN(pv), flags)
470
471 #define get_cvs(str, flags)                                     \
472         Perl_get_cvn_flags(aTHX_ STR_WITH_LEN(str), (flags))
473
474 /* internal helpers */
475 /* Transitional */
476 #ifndef PERL_VERSION_MAJOR
477 #  define PERL_VERSION_MAJOR  PERL_REVISION
478 #else
479 #  undef  PERL_REVISION     /* We don't want code to be using these */
480 #endif
481 #ifndef PERL_VERSION_MINOR
482 #  define PERL_VERSION_MINOR  PERL_VERSION
483 #else
484 #  undef  PERL_VERSION
485 #endif
486 #ifndef PERL_VERSION_PATCH
487 #  define PERL_VERSION_PATCH  PERL_SUBVERSION
488 #else
489 #  undef  PERL_SUBVERSION
490 #endif
491
492 #define PERL_JNP_TO_DECIMAL_(maJor,miNor,Patch)                             \
493             /* '10*' leaves room for things like alpha, beta, releases */   \
494                     (10 * ((maJor) * 1000000) + ((miNor) * 1000) + (Patch))
495 #define PERL_DECIMAL_VERSION_                                               \
496         PERL_JNP_TO_DECIMAL_(PERL_VERSION_MAJOR, PERL_VERSION_MINOR,        \
497                                                         PERL_VERSION_PATCH)
498
499 /*
500 =for apidoc_section $versioning
501 =for apidoc AmR|bool|PERL_VERSION_EQ|const U8 major|const U8 minor|const U8 patch
502 =for apidoc_item PERL_VERSION_NE
503 =for apidoc_item PERL_VERSION_LT
504 =for apidoc_item PERL_VERSION_LE
505 =for apidoc_item PERL_VERSION_GT
506 =for apidoc_item PERL_VERSION_GE
507
508 Returns whether or not the perl currently being compiled has the specified
509 relationship to the perl given by the parameters.  For example,
510
511  #if PERL_VERSION_GT(5,24,2)
512    code that will only be compiled on perls after v5.24.2
513  #else
514    fallback code
515  #endif
516
517 Note that this is usable in making compile-time decisions
518
519 You may use the special value '*' for the final number to mean ALL possible
520 values for it.  Thus,
521
522  #if PERL_VERSION_EQ(5,31,'*')
523
524 means all perls in the 5.31 series.  And
525
526  #if PERL_VERSION_NE(5,24,'*')
527
528 means all perls EXCEPT 5.24 ones.  And
529
530  #if PERL_VERSION_LE(5,9,'*')
531
532 is effectively
533
534  #if PERL_VERSION_LT(5,10,0)
535
536 This means you don't have to think so much when converting from the existing
537 deprecated C<PERL_VERSION> to using this macro:
538
539  #if PERL_VERSION <= 9
540
541 becomes
542
543  #if PERL_VERSION_LE(5,9,'*')
544
545 =cut
546 */
547
548 /* N.B. These don't work if the patch version is 42 or 92, as those are what
549  * '*' is in ASCII and EBCDIC respectively */
550 # define PERL_VERSION_EQ(j,n,p)                                             \
551               (((p) == '*')                                                 \
552                ? (   (j) == PERL_VERSION_MAJOR                              \
553                   && (n) == PERL_VERSION_MINOR)                             \
554                : (PERL_DECIMAL_VERSION_ == PERL_JNP_TO_DECIMAL_(j,n,p)))
555 # define PERL_VERSION_NE(j,n,p) (! PERL_VERSION_EQ(j,n,p))
556
557 # define PERL_VERSION_LT(j,n,p) /* < '*' effectively means < 0 */           \
558     (PERL_DECIMAL_VERSION_ < PERL_JNP_TO_DECIMAL_( (j),                     \
559                                                    (n),                     \
560                                                  (((p) == '*') ? 0 : p)))
561 # define PERL_VERSION_GE(j,n,p)  (! PERL_VERSION_LT(j,n,p))
562
563 # define PERL_VERSION_LE(j,n,p)  /* <= '*' effectively means < n+1 */       \
564     (PERL_DECIMAL_VERSION_ < PERL_JNP_TO_DECIMAL_(                  (j),    \
565                                           (((p) == '*') ? ((n)+1) : (n)),   \
566                                           (((p) == '*') ? 0 : p)))
567 # define PERL_VERSION_GT(j,n,p) (! PERL_VERSION_LE(j,n,p))
568
569 /*
570 =for apidoc_section $string
571
572 =for apidoc Am|bool|strNE|char* s1|char* s2
573 Test two C<NUL>-terminated strings to see if they are different.  Returns true
574 or false.
575
576 =for apidoc Am|bool|strEQ|char* s1|char* s2
577 Test two C<NUL>-terminated strings to see if they are equal.  Returns true or
578 false.
579
580 =for apidoc Am|bool|strLT|char* s1|char* s2
581 Test two C<NUL>-terminated strings to see if the first, C<s1>, is less than the
582 second, C<s2>.  Returns true or false.
583
584 =for apidoc Am|bool|strLE|char* s1|char* s2
585 Test two C<NUL>-terminated strings to see if the first, C<s1>, is less than or
586 equal to the second, C<s2>.  Returns true or false.
587
588 =for apidoc Am|bool|strGT|char* s1|char* s2
589 Test two C<NUL>-terminated strings to see if the first, C<s1>, is greater than
590 the second, C<s2>.  Returns true or false.
591
592 =for apidoc Am|bool|strGE|char* s1|char* s2
593 Test two C<NUL>-terminated strings to see if the first, C<s1>, is greater than
594 or equal to the second, C<s2>.  Returns true or false.
595
596 =for apidoc Am|bool|strnNE|char* s1|char* s2|STRLEN len
597 Test two C<NUL>-terminated strings to see if they are different.  The C<len>
598 parameter indicates the number of bytes to compare.  Returns true or false.  (A
599 wrapper for C<strncmp>).
600
601 =for apidoc Am|bool|strnEQ|char* s1|char* s2|STRLEN len
602 Test two C<NUL>-terminated strings to see if they are equal.  The C<len>
603 parameter indicates the number of bytes to compare.  Returns true or false.  (A
604 wrapper for C<strncmp>).
605
606 =for apidoc Am|bool|memEQ|char* s1|char* s2|STRLEN len
607 Test two buffers (which may contain embedded C<NUL> characters, to see if they
608 are equal.  The C<len> parameter indicates the number of bytes to compare.
609 Returns true or false.  It is undefined behavior if either of the buffers
610 doesn't contain at least C<len> bytes.
611
612 =for apidoc Am|bool|memEQs|char* s1|STRLEN l1|"s2"
613 Like L</memEQ>, but the second string is a literal enclosed in double quotes,
614 C<l1> gives the number of bytes in C<s1>.
615 Returns true or false.
616
617 =for apidoc Am|bool|memNE|char* s1|char* s2|STRLEN len
618 Test two buffers (which may contain embedded C<NUL> characters, to see if they
619 are not equal.  The C<len> parameter indicates the number of bytes to compare.
620 Returns true or false.  It is undefined behavior if either of the buffers
621 doesn't contain at least C<len> bytes.
622
623 =for apidoc Am|bool|memNEs|char* s1|STRLEN l1|"s2"
624 Like L</memNE>, but the second string is a literal enclosed in double quotes,
625 C<l1> gives the number of bytes in C<s1>.
626 Returns true or false.
627
628 =for apidoc Am|bool|memCHRs|"list"|char c
629 Returns the position of the first occurence of the byte C<c> in the literal
630 string C<"list">, or NULL if C<c> doesn't appear in C<"list">.  All bytes are
631 treated as unsigned char.  Thus this macro can be used to determine if C<c> is
632 in a set of particular characters.  Unlike L<strchr(3)>, it works even if C<c>
633 is C<NUL> (and the set doesn't include C<NUL>).
634
635 =cut
636
637 New macros should use the following conventions for their names (which are
638 based on the underlying C library functions):
639
640   (mem | str n? ) (EQ | NE | LT | GT | GE | (( BEGIN | END ) P? )) l? s?
641
642   Each has two main parameters, string-like operands that are compared
643   against each other, as specified by the macro name.  Some macros may
644   additionally have one or potentially even two length parameters.  If a length
645   parameter applies to both string parameters, it will be positioned third;
646   otherwise any length parameter immediately follows the string parameter it
647   applies to.
648
649   If the prefix to the name is 'str', the string parameter is a pointer to a C
650   language string.  Such a string does not contain embedded NUL bytes; its
651   length may be unknown, but can be calculated by C<strlen()>, since it is
652   terminated by a NUL, which isn't included in its length.
653
654   The optional 'n' following 'str' means that there is a third parameter,
655   giving the maximum number of bytes to look at in each string.  Even if both
656   strings are longer than the length parameter, those extra bytes will be
657   unexamined.
658
659   The 's' suffix means that the 2nd byte string parameter is a literal C
660   double-quoted string.  Its length will automatically be calculated by the
661   macro, so no length parameter will ever be needed for it.
662
663   If the prefix is 'mem', the string parameters don't have to be C strings;
664   they may contain embedded NUL bytes, do not necessarily have a terminating
665   NUL, and their lengths can be known only through other means, which in
666   practice are additional parameter(s) passed to the function.  All 'mem'
667   functions have at least one length parameter.  Barring any 'l' or 's' suffix,
668   there is a single length parameter, in position 3, which applies to both
669   string parameters.  The 's' suffix means, as described above, that the 2nd
670   string is a literal double-quoted C string (hence its length is calculated by
671   the macro, and the length parameter to the function applies just to the first
672   string parameter, and hence is positioned just after it).  An 'l' suffix
673   means that the 2nd string parameter has its own length parameter, and the
674   signature will look like memFOOl(s1, l1, s2, l2).
675
676   BEGIN (and END) are for testing if the 2nd string is an initial (or final)
677   substring  of the 1st string.  'P' if present indicates that the substring
678   must be a "proper" one in tha mathematical sense that the first one must be
679   strictly larger than the 2nd.
680
681 */
682
683
684 #define strNE(s1,s2) (strcmp(s1,s2) != 0)
685 #define strEQ(s1,s2) (strcmp(s1,s2) == 0)
686 #define strLT(s1,s2) (strcmp(s1,s2) < 0)
687 #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
688 #define strGT(s1,s2) (strcmp(s1,s2) > 0)
689 #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
690
691 #define strnNE(s1,s2,l) (strncmp(s1,s2,l) != 0)
692 #define strnEQ(s1,s2,l) (strncmp(s1,s2,l) == 0)
693
694 #define memEQ(s1,s2,l) (memcmp(((const void *) (s1)), ((const void *) (s2)), l) == 0)
695 #define memNE(s1,s2,l) (! memEQ(s1,s2,l))
696
697 /* memEQ and memNE where second comparand is a string constant */
698 #define memEQs(s1, l, s2) \
699         (((sizeof(s2)-1) == (l)) && memEQ((s1), ASSERT_IS_LITERAL(s2), (sizeof(s2)-1)))
700 #define memNEs(s1, l, s2) (! memEQs(s1, l, s2))
701
702 /* Keep these private until we decide it was a good idea */
703 #if defined(PERL_CORE) || defined(PERL_EXT) || defined(PERL_EXT_POSIX)
704
705 #define strBEGINs(s1,s2) (strncmp(s1,ASSERT_IS_LITERAL(s2), sizeof(s2)-1) == 0)
706
707 #define memBEGINs(s1, l, s2)                                                \
708             (   (Ptrdiff_t) (l) >= (Ptrdiff_t) sizeof(s2) - 1               \
709              && memEQ(s1, ASSERT_IS_LITERAL(s2), sizeof(s2)-1))
710 #define memBEGINPs(s1, l, s2)                                               \
711             (   (Ptrdiff_t) (l) > (Ptrdiff_t) sizeof(s2) - 1                \
712              && memEQ(s1, ASSERT_IS_LITERAL(s2), sizeof(s2)-1))
713 #define memENDs(s1, l, s2)                                                  \
714             (   (Ptrdiff_t) (l) >= (Ptrdiff_t) sizeof(s2) - 1               \
715              && memEQ(s1 + (l) - (sizeof(s2) - 1), ASSERT_IS_LITERAL(s2), sizeof(s2)-1))
716 #define memENDPs(s1, l, s2)                                                 \
717             (   (Ptrdiff_t) (l) > (Ptrdiff_t) sizeof(s2)                    \
718              && memEQ(s1 + (l) - (sizeof(s2) - 1), ASSERT_IS_LITERAL(s2), sizeof(s2)-1))
719 #endif  /* End of making macros private */
720
721 #define memLT(s1,s2,l) (memcmp(s1,s2,l) < 0)
722 #define memLE(s1,s2,l) (memcmp(s1,s2,l) <= 0)
723 #define memGT(s1,s2,l) (memcmp(s1,s2,l) > 0)
724 #define memGE(s1,s2,l) (memcmp(s1,s2,l) >= 0)
725
726 #define memCHRs(s1,c) ((const char *) memchr(ASSERT_IS_LITERAL(s1) , c, sizeof(s1)-1))
727
728 /*
729  * Character classes.
730  *
731  * Unfortunately, the introduction of locales means that we
732  * can't trust isupper(), etc. to tell the truth.  And when
733  * it comes to /\w+/ with tainting enabled, we *must* be able
734  * to trust our character classes.
735  *
736  * Therefore, the default tests in the text of Perl will be
737  * independent of locale.  Any code that wants to depend on
738  * the current locale will use the tests that begin with "lc".
739  */
740
741 #ifdef USE_LOCALE
742 #  ifndef CTYPE256
743 #    define CTYPE256
744 #  endif
745 #endif
746
747 /*
748
749 =head1 Character classification
750 This section is about functions (really macros) that classify characters
751 into types, such as punctuation versus alphabetic, etc.  Most of these are
752 analogous to regular expression character classes.  (See
753 L<perlrecharclass/POSIX Character Classes>.)  There are several variants for
754 each class.  (Not all macros have all variants; each item below lists the
755 ones valid for it.)  None are affected by C<use bytes>, and only the ones
756 with C<LC> in the name are affected by the current locale.
757
758 The base function, e.g., C<isALPHA()>, takes any signed or unsigned value,
759 treating it as a code point, and returns a boolean as to whether or not the
760 character represented by it is (or on non-ASCII platforms, corresponds to) an
761 ASCII character in the named class based on platform, Unicode, and Perl rules.
762 If the input is a number that doesn't fit in an octet, FALSE is returned.
763
764 Variant C<isI<FOO>_A> (e.g., C<isALPHA_A()>) is identical to the base function
765 with no suffix C<"_A">.  This variant is used to emphasize by its name that
766 only ASCII-range characters can return TRUE.
767
768 Variant C<isI<FOO>_L1> imposes the Latin-1 (or EBCDIC equivalent) character set
769 onto the platform.  That is, the code points that are ASCII are unaffected,
770 since ASCII is a subset of Latin-1.  But the non-ASCII code points are treated
771 as if they are Latin-1 characters.  For example, C<isWORDCHAR_L1()> will return
772 true when called with the code point 0xDF, which is a word character in both
773 ASCII and EBCDIC (though it represents different characters in each).
774 If the input is a number that doesn't fit in an octet, FALSE is returned.
775 (Perl's documentation uses a colloquial definition of Latin-1, to include all
776 code points below 256.)
777
778 Variant C<isI<FOO>_uvchr> is exactly like the C<isI<FOO>_L1> variant, for
779 inputs below 256, but if the code point is larger than 255, Unicode rules are
780 used to determine if it is in the character class.  For example,
781 C<isWORDCHAR_uvchr(0x100)> returns TRUE, since 0x100 is LATIN CAPITAL LETTER A
782 WITH MACRON in Unicode, and is a word character.
783
784 Variants C<isI<FOO>_utf8> and C<isI<FOO>_utf8_safe> are like C<isI<FOO>_uvchr>,
785 but are used for UTF-8 encoded strings.  The two forms are different names for
786 the same thing.  Each call to one of these classifies the first character of
787 the string starting at C<p>.  The second parameter, C<e>, points to anywhere in
788 the string beyond the first character, up to one byte past the end of the
789 entire string.  Although both variants are identical, the suffix C<_safe> in
790 one name emphasizes that it will not attempt to read beyond S<C<e - 1>>,
791 provided that the constraint S<C<s E<lt> e>> is true (this is asserted for in
792 C<-DDEBUGGING> builds).  If the UTF-8 for the input character is malformed in
793 some way, the program may croak, or the function may return FALSE, at the
794 discretion of the implementation, and subject to change in future releases.
795
796 Variant C<isI<FOO>_LC> is like the C<isI<FOO>_A> and C<isI<FOO>_L1> variants,
797 but the result is based on the current locale, which is what C<LC> in the name
798 stands for.  If Perl can determine that the current locale is a UTF-8 locale,
799 it uses the published Unicode rules; otherwise, it uses the C library function
800 that gives the named classification.  For example, C<isDIGIT_LC()> when not in
801 a UTF-8 locale returns the result of calling C<isdigit()>.  FALSE is always
802 returned if the input won't fit into an octet.  On some platforms where the C
803 library function is known to be defective, Perl changes its result to follow
804 the POSIX standard's rules.
805
806 Variant C<isI<FOO>_LC_uvchr> acts exactly like C<isI<FOO>_LC> for inputs less
807 than 256, but for larger ones it returns the Unicode classification of the code
808 point.
809
810 Variants C<isI<FOO>_LC_utf8> and C<isI<FOO>_LC_utf8_safe> are like
811 C<isI<FOO>_LC_uvchr>, but are used for UTF-8 encoded strings.  The two forms
812 are different names for the same thing.  Each call to one of these classifies
813 the first character of the string starting at C<p>.  The second parameter,
814 C<e>, points to anywhere in the string beyond the first character, up to one
815 byte past the end of the entire string.  Although both variants are identical,
816 the suffix C<_safe> in one name emphasizes that it will not attempt to read
817 beyond S<C<e - 1>>, provided that the constraint S<C<s E<lt> e>> is true (this
818 is asserted for in C<-DDEBUGGING> builds).  If the UTF-8 for the input
819 character is malformed in some way, the program may croak, or the function may
820 return FALSE, at the discretion of the implementation, and subject to change in
821 future releases.
822
823 =for apidoc Am|bool|isALPHA|UV ch
824 =for apidoc_item ||isALPHA_A|UV ch
825 =for apidoc_item ||isALPHA_L1|UV ch
826 =for apidoc_item ||isALPHA_uvchr|UV ch
827 =for apidoc_item ||isALPHA_utf8_safe|U8 * s|U8 * end
828 =for apidoc_item ||isALPHA_utf8|U8 * s|U8 * end
829 =for apidoc_item ||isALPHA_LC|UV ch
830 =for apidoc_item ||isALPHA_LC_uvchr|UV ch
831 =for apidoc_item ||isALPHA_LC_utf8_safe|U8 * s| U8 *end
832 Returns a boolean indicating whether the specified input is one of C<[A-Za-z]>,
833 analogous to C<m/[[:alpha:]]/>.
834 See the L<top of this section|/Character classification> for an explanation of
835 the variants.
836
837 =cut
838
839 Here and below, we add the prototypes of these macros for downstream programs
840 that would be interested in them, such as Devel::PPPort
841
842 =for apidoc Am|bool|isALPHANUMERIC|UV ch
843 =for apidoc_item ||isALPHANUMERIC_A|UV ch
844 =for apidoc_item ||isALPHANUMERIC_L1|UV ch
845 =for apidoc_item ||isALPHANUMERIC_uvchr|UV ch
846 =for apidoc_item ||isALPHANUMERIC_utf8_safe|U8 * s|U8 * end
847 =for apidoc_item ||isALPHANUMERIC_utf8|U8 * s|U8 * end
848 =for apidoc_item ||isALPHANUMERIC_LC|UV ch
849 =for apidoc_item ||isALPHANUMERIC_LC_uvchr|UV ch
850 =for apidoc_item ||isALPHANUMERIC_LC_utf8_safe|U8 * s| U8 *end
851 =for apidoc_item ||isALNUMC|UV ch
852 =for apidoc_item ||isALNUMC_A|UV ch
853 =for apidoc_item ||isALNUMC_L1|UV ch
854 =for apidoc_item ||isALNUMC_LC|UV ch
855 =for apidoc_item ||isALNUMC_LC_uvchr|UV ch
856 Returns a boolean indicating whether the specified character is one of
857 C<[A-Za-z0-9]>, analogous to C<m/[[:alnum:]]/>.
858 See the L<top of this section|/Character classification> for an explanation of
859 the variants.
860
861 A (discouraged from use) synonym is C<isALNUMC> (where the C<C> suffix means
862 this corresponds to the C language alphanumeric definition).  Also
863 there are the variants
864 C<isALNUMC_A>, C<isALNUMC_L1>
865 C<isALNUMC_LC>, and C<isALNUMC_LC_uvchr>.
866
867 =for apidoc Am|bool|isASCII|UV ch
868 =for apidoc_item ||isASCII_A|UV ch
869 =for apidoc_item ||isASCII_L1|UV ch
870 =for apidoc_item ||isASCII_uvchr|UV ch
871 =for apidoc_item ||isASCII_utf8_safe|U8 * s|U8 * end
872 =for apidoc_item ||isASCII_utf8|U8 * s|U8 * end
873 =for apidoc_item ||isASCII_LC|UV ch
874 =for apidoc_item ||isASCII_LC_uvchr|UV ch
875 =for apidoc_item ||isASCII_LC_utf8_safe|U8 * s| U8 *end
876 Returns a boolean indicating whether the specified character is one of the 128
877 characters in the ASCII character set, analogous to C<m/[[:ascii:]]/>.
878 On non-ASCII platforms, it returns TRUE iff this
879 character corresponds to an ASCII character.  Variants C<isASCII_A()> and
880 C<isASCII_L1()> are identical to C<isASCII()>.
881 See the L<top of this section|/Character classification> for an explanation of
882 the variants.
883 Note, however, that some platforms do not have the C library routine
884 C<isascii()>.  In these cases, the variants whose names contain C<LC> are the
885 same as the corresponding ones without.
886
887 Also note, that because all ASCII characters are UTF-8 invariant (meaning they
888 have the exact same representation (always a single byte) whether encoded in
889 UTF-8 or not), C<isASCII> will give the correct results when called with any
890 byte in any string encoded or not in UTF-8.  And similarly C<isASCII_utf8> and
891 C<isASCII_utf8_safe> will work properly on any string encoded or not in UTF-8.
892
893 =for apidoc Am|bool|isBLANK|UV ch
894 =for apidoc_item ||isBLANK_A|UV ch
895 =for apidoc_item ||isBLANK_L1|UV ch
896 =for apidoc_item ||isBLANK_uvchr|UV ch
897 =for apidoc_item ||isBLANK_utf8_safe|U8 * s|U8 * end
898 =for apidoc_item ||isBLANK_utf8|U8 * s|U8 * end
899 =for apidoc_item ||isBLANK_LC|UV ch
900 =for apidoc_item ||isBLANK_LC_uvchr|UV ch
901 =for apidoc_item ||isBLANK_LC_utf8_safe|U8 * s| U8 *end
902 Returns a boolean indicating whether the specified character is a
903 character considered to be a blank, analogous to C<m/[[:blank:]]/>.
904 See the L<top of this section|/Character classification> for an explanation of
905 the variants.
906 Note,
907 however, that some platforms do not have the C library routine
908 C<isblank()>.  In these cases, the variants whose names contain C<LC> are
909 the same as the corresponding ones without.
910
911 =for apidoc Am|bool|isCNTRL|UV ch
912 =for apidoc_item ||isCNTRL_A|UV ch
913 =for apidoc_item ||isCNTRL_L1|UV ch
914 =for apidoc_item ||isCNTRL_uvchr|UV ch
915 =for apidoc_item ||isCNTRL_utf8_safe|U8 * s|U8 * end
916 =for apidoc_item ||isCNTRL_utf8|U8 * s|U8 * end
917 =for apidoc_item ||isCNTRL_LC|UV ch
918 =for apidoc_item ||isCNTRL_LC_uvchr|UV ch
919 =for apidoc_item ||isCNTRL_LC_utf8_safe|U8 * s| U8 *end
920
921 Returns a boolean indicating whether the specified character is a
922 control character, analogous to C<m/[[:cntrl:]]/>.
923 See the L<top of this section|/Character classification> for an explanation of
924 the variants.
925 On EBCDIC platforms, you almost always want to use the C<isCNTRL_L1> variant.
926
927 =for apidoc Am|bool|isDIGIT|UV ch
928 =for apidoc_item ||isDIGIT_A|UV ch
929 =for apidoc_item ||isDIGIT_L1|UV ch
930 =for apidoc_item ||isDIGIT_uvchr|UV ch
931 =for apidoc_item ||isDIGIT_utf8_safe|U8 * s|U8 * end
932 =for apidoc_item ||isDIGIT_utf8|U8 * s|U8 * end
933 =for apidoc_item ||isDIGIT_LC|UV ch
934 =for apidoc_item ||isDIGIT_LC_uvchr|UV ch
935 =for apidoc_item ||isDIGIT_LC_utf8_safe|U8 * s| U8 *end
936
937 Returns a boolean indicating whether the specified character is a
938 digit, analogous to C<m/[[:digit:]]/>.
939 Variants C<isDIGIT_A> and C<isDIGIT_L1> are identical to C<isDIGIT>.
940 See the L<top of this section|/Character classification> for an explanation of
941 the variants.
942
943 =for apidoc Am|bool|isGRAPH|UV ch
944 =for apidoc_item ||isGRAPH_A|UV ch
945 =for apidoc_item ||isGRAPH_L1|UV ch
946 =for apidoc_item ||isGRAPH_uvchr|UV ch
947 =for apidoc_item ||isGRAPH_utf8_safe|U8 * s|U8 * end
948 =for apidoc_item ||isGRAPH_utf8|U8 * s|U8 * end
949 =for apidoc_item ||isGRAPH_LC|UV ch
950 =for apidoc_item ||isGRAPH_LC_uvchr|UV ch
951 =for apidoc_item ||isGRAPH_LC_utf8_safe|U8 * s| U8 *end
952 Returns a boolean indicating whether the specified character is a
953 graphic character, analogous to C<m/[[:graph:]]/>.
954 See the L<top of this section|/Character classification> for an explanation of
955 the variants.
956
957 =for apidoc Am|bool|isLOWER|UV ch
958 =for apidoc_item ||isLOWER_A|UV ch
959 =for apidoc_item ||isLOWER_L1|UV ch
960 =for apidoc_item ||isLOWER_uvchr|UV ch
961 =for apidoc_item ||isLOWER_utf8_safe|U8 * s|U8 * end
962 =for apidoc_item ||isLOWER_utf8|U8 * s|U8 * end
963 =for apidoc_item ||isLOWER_LC|UV ch
964 =for apidoc_item ||isLOWER_LC_uvchr|UV ch
965 =for apidoc_item ||isLOWER_LC_utf8_safe|U8 * s| U8 *end
966 Returns a boolean indicating whether the specified character is a
967 lowercase character, analogous to C<m/[[:lower:]]/>.
968 See the L<top of this section|/Character classification> for an explanation of
969 the variants
970
971 =for apidoc Am|bool|isOCTAL|UV ch
972 =for apidoc_item ||isOCTAL_A|UV ch
973 =for apidoc_item ||isOCTAL_L1|UV ch
974 Returns a boolean indicating whether the specified character is an
975 octal digit, [0-7].
976 The only two variants are C<isOCTAL_A> and C<isOCTAL_L1>; each is identical to
977 C<isOCTAL>.
978
979 =for apidoc Am|bool|isPUNCT|UV ch
980 =for apidoc_item ||isPUNCT_A|UV ch
981 =for apidoc_item ||isPUNCT_L1|UV ch
982 =for apidoc_item ||isPUNCT_uvchr|UV ch
983 =for apidoc_item ||isPUNCT_utf8_safe|U8 * s|U8 * end
984 =for apidoc_item ||isPUNCT_utf8|U8 * s|U8 * end
985 =for apidoc_item ||isPUNCT_LC|UV ch
986 =for apidoc_item ||isPUNCT_LC_uvchr|UV ch
987 =for apidoc_item ||isPUNCT_LC_utf8_safe|U8 * s| U8 *end
988 Returns a boolean indicating whether the specified character is a
989 punctuation character, analogous to C<m/[[:punct:]]/>.
990 Note that the definition of what is punctuation isn't as
991 straightforward as one might desire.  See L<perlrecharclass/POSIX Character
992 Classes> for details.
993 See the L<top of this section|/Character classification> for an explanation of
994 the variants.
995
996 =for apidoc Am|bool|isSPACE|UV ch
997 =for apidoc_item ||isSPACE_A|UV ch
998 =for apidoc_item ||isSPACE_L1|UV ch
999 =for apidoc_item ||isSPACE_uvchr|UV ch
1000 =for apidoc_item ||isSPACE_utf8_safe|U8 * s|U8 * end
1001 =for apidoc_item ||isSPACE_utf8|U8 * s|U8 * end
1002 =for apidoc_item ||isSPACE_LC|UV ch
1003 =for apidoc_item ||isSPACE_LC_uvchr|UV ch
1004 =for apidoc_item ||isSPACE_LC_utf8_safe|U8 * s| U8 *end
1005 Returns a boolean indicating whether the specified character is a
1006 whitespace character.  This is analogous
1007 to what C<m/\s/> matches in a regular expression.  Starting in Perl 5.18
1008 this also matches what C<m/[[:space:]]/> does.  Prior to 5.18, only the
1009 locale forms of this macro (the ones with C<LC> in their names) matched
1010 precisely what C<m/[[:space:]]/> does.  In those releases, the only difference,
1011 in the non-locale variants, was that C<isSPACE()> did not match a vertical tab.
1012 (See L</isPSXSPC> for a macro that matches a vertical tab in all releases.)
1013 See the L<top of this section|/Character classification> for an explanation of
1014 the variants.
1015
1016 =for apidoc Am|bool|isPSXSPC|UV ch
1017 =for apidoc_item ||isPSXSPC_A|UV ch
1018 =for apidoc_item ||isPSXSPC_L1|UV ch
1019 =for apidoc_item ||isPSXSPC_uvchr|UV ch
1020 =for apidoc_item ||isPSXSPC_utf8_safe|U8 * s|U8 * end
1021 =for apidoc_item ||isPSXSPC_utf8|U8 * s|U8 * end
1022 =for apidoc_item ||isPSXSPC_LC|UV ch
1023 =for apidoc_item ||isPSXSPC_LC_uvchr|UV ch
1024 =for apidoc_item ||isPSXSPC_LC_utf8_safe|U8 * s| U8 *end
1025 (short for Posix Space)
1026 Starting in 5.18, this is identical in all its forms to the
1027 corresponding C<isSPACE()> macros.
1028 The locale forms of this macro are identical to their corresponding
1029 C<isSPACE()> forms in all Perl releases.  In releases prior to 5.18, the
1030 non-locale forms differ from their C<isSPACE()> forms only in that the
1031 C<isSPACE()> forms don't match a Vertical Tab, and the C<isPSXSPC()> forms do.
1032 Otherwise they are identical.  Thus this macro is analogous to what
1033 C<m/[[:space:]]/> matches in a regular expression.
1034 See the L<top of this section|/Character classification> for an explanation of
1035 the variants.
1036
1037 =for apidoc Am|bool|isUPPER|UV ch
1038 =for apidoc_item ||isUPPER_A|UV ch
1039 =for apidoc_item ||isUPPER_L1|UV ch
1040 =for apidoc_item ||isUPPER_uvchr|UV ch
1041 =for apidoc_item ||isUPPER_utf8_safe|U8 * s|U8 * end
1042 =for apidoc_item ||isUPPER_utf8|U8 * s|U8 * end
1043 =for apidoc_item ||isUPPER_LC|UV ch
1044 =for apidoc_item ||isUPPER_LC_uvchr|UV ch
1045 =for apidoc_item ||isUPPER_LC_utf8_safe|U8 * s| U8 *end
1046 Returns a boolean indicating whether the specified character is an
1047 uppercase character, analogous to C<m/[[:upper:]]/>.
1048 See the L<top of this section|/Character classification> for an explanation of
1049 the variants.
1050
1051 =for apidoc Am|bool|isPRINT|UV ch
1052 =for apidoc_item ||isPRINT_A|UV ch
1053 =for apidoc_item ||isPRINT_L1|UV ch
1054 =for apidoc_item ||isPRINT_uvchr|UV ch
1055 =for apidoc_item ||isPRINT_utf8_safe|U8 * s|U8 * end
1056 =for apidoc_item ||isPRINT_utf8|U8 * s|U8 * end
1057 =for apidoc_item ||isPRINT_LC|UV ch
1058 =for apidoc_item ||isPRINT_LC_uvchr|UV ch
1059 =for apidoc_item ||isPRINT_LC_utf8_safe|U8 * s| U8 *end
1060 Returns a boolean indicating whether the specified character is a
1061 printable character, analogous to C<m/[[:print:]]/>.
1062 See the L<top of this section|/Character classification> for an explanation of
1063 the variants.
1064
1065 =for apidoc Am|bool|isWORDCHAR|UV ch
1066 =for apidoc_item ||isWORDCHAR_A|UV ch
1067 =for apidoc_item ||isWORDCHAR_L1|UV ch
1068 =for apidoc_item ||isWORDCHAR_uvchr|UV ch
1069 =for apidoc_item ||isWORDCHAR_utf8_safe|U8 * s|U8 * end
1070 =for apidoc_item ||isWORDCHAR_utf8|U8 * s|U8 * end
1071 =for apidoc_item ||isWORDCHAR_LC|UV ch
1072 =for apidoc_item ||isWORDCHAR_LC_uvchr|UV ch
1073 =for apidoc_item ||isWORDCHAR_LC_utf8_safe|U8 * s| U8 *end
1074 =for apidoc_item ||isALNUM|UV ch
1075 =for apidoc_item ||isALNUM_A|UV ch
1076 =for apidoc_item ||isALNUM_LC|UV ch
1077 =for apidoc_item ||isALNUM_LC_uvchr|UV ch
1078 Returns a boolean indicating whether the specified character is a character
1079 that is a word character, analogous to what C<m/\w/> and C<m/[[:word:]]/> match
1080 in a regular expression.  A word character is an alphabetic character, a
1081 decimal digit, a connecting punctuation character (such as an underscore), or
1082 a "mark" character that attaches to one of those (like some sort of accent).
1083 C<isALNUM()> is a synonym provided for backward compatibility, even though a
1084 word character includes more than the standard C language meaning of
1085 alphanumeric.
1086 See the L<top of this section|/Character classification> for an explanation of
1087 the variants.
1088 C<isWORDCHAR_A>, C<isWORDCHAR_L1>, C<isWORDCHAR_uvchr>,
1089 C<isWORDCHAR_LC>, C<isWORDCHAR_LC_uvchr>, C<isWORDCHAR_LC_utf8>, and
1090 C<isWORDCHAR_LC_utf8_safe> are also as described there, but additionally
1091 include the platform's native underscore.
1092
1093 =for apidoc Am|bool|isXDIGIT|UV ch
1094 =for apidoc_item ||isXDIGIT_A|UV ch
1095 =for apidoc_item ||isXDIGIT_L1|UV ch
1096 =for apidoc_item ||isXDIGIT_uvchr|UV ch
1097 =for apidoc_item ||isXDIGIT_utf8_safe|U8 * s|U8 * end
1098 =for apidoc_item ||isXDIGIT_utf8|U8 * s|U8 * end
1099 =for apidoc_item ||isXDIGIT_LC|UV ch
1100 =for apidoc_item ||isXDIGIT_LC_uvchr|UV ch
1101 =for apidoc_item ||isXDIGIT_LC_utf8_safe|U8 * s| U8 *end
1102 Returns a boolean indicating whether the specified character is a hexadecimal
1103 digit.  In the ASCII range these are C<[0-9A-Fa-f]>.  Variants C<isXDIGIT_A()>
1104 and C<isXDIGIT_L1()> are identical to C<isXDIGIT()>.
1105 See the L<top of this section|/Character classification> for an explanation of
1106 the variants.
1107
1108 =for apidoc Am|bool|isIDFIRST|UV ch
1109 =for apidoc_item ||isIDFIRST_A|UV ch
1110 =for apidoc_item ||isIDFIRST_L1|UV ch
1111 =for apidoc_item ||isIDFIRST_uvchr|UV ch
1112 =for apidoc_item ||isIDFIRST_utf8_safe|U8 * s|U8 * end
1113 =for apidoc_item ||isIDFIRST_utf8|U8 * s|U8 * end
1114 =for apidoc_item ||isIDFIRST_LC|UV ch
1115 =for apidoc_item ||isIDFIRST_LC_uvchr|UV ch
1116 =for apidoc_item ||isIDFIRST_LC_utf8_safe|U8 * s| U8 *end
1117 Returns a boolean indicating whether the specified character can be the first
1118 character of an identifier.  This is very close to, but not quite the same as
1119 the official Unicode property C<XID_Start>.  The difference is that this
1120 returns true only if the input character also matches L</isWORDCHAR>.
1121 See the L<top of this section|/Character classification> for an explanation of
1122 the variants.
1123
1124 =for apidoc Am|bool|isIDCONT|UV ch
1125 =for apidoc_item ||isIDCONT_A|UV ch
1126 =for apidoc_item ||isIDCONT_L1|UV ch
1127 =for apidoc_item ||isIDCONT_uvchr|UV ch
1128 =for apidoc_item ||isIDCONT_utf8_safe|U8 * s|U8 * end
1129 =for apidoc_item ||isIDCONT_utf8|U8 * s|U8 * end
1130 =for apidoc_item ||isIDCONT_LC|UV ch
1131 =for apidoc_item ||isIDCONT_LC_uvchr|UV ch
1132 =for apidoc_item ||isIDCONT_LC_utf8_safe|U8 * s| U8 *end
1133 Returns a boolean indicating whether the specified character can be the
1134 second or succeeding character of an identifier.  This is very close to, but
1135 not quite the same as the official Unicode property C<XID_Continue>.  The
1136 difference is that this returns true only if the input character also matches
1137 L</isWORDCHAR>.  See the L<top of this section|/Character classification> for
1138 an explanation of the variants.
1139
1140 =for apidoc_section $numeric
1141
1142 =for apidoc Am|U8|READ_XDIGIT|char str*
1143 Returns the value of an ASCII-range hex digit and advances the string pointer.
1144 Behaviour is only well defined when isXDIGIT(*str) is true.
1145
1146 =head1 Character case changing
1147 Perl uses "full" Unicode case mappings.  This means that converting a single
1148 character to another case may result in a sequence of more than one character.
1149 For example, the uppercase of C<E<223>> (LATIN SMALL LETTER SHARP S) is the two
1150 character sequence C<SS>.  This presents some complications   The lowercase of
1151 all characters in the range 0..255 is a single character, and thus
1152 C<L</toLOWER_L1>> is furnished.  But, C<toUPPER_L1> can't exist, as it couldn't
1153 return a valid result for all legal inputs.  Instead C<L</toUPPER_uvchr>> has
1154 an API that does allow every possible legal result to be returned.)  Likewise
1155 no other function that is crippled by not being able to give the correct
1156 results for the full range of possible inputs has been implemented here.
1157
1158 =for apidoc Am|UV|toUPPER|UV cp
1159 =for apidoc_item |UV|toUPPER_A|UV cp
1160 =for apidoc_item |UV|toUPPER_uvchr|UV cp|U8* s|STRLEN* lenp
1161 =for apidoc_item |UV|toUPPER_utf8|U8* p|U8* e|U8* s|STRLEN* lenp
1162 =for apidoc_item |UV|toUPPER_utf8_safe|U8* p|U8* e|U8* s|STRLEN* lenp
1163
1164 These all return the uppercase of a character.  The differences are what domain
1165 they operate on, and whether the input is specified as a code point (those
1166 forms with a C<cp> parameter) or as a UTF-8 string (the others).  In the latter
1167 case, the code point to use is the first one in the buffer of UTF-8 encoded
1168 code points, delineated by the arguments S<C<p .. e - 1>>.
1169
1170 C<toUPPER> and C<toUPPER_A> are synonyms of each other.  They return the
1171 uppercase of any lowercase ASCII-range code point.  All other inputs are
1172 returned unchanged.  Since these are macros, the input type may be any integral
1173 one, and the output will occupy the same number of bits as the input.
1174
1175 There is no C<toUPPER_L1> nor C<toUPPER_LATIN1> as the uppercase of some code
1176 points in the 0..255 range is above that range or consists of multiple
1177 characters.  Instead use C<toUPPER_uvchr>.
1178
1179 C<toUPPER_uvchr> returns the uppercase of any Unicode code point.  The return
1180 value is identical to that of C<toUPPER_A> for input code points in the ASCII
1181 range.  The uppercase of the vast majority of Unicode code points is the same
1182 as the code point itself.  For these, and for code points above the legal
1183 Unicode maximum, this returns the input code point unchanged.  It additionally
1184 stores the UTF-8 of the result into the buffer beginning at C<s>, and its
1185 length in bytes into C<*lenp>.  The caller must have made C<s> large enough to
1186 contain at least C<UTF8_MAXBYTES_CASE+1> bytes to avoid possible overflow.
1187
1188 NOTE: the uppercase of a code point may be more than one code point.  The
1189 return value of this function is only the first of these.  The entire uppercase
1190 is returned in C<s>.  To determine if the result is more than a single code
1191 point, you can do something like this:
1192
1193  uc = toUPPER_uvchr(cp, s, &len);
1194  if (len > UTF8SKIP(s)) { is multiple code points }
1195  else { is a single code point }
1196
1197 C<toUPPER_utf8> and C<toUPPER_utf8_safe> are synonyms of each other.  The only
1198 difference between these and C<toUPPER_uvchr> is that the source for these is
1199 encoded in UTF-8, instead of being a code point.  It is passed as a buffer
1200 starting at C<p>, with C<e> pointing to one byte beyond its end.  The C<p>
1201 buffer may certainly contain more than one code point; but only the first one
1202 (up through S<C<e - 1>>) is examined.  If the UTF-8 for the input character is
1203 malformed in some way, the program may croak, or the function may return the
1204 REPLACEMENT CHARACTER, at the discretion of the implementation, and subject to
1205 change in future releases.
1206
1207 =for apidoc Am|UV|toFOLD|UV cp
1208 =for apidoc_item |UV|toFOLD_A|UV cp
1209 =for apidoc_item |UV|toFOLD_uvchr|UV cp|U8* s|STRLEN* lenp
1210 =for apidoc_item |UV|toFOLD_utf8|U8* p|U8* e|U8* s|STRLEN* lenp
1211 =for apidoc_item |UV|toFOLD_utf8_safe|U8* p|U8* e|U8* s|STRLEN* lenp
1212
1213 These all return the foldcase of a character.  "foldcase" is an internal case
1214 for C</i> pattern matching. If the foldcase of character A and the foldcase of
1215 character B are the same, they match caselessly; otherwise they don't.
1216
1217 The differences in the forms are what domain they operate on, and whether the
1218 input is specified as a code point (those forms with a C<cp> parameter) or as a
1219 UTF-8 string (the others).  In the latter case, the code point to use is the
1220 first one in the buffer of UTF-8 encoded code points, delineated by the
1221 arguments S<C<p .. e - 1>>.
1222
1223 C<toFOLD> and C<toFOLD_A> are synonyms of each other.  They return the
1224 foldcase of any ASCII-range code point.  In this range, the foldcase is
1225 identical to the lowercase.  All other inputs are returned unchanged.  Since
1226 these are macros, the input type may be any integral one, and the output will
1227 occupy the same number of bits as the input.
1228
1229 There is no C<toFOLD_L1> nor C<toFOLD_LATIN1> as the foldcase of some code
1230 points in the 0..255 range is above that range or consists of multiple
1231 characters.  Instead use C<toFOLD_uvchr>.
1232
1233 C<toFOLD_uvchr> returns the foldcase of any Unicode code point.  The return
1234 value is identical to that of C<toFOLD_A> for input code points in the ASCII
1235 range.  The foldcase of the vast majority of Unicode code points is the same
1236 as the code point itself.  For these, and for code points above the legal
1237 Unicode maximum, this returns the input code point unchanged.  It additionally
1238 stores the UTF-8 of the result into the buffer beginning at C<s>, and its
1239 length in bytes into C<*lenp>.  The caller must have made C<s> large enough to
1240 contain at least C<UTF8_MAXBYTES_CASE+1> bytes to avoid possible overflow.
1241
1242 NOTE: the foldcase of a code point may be more than one code point.  The
1243 return value of this function is only the first of these.  The entire foldcase
1244 is returned in C<s>.  To determine if the result is more than a single code
1245 point, you can do something like this:
1246
1247  uc = toFOLD_uvchr(cp, s, &len);
1248  if (len > UTF8SKIP(s)) { is multiple code points }
1249  else { is a single code point }
1250
1251 C<toFOLD_utf8> and C<toFOLD_utf8_safe> are synonyms of each other.  The only
1252 difference between these and C<toFOLD_uvchr> is that the source for these is
1253 encoded in UTF-8, instead of being a code point.  It is passed as a buffer
1254 starting at C<p>, with C<e> pointing to one byte beyond its end.  The C<p>
1255 buffer may certainly contain more than one code point; but only the first one
1256 (up through S<C<e - 1>>) is examined.  If the UTF-8 for the input character is
1257 malformed in some way, the program may croak, or the function may return the
1258 REPLACEMENT CHARACTER, at the discretion of the implementation, and subject to
1259 change in future releases.
1260
1261 =for apidoc Am|UV|toLOWER|UV cp
1262 =for apidoc_item |UV|toLOWER_A|UV cp
1263 =for apidoc_item |UV|toLOWER_L1|UV cp
1264 =for apidoc_item |UV|toLOWER_LATIN1|UV cp
1265 =for apidoc_item |UV|toLOWER_LC|UV cp
1266 =for apidoc_item |UV|toLOWER_uvchr|UV cp|U8* s|STRLEN* lenp
1267 =for apidoc_item |UV|toLOWER_utf8|U8* p|U8* e|U8* s|STRLEN* lenp
1268 =for apidoc_item |UV|toLOWER_utf8_safe|U8* p|U8* e|U8* s|STRLEN* lenp
1269
1270 These all return the lowercase of a character.  The differences are what domain
1271 they operate on, and whether the input is specified as a code point (those
1272 forms with a C<cp> parameter) or as a UTF-8 string (the others).  In the latter
1273 case, the code point to use is the first one in the buffer of UTF-8 encoded
1274 code points, delineated by the arguments S<C<p .. e - 1>>.
1275
1276 C<toLOWER> and C<toLOWER_A> are synonyms of each other.  They return the
1277 lowercase of any uppercase ASCII-range code point.  All other inputs are
1278 returned unchanged.  Since these are macros, the input type may be any integral
1279 one, and the output will occupy the same number of bits as the input.
1280
1281 C<toLOWER_L1> and C<toLOWER_LATIN1> are synonyms of each other.  They behave
1282 identically as C<toLOWER> for ASCII-range input.  But additionally will return
1283 the lowercase of any uppercase code point in the entire 0..255 range, assuming
1284 a Latin-1 encoding (or the EBCDIC equivalent on such platforms).
1285
1286 C<toLOWER_LC> returns the lowercase of the input code point according to the
1287 rules of the current POSIX locale.  Input code points outside the range 0..255
1288 are returned unchanged.
1289
1290 C<toLOWER_uvchr> returns the lowercase of any Unicode code point.  The return
1291 value is identical to that of C<toLOWER_L1> for input code points in the 0..255
1292 range.  The lowercase of the vast majority of Unicode code points is the same
1293 as the code point itself.  For these, and for code points above the legal
1294 Unicode maximum, this returns the input code point unchanged.  It additionally
1295 stores the UTF-8 of the result into the buffer beginning at C<s>, and its
1296 length in bytes into C<*lenp>.  The caller must have made C<s> large enough to
1297 contain at least C<UTF8_MAXBYTES_CASE+1> bytes to avoid possible overflow.
1298
1299 NOTE: the lowercase of a code point may be more than one code point.  The
1300 return value of this function is only the first of these.  The entire lowercase
1301 is returned in C<s>.  To determine if the result is more than a single code
1302 point, you can do something like this:
1303
1304  uc = toLOWER_uvchr(cp, s, &len);
1305  if (len > UTF8SKIP(s)) { is multiple code points }
1306  else { is a single code point }
1307
1308 C<toLOWER_utf8> and C<toLOWER_utf8_safe> are synonyms of each other.  The only
1309 difference between these and C<toLOWER_uvchr> is that the source for these is
1310 encoded in UTF-8, instead of being a code point.  It is passed as a buffer
1311 starting at C<p>, with C<e> pointing to one byte beyond its end.  The C<p>
1312 buffer may certainly contain more than one code point; but only the first one
1313 (up through S<C<e - 1>>) is examined.  If the UTF-8 for the input character is
1314 malformed in some way, the program may croak, or the function may return the
1315 REPLACEMENT CHARACTER, at the discretion of the implementation, and subject to
1316 change in future releases.
1317
1318 =for apidoc Am|UV|toTITLE|UV cp
1319 =for apidoc_item |UV|toTITLE_A|UV cp
1320 =for apidoc_item |UV|toTITLE_uvchr|UV cp|U8* s|STRLEN* lenp
1321 =for apidoc_item |UV|toTITLE_utf8|U8* p|U8* e|U8* s|STRLEN* lenp
1322 =for apidoc_item |UV|toTITLE_utf8_safe|U8* p|U8* e|U8* s|STRLEN* lenp
1323
1324 These all return the titlecase of a character.  The differences are what domain
1325 they operate on, and whether the input is specified as a code point (those
1326 forms with a C<cp> parameter) or as a UTF-8 string (the others).  In the latter
1327 case, the code point to use is the first one in the buffer of UTF-8 encoded
1328 code points, delineated by the arguments S<C<p .. e - 1>>.
1329
1330 C<toTITLE> and C<toTITLE_A> are synonyms of each other.  They return the
1331 titlecase of any lowercase ASCII-range code point.  In this range, the
1332 titlecase is identical to the uppercase.  All other inputs are returned
1333 unchanged.  Since these are macros, the input type may be any integral one, and
1334 the output will occupy the same number of bits as the input.
1335
1336 There is no C<toTITLE_L1> nor C<toTITLE_LATIN1> as the titlecase of some code
1337 points in the 0..255 range is above that range or consists of multiple
1338 characters.  Instead use C<toTITLE_uvchr>.
1339
1340 C<toTITLE_uvchr> returns the titlecase of any Unicode code point.  The return
1341 value is identical to that of C<toTITLE_A> for input code points in the ASCII
1342 range.  The titlecase of the vast majority of Unicode code points is the same
1343 as the code point itself.  For these, and for code points above the legal
1344 Unicode maximum, this returns the input code point unchanged.  It additionally
1345 stores the UTF-8 of the result into the buffer beginning at C<s>, and its
1346 length in bytes into C<*lenp>.  The caller must have made C<s> large enough to
1347 contain at least C<UTF8_MAXBYTES_CASE+1> bytes to avoid possible overflow.
1348
1349 NOTE: the titlecase of a code point may be more than one code point.  The
1350 return value of this function is only the first of these.  The entire titlecase
1351 is returned in C<s>.  To determine if the result is more than a single code
1352 point, you can do something like this:
1353
1354  uc = toTITLE_uvchr(cp, s, &len);
1355  if (len > UTF8SKIP(s)) { is multiple code points }
1356  else { is a single code point }
1357
1358 C<toTITLE_utf8> and C<toTITLE_utf8_safe> are synonyms of each other.  The only
1359 difference between these and C<toTITLE_uvchr> is that the source for these is
1360 encoded in UTF-8, instead of being a code point.  It is passed as a buffer
1361 starting at C<p>, with C<e> pointing to one byte beyond its end.  The C<p>
1362 buffer may certainly contain more than one code point; but only the first one
1363 (up through S<C<e - 1>>) is examined.  If the UTF-8 for the input character is
1364 malformed in some way, the program may croak, or the function may return the
1365 REPLACEMENT CHARACTER, at the discretion of the implementation, and subject to
1366 change in future releases.
1367
1368 =cut
1369
1370 XXX Still undocumented isVERTWS_uvchr and _utf8; it's unclear what their names
1371 really should be.  Also toUPPER_LC and toFOLD_LC, which are subject to change,
1372 and aren't general purpose as they don't work on U+DF, and assert against that.
1373
1374 Note that these macros are repeated in Devel::PPPort, so should also be
1375 patched there.  The file as of this writing is cpan/Devel-PPPort/parts/inc/misc
1376
1377 */
1378
1379 /*
1380    void below because that's the best fit, and works for Devel::PPPort
1381 =for apidoc_section $integer
1382 =for apidoc AyT||WIDEST_UTYPE
1383
1384 Yields the widest unsigned integer type on the platform, currently either
1385 C<U32> or C<U64>.  This can be used in declarations such as
1386
1387  WIDEST_UTYPE my_uv;
1388
1389 or casts
1390
1391  my_uv = (WIDEST_UTYPE) val;
1392
1393 =cut
1394
1395 */
1396 #ifdef QUADKIND
1397 #   define WIDEST_UTYPE U64
1398 #else
1399 #   define WIDEST_UTYPE U32
1400 #endif
1401
1402 /* Where there could be some confusion, use this as a static assert in macros
1403  * to make sure that a parameter isn't a pointer.  But some compilers can't
1404  * handle this.  The only one known so far that doesn't is gcc 3.3.6; the check
1405  * below isn't thorough for such an old compiler, so may have to be revised if
1406  * experience so dictates. */
1407 #if  ! PERL_IS_GCC || PERL_GCC_VERSION_GT(3,3,6)
1408 #  define ASSERT_NOT_PTR(x) ((x) | 0)
1409 #else
1410 #  define ASSERT_NOT_PTR(x) (x)
1411 #endif
1412
1413 /* Likewise, this is effectively a static assert to be used to guarantee the
1414  * parameter is a pointer */
1415 #define ASSERT_IS_PTR(x) (__ASSERT_(sizeof(*(x))) (x))
1416
1417 /* FITS_IN_8_BITS(c) returns true if c doesn't have  a bit set other than in
1418  * the lower 8.  It is designed to be hopefully bomb-proof, making sure that no
1419  * bits of information are lost even on a 64-bit machine, but to get the
1420  * compiler to optimize it out if possible.  This is because Configure makes
1421  * sure that the machine has an 8-bit byte, so if c is stored in a byte, the
1422  * sizeof() guarantees that this evaluates to a constant true at compile time.
1423  *
1424  * For Coverity, be always true, because otherwise Coverity thinks
1425  * it finds several expressions that are always true, independent
1426  * of operands.  Well, they are, but that is kind of the point.
1427  */
1428 #ifndef __COVERITY__
1429   /* The '| 0' part in ASSERT_NOT_PTR ensures a compiler error if c is not
1430    * integer (like e.g., a pointer) */
1431 #  define FITS_IN_8_BITS(c) (   (sizeof(c) == 1)                            \
1432                              || (((WIDEST_UTYPE) ASSERT_NOT_PTR(c)) >> 8) == 0)
1433 #else
1434 #  define FITS_IN_8_BITS(c) (1)
1435 #endif
1436
1437 /* Returns true if l <= c <= (l + n), where 'l' and 'n' are non-negative
1438  * Written this way so that after optimization, only one conditional test is
1439  * needed.  (The NV casts stop any warnings about comparison always being true
1440  * if called with an unsigned.  The cast preserves the sign, which is all we
1441  * care about.) */
1442 #define withinCOUNT(c, l, n)  (__ASSERT_((NV) (l) >= 0)                 \
1443                                __ASSERT_((NV) (n) >= 0)                 \
1444                                withinCOUNT_KNOWN_VALID_((c), (l), (n)))
1445
1446 /* For internal use only, this can be used in places where it is known that the
1447  * parameters to withinCOUNT() are valid, to avoid the asserts.  For example,
1448  * inRANGE() below, calls this several times, but does all the necessary
1449  * asserts itself, once.  The reason that this is necessary is that the
1450  * duplicate asserts were exceeding the internal limits of some compilers */
1451 #define withinCOUNT_KNOWN_VALID_(c, l, n)                                   \
1452     ((((WIDEST_UTYPE) (c)) - ASSERT_NOT_PTR(l))                             \
1453                                    <= ((WIDEST_UTYPE) ASSERT_NOT_PTR(n)))
1454
1455 /* Returns true if c is in the range l..u, where 'l' is non-negative
1456  * Written this way so that after optimization, only one conditional test is
1457  * needed. */
1458 #define inRANGE(c, l, u) (__ASSERT_((NV) (l) >= 0) __ASSERT_((u) >= (l))    \
1459    (  (sizeof(c) == sizeof(U8))  ? inRANGE_helper_(U8, (c), (l), ((u)))     \
1460     : (sizeof(c) == sizeof(U16)) ? inRANGE_helper_(U16,(c), (l), ((u)))     \
1461     : (sizeof(c) == sizeof(U32)) ? inRANGE_helper_(U32,(c), (l), ((u)))     \
1462              : (__ASSERT_(sizeof(c) == sizeof(WIDEST_UTYPE))                \
1463                           inRANGE_helper_(WIDEST_UTYPE,(c), (l), ((u))))))
1464
1465 /* For internal use, this is used by machine-generated code which generates
1466  * known valid calls, with a known sizeof().  This avoids the extra code and
1467  * asserts that were exceeding internal limits of some compilers. */
1468 #define inRANGE_helper_(cast, c, l, u)                                      \
1469                     withinCOUNT_KNOWN_VALID_(((cast) (c)), (l), ((u) - (l)))
1470
1471 #ifdef EBCDIC
1472 #   ifndef _ALL_SOURCE
1473         /* The native libc isascii() et.al. functions return the wrong results
1474          * on at least z/OS unless this is defined. */
1475 #       error   _ALL_SOURCE should probably be defined
1476 #   endif
1477 #else
1478     /* There is a simple definition of ASCII for ASCII platforms.  But the
1479      * EBCDIC one isn't so simple, so is defined using table look-up like the
1480      * other macros below.
1481      *
1482      * The cast here is used instead of '(c) >= 0', because some compilers emit
1483      * a warning that that test is always true when the parameter is an
1484      * unsigned type.  khw supposes that it could be written as
1485      *      && ((c) == '\0' || (c) > 0)
1486      * to avoid the message, but the cast will likely avoid extra branches even
1487      * with stupid compilers. */
1488 #   define isASCII(c)    (((WIDEST_UTYPE) ASSERT_NOT_PTR(c)) < 128)
1489 #endif
1490
1491 /* Take the eight possible bit patterns of the lower 3 bits and you get the
1492  * lower 3 bits of the 8 octal digits, in both ASCII and EBCDIC, so those bits
1493  * can be ignored.  If the rest match '0', we have an octal */
1494 #define isOCTAL_A(c)  ((((WIDEST_UTYPE) ASSERT_NOT_PTR(c)) & ~7) == '0')
1495
1496 #ifdef H_PERL       /* If have access to perl.h, lookup in its table */
1497
1498 /* Character class numbers.  For internal core Perl use only.  The ones less
1499  * than 32 are used in PL_charclass[] and the ones up through the one that
1500  * corresponds to <_HIGHEST_REGCOMP_DOT_H_SYNC> are used by regcomp.h and
1501  * related files.  PL_charclass ones use names used in l1_char_class_tab.h but
1502  * their actual definitions are here.  If that file has a name not used here,
1503  * it won't compile.
1504  *
1505  * The first group of these is ordered in what I (khw) estimate to be the
1506  * frequency of their use.  This gives a slight edge to exiting a loop earlier
1507  * (in reginclass() in regexec.c).  Except \v should be last, as it isn't a
1508  * real Posix character class, and some (small) inefficiencies in regular
1509  * expression handling would be introduced by putting it in the middle of those
1510  * that are.  Also, cntrl and ascii come after the others as it may be useful
1511  * to group these which have no members that match above Latin1, (or above
1512  * ASCII in the latter case) */
1513
1514 #  define _CC_WORDCHAR           0      /* \w and [:word:] */
1515 #  define _CC_DIGIT              1      /* \d and [:digit:] */
1516 #  define _CC_ALPHA              2      /* [:alpha:] */
1517 #  define _CC_LOWER              3      /* [:lower:] */
1518 #  define _CC_UPPER              4      /* [:upper:] */
1519 #  define _CC_PUNCT              5      /* [:punct:] */
1520 #  define _CC_PRINT              6      /* [:print:] */
1521 #  define _CC_ALPHANUMERIC       7      /* [:alnum:] */
1522 #  define _CC_GRAPH              8      /* [:graph:] */
1523 #  define _CC_CASED              9      /* [:lower:] or [:upper:] under /i */
1524 #  define _CC_SPACE             10      /* \s, [:space:] */
1525 #  define _CC_BLANK             11      /* [:blank:] */
1526 #  define _CC_XDIGIT            12      /* [:xdigit:] */
1527 #  define _CC_CNTRL             13      /* [:cntrl:] */
1528 #  define _CC_ASCII             14      /* [:ascii:] */
1529 #  define _CC_VERTSPACE         15      /* \v */
1530
1531 #  define _HIGHEST_REGCOMP_DOT_H_SYNC _CC_VERTSPACE
1532
1533 /* The members of the third group below do not need to be coordinated with data
1534  * structures in regcomp.[ch] and regexec.c. */
1535 #  define _CC_IDFIRST                  16
1536 #  define _CC_CHARNAME_CONT            17
1537 #  define _CC_NONLATIN1_FOLD           18
1538 #  define _CC_NONLATIN1_SIMPLE_FOLD    19
1539 #  define _CC_QUOTEMETA                20
1540 #  define _CC_NON_FINAL_FOLD           21
1541 #  define _CC_IS_IN_SOME_FOLD          22
1542 #  define _CC_BINDIGIT                 23
1543 #  define _CC_OCTDIGIT                 24
1544 #  define _CC_MNEMONIC_CNTRL           25
1545
1546 /* Unused: 26-31
1547  * If more bits are needed, one could add a second word for non-64bit
1548  * QUAD_IS_INT systems, using some #ifdefs to distinguish between having a 2nd
1549  * word or not.  The IS_IN_SOME_FOLD bit is the most easily expendable, as it
1550  * is used only for optimization (as of this writing), and differs in the
1551  * Latin1 range from the ALPHA bit only in two relatively unimportant
1552  * characters: the masculine and feminine ordinal indicators, so removing it
1553  * would just cause /i regexes which match them to run less efficiently.
1554  * Similarly the EBCDIC-only bits are used just for speed, and could be
1555  * replaced by other means */
1556
1557 #if defined(PERL_CORE) || defined(PERL_EXT)
1558 /* An enum version of the character class numbers, to help compilers
1559  * optimize */
1560 typedef enum {
1561     _CC_ENUM_ALPHA          = _CC_ALPHA,
1562     _CC_ENUM_ALPHANUMERIC   = _CC_ALPHANUMERIC,
1563     _CC_ENUM_ASCII          = _CC_ASCII,
1564     _CC_ENUM_BLANK          = _CC_BLANK,
1565     _CC_ENUM_CASED          = _CC_CASED,
1566     _CC_ENUM_CNTRL          = _CC_CNTRL,
1567     _CC_ENUM_DIGIT          = _CC_DIGIT,
1568     _CC_ENUM_GRAPH          = _CC_GRAPH,
1569     _CC_ENUM_LOWER          = _CC_LOWER,
1570     _CC_ENUM_PRINT          = _CC_PRINT,
1571     _CC_ENUM_PUNCT          = _CC_PUNCT,
1572     _CC_ENUM_SPACE          = _CC_SPACE,
1573     _CC_ENUM_UPPER          = _CC_UPPER,
1574     _CC_ENUM_VERTSPACE      = _CC_VERTSPACE,
1575     _CC_ENUM_WORDCHAR       = _CC_WORDCHAR,
1576     _CC_ENUM_XDIGIT         = _CC_XDIGIT
1577 } _char_class_number;
1578 #endif
1579
1580 #define POSIX_CC_COUNT    (_HIGHEST_REGCOMP_DOT_H_SYNC + 1)
1581
1582 START_EXTERN_C
1583 #  ifdef DOINIT
1584 EXTCONST  U32 PL_charclass[] = {
1585 #    include "l1_char_class_tab.h"
1586 };
1587
1588 #  else /* ! DOINIT */
1589 EXTCONST U32 PL_charclass[];
1590 #  endif
1591 END_EXTERN_C
1592
1593     /* The 1U keeps Solaris from griping when shifting sets the uppermost bit */
1594 #   define _CC_mask(classnum) (1U << (classnum))
1595
1596     /* For internal core Perl use only: the base macro for defining macros like
1597      * isALPHA */
1598 #   define _generic_isCC(c, classnum) cBOOL(FITS_IN_8_BITS(c)    \
1599                 && (PL_charclass[(U8) (c)] & _CC_mask(classnum)))
1600
1601     /* The mask for the _A versions of the macros; it just adds in the bit for
1602      * ASCII. */
1603 #   define _CC_mask_A(classnum) (_CC_mask(classnum) | _CC_mask(_CC_ASCII))
1604
1605     /* For internal core Perl use only: the base macro for defining macros like
1606      * isALPHA_A.  The foo_A version makes sure that both the desired bit and
1607      * the ASCII bit are present */
1608 #   define _generic_isCC_A(c, classnum) (FITS_IN_8_BITS(c)      \
1609         && ((PL_charclass[(U8) (c)] & _CC_mask_A(classnum))     \
1610                                    == _CC_mask_A(classnum)))
1611
1612 /* On ASCII platforms certain classes form a single range.  It's faster to
1613  * special case these.  isDIGIT is a single range on all platforms */
1614 #   ifdef EBCDIC
1615 #     define isALPHA_A(c)  _generic_isCC_A(c, _CC_ALPHA)
1616 #     define isGRAPH_A(c)  _generic_isCC_A(c, _CC_GRAPH)
1617 #     define isLOWER_A(c)  _generic_isCC_A(c, _CC_LOWER)
1618 #     define isPRINT_A(c)  _generic_isCC_A(c, _CC_PRINT)
1619 #     define isUPPER_A(c)  _generic_isCC_A(c, _CC_UPPER)
1620 #   else
1621       /* By folding the upper and lowercase, we can use a single range */
1622 #     define isALPHA_A(c)  inRANGE((~('A' ^ 'a') & (c)), 'A', 'Z')
1623 #     define isGRAPH_A(c)  inRANGE(c, ' ' + 1, 0x7e)
1624 #     define isLOWER_A(c)  inRANGE(c, 'a', 'z')
1625 #     define isPRINT_A(c)  inRANGE(c, ' ', 0x7e)
1626 #     define isUPPER_A(c)  inRANGE(c, 'A', 'Z')
1627 #   endif
1628 #   define isALPHANUMERIC_A(c) _generic_isCC_A(c, _CC_ALPHANUMERIC)
1629 #   define isBLANK_A(c)  _generic_isCC_A(c, _CC_BLANK)
1630 #   define isCNTRL_A(c)  _generic_isCC_A(c, _CC_CNTRL)
1631 #   define isDIGIT_A(c)  inRANGE(c, '0', '9')
1632 #   define isPUNCT_A(c)  _generic_isCC_A(c, _CC_PUNCT)
1633 #   define isSPACE_A(c)  _generic_isCC_A(c, _CC_SPACE)
1634 #   define isWORDCHAR_A(c) _generic_isCC_A(c, _CC_WORDCHAR)
1635 #   define isXDIGIT_A(c)  _generic_isCC(c, _CC_XDIGIT) /* No non-ASCII xdigits
1636                                                         */
1637 #   define isIDFIRST_A(c) _generic_isCC_A(c, _CC_IDFIRST)
1638 #   define isALPHA_L1(c)  _generic_isCC(c, _CC_ALPHA)
1639 #   define isALPHANUMERIC_L1(c) _generic_isCC(c, _CC_ALPHANUMERIC)
1640 #   define isBLANK_L1(c)  _generic_isCC(c, _CC_BLANK)
1641
1642     /* continuation character for legal NAME in \N{NAME} */
1643 #   define isCHARNAME_CONT(c) _generic_isCC(c, _CC_CHARNAME_CONT)
1644
1645 #   define isCNTRL_L1(c)  _generic_isCC(c, _CC_CNTRL)
1646 #   define isGRAPH_L1(c)  _generic_isCC(c, _CC_GRAPH)
1647 #   define isLOWER_L1(c)  _generic_isCC(c, _CC_LOWER)
1648 #   define isPRINT_L1(c)  _generic_isCC(c, _CC_PRINT)
1649 #   define isPSXSPC_L1(c)  isSPACE_L1(c)
1650 #   define isPUNCT_L1(c)  _generic_isCC(c, _CC_PUNCT)
1651 #   define isSPACE_L1(c)  _generic_isCC(c, _CC_SPACE)
1652 #   define isUPPER_L1(c)  _generic_isCC(c, _CC_UPPER)
1653 #   define isWORDCHAR_L1(c) _generic_isCC(c, _CC_WORDCHAR)
1654 #   define isIDFIRST_L1(c) _generic_isCC(c, _CC_IDFIRST)
1655
1656 #   ifdef EBCDIC
1657 #       define isASCII(c) _generic_isCC(c, _CC_ASCII)
1658 #   endif
1659
1660     /* Participates in a single-character fold with a character above 255 */
1661 #   if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C)
1662 #     define HAS_NONLATIN1_SIMPLE_FOLD_CLOSURE(c)                          \
1663         ((   ! cBOOL(FITS_IN_8_BITS(c)))                                    \
1664           || (PL_charclass[(U8) (c)] & _CC_mask(_CC_NONLATIN1_SIMPLE_FOLD)))
1665
1666 #   define IS_NON_FINAL_FOLD(c)   _generic_isCC(c, _CC_NON_FINAL_FOLD)
1667 #   define IS_IN_SOME_FOLD_L1(c)  _generic_isCC(c, _CC_IS_IN_SOME_FOLD)
1668 #  endif
1669
1670     /* Like the above, but also can be part of a multi-char fold */
1671 #   define HAS_NONLATIN1_FOLD_CLOSURE(c)                                    \
1672       (   (! cBOOL(FITS_IN_8_BITS(c)))                                      \
1673        || (PL_charclass[(U8) (c)] & _CC_mask(_CC_NONLATIN1_FOLD)))
1674
1675 #   define _isQUOTEMETA(c) _generic_isCC(c, _CC_QUOTEMETA)
1676
1677 /* is c a control character for which we have a mnemonic? */
1678 #  if defined(PERL_CORE) || defined(PERL_EXT)
1679 #     define isMNEMONIC_CNTRL(c) _generic_isCC(c, _CC_MNEMONIC_CNTRL)
1680 #  endif
1681 #else   /* else we don't have perl.h H_PERL */
1682
1683     /* If we don't have perl.h, we are compiling a utility program.  Below we
1684      * hard-code various macro definitions that wouldn't otherwise be available
1685      * to it. Most are coded based on first principles.  These are written to
1686      * avoid EBCDIC vs. ASCII #ifdef's as much as possible. */
1687 #   define isDIGIT_A(c)  inRANGE(c, '0', '9')
1688 #   define isBLANK_A(c)  ((c) == ' ' || (c) == '\t')
1689 #   define isSPACE_A(c)  (isBLANK_A(c)                                   \
1690                           || (c) == '\n'                                 \
1691                           || (c) == '\r'                                 \
1692                           || (c) == '\v'                                 \
1693                           || (c) == '\f')
1694     /* On EBCDIC, there are gaps between 'i' and 'j'; 'r' and 's'.  Same for
1695      * uppercase.  The tests for those aren't necessary on ASCII, but hurt only
1696      * performance (if optimization isn't on), and allow the same code to be
1697      * used for both platform types */
1698 #   define isLOWER_A(c)  inRANGE((c), 'a', 'i')                         \
1699                       || inRANGE((c), 'j', 'r')                         \
1700                       || inRANGE((c), 's', 'z')
1701 #   define isUPPER_A(c)  inRANGE((c), 'A', 'I')                         \
1702                       || inRANGE((c), 'J', 'R')                         \
1703                       || inRANGE((c), 'S', 'Z')
1704 #   define isALPHA_A(c)  (isUPPER_A(c) || isLOWER_A(c))
1705 #   define isALPHANUMERIC_A(c) (isALPHA_A(c) || isDIGIT_A(c))
1706 #   define isWORDCHAR_A(c)   (isALPHANUMERIC_A(c) || (c) == '_')
1707 #   define isIDFIRST_A(c)    (isALPHA_A(c) || (c) == '_')
1708 #   define isXDIGIT_A(c) (   isDIGIT_A(c)                               \
1709                           || inRANGE((c), 'a', 'f')                     \
1710                           || inRANGE((c), 'A', 'F')
1711 #   define isPUNCT_A(c)  ((c) == '-' || (c) == '!' || (c) == '"'        \
1712                        || (c) == '#' || (c) == '$' || (c) == '%'        \
1713                        || (c) == '&' || (c) == '\'' || (c) == '('       \
1714                        || (c) == ')' || (c) == '*' || (c) == '+'        \
1715                        || (c) == ',' || (c) == '.' || (c) == '/'        \
1716                        || (c) == ':' || (c) == ';' || (c) == '<'        \
1717                        || (c) == '=' || (c) == '>' || (c) == '?'        \
1718                        || (c) == '@' || (c) == '[' || (c) == '\\'       \
1719                        || (c) == ']' || (c) == '^' || (c) == '_'        \
1720                        || (c) == '`' || (c) == '{' || (c) == '|'        \
1721                        || (c) == '}' || (c) == '~')
1722 #   define isGRAPH_A(c)  (isALPHANUMERIC_A(c) || isPUNCT_A(c))
1723 #   define isPRINT_A(c)  (isGRAPH_A(c) || (c) == ' ')
1724
1725 #   ifdef EBCDIC
1726         /* The below is accurate for the 3 EBCDIC code pages traditionally
1727          * supported by perl.  The only difference between them in the controls
1728          * is the position of \n, and that is represented symbolically below */
1729 #       define isCNTRL_A(c)  ((c) == '\0' || (c) == '\a' || (c) == '\b'     \
1730                           ||  (c) == '\f' || (c) == '\n' || (c) == '\r'     \
1731                           ||  (c) == '\t' || (c) == '\v'                    \
1732                           || inRANGE((c), 1, 3)     /* SOH, STX, ETX */     \
1733                           ||  (c) == 7F   /* U+7F DEL */                    \
1734                           || inRANGE((c), 0x0E, 0x13) /* SO SI DLE          \
1735                                                          DC[1-3] */         \
1736                           ||  (c) == 0x18 /* U+18 CAN */                    \
1737                           ||  (c) == 0x19 /* U+19 EOM */                    \
1738                           || inRANGE((c), 0x1C, 0x1F) /* [FGRU]S */         \
1739                           ||  (c) == 0x26 /* U+17 ETB */                    \
1740                           ||  (c) == 0x27 /* U+1B ESC */                    \
1741                           ||  (c) == 0x2D /* U+05 ENQ */                    \
1742                           ||  (c) == 0x2E /* U+06 ACK */                    \
1743                           ||  (c) == 0x32 /* U+16 SYN */                    \
1744                           ||  (c) == 0x37 /* U+04 EOT */                    \
1745                           ||  (c) == 0x3C /* U+14 DC4 */                    \
1746                           ||  (c) == 0x3D /* U+15 NAK */                    \
1747                           ||  (c) == 0x3F)/* U+1A SUB */
1748 #       define isASCII(c)    (isCNTRL_A(c) || isPRINT_A(c))
1749 #   else /* isASCII is already defined for ASCII platforms, so can use that to
1750             define isCNTRL */
1751 #       define isCNTRL_A(c)  (isASCII(c) && ! isPRINT_A(c))
1752 #   endif
1753
1754     /* The _L1 macros may be unnecessary for the utilities; I (khw) added them
1755      * during debugging, and it seems best to keep them.  We may be called
1756      * without NATIVE_TO_LATIN1 being defined.  On ASCII platforms, it doesn't
1757      * do anything anyway, so make it not a problem */
1758 #   if ! defined(EBCDIC) && ! defined(NATIVE_TO_LATIN1)
1759 #       define NATIVE_TO_LATIN1(ch) (ch)
1760 #   endif
1761 #   define isALPHA_L1(c)     (isUPPER_L1(c) || isLOWER_L1(c))
1762 #   define isALPHANUMERIC_L1(c) (isALPHA_L1(c) || isDIGIT_A(c))
1763 #   define isBLANK_L1(c)     (isBLANK_A(c)                                   \
1764                               || (FITS_IN_8_BITS(c)                          \
1765                                   && NATIVE_TO_LATIN1((U8) c) == 0xA0))
1766 #   define isCNTRL_L1(c)     (FITS_IN_8_BITS(c) && (! isPRINT_L1(c)))
1767 #   define isGRAPH_L1(c)     (isPRINT_L1(c) && (! isBLANK_L1(c)))
1768 #   define isLOWER_L1(c)     (isLOWER_A(c)                                   \
1769                               || (FITS_IN_8_BITS(c)                          \
1770                                   && ((   NATIVE_TO_LATIN1((U8) c) >= 0xDF   \
1771                                        && NATIVE_TO_LATIN1((U8) c) != 0xF7)  \
1772                                        || NATIVE_TO_LATIN1((U8) c) == 0xAA   \
1773                                        || NATIVE_TO_LATIN1((U8) c) == 0xBA   \
1774                                        || NATIVE_TO_LATIN1((U8) c) == 0xB5)))
1775 #   define isPRINT_L1(c)     (isPRINT_A(c)                                   \
1776                               || (FITS_IN_8_BITS(c)                          \
1777                                   && NATIVE_TO_LATIN1((U8) c) >= 0xA0))
1778 #   define isPUNCT_L1(c)     (isPUNCT_A(c)                                   \
1779                               || (FITS_IN_8_BITS(c)                          \
1780                                   && (   NATIVE_TO_LATIN1((U8) c) == 0xA1    \
1781                                       || NATIVE_TO_LATIN1((U8) c) == 0xA7    \
1782                                       || NATIVE_TO_LATIN1((U8) c) == 0xAB    \
1783                                       || NATIVE_TO_LATIN1((U8) c) == 0xB6    \
1784                                       || NATIVE_TO_LATIN1((U8) c) == 0xB7    \
1785                                       || NATIVE_TO_LATIN1((U8) c) == 0xBB    \
1786                                       || NATIVE_TO_LATIN1((U8) c) == 0xBF)))
1787 #   define isSPACE_L1(c)     (isSPACE_A(c)                                   \
1788                               || (FITS_IN_8_BITS(c)                          \
1789                                   && (   NATIVE_TO_LATIN1((U8) c) == 0x85    \
1790                                       || NATIVE_TO_LATIN1((U8) c) == 0xA0)))
1791 #   define isUPPER_L1(c)     (isUPPER_A(c)                                   \
1792                               || (FITS_IN_8_BITS(c)                          \
1793                                   && (   IN_RANGE(NATIVE_TO_LATIN1((U8) c),  \
1794                                                   0xC0, 0xDE)                \
1795                                       && NATIVE_TO_LATIN1((U8) c) != 0xD7)))
1796 #   define isWORDCHAR_L1(c)  (isIDFIRST_L1(c) || isDIGIT_A(c))
1797 #   define isIDFIRST_L1(c)   (isALPHA_L1(c) || NATIVE_TO_LATIN1(c) == '_')
1798 #   define isCHARNAME_CONT(c) (isWORDCHAR_L1(c)                              \
1799                                || isBLANK_L1(c)                              \
1800                                || (c) == '-'                                 \
1801                                || (c) == '('                                 \
1802                                || (c) == ')')
1803     /* The following are not fully accurate in the above-ASCII range.  I (khw)
1804      * don't think it's necessary to be so for the purposes where this gets
1805      * compiled */
1806 #   define _isQUOTEMETA(c)      (FITS_IN_8_BITS(c) && ! isWORDCHAR_L1(c))
1807 #   define _IS_IN_SOME_FOLD_ONLY_FOR_USE_BY_REGCOMP_DOT_C(c) isALPHA_L1(c)
1808
1809     /*  And these aren't accurate at all.  They are useful only for above
1810      *  Latin1, which utilities and bootstrapping don't deal with */
1811 #   define _IS_NON_FINAL_FOLD_ONLY_FOR_USE_BY_REGCOMP_DOT_C(c) 0
1812 #   define _HAS_NONLATIN1_SIMPLE_FOLD_CLOSURE_ONLY_FOR_USE_BY_REGCOMP_DOT_C_AND_REGEXEC_DOT_C(c) 0
1813 #   define _HAS_NONLATIN1_FOLD_CLOSURE_ONLY_FOR_USE_BY_REGCOMP_DOT_C_AND_REGEXEC_DOT_C(c) 0
1814
1815     /* Many of the macros later in this file are defined in terms of these.  By
1816      * implementing them with a function, which converts the class number into
1817      * a call to the desired macro, all of the later ones work.  However, that
1818      * function won't be actually defined when building a utility program (no
1819      * perl.h), and so a compiler error will be generated if one is attempted
1820      * to be used.  And the above-Latin1 code points require Unicode tables to
1821      * be present, something unlikely to be the case when bootstrapping */
1822 #   define _generic_isCC(c, classnum)                                        \
1823          (FITS_IN_8_BITS(c) && S_bootstrap_ctype((U8) (c), (classnum), TRUE))
1824 #   define _generic_isCC_A(c, classnum)                                      \
1825          (FITS_IN_8_BITS(c) && S_bootstrap_ctype((U8) (c), (classnum), FALSE))
1826 #endif  /* End of no perl.h H_PERL */
1827
1828 #define isALPHANUMERIC(c)  isALPHANUMERIC_A(c)
1829 #define isALPHA(c)   isALPHA_A(c)
1830 #define isASCII_A(c)  isASCII(c)
1831 #define isASCII_L1(c)  isASCII(c)
1832 #define isBLANK(c)   isBLANK_A(c)
1833 #define isCNTRL(c)   isCNTRL_A(c)
1834 #define isDIGIT(c)   isDIGIT_A(c)
1835 #define isGRAPH(c)   isGRAPH_A(c)
1836 #define isIDFIRST(c) isIDFIRST_A(c)
1837 #define isLOWER(c)   isLOWER_A(c)
1838 #define isPRINT(c)   isPRINT_A(c)
1839 #define isPSXSPC_A(c) isSPACE_A(c)
1840 #define isPSXSPC(c)  isPSXSPC_A(c)
1841 #define isPSXSPC_L1(c) isSPACE_L1(c)
1842 #define isPUNCT(c)   isPUNCT_A(c)
1843 #define isSPACE(c)   isSPACE_A(c)
1844 #define isUPPER(c)   isUPPER_A(c)
1845 #define isWORDCHAR(c) isWORDCHAR_A(c)
1846 #define isXDIGIT(c)  isXDIGIT_A(c)
1847
1848 /* ASCII casing.  These could also be written as
1849     #define toLOWER(c) (isASCII(c) ? toLOWER_LATIN1(c) : (c))
1850     #define toUPPER(c) (isASCII(c) ? toUPPER_LATIN1_MOD(c) : (c))
1851    which uses table lookup and mask instead of subtraction.  (This would
1852    work because the _MOD does not apply in the ASCII range).
1853
1854    These actually are UTF-8 invariant casing, not just ASCII, as any non-ASCII
1855    UTF-8 invariants are neither upper nor lower.  (Only on EBCDIC platforms are
1856    there non-ASCII invariants, and all of them are controls.) */
1857 #define toLOWER(c)  (isUPPER(c) ? (U8)((c) + ('a' - 'A')) : (c))
1858 #define toUPPER(c)  (isLOWER(c) ? (U8)((c) - ('a' - 'A')) : (c))
1859
1860 /* In the ASCII range, these are equivalent to what they're here defined to be.
1861  * But by creating these definitions, other code doesn't have to be aware of
1862  * this detail.  Actually this works for all UTF-8 invariants, not just the
1863  * ASCII range. (EBCDIC platforms can have non-ASCII invariants.) */
1864 #define toFOLD(c)    toLOWER(c)
1865 #define toTITLE(c)   toUPPER(c)
1866
1867 #define toLOWER_A(c) toLOWER(c)
1868 #define toUPPER_A(c) toUPPER(c)
1869 #define toFOLD_A(c)  toFOLD(c)
1870 #define toTITLE_A(c) toTITLE(c)
1871
1872 /* Use table lookup for speed; returns the input itself if is out-of-range */
1873 #define toLOWER_LATIN1(c)    ((! FITS_IN_8_BITS(c))                        \
1874                              ? (c)                                         \
1875                              : PL_latin1_lc[ (U8) (c) ])
1876 #define toLOWER_L1(c)    toLOWER_LATIN1(c)  /* Synonym for consistency */
1877
1878 /* Modified uc.  Is correct uc except for three non-ascii chars which are
1879  * all mapped to one of them, and these need special handling; returns the
1880  * input itself if is out-of-range */
1881 #define toUPPER_LATIN1_MOD(c) ((! FITS_IN_8_BITS(c))                       \
1882                                ? (c)                                       \
1883                                : PL_mod_latin1_uc[ (U8) (c) ])
1884 #define IN_UTF8_CTYPE_LOCALE PL_in_utf8_CTYPE_locale
1885
1886 /* Use foo_LC_uvchr() instead  of these for beyond the Latin1 range */
1887
1888 /* For internal core Perl use only: the base macro for defining macros like
1889  * isALPHA_LC, which uses the current LC_CTYPE locale.  'c' is the code point
1890  * (0-255) to check.  In a UTF-8 locale, the result is the same as calling
1891  * isFOO_L1(); the 'utf8_locale_classnum' parameter is something like
1892  * _CC_UPPER, which gives the class number for doing this.  For non-UTF-8
1893  * locales, the code to actually do the test this is passed in 'non_utf8'.  If
1894  * 'c' is above 255, 0 is returned.  For accessing the full range of possible
1895  * code points under locale rules, use the macros based on _generic_LC_uvchr
1896  * instead of this. */
1897 #define _generic_LC_base(c, utf8_locale_classnum, non_utf8)                    \
1898            (! FITS_IN_8_BITS(c)                                                \
1899            ? 0                                                                 \
1900            : IN_UTF8_CTYPE_LOCALE                                              \
1901              ? cBOOL(PL_charclass[(U8) (c)] & _CC_mask(utf8_locale_classnum))  \
1902              : cBOOL(non_utf8))
1903
1904 /* For internal core Perl use only: a helper macro for defining macros like
1905  * isALPHA_LC.  'c' is the code point (0-255) to check.  The function name to
1906  * actually do this test is passed in 'non_utf8_func', which is called on 'c',
1907  * casting 'c' to the macro _LC_CAST, which should not be parenthesized.  See
1908  * _generic_LC_base for more info */
1909 #define _generic_LC(c, utf8_locale_classnum, non_utf8_func)                    \
1910                         _generic_LC_base(c,utf8_locale_classnum,               \
1911                                          non_utf8_func( (_LC_CAST) (c)))
1912
1913 /* For internal core Perl use only: like _generic_LC, but also returns TRUE if
1914  * 'c' is the platform's native underscore character */
1915 #define _generic_LC_underscore(c,utf8_locale_classnum,non_utf8_func)           \
1916                         _generic_LC_base(c, utf8_locale_classnum,              \
1917                                          (non_utf8_func( (_LC_CAST) (c))       \
1918                                           || (char)(c) == '_'))
1919
1920 /* These next three are also for internal core Perl use only: case-change
1921  * helper macros.  The reason for using the PL_latin arrays is in case the
1922  * system function is defective; it ensures uniform results that conform to the
1923  * Unicod standard.   It does not handle the anomalies in UTF-8 Turkic locales */
1924 #define _generic_toLOWER_LC(c, function, cast)  (! FITS_IN_8_BITS(c)           \
1925                                                 ? (c)                          \
1926                                                 : (IN_UTF8_CTYPE_LOCALE)       \
1927                                                   ? PL_latin1_lc[ (U8) (c) ]   \
1928                                                   : (cast)function((cast)(c)))
1929
1930 /* Note that the result can be larger than a byte in a UTF-8 locale.  It
1931  * returns a single value, so can't adequately return the upper case of LATIN
1932  * SMALL LETTER SHARP S in a UTF-8 locale (which should be a string of two
1933  * values "SS");  instead it asserts against that under DEBUGGING, and
1934  * otherwise returns its input.  It does not handle the anomalies in UTF-8
1935  * Turkic locales. */
1936 #define _generic_toUPPER_LC(c, function, cast)                                 \
1937                     (! FITS_IN_8_BITS(c)                                       \
1938                     ? (c)                                                      \
1939                     : ((! IN_UTF8_CTYPE_LOCALE)                                \
1940                       ? (cast)function((cast)(c))                              \
1941                       : ((((U8)(c)) == MICRO_SIGN)                             \
1942                         ? GREEK_CAPITAL_LETTER_MU                              \
1943                         : ((((U8)(c)) == LATIN_SMALL_LETTER_Y_WITH_DIAERESIS)  \
1944                           ? LATIN_CAPITAL_LETTER_Y_WITH_DIAERESIS              \
1945                           : ((((U8)(c)) == LATIN_SMALL_LETTER_SHARP_S)         \
1946                             ? (__ASSERT_(0) (c))                               \
1947                             : PL_mod_latin1_uc[ (U8) (c) ])))))
1948
1949 /* Note that the result can be larger than a byte in a UTF-8 locale.  It
1950  * returns a single value, so can't adequately return the fold case of LATIN
1951  * SMALL LETTER SHARP S in a UTF-8 locale (which should be a string of two
1952  * values "ss"); instead it asserts against that under DEBUGGING, and
1953  * otherwise returns its input.  It does not handle the anomalies in UTF-8
1954  * Turkic locales */
1955 #define _generic_toFOLD_LC(c, function, cast)                                  \
1956                     ((UNLIKELY((c) == MICRO_SIGN) && IN_UTF8_CTYPE_LOCALE)     \
1957                       ? GREEK_SMALL_LETTER_MU                                  \
1958                       : (__ASSERT_(! IN_UTF8_CTYPE_LOCALE                      \
1959                                    || (c) != LATIN_SMALL_LETTER_SHARP_S)       \
1960                          _generic_toLOWER_LC(c, function, cast)))
1961
1962 /* Use the libc versions for these if available. */
1963 #if defined(HAS_ISASCII)
1964 #   define isASCII_LC(c) (FITS_IN_8_BITS(c) && isascii( (U8) (c)))
1965 #else
1966 #   define isASCII_LC(c) isASCII(c)
1967 #endif
1968
1969 #if defined(HAS_ISBLANK)
1970 #   define isBLANK_LC(c) _generic_LC(c, _CC_BLANK, isblank)
1971 #else /* Unlike isASCII, varies if in a UTF-8 locale */
1972 #   define isBLANK_LC(c) ((IN_UTF8_CTYPE_LOCALE) ? isBLANK_L1(c) : isBLANK(c))
1973 #endif
1974
1975 #define _LC_CAST U8
1976
1977 #ifdef WIN32
1978     /* The Windows functions don't bother to follow the POSIX standard, which
1979      * for example says that something can't both be a printable and a control.
1980      * But Windows treats the \t control as a printable, and does such things
1981      * as making superscripts into both digits and punctuation.  This tames
1982      * these flaws by assuming that the definitions of both controls and space
1983      * are correct, and then making sure that other definitions don't have
1984      * weirdnesses, by making sure that isalnum() isn't also ispunct(), etc.
1985      * Not all possible weirdnesses are checked for, just the ones that were
1986      * detected on actual Microsoft code pages */
1987
1988 #  define isCNTRL_LC(c)  _generic_LC(c, _CC_CNTRL, iscntrl)
1989 #  define isSPACE_LC(c)  _generic_LC(c, _CC_SPACE, isspace)
1990
1991 #  define isALPHA_LC(c)  (_generic_LC(c, _CC_ALPHA, isalpha)                  \
1992                                                     && isALPHANUMERIC_LC(c))
1993 #  define isALPHANUMERIC_LC(c)  (_generic_LC(c, _CC_ALPHANUMERIC, isalnum) && \
1994                                                               ! isPUNCT_LC(c))
1995 #  define isDIGIT_LC(c)  (_generic_LC(c, _CC_DIGIT, isdigit) &&               \
1996                                                          isALPHANUMERIC_LC(c))
1997 #  define isGRAPH_LC(c)  (_generic_LC(c, _CC_GRAPH, isgraph) && isPRINT_LC(c))
1998 #  define isIDFIRST_LC(c) (((c) == '_')                                       \
1999                  || (_generic_LC(c, _CC_IDFIRST, isalpha) && ! isPUNCT_LC(c)))
2000 #  define isLOWER_LC(c)  (_generic_LC(c, _CC_LOWER, islower) && isALPHA_LC(c))
2001 #  define isPRINT_LC(c)  (_generic_LC(c, _CC_PRINT, isprint) && ! isCNTRL_LC(c))
2002 #  define isPUNCT_LC(c)  (_generic_LC(c, _CC_PUNCT, ispunct) && ! isCNTRL_LC(c))
2003 #  define isUPPER_LC(c)  (_generic_LC(c, _CC_UPPER, isupper) && isALPHA_LC(c))
2004 #  define isWORDCHAR_LC(c) (((c) == '_') || isALPHANUMERIC_LC(c))
2005 #  define isXDIGIT_LC(c) (_generic_LC(c, _CC_XDIGIT, isxdigit)                \
2006                                                     && isALPHANUMERIC_LC(c))
2007
2008 #  define toLOWER_LC(c) _generic_toLOWER_LC((c), tolower, U8)
2009 #  define toUPPER_LC(c) _generic_toUPPER_LC((c), toupper, U8)
2010 #  define toFOLD_LC(c)  _generic_toFOLD_LC((c), tolower, U8)
2011
2012 #elif defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
2013     /* For most other platforms */
2014
2015 #  define isALPHA_LC(c)   _generic_LC(c, _CC_ALPHA, isalpha)
2016 #  define isALPHANUMERIC_LC(c)  _generic_LC(c, _CC_ALPHANUMERIC, isalnum)
2017 #  define isCNTRL_LC(c)    _generic_LC(c, _CC_CNTRL, iscntrl)
2018 #  define isDIGIT_LC(c)    _generic_LC(c, _CC_DIGIT, isdigit)
2019 #  define isGRAPH_LC(c)    _generic_LC(c, _CC_GRAPH, isgraph)
2020 #  define isIDFIRST_LC(c)  _generic_LC_underscore(c, _CC_IDFIRST, isalpha)
2021 #  define isLOWER_LC(c)    _generic_LC(c, _CC_LOWER, islower)
2022 #  define isPRINT_LC(c)    _generic_LC(c, _CC_PRINT, isprint)
2023 #  define isPUNCT_LC(c)    _generic_LC(c, _CC_PUNCT, ispunct)
2024 #  define isSPACE_LC(c)    _generic_LC(c, _CC_SPACE, isspace)
2025 #  define isUPPER_LC(c)    _generic_LC(c, _CC_UPPER, isupper)
2026 #  define isWORDCHAR_LC(c) _generic_LC_underscore(c, _CC_WORDCHAR, isalnum)
2027 #  define isXDIGIT_LC(c)   _generic_LC(c, _CC_XDIGIT, isxdigit)
2028
2029
2030 #  define toLOWER_LC(c) _generic_toLOWER_LC((c), tolower, U8)
2031 #  define toUPPER_LC(c) _generic_toUPPER_LC((c), toupper, U8)
2032 #  define toFOLD_LC(c)  _generic_toFOLD_LC((c), tolower, U8)
2033
2034 #else  /* The final fallback position */
2035
2036 #  define isALPHA_LC(c)         (isascii(c) && isalpha(c))
2037 #  define isALPHANUMERIC_LC(c)  (isascii(c) && isalnum(c))
2038 #  define isCNTRL_LC(c)         (isascii(c) && iscntrl(c))
2039 #  define isDIGIT_LC(c)         (isascii(c) && isdigit(c))
2040 #  define isGRAPH_LC(c)         (isascii(c) && isgraph(c))
2041 #  define isIDFIRST_LC(c)       (isascii(c) && (isalpha(c) || (c) == '_'))
2042 #  define isLOWER_LC(c)         (isascii(c) && islower(c))
2043 #  define isPRINT_LC(c)         (isascii(c) && isprint(c))
2044 #  define isPUNCT_LC(c)         (isascii(c) && ispunct(c))
2045 #  define isSPACE_LC(c)         (isascii(c) && isspace(c))
2046 #  define isUPPER_LC(c)         (isascii(c) && isupper(c))
2047 #  define isWORDCHAR_LC(c)      (isascii(c) && (isalnum(c) || (c) == '_'))
2048 #  define isXDIGIT_LC(c)        (isascii(c) && isxdigit(c))
2049
2050 #  define toLOWER_LC(c) (isascii(c) ? tolower(c) : (c))
2051 #  define toUPPER_LC(c) (isascii(c) ? toupper(c) : (c))
2052 #  define toFOLD_LC(c)  (isascii(c) ? tolower(c) : (c))
2053
2054 #endif
2055
2056 #define isIDCONT(c)             isWORDCHAR(c)
2057 #define isIDCONT_A(c)           isWORDCHAR_A(c)
2058 #define isIDCONT_L1(c)          isWORDCHAR_L1(c)
2059 #define isIDCONT_LC(c)          isWORDCHAR_LC(c)
2060 #define isPSXSPC_LC(c)          isSPACE_LC(c)
2061
2062 /* For internal core Perl use only: the base macros for defining macros like
2063  * isALPHA_uvchr.  'c' is the code point to check.  'classnum' is the POSIX class
2064  * number defined earlier in this file.  _generic_uvchr() is used for POSIX
2065  * classes where there is a macro or function 'above_latin1' that takes the
2066  * single argument 'c' and returns the desired value.  These exist for those
2067  * classes which have simple definitions, avoiding the overhead of an inversion
2068  * list binary search.  _generic_invlist_uvchr() can be used
2069  * for classes where that overhead is faster than a direct lookup.
2070  * _generic_uvchr() won't compile if 'c' isn't unsigned, as it won't match the
2071  * 'above_latin1' prototype. _generic_isCC() macro does bounds checking, so
2072  * have duplicate checks here, so could create versions of the macros that
2073  * don't, but experiments show that gcc optimizes them out anyway. */
2074
2075 /* Note that all ignore 'use bytes' */
2076 #define _generic_uvchr(classnum, above_latin1, c) ((c) < 256                \
2077                                              ? _generic_isCC(c, classnum)   \
2078                                              : above_latin1(c))
2079 #define _generic_invlist_uvchr(classnum, c) ((c) < 256                        \
2080                                              ? _generic_isCC(c, classnum)   \
2081                                              : _is_uni_FOO(classnum, c))
2082 #define isALPHA_uvchr(c)      _generic_invlist_uvchr(_CC_ALPHA, c)
2083 #define isALPHANUMERIC_uvchr(c) _generic_invlist_uvchr(_CC_ALPHANUMERIC, c)
2084 #define isASCII_uvchr(c)      isASCII(c)
2085 #define isBLANK_uvchr(c)      _generic_uvchr(_CC_BLANK, is_HORIZWS_cp_high, c)
2086 #define isCNTRL_uvchr(c)      isCNTRL_L1(c) /* All controls are in Latin1 */
2087 #define isDIGIT_uvchr(c)      _generic_invlist_uvchr(_CC_DIGIT, c)
2088 #define isGRAPH_uvchr(c)      _generic_invlist_uvchr(_CC_GRAPH, c)
2089 #define isIDCONT_uvchr(c)                                                   \
2090                     _generic_uvchr(_CC_WORDCHAR, _is_uni_perl_idcont, c)
2091 #define isIDFIRST_uvchr(c)                                                  \
2092                     _generic_uvchr(_CC_IDFIRST, _is_uni_perl_idstart, c)
2093 #define isLOWER_uvchr(c)      _generic_invlist_uvchr(_CC_LOWER, c)
2094 #define isPRINT_uvchr(c)      _generic_invlist_uvchr(_CC_PRINT, c)
2095
2096 #define isPUNCT_uvchr(c)      _generic_invlist_uvchr(_CC_PUNCT, c)
2097 #define isSPACE_uvchr(c)      _generic_uvchr(_CC_SPACE, is_XPERLSPACE_cp_high, c)
2098 #define isPSXSPC_uvchr(c)     isSPACE_uvchr(c)
2099
2100 #define isUPPER_uvchr(c)      _generic_invlist_uvchr(_CC_UPPER, c)
2101 #define isVERTWS_uvchr(c)     _generic_uvchr(_CC_VERTSPACE, is_VERTWS_cp_high, c)
2102 #define isWORDCHAR_uvchr(c)   _generic_invlist_uvchr(_CC_WORDCHAR, c)
2103 #define isXDIGIT_uvchr(c)     _generic_uvchr(_CC_XDIGIT, is_XDIGIT_cp_high, c)
2104
2105 #define toFOLD_uvchr(c,s,l)     to_uni_fold(c,s,l)
2106 #define toLOWER_uvchr(c,s,l)    to_uni_lower(c,s,l)
2107 #define toTITLE_uvchr(c,s,l)    to_uni_title(c,s,l)
2108 #define toUPPER_uvchr(c,s,l)    to_uni_upper(c,s,l)
2109
2110 /* For backwards compatibility, even though '_uni' should mean official Unicode
2111  * code points, in Perl it means native for those below 256 */
2112 #define isALPHA_uni(c)          isALPHA_uvchr(c)
2113 #define isALPHANUMERIC_uni(c)   isALPHANUMERIC_uvchr(c)
2114 #define isASCII_uni(c)          isASCII_uvchr(c)
2115 #define isBLANK_uni(c)          isBLANK_uvchr(c)
2116 #define isCNTRL_uni(c)          isCNTRL_uvchr(c)
2117 #define isDIGIT_uni(c)          isDIGIT_uvchr(c)
2118 #define isGRAPH_uni(c)          isGRAPH_uvchr(c)
2119 #define isIDCONT_uni(c)         isIDCONT_uvchr(c)
2120 #define isIDFIRST_uni(c)        isIDFIRST_uvchr(c)
2121 #define isLOWER_uni(c)          isLOWER_uvchr(c)
2122 #define isPRINT_uni(c)          isPRINT_uvchr(c)
2123 #define isPUNCT_uni(c)          isPUNCT_uvchr(c)
2124 #define isSPACE_uni(c)          isSPACE_uvchr(c)
2125 #define isPSXSPC_uni(c)         isPSXSPC_uvchr(c)
2126 #define isUPPER_uni(c)          isUPPER_uvchr(c)
2127 #define isVERTWS_uni(c)         isVERTWS_uvchr(c)
2128 #define isWORDCHAR_uni(c)       isWORDCHAR_uvchr(c)
2129 #define isXDIGIT_uni(c)         isXDIGIT_uvchr(c)
2130 #define toFOLD_uni(c,s,l)       toFOLD_uvchr(c,s,l)
2131 #define toLOWER_uni(c,s,l)      toLOWER_uvchr(c,s,l)
2132 #define toTITLE_uni(c,s,l)      toTITLE_uvchr(c,s,l)
2133 #define toUPPER_uni(c,s,l)      toUPPER_uvchr(c,s,l)
2134
2135 /* For internal core Perl use only: the base macros for defining macros like
2136  * isALPHA_LC_uvchr.  These are like isALPHA_LC, but the input can be any code
2137  * point, not just 0-255.  Like _generic_uvchr, there are two versions, one for
2138  * simple class definitions; the other for more complex.  These are like
2139  * _generic_uvchr, so see it for more info. */
2140 #define _generic_LC_uvchr(latin1, above_latin1, c)                            \
2141                                     (c < 256 ? latin1(c) : above_latin1(c))
2142 #define _generic_LC_invlist_uvchr(latin1, classnum, c)                          \
2143                             (c < 256 ? latin1(c) : _is_uni_FOO(classnum, c))
2144
2145 #define isALPHA_LC_uvchr(c)  _generic_LC_invlist_uvchr(isALPHA_LC, _CC_ALPHA, c)
2146 #define isALPHANUMERIC_LC_uvchr(c)  _generic_LC_invlist_uvchr(isALPHANUMERIC_LC, \
2147                                                          _CC_ALPHANUMERIC, c)
2148 #define isASCII_LC_uvchr(c)   isASCII_LC(c)
2149 #define isBLANK_LC_uvchr(c)  _generic_LC_uvchr(isBLANK_LC,                    \
2150                                                         is_HORIZWS_cp_high, c)
2151 #define isCNTRL_LC_uvchr(c)  (c < 256 ? isCNTRL_LC(c) : 0)
2152 #define isDIGIT_LC_uvchr(c)  _generic_LC_invlist_uvchr(isDIGIT_LC, _CC_DIGIT, c)
2153 #define isGRAPH_LC_uvchr(c)  _generic_LC_invlist_uvchr(isGRAPH_LC, _CC_GRAPH, c)
2154 #define isIDCONT_LC_uvchr(c) _generic_LC_uvchr(isIDCONT_LC,                   \
2155                                                   _is_uni_perl_idcont, c)
2156 #define isIDFIRST_LC_uvchr(c) _generic_LC_uvchr(isIDFIRST_LC,                 \
2157                                                   _is_uni_perl_idstart, c)
2158 #define isLOWER_LC_uvchr(c)  _generic_LC_invlist_uvchr(isLOWER_LC, _CC_LOWER, c)
2159 #define isPRINT_LC_uvchr(c)  _generic_LC_invlist_uvchr(isPRINT_LC, _CC_PRINT, c)
2160 #define isPSXSPC_LC_uvchr(c)  isSPACE_LC_uvchr(c)
2161 #define isPUNCT_LC_uvchr(c)  _generic_LC_invlist_uvchr(isPUNCT_LC, _CC_PUNCT, c)
2162 #define isSPACE_LC_uvchr(c)  _generic_LC_uvchr(isSPACE_LC,                    \
2163                                                     is_XPERLSPACE_cp_high, c)
2164 #define isUPPER_LC_uvchr(c)  _generic_LC_invlist_uvchr(isUPPER_LC, _CC_UPPER, c)
2165 #define isWORDCHAR_LC_uvchr(c) _generic_LC_invlist_uvchr(isWORDCHAR_LC,         \
2166                                                            _CC_WORDCHAR, c)
2167 #define isXDIGIT_LC_uvchr(c) _generic_LC_uvchr(isXDIGIT_LC,                  \
2168                                                        is_XDIGIT_cp_high, c)
2169
2170 #define isBLANK_LC_uni(c)    isBLANK_LC_uvchr(UNI_TO_NATIVE(c))
2171
2172 /* The "_safe" macros make sure that we don't attempt to read beyond 'e', but
2173  * they don't otherwise go out of their way to look for malformed UTF-8.  If
2174  * they can return accurate results without knowing if the input is otherwise
2175  * malformed, they do so.  For example isASCII is accurate in spite of any
2176  * non-length malformations because it looks only at a single byte. Likewise
2177  * isDIGIT looks just at the first byte for code points 0-255, as all UTF-8
2178  * variant ones return FALSE.  But, if the input has to be well-formed in order
2179  * for the results to be accurate, the macros will test and if malformed will
2180  * call a routine to die
2181  *
2182  * Except for toke.c, the macros do assume that e > p, asserting that on
2183  * DEBUGGING builds.  Much code that calls these depends on this being true,
2184  * for other reasons.  toke.c is treated specially as using the regular
2185  * assertion breaks it in many ways.  All strings that these operate on there
2186  * are supposed to have an extra NUL character at the end,  so that *e = \0. A
2187  * bunch of code in toke.c assumes that this is true, so the assertion allows
2188  * for that */
2189 #ifdef PERL_IN_TOKE_C
2190 #  define _utf8_safe_assert(p,e) ((e) > (p) || ((e) == (p) && *(p) == '\0'))
2191 #else
2192 #  define _utf8_safe_assert(p,e) ((e) > (p))
2193 #endif
2194
2195 #define _generic_utf8_safe(classnum, p, e, above_latin1)                    \
2196     ((! _utf8_safe_assert(p, e))                                            \
2197       ? (_force_out_malformed_utf8_message((U8 *) (p), (U8 *) (e), 0, 1), 0)\
2198       : (UTF8_IS_INVARIANT(*(p)))                                           \
2199           ? _generic_isCC(*(p), classnum)                                   \
2200           : (UTF8_IS_DOWNGRADEABLE_START(*(p))                              \
2201              ? ((LIKELY((e) - (p) > 1 && UTF8_IS_CONTINUATION(*((p)+1))))   \
2202                 ? _generic_isCC(EIGHT_BIT_UTF8_TO_NATIVE(*(p), *((p)+1 )),  \
2203                                 classnum)                                   \
2204                 : (_force_out_malformed_utf8_message(                       \
2205                                         (U8 *) (p), (U8 *) (e), 0, 1), 0))  \
2206              : above_latin1))
2207 /* Like the above, but calls 'above_latin1(p)' to get the utf8 value.
2208  * 'above_latin1' can be a macro */
2209 #define _generic_func_utf8_safe(classnum, above_latin1, p, e)               \
2210                     _generic_utf8_safe(classnum, p, e, above_latin1(p, e))
2211 #define _generic_non_invlist_utf8_safe(classnum, above_latin1, p, e)          \
2212           _generic_utf8_safe(classnum, p, e,                                \
2213                              (UNLIKELY((e) - (p) < UTF8SKIP(p))             \
2214                               ? (_force_out_malformed_utf8_message(         \
2215                                       (U8 *) (p), (U8 *) (e), 0, 1), 0)     \
2216                               : above_latin1(p)))
2217 /* Like the above, but passes classnum to _isFOO_utf8(), instead of having an
2218  * 'above_latin1' parameter */
2219 #define _generic_invlist_utf8_safe(classnum, p, e)                            \
2220             _generic_utf8_safe(classnum, p, e, _is_utf8_FOO(classnum, p, e))
2221
2222 /* Like the above, but should be used only when it is known that there are no
2223  * characters in the upper-Latin1 range (128-255 on ASCII platforms) which the
2224  * class is TRUE for.  Hence it can skip the tests for this range.
2225  * 'above_latin1' should include its arguments */
2226 #define _generic_utf8_safe_no_upper_latin1(classnum, p, e, above_latin1)    \
2227          (__ASSERT_(_utf8_safe_assert(p, e))                                \
2228          (isASCII(*(p)))                                                    \
2229           ? _generic_isCC(*(p), classnum)                                   \
2230           : (UTF8_IS_DOWNGRADEABLE_START(*(p)))                             \
2231              ? 0 /* Note that doesn't check validity for latin1 */          \
2232              : above_latin1)
2233
2234
2235 #define isALPHA_utf8(p, e)         isALPHA_utf8_safe(p, e)
2236 #define isALPHANUMERIC_utf8(p, e)  isALPHANUMERIC_utf8_safe(p, e)
2237 #define isASCII_utf8(p, e)         isASCII_utf8_safe(p, e)
2238 #define isBLANK_utf8(p, e)         isBLANK_utf8_safe(p, e)
2239 #define isCNTRL_utf8(p, e)         isCNTRL_utf8_safe(p, e)
2240 #define isDIGIT_utf8(p, e)         isDIGIT_utf8_safe(p, e)
2241 #define isGRAPH_utf8(p, e)         isGRAPH_utf8_safe(p, e)
2242 #define isIDCONT_utf8(p, e)        isIDCONT_utf8_safe(p, e)
2243 #define isIDFIRST_utf8(p, e)       isIDFIRST_utf8_safe(p, e)
2244 #define isLOWER_utf8(p, e)         isLOWER_utf8_safe(p, e)
2245 #define isPRINT_utf8(p, e)         isPRINT_utf8_safe(p, e)
2246 #define isPSXSPC_utf8(p, e)        isPSXSPC_utf8_safe(p, e)
2247 #define isPUNCT_utf8(p, e)         isPUNCT_utf8_safe(p, e)
2248 #define isSPACE_utf8(p, e)         isSPACE_utf8_safe(p, e)
2249 #define isUPPER_utf8(p, e)         isUPPER_utf8_safe(p, e)
2250 #define isVERTWS_utf8(p, e)        isVERTWS_utf8_safe(p, e)
2251 #define isWORDCHAR_utf8(p, e)      isWORDCHAR_utf8_safe(p, e)
2252 #define isXDIGIT_utf8(p, e)        isXDIGIT_utf8_safe(p, e)
2253
2254 #define isALPHA_utf8_safe(p, e)  _generic_invlist_utf8_safe(_CC_ALPHA, p, e)
2255 #define isALPHANUMERIC_utf8_safe(p, e)                                      \
2256                         _generic_invlist_utf8_safe(_CC_ALPHANUMERIC, p, e)
2257 #define isASCII_utf8_safe(p, e)                                             \
2258     /* Because ASCII is invariant under utf8, the non-utf8 macro            \
2259     * works */                                                              \
2260     (__ASSERT_(_utf8_safe_assert(p, e)) isASCII(*(p)))
2261 #define isBLANK_utf8_safe(p, e)                                             \
2262         _generic_non_invlist_utf8_safe(_CC_BLANK, is_HORIZWS_high, p, e)
2263
2264 #ifdef EBCDIC
2265     /* Because all controls are UTF-8 invariants in EBCDIC, we can use this
2266      * more efficient macro instead of the more general one */
2267 #   define isCNTRL_utf8_safe(p, e)                                          \
2268                     (__ASSERT_(_utf8_safe_assert(p, e)) isCNTRL_L1(*(p)))
2269 #else
2270 #   define isCNTRL_utf8_safe(p, e)  _generic_utf8_safe(_CC_CNTRL, p, e, 0)
2271 #endif
2272
2273 #define isDIGIT_utf8_safe(p, e)                                             \
2274             _generic_utf8_safe_no_upper_latin1(_CC_DIGIT, p, e,             \
2275                                             _is_utf8_FOO(_CC_DIGIT, p, e))
2276 #define isGRAPH_utf8_safe(p, e)    _generic_invlist_utf8_safe(_CC_GRAPH, p, e)
2277 #define isIDCONT_utf8_safe(p, e)   _generic_func_utf8_safe(_CC_WORDCHAR,    \
2278                                                  _is_utf8_perl_idcont, p, e)
2279
2280 /* To prevent S_scan_word in toke.c from hanging, we have to make sure that
2281  * IDFIRST is an alnum.  See
2282  * https://github.com/Perl/perl5/issues/10275 for more detail than you
2283  * ever wanted to know about.  (In the ASCII range, there isn't a difference.)
2284  * This used to be not the XID version, but we decided to go with the more
2285  * modern Unicode definition */
2286 #define isIDFIRST_utf8_safe(p, e)                                           \
2287     _generic_func_utf8_safe(_CC_IDFIRST,                                    \
2288                             _is_utf8_perl_idstart, (U8 *) (p), (U8 *) (e))
2289
2290 #define isLOWER_utf8_safe(p, e)     _generic_invlist_utf8_safe(_CC_LOWER, p, e)
2291 #define isPRINT_utf8_safe(p, e)     _generic_invlist_utf8_safe(_CC_PRINT, p, e)
2292 #define isPSXSPC_utf8_safe(p, e)     isSPACE_utf8_safe(p, e)
2293 #define isPUNCT_utf8_safe(p, e)     _generic_invlist_utf8_safe(_CC_PUNCT, p, e)
2294 #define isSPACE_utf8_safe(p, e)                                             \
2295     _generic_non_invlist_utf8_safe(_CC_SPACE, is_XPERLSPACE_high, p, e)
2296 #define isUPPER_utf8_safe(p, e)  _generic_invlist_utf8_safe(_CC_UPPER, p, e)
2297 #define isVERTWS_utf8_safe(p, e)                                            \
2298         _generic_non_invlist_utf8_safe(_CC_VERTSPACE, is_VERTWS_high, p, e)
2299 #define isWORDCHAR_utf8_safe(p, e)                                          \
2300                              _generic_invlist_utf8_safe(_CC_WORDCHAR, p, e)
2301 #define isXDIGIT_utf8_safe(p, e)                                            \
2302                    _generic_utf8_safe_no_upper_latin1(_CC_XDIGIT, p, e,     \
2303                              (UNLIKELY((e) - (p) < UTF8SKIP(p))             \
2304                               ? (_force_out_malformed_utf8_message(         \
2305                                       (U8 *) (p), (U8 *) (e), 0, 1), 0)     \
2306                               : is_XDIGIT_high(p)))
2307
2308 #define toFOLD_utf8(p,e,s,l)    toFOLD_utf8_safe(p,e,s,l)
2309 #define toLOWER_utf8(p,e,s,l)   toLOWER_utf8_safe(p,e,s,l)
2310 #define toTITLE_utf8(p,e,s,l)   toTITLE_utf8_safe(p,e,s,l)
2311 #define toUPPER_utf8(p,e,s,l)   toUPPER_utf8_safe(p,e,s,l)
2312
2313 /* For internal core use only, subject to change */
2314 #define _toFOLD_utf8_flags(p,e,s,l,f)  _to_utf8_fold_flags (p,e,s,l,f)
2315 #define _toLOWER_utf8_flags(p,e,s,l,f) _to_utf8_lower_flags(p,e,s,l,f)
2316 #define _toTITLE_utf8_flags(p,e,s,l,f) _to_utf8_title_flags(p,e,s,l,f)
2317 #define _toUPPER_utf8_flags(p,e,s,l,f) _to_utf8_upper_flags(p,e,s,l,f)
2318
2319 #define toFOLD_utf8_safe(p,e,s,l)   _toFOLD_utf8_flags(p,e,s,l, FOLD_FLAGS_FULL)
2320 #define toLOWER_utf8_safe(p,e,s,l)  _toLOWER_utf8_flags(p,e,s,l, 0)
2321 #define toTITLE_utf8_safe(p,e,s,l)  _toTITLE_utf8_flags(p,e,s,l, 0)
2322 #define toUPPER_utf8_safe(p,e,s,l)  _toUPPER_utf8_flags(p,e,s,l, 0)
2323
2324 #define isALPHA_LC_utf8(p, e)         isALPHA_LC_utf8_safe(p, e)
2325 #define isALPHANUMERIC_LC_utf8(p, e)  isALPHANUMERIC_LC_utf8_safe(p, e)
2326 #define isASCII_LC_utf8(p, e)         isASCII_LC_utf8_safe(p, e)
2327 #define isBLANK_LC_utf8(p, e)         isBLANK_LC_utf8_safe(p, e)
2328 #define isCNTRL_LC_utf8(p, e)         isCNTRL_LC_utf8_safe(p, e)
2329 #define isDIGIT_LC_utf8(p, e)         isDIGIT_LC_utf8_safe(p, e)
2330 #define isGRAPH_LC_utf8(p, e)         isGRAPH_LC_utf8_safe(p, e)
2331 #define isIDCONT_LC_utf8(p, e)        isIDCONT_LC_utf8_safe(p, e)
2332 #define isIDFIRST_LC_utf8(p, e)       isIDFIRST_LC_utf8_safe(p, e)
2333 #define isLOWER_LC_utf8(p, e)         isLOWER_LC_utf8_safe(p, e)
2334 #define isPRINT_LC_utf8(p, e)         isPRINT_LC_utf8_safe(p, e)
2335 #define isPSXSPC_LC_utf8(p, e)        isPSXSPC_LC_utf8_safe(p, e)
2336 #define isPUNCT_LC_utf8(p, e)         isPUNCT_LC_utf8_safe(p, e)
2337 #define isSPACE_LC_utf8(p, e)         isSPACE_LC_utf8_safe(p, e)
2338 #define isUPPER_LC_utf8(p, e)         isUPPER_LC_utf8_safe(p, e)
2339 #define isWORDCHAR_LC_utf8(p, e)      isWORDCHAR_LC_utf8_safe(p, e)
2340 #define isXDIGIT_LC_utf8(p, e)        isXDIGIT_LC_utf8_safe(p, e)
2341
2342 /* For internal core Perl use only: the base macros for defining macros like
2343  * isALPHA_LC_utf8_safe.  These are like _generic_utf8, but if the first code
2344  * point in 'p' is within the 0-255 range, it uses locale rules from the
2345  * passed-in 'macro' parameter */
2346 #define _generic_LC_utf8_safe(macro, p, e, above_latin1)                    \
2347          (__ASSERT_(_utf8_safe_assert(p, e))                                \
2348          (UTF8_IS_INVARIANT(*(p)))                                          \
2349           ? macro(*(p))                                                     \
2350           : (UTF8_IS_DOWNGRADEABLE_START(*(p))                              \
2351              ? ((LIKELY((e) - (p) > 1 && UTF8_IS_CONTINUATION(*((p)+1))))   \
2352                 ? macro(EIGHT_BIT_UTF8_TO_NATIVE(*(p), *((p)+1)))           \
2353                 : (_force_out_malformed_utf8_message(                       \
2354                                         (U8 *) (p), (U8 *) (e), 0, 1), 0))  \
2355               : above_latin1))
2356
2357 #define _generic_LC_invlist_utf8_safe(macro, classnum, p, e)                  \
2358             _generic_LC_utf8_safe(macro, p, e,                              \
2359                                             _is_utf8_FOO(classnum, p, e))
2360
2361 #define _generic_LC_func_utf8_safe(macro, above_latin1, p, e)               \
2362             _generic_LC_utf8_safe(macro, p, e, above_latin1(p, e))
2363
2364 #define _generic_LC_non_invlist_utf8_safe(classnum, above_latin1, p, e)       \
2365           _generic_LC_utf8_safe(classnum, p, e,                             \
2366                              (UNLIKELY((e) - (p) < UTF8SKIP(p))             \
2367                               ? (_force_out_malformed_utf8_message(         \
2368                                       (U8 *) (p), (U8 *) (e), 0, 1), 0)     \
2369                               : above_latin1(p)))
2370
2371 #define isALPHANUMERIC_LC_utf8_safe(p, e)                                   \
2372             _generic_LC_invlist_utf8_safe(isALPHANUMERIC_LC,                  \
2373                                         _CC_ALPHANUMERIC, p, e)
2374 #define isALPHA_LC_utf8_safe(p, e)                                          \
2375             _generic_LC_invlist_utf8_safe(isALPHA_LC, _CC_ALPHA, p, e)
2376 #define isASCII_LC_utf8_safe(p, e)                                          \
2377                     (__ASSERT_(_utf8_safe_assert(p, e)) isASCII_LC(*(p)))
2378 #define isBLANK_LC_utf8_safe(p, e)                                          \
2379         _generic_LC_non_invlist_utf8_safe(isBLANK_LC, is_HORIZWS_high, p, e)
2380 #define isCNTRL_LC_utf8_safe(p, e)                                          \
2381             _generic_LC_utf8_safe(isCNTRL_LC, p, e, 0)
2382 #define isDIGIT_LC_utf8_safe(p, e)                                          \
2383             _generic_LC_invlist_utf8_safe(isDIGIT_LC, _CC_DIGIT, p, e)
2384 #define isGRAPH_LC_utf8_safe(p, e)                                          \
2385             _generic_LC_invlist_utf8_safe(isGRAPH_LC, _CC_GRAPH, p, e)
2386 #define isIDCONT_LC_utf8_safe(p, e)                                         \
2387             _generic_LC_func_utf8_safe(isIDCONT_LC,                         \
2388                                                 _is_utf8_perl_idcont, p, e)
2389 #define isIDFIRST_LC_utf8_safe(p, e)                                        \
2390             _generic_LC_func_utf8_safe(isIDFIRST_LC,                        \
2391                                                _is_utf8_perl_idstart, p, e)
2392 #define isLOWER_LC_utf8_safe(p, e)                                          \
2393             _generic_LC_invlist_utf8_safe(isLOWER_LC, _CC_LOWER, p, e)
2394 #define isPRINT_LC_utf8_safe(p, e)                                          \
2395             _generic_LC_invlist_utf8_safe(isPRINT_LC, _CC_PRINT, p, e)
2396 #define isPSXSPC_LC_utf8_safe(p, e)    isSPACE_LC_utf8_safe(p, e)
2397 #define isPUNCT_LC_utf8_safe(p, e)                                          \
2398             _generic_LC_invlist_utf8_safe(isPUNCT_LC, _CC_PUNCT, p, e)
2399 #define isSPACE_LC_utf8_safe(p, e)                                          \
2400     _generic_LC_non_invlist_utf8_safe(isSPACE_LC, is_XPERLSPACE_high, p, e)
2401 #define isUPPER_LC_utf8_safe(p, e)                                          \
2402             _generic_LC_invlist_utf8_safe(isUPPER_LC, _CC_UPPER, p, e)
2403 #define isWORDCHAR_LC_utf8_safe(p, e)                                       \
2404             _generic_LC_invlist_utf8_safe(isWORDCHAR_LC, _CC_WORDCHAR, p, e)
2405 #define isXDIGIT_LC_utf8_safe(p, e)                                         \
2406         _generic_LC_non_invlist_utf8_safe(isXDIGIT_LC, is_XDIGIT_high, p, e)
2407
2408 /* Macros for backwards compatibility and for completeness when the ASCII and
2409  * Latin1 values are identical */
2410 #define isALPHAU(c)         isALPHA_L1(c)
2411 #define isDIGIT_L1(c)       isDIGIT_A(c)
2412 #define isOCTAL(c)          isOCTAL_A(c)
2413 #define isOCTAL_L1(c)       isOCTAL_A(c)
2414 #define isXDIGIT_L1(c)      isXDIGIT_A(c)
2415 #define isALNUM(c)          isWORDCHAR(c)
2416 #define isALNUM_A(c)        isALNUM(c)
2417 #define isALNUMU(c)         isWORDCHAR_L1(c)
2418 #define isALNUM_LC(c)       isWORDCHAR_LC(c)
2419 #define isALNUM_uni(c)      isWORDCHAR_uni(c)
2420 #define isALNUM_LC_uvchr(c) isWORDCHAR_LC_uvchr(c)
2421 #define isALNUM_utf8(p,e)   isWORDCHAR_utf8(p,e)
2422 #define isALNUM_utf8_safe(p,e) isWORDCHAR_utf8_safe(p,e)
2423 #define isALNUM_LC_utf8(p,e)isWORDCHAR_LC_utf8(p,e)
2424 #define isALNUM_LC_utf8_safe(p,e)isWORDCHAR_LC_utf8_safe(p,e)
2425 #define isALNUMC_A(c)       isALPHANUMERIC_A(c)      /* Mnemonic: "C's alnum" */
2426 #define isALNUMC_L1(c)      isALPHANUMERIC_L1(c)
2427 #define isALNUMC(c)         isALPHANUMERIC(c)
2428 #define isALNUMC_LC(c)      isALPHANUMERIC_LC(c)
2429 #define isALNUMC_uni(c)     isALPHANUMERIC_uni(c)
2430 #define isALNUMC_LC_uvchr(c) isALPHANUMERIC_LC_uvchr(c)
2431 #define isALNUMC_utf8(p,e)  isALPHANUMERIC_utf8(p,e)
2432 #define isALNUMC_utf8_safe(p,e)  isALPHANUMERIC_utf8_safe(p,e)
2433 #define isALNUMC_LC_utf8_safe(p,e) isALPHANUMERIC_LC_utf8_safe(p,e)
2434
2435 /* On EBCDIC platforms, CTRL-@ is 0, CTRL-A is 1, etc, just like on ASCII,
2436  * except that they don't necessarily mean the same characters, e.g. CTRL-D is
2437  * 4 on both systems, but that is EOT on ASCII;  ST on EBCDIC.
2438  * '?' is special-cased on EBCDIC to APC, which is the control there that is
2439  * the outlier from the block that contains the other controls, just like
2440  * toCTRL('?') on ASCII yields DEL, the control that is the outlier from the C0
2441  * block.  If it weren't special cased, it would yield a non-control.
2442  * The conversion works both ways, so toCTRL('D') is 4, and toCTRL(4) is D,
2443  * etc. */
2444 #ifndef EBCDIC
2445 #  define toCTRL(c)    (__ASSERT_(FITS_IN_8_BITS(c)) toUPPER(((U8)(c))) ^ 64)
2446 #else
2447 #  define toCTRL(c)   (__ASSERT_(FITS_IN_8_BITS(c))                     \
2448                       ((isPRINT_A(c))                                   \
2449                        ? (UNLIKELY((c) == '?')                          \
2450                          ? QUESTION_MARK_CTRL                           \
2451                          : (NATIVE_TO_LATIN1(toUPPER((U8) (c))) ^ 64))  \
2452                        : (UNLIKELY((c) == QUESTION_MARK_CTRL)           \
2453                          ? '?'                                          \
2454                          : (LATIN1_TO_NATIVE(((U8) (c)) ^ 64)))))
2455 #endif
2456
2457 /*
2458 =for apidoc Ay||line_t
2459 The typedef to use to declare variables that are to hold line numbers.
2460
2461 =cut
2462
2463   Line numbers are unsigned, 32 bits.
2464 */
2465 typedef U32 line_t;
2466 #define NOLINE ((line_t) 4294967295UL)  /* = FFFFFFFF */
2467
2468 /* Helpful alias for version prescan */
2469 #define is_LAX_VERSION(a,b) \
2470         (a != Perl_prescan_version(aTHX_ a, FALSE, b, NULL, NULL, NULL, NULL))
2471
2472 #define is_STRICT_VERSION(a,b) \
2473         (a != Perl_prescan_version(aTHX_ a, TRUE, b, NULL, NULL, NULL, NULL))
2474
2475 #define BADVERSION(a,b,c) \
2476         if (b) { \
2477             *b = c; \
2478         } \
2479         return a;
2480
2481 /* Converts a character KNOWN to represent a hexadecimal digit (0-9, A-F, or
2482  * a-f) to its numeric value without using any branches.  The input is
2483  * validated only by an assert() in DEBUGGING builds.
2484  *
2485  * It works by right shifting and isolating the bit that is 0 for the digits,
2486  * and 1 for at least the alphas A-F, a-f.  The bit is shifted to the ones
2487  * position, and then to the eights position.  Both are added together to form
2488  * 0 if the input is '0'-'9' and to form 9 if alpha.  This is added to the
2489  * final four bits of the input to form the correct value. */
2490 #define XDIGIT_VALUE(c) (__ASSERT_(isXDIGIT(c))                             \
2491            ((NATIVE_TO_LATIN1(c) >> 6) & 1)  /* 1 if alpha; 0 if not */     \
2492          + ((NATIVE_TO_LATIN1(c) >> 3) & 8)  /* 8 if alpha; 0 if not */     \
2493          + ((c) & 0xF))   /* 0-9 if input valid hex digit */
2494
2495 /* The argument is a string pointer, which is advanced. */
2496 #define READ_XDIGIT(s)  ((s)++, XDIGIT_VALUE(*((s) - 1)))
2497
2498 /* Converts a character known to represent an octal digit (0-7) to its numeric
2499  * value.  The input is validated only by an assert() in DEBUGGING builds.  In
2500  * both ASCII and EBCDIC the last 3 bits of the octal digits range from 0-7. */
2501 #define OCTAL_VALUE(c) (__ASSERT_(isOCTAL(c)) (7 & (c)))
2502
2503 /* Efficiently returns a boolean as to if two native characters are equivalent
2504  * case-insensitively.  At least one of the characters must be one of [A-Za-z];
2505  * the ALPHA in the name is to remind you of that.  This is asserted() in
2506  * DEBUGGING builds.  Because [A-Za-z] are invariant under UTF-8, this macro
2507  * works (on valid input) for both non- and UTF-8-encoded bytes.
2508  *
2509  * When one of the inputs is a compile-time constant and gets folded by the
2510  * compiler, this reduces to an AND and a TEST.  On both EBCDIC and ASCII
2511  * machines, 'A' and 'a' differ by a single bit; the same with the upper and
2512  * lower case of all other ASCII-range alphabetics.  On ASCII platforms, they
2513  * are 32 apart; on EBCDIC, they are 64.  At compile time, this uses an
2514  * exclusive 'or' to find that bit and then inverts it to form a mask, with
2515  * just a single 0, in the bit position where the upper- and lowercase differ.
2516  * */
2517 #define isALPHA_FOLD_EQ(c1, c2)                                         \
2518                       (__ASSERT_(isALPHA_A(c1) || isALPHA_A(c2))        \
2519                       ((c1) & ~('A' ^ 'a')) ==  ((c2) & ~('A' ^ 'a')))
2520 #define isALPHA_FOLD_NE(c1, c2) (! isALPHA_FOLD_EQ((c1), (c2)))
2521
2522 /*
2523 =for apidoc_section $memory
2524
2525 =for apidoc Am|void|Newx|void* ptr|int nitems|type
2526 The XSUB-writer's interface to the C C<malloc> function.
2527
2528 Memory obtained by this should B<ONLY> be freed with L</"Safefree">.
2529
2530 In 5.9.3, Newx() and friends replace the older New() API, and drops
2531 the first parameter, I<x>, a debug aid which allowed callers to identify
2532 themselves.  This aid has been superseded by a new build option,
2533 PERL_MEM_LOG (see L<perlhacktips/PERL_MEM_LOG>).  The older API is still
2534 there for use in XS modules supporting older perls.
2535
2536 =for apidoc Am|void|Newxc|void* ptr|int nitems|type|cast
2537 The XSUB-writer's interface to the C C<malloc> function, with
2538 cast.  See also C<L</Newx>>.
2539
2540 Memory obtained by this should B<ONLY> be freed with L</"Safefree">.
2541
2542 =for apidoc Am|void|Newxz|void* ptr|int nitems|type
2543 The XSUB-writer's interface to the C C<malloc> function.  The allocated
2544 memory is zeroed with C<memzero>.  See also C<L</Newx>>.
2545
2546 Memory obtained by this should B<ONLY> be freed with L</"Safefree">.
2547
2548 =for apidoc Am|void|Renew|void* ptr|int nitems|type
2549 The XSUB-writer's interface to the C C<realloc> function.
2550
2551 Memory obtained by this should B<ONLY> be freed with L</"Safefree">.
2552
2553 =for apidoc Am|void|Renewc|void* ptr|int nitems|type|cast
2554 The XSUB-writer's interface to the C C<realloc> function, with
2555 cast.
2556
2557 Memory obtained by this should B<ONLY> be freed with L</"Safefree">.
2558
2559 =for apidoc Am|void|Safefree|void* ptr
2560 The XSUB-writer's interface to the C C<free> function.
2561
2562 This should B<ONLY> be used on memory obtained using L</"Newx"> and friends.
2563
2564 =for apidoc_section $string
2565 =for apidoc Am|void|Move|void* src|void* dest|int nitems|type
2566 The XSUB-writer's interface to the C C<memmove> function.  The C<src> is the
2567 source, C<dest> is the destination, C<nitems> is the number of items, and
2568 C<type> is the type.  Can do overlapping moves.  See also C<L</Copy>>.
2569
2570 =for apidoc Am|void *|MoveD|void* src|void* dest|int nitems|type
2571 Like C<Move> but returns C<dest>.  Useful
2572 for encouraging compilers to tail-call
2573 optimise.
2574
2575 =for apidoc Am|void|Copy|void* src|void* dest|int nitems|type
2576 The XSUB-writer's interface to the C C<memcpy> function.  The C<src> is the
2577 source, C<dest> is the destination, C<nitems> is the number of items, and
2578 C<type> is the type.  May fail on overlapping copies.  See also C<L</Move>>.
2579
2580 =for apidoc Am|void *|CopyD|void* src|void* dest|int nitems|type
2581
2582 Like C<Copy> but returns C<dest>.  Useful
2583 for encouraging compilers to tail-call
2584 optimise.
2585
2586 =for apidoc Am|void|Zero|void* dest|int nitems|type
2587
2588 The XSUB-writer's interface to the C C<memzero> function.  The C<dest> is the
2589 destination, C<nitems> is the number of items, and C<type> is the type.
2590
2591 =for apidoc Am|void *|ZeroD|void* dest|int nitems|type
2592
2593 Like C<Zero> but returns dest.  Useful
2594 for encouraging compilers to tail-call
2595 optimise.
2596
2597 =for apidoc_section $utility
2598 =for apidoc Amu|void|StructCopy|type *src|type *dest|type
2599 This is an architecture-independent macro to copy one structure to another.
2600
2601 =for apidoc Am|void|PoisonWith|void* dest|int nitems|type|U8 byte
2602
2603 Fill up memory with a byte pattern (a byte repeated over and over
2604 again) that hopefully catches attempts to access uninitialized memory.
2605
2606 =for apidoc Am|void|PoisonNew|void* dest|int nitems|type
2607
2608 PoisonWith(0xAB) for catching access to allocated but uninitialized memory.
2609
2610 =for apidoc Am|void|PoisonFree|void* dest|int nitems|type
2611
2612 PoisonWith(0xEF) for catching access to freed memory.
2613
2614 =for apidoc Am|void|Poison|void* dest|int nitems|type
2615
2616 PoisonWith(0xEF) for catching access to freed memory.
2617
2618 =cut */
2619
2620 /* Maintained for backwards-compatibility only. Use newSV() instead. */
2621 #ifndef PERL_CORE
2622 #define NEWSV(x,len)    newSV(len)
2623 #endif
2624
2625 #define MEM_SIZE_MAX ((MEM_SIZE)-1)
2626
2627 #define _PERL_STRLEN_ROUNDUP_UNCHECKED(n) (((n) - 1 + PERL_STRLEN_ROUNDUP_QUANTUM) & ~((MEM_SIZE)PERL_STRLEN_ROUNDUP_QUANTUM - 1))
2628
2629 #ifdef PERL_MALLOC_WRAP
2630
2631 /* This expression will be constant-folded at compile time.  It checks
2632  * whether or not the type of the count n is so small (e.g. U8 or U16, or
2633  * U32 on 64-bit systems) that there's no way a wrap-around could occur.
2634  * As well as avoiding the need for a run-time check in some cases, it's
2635  * designed to avoid compiler warnings like:
2636  *     comparison is always false due to limited range of data type
2637  * It's mathematically equivalent to
2638  *    max(n) * sizeof(t) > MEM_SIZE_MAX
2639  */
2640
2641 #  define _MEM_WRAP_NEEDS_RUNTIME_CHECK(n,t) \
2642     (  sizeof(MEM_SIZE) < sizeof(n) \
2643     || sizeof(t) > ((MEM_SIZE)1 << 8*(sizeof(MEM_SIZE) - sizeof(n))))
2644
2645 /* This is written in a slightly odd way to avoid various spurious
2646  * compiler warnings. We *want* to write the expression as
2647  *    _MEM_WRAP_NEEDS_RUNTIME_CHECK(n,t) && (n > C)
2648  * (for some compile-time constant C), but even when the LHS
2649  * constant-folds to false at compile-time, g++ insists on emitting
2650  * warnings about the RHS (e.g. "comparison is always false"), so instead
2651  * we write it as
2652  *
2653  *    (cond ? n : X) > C
2654  *
2655  * where X is a constant with X > C always false. Choosing a value for X
2656  * is tricky. If 0, some compilers will complain about 0 > C always being
2657  * false; if 1, Coverity complains when n happens to be the constant value
2658  * '1', that cond ? 1 : 1 has the same value on both branches; so use C
2659  * for X and hope that nothing else whines.
2660  */
2661
2662 #  define _MEM_WRAP_WILL_WRAP(n,t) \
2663       ((_MEM_WRAP_NEEDS_RUNTIME_CHECK(n,t) ? (MEM_SIZE)(n) : \
2664             MEM_SIZE_MAX/sizeof(t)) > MEM_SIZE_MAX/sizeof(t))
2665
2666 #  define MEM_WRAP_CHECK(n,t) \
2667         (void)(UNLIKELY(_MEM_WRAP_WILL_WRAP(n,t)) \
2668         && (croak_memory_wrap(),0))
2669
2670 #  define MEM_WRAP_CHECK_1(n,t,a) \
2671         (void)(UNLIKELY(_MEM_WRAP_WILL_WRAP(n,t)) \
2672         && (Perl_croak_nocontext("%s",(a)),0))
2673
2674 /* "a" arg must be a string literal */
2675 #  define MEM_WRAP_CHECK_s(n,t,a) \
2676         (   (void) (UNLIKELY(_MEM_WRAP_WILL_WRAP(n,t))          \
2677          && (Perl_croak_nocontext(ASSERT_IS_LITERAL(a)), 0)))
2678
2679 #define MEM_WRAP_CHECK_(n,t) MEM_WRAP_CHECK(n,t),
2680
2681 #define PERL_STRLEN_ROUNDUP(n) ((void)(((n) > MEM_SIZE_MAX - 2 * PERL_STRLEN_ROUNDUP_QUANTUM) ? (croak_memory_wrap(),0) : 0), _PERL_STRLEN_ROUNDUP_UNCHECKED(n))
2682 #else
2683
2684 #define MEM_WRAP_CHECK(n,t)
2685 #define MEM_WRAP_CHECK_1(n,t,a)
2686 #define MEM_WRAP_CHECK_s(n,t,a)
2687 #define MEM_WRAP_CHECK_(n,t)
2688
2689 #define PERL_STRLEN_ROUNDUP(n) _PERL_STRLEN_ROUNDUP_UNCHECKED(n)
2690
2691 #endif
2692
2693 #ifdef PERL_MEM_LOG
2694 /*
2695  * If PERL_MEM_LOG is defined, all Newx()s, Renew()s, and Safefree()s
2696  * go through functions, which are handy for debugging breakpoints, but
2697  * which more importantly get the immediate calling environment (file and
2698  * line number, and C function name if available) passed in.  This info can
2699  * then be used for logging the calls, for which one gets a sample
2700  * implementation unless -DPERL_MEM_LOG_NOIMPL is also defined.
2701  *
2702  * Known problems:
2703  * - not all memory allocs get logged, only those
2704  *   that go through Newx() and derivatives (while all
2705  *   Safefrees do get logged)
2706  * - __FILE__ and __LINE__ do not work everywhere
2707  * - __func__ or __FUNCTION__ even less so
2708  * - I think more goes on after the perlio frees but
2709  *   the thing is that STDERR gets closed (as do all
2710  *   the file descriptors)
2711  * - no deeper calling stack than the caller of the Newx()
2712  *   or the kind, but do I look like a C reflection/introspection
2713  *   utility to you?
2714  * - the function prototypes for the logging functions
2715  *   probably should maybe be somewhere else than handy.h
2716  * - one could consider inlining (macrofying) the logging
2717  *   for speed, but I am too lazy
2718  * - one could imagine recording the allocations in a hash,
2719  *   (keyed by the allocation address?), and maintain that
2720  *   through reallocs and frees, but how to do that without
2721  *   any News() happening...?
2722  * - lots of -Ddefines to get useful/controllable output
2723  * - lots of ENV reads
2724  */
2725
2726 # ifdef PERL_CORE
2727 #  ifndef PERL_MEM_LOG_NOIMPL
2728 enum mem_log_type {
2729   MLT_ALLOC,
2730   MLT_REALLOC,
2731   MLT_FREE,
2732   MLT_NEW_SV,
2733   MLT_DEL_SV
2734 };
2735 #  endif
2736 #  if defined(PERL_IN_SV_C)  /* those are only used in sv.c */
2737 void Perl_mem_log_new_sv(const SV *sv, const char *filename, const int linenumber, const char *funcname);
2738 void Perl_mem_log_del_sv(const SV *sv, const char *filename, const int linenumber, const char *funcname);
2739 #  endif
2740 # endif
2741
2742 #endif
2743
2744 #ifdef PERL_MEM_LOG
2745 #define MEM_LOG_ALLOC(n,t,a)     Perl_mem_log_alloc(n,sizeof(t),STRINGIFY(t),a,__FILE__,__LINE__,FUNCTION__)
2746 #define MEM_LOG_REALLOC(n,t,v,a) Perl_mem_log_realloc(n,sizeof(t),STRINGIFY(t),v,a,__FILE__,__LINE__,FUNCTION__)
2747 #define MEM_LOG_FREE(a)          Perl_mem_log_free(a,__FILE__,__LINE__,FUNCTION__)
2748 #endif
2749
2750 #ifndef MEM_LOG_ALLOC
2751 #define MEM_LOG_ALLOC(n,t,a)     (a)
2752 #endif
2753 #ifndef MEM_LOG_REALLOC
2754 #define MEM_LOG_REALLOC(n,t,v,a) (a)
2755 #endif
2756 #ifndef MEM_LOG_FREE
2757 #define MEM_LOG_FREE(a)          (a)
2758 #endif
2759
2760 #define Newx(v,n,t)     (v = (MEM_WRAP_CHECK_(n,t) (t*)MEM_LOG_ALLOC(n,t,safemalloc((MEM_SIZE)((n)*sizeof(t))))))
2761 #define Newxc(v,n,t,c)  (v = (MEM_WRAP_CHECK_(n,t) (c*)MEM_LOG_ALLOC(n,t,safemalloc((MEM_SIZE)((n)*sizeof(t))))))
2762 #define Newxz(v,n,t)    (v = (MEM_WRAP_CHECK_(n,t) (t*)MEM_LOG_ALLOC(n,t,safecalloc((n),sizeof(t)))))
2763
2764 #ifndef PERL_CORE
2765 /* pre 5.9.x compatibility */
2766 #define New(x,v,n,t)    Newx(v,n,t)
2767 #define Newc(x,v,n,t,c) Newxc(v,n,t,c)
2768 #define Newz(x,v,n,t)   Newxz(v,n,t)
2769 #endif
2770
2771 #define Renew(v,n,t) \
2772           (v = (MEM_WRAP_CHECK_(n,t) (t*)MEM_LOG_REALLOC(n,t,v,saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))))
2773 #define Renewc(v,n,t,c) \
2774           (v = (MEM_WRAP_CHECK_(n,t) (c*)MEM_LOG_REALLOC(n,t,v,saferealloc((Malloc_t)(v),(MEM_SIZE)((n)*sizeof(t))))))
2775
2776 #ifdef PERL_POISON
2777 #define Safefree(d) \
2778   ((d) ? (void)(safefree(MEM_LOG_FREE((Malloc_t)(d))), Poison(&(d), 1, Malloc_t)) : (void) 0)
2779 #else
2780 #define Safefree(d)     safefree(MEM_LOG_FREE((Malloc_t)(d)))
2781 #endif
2782
2783 /* assert that a valid ptr has been supplied - use this instead of assert(ptr)  *
2784  * as it handles cases like constant string arguments without throwing warnings *
2785  * the cast is required, as is the inequality check, to avoid warnings          */
2786 #define perl_assert_ptr(p) assert( ((void*)(p)) != 0 )
2787
2788
2789 #define Move(s,d,n,t)   (MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), perl_assert_ptr(s), (void)memmove((char*)(d),(const char*)(s), (n) * sizeof(t)))
2790 #define Copy(s,d,n,t)   (MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), perl_assert_ptr(s), (void)memcpy((char*)(d),(const char*)(s), (n) * sizeof(t)))
2791 #define Zero(d,n,t)     (MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), (void)memzero((char*)(d), (n) * sizeof(t)))
2792
2793 /* Like above, but returns a pointer to 'd' */
2794 #define MoveD(s,d,n,t)  (MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), perl_assert_ptr(s), memmove((char*)(d),(const char*)(s), (n) * sizeof(t)))
2795 #define CopyD(s,d,n,t)  (MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), perl_assert_ptr(s), memcpy((char*)(d),(const char*)(s), (n) * sizeof(t)))
2796 #define ZeroD(d,n,t)    (MEM_WRAP_CHECK_(n,t) perl_assert_ptr(d), memzero((char*)(d), (n) * sizeof(t)))
2797
2798 #define PoisonWith(d,n,t,b)     (MEM_WRAP_CHECK_(n,t) (void)memset((char*)(d), (U8)(b), (n) * sizeof(t)))
2799 #define PoisonNew(d,n,t)        PoisonWith(d,n,t,0xAB)
2800 #define PoisonFree(d,n,t)       PoisonWith(d,n,t,0xEF)
2801 #define Poison(d,n,t)           PoisonFree(d,n,t)
2802
2803 #ifdef PERL_POISON
2804 #  define PERL_POISON_EXPR(x) x
2805 #else
2806 #  define PERL_POISON_EXPR(x)
2807 #endif
2808
2809 /* Shallow copy */
2810 #define StructCopy(s,d,t) (*((t*)(d)) = *((t*)(s)))
2811
2812 /*
2813 =for apidoc_section $utility
2814
2815 =for apidoc Am|STRLEN|C_ARRAY_LENGTH|void *a
2816
2817 Returns the number of elements in the input C array (so you want your
2818 zero-based indices to be less than but not equal to).
2819
2820 =for apidoc Am|void *|C_ARRAY_END|void *a
2821
2822 Returns a pointer to one element past the final element of the input C array.
2823
2824 =cut
2825
2826 C_ARRAY_END is one past the last: half-open/half-closed range, not
2827 last-inclusive range.
2828 */
2829 #define C_ARRAY_LENGTH(a)       (sizeof(a)/sizeof((a)[0]))
2830 #define C_ARRAY_END(a)          ((a) + C_ARRAY_LENGTH(a))
2831
2832 #ifdef NEED_VA_COPY
2833 # ifdef va_copy
2834 #  define Perl_va_copy(s, d) va_copy(d, s)
2835 # elif defined(__va_copy)
2836 #  define Perl_va_copy(s, d) __va_copy(d, s)
2837 # else
2838 #  define Perl_va_copy(s, d) Copy(s, d, 1, va_list)
2839 # endif
2840 #endif
2841
2842 /* convenience debug macros */
2843 #ifdef USE_ITHREADS
2844 #define pTHX_FORMAT  "Perl interpreter: 0x%p"
2845 #define pTHX__FORMAT ", Perl interpreter: 0x%p"
2846 #define pTHX_VALUE_   (void *)my_perl,
2847 #define pTHX_VALUE    (void *)my_perl
2848 #define pTHX__VALUE_ ,(void *)my_perl,
2849 #define pTHX__VALUE  ,(void *)my_perl
2850 #else
2851 #define pTHX_FORMAT
2852 #define pTHX__FORMAT
2853 #define pTHX_VALUE_
2854 #define pTHX_VALUE
2855 #define pTHX__VALUE_
2856 #define pTHX__VALUE
2857 #endif /* USE_ITHREADS */
2858
2859 /* Perl_deprecate was not part of the public API, and did not have a deprecate()
2860    shortcut macro defined without -DPERL_CORE. Neither codesearch.google.com nor
2861    CPAN::Unpack show any users outside the core.  */
2862 #ifdef PERL_CORE
2863 #  define deprecate(s) Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED),    \
2864                                             "Use of " s " is deprecated")
2865 #  define deprecate_disappears_in(when,message) \
2866               Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED),    \
2867                                message " is deprecated, and will disappear in Perl " when)
2868 #  define deprecate_fatal_in(when,message) \
2869               Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED),    \
2870                                message " is deprecated, and will become fatal in Perl " when)
2871 #endif
2872
2873 /* Internal macros to deal with gids and uids */
2874 #ifdef PERL_CORE
2875
2876 #  if Uid_t_size > IVSIZE
2877 #    define sv_setuid(sv, uid)       sv_setnv((sv), (NV)(uid))
2878 #    define SvUID(sv)                SvNV(sv)
2879 #  elif Uid_t_sign <= 0
2880 #    define sv_setuid(sv, uid)       sv_setiv((sv), (IV)(uid))
2881 #    define SvUID(sv)                SvIV(sv)
2882 #  else
2883 #    define sv_setuid(sv, uid)       sv_setuv((sv), (UV)(uid))
2884 #    define SvUID(sv)                SvUV(sv)
2885 #  endif /* Uid_t_size */
2886
2887 #  if Gid_t_size > IVSIZE
2888 #    define sv_setgid(sv, gid)       sv_setnv((sv), (NV)(gid))
2889 #    define SvGID(sv)                SvNV(sv)
2890 #  elif Gid_t_sign <= 0
2891 #    define sv_setgid(sv, gid)       sv_setiv((sv), (IV)(gid))
2892 #    define SvGID(sv)                SvIV(sv)
2893 #  else
2894 #    define sv_setgid(sv, gid)       sv_setuv((sv), (UV)(gid))
2895 #    define SvGID(sv)                SvUV(sv)
2896 #  endif /* Gid_t_size */
2897
2898 #endif
2899
2900 #endif  /* PERL_HANDY_H_ */
2901
2902 /*
2903  * ex: set ts=8 sts=4 sw=4 et:
2904  */