xref: /openbsd/gnu/usr.bin/perl/perl.h (revision 3d61058a)
1 /*    perl.h
2  *
3  *    Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
4  *    2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 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 #ifndef H_PERL
12 #define H_PERL 1
13 
14 #if defined(__HP_cc) || defined(__HP_aCC)
15 /* The HPUX compiler for Itanium is very picky and warns about
16  * things that gcc doesn't and that we would prefer it does not.
17  * So on that platform silence certain warnings unlaterally. */
18 
19 /* silence "relational operator ">" always evaluates to 'false'"
20  * warnings. We get a LOT of these from the memwrap checks. */
21 #pragma diag_suppress 4276
22 
23 /* silence "may cause misaligned access" warnings from our "OO in C"
24  * type logic. we do this a lot and if it was broken we would fail tests
25  * all over the place */
26 #pragma diag_suppress 4232
27 
28 #endif /* end HPUX warning disablement */
29 
30 #ifdef PERL_FOR_X2P
31 /*
32  * This file is being used for x2p stuff.
33  * Above symbol is defined via -D in 'x2p/Makefile.SH'
34  * Decouple x2p stuff from some of perls more extreme eccentricities.
35  */
36 #undef MULTIPLICITY
37 #undef USE_STDIO
38 #define USE_STDIO
39 #endif /* PERL_FOR_X2P */
40 
41 /* Treat the SVs on the argument stack as having been reference counted.
42  * (Experimental).
43  */
44 /* #define PERL_RC_STACK */
45 
46 #include "config.h"
47 
48 /* This fakes up using Mingw for locale handling.  In order to not define WIN32
49  * in this file (and hence throughout the code that isn't expecting it), this
50  * doesn't define that, but defines the appropriate things that would otherwise
51  * be defined later in the file.  Hence those and here must be kept in sync */
52 #ifdef WIN32_USE_FAKE_OLD_MINGW_LOCALES
53 #  define UINT  unsigned int
54 #  undef USE_THREAD_SAFE_LOCALE
55 #  define NO_POSIX_2008_LOCALE
56 #  undef HAS_NL_LANGINFO
57 #  undef HAS_NL_LANGINFO_L
58 #  undef _UCRT
59 #  ifdef USE_LOCALE
60 #    define TS_W32_BROKEN_LOCALECONV
61 #    ifdef USE_THREADS
62 #      define EMULATE_THREAD_SAFE_LOCALES
63 #    endif
64 #  endif
65 #endif
66 
67 /*
68 =for apidoc_section $debugging
69 =for apidoc CmnW ||comma_aDEPTH
70 Some functions when compiled under DEBUGGING take an extra final argument named
71 C<depth>, indicating the C stack depth.  This argument is omitted otherwise.
72 This macro expands to either S<C<, depth>> under DEBUGGING, or to nothing at
73 all when not under DEBUGGING, reducing the number of C<#ifdef>'s in the code.
74 
75 The program is responsible for maintaining the correct value for C<depth>.
76 
77 =for apidoc CyW ||comma_pDEPTH
78 This is used in the prototype declarations for functions that take a L</C<comma_aDEPTH>>
79 final parameter, much like L<C<pTHX_>|perlguts/Background and MULTIPLICITY>
80 is used in functions that take a thread context initial parameter.
81 
82 =for apidoc CmnW ||debug_aDEPTH
83 Same as L</C<comma_aDEPTH>> but with no leading argument. Intended for functions with
84 no normal arguments, and used by L</C<comma_aDEPTH>> itself.
85 
86 =for apidoc CmnW ||debug_pDEPTH
87 Same as L</C<comma_pDEPTH>> but with no leading argument. Intended for functions with
88 no normal arguments, and used by L</C<comma_pDEPTH>> itself.
89 
90 =cut
91  */
92 
93 #ifdef DEBUGGING
94 #  define debug_pDEPTH U32 depth
95 #  define comma_pDEPTH ,debug_pDEPTH
96 #  define debug_aDEPTH depth
97 #  define comma_aDEPTH ,debug_aDEPTH
98 #else
99 #  define debug_aDEPTH
100 #  define comma_aDEPTH
101 #  define debug_pDEPTH
102 #  define comma_pDEPTH
103 #endif
104 
105 /* NOTE 1: that with gcc -std=c89 the __STDC_VERSION__ is *not* defined
106  * because the __STDC_VERSION__ became a thing only with C90.  Therefore,
107  * with gcc, HAS_C99 will never become true as long as we use -std=c89.
108 
109  * NOTE 2: headers lie.  Do not expect that if HAS_C99 gets to be true,
110  * all the C99 features are there and are correct. */
111 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
112     defined(_STDC_C99) || defined(__c99)
113 #  define HAS_C99 1
114 #endif
115 
116 /* =========================================================================
117  * The defines from here to the following ===== line are unfortunately
118  * duplicated in makedef.pl, and changes here MUST also be made there */
119 
120 /* See L<perlguts/"The Perl API"> for detailed notes on
121  * MULTIPLICITY and PERL_IMPLICIT_SYS */
122 
123 #ifdef USE_THREADS
124 #  if !defined(MULTIPLICITY)
125 #    define MULTIPLICITY
126 #  endif
127 #endif
128 
129 /* PERL_IMPLICIT_CONTEXT is a legacy synonym for MULTIPLICITY */
130 #if defined(MULTIPLICITY)               \
131  && ! defined(PERL_CORE)                \
132  && ! defined(PERL_IMPLICIT_CONTEXT)
133 #  define PERL_IMPLICIT_CONTEXT
134 #endif
135 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(MULTIPLICITY)
136 #  define MULTIPLICITY
137 #endif
138 #if defined(PERL_CORE) && defined(PERL_IMPLICIT_CONTEXT)
139 #  pragma message("PERL_IMPLICIT_CONTEXT was removed from core perl. It does not do anything. Undeffing it for compilation")
140 #  undef PERL_IMPLICIT_CONTEXT
141 #endif
142 
143 /* undef WIN32 when building on Cygwin (for libwin32) - gph */
144 #ifdef __CYGWIN__
145 #   undef WIN32
146 #   undef _WIN32
147 #endif
148 
149 /* Use the reentrant APIs like localtime_r and getpwent_r */
150 /* Win32 has naturally threadsafe libraries, no need to use any _r variants.
151  * XXX KEEP makedef.pl copy of this code in sync */
152 #if defined(MULTIPLICITY) && !defined(USE_REENTRANT_API) && !defined(WIN32)
153 #   define USE_REENTRANT_API
154 #endif
155 
156 /* end of makedef.pl logic duplication.  But there are other groups below.
157  * ========================================================================= */
158 
159 /*
160 =for apidoc_section $directives
161 =for apidoc AmnUu|void|EXTERN_C
162 When not compiling using C++, expands to nothing.
163 Otherwise is used in a declaration of a function to indicate the function
164 should have external C linkage.  This is required for things to work for just
165 about all functions with external linkage compiled into perl.
166 Often, you can use C<L</START_EXTERN_C>> ... C<L</END_EXTERN_C>> blocks
167 surrounding all your code that you need to have this linkage.
168 
169 Example usage:
170 
171  EXTERN_C int flock(int fd, int op);
172 
173 =for apidoc Amnu||START_EXTERN_C
174 When not compiling using C++, expands to nothing.
175 Otherwise begins a section of code in which every function will effectively
176 have C<L</EXTERN_C>> applied to it, that is to have external C linkage.  The
177 section is ended by a C<L</END_EXTERN_C>>.
178 
179 =for apidoc Amnu||END_EXTERN_C
180 When not compiling using C++, expands to nothing.
181 Otherwise ends a section of code already begun by a C<L</START_EXTERN_C>>.
182 
183 =cut
184 */
185 
186 #undef START_EXTERN_C
187 #undef END_EXTERN_C
188 #undef EXTERN_C
189 #ifdef __cplusplus
190 #  define EXTERN_C extern "C"
191 #  define START_EXTERN_C EXTERN_C {
192 #  define END_EXTERN_C }
193 #else
194 #  define START_EXTERN_C
195 #  define END_EXTERN_C
196 #  define EXTERN_C extern
197 #endif
198 
199 /* Fallback definitions in case we don't have definitions from config.h.
200    This should only matter for systems that don't use Configure and
201    haven't been modified to define PERL_STATIC_INLINE yet.
202 */
203 #if !defined(PERL_STATIC_INLINE)
204 #  ifdef HAS_STATIC_INLINE
205 #    define PERL_STATIC_INLINE static inline
206 #  else
207 #    define PERL_STATIC_INLINE static
208 #  endif
209 #endif
210 
211 /*
212 =for apidoc_section $concurrency
213 =for apidoc AmU|void|dTHXa|PerlInterpreter * a
214 On threaded perls, set C<pTHX> to C<a>; on unthreaded perls, do nothing
215 
216 =for apidoc AmU|void|dTHXoa|PerlInterpreter * a
217 Now a synonym for C<L</dTHXa>>.
218 
219 =cut
220 */
221 
222 #ifdef MULTIPLICITY
223 #  define tTHX	PerlInterpreter*
224 #  define pTHX  tTHX my_perl PERL_UNUSED_DECL
225 #  define aTHX	my_perl
226 #  define aTHXa(a) aTHX = (tTHX)a
227 #  define dTHXa(a)	pTHX = (tTHX)a
228 #  define dTHX		pTHX = PERL_GET_THX
229 #  define pTHX_		pTHX,
230 #  define aTHX_		aTHX,
231 #  define pTHX_1	2
232 #  define pTHX_2	3
233 #  define pTHX_3	4
234 #  define pTHX_4	5
235 #  define pTHX_5	6
236 #  define pTHX_6	7
237 #  define pTHX_7	8
238 #  define pTHX_8	9
239 #  define pTHX_9	10
240 #  define pTHX_12	13
241 #  if defined(DEBUGGING) && !defined(PERL_TRACK_MEMPOOL)
242 #    define PERL_TRACK_MEMPOOL
243 #  endif
244 #else
245 #  undef PERL_TRACK_MEMPOOL
246 #endif
247 
248 #ifdef DEBUGGING
249 #  define dTHX_DEBUGGING dTHX
250 #else
251 #  define dTHX_DEBUGGING dNOOP
252 #endif
253 
254 #define STATIC static
255 
256 #ifndef PERL_CORE
257 /* Do not use these macros. They were part of PERL_OBJECT, which was an
258  * implementation of multiplicity using C++ objects. They have been left
259  * here solely for the sake of XS code which has incorrectly
260  * cargo-culted them.
261  *
262  * The only one Devel::PPPort handles is this; list it as deprecated
263 
264 =for apidoc_section $concurrency
265 =for apidoc AmD|void|CPERLscope|void x
266 Now a no-op.
267 
268 =cut
269  */
270 #  define CPERLscope(x) x
271 #  define CPERLarg void
272 #  define CPERLarg_
273 #  define _CPERLarg
274 #  define PERL_OBJECT_THIS
275 #  define _PERL_OBJECT_THIS
276 #  define PERL_OBJECT_THIS_
277 #  define CALL_FPTR(fptr) (*fptr)
278 #  define MEMBER_TO_FPTR(name) name
279 #endif /* !PERL_CORE */
280 
281 #ifdef PERL_RC_STACK
282 #  define CALLRUNOPS  Perl_runops_wrap
283 #else
284 #  define CALLRUNOPS  PL_runops
285 #endif
286 
287 #define CALLREGCOMP(sv, flags) Perl_pregcomp(aTHX_ (sv),(flags))
288 
289 #define CALLREGCOMP_ENG(prog, sv, flags) (prog)->comp(aTHX_ sv, flags)
290 #define CALLREGEXEC(prog,stringarg,strend,strbeg,minend,sv,data,flags) \
291     RX_ENGINE(prog)->exec(aTHX_ (prog),(stringarg),(strend), \
292         (strbeg),(minend),(sv),(data),(flags))
293 #define CALLREG_INTUIT_START(prog,sv,strbeg,strpos,strend,flags,data) \
294     RX_ENGINE(prog)->intuit(aTHX_ (prog), (sv), (strbeg), (strpos), \
295         (strend),(flags),(data))
296 #define CALLREG_INTUIT_STRING(prog) \
297     RX_ENGINE(prog)->checkstr(aTHX_ (prog))
298 
299 #define CALLREGFREE(prog) \
300     Perl_pregfree(aTHX_ (prog))
301 
302 #define CALLREGFREE_PVT(prog) \
303     if(prog && RX_ENGINE(prog)) RX_ENGINE(prog)->rxfree(aTHX_ (prog))
304 
305 #define CALLREG_NUMBUF_FETCH(rx,paren,usesv)                                \
306     RX_ENGINE(rx)->numbered_buff_FETCH(aTHX_ (rx),(paren),(usesv))
307 
308 #define CALLREG_NUMBUF_STORE(rx,paren,value) \
309     RX_ENGINE(rx)->numbered_buff_STORE(aTHX_ (rx),(paren),(value))
310 
311 #define CALLREG_NUMBUF_LENGTH(rx,sv,paren)                              \
312     RX_ENGINE(rx)->numbered_buff_LENGTH(aTHX_ (rx),(sv),(paren))
313 
314 #define CALLREG_NAMED_BUFF_FETCH(rx, key, flags) \
315     RX_ENGINE(rx)->named_buff(aTHX_ (rx), (key), NULL, ((flags) | RXapif_FETCH))
316 
317 #define CALLREG_NAMED_BUFF_STORE(rx, key, value, flags) \
318     RX_ENGINE(rx)->named_buff(aTHX_ (rx), (key), (value), ((flags) | RXapif_STORE))
319 
320 #define CALLREG_NAMED_BUFF_DELETE(rx, key, flags) \
321     RX_ENGINE(rx)->named_buff(aTHX_ (rx),(key), NULL, ((flags) | RXapif_DELETE))
322 
323 #define CALLREG_NAMED_BUFF_CLEAR(rx, flags) \
324     RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, ((flags) | RXapif_CLEAR))
325 
326 #define CALLREG_NAMED_BUFF_EXISTS(rx, key, flags) \
327     RX_ENGINE(rx)->named_buff(aTHX_ (rx), (key), NULL, ((flags) | RXapif_EXISTS))
328 
329 #define CALLREG_NAMED_BUFF_FIRSTKEY(rx, flags) \
330     RX_ENGINE(rx)->named_buff_iter(aTHX_ (rx), NULL, ((flags) | RXapif_FIRSTKEY))
331 
332 #define CALLREG_NAMED_BUFF_NEXTKEY(rx, lastkey, flags) \
333     RX_ENGINE(rx)->named_buff_iter(aTHX_ (rx), (lastkey), ((flags) | RXapif_NEXTKEY))
334 
335 #define CALLREG_NAMED_BUFF_SCALAR(rx, flags) \
336     RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, ((flags) | RXapif_SCALAR))
337 
338 #define CALLREG_NAMED_BUFF_COUNT(rx) \
339     RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, RXapif_REGNAMES_COUNT)
340 
341 #define CALLREG_NAMED_BUFF_ALL(rx, flags) \
342     RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, flags)
343 
344 #define CALLREG_PACKAGE(rx) \
345     RX_ENGINE(rx)->qr_package(aTHX_ (rx))
346 
347 #if defined(USE_ITHREADS)
348 #  define CALLREGDUPE(prog,param) \
349     Perl_re_dup(aTHX_ (prog),(param))
350 
351 #  define CALLREGDUPE_PVT(prog,param) \
352     (prog ? RX_ENGINE(prog)->dupe(aTHX_ (prog),(param)) \
353           : (REGEXP *)NULL)
354 #endif
355 
356 /* some compilers impersonate gcc */
357 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
358 #  define PERL_IS_GCC 1
359 #endif
360 
361 #define PERL_GCC_VERSION_GE(major,minor,patch)                              \
362     (((100000 * __GNUC__) + (1000 * __GNUC_MINOR__) + __GNUC_PATCHLEVEL__)  \
363         >= ((100000 * (major)) + (1000 * (minor)) + (patch)))
364 #define PERL_GCC_VERSION_GT(major,minor,patch)                              \
365     (((100000 * __GNUC__) + (1000 * __GNUC_MINOR__) + __GNUC_PATCHLEVEL__)  \
366         > ((100000 * (major)) + (1000 * (minor)) + (patch)))
367 #define PERL_GCC_VERSION_LE(major,minor,patch)                              \
368     (((100000 * __GNUC__) + (1000 * __GNUC_MINOR__) + __GNUC_PATCHLEVEL__)  \
369         <= ((100000 * (major)) + (1000 * (minor)) + (patch)))
370 #define PERL_GCC_VERSION_LT(major,minor,patch)                              \
371     (((100000 * __GNUC__) + (1000 * __GNUC_MINOR__) + __GNUC_PATCHLEVEL__)  \
372         < ((100000 * (major)) + (1000 * (minor)) + (patch)))
373 
374 /* In case Configure was not used (we are using a "canned config"
375  * such as Win32, or a cross-compilation setup, for example) try going
376  * by the gcc major and minor versions.  One useful URL is
377  * http://www.ohse.de/uwe/articles/gcc-attributes.html,
378  * but contrary to this information warn_unused_result seems
379  * not to be in gcc 3.3.5, at least. --jhi
380  * Also, when building extensions with an installed perl, this allows
381  * the user to upgrade gcc and get the right attributes, rather than
382  * relying on the list generated at Configure time.  --AD
383  * Set these up now otherwise we get confused when some of the <*thread.h>
384  * includes below indirectly pull in <perlio.h> (which needs to know if we
385  * have HASATTRIBUTE_FORMAT).
386  */
387 
388 #if defined __GNUC__ && !defined(__INTEL_COMPILER)
389 #  if PERL_GCC_VERSION_GE(3,1,0)
390 #    define HASATTRIBUTE_DEPRECATED
391 #  endif
392 #  if PERL_GCC_VERSION_GE(3,0,0)  /* XXX Verify this version */
393 #    define HASATTRIBUTE_FORMAT
394 #    if defined __MINGW32__
395 #      define PRINTF_FORMAT_NULL_OK
396 #    endif
397 #  endif
398 #  if PERL_GCC_VERSION_GE(3,0,0)
399 #    define HASATTRIBUTE_MALLOC
400 #  endif
401 #  if PERL_GCC_VERSION_GE(3,3,0)
402 #    define HASATTRIBUTE_NONNULL
403 #  endif
404 #  if PERL_GCC_VERSION_GE(2,5,0)
405 #    define HASATTRIBUTE_NORETURN
406 #  endif
407 #  if PERL_GCC_VERSION_GE(3,0,0)
408 #    define HASATTRIBUTE_PURE
409 #  endif
410 #  if PERL_GCC_VERSION_GE(3,4,0)
411 #    define HASATTRIBUTE_UNUSED
412 #  endif
413 #  if __GNUC__ == 3 && __GNUC_MINOR__ == 3 && !defined(__cplusplus)
414 #    define HASATTRIBUTE_UNUSED /* gcc-3.3, but not g++-3.3. */
415 #  endif
416 #  if PERL_GCC_VERSION_GE(3,4,0)
417 #    define HASATTRIBUTE_WARN_UNUSED_RESULT
418 #  endif
419    /* always_inline is buggy in gcc <= 4.6 and causes compilation errors */
420 #  if PERL_GCC_VERSION_GE(4,7,0)
421 #    define HASATTRIBUTE_ALWAYS_INLINE
422 #  endif
423 #  if PERL_GCC_VERSION_GE(3,3,0)
424 #    define HASATTRIBUTE_VISIBILITY
425 #  endif
426 #endif
427 
428 #ifdef HASATTRIBUTE_DEPRECATED
429 #  define __attribute__deprecated__         __attribute__((deprecated))
430 #endif
431 #ifdef HASATTRIBUTE_FORMAT
432 #  define __attribute__format__(x,y,z)      __attribute__((format(x,y,z)))
433 #endif
434 #ifdef HASATTRIBUTE_MALLOC
435 #  define __attribute__malloc__             __attribute__((__malloc__))
436 #endif
437 #ifdef HASATTRIBUTE_NONNULL
438 #  define __attribute__nonnull__(a)         __attribute__((nonnull(a)))
439 #endif
440 #ifdef HASATTRIBUTE_NORETURN
441 #  define __attribute__noreturn__           __attribute__((noreturn))
442 #endif
443 #ifdef HASATTRIBUTE_PURE
444 #  define __attribute__pure__               __attribute__((pure))
445 #endif
446 #ifdef HASATTRIBUTE_UNUSED
447 #  define __attribute__unused__             __attribute__((unused))
448 #endif
449 #ifdef HASATTRIBUTE_WARN_UNUSED_RESULT
450 #  define __attribute__warn_unused_result__ __attribute__((warn_unused_result))
451 #endif
452 #ifdef HASATTRIBUTE_ALWAYS_INLINE
453 /* always_inline is buggy in gcc <= 4.6 and causes compilation errors */
454 #  if !defined(PERL_IS_GCC) || PERL_GCC_VERSION_GE(4,7,0)
455 #    define __attribute__always_inline__      __attribute__((always_inline))
456 #  endif
457 #endif
458 #if defined(HASATTRIBUTE_VISIBILITY) && !defined(_WIN32) && !defined(__CYGWIN__)
459 /* On Windows instead of this, we use __declspec(dllexport) and a .def file
460  * Cygwin works by exporting every global symbol, see the definition of ldflags
461  * near the end of hints/cygwin.sh and the visibility attribute doesn't appear
462  * to control that.
463  */
464 #  define __attribute__visibility__(x) __attribute__((visibility(x)))
465 #endif
466 
467 /* If we haven't defined the attributes yet, define them to blank. */
468 #ifndef __attribute__deprecated__
469 #  define __attribute__deprecated__
470 #endif
471 #ifndef __attribute__format__
472 #  define __attribute__format__(x,y,z)
473 #endif
474 #ifndef __attribute__malloc__
475 #  define __attribute__malloc__
476 #endif
477 #ifndef __attribute__nonnull__
478 #  define __attribute__nonnull__(a)
479 #endif
480 #ifndef __attribute__noreturn__
481 #  define __attribute__noreturn__
482 #endif
483 #ifndef __attribute__pure__
484 #  define __attribute__pure__
485 #endif
486 #ifndef __attribute__unused__
487 #  define __attribute__unused__
488 #endif
489 #ifndef __attribute__warn_unused_result__
490 #  define __attribute__warn_unused_result__
491 #endif
492 #ifndef __attribute__always_inline__
493 #  define __attribute__always_inline__
494 #endif
495 #ifndef __attribute__visibility__
496 #  define __attribute__visibility__(x)
497 #endif
498 
499 /* Some OS warn on NULL format to printf */
500 #ifdef PRINTF_FORMAT_NULL_OK
501 #  define __attribute__format__null_ok__(x,y,z)  __attribute__format__(x,y,z)
502 #else
503 #  define __attribute__format__null_ok__(x,y,z)
504 #endif
505 
506 /*
507  * Because of backward compatibility reasons the PERL_UNUSED_DECL
508  * cannot be changed from postfix to PERL_UNUSED_DECL(x).  Sigh.
509  *
510  * Note that there are C compilers such as MetroWerks CodeWarrior
511  * which do not have an "inlined" way (like the gcc __attribute__) of
512  * marking unused variables (they need e.g. a #pragma) and therefore
513  * cpp macros like PERL_UNUSED_DECL cannot work for this purpose, even
514  * if it were PERL_UNUSED_DECL(x), which it cannot be (see above).
515 */
516 
517 /*
518 =for apidoc_section $directives
519 =for apidoc AmnU||PERL_UNUSED_DECL
520 Tells the compiler that the parameter in the function prototype just before it
521 is not necessarily expected to be used in the function.  Not that many
522 compilers understand this, so this should only be used in cases where
523 C<L</PERL_UNUSED_ARG>> can't conveniently be used.
524 
525 Example usage:
526 
527 =over
528 
529  Signal_t
530  Perl_perly_sighandler(int sig, Siginfo_t *sip PERL_UNUSED_DECL,
531                        void *uap PERL_UNUSED_DECL, bool safe)
532 
533 =back
534 
535 =cut
536 */
537 
538 #ifndef PERL_UNUSED_DECL
539 #  define PERL_UNUSED_DECL __attribute__unused__
540 #endif
541 
542 /* gcc -Wall:
543  * for silencing unused variables that are actually used most of the time,
544  * but we cannot quite get rid of, such as "ax" in PPCODE+noargs xsubs,
545  * or variables/arguments that are used only in certain configurations.
546  */
547 /*
548 =for apidoc Am;||PERL_UNUSED_ARG|void x
549 This is used to suppress compiler warnings that a parameter to a function is
550 not used.  This situation can arise, for example, when a parameter is needed
551 under some configuration conditions, but not others, so that C preprocessor
552 conditional compilation causes it be used just sometimes.
553 
554 =for apidoc Amn;||PERL_UNUSED_CONTEXT
555 This is used to suppress compiler warnings that the thread context parameter to
556 a function is not used.  This situation can arise, for example, when a
557 C preprocessor conditional compilation causes it be used just some times.
558 
559 =for apidoc Am;||PERL_UNUSED_VAR|void x
560 This is used to suppress compiler warnings that the variable I<x> is not used.
561 This situation can arise, for example, when a C preprocessor conditional
562 compilation causes it be used just some times.
563 
564 =cut
565 */
566 #ifndef PERL_UNUSED_ARG
567 #  define PERL_UNUSED_ARG(x) ((void)sizeof(x))
568 #endif
569 #ifndef PERL_UNUSED_VAR
570 #  define PERL_UNUSED_VAR(x) ((void)sizeof(x))
571 #endif
572 
573 #if defined(MULTIPLICITY)
574 #  define PERL_UNUSED_CONTEXT PERL_UNUSED_ARG(my_perl)
575 #else
576 #  define PERL_UNUSED_CONTEXT
577 #endif
578 
579 /* gcc (-ansi) -pedantic doesn't allow gcc statement expressions,
580  * g++ allows them but seems to have problems with them
581  * (insane errors ensue).
582  * g++ does not give insane errors now (RMB 2008-01-30, gcc 4.2.2).
583  */
584 #if defined(PERL_GCC_PEDANTIC) || \
585     (defined(__GNUC__) && defined(__cplusplus) && \
586         (PERL_GCC_VERSION_LT(4,2,0)))
587 #  ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN
588 #    define PERL_GCC_BRACE_GROUPS_FORBIDDEN
589 #  endif
590 #endif
591 
592 /*
593 
594 =for apidoc Am||PERL_UNUSED_RESULT|void x
595 
596 This macro indicates to discard the return value of the function call inside
597 it, I<e.g.>,
598 
599  PERL_UNUSED_RESULT(foo(a, b))
600 
601 The main reason for this is that the combination of C<gcc -Wunused-result>
602 (part of C<-Wall>) and the C<__attribute__((warn_unused_result))> cannot
603 be silenced with casting to C<void>.  This causes trouble when the system
604 header files use the attribute.
605 
606 Use C<PERL_UNUSED_RESULT> sparingly, though, since usually the warning
607 is there for a good reason: you might lose success/failure information,
608 or leak resources, or changes in resources.
609 
610 But sometimes you just want to ignore the return value, I<e.g.>, on
611 codepaths soon ending up in abort, or in "best effort" attempts,
612 or in situations where there is no good way to handle failures.
613 
614 Sometimes C<PERL_UNUSED_RESULT> might not be the most natural way:
615 another possibility is that you can capture the return value
616 and use C<L</PERL_UNUSED_VAR>> on that.
617 
618 =cut
619 
620 The __typeof__() is used instead of typeof() since typeof() is not
621 available under strict ISO C, and because of compilers masquerading
622 as gcc (clang and icc), we want exactly the gcc extension
623 __typeof__ and nothing else.
624 
625 */
626 #ifndef PERL_UNUSED_RESULT
627 #  if defined(__GNUC__) && defined(HASATTRIBUTE_WARN_UNUSED_RESULT)
628 #    define PERL_UNUSED_RESULT(v) STMT_START { __typeof__(v) z = (v); (void)sizeof(z); } STMT_END
629 #  else
630 #    define PERL_UNUSED_RESULT(v) ((void)(v))
631 #  endif
632 #endif
633 
634 /* on gcc (and clang), specify that a warning should be temporarily
635  * ignored; e.g.
636  *
637  *    GCC_DIAG_IGNORE_DECL(-Wmultichar);
638  *    char b = 'ab';
639  *    GCC_DIAG_RESTORE_DECL;
640  *
641  * based on http://dbp-consulting.com/tutorials/SuppressingGCCWarnings.html
642  *
643  * Note that "pragma GCC diagnostic push/pop" was added in GCC 4.6, Mar 2011;
644  * clang only pretends to be GCC 4.2, but still supports push/pop.
645  *
646  * Note on usage: all macros must be used at a place where a declaration
647  * or statement can occur, i.e., not in the middle of an expression.
648  * *_DIAG_IGNORE() and *_DIAG_RESTORE can be used in any such place, but
649  * must be used without a following semicolon.  *_DIAG_IGNORE_DECL() and
650  * *_DIAG_RESTORE_DECL must be used with a following semicolon, and behave
651  * syntactically as declarations (like dNOOP).  *_DIAG_IGNORE_STMT()
652  * and *_DIAG_RESTORE_STMT must be used with a following semicolon,
653  * and behave syntactically as statements (like NOOP).
654  *
655  */
656 
657 #if defined(__clang__) || defined(__clang) || PERL_GCC_VERSION_GE(4,6,0)
658 #  define GCC_DIAG_PRAGMA(x) _Pragma (#x)
659 /* clang has "clang diagnostic" pragmas, but also understands gcc. */
660 #  define GCC_DIAG_IGNORE(x) _Pragma("GCC diagnostic push") \
661                              GCC_DIAG_PRAGMA(GCC diagnostic ignored #x)
662 #  define GCC_DIAG_RESTORE   _Pragma("GCC diagnostic pop")
663 #else
664 #  define GCC_DIAG_IGNORE(w)
665 #  define GCC_DIAG_RESTORE
666 #endif
667 #define GCC_DIAG_IGNORE_DECL(x) GCC_DIAG_IGNORE(x) dNOOP
668 #define GCC_DIAG_RESTORE_DECL GCC_DIAG_RESTORE dNOOP
669 #define GCC_DIAG_IGNORE_STMT(x) GCC_DIAG_IGNORE(x) NOOP
670 #define GCC_DIAG_RESTORE_STMT GCC_DIAG_RESTORE NOOP
671 /* for clang specific pragmas */
672 #if defined(__clang__) || defined(__clang)
673 #  define CLANG_DIAG_PRAGMA(x) _Pragma (#x)
674 #  define CLANG_DIAG_IGNORE(x) _Pragma("clang diagnostic push") \
675                                CLANG_DIAG_PRAGMA(clang diagnostic ignored #x)
676 #  define CLANG_DIAG_RESTORE   _Pragma("clang diagnostic pop")
677 #else
678 #  define CLANG_DIAG_IGNORE(w)
679 #  define CLANG_DIAG_RESTORE
680 #endif
681 #define CLANG_DIAG_IGNORE_DECL(x) CLANG_DIAG_IGNORE(x) dNOOP
682 #define CLANG_DIAG_RESTORE_DECL CLANG_DIAG_RESTORE dNOOP
683 #define CLANG_DIAG_IGNORE_STMT(x) CLANG_DIAG_IGNORE(x) NOOP
684 #define CLANG_DIAG_RESTORE_STMT CLANG_DIAG_RESTORE NOOP
685 
686 #if defined(_MSC_VER)
687 #  define MSVC_DIAG_IGNORE(x) __pragma(warning(push)) \
688                               __pragma(warning(disable : x))
689 #  define MSVC_DIAG_RESTORE   __pragma(warning(pop))
690 #else
691 #  define MSVC_DIAG_IGNORE(x)
692 #  define MSVC_DIAG_RESTORE
693 #endif
694 #define MSVC_DIAG_IGNORE_DECL(x) MSVC_DIAG_IGNORE(x) dNOOP
695 #define MSVC_DIAG_RESTORE_DECL MSVC_DIAG_RESTORE dNOOP
696 #define MSVC_DIAG_IGNORE_STMT(x) MSVC_DIAG_IGNORE(x) NOOP
697 #define MSVC_DIAG_RESTORE_STMT MSVC_DIAG_RESTORE NOOP
698 
699 /*
700 =for apidoc Amn;||NOOP
701 Do nothing; typically used as a placeholder to replace something that used to
702 do something.
703 
704 =for apidoc Amn;||dNOOP
705 Declare nothing; typically used as a placeholder to replace something that used
706 to declare something.  Works on compilers that require declarations before any
707 code.
708 
709 =cut
710 */
711 #define NOOP ((void)0)
712 #define dNOOP struct Perl___notused_struct
713 
714 #ifndef pTHX
715 /* Don't bother defining tTHX ; using it outside
716  * code guarded by MULTIPLICITY is an error.
717  */
718 #  define pTHX		void
719 #  define pTHX_
720 #  define aTHX
721 #  define aTHX_
722 #  define aTHXa(a)      NOOP
723 #  define dTHXa(a)	dNOOP
724 #  define dTHX		dNOOP
725 #  define pTHX_1	1
726 #  define pTHX_2	2
727 #  define pTHX_3	3
728 #  define pTHX_4	4
729 #  define pTHX_5	5
730 #  define pTHX_6	6
731 #  define pTHX_7	7
732 #  define pTHX_8	8
733 #  define pTHX_9	9
734 #  define pTHX_12	12
735 #endif
736 
737 /*
738 =for apidoc_section $concurrency
739 =for apidoc AmnU||dVAR
740 This is now a synonym for dNOOP: declare nothing
741 
742 =for apidoc_section $XS
743 =for apidoc Amn;||dMY_CXT_SV
744 Now a placeholder that declares nothing
745 
746 =cut
747 */
748 
749 #ifndef PERL_CORE
750     /* Backwards compatibility macro for XS code. It used to be part of the
751      * PERL_GLOBAL_STRUCT(_PRIVATE) feature, which no longer exists */
752 #  define dVAR		dNOOP
753 
754     /* these are only defined for compatibility; should not be used internally.
755      * */
756 #  define dMY_CXT_SV    dNOOP
757 #  ifndef pTHXo
758 #    define pTHXo		pTHX
759 #    define pTHXo_	pTHX_
760 #    define aTHXo		aTHX
761 #    define aTHXo_	aTHX_
762 #    define dTHXo		dTHX
763 #    define dTHXoa(x)	dTHXa(x)
764 #  endif
765 #endif
766 
767 #ifndef pTHXx
768 #  define pTHXx		PerlInterpreter *my_perl
769 #  define pTHXx_	pTHXx,
770 #  define aTHXx		my_perl
771 #  define aTHXx_	aTHXx,
772 #  define dTHXx		dTHX
773 #endif
774 
775 /* Under PERL_IMPLICIT_SYS (used in Windows for fork emulation)
776  * PerlIO_foo() expands to PL_StdIO->pFOO(PL_StdIO, ...).
777  * dTHXs is therefore needed for all functions using PerlIO_foo(). */
778 #ifdef PERL_IMPLICIT_SYS
779 #    define dTHXs		dTHX
780 #else
781 #    define dTHXs		dNOOP
782 #endif
783 
784 #if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__cplusplus)
785 #  ifndef PERL_USE_GCC_BRACE_GROUPS
786 #    define PERL_USE_GCC_BRACE_GROUPS
787 #  endif
788 #endif
789 
790 /*
791 =for apidoc_section $directives
792 =for apidoc AmnUu|void|STMT_END
793 =for apidoc_item |    |STMT_START
794 
795 These allow a series of statements in a macro to be used as a single statement,
796 as in
797 
798  if (x) STMT_START { ... } STMT_END else ...
799 
800 Note that you can't return a value out of this construct and cannot use it as
801 an operand to the comma operator.  These limit its utility.
802 
803 But, a value could be returned by constructing the API so that a pointer is
804 passed and the macro dereferences this to set the return.  If the value can be
805 any of various types, depending on context, you can handle that situation in
806 some situations by adding the type of the return as an extra accompanying
807 parameter:
808 
809  #define foo(param, type)  STMT_START {
810                               type * param; *param = do_calc; ...
811                            } STMT_END
812 
813 This could be awkward, so consider instead using a C language C<static inline>
814 function.
815 
816 If you do use this construct, it is easy to forget that it is a macro and not a
817 function, and hence fall into traps that might not show up until someone
818 someday writes code which contains names that clash with the ones you chose
819 here, or calls it with a parameter which is an expression with side effects,
820 the consequences of which you didn't think about.  See L<perlhacktips/Writing
821 safer macros> for how to avoid these.
822 
823 =for apidoc_section $genconfig
824 =for apidoc Amn#||PERL_USE_GCC_BRACE_GROUPS
825 
826 This C pre-processor value, if defined, indicates that it is permissible to use
827 the GCC brace groups extension.  However, use of this extension is DISCOURAGED.
828 Use a C<static inline> function instead.
829 
830 The extension, of the form
831 
832  ({ statement ... })
833 
834 turns the block consisting of I<statement ...> into an expression with a
835 value, unlike plain C language blocks.  This can present optimization
836 possibilities, B<BUT>, unless you know for sure that this will never be
837 compiled without this extension being available and not forbidden, you need to
838 specify an alternative.  Thus two code paths have to be maintained, which can
839 get out-of-sync.  All these issues are solved by using a C<static inline>
840 function instead.
841 
842 Perl can be configured to not use this feature by passing the parameter
843 C<-Accflags=-DPERL_GCC_BRACE_GROUPS_FORBIDDEN> to F<Configure>.
844 
845 =for apidoc Amnh#||PERL_GCC_BRACE_GROUPS_FORBIDDEN
846 
847 Example usage:
848 
849 =over
850 
851  #ifdef PERL_USE_GCC_BRACE_GROUPS
852    ...
853  #else
854    ...
855  #endif
856 
857 =back
858 
859 =cut
860 
861  Trying to select a version that gives no warnings...
862 */
863 #if !(defined(STMT_START) && defined(STMT_END))
864 #   define STMT_START	do
865 #   define STMT_END	while (0)
866 #endif
867 
868 #ifndef BYTEORDER  /* Should never happen -- byteorder is in config.h */
869 #   define BYTEORDER 0x1234
870 #endif
871 
872 /*
873 =for apidoc_section $genconfig
874 =for apidoc Amn#||ASCIIish
875 
876 A preprocessor symbol that is defined iff the system is an ASCII platform; this
877 symbol would not be defined on C<L</EBCDIC>> platforms.
878 
879 =cut
880 */
881 #if 'A' == 65 && 'I' == 73 && 'J' == 74 && 'Z' == 90
882 #  define ASCIIish
883 #else
884 #  undef  ASCIIish
885 #endif
886 
887 /*
888  * The following contortions are brought to you on behalf of all the
889  * standards, semi-standards, de facto standards, not-so-de-facto standards
890  * of the world, as well as all the other botches anyone ever thought of.
891  * The basic theory is that if we work hard enough here, the rest of the
892  * code can be a lot prettier.  Well, so much for theory.  Sorry, Henry...
893  */
894 
895 /* define this once if either system, instead of cluttering up the src */
896 #if defined(WIN32)
897 #define DOSISH 1
898 #endif
899 
900 /* These exist only for back-compat with XS modules. */
901 #ifndef PERL_CORE
902 #define VOL volatile
903 #define CAN_PROTOTYPE
904 #define _(args) args
905 #define I_LIMITS
906 #define I_STDARG
907 #define STANDARD_C
908 #endif
909 
910 /* Don't compile 'code' if PERL_MEM_LOG is defined.  This is used for
911  * constructs that don't play well when PERL_MEM_LOG is active, so that they
912  * automatically don't get compiled without having to use extra #ifdef's */
913 #ifndef PERL_MEM_LOG
914 #  define UNLESS_PERL_MEM_LOG(code)  code
915 #else
916 #  define UNLESS_PERL_MEM_LOG(code)
917 #endif
918 
919 /* By compiling a perl with -DNO_TAINT_SUPPORT or -DSILENT_NO_TAINT_SUPPORT,
920  * you get a perl without taint support, but doubtlessly with a lesser
921  * degree of support. Do not do so unless you know exactly what it means
922  * technically, have a good reason to do so, and know exactly how the
923  * perl will be used. perls with -DSILENT_NO_TAINT_SUPPORT are considered
924  * a potential security risk due to flat out ignoring the security-relevant
925  * taint flags. This being said, a perl without taint support compiled in
926  * has marginal run-time performance benefits.
927  * SILENT_NO_TAINT_SUPPORT implies NO_TAINT_SUPPORT.
928  * SILENT_NO_TAINT_SUPPORT is the same as NO_TAINT_SUPPORT except it
929  * silently ignores -t/-T instead of throwing an exception.
930  *
931  * DANGER! Using NO_TAINT_SUPPORT or SILENT_NO_TAINT_SUPPORT
932  *         voids your nonexistent warranty!
933  */
934 #if defined(SILENT_NO_TAINT_SUPPORT) && !defined(NO_TAINT_SUPPORT)
935 #  define NO_TAINT_SUPPORT 1
936 #endif
937 
938 /* NO_TAINT_SUPPORT can be set to transform virtually all taint-related
939  * operations into no-ops for a very modest speed-up. Enable only if you
940  * know what you're doing: tests and CPAN modules' tests are bound to fail.
941  */
942 #ifdef NO_TAINT_SUPPORT
943 #   define TAINT		NOOP
944 #   define TAINT_NOT		NOOP
945 #   define TAINT_IF(c)		NOOP
946 #   define TAINT_ENV()		NOOP
947 #   define TAINT_PROPER(s)	NOOP
948 #   define TAINT_set(s)		NOOP
949 #   define TAINT_get		0
950 #   define TAINTING_get		0
951 #   define TAINTING_set(s)	NOOP
952 #   define TAINT_WARN_get       0
953 #   define TAINT_WARN_set(s)    NOOP
954 #else
955 
956 /*
957 =for apidoc_section $tainting
958 =for apidoc Cm|void|TAINT
959 
960 If we aren't in taint checking mode, do nothing;
961 otherwise indicate to L</C<TAINT_set>> and L</C<TAINT_PROPER>> that some
962 unspecified element is tainted.
963 
964 =for apidoc Cm|void|TAINT_NOT
965 
966 Remove any taintedness previously set by, I<e.g.>, C<TAINT>.
967 
968 =for apidoc Cm|void|TAINT_IF|bool c
969 
970 If C<c> evaluates to true, call L</C<TAINT>> to indicate that something is
971 tainted; otherwise do nothing.
972 
973 =for apidoc Cmn|void|TAINT_ENV
974 
975 Looks at several components of L<C<%ENV>|perlvar/%ENV> for taintedness, and
976 calls L</C<taint_proper>> if any are tainted.  The components it searches are
977 things like C<$PATH>.
978 
979 =for apidoc Cm|void|TAINT_PROPER|const char * s
980 
981 If no element is tainted, do nothing;
982 otherwise output a message (containing C<s>) that indicates there is a
983 tainting violation.  If such violations are fatal, it croaks.
984 
985 =for apidoc Cm|void|TAINT_set|bool s
986 
987 If C<s> is true, L</C<TAINT_get>> returns true;
988 If C<s> is false, L</C<TAINT_get>> returns false;
989 
990 =for apidoc Cm|bool|TAINT_get
991 
992 Returns a boolean as to whether some element is tainted or not.
993 
994 =for apidoc Cm|bool|TAINTING_get
995 
996 Returns a boolean as to whether taint checking is enabled or not.
997 
998 =for apidoc Cm|void|TAINTING_set|bool s
999 
1000 Turn taint checking mode off/on
1001 
1002 =for apidoc Cm|bool|TAINT_WARN_get
1003 
1004 Returns false if tainting violations are fatal;
1005 Returns true if they're just warnings
1006 
1007 =for apidoc Cm|void|TAINT_WARN_set|bool s
1008 
1009 C<s> being true indicates L</C<TAINT_WARN_get>> should return that tainting
1010 violations are just warnings
1011 
1012 C<s> being false indicates L</C<TAINT_WARN_get>> should return that tainting
1013 violations are fatal.
1014 
1015 =cut
1016 */
1017     /* Set to tainted if we are running under tainting mode */
1018 #   define TAINT		(PL_tainted = PL_tainting)
1019 
1020 #   define TAINT_NOT	(PL_tainted = FALSE)        /* Untaint */
1021 #   define TAINT_IF(c)	if (UNLIKELY(c)) { TAINT; } /* Conditionally taint */
1022 #   define TAINT_ENV()	if (UNLIKELY(PL_tainting)) { taint_env(); }
1023                                 /* croak or warn if tainting */
1024 #   define TAINT_PROPER(s)	if (UNLIKELY(PL_tainting)) {                \
1025                                     taint_proper(NULL, s);                  \
1026                                 }
1027 #   define TAINT_set(s)		(PL_tainted = cBOOL(s))
1028 #   define TAINT_get		(cBOOL(UNLIKELY(PL_tainted)))    /* Is something tainted? */
1029 #   define TAINTING_get		(cBOOL(UNLIKELY(PL_tainting)))
1030 #   define TAINTING_set(s)	(PL_tainting = cBOOL(s))
1031 #   define TAINT_WARN_get       (PL_taint_warn)
1032 #   define TAINT_WARN_set(s)    (PL_taint_warn = cBOOL(s))
1033 #endif
1034 
1035 /* flags used internally only within pp_subst and pp_substcont */
1036 #ifdef PERL_CORE
1037 #  define SUBST_TAINT_STR      1	/* string tainted */
1038 #  define SUBST_TAINT_PAT      2	/* pattern tainted */
1039 #  define SUBST_TAINT_REPL     4	/* replacement tainted */
1040 #  define SUBST_TAINT_RETAINT  8	/* use re'taint' in scope */
1041 #  define SUBST_TAINT_BOOLRET 16	/* return is boolean (don't taint) */
1042 #endif
1043 
1044 /* XXX All process group stuff is handled in pp_sys.c.  Should these
1045    defines move there?  If so, I could simplify this a lot. --AD  9/96.
1046 */
1047 /* Process group stuff changed from traditional BSD to POSIX.
1048    perlfunc.pod documents the traditional BSD-style syntax, so we'll
1049    try to preserve that, if possible.
1050 */
1051 #ifdef HAS_SETPGID
1052 #  define BSD_SETPGRP(pid, pgrp)	setpgid((pid), (pgrp))
1053 #elif defined(HAS_SETPGRP) && defined(USE_BSD_SETPGRP)
1054 #  define BSD_SETPGRP(pid, pgrp)	setpgrp((pid), (pgrp))
1055 #elif defined(HAS_SETPGRP2)
1056 #  define BSD_SETPGRP(pid, pgrp)	setpgrp2((pid), (pgrp))
1057 #endif
1058 #if defined(BSD_SETPGRP) && !defined(HAS_SETPGRP)
1059 #  define HAS_SETPGRP  /* Well, effectively it does . . . */
1060 #endif
1061 
1062 #ifdef HAS_GETPGID
1063 #  define BSD_GETPGRP(pid)		getpgid((pid))
1064 #elif defined(HAS_GETPGRP) && defined(USE_BSD_GETPGRP)
1065 #  define BSD_GETPGRP(pid)		getpgrp((pid))
1066 #elif defined(HAS_GETPGRP2)
1067 #  define BSD_GETPGRP(pid)		getpgrp2((pid))
1068 #endif
1069 #if defined(BSD_GETPGRP) && !defined(HAS_GETPGRP)
1070 #  define HAS_GETPGRP  /* Well, effectively it does . . . */
1071 #endif
1072 
1073 /* These are not exact synonyms, since setpgrp() and getpgrp() may
1074    have different behaviors, but perl.h used to define USE_BSDPGRP
1075    (prior to 5.003_05) so some extension might depend on it.
1076 */
1077 #if defined(USE_BSD_SETPGRP) || defined(USE_BSD_GETPGRP)
1078 #  ifndef USE_BSDPGRP
1079 #    define USE_BSDPGRP
1080 #  endif
1081 #endif
1082 
1083 /* This define exists only for compatibility. It used to mean "my_setenv and
1084  * friends should use setenv/putenv, instead of manipulating environ directly",
1085  * which is now always the case. It's still defined to prevent XS modules from
1086  * using the no longer existing PL_use_safe_putenv variable.
1087  */
1088 #define PERL_USE_SAFE_PUTENV
1089 
1090 /* Control whether we set and test the stack high water mark.
1091  *
1092  * When enabled this checks that pp funcs and XSUBs properly EXTEND()
1093  * the stack.
1094  *
1095  * Debugging builds have HWM checks on by default, you can add
1096  * -DPERL_NO_HWM to ccflags to prevent those checks, or add
1097  * -DPERL_USE_HWM to ccflags to perform HWM checks even on
1098  * non-debugging builds.
1099  */
1100 
1101 #if defined PERL_NO_HWM
1102 #  undef PERL_USE_HWM
1103 #elif defined PERL_USE_HWM
1104 /* nothing to do here */
1105 #elif defined DEBUGGING && !defined DEBUGGING_RE_ONLY
1106 #  define PERL_USE_HWM
1107 #endif
1108 
1109 
1110 /* HP-UX 10.X CMA (Common Multithreaded Architecture) insists that
1111    pthread.h must be included before all other header files.
1112 */
1113 #if defined(USE_ITHREADS) && defined(PTHREAD_H_FIRST) && defined(I_PTHREAD)
1114 #  include <pthread.h>
1115 #endif
1116 
1117 #include <sys/types.h>
1118 
1119 #  ifdef I_WCHAR
1120 #    include <wchar.h>
1121 #  endif
1122 
1123 # include <stdarg.h>
1124 
1125 #ifdef I_STDINT
1126 # include <stdint.h>
1127 #endif
1128 
1129 #include <ctype.h>
1130 #include <float.h>
1131 #include <limits.h>
1132 
1133 #ifdef METHOD 	/* Defined by OSF/1 v3.0 by ctype.h */
1134 #undef METHOD
1135 #endif
1136 
1137 #ifdef I_LOCALE
1138 #   include <locale.h>
1139 #endif
1140 
1141 #ifdef NEED_XLOCALE_H
1142 #   include <xlocale.h>
1143 #endif
1144 
1145 /* Even if not using locales, this header should be #included so as to #define
1146  * some symbols which avoid #ifdefs to get things to compile.  But make sure
1147  * the macro it calls does nothing */
1148 #undef PERL_LOCALE_TABLE_ENTRY
1149 #define PERL_LOCALE_TABLE_ENTRY(name, call_back)
1150 #include "locale_table.h"
1151 
1152 #include "perl_langinfo.h"    /* Needed for _NL_LOCALE_NAME */
1153 
1154 /* =========================================================================
1155  * The defines from here to the following ===== line are unfortunately
1156  * duplicated in makedef.pl, and changes here MUST also be made there */
1157 
1158 /* If not forbidden, we enable locale handling if either 1) the POSIX 2008
1159  * functions are available, or 2) just the setlocale() function.  This logic is
1160  * repeated in t/loc_tools.pl and makedef.pl;  The three should be kept in
1161  * sync. */
1162 #if   ! defined(NO_LOCALE)
1163 #  if ! defined(NO_POSIX_2008_LOCALE)           \
1164    &&   defined(HAS_NEWLOCALE)                  \
1165    &&   defined(HAS_USELOCALE)                  \
1166    &&   defined(HAS_DUPLOCALE)                  \
1167    &&   defined(HAS_FREELOCALE)                 \
1168    &&   defined(LC_ALL_MASK)
1169 
1170     /* For simplicity, the code is written to assume that any platform advanced
1171      * enough to have the Posix 2008 locale functions has LC_ALL.  The final
1172      * test above makes sure that assumption is valid */
1173 
1174 #    define HAS_POSIX_2008_LOCALE
1175 #    define USE_LOCALE
1176 #  elif defined(HAS_SETLOCALE)
1177 #    define USE_LOCALE
1178 #  endif
1179 #endif
1180 
1181 /* end of makedef.pl logic duplication.  But there are other groups below.
1182  * ========================================================================= */
1183 
1184 #ifdef USE_LOCALE
1185 #   define HAS_SKIP_LOCALE_INIT /* Solely for XS code to test for this
1186                                    #define */
1187 #endif
1188 
1189 /* XXX The Configure probe for categories must be updated when adding new
1190  * categories here */
1191 
1192 /* Create an enum that allows translation between the arbitrary locale category
1193  * integers that a platform has, and our desired values that range from 0..n
1194  * which makes array indexing feasible.
1195  *
1196  * In locale.c, there are a bunch of parallel arrays corresponding to this
1197  * enum.  The first element of each corresponds with the first enum value here,
1198  * and so on.  That means this enum must be in identical order with those
1199  * arrays.  This is guaranteed by using locale_table.h in all instances.
1200  * (There are also asserts in locale.c that should fail if this gets
1201  * out-of-sync.)  So, if the platform doesn't have LC_CTYPE, but does have
1202  * LC_NUMERIC, the code below will cause LC_NUMERIC_INDEX_ to be defined to be
1203  * 0.  That way the foo_INDEX_ values are contiguous non-negative integers,
1204  * regardless of how the platform defines the actual locale categories.
1205  *
1206  * It is possible to tell perl it is not to pay attention to certain categories
1207  * that exist on a platform (which means they are always kept in the "C"
1208  * locale).  For the ones perl is supposed to pay attention to, The hdr file
1209  * creates a 'USE_LOCALE_foo' #define.  If any are to be ignored by perl, it
1210  * #defines HAS_IGNORED_LOCALE_CATEGORIES_ */
1211 typedef enum {
1212 
1213 #ifdef USE_LOCALE
1214 #    undef PERL_LOCALE_TABLE_ENTRY
1215 #    define PERL_LOCALE_TABLE_ENTRY(name, call_back)  LC_ ## name ## _INDEX_,
1216 #    include "locale_table.h"
1217 #endif  /* USE_LOCALE */
1218 
1219     LC_ALL_INDEX_   /* Always defined, even if no LC_ALL on system */
1220 
1221 } locale_category_index;
1222 
1223 #ifdef USE_LOCALE
1224 
1225 /* And a count of all the locale categories, mainly for use in array
1226  * declarations */
1227 #  define LOCALE_CATEGORIES_COUNT_        (LC_ALL_INDEX_ + 1)
1228 
1229 /* As a development aid for platforms that have LC_ALL name=value notation,
1230  * setting -Accflags=-DUSE_FAKE_LC_ALL_POSITIONAL_NOTATION, simulates a
1231  * platform that instead uses positional notation.  By doing this, you can find
1232  * many bugs without trying it out on a real such platform.  It would be
1233  * possible to create the reverse definitions for people who have ready access
1234  * to a posiional notation box, but harder to get a name=value box */
1235 #  if defined(USE_FAKE_LC_ALL_POSITIONAL_NOTATION)            \
1236    && defined(PERL_LC_ALL_USES_NAME_VALUE_PAIRS)
1237 #    undef  PERL_LC_ALL_USES_NAME_VALUE_PAIRS
1238 
1239 #    define  PERL_LC_ALL_CATEGORY_POSITIONS_INIT /* Assumes glibc cateories */\
1240                                   { 12, 11, 10, 9, 8, 7, 5, 4, 3, 2, 1, 0 }
1241 #    define  PERL_LC_ALL_SEPARATOR "/ = /"
1242 #  endif
1243 /* =========================================================================
1244  * The defines from here to the following ===== line are unfortunately
1245  * duplicated in makedef.pl, and changes here MUST also be made there */
1246 
1247 #  if defined(USE_THREADS) && ! defined(NO_LOCALE_THREADS)
1248 #    define USE_LOCALE_THREADS
1249 #  endif
1250 
1251    /* Use POSIX 2008 locales if available, and no alternative exists
1252     * ('setlocale()' is the alternative); or is threaded and not forbidden to
1253     * use them */
1254 #  if (       defined(HAS_POSIX_2008_LOCALE)                                \
1255        && (    ! defined(HAS_SETLOCALE)                                     \
1256            || (     defined(USE_LOCALE_THREADS)                             \
1257                && ! defined(NO_POSIX_2008_LOCALE)))                         \
1258                && ! defined(NO_THREAD_SAFE_LOCALE))
1259 #    define USE_POSIX_2008_LOCALE
1260 #  endif
1261 
1262    /* On threaded builds, use thread-safe locales if they are available and not
1263     * forbidden.  Availability is when we are using POSIX 2008 locales, or
1264     * Windows for any vintage recent enough to have _MSC_VER defined, or are
1265     * using UCRT (principally MINGW in this latter case) */
1266 #  if defined(USE_LOCALE_THREADS) && ! defined(NO_THREAD_SAFE_LOCALE)
1267 #    if  defined(USE_POSIX_2008_LOCALE)                                     \
1268      || (defined(WIN32) && (defined(_MSC_VER) || (defined(_UCRT))))
1269 #      define USE_THREAD_SAFE_LOCALE
1270 #    endif
1271 #  endif
1272 
1273 #  ifdef USE_POSIX_2008_LOCALE
1274 #    if  defined(HAS_QUERYLOCALE)                                           \
1275               /* Use querylocale if has it, or has the glibc internal       \
1276                * undocumented equivalent (if not forbidden). */             \
1277      || (     defined(_NL_LOCALE_NAME)                                      \
1278          && ! defined(NO_USE_NL_LOCALE_NAME)                                \
1279               /* nl_langinfo_l almost certainly will exist on systems that  \
1280                * have _NL_LOCALE_NAME, so there is nothing lost by          \
1281                * requiring it instead of also allowing plain nl_langinfo(). \
1282                * And experience indicates that its glibc implementation is  \
1283                * thread-safe, eliminating code complications */             \
1284          &&   defined(HAS_NL_LANGINFO_L)                                    \
1285                /* On systems that accept any locale name, the real          \
1286                 * underlying locale is often returned by this internal      \
1287                 * langinfo item, so we can't use it */                      \
1288          && ! defined(SETLOCALE_ACCEPTS_ANY_LOCALE_NAME))
1289 #      define USE_QUERYLOCALE
1290 #    endif
1291 #  endif
1292 
1293    /* POSIX 2008 has no means of finding out the current locale without a
1294     * querylocale; so must keep track of it ourselves */
1295 #  if (defined(USE_POSIX_2008_LOCALE) && ! defined(USE_QUERYLOCALE))
1296 #    define USE_PL_CURLOCALES
1297 #  endif
1298 
1299 #  if defined(WIN32)
1300 
1301       /* We need to be able to map the current value of what the tTHX context
1302        * thinks LC_ALL is so as to inform the Windows libc when switching
1303        * contexts. */
1304 #    if defined(USE_THREAD_SAFE_LOCALE)
1305 #      define USE_PL_CUR_LC_ALL
1306 #    endif
1307 
1308      /* Assume MingW without UCRT has the broken localeconv() that Microsoft
1309       * fixed in VS 2015 */
1310 #    if ! defined(_MSC_VER) && ! defined(_UCRT)
1311 #      define TS_W32_BROKEN_LOCALECONV
1312 #    endif
1313 #  endif
1314 
1315    /* POSIX 2008 and Windows with thread-safe locales keep locale information
1316     * in libc data.  Therefore we must inform their libc's when the context
1317     * switches */
1318 #  if defined(MULTIPLICITY) && (   defined(USE_POSIX_2008_LOCALE)           \
1319                                 || (   defined(WIN32)                       \
1320                                     && defined(USE_THREAD_SAFE_LOCALE)))
1321 #    define USE_PERL_SWITCH_LOCALE_CONTEXT
1322 #  endif
1323 #endif  /* End of USE_LOCALE */
1324 
1325 /* end of makedef.pl logic duplication
1326  * ========================================================================= */
1327 
1328 #ifdef PERL_CORE
1329 
1330 /* These typedefs are used in locale.c only (and documented there), but defined
1331  * here so that embed.fnc can generate the proper prototypes. */
1332 
1333 typedef enum {  /* Is the locale UTF8? */
1334     LOCALE_NOT_UTF8,
1335     LOCALE_IS_UTF8,
1336     LOCALE_UTF8NESS_UNKNOWN
1337 } locale_utf8ness_t;
1338 
1339 typedef struct {
1340     const char *name;
1341     size_t offset;
1342 } lconv_offset_t;
1343 
1344 typedef enum {
1345     INTERNAL_FORMAT,
1346     EXTERNAL_FORMAT_FOR_SET,
1347     EXTERNAL_FORMAT_FOR_QUERY
1348 } calc_LC_ALL_format;
1349 
1350 typedef enum {
1351     WANT_VOID,
1352     WANT_TEMP_PV,
1353     WANT_PL_setlocale_buf,
1354 } calc_LC_ALL_return;
1355 
1356 typedef enum {
1357     no_override,
1358     override_if_ignored,
1359     check_that_overridden
1360 } parse_LC_ALL_STRING_action;
1361 
1362 typedef enum {
1363     invalid,
1364     no_array,
1365     only_element_0,
1366     full_array
1367 } parse_LC_ALL_string_return;
1368 
1369 #endif
1370 
1371 #include <setjmp.h>
1372 
1373 #ifdef I_SYS_PARAM
1374 #   ifdef PARAM_NEEDS_TYPES
1375 #	include <sys/types.h>
1376 #   endif
1377 #   include <sys/param.h>
1378 #endif
1379 
1380 /* On BSD-derived systems, <sys/param.h> defines BSD to a year-month
1381    value something like 199306.  This may be useful if no more-specific
1382    feature test is available.
1383 */
1384 #if defined(BSD)
1385 #   ifndef BSDish
1386 #       define BSDish
1387 #   endif
1388 #endif
1389 
1390 /* Use all the "standard" definitions */
1391 #include <stdlib.h>
1392 
1393 /* If this causes problems, set i_unistd=undef in the hint file.  */
1394 #ifdef I_UNISTD
1395 #    if defined(__amigaos4__)
1396 #        ifdef I_NETINET_IN
1397 #            include <netinet/in.h>
1398 #        endif
1399 #   endif
1400 #   include <unistd.h>
1401 #   if defined(__amigaos4__)
1402 /* Under AmigaOS 4 newlib.library provides an environ.  However using
1403  * it doesn't give us enough control over inheritance of variables by
1404  * subshells etc. so replace with custom version based on abc-shell
1405  * code. */
1406 extern char **myenviron;
1407 #       undef environ
1408 #       define environ myenviron
1409 #   endif
1410 #endif
1411 
1412 /* for WCOREDUMP */
1413 #ifdef I_SYS_WAIT
1414 #   include <sys/wait.h>
1415 #endif
1416 
1417 #if defined(HAS_SYSCALL) && !defined(HAS_SYSCALL_PROTO)
1418 EXTERN_C int syscall(int, ...);
1419 #endif
1420 
1421 #if defined(HAS_USLEEP) && !defined(HAS_USLEEP_PROTO)
1422 EXTERN_C int usleep(unsigned int);
1423 #endif
1424 
1425 /* Macros for correct constant construction.  These are in C99 <stdint.h>
1426  * (so they will not be available in strict C89 mode), but they are nice, so
1427  * let's define them if necessary. */
1428 
1429 /*
1430 =for apidoc_section $integer
1431 =for apidoc    Am|I16|INT16_C|number
1432 =for apidoc_item |I32|INT32_C|number
1433 =for apidoc_item |I64|INT64_C|number
1434 
1435 Returns a token the C compiler recognizes for the constant C<number> of the
1436 corresponding integer type on the machine.
1437 
1438 If the machine does not have a 64-bit type, C<INT64_C> is undefined.
1439 Use C<L</INTMAX_C>> to get the largest type available on the platform.
1440 
1441 =for apidoc    Am|U16|UINT16_C|number
1442 =for apidoc_item |U32|UINT32_C|number
1443 =for apidoc_item |U64|UINT64_C|number
1444 
1445 Returns a token the C compiler recognizes for the constant C<number> of the
1446 corresponding unsigned integer type on the machine.
1447 
1448 If the machine does not have a 64-bit type, C<UINT64_C> is undefined.
1449 Use C<L</UINTMAX_C>> to get the largest type available on the platform.
1450 
1451 
1452 =cut
1453 */
1454 #ifndef UINT16_C
1455 #  if INTSIZE >= 2
1456 #    define UINT16_C(x) ((U16_TYPE)x##U)
1457 #  else
1458 #    define UINT16_C(x) ((U16_TYPE)x##UL)
1459 #  endif
1460 #endif
1461 
1462 #ifndef UINT32_C
1463 #  if INTSIZE >= 4
1464 #    define UINT32_C(x) ((U32_TYPE)x##U)
1465 #  else
1466 #    define UINT32_C(x) ((U32_TYPE)x##UL)
1467 #  endif
1468 #endif
1469 
1470 #ifdef I_STDINT
1471     typedef intmax_t  PERL_INTMAX_T;
1472     typedef uintmax_t PERL_UINTMAX_T;
1473 #endif
1474 
1475 /* N.B.  We use QUADKIND here instead of HAS_QUAD here, because that doesn't
1476  * actually mean what it has always been documented to mean (see RT #119753)
1477  * and is explicitly turned off outside of core with dire warnings about
1478  * removing the undef. */
1479 
1480 #if defined(QUADKIND)
1481 #  undef PeRl_INT64_C
1482 #  undef PeRl_UINT64_C
1483 /* Prefer the native integer types (int and long) over long long
1484  * (which is not C89) and Win32-specific __int64. */
1485 #  if QUADKIND == QUAD_IS_INT && INTSIZE == 8
1486 #    define PeRl_INT64_C(c)	(c)
1487 #    define PeRl_UINT64_C(c)	CAT2(c,U)
1488 #  endif
1489 #  if QUADKIND == QUAD_IS_LONG && LONGSIZE == 8
1490 #    define PeRl_INT64_C(c)	CAT2(c,L)
1491 #    define PeRl_UINT64_C(c)	CAT2(c,UL)
1492 #  endif
1493 #  if QUADKIND == QUAD_IS_LONG_LONG && defined(HAS_LONG_LONG)
1494 #    define PeRl_INT64_C(c)	CAT2(c,LL)
1495 #    define PeRl_UINT64_C(c)	CAT2(c,ULL)
1496 #  endif
1497 #  if QUADKIND == QUAD_IS___INT64
1498 #    define PeRl_INT64_C(c)	CAT2(c,I64)
1499 #    define PeRl_UINT64_C(c)	CAT2(c,UI64)
1500 #  endif
1501 #  ifndef PeRl_INT64_C
1502 #    define PeRl_INT64_C(c)	((I64)(c)) /* last resort */
1503 #    define PeRl_UINT64_C(c)	((U64TYPE)(c))
1504 #  endif
1505 /* In OS X the INT64_C/UINT64_C are defined with LL/ULL, which will
1506  * not fly with C89-pedantic gcc, so let's undefine them first so that
1507  * we can redefine them with our native integer preferring versions. */
1508 #  if defined(PERL_DARWIN) && defined(PERL_GCC_PEDANTIC)
1509 #    undef INT64_C
1510 #    undef UINT64_C
1511 #  endif
1512 #  ifndef INT64_C
1513 #    define INT64_C(c) PeRl_INT64_C(c)
1514 #  endif
1515 #  ifndef UINT64_C
1516 #    define UINT64_C(c) PeRl_UINT64_C(c)
1517 #  endif
1518 
1519 /*
1520 =for apidoc_section $integer
1521 =for apidoc Am||INTMAX_C|number
1522 Returns a token the C compiler recognizes for the constant C<number> of the
1523 widest integer type on the machine.  For example, if the machine has C<long
1524 long>s, C<INTMAX_C(-1)> would yield
1525 
1526  -1LL
1527 
1528 See also, for example, C<L</INT32_C>>.
1529 
1530 Use L</IV> to declare variables of the maximum usable size on this platform.
1531 
1532 =for apidoc Am||UINTMAX_C|number
1533 Returns a token the C compiler recognizes for the constant C<number> of the
1534 widest unsigned integer type on the machine.  For example, if the machine has
1535 C<long>s, C<UINTMAX_C(1)> would yield
1536 
1537  1UL
1538 
1539 See also, for example, C<L</UINT32_C>>.
1540 
1541 Use L</UV> to declare variables of the maximum usable size on this platform.
1542 
1543 =cut
1544 */
1545 
1546 #  ifndef I_STDINT
1547     typedef I64TYPE PERL_INTMAX_T;
1548     typedef U64TYPE PERL_UINTMAX_T;
1549 #  endif
1550 #  ifndef INTMAX_C
1551 #    define INTMAX_C(c) INT64_C(c)
1552 #  endif
1553 #  ifndef UINTMAX_C
1554 #    define UINTMAX_C(c) UINT64_C(c)
1555 #  endif
1556 
1557 #else  /* below QUADKIND is undefined */
1558 
1559 /* Perl doesn't work on 16 bit systems, so must be 32 bit */
1560 #  ifndef I_STDINT
1561     typedef I32TYPE PERL_INTMAX_T;
1562     typedef U32TYPE PERL_UINTMAX_T;
1563 #  endif
1564 #  ifndef INTMAX_C
1565 #    define INTMAX_C(c) INT32_C(c)
1566 #  endif
1567 #  ifndef UINTMAX_C
1568 #    define UINTMAX_C(c) UINT32_C(c)
1569 #  endif
1570 
1571 #endif  /* no QUADKIND */
1572 
1573 #ifdef PERL_CORE
1574 
1575 /* byte-swapping functions for big-/little-endian conversion */
1576 # define _swab_16_(x) ((U16)( \
1577          (((U16)(x) & UINT16_C(0x00ff)) << 8) | \
1578          (((U16)(x) & UINT16_C(0xff00)) >> 8) ))
1579 
1580 # define _swab_32_(x) ((U32)( \
1581          (((U32)(x) & UINT32_C(0x000000ff)) << 24) | \
1582          (((U32)(x) & UINT32_C(0x0000ff00)) <<  8) | \
1583          (((U32)(x) & UINT32_C(0x00ff0000)) >>  8) | \
1584          (((U32)(x) & UINT32_C(0xff000000)) >> 24) ))
1585 
1586 # ifdef HAS_QUAD
1587 #  define _swab_64_(x) ((U64)( \
1588           (((U64)(x) & UINT64_C(0x00000000000000ff)) << 56) | \
1589           (((U64)(x) & UINT64_C(0x000000000000ff00)) << 40) | \
1590           (((U64)(x) & UINT64_C(0x0000000000ff0000)) << 24) | \
1591           (((U64)(x) & UINT64_C(0x00000000ff000000)) <<  8) | \
1592           (((U64)(x) & UINT64_C(0x000000ff00000000)) >>  8) | \
1593           (((U64)(x) & UINT64_C(0x0000ff0000000000)) >> 24) | \
1594           (((U64)(x) & UINT64_C(0x00ff000000000000)) >> 40) | \
1595           (((U64)(x) & UINT64_C(0xff00000000000000)) >> 56) ))
1596 # endif
1597 
1598 /* Maximum level of recursion */
1599 #ifndef PERL_SUB_DEPTH_WARN
1600 #define PERL_SUB_DEPTH_WARN 100
1601 #endif
1602 
1603 #endif /* PERL_CORE */
1604 
1605 /* Maximum number of args that may be passed to an OP_MULTICONCAT op.
1606  * It determines the size of local arrays in S_maybe_multiconcat() and
1607  * pp_multiconcat().
1608  */
1609 #define PERL_MULTICONCAT_MAXARG 64
1610 
1611 /* The indexes of fields of a multiconcat aux struct.
1612  * The fixed fields are followed by nargs+1 const segment lengths,
1613  * and if utf8 and non-utf8 differ, a second nargs+1 set for utf8.
1614  */
1615 
1616 #define PERL_MULTICONCAT_IX_NARGS     0 /* number of arguments */
1617 #define PERL_MULTICONCAT_IX_PLAIN_PV  1 /* non-utf8 constant string */
1618 #define PERL_MULTICONCAT_IX_PLAIN_LEN 2 /* non-utf8 constant string length */
1619 #define PERL_MULTICONCAT_IX_UTF8_PV   3 /* utf8 constant string */
1620 #define PERL_MULTICONCAT_IX_UTF8_LEN  4 /* utf8 constant string length */
1621 #define PERL_MULTICONCAT_IX_PADTMP0   5 /* up to 3 pad indexes for PADTMPs */
1622 #define PERL_MULTICONCAT_IX_PADTMP1   6
1623 #define PERL_MULTICONCAT_IX_PADTMP2   7
1624 #define PERL_MULTICONCAT_IX_LENGTHS   8 /* first of nargs+1 const segment lens */
1625 #define PERL_MULTICONCAT_HEADER_SIZE  8 /* The number of fields of a
1626                                            multiconcat header */
1627 
1628 /* We no longer default to creating a new SV for GvSV.
1629    Do this before embed.  */
1630 #ifndef PERL_CREATE_GVSV
1631 #  ifndef PERL_DONT_CREATE_GVSV
1632 #    define PERL_DONT_CREATE_GVSV
1633 #  endif
1634 #endif
1635 
1636 #if !defined(HAS_WAITPID) && !defined(HAS_WAIT4) || defined(HAS_WAITPID_RUNTIME)
1637 #define PERL_USES_PL_PIDSTATUS
1638 #endif
1639 
1640 #if !defined(OS2) && !defined(WIN32)
1641 #define PERL_DEFAULT_DO_EXEC3_IMPLEMENTATION
1642 #endif
1643 
1644 #define MEM_SIZE Size_t
1645 
1646 /* av_extend and analogues enforce a minimum number of array elements.
1647  * This has been 4 elements (so a minimum key size of 3) for a long
1648  * time, but the rationale behind this seems to have been lost to the
1649  * mists of time. */
1650 #ifndef PERL_ARRAY_NEW_MIN_KEY
1651 #define PERL_ARRAY_NEW_MIN_KEY 3
1652 #endif
1653 
1654 /* Functions like Perl_sv_grow mandate a minimum string size.
1655  * This was 10 bytes for a long time, the rationale for which seems lost
1656  * to the mists of time. However, this does not correlate to what modern
1657  * malloc implementations will actually return, in particular the fact
1658  * that chunks are almost certainly some multiple of pointer size. The
1659  * default has therefore been revised to a more useful approximation.
1660  * Notes: The following is specifically conservative for 64 bit, since
1661  * most dlmalloc derivatives seem to serve a 3xPTRSIZE minimum chunk,
1662  * so the below perhaps should be:
1663  *     ((PTRSIZE == 4) ? 12 : 24)
1664  * Configure probes for malloc_good_size, malloc_actual_size etc.
1665  * could be revised to record the actual minimum chunk size, to which
1666  * PERL_STRLEN_NEW_MIN could then be set.
1667  */
1668 #ifndef PERL_STRLEN_NEW_MIN
1669 #define PERL_STRLEN_NEW_MIN ((PTRSIZE == 4) ? 12 : 16)
1670 #endif
1671 
1672 /* Round all values passed to malloc up, by default to a multiple of
1673    sizeof(size_t)
1674 */
1675 #ifndef PERL_STRLEN_ROUNDUP_QUANTUM
1676 #define PERL_STRLEN_ROUNDUP_QUANTUM Size_t_size
1677 #endif
1678 
1679 /* sv_grow() will expand strings by at least a certain percentage of
1680    the previously *used* length to avoid excessive calls to realloc().
1681    The default is 25% of the current length.
1682 */
1683 #ifndef PERL_STRLEN_EXPAND_SHIFT
1684 #  define PERL_STRLEN_EXPAND_SHIFT 2
1685 #endif
1686 
1687 /* This use of offsetof() requires /Zc:offsetof- for VS2017 (and presumably
1688  * onwards) when building Socket.xs, but we can just use a different definition
1689  * for STRUCT_OFFSET instead. */
1690 #if defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1910
1691 #  define STRUCT_OFFSET(s,m)  (Size_t)(&(((s *)0)->m))
1692 #else
1693 #  include <stddef.h>
1694 #  define STRUCT_OFFSET(s,m)  offsetof(s,m)
1695 #endif
1696 
1697 /* ptrdiff_t is C11, so undef it under pedantic builds.  (Actually it is
1698  * in C89, but apparently there are platforms where it doesn't exist.  See
1699  * thread beginning at http://nntp.perl.org/group/perl.perl5.porters/251541.)
1700  * */
1701 #ifdef PERL_GCC_PEDANTIC
1702 #   undef HAS_PTRDIFF_T
1703 #endif
1704 
1705 #ifdef HAS_PTRDIFF_T
1706 #  define Ptrdiff_t ptrdiff_t
1707 #else
1708 #  define Ptrdiff_t SSize_t
1709 #endif
1710 
1711 #  include <string.h>
1712 
1713 /* This comes after <stdlib.h> so we don't try to change the standard
1714  * library prototypes; we'll use our own in proto.h instead. */
1715 
1716 #ifdef MYMALLOC
1717 #  ifdef PERL_POLLUTE_MALLOC
1718 #   ifndef PERL_EXTMALLOC_DEF
1719 #    define Perl_malloc		malloc
1720 #    define Perl_calloc		calloc
1721 #    define Perl_realloc	realloc
1722 #    define Perl_mfree		free
1723 #   endif
1724 #  else
1725 #    define EMBEDMYMALLOC	/* for compatibility */
1726 #  endif
1727 
1728 #  define safemalloc  Perl_malloc
1729 #  define safecalloc  Perl_calloc
1730 #  define saferealloc Perl_realloc
1731 #  define safefree    Perl_mfree
1732 #  define CHECK_MALLOC_TOO_LATE_FOR_(code)	STMT_START {		\
1733         if (!TAINTING_get && MallocCfg_ptr[MallocCfg_cfg_env_read])	\
1734                 code;							\
1735     } STMT_END
1736 #  define CHECK_MALLOC_TOO_LATE_FOR(ch)				\
1737         CHECK_MALLOC_TOO_LATE_FOR_(MALLOC_TOO_LATE_FOR(ch))
1738 #  define panic_write2(s)		write(2, s, strlen(s))
1739 #  define CHECK_MALLOC_TAINT(newval)				\
1740         CHECK_MALLOC_TOO_LATE_FOR_(				\
1741                 if (newval) {					\
1742                   PERL_UNUSED_RESULT(panic_write2("panic: tainting with $ENV{PERL_MALLOC_OPT}\n"));\
1743                   exit(1); })
1744 #  define MALLOC_CHECK_TAINT(argc,argv,env)                     \
1745     STMT_START {                                                \
1746         if (doing_taint(argc,argv,env)) {                       \
1747             MallocCfg_ptr[MallocCfg_skip_cfg_env] = 1;          \
1748         }                                                       \
1749     } STMT_END;
1750 #else  /* MYMALLOC */
1751 #  define safemalloc  safesysmalloc
1752 #  define safecalloc  safesyscalloc
1753 #  define saferealloc safesysrealloc
1754 #  define safefree    safesysfree
1755 #  define CHECK_MALLOC_TOO_LATE_FOR(ch)		((void)0)
1756 #  define CHECK_MALLOC_TAINT(newval)		((void)0)
1757 #  define MALLOC_CHECK_TAINT(argc,argv,env)
1758 #endif /* MYMALLOC */
1759 
1760 /* diag_listed_as: "-T" is on the #! line, it must also be used on the command line */
1761 #define TOO_LATE_FOR_(ch,what)	Perl_croak(aTHX_ "\"-%c\" is on the #! line, it must also be used on the command line%s", (char)(ch), what)
1762 #define TOO_LATE_FOR(ch)	TOO_LATE_FOR_(ch, "")
1763 #define MALLOC_TOO_LATE_FOR(ch)	TOO_LATE_FOR_(ch, " with $ENV{PERL_MALLOC_OPT}")
1764 #define MALLOC_CHECK_TAINT2(argc,argv)	MALLOC_CHECK_TAINT(argc,argv,NULL)
1765 
1766 /*
1767 =for apidoc Am|void|memzero|void * d|Size_t l
1768 Set the C<l> bytes starting at C<*d> to all zeroes.
1769 
1770 =cut
1771 */
1772 #ifndef memzero
1773 #   define memzero(d,l) memset(d,0,l)
1774 #endif
1775 
1776 #ifdef I_NETINET_IN
1777 #   include <netinet/in.h>
1778 #endif
1779 
1780 #ifdef I_ARPA_INET
1781 #   include <arpa/inet.h>
1782 #endif
1783 
1784 #ifdef I_SYS_STAT
1785 #   include <sys/stat.h>
1786 #endif
1787 
1788 /* Microsoft VC's sys/stat.h defines all S_Ixxx macros except S_IFIFO.
1789    This definition should ideally go into win32/win32.h, but S_IFIFO is
1790    used later here in perl.h before win32/win32.h is being included. */
1791 #if !defined(S_IFIFO) && defined(_S_IFIFO)
1792 #   define S_IFIFO _S_IFIFO
1793 #endif
1794 
1795 /* The stat macros for Unisoft System V/88 (and derivatives
1796    like UTekV) are broken, sometimes giving false positives.  Undefine
1797    them here and let the code below set them to proper values.
1798 
1799    The ghs macro stands for GreenHills Software C-1.8.5 which
1800    is the C compiler for sysV88 and the various derivatives.
1801    This header file bug is corrected in gcc-2.5.8 and later versions.
1802    --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94.  */
1803 
1804 #if defined(m88k) && defined(ghs)
1805 #   undef S_ISDIR
1806 #   undef S_ISCHR
1807 #   undef S_ISBLK
1808 #   undef S_ISREG
1809 #   undef S_ISFIFO
1810 #   undef S_ISLNK
1811 #endif
1812 
1813 #include <time.h>
1814 
1815 #ifdef I_SYS_TIME
1816 #   ifdef I_SYS_TIME_KERNEL
1817 #	define KERNEL
1818 #   endif
1819 #   include <sys/time.h>
1820 #   ifdef I_SYS_TIME_KERNEL
1821 #	undef KERNEL
1822 #   endif
1823 #endif
1824 
1825 #if defined(HAS_TIMES) && defined(I_SYS_TIMES)
1826 #    include <sys/times.h>
1827 #endif
1828 
1829 #include <errno.h>
1830 
1831 #if defined(WIN32) && defined(PERL_IMPLICIT_SYS)
1832 #  define WIN32SCK_IS_STDSCK		/* don't pull in custom wsock layer */
1833 #endif
1834 
1835 #if defined(HAS_SOCKET) && !defined(WIN32) /* WIN32 handles sockets via win32.h */
1836 # include <sys/socket.h>
1837 # if defined(USE_SOCKS) && defined(I_SOCKS)
1838 #   if !defined(INCLUDE_PROTOTYPES)
1839 #       define INCLUDE_PROTOTYPES /* for <socks.h> */
1840 #       define PERL_SOCKS_NEED_PROTOTYPES
1841 #   endif
1842 #   include <socks.h>
1843 #   ifdef PERL_SOCKS_NEED_PROTOTYPES /* keep cpp space clean */
1844 #       undef INCLUDE_PROTOTYPES
1845 #       undef PERL_SOCKS_NEED_PROTOTYPES
1846 #   endif
1847 # endif
1848 # ifdef I_NETDB
1849 #  include <netdb.h>
1850 # endif
1851 # ifndef ENOTSOCK
1852 #  ifdef I_NET_ERRNO
1853 #   include <net/errno.h>
1854 #  endif
1855 # endif
1856 #endif
1857 
1858 /* sockatmark() is so new (2001) that many places might have it hidden
1859  * behind some -D_BLAH_BLAH_SOURCE guard.  The __THROW magic is required
1860  * e.g. in Gentoo, see http://bugs.gentoo.org/show_bug.cgi?id=12605 */
1861 #if defined(HAS_SOCKATMARK) && !defined(HAS_SOCKATMARK_PROTO)
1862 # if defined(__THROW) && defined(__GLIBC__)
1863 int sockatmark(int) __THROW;
1864 # else
1865 int sockatmark(int);
1866 # endif
1867 #endif
1868 
1869 #if defined(__osf__) && defined(__cplusplus) && !defined(_XOPEN_SOURCE_EXTENDED) /* Tru64 "cxx" (C++), see hints/dec_osf.sh for why the _XOPEN_SOURCE_EXTENDED cannot be defined. */
1870 EXTERN_C int fchdir(int);
1871 EXTERN_C int flock(int, int);
1872 EXTERN_C int fseeko(FILE *, off_t, int);
1873 EXTERN_C off_t ftello(FILE *);
1874 #endif
1875 
1876 #if defined(__SUNPRO_CC) /* SUNWspro CC (C++) */
1877 EXTERN_C char *crypt(const char *, const char *);
1878 #endif
1879 
1880 #if defined(__cplusplus) && defined(__CYGWIN__)
1881 EXTERN_C char *crypt(const char *, const char *);
1882 #endif
1883 
1884 /*
1885 =for apidoc_section $errno
1886 
1887 =for apidoc m|void|SETERRNO|int errcode|int vmserrcode
1888 
1889 Set C<errno>, and on VMS set C<vaxc$errno>.
1890 
1891 =for apidoc mn|void|dSAVEDERRNO
1892 
1893 Declare variables needed to save C<errno> and any operating system
1894 specific error number.
1895 
1896 =for apidoc mn|void|dSAVE_ERRNO
1897 
1898 Declare variables needed to save C<errno> and any operating system
1899 specific error number, and save them for optional later restoration
1900 by C<RESTORE_ERRNO>.
1901 
1902 =for apidoc mn|void|SAVE_ERRNO
1903 
1904 Save C<errno> and any operating system specific error number for
1905 optional later restoration by C<RESTORE_ERRNO>.  Requires
1906 C<dSAVEDERRNO> or C<dSAVE_ERRNO> in scope.
1907 
1908 =for apidoc mn|void|RESTORE_ERRNO
1909 
1910 Restore C<errno> and any operating system specific error number that
1911 was saved by C<dSAVE_ERRNO> or C<RESTORE_ERRNO>.
1912 
1913 =cut
1914 */
1915 
1916 #ifdef SETERRNO
1917 # undef SETERRNO  /* SOCKS might have defined this */
1918 #endif
1919 
1920 #if defined(VMS) || defined(WIN32) || defined(OS2)
1921 #    define HAS_EXTENDED_OS_ERRNO
1922 #    define get_extended_os_errno()  Perl_get_extended_os_errno()
1923 #  else
1924 #    define get_extended_os_errno()  errno
1925 #  endif
1926 #ifdef VMS
1927 #   define SETERRNO(errcode,vmserrcode) \
1928         STMT_START {			\
1929             set_errno(errcode);		\
1930             set_vaxc_errno(vmserrcode);	\
1931         } STMT_END
1932 #   define dSAVEDERRNO    int saved_errno; unsigned saved_vms_errno
1933 #   define dSAVE_ERRNO    int saved_errno = errno; unsigned saved_vms_errno = vaxc$errno
1934 #   define SAVE_ERRNO     ( saved_errno = errno, saved_vms_errno = vaxc$errno )
1935 #   define RESTORE_ERRNO  SETERRNO(saved_errno, saved_vms_errno)
1936 
1937 #   define LIB_INVARG 		LIB$_INVARG
1938 #   define RMS_DIR    		RMS$_DIR
1939 #   define RMS_FAC    		RMS$_FAC
1940 #   define RMS_FEX    		RMS$_FEX
1941 #   define RMS_FNF    		RMS$_FNF
1942 #   define RMS_IFI    		RMS$_IFI
1943 #   define RMS_ISI    		RMS$_ISI
1944 #   define RMS_PRV    		RMS$_PRV
1945 #   define SS_ACCVIO      	SS$_ACCVIO
1946 #   define SS_DEVOFFLINE	SS$_DEVOFFLINE
1947 #   define SS_IVCHAN  		SS$_IVCHAN
1948 #   define SS_NORMAL  		SS$_NORMAL
1949 #   define SS_NOPRIV  		SS$_NOPRIV
1950 #   define SS_BUFFEROVF		SS$_BUFFEROVF
1951 #else
1952 #   define LIB_INVARG 		0
1953 #   define RMS_DIR    		0
1954 #   define RMS_FAC    		0
1955 #   define RMS_FEX    		0
1956 #   define RMS_FNF    		0
1957 #   define RMS_IFI    		0
1958 #   define RMS_ISI    		0
1959 #   define RMS_PRV    		0
1960 #   define SS_ACCVIO      	0
1961 #   define SS_DEVOFFLINE	0
1962 #   define SS_IVCHAN  		0
1963 #   define SS_NORMAL  		0
1964 #   define SS_NOPRIV  		0
1965 #   define SS_BUFFEROVF		0
1966 #endif
1967 
1968 #ifdef WIN32
1969 #   define dSAVEDERRNO  int saved_errno; DWORD saved_win32_errno
1970 #   define dSAVE_ERRNO  int saved_errno = errno; DWORD saved_win32_errno = GetLastError()
1971 #   define SAVE_ERRNO   ( saved_errno = errno, saved_win32_errno = GetLastError() )
1972 #   define RESTORE_ERRNO ( errno = saved_errno, SetLastError(saved_win32_errno) )
1973 #endif
1974 
1975 #ifdef OS2
1976 #   define dSAVEDERRNO  int saved_errno; unsigned long saved_os2_errno
1977 #   define dSAVE_ERRNO  int saved_errno = errno; unsigned long saved_os2_errno = Perl_rc
1978 #   define SAVE_ERRNO   ( saved_errno = errno, saved_os2_errno = Perl_rc )
1979 #   define RESTORE_ERRNO ( errno = saved_errno, Perl_rc = saved_os2_errno )
1980 #endif
1981 
1982 #ifndef SETERRNO
1983 #   define SETERRNO(errcode,vmserrcode) (errno = (errcode))
1984 #endif
1985 
1986 #ifndef dSAVEDERRNO
1987 #   define dSAVEDERRNO    int saved_errno
1988 #   define dSAVE_ERRNO    int saved_errno = errno
1989 #   define SAVE_ERRNO     (saved_errno = errno)
1990 #   define RESTORE_ERRNO  (errno = saved_errno)
1991 #endif
1992 
1993 /*
1994 =for apidoc_section $warning
1995 
1996 =for apidoc Amn|SV *|ERRSV
1997 
1998 Returns the SV for C<$@>, creating it if needed.
1999 
2000 =for apidoc Am|void|CLEAR_ERRSV
2001 
2002 Clear the contents of C<$@>, setting it to the empty string.
2003 
2004 This replaces any read-only SV with a fresh SV and removes any magic.
2005 
2006 =for apidoc Am|void|SANE_ERRSV
2007 
2008 Clean up ERRSV so we can safely set it.
2009 
2010 This replaces any read-only SV with a fresh writable copy and removes
2011 any magic.
2012 
2013 =cut
2014 */
2015 
2016 #define ERRSV GvSVn(PL_errgv)
2017 
2018 /* contains inlined gv_add_by_type */
2019 #define CLEAR_ERRSV() STMT_START {					\
2020     SV ** const svp = &GvSV(PL_errgv);					\
2021     if (!*svp) {							\
2022         *svp = newSVpvs("");                                            \
2023     } else if (SvREADONLY(*svp)) {					\
2024         SvREFCNT_dec_NN(*svp);						\
2025         *svp = newSVpvs("");						\
2026     } else {								\
2027         SV *const errsv = *svp;						\
2028         SvPVCLEAR(errsv);                                               \
2029         SvPOK_only(errsv);						\
2030         if (SvMAGICAL(errsv)) {						\
2031             mg_free(errsv);						\
2032         }								\
2033     }									\
2034     } STMT_END
2035 
2036 /* contains inlined gv_add_by_type */
2037 #define SANE_ERRSV() STMT_START {					\
2038     SV ** const svp = &GvSV(PL_errgv);					\
2039     if (!*svp) {							\
2040         *svp = newSVpvs("");                                            \
2041     } else if (SvREADONLY(*svp)) {					\
2042         SV *dupsv = newSVsv(*svp);					\
2043         SvREFCNT_dec_NN(*svp);						\
2044         *svp = dupsv;							\
2045     } else {								\
2046         SV *const errsv = *svp;						\
2047         if (SvMAGICAL(errsv)) {						\
2048             mg_free(errsv);						\
2049         }								\
2050     }									\
2051     } STMT_END
2052 
2053 
2054 #ifdef PERL_CORE
2055 # define DEFSV (0 + GvSVn(PL_defgv))
2056 # define DEFSV_set(sv) \
2057     (SvREFCNT_dec(GvSV(PL_defgv)), GvSV(PL_defgv) = SvREFCNT_inc(sv))
2058 # define SAVE_DEFSV                \
2059     (                               \
2060         save_gp(PL_defgv, 0),        \
2061         GvINTRO_off(PL_defgv),        \
2062         SAVEGENERICSV(GvSV(PL_defgv)), \
2063         GvSV(PL_defgv) = NULL           \
2064     )
2065 #else
2066 # define DEFSV GvSVn(PL_defgv)
2067 # define DEFSV_set(sv) (GvSV(PL_defgv) = (sv))
2068 # define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
2069 #endif
2070 
2071 /*
2072 =for apidoc_section $SV
2073 =for apidoc Amn|SV *|DEFSV
2074 Returns the SV associated with C<$_>
2075 
2076 =for apidoc Am|void|DEFSV_set|SV * sv
2077 Associate C<sv> with C<$_>
2078 
2079 =for apidoc Amn|void|SAVE_DEFSV
2080 Localize C<$_>.  See L<perlguts/Localizing changes>.
2081 
2082 =cut
2083 */
2084 
2085 #ifndef errno
2086         extern int errno;     /* ANSI allows errno to be an lvalue expr.
2087                                * For example in multithreaded environments
2088                                * something like this might happen:
2089                                * extern int *_errno(void);
2090                                * #define errno (*_errno()) */
2091 #endif
2092 
2093 #define UNKNOWN_ERRNO_MSG "(unknown)"
2094 
2095 #ifdef VMS
2096 #define Strerror(e) strerror((e), vaxc$errno)
2097 #else
2098 #define Strerror(e) strerror(e)
2099 #endif
2100 
2101 #ifdef I_SYS_IOCTL
2102 #   ifndef _IOCTL_
2103 #	include <sys/ioctl.h>
2104 #   endif
2105 #endif
2106 
2107 #if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
2108 #   ifdef HAS_SOCKETPAIR
2109 #	undef HAS_SOCKETPAIR
2110 #   endif
2111 #   ifdef I_NDBM
2112 #	undef I_NDBM
2113 #   endif
2114 #endif
2115 
2116 #ifndef HAS_SOCKETPAIR
2117 #   ifdef HAS_SOCKET
2118 #	define socketpair Perl_my_socketpair
2119 #   endif
2120 #endif
2121 
2122 #if INTSIZE == 2
2123 #   define htoni htons
2124 #   define ntohi ntohs
2125 #else
2126 #   define htoni htonl
2127 #   define ntohi ntohl
2128 #endif
2129 
2130 /* Configure already sets Direntry_t */
2131 #if defined(I_DIRENT)
2132 #  include <dirent.h>
2133 #elif defined(I_SYS_NDIR)
2134 #  include <sys/ndir.h>
2135 #elif defined(I_SYS_DIR)
2136 #  include <sys/dir.h>
2137 #endif
2138 
2139 /*
2140  * The following gobbledygook brought to you on behalf of __STDC__.
2141  * (I could just use #ifndef __STDC__, but this is more bulletproof
2142  * in the face of half-implementations.)
2143  */
2144 
2145 #if defined(I_SYSMODE)
2146 #include <sys/mode.h>
2147 #endif
2148 
2149 #ifndef S_IFMT
2150 #   ifdef _S_IFMT
2151 #	define S_IFMT _S_IFMT
2152 #   else
2153 #	define S_IFMT 0170000
2154 #   endif
2155 #endif
2156 
2157 #ifndef S_ISDIR
2158 #   define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
2159 #endif
2160 
2161 #ifndef S_ISCHR
2162 #   define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
2163 #endif
2164 
2165 #ifndef S_ISBLK
2166 #   ifdef S_IFBLK
2167 #	define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
2168 #   else
2169 #	define S_ISBLK(m) (0)
2170 #   endif
2171 #endif
2172 
2173 #ifndef S_ISREG
2174 #   define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
2175 #endif
2176 
2177 #ifndef S_ISFIFO
2178 #   ifdef S_IFIFO
2179 #	define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
2180 #   else
2181 #	define S_ISFIFO(m) (0)
2182 #   endif
2183 #endif
2184 
2185 #ifndef S_ISLNK
2186 #  ifdef _S_ISLNK
2187 #    define S_ISLNK(m) _S_ISLNK(m)
2188 #  elif defined(_S_IFLNK)
2189 #    define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
2190 #  elif defined(S_IFLNK)
2191 #    define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
2192 #  else
2193 #    define S_ISLNK(m) (0)
2194 #  endif
2195 #endif
2196 
2197 #ifndef S_ISSOCK
2198 #  ifdef _S_ISSOCK
2199 #    define S_ISSOCK(m) _S_ISSOCK(m)
2200 #  elif defined(_S_IFSOCK)
2201 #    define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
2202 #  elif defined(S_IFSOCK)
2203 #    define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
2204 #  else
2205 #    define S_ISSOCK(m) (0)
2206 #  endif
2207 #endif
2208 
2209 #ifndef S_IRUSR
2210 #   ifdef S_IREAD
2211 #	define S_IRUSR S_IREAD
2212 #	define S_IWUSR S_IWRITE
2213 #	define S_IXUSR S_IEXEC
2214 #   else
2215 #	define S_IRUSR 0400
2216 #	define S_IWUSR 0200
2217 #	define S_IXUSR 0100
2218 #   endif
2219 #endif
2220 
2221 #ifndef S_IRGRP
2222 #   ifdef S_IRUSR
2223 #       define S_IRGRP (S_IRUSR>>3)
2224 #       define S_IWGRP (S_IWUSR>>3)
2225 #       define S_IXGRP (S_IXUSR>>3)
2226 #   else
2227 #       define S_IRGRP 0040
2228 #       define S_IWGRP 0020
2229 #       define S_IXGRP 0010
2230 #   endif
2231 #endif
2232 
2233 #ifndef S_IROTH
2234 #   ifdef S_IRUSR
2235 #       define S_IROTH (S_IRUSR>>6)
2236 #       define S_IWOTH (S_IWUSR>>6)
2237 #       define S_IXOTH (S_IXUSR>>6)
2238 #   else
2239 #       define S_IROTH 0040
2240 #       define S_IWOTH 0020
2241 #       define S_IXOTH 0010
2242 #   endif
2243 #endif
2244 
2245 #ifndef S_ISUID
2246 #   define S_ISUID 04000
2247 #endif
2248 
2249 #ifndef S_ISGID
2250 #   define S_ISGID 02000
2251 #endif
2252 
2253 #ifndef S_IRWXU
2254 #   define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR)
2255 #endif
2256 
2257 #ifndef S_IRWXG
2258 #   define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP)
2259 #endif
2260 
2261 #ifndef S_IRWXO
2262 #   define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH)
2263 #endif
2264 
2265 /* Haiku R1 seems to define S_IREAD and S_IWRITE in <posix/fcntl.h>
2266  * which would get included through <sys/file.h >, but that is 3000
2267  * lines in the future.  --jhi */
2268 
2269 #if !defined(S_IREAD) && !defined(__HAIKU__)
2270 #   define S_IREAD S_IRUSR
2271 #endif
2272 
2273 #if !defined(S_IWRITE) && !defined(__HAIKU__)
2274 #   define S_IWRITE S_IWUSR
2275 #endif
2276 
2277 #ifndef S_IEXEC
2278 #   define S_IEXEC S_IXUSR
2279 #endif
2280 
2281 #if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
2282 #   define SLOPPYDIVIDE
2283 #endif
2284 
2285 #ifdef UV
2286 #undef UV
2287 #endif
2288 
2289 /* This used to be conditionally defined based on whether we had a sprintf()
2290  * that correctly returns the string length (as required by C89), but we no
2291  * longer need that. XS modules can (and do) use this name, so it must remain
2292  * a part of the API that's visible to modules.
2293 
2294 =for apidoc_section $string
2295 =for apidoc ATmD|int|my_sprintf|NN char *buffer|NN const char *pat|...
2296 
2297 Do NOT use this due to the possibility of overflowing C<buffer>.  Instead use
2298 my_snprintf()
2299 
2300 =cut
2301 */
2302 #define my_sprintf sprintf
2303 
2304 /*
2305  * If we have v?snprintf() and the C99 variadic macros, we can just
2306  * use just the v?snprintf().  It is nice to try to trap the buffer
2307  * overflow, however, so if we are DEBUGGING, and we cannot use the
2308  * gcc statement expressions, then use the function wrappers which try
2309  * to trap the overflow.  If we can use the gcc statement expressions,
2310  * we can try that even with the version that uses the C99 variadic
2311  * macros.
2312  */
2313 
2314 /* Note that we do not check against snprintf()/vsnprintf() returning
2315  * negative values because that is non-standard behaviour and we use
2316  * snprintf/vsnprintf only iff HAS_VSNPRINTF has been defined, and
2317  * that should be true only if the snprintf()/vsnprintf() are true
2318  * to the standard. */
2319 
2320 #define PERL_SNPRINTF_CHECK(len, max, api) STMT_START { if ((max) > 0 && (Size_t)len > (max)) Perl_croak_nocontext("panic: %s buffer overflow", STRINGIFY(api)); } STMT_END
2321 
2322 #if defined(USE_LOCALE_NUMERIC) || defined(USE_QUADMATH)
2323 #  define my_snprintf Perl_my_snprintf
2324 #  define PERL_MY_SNPRINTF_GUARDED
2325 #elif defined(HAS_SNPRINTF) && defined(HAS_C99_VARIADIC_MACROS) && !(defined(DEBUGGING) && !defined(PERL_USE_GCC_BRACE_GROUPS)) && !defined(PERL_GCC_PEDANTIC)
2326 #  ifdef PERL_USE_GCC_BRACE_GROUPS
2327 #      define my_snprintf(buffer, max, ...) ({ int len = snprintf(buffer, max, __VA_ARGS__); PERL_SNPRINTF_CHECK(len, max, snprintf); len; })
2328 #      define PERL_MY_SNPRINTF_GUARDED
2329 #  else
2330 #    define my_snprintf(buffer, max, ...) snprintf(buffer, max, __VA_ARGS__)
2331 #  endif
2332 #else
2333 #  define my_snprintf  Perl_my_snprintf
2334 #  define PERL_MY_SNPRINTF_GUARDED
2335 #endif
2336 
2337 /* There is no quadmath_vsnprintf, and therefore my_vsnprintf()
2338  * dies if called under USE_QUADMATH. */
2339 #if !  defined(USE_LOCALE_NUMERIC)                                  \
2340  &&    defined(HAS_VSNPRINTF)                                       \
2341  &&    defined(HAS_C99_VARIADIC_MACROS)                             \
2342  && ! (defined(DEBUGGING) && ! defined(PERL_USE_GCC_BRACE_GROUPS))  \
2343  && !  defined(PERL_GCC_PEDANTIC)
2344 #  ifdef PERL_USE_GCC_BRACE_GROUPS
2345 #      define my_vsnprintf(buffer, max, ...)                        \
2346             ({ int len = vsnprintf(buffer, max, __VA_ARGS__);       \
2347              PERL_SNPRINTF_CHECK(len, max, vsnprintf);              \
2348              len; })
2349 #      define PERL_MY_VSNPRINTF_GUARDED
2350 #  else
2351 #    define my_vsnprintf(buffer, max, ...) vsnprintf(buffer, max, __VA_ARGS__)
2352 #  endif
2353 #else
2354 #  define my_vsnprintf Perl_my_vsnprintf
2355 #  define PERL_MY_VSNPRINTF_GUARDED
2356 #endif
2357 
2358 /* You will definitely need to use the PERL_MY_SNPRINTF_POST_GUARD()
2359  * or PERL_MY_VSNPRINTF_POST_GUARD() if you otherwise decide to ignore
2360  * the result of my_snprintf() or my_vsnprintf().  (No, you should not
2361  * completely ignore it: otherwise you cannot know whether your output
2362  * was too long.)
2363  *
2364  * int len = my_sprintf(buf, max, ...);
2365  * PERL_MY_SNPRINTF_POST_GUARD(len, max);
2366  *
2367  * The trick is that in certain platforms [a] the my_sprintf() already
2368  * contains the sanity check, while in certain platforms [b] it needs
2369  * to be done as a separate step.  The POST_GUARD is that step-- in [a]
2370  * platforms the POST_GUARD actually does nothing since the check has
2371  * already been done.  Watch out for the max being the same in both calls.
2372  *
2373  * If you actually use the snprintf/vsnprintf return value already,
2374  * you assumedly are checking its validity somehow.  But you can
2375  * insert the POST_GUARD() also in that case. */
2376 
2377 #ifndef PERL_MY_SNPRINTF_GUARDED
2378 #  define PERL_MY_SNPRINTF_POST_GUARD(len, max) PERL_SNPRINTF_CHECK(len, max, snprintf)
2379 #else
2380 #  define PERL_MY_SNPRINTF_POST_GUARD(len, max) PERL_UNUSED_VAR(len)
2381 #endif
2382 
2383 #ifndef  PERL_MY_VSNPRINTF_GUARDED
2384 #  define PERL_MY_VSNPRINTF_POST_GUARD(len, max) PERL_SNPRINTF_CHECK(len, max, vsnprintf)
2385 #else
2386 #  define PERL_MY_VSNPRINTF_POST_GUARD(len, max) PERL_UNUSED_VAR(len)
2387 #endif
2388 
2389 #ifdef HAS_STRLCAT
2390 #  define my_strlcat    strlcat
2391 #endif
2392 
2393 #if defined(PERL_CORE) || defined(PERL_EXT)
2394 #  ifdef HAS_MEMRCHR
2395 #    define my_memrchr	memrchr
2396 #  else
2397 #    define my_memrchr	S_my_memrchr
2398 #  endif
2399 #endif
2400 
2401 #ifdef HAS_STRLCPY
2402 #  define my_strlcpy	strlcpy
2403 #endif
2404 
2405 #ifdef HAS_STRNLEN
2406 #  define my_strnlen	strnlen
2407 #endif
2408 
2409 /*
2410     The IV type is supposed to be long enough to hold any integral
2411     value or a pointer.
2412     --Andy Dougherty	August 1996
2413 */
2414 
2415 typedef IVTYPE IV;
2416 typedef UVTYPE UV;
2417 
2418 #if defined(USE_64_BIT_INT) && defined(HAS_QUAD)
2419 #  if QUADKIND == QUAD_IS_INT64_T && defined(INT64_MAX)
2420 #    define IV_MAX ((IV)INT64_MAX)
2421 #    define IV_MIN ((IV)INT64_MIN)
2422 #    define UV_MAX ((UV)UINT64_MAX)
2423 #    ifndef UINT64_MIN
2424 #      define UINT64_MIN 0
2425 #    endif
2426 #    define UV_MIN ((UV)UINT64_MIN)
2427 #  else
2428 #    define IV_MAX PERL_QUAD_MAX
2429 #    define IV_MIN PERL_QUAD_MIN
2430 #    define UV_MAX PERL_UQUAD_MAX
2431 #    define UV_MIN PERL_UQUAD_MIN
2432 #  endif
2433 #  define IV_IS_QUAD
2434 #  define UV_IS_QUAD
2435 #else
2436 #  if defined(INT32_MAX) && IVSIZE == 4
2437 #    define IV_MAX ((IV)INT32_MAX)
2438 #    define IV_MIN ((IV)INT32_MIN)
2439 #    ifndef UINT32_MAX_BROKEN /* e.g. HP-UX with gcc messes this up */
2440 #        define UV_MAX ((UV)UINT32_MAX)
2441 #    else
2442 #        define UV_MAX ((UV)4294967295U)
2443 #    endif
2444 #    ifndef UINT32_MIN
2445 #      define UINT32_MIN 0
2446 #    endif
2447 #    define UV_MIN ((UV)UINT32_MIN)
2448 #  else
2449 #    define IV_MAX PERL_LONG_MAX
2450 #    define IV_MIN PERL_LONG_MIN
2451 #    define UV_MAX PERL_ULONG_MAX
2452 #    define UV_MIN PERL_ULONG_MIN
2453 #  endif
2454 #  if IVSIZE == 8
2455 #    define IV_IS_QUAD
2456 #    define UV_IS_QUAD
2457 #    ifndef HAS_QUAD
2458 #      define HAS_QUAD
2459 #    endif
2460 #  else
2461 #    undef IV_IS_QUAD
2462 #    undef UV_IS_QUAD
2463 #if !defined(PERL_CORE)
2464 /* We think that removing this decade-old undef this will cause too much
2465    breakage on CPAN for too little gain. (See RT #119753)
2466    However, we do need HAS_QUAD in the core for use by the drand48 code. */
2467 #    undef HAS_QUAD
2468 #endif
2469 #  endif
2470 #endif
2471 
2472 #define Size_t_MAX (~(Size_t)0)
2473 #define SSize_t_MAX (SSize_t)(~(Size_t)0 >> 1)
2474 
2475 #define IV_DIG (BIT_DIGITS(IVSIZE * 8))
2476 #define UV_DIG (BIT_DIGITS(UVSIZE * 8))
2477 
2478 #ifndef NO_PERL_PRESERVE_IVUV
2479 #define PERL_PRESERVE_IVUV	/* We like our integers to stay integers. */
2480 #endif
2481 
2482 /*
2483  *  The macros INT2PTR and NUM2PTR are (despite their names)
2484  *  bi-directional: they will convert int/float to or from pointers.
2485  *  However the conversion to int/float are named explicitly:
2486  *  PTR2IV, PTR2UV, PTR2NV.
2487  *
2488  *  For int conversions we do not need two casts if pointers are
2489  *  the same size as IV and UV.   Otherwise we need an explicit
2490  *  cast (PTRV) to avoid compiler warnings.
2491  *
2492  *  These are mentioned in perlguts
2493  */
2494 #if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE)
2495 #  define PTRV			UV
2496 #  define INT2PTR(any,d)	(any)(d)
2497 #elif PTRSIZE == LONGSIZE
2498 #  define PTRV			unsigned long
2499 #  define PTR2ul(p)		(unsigned long)(p)
2500 #else
2501 #  define PTRV			unsigned
2502 #endif
2503 
2504 #ifndef INT2PTR
2505 #  define INT2PTR(any,d)	(any)(PTRV)(d)
2506 #endif
2507 
2508 #ifndef PTR2ul
2509 #  define PTR2ul(p)	INT2PTR(unsigned long,p)
2510 #endif
2511 
2512 /*
2513 =for apidoc_section $casting
2514 =for apidoc Cyh|type|NUM2PTR|type|int value
2515 You probably want to be using L<C</INT2PTR>> instead.
2516 
2517 =cut
2518 */
2519 
2520 #define NUM2PTR(any,d)	(any)(PTRV)(d)
2521 #define PTR2IV(p)	INT2PTR(IV,p)
2522 #define PTR2UV(p)	INT2PTR(UV,p)
2523 #define PTR2NV(p)	NUM2PTR(NV,p)
2524 #define PTR2nat(p)	(PTRV)(p)	/* pointer to integer of PTRSIZE */
2525 
2526 /* According to strict ANSI C89 one cannot freely cast between
2527  * data pointers and function (code) pointers.  There are at least
2528  * two ways around this.  One (used below) is to do two casts,
2529  * first the other pointer to an (unsigned) integer, and then
2530  * the integer to the other pointer.  The other way would be
2531  * to use unions to "overlay" the pointers.  For an example of
2532  * the latter technique, see union dirpu in struct xpvio in sv.h.
2533  * The only feasible use is probably temporarily storing
2534  * function pointers in a data pointer (such as a void pointer). */
2535 
2536 #define DPTR2FPTR(t,p) ((t)PTR2nat(p))	/* data pointer to function pointer */
2537 #define FPTR2DPTR(t,p) ((t)PTR2nat(p))	/* function pointer to data pointer */
2538 
2539 #ifdef USE_LONG_DOUBLE
2540 #  if LONG_DOUBLESIZE == DOUBLESIZE
2541 #    define LONG_DOUBLE_EQUALS_DOUBLE
2542 #    undef USE_LONG_DOUBLE /* Ouch! */
2543 #  endif
2544 #endif
2545 
2546 /* The following is all to get LDBL_DIG, in order to pick a nice
2547    default value for printing floating point numbers in Gconvert.
2548    (see config.h)
2549 */
2550 #ifndef HAS_LDBL_DIG
2551 #  if LONG_DOUBLESIZE == 10
2552 #    define LDBL_DIG 18 /* assume IEEE */
2553 #  elif LONG_DOUBLESIZE == 12
2554 #    define LDBL_DIG 18 /* gcc? */
2555 #  elif LONG_DOUBLESIZE == 16
2556 #    define LDBL_DIG 33 /* assume IEEE */
2557 #  elif LONG_DOUBLESIZE == DOUBLESIZE
2558 #    define LDBL_DIG DBL_DIG /* bummer */
2559 #  endif
2560 #endif
2561 
2562 /* On MS Windows,with 64-bit mingw-w64 compilers, we
2563    need to attend to a __float128 alignment issue if
2564    USE_QUADMATH is defined. Otherwise we simply:
2565    typedef NVTYPE NV
2566    32-bit mingw.org compilers might also require
2567    aligned(32) - at least that's what I found with my
2568    Math::Foat128 module. But this is as yet untested
2569    here, so no allowance is being made for mingw.org
2570    compilers at this stage. -- sisyphus January 2021
2571 */
2572 #if (defined(USE_LONG_DOUBLE) || defined(USE_QUADMATH)) && defined(__MINGW64__)
2573    /* 64-bit build, mingw-w64 compiler only */
2574    typedef NVTYPE NV __attribute__ ((aligned(8)));
2575 #else
2576    typedef NVTYPE NV;
2577 #endif
2578 
2579 #ifdef I_IEEEFP
2580 #   include <ieeefp.h>
2581 #endif
2582 
2583 #if defined(__DECC) && defined(__osf__)
2584 /* Also Tru64 cc has broken NaN comparisons. */
2585 #  define NAN_COMPARE_BROKEN
2586 #endif
2587 #if defined(__sgi)
2588 #  define NAN_COMPARE_BROKEN
2589 #endif
2590 
2591 #ifdef USE_LONG_DOUBLE
2592 #   ifdef I_SUNMATH
2593 #       include <sunmath.h>
2594 #   endif
2595 #   if defined(LDBL_DIG)
2596 #       define NV_DIG LDBL_DIG
2597 #       ifdef LDBL_MANT_DIG
2598 #           define NV_MANT_DIG LDBL_MANT_DIG
2599 #       endif
2600 #       ifdef LDBL_MIN
2601 #           define NV_MIN LDBL_MIN
2602 #       endif
2603 #       ifdef LDBL_MAX
2604 #           define NV_MAX LDBL_MAX
2605 #       endif
2606 #       ifdef LDBL_MIN_EXP
2607 #           define NV_MIN_EXP LDBL_MIN_EXP
2608 #       endif
2609 #       ifdef LDBL_MAX_EXP
2610 #           define NV_MAX_EXP LDBL_MAX_EXP
2611 #       endif
2612 #       ifdef LDBL_MIN_10_EXP
2613 #           define NV_MIN_10_EXP LDBL_MIN_10_EXP
2614 #       endif
2615 #       ifdef LDBL_MAX_10_EXP
2616 #           define NV_MAX_10_EXP LDBL_MAX_10_EXP
2617 #       endif
2618 #       ifdef LDBL_EPSILON
2619 #           define NV_EPSILON LDBL_EPSILON
2620 #       endif
2621 #       ifdef LDBL_MAX
2622 #           define NV_MAX LDBL_MAX
2623 /* Having LDBL_MAX doesn't necessarily mean that we have LDBL_MIN... -Allen */
2624 #       elif defined(HUGE_VALL)
2625 #           define NV_MAX HUGE_VALL
2626 #       endif
2627 #   endif
2628 #   if defined(HAS_SQRTL)
2629 #       define Perl_acos acosl
2630 #       define Perl_asin asinl
2631 #       define Perl_atan atanl
2632 #       define Perl_atan2 atan2l
2633 #       define Perl_ceil ceill
2634 #       define Perl_cos cosl
2635 #       define Perl_cosh coshl
2636 #       define Perl_exp expl
2637 #       define Perl_fabs fabsl
2638 #       define Perl_floor floorl
2639 #       define Perl_fmod fmodl
2640 #       define Perl_log logl
2641 #       define Perl_log10 log10l
2642 #       define Perl_pow powl
2643 #       define Perl_sin sinl
2644 #       define Perl_sinh sinhl
2645 #       define Perl_sqrt sqrtl
2646 #       define Perl_tan tanl
2647 #       define Perl_tanh tanhl
2648 #   endif
2649 /* e.g. libsunmath doesn't have modfl and frexpl as of mid-March 2000 */
2650 #   ifndef Perl_modf
2651 #       ifdef HAS_MODFL
2652 #           define Perl_modf(x,y) modfl(x,y)
2653 /* eg glibc 2.2 series seems to provide modfl on ppc and arm, but has no
2654    prototype in <math.h> */
2655 #           ifndef HAS_MODFL_PROTO
2656 EXTERN_C long double modfl(long double, long double *);
2657 #	    endif
2658 #       elif (defined(HAS_TRUNCL) || defined(HAS_AINTL)) && defined(HAS_COPYSIGNL)
2659         extern long double Perl_my_modfl(long double x, long double *ip);
2660 #           define Perl_modf(x,y) Perl_my_modfl(x,y)
2661 #       endif
2662 #   endif
2663 #   ifndef Perl_frexp
2664 #       ifdef HAS_FREXPL
2665 #           define Perl_frexp(x,y) frexpl(x,y)
2666 #       elif defined(HAS_ILOGBL) && defined(HAS_SCALBNL)
2667 extern long double Perl_my_frexpl(long double x, int *e);
2668 #           define Perl_frexp(x,y) Perl_my_frexpl(x,y)
2669 #       endif
2670 #   endif
2671 #   ifndef Perl_ldexp
2672 #       ifdef HAS_LDEXPL
2673 #           define Perl_ldexp(x, y) ldexpl(x,y)
2674 #       elif defined(HAS_SCALBNL) && FLT_RADIX == 2
2675 #           define Perl_ldexp(x,y) scalbnl(x,y)
2676 #       endif
2677 #   endif
2678 #   ifndef Perl_isnan
2679 #       if defined(HAS_ISNANL) && !(defined(isnan) && defined(HAS_C99))
2680 #           define Perl_isnan(x) isnanl(x)
2681 #       elif defined(__sgi) && defined(__c99)  /* XXX Configure test needed */
2682 #           define Perl_isnan(x) isnan(x)
2683 #       endif
2684 #   endif
2685 #   ifndef Perl_isinf
2686 #       if defined(HAS_ISINFL) && !(defined(isinf) && defined(HAS_C99))
2687 #           define Perl_isinf(x) isinfl(x)
2688 #       elif defined(__sgi) && defined(__c99)  /* XXX Configure test needed */
2689 #           define Perl_isinf(x) isinf(x)
2690 #       elif defined(LDBL_MAX) && !defined(NAN_COMPARE_BROKEN)
2691 #           define Perl_isinf(x) ((x) > LDBL_MAX || (x) < -LDBL_MAX)
2692 #       endif
2693 #   endif
2694 #   ifndef Perl_isfinite
2695 #       define Perl_isfinite(x) Perl_isfinitel(x)
2696 #   endif
2697 #elif defined(USE_QUADMATH) && defined(I_QUADMATH)
2698 #   include <quadmath.h>
2699 #   define NV_DIG FLT128_DIG
2700 #   define NV_MANT_DIG FLT128_MANT_DIG
2701 #   define NV_MIN FLT128_MIN
2702 #   define NV_MAX FLT128_MAX
2703 #   define NV_MIN_EXP FLT128_MIN_EXP
2704 #   define NV_MAX_EXP FLT128_MAX_EXP
2705 #   define NV_EPSILON FLT128_EPSILON
2706 #   define NV_MIN_10_EXP FLT128_MIN_10_EXP
2707 #   define NV_MAX_10_EXP FLT128_MAX_10_EXP
2708 #   define Perl_acos acosq
2709 #   define Perl_asin asinq
2710 #   define Perl_atan atanq
2711 #   define Perl_atan2 atan2q
2712 #   define Perl_ceil ceilq
2713 #   define Perl_cos cosq
2714 #   define Perl_cosh coshq
2715 #   define Perl_exp expq
2716 #   define Perl_fabs fabsq
2717 #   define Perl_floor floorq
2718 #   define Perl_fmod fmodq
2719 #   define Perl_log logq
2720 #   define Perl_log10 log10q
2721 #   define Perl_signbit signbitq
2722 #   define Perl_pow powq
2723 #   define Perl_sin sinq
2724 #   define Perl_sinh sinhq
2725 #   define Perl_sqrt sqrtq
2726 #   define Perl_tan tanq
2727 #   define Perl_tanh tanhq
2728 #   define Perl_modf(x,y) modfq(x,y)
2729 #   define Perl_frexp(x,y) frexpq(x,y)
2730 #   define Perl_ldexp(x, y) ldexpq(x,y)
2731 #   define Perl_isinf(x) isinfq(x)
2732 #   define Perl_isnan(x) isnanq(x)
2733 #   define Perl_isfinite(x) (!(isnanq(x) || isinfq(x)))
2734 #   define Perl_fp_class(x) ((x) == 0.0Q ? 0 : isinfq(x) ? 3 : isnanq(x) ? 4 : PERL_ABS(x) < FLT128_MIN ? 2 : 1)
2735 #   define Perl_fp_class_inf(x)    (Perl_fp_class(x) == 3)
2736 #   define Perl_fp_class_nan(x)    (Perl_fp_class(x) == 4)
2737 #   define Perl_fp_class_norm(x)   (Perl_fp_class(x) == 1)
2738 #   define Perl_fp_class_denorm(x) (Perl_fp_class(x) == 2)
2739 #   define Perl_fp_class_zero(x)   (Perl_fp_class(x) == 0)
2740 #else
2741 #   define NV_DIG DBL_DIG
2742 #   define NV_MANT_DIG DBL_MANT_DIG
2743 #   define NV_MIN DBL_MIN
2744 #   define NV_MAX DBL_MAX
2745 #   define NV_MIN_EXP DBL_MIN_EXP
2746 #   define NV_MAX_EXP DBL_MAX_EXP
2747 #   define NV_MIN_10_EXP DBL_MIN_10_EXP
2748 #   define NV_MAX_10_EXP DBL_MAX_10_EXP
2749 #   define NV_EPSILON DBL_EPSILON
2750 #   define NV_MAX DBL_MAX
2751 #   define NV_MIN DBL_MIN
2752 
2753 /* These math interfaces are C89. */
2754 #   define Perl_acos acos
2755 #   define Perl_asin asin
2756 #   define Perl_atan atan
2757 #   define Perl_atan2 atan2
2758 #   define Perl_ceil ceil
2759 #   define Perl_cos cos
2760 #   define Perl_cosh cosh
2761 #   define Perl_exp exp
2762 #   define Perl_fabs fabs
2763 #   define Perl_floor floor
2764 #   define Perl_fmod fmod
2765 #   define Perl_log log
2766 #   define Perl_log10 log10
2767 #   define Perl_pow pow
2768 #   define Perl_sin sin
2769 #   define Perl_sinh sinh
2770 #   define Perl_sqrt sqrt
2771 #   define Perl_tan tan
2772 #   define Perl_tanh tanh
2773 
2774 #   define Perl_modf(x,y) modf(x,y)
2775 #   define Perl_frexp(x,y) frexp(x,y)
2776 #   define Perl_ldexp(x,y) ldexp(x,y)
2777 
2778 #   ifndef Perl_isnan
2779 #       ifdef HAS_ISNAN
2780 #           define Perl_isnan(x) isnan(x)
2781 #       endif
2782 #   endif
2783 #   ifndef Perl_isinf
2784 #       if defined(HAS_ISINF)
2785 #           define Perl_isinf(x) isinf(x)
2786 #       elif defined(DBL_MAX) && !defined(NAN_COMPARE_BROKEN)
2787 #           define Perl_isinf(x) ((x) > DBL_MAX || (x) < -DBL_MAX)
2788 #       endif
2789 #   endif
2790 #   ifndef Perl_isfinite
2791 #     ifdef HAS_ISFINITE
2792 #       define Perl_isfinite(x) isfinite(x)
2793 #     elif defined(HAS_FINITE)
2794 #       define Perl_isfinite(x) finite(x)
2795 #     endif
2796 #   endif
2797 #endif
2798 
2799 /* fpclassify(): C99.  It is supposed to be a macro that switches on
2800 * the sizeof() of its argument, so there's no need for e.g. fpclassifyl().*/
2801 #if !defined(Perl_fp_class) && defined(HAS_FPCLASSIFY)
2802 #    include <math.h>
2803 #    if defined(FP_INFINITE) && defined(FP_NAN)
2804 #        define Perl_fp_class(x)	fpclassify(x)
2805 #        define Perl_fp_class_inf(x)	(Perl_fp_class(x)==FP_INFINITE)
2806 #        define Perl_fp_class_nan(x)	(Perl_fp_class(x)==FP_NAN)
2807 #        define Perl_fp_class_norm(x)	(Perl_fp_class(x)==FP_NORMAL)
2808 #        define Perl_fp_class_denorm(x)	(Perl_fp_class(x)==FP_SUBNORMAL)
2809 #        define Perl_fp_class_zero(x)	(Perl_fp_class(x)==FP_ZERO)
2810 #    elif defined(FP_PLUS_INF) && defined(FP_QNAN)
2811 /* Some versions of HP-UX (10.20) have (only) fpclassify() but which is
2812  * actually not the C99 fpclassify, with its own set of return defines. */
2813 #        define Perl_fp_class(x)	fpclassify(x)
2814 #        define Perl_fp_class_pinf(x)	(Perl_fp_class(x)==FP_PLUS_INF)
2815 #        define Perl_fp_class_ninf(x)	(Perl_fp_class(x)==FP_MINUS_INF)
2816 #        define Perl_fp_class_snan(x)	(Perl_fp_class(x)==FP_SNAN)
2817 #        define Perl_fp_class_qnan(x)	(Perl_fp_class(x)==FP_QNAN)
2818 #        define Perl_fp_class_pnorm(x)	(Perl_fp_class(x)==FP_PLUS_NORM)
2819 #        define Perl_fp_class_nnorm(x)	(Perl_fp_class(x)==FP_MINUS_NORM)
2820 #        define Perl_fp_class_pdenorm(x)	(Perl_fp_class(x)==FP_PLUS_DENORM)
2821 #        define Perl_fp_class_ndenorm(x)	(Perl_fp_class(x)==FP_MINUS_DENORM)
2822 #        define Perl_fp_class_pzero(x)	(Perl_fp_class(x)==FP_PLUS_ZERO)
2823 #        define Perl_fp_class_nzero(x)	(Perl_fp_class(x)==FP_MINUS_ZERO)
2824 #    else
2825 #        undef Perl_fp_class /* Unknown set of defines */
2826 #    endif
2827 #endif
2828 
2829 /* fp_classify(): Legacy: VMS, maybe Unicos? The values, however,
2830  * are identical to the C99 fpclassify(). */
2831 #if !defined(Perl_fp_class) && defined(HAS_FP_CLASSIFY)
2832 #    include <math.h>
2833 #    ifdef __VMS
2834      /* FP_INFINITE and others are here rather than in math.h as C99 stipulates */
2835 #        include <fp.h>
2836      /* oh, and the isnormal macro has a typo in it! */
2837 #    undef isnormal
2838 #    define isnormal(x) Perl_fp_class_norm(x)
2839 #    endif
2840 #    if defined(FP_INFINITE) && defined(FP_NAN)
2841 #        define Perl_fp_class(x)	fp_classify(x)
2842 #        define Perl_fp_class_inf(x)	(Perl_fp_class(x)==FP_INFINITE)
2843 #        define Perl_fp_class_nan(x)	(Perl_fp_class(x)==FP_NAN)
2844 #        define Perl_fp_class_norm(x)	(Perl_fp_class(x)==FP_NORMAL)
2845 #        define Perl_fp_class_denorm(x)	(Perl_fp_class(x)==FP_SUBNORMAL)
2846 #        define Perl_fp_class_zero(x)	(Perl_fp_class(x)==FP_ZERO)
2847 #    else
2848 #        undef Perl_fp_class /* Unknown set of defines */
2849 #    endif
2850 #endif
2851 
2852 /* Feel free to check with me for the SGI manpages, SGI testing,
2853  * etcetera, if you want to try getting this to work with IRIX.
2854  *
2855  * - Allen <allens@cpan.org> */
2856 
2857 /* fpclass(): SysV, at least Solaris and some versions of IRIX. */
2858 #if !defined(Perl_fp_class) && (defined(HAS_FPCLASS)||defined(HAS_FPCLASSL))
2859 /* Solaris and IRIX have fpclass/fpclassl, but they are using
2860  * an enum typedef, not cpp symbols, and Configure doesn't detect that.
2861  * Define some symbols also as cpp symbols so we can detect them. */
2862 #    if defined(__sun) || defined(__sgi) /* XXX Configure test instead */
2863 #     define FP_PINF FP_PINF
2864 #     define FP_QNAN FP_QNAN
2865 #    endif
2866 #    include <math.h>
2867 #    ifdef I_IEEEFP
2868 #        include <ieeefp.h>
2869 #    endif
2870 #    ifdef I_FP
2871 #        include <fp.h>
2872 #    endif
2873 #    if defined(USE_LONG_DOUBLE) && defined(HAS_FPCLASSL)
2874 #        define Perl_fp_class(x)	fpclassl(x)
2875 #    else
2876 #        define Perl_fp_class(x)	fpclass(x)
2877 #    endif
2878 #    if defined(FP_CLASS_PINF) && defined(FP_CLASS_SNAN)
2879 #        define Perl_fp_class_snan(x)	(Perl_fp_class(x)==FP_CLASS_SNAN)
2880 #        define Perl_fp_class_qnan(x)	(Perl_fp_class(x)==FP_CLASS_QNAN)
2881 #        define Perl_fp_class_ninf(x)	(Perl_fp_class(x)==FP_CLASS_NINF)
2882 #        define Perl_fp_class_pinf(x)	(Perl_fp_class(x)==FP_CLASS_PINF)
2883 #        define Perl_fp_class_nnorm(x)	(Perl_fp_class(x)==FP_CLASS_NNORM)
2884 #        define Perl_fp_class_pnorm(x)	(Perl_fp_class(x)==FP_CLASS_PNORM)
2885 #        define Perl_fp_class_ndenorm(x)	(Perl_fp_class(x)==FP_CLASS_NDENORM)
2886 #        define Perl_fp_class_pdenorm(x)	(Perl_fp_class(x)==FP_CLASS_PDENORM)
2887 #        define Perl_fp_class_nzero(x)	(Perl_fp_class(x)==FP_CLASS_NZERO)
2888 #        define Perl_fp_class_pzero(x)	(Perl_fp_class(x)==FP_CLASS_PZERO)
2889 #    elif defined(FP_PINF) && defined(FP_QNAN)
2890 #        define Perl_fp_class_snan(x)	(Perl_fp_class(x)==FP_SNAN)
2891 #        define Perl_fp_class_qnan(x)	(Perl_fp_class(x)==FP_QNAN)
2892 #        define Perl_fp_class_ninf(x)	(Perl_fp_class(x)==FP_NINF)
2893 #        define Perl_fp_class_pinf(x)	(Perl_fp_class(x)==FP_PINF)
2894 #        define Perl_fp_class_nnorm(x)	(Perl_fp_class(x)==FP_NNORM)
2895 #        define Perl_fp_class_pnorm(x)	(Perl_fp_class(x)==FP_PNORM)
2896 #        define Perl_fp_class_ndenorm(x)	(Perl_fp_class(x)==FP_NDENORM)
2897 #        define Perl_fp_class_pdenorm(x)	(Perl_fp_class(x)==FP_PDENORM)
2898 #        define Perl_fp_class_nzero(x)	(Perl_fp_class(x)==FP_NZERO)
2899 #        define Perl_fp_class_pzero(x)	(Perl_fp_class(x)==FP_PZERO)
2900 #    else
2901 #        undef Perl_fp_class /* Unknown set of defines */
2902 #    endif
2903 #endif
2904 
2905 /* fp_class(): Legacy: at least Tru64, some versions of IRIX. */
2906 #if !defined(Perl_fp_class) && (defined(HAS_FP_CLASS)||defined(HAS_FP_CLASSL))
2907 #    include <math.h>
2908 #    if !defined(FP_SNAN) && defined(I_FP_CLASS)
2909 #        include <fp_class.h>
2910 #    endif
2911 #    if defined(FP_POS_INF) && defined(FP_QNAN)
2912 #        ifdef __sgi /* XXX Configure test instead */
2913 #            ifdef USE_LONG_DOUBLE
2914 #                define Perl_fp_class(x)	fp_class_l(x)
2915 #            else
2916 #                define Perl_fp_class(x)	fp_class_d(x)
2917 #            endif
2918 #        else
2919 #            if defined(USE_LONG_DOUBLE) && defined(HAS_FP_CLASSL)
2920 #                define Perl_fp_class(x)	fp_classl(x)
2921 #            else
2922 #                define Perl_fp_class(x)	fp_class(x)
2923 #            endif
2924 #        endif
2925 #        if defined(FP_POS_INF) && defined(FP_QNAN)
2926 #            define Perl_fp_class_snan(x)	(Perl_fp_class(x)==FP_SNAN)
2927 #            define Perl_fp_class_qnan(x)	(Perl_fp_class(x)==FP_QNAN)
2928 #            define Perl_fp_class_ninf(x)	(Perl_fp_class(x)==FP_NEG_INF)
2929 #            define Perl_fp_class_pinf(x)	(Perl_fp_class(x)==FP_POS_INF)
2930 #            define Perl_fp_class_nnorm(x)	(Perl_fp_class(x)==FP_NEG_NORM)
2931 #            define Perl_fp_class_pnorm(x)	(Perl_fp_class(x)==FP_POS_NORM)
2932 #            define Perl_fp_class_ndenorm(x)	(Perl_fp_class(x)==FP_NEG_DENORM)
2933 #            define Perl_fp_class_pdenorm(x)	(Perl_fp_class(x)==FP_POS_DENORM)
2934 #            define Perl_fp_class_nzero(x)	(Perl_fp_class(x)==FP_NEG_ZERO)
2935 #            define Perl_fp_class_pzero(x)	(Perl_fp_class(x)==FP_POS_ZERO)
2936 #        else
2937 #            undef Perl_fp_class /* Unknown set of defines */
2938 #        endif
2939 #    endif
2940 #endif
2941 
2942 /* class(), _class(): Legacy: AIX. */
2943 #if !defined(Perl_fp_class) && defined(HAS_CLASS)
2944 #    include <math.h>
2945 #    if defined(FP_PLUS_NORM) && defined(FP_PLUS_INF)
2946 #        ifndef _cplusplus
2947 #            define Perl_fp_class(x)	class(x)
2948 #        else
2949 #            define Perl_fp_class(x)	_class(x)
2950 #        endif
2951 #        if defined(FP_PLUS_INF) && defined(FP_NANQ)
2952 #            define Perl_fp_class_snan(x)	(Perl_fp_class(x)==FP_NANS)
2953 #            define Perl_fp_class_qnan(x)	(Perl_fp_class(x)==FP_NANQ)
2954 #            define Perl_fp_class_ninf(x)	(Perl_fp_class(x)==FP_MINUS_INF)
2955 #            define Perl_fp_class_pinf(x)	(Perl_fp_class(x)==FP_PLUS_INF)
2956 #            define Perl_fp_class_nnorm(x)	(Perl_fp_class(x)==FP_MINUS_NORM)
2957 #            define Perl_fp_class_pnorm(x)	(Perl_fp_class(x)==FP_PLUS_NORM)
2958 #            define Perl_fp_class_ndenorm(x)	(Perl_fp_class(x)==FP_MINUS_DENORM)
2959 #            define Perl_fp_class_pdenorm(x)	(Perl_fp_class(x)==FP_PLUS_DENORM)
2960 #            define Perl_fp_class_nzero(x)	(Perl_fp_class(x)==FP_MINUS_ZERO)
2961 #            define Perl_fp_class_pzero(x)	(Perl_fp_class(x)==FP_PLUS_ZERO)
2962 #        else
2963 #            undef Perl_fp_class /* Unknown set of defines */
2964 #        endif
2965 #    endif
2966 #endif
2967 
2968 /* Win32: _fpclass(), _isnan(), _finite(). */
2969 #ifdef _MSC_VER
2970 #  ifndef Perl_isnan
2971 #    define Perl_isnan(x) _isnan(x)
2972 #  endif
2973 #  ifndef Perl_isfinite
2974 #    define Perl_isfinite(x) _finite(x)
2975 #  endif
2976 #  ifndef Perl_fp_class_snan
2977 /* No simple way to #define Perl_fp_class because _fpclass()
2978  * returns a set of bits. */
2979 #    define Perl_fp_class_snan(x) (_fpclass(x) & _FPCLASS_SNAN)
2980 #    define Perl_fp_class_qnan(x) (_fpclass(x) & _FPCLASS_QNAN)
2981 #    define Perl_fp_class_nan(x) (_fpclass(x) & (_FPCLASS_SNAN|_FPCLASS_QNAN))
2982 #    define Perl_fp_class_ninf(x) (_fpclass(x) & _FPCLASS_NINF)
2983 #    define Perl_fp_class_pinf(x) (_fpclass(x) & _FPCLASS_PINF)
2984 #    define Perl_fp_class_inf(x) (_fpclass(x) & (_FPCLASS_NINF|_FPCLASS_PINF))
2985 #    define Perl_fp_class_nnorm(x) (_fpclass(x) & _FPCLASS_NN)
2986 #    define Perl_fp_class_pnorm(x) (_fpclass(x) & _FPCLASS_PN)
2987 #    define Perl_fp_class_norm(x) (_fpclass(x) & (_FPCLASS_NN|_FPCLASS_PN))
2988 #    define Perl_fp_class_ndenorm(x) (_fpclass(x) & _FPCLASS_ND)
2989 #    define Perl_fp_class_pdenorm(x) (_fpclass(x) & _FPCLASS_PD)
2990 #    define Perl_fp_class_denorm(x) (_fpclass(x) & (_FPCLASS_ND|_FPCLASS_PD))
2991 #    define Perl_fp_class_nzero(x) (_fpclass(x) & _FPCLASS_NZ)
2992 #    define Perl_fp_class_pzero(x) (_fpclass(x) & _FPCLASS_PZ)
2993 #    define Perl_fp_class_zero(x) (_fpclass(x) & (_FPCLASS_NZ|_FPCLASS_PZ))
2994 #  endif
2995 #endif
2996 
2997 #if !defined(Perl_fp_class_inf) && \
2998   defined(Perl_fp_class_pinf) && defined(Perl_fp_class_ninf)
2999 #  define Perl_fp_class_inf(x) \
3000     (Perl_fp_class_pinf(x) || Perl_fp_class_ninf(x))
3001 #endif
3002 
3003 #if !defined(Perl_fp_class_nan) && \
3004   defined(Perl_fp_class_snan) && defined(Perl_fp_class_qnan)
3005 #  define Perl_fp_class_nan(x) \
3006     (Perl_fp_class_snan(x) || Perl_fp_class_qnan(x))
3007 #endif
3008 
3009 #if !defined(Perl_fp_class_zero) && \
3010   defined(Perl_fp_class_pzero) && defined(Perl_fp_class_nzero)
3011 #  define Perl_fp_class_zero(x) \
3012     (Perl_fp_class_pzero(x) || Perl_fp_class_nzero(x))
3013 #endif
3014 
3015 #if !defined(Perl_fp_class_norm) && \
3016   defined(Perl_fp_class_pnorm) && defined(Perl_fp_class_nnorm)
3017 #  define Perl_fp_class_norm(x) \
3018     (Perl_fp_class_pnorm(x) || Perl_fp_class_nnorm(x))
3019 #endif
3020 
3021 #if !defined(Perl_fp_class_denorm) && \
3022   defined(Perl_fp_class_pdenorm) && defined(Perl_fp_class_ndenorm)
3023 #  define Perl_fp_class_denorm(x) \
3024     (Perl_fp_class_pdenorm(x) || Perl_fp_class_ndenorm(x))
3025 #endif
3026 
3027 #ifndef Perl_isnan
3028 #   ifdef Perl_fp_class_nan
3029 #       define Perl_isnan(x) Perl_fp_class_nan(x)
3030 #   elif defined(HAS_UNORDERED)
3031 #       define Perl_isnan(x) unordered((x), 0.0)
3032 #   else
3033 #       define Perl_isnan(x) ((x)!=(x))
3034 #   endif
3035 #endif
3036 
3037 #ifndef Perl_isinf
3038 #   ifdef Perl_fp_class_inf
3039 #       define Perl_isinf(x) Perl_fp_class_inf(x)
3040 #   endif
3041 #endif
3042 
3043 #ifndef Perl_isfinite
3044 #   if defined(HAS_ISFINITE) && !defined(isfinite)
3045 #     define Perl_isfinite(x) isfinite((double)(x))
3046 #   elif defined(HAS_FINITE)
3047 #       define Perl_isfinite(x) finite((double)(x))
3048 #   elif defined(Perl_fp_class_finite)
3049 #     define Perl_isfinite(x) Perl_fp_class_finite(x)
3050 #   else
3051 /* For the infinities the multiplication returns nan,
3052  * for the nan the multiplication also returns nan,
3053  * for everything else (that is, finite) zero should be returned. */
3054 #     define Perl_isfinite(x) (((x) * 0) == 0)
3055 #   endif
3056 #endif
3057 
3058 #ifndef Perl_isinf
3059 #   if defined(Perl_isfinite) && defined(Perl_isnan)
3060 #       define Perl_isinf(x) (!(Perl_isfinite(x)||Perl_isnan(x)))
3061 #   endif
3062 #endif
3063 
3064 /* We need Perl_isfinitel (ends with ell) (if available) even when
3065  * not USE_LONG_DOUBLE because the printf code (sv_catpvfn_flags)
3066  * needs that. */
3067 #if defined(HAS_LONG_DOUBLE) && !defined(Perl_isfinitel)
3068 /* If isfinite() is a macro and looks like we have C99,
3069  * we assume it's the type-aware C99 isfinite(). */
3070 #    if defined(HAS_ISFINITE) && defined(isfinite) && defined(HAS_C99)
3071 #        define Perl_isfinitel(x) isfinite(x)
3072 #    elif defined(HAS_ISFINITEL)
3073 #        define Perl_isfinitel(x) isfinitel(x)
3074 #    elif defined(HAS_FINITEL)
3075 #        define Perl_isfinitel(x) finitel(x)
3076 #    elif defined(HAS_ISINFL) && defined(HAS_ISNANL)
3077 #        define Perl_isfinitel(x) (!(isinfl(x)||isnanl(x)))
3078 #    else
3079 #        define Perl_isfinitel(x) ((x) * 0 == 0)  /* See Perl_isfinite. */
3080 #    endif
3081 #endif
3082 
3083 /* The default is to use Perl's own atof() implementation (in numeric.c).
3084  * This knows about if 'use locale' is in effect or not, and handles the radix
3085  * character accordingly.  On some platforms (e.g. UNICOS) it is however best
3086  * to use the native implementation of atof, as long as you accept that the
3087  * current underlying locale will affect the radix character.  Perl's version
3088  * uses a dot for a radix, execpt within the lexical scope of a Perl C<use
3089  * locale> statement.
3090  *
3091  * You can experiment with using your native one by -DUSE_PERL_ATOF=0.
3092  * Some good tests to try out with either setting are t/base/num.t,
3093  * t/op/numconvert.t, and t/op/pack.t. Note that if using long doubles
3094  * you may need to be using a different function than atof! */
3095 
3096 #ifndef USE_PERL_ATOF
3097 #   ifndef _UNICOS
3098 #       define USE_PERL_ATOF
3099 #   endif
3100 #else
3101 #   if USE_PERL_ATOF == 0
3102 #       undef USE_PERL_ATOF
3103 #   endif
3104 #endif
3105 
3106 #ifdef USE_PERL_ATOF
3107 #   define Perl_atof(s) Perl_my_atof(aTHX_ s)
3108 #   define Perl_atof2(s, n) Perl_my_atof3(aTHX_ (s), &(n), 0)
3109 #else
3110 #   define Perl_atof(s) (NV)atof(s)
3111 #   define Perl_atof2(s, n) ((n) = atof(s))
3112 #endif
3113 #define my_atof2(a,b) my_atof3(a,b,0)
3114 
3115 /*
3116 =for apidoc AmTR|NV|Atof|NN const char * const s
3117 
3118 This is a synonym for L</C<my_atof>>.
3119 
3120 =cut
3121 
3122 */
3123 
3124 #define Atof				my_atof
3125 
3126 /*
3127 =for apidoc_section $numeric
3128 =for apidoc   AmT|NV|Perl_acos|NV x
3129 =for apidoc_item |NV|Perl_asin|NV x
3130 =for apidoc_item |NV|Perl_atan|NV x
3131 =for apidoc_item |NV|Perl_atan2|NV x|NV y
3132 =for apidoc_item |NV|Perl_ceil|NV x
3133 =for apidoc_item |NV|Perl_cos|NV x
3134 =for apidoc_item |NV|Perl_cosh|NV x
3135 =for apidoc_item |NV|Perl_exp|NV x
3136 =for apidoc_item |NV|Perl_floor|NV x
3137 =for apidoc_item |NV|Perl_fmod|NV x|NV y
3138 =for apidoc_item |NV|Perl_frexp|NV x|int *exp
3139 =for apidoc_item |IV|Perl_isfinite|NV x
3140 =for apidoc_item |IV|Perl_isinf|NV x
3141 =for apidoc_item |IV|Perl_isnan|NV x
3142 =for apidoc_item |NV|Perl_ldexp|NV x|int exp
3143 =for apidoc_item |NV|Perl_log|NV x
3144 =for apidoc_item |NV|Perl_log10|NV x
3145 =for apidoc_item |NV|Perl_modf|NV x|NV *iptr
3146 =for apidoc_item |NV|Perl_pow|NV x|NV y
3147 =for apidoc_item |NV|Perl_sin|NV x
3148 =for apidoc_item |NV|Perl_sinh|NV x
3149 =for apidoc_item |NV|Perl_sqrt|NV x
3150 =for apidoc_item |NV|Perl_tan|NV x
3151 =for apidoc_item |NV|Perl_tanh|NV x
3152 
3153 These perform the corresponding mathematical operation on the operand(s), using
3154 the libc function designed for the task that has just enough precision for an
3155 NV on this platform.  If no such function with sufficient precision exists,
3156 the highest precision one available is used.
3157 
3158 =cut
3159 
3160 */
3161 
3162 /*
3163  * CHAR_MIN and CHAR_MAX are not included here, as the (char) type may be
3164  * ambiguous. It may be equivalent to (signed char) or (unsigned char)
3165  * depending on local options. Until Configure detects this (or at least
3166  * detects whether the "signed" keyword is available) the CHAR ranges
3167  * will not be included. UCHAR functions normally.
3168  *                                                           - kja
3169  */
3170 
3171 #define PERL_UCHAR_MIN ((unsigned char)0)
3172 #define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX)
3173 
3174 #define PERL_USHORT_MIN ((unsigned short)0)
3175 #define PERL_USHORT_MAX ((unsigned short)USHRT_MAX)
3176 
3177 #define PERL_SHORT_MAX ((short)SHRT_MAX)
3178 #define PERL_SHORT_MIN ((short)SHRT_MIN)
3179 
3180 #define PERL_UINT_MAX ((unsigned int)UINT_MAX)
3181 #define PERL_UINT_MIN ((unsigned int)0)
3182 
3183 #define PERL_INT_MAX ((int)INT_MAX)
3184 #define PERL_INT_MIN ((int)INT_MIN)
3185 
3186 #define PERL_ULONG_MAX ((unsigned long)ULONG_MAX)
3187 #define PERL_ULONG_MIN ((unsigned long)0L)
3188 
3189 #define PERL_LONG_MAX ((long)LONG_MAX)
3190 #define PERL_LONG_MIN ((long)LONG_MIN)
3191 
3192 #ifdef UV_IS_QUAD
3193 #    define PERL_UQUAD_MAX	(~(UV)0)
3194 #    define PERL_UQUAD_MIN	((UV)0)
3195 #    define PERL_QUAD_MAX 	((IV) (PERL_UQUAD_MAX >> 1))
3196 #    define PERL_QUAD_MIN 	(-PERL_QUAD_MAX - ((3 & -1) == 3))
3197 #endif
3198 
3199 /*
3200 =for apidoc_section $integer
3201 
3202 =for apidoc Amn |int|PERL_INT_MAX
3203 =for apidoc_item |int|PERL_INT_MIN
3204 =for apidoc_item |long|PERL_LONG_MAX
3205 =for apidoc_item |long|PERL_LONG_MIN
3206 =for apidoc_item |IV|PERL_QUAD_MAX
3207 =for apidoc_item |IV|PERL_QUAD_MIN
3208 =for apidoc_item |short|PERL_SHORT_MAX
3209 =for apidoc_item |short|PERL_SHORT_MIN
3210 =for apidoc_item |U8|PERL_UCHAR_MAX
3211 =for apidoc_item |U8|PERL_UCHAR_MIN
3212 =for apidoc_item |unsigned int|PERL_UINT_MAX
3213 =for apidoc_item |unsigned int|PERL_UINT_MIN
3214 =for apidoc_item |unsigned long|PERL_ULONG_MAX
3215 =for apidoc_item |unsigned long|PERL_ULONG_MIN
3216 =for apidoc_item |UV|PERL_UQUAD_MAX
3217 =for apidoc_item |UV|PERL_UQUAD_MIN
3218 =for apidoc_item |unsigned short|PERL_USHORT_MAX
3219 =for apidoc_item |unsigned short|PERL_USHORT_MIN
3220 
3221 These give the largest and smallest number representable in the current
3222 platform in variables of the corresponding types.
3223 
3224 For signed types, the smallest representable number is the most negative
3225 number, the one furthest away from zero.
3226 
3227 For C99 and later compilers, these correspond to things like C<INT_MAX>, which
3228 are available to the C code.  But these constants, furnished by Perl,
3229 allow code compiled on earlier compilers to portably have access to the same
3230 constants.
3231 
3232 =cut
3233 
3234 */
3235 
3236 typedef MEM_SIZE STRLEN;
3237 
3238 typedef struct op OP;
3239 typedef struct cop COP;
3240 typedef struct unop UNOP;
3241 typedef struct unop_aux UNOP_AUX;
3242 typedef struct binop BINOP;
3243 typedef struct listop LISTOP;
3244 typedef struct logop LOGOP;
3245 typedef struct pmop PMOP;
3246 typedef struct svop SVOP;
3247 typedef struct padop PADOP;
3248 typedef struct pvop PVOP;
3249 typedef struct loop LOOP;
3250 typedef struct methop METHOP;
3251 
3252 #ifdef PERL_CORE
3253 typedef struct opslab OPSLAB;
3254 typedef struct opslot OPSLOT;
3255 #endif
3256 
3257 typedef struct block_hooks BHK;
3258 typedef struct custom_op XOP;
3259 
3260 typedef struct interpreter PerlInterpreter;
3261 
3262 /* SGI's <sys/sema.h> has struct sv */
3263 #if defined(__sgi)
3264 #   define STRUCT_SV perl_sv
3265 #else
3266 #   define STRUCT_SV sv
3267 #endif
3268 typedef struct STRUCT_SV SV;
3269 typedef struct av AV;
3270 typedef struct hv HV;
3271 typedef struct cv CV;
3272 typedef struct p5rx REGEXP;
3273 typedef struct gp GP;
3274 typedef struct gv GV;
3275 typedef struct io IO;
3276 typedef struct context PERL_CONTEXT;
3277 typedef struct block BLOCK;
3278 typedef struct invlist INVLIST;
3279 
3280 typedef struct magic MAGIC;
3281 typedef struct xpv XPV;
3282 typedef struct xpviv XPVIV;
3283 typedef struct xpvuv XPVUV;
3284 typedef struct xpvnv XPVNV;
3285 typedef struct xpvmg XPVMG;
3286 typedef struct xpvlv XPVLV;
3287 typedef struct xpvinvlist XINVLIST;
3288 typedef struct xpvav XPVAV;
3289 typedef struct xpvhv XPVHV;
3290 typedef struct xpvgv XPVGV;
3291 typedef struct xpvcv XPVCV;
3292 typedef struct xpvbm XPVBM;
3293 typedef struct xpvfm XPVFM;
3294 typedef struct xpvio XPVIO;
3295 typedef struct xobject XPVOBJ;
3296 typedef struct mgvtbl MGVTBL;
3297 typedef union any ANY;
3298 typedef struct ptr_tbl_ent PTR_TBL_ENT_t;
3299 typedef struct ptr_tbl PTR_TBL_t;
3300 typedef struct clone_params CLONE_PARAMS;
3301 
3302 /* a pad is currently just an AV; but that might change,
3303  * so hide the type.  */
3304 typedef struct padlist PADLIST;
3305 typedef AV PAD;
3306 typedef struct padnamelist PADNAMELIST;
3307 typedef struct padname PADNAME;
3308 
3309 /* always enable PERL_OP_PARENT  */
3310 #if !defined(PERL_OP_PARENT)
3311 #  define PERL_OP_PARENT
3312 #endif
3313 
3314 /* enable PERL_COPY_ON_WRITE by default */
3315 #if !defined(PERL_COPY_ON_WRITE) && !defined(PERL_NO_COW)
3316 #  define PERL_COPY_ON_WRITE
3317 #endif
3318 
3319 #ifdef PERL_COPY_ON_WRITE
3320 #  define PERL_ANY_COW
3321 #else
3322 # define PERL_SAWAMPERSAND
3323 #endif
3324 
3325 #if defined(PERL_DEBUG_READONLY_OPS) && !defined(USE_ITHREADS)
3326 # error PERL_DEBUG_READONLY_OPS only works with ithreads
3327 #endif
3328 
3329 #include "handy.h"
3330 #include "charclass_invlists.h"
3331 
3332 #if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_RAWIO)
3333 #   if LSEEKSIZE == 8 && !defined(USE_64_BIT_RAWIO)
3334 #       define USE_64_BIT_RAWIO	/* implicit */
3335 #   endif
3336 #endif
3337 
3338 /* Notice the use of HAS_FSEEKO: now we are obligated to always use
3339  * fseeko/ftello if possible.  Don't go #defining ftell to ftello yourself,
3340  * however, because operating systems like to do that themself. */
3341 #ifndef FSEEKSIZE
3342 #   ifdef HAS_FSEEKO
3343 #       define FSEEKSIZE LSEEKSIZE
3344 #   else
3345 #       define FSEEKSIZE LONGSIZE
3346 #   endif
3347 #endif
3348 
3349 #if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_STDIO)
3350 #   if FSEEKSIZE == 8 && !defined(USE_64_BIT_STDIO)
3351 #       define USE_64_BIT_STDIO /* implicit */
3352 #   endif
3353 #endif
3354 
3355 #ifdef USE_64_BIT_RAWIO
3356 #   ifdef HAS_OFF64_T
3357 #       undef Off_t
3358 #       define Off_t off64_t
3359 #       undef LSEEKSIZE
3360 #       define LSEEKSIZE 8
3361 #   endif
3362 /* Most 64-bit environments have defines like _LARGEFILE_SOURCE that
3363  * will trigger defines like the ones below.  Some 64-bit environments,
3364  * however, do not.  Therefore we have to explicitly mix and match. */
3365 #   if defined(USE_OPEN64)
3366 #       define open open64
3367 #   endif
3368 #   if defined(USE_LSEEK64)
3369 #       define lseek lseek64
3370 #   else
3371 #       if defined(USE_LLSEEK)
3372 #           define lseek llseek
3373 #       endif
3374 #   endif
3375 #   if defined(USE_STAT64)
3376 #       define stat stat64
3377 #   endif
3378 #   if defined(USE_FSTAT64)
3379 #       define fstat fstat64
3380 #   endif
3381 #   if defined(USE_LSTAT64)
3382 #       define lstat lstat64
3383 #   endif
3384 #   if defined(USE_FLOCK64)
3385 #       define flock flock64
3386 #   endif
3387 #   if defined(USE_LOCKF64)
3388 #       define lockf lockf64
3389 #   endif
3390 #   if defined(USE_FCNTL64)
3391 #       define fcntl fcntl64
3392 #   endif
3393 #   if defined(USE_TRUNCATE64)
3394 #       define truncate truncate64
3395 #   endif
3396 #   if defined(USE_FTRUNCATE64)
3397 #       define ftruncate ftruncate64
3398 #   endif
3399 #endif
3400 
3401 #ifdef USE_64_BIT_STDIO
3402 #   ifdef HAS_FPOS64_T
3403 #       undef Fpos_t
3404 #       define Fpos_t fpos64_t
3405 #   endif
3406 /* Most 64-bit environments have defines like _LARGEFILE_SOURCE that
3407  * will trigger defines like the ones below.  Some 64-bit environments,
3408  * however, do not. */
3409 #   if defined(USE_FOPEN64)
3410 #       define fopen fopen64
3411 #   endif
3412 #   if defined(USE_FSEEK64)
3413 #       define fseek fseek64 /* don't do fseeko here, see perlio.c */
3414 #   endif
3415 #   if defined(USE_FTELL64)
3416 #       define ftell ftell64 /* don't do ftello here, see perlio.c */
3417 #   endif
3418 #   if defined(USE_FSETPOS64)
3419 #       define fsetpos fsetpos64
3420 #   endif
3421 #   if defined(USE_FGETPOS64)
3422 #       define fgetpos fgetpos64
3423 #   endif
3424 #   if defined(USE_TMPFILE64)
3425 #       define tmpfile tmpfile64
3426 #   endif
3427 #   if defined(USE_FREOPEN64)
3428 #       define freopen freopen64
3429 #   endif
3430 #endif
3431 
3432 #if defined(OS2)
3433 #  include "iperlsys.h"
3434 #endif
3435 
3436 #ifdef DOSISH
3437 #   if defined(OS2)
3438 #       include "os2ish.h"
3439 #   else
3440 #       include "dosish.h"
3441 #   endif
3442 #elif defined(VMS)
3443 #   include "vmsish.h"
3444 #elif defined(PLAN9)
3445 #   include "./plan9/plan9ish.h"
3446 #elif defined(__VOS__)
3447 #   ifdef __GNUC__
3448 #     include "./vos/vosish.h"
3449 #   else
3450 #     include "vos/vosish.h"
3451 #   endif
3452 #elif defined(__HAIKU__)
3453 #   include "haiku/haikuish.h"
3454 #else
3455 #   include "unixish.h"
3456 #endif
3457 
3458 #ifdef __amigaos4__
3459 #    include "amigaos.h"
3460 #    undef FD_CLOEXEC /* a lie in AmigaOS */
3461 #endif
3462 
3463 /* NSIG logic from Configure --> */
3464 #ifndef NSIG
3465 #  ifdef _NSIG
3466 #    define NSIG (_NSIG)
3467 #  elif defined(SIGMAX)
3468 #    define NSIG (SIGMAX+1)
3469 #  elif defined(SIG_MAX)
3470 #    define NSIG (SIG_MAX+1)
3471 #  elif defined(_SIG_MAX)
3472 #    define NSIG (_SIG_MAX+1)
3473 #  elif defined(MAXSIG)
3474 #    define NSIG (MAXSIG+1)
3475 #  elif defined(MAX_SIG)
3476 #    define NSIG (MAX_SIG+1)
3477 #  elif defined(SIGARRAYSIZE)
3478 #    define NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */
3479 #  elif defined(_sys_nsig)
3480 #    define NSIG (_sys_nsig) /* Solaris 2.5 */
3481 #  else
3482      /* Default to some arbitrary number that's big enough to get most
3483       * of the common signals.  */
3484 #    define NSIG 50
3485 #  endif
3486 #endif
3487 /* <-- NSIG logic from Configure */
3488 
3489 #ifndef NO_ENVIRON_ARRAY
3490 #  define USE_ENVIRON_ARRAY
3491 #endif
3492 
3493 #if defined(HAS_SIGACTION) && defined(SA_SIGINFO)
3494     /* having sigaction(2) means that the OS supports both 1-arg and 3-arg
3495      * signal handlers. But the perl core itself only fully supports 1-arg
3496      * handlers, so don't enable for now.
3497      * NB: POSIX::sigaction() supports both.
3498      *
3499      * # define PERL_USE_3ARG_SIGHANDLER
3500      */
3501 #endif
3502 
3503 /* Siginfo_t:
3504  * This is an alias for the OS's siginfo_t, except that where the OS
3505  * doesn't support it, declare a dummy version instead. This allows us to
3506  * have signal handler functions which always have a Siginfo_t parameter
3507  * regardless of platform, (and which will just be passed a NULL value
3508  * where the OS doesn't support HAS_SIGACTION).
3509  */
3510 
3511 #if defined(HAS_SIGACTION) && defined(SA_SIGINFO)
3512     typedef siginfo_t Siginfo_t;
3513 #else
3514 #ifdef si_signo /* minix */
3515 #undef si_signo
3516 #endif
3517     typedef struct {
3518         int si_signo;
3519     } Siginfo_t;
3520 #endif
3521 
3522 
3523 /*
3524  * initialise to avoid floating-point exceptions from overflow, etc
3525  */
3526 #ifndef PERL_FPU_INIT
3527 #  ifdef HAS_FPSETMASK
3528 #    if HAS_FLOATINGPOINT_H
3529 #      include <floatingpoint.h>
3530 #    endif
3531 /* Some operating systems have this as a macro, which in turn expands to a comma
3532    expression, and the last sub-expression is something that gets calculated,
3533    and then they have the gall to warn that a value computed is not used. Hence
3534    cast to void.  */
3535 #    define PERL_FPU_INIT (void)fpsetmask(0)
3536 #  elif defined(SIGFPE) && defined(SIG_IGN)
3537 #    define PERL_FPU_INIT       PL_sigfpe_saved = (Sighandler_t) signal(SIGFPE, SIG_IGN)
3538 #    define PERL_FPU_PRE_EXEC   { Sigsave_t xfpe; rsignal_save(SIGFPE, PL_sigfpe_saved, &xfpe);
3539 #    define PERL_FPU_POST_EXEC    rsignal_restore(SIGFPE, &xfpe); }
3540 #  else
3541 #    define PERL_FPU_INIT
3542 #  endif
3543 #endif
3544 #ifndef PERL_FPU_PRE_EXEC
3545 #  define PERL_FPU_PRE_EXEC   {
3546 #  define PERL_FPU_POST_EXEC  }
3547 #endif
3548 
3549 /* In Tru64 the cc -ieee enables the IEEE math but disables traps.
3550  * We need to reenable the "invalid" trap because otherwise generation
3551  * of NaN values leaves the IEEE fp flags in bad state, leaving any further
3552  * fp ops behaving strangely (Inf + 1 resulting in zero, for example). */
3553 #ifdef __osf__
3554 #  include <machine/fpu.h>
3555 #  define PERL_SYS_FPU_INIT \
3556      STMT_START { \
3557          ieee_set_fp_control(IEEE_TRAP_ENABLE_INV); \
3558          signal(SIGFPE, SIG_IGN); \
3559      } STMT_END
3560 #endif
3561 /* In IRIX the default for Flush to Zero bit is true,
3562  * which means that results going below the minimum of normal
3563  * floating points go to zero, instead of going denormal/subnormal.
3564  * This is unlike almost any other system running Perl, so let's clear it.
3565  * [perl #123767] IRIX64 blead (ddce084a) opbasic/arith.t failure, originally
3566  * [perl #120426] small numbers shouldn't round to zero if they have extra floating digits
3567  *
3568  * XXX The flush-to-zero behaviour should be a Configure scan.
3569  * To change the behaviour usually requires some system-specific
3570  * incantation, though, like the below. */
3571 #ifdef __sgi
3572 #  include <sys/fpu.h>
3573 #  define PERL_SYS_FPU_INIT \
3574      STMT_START { \
3575          union fpc_csr csr; \
3576          csr.fc_word = get_fpc_csr(); \
3577          csr.fc_struct.flush = 0; \
3578          set_fpc_csr(csr.fc_word); \
3579      } STMT_END
3580 #endif
3581 
3582 #ifndef PERL_SYS_FPU_INIT
3583 #  define PERL_SYS_FPU_INIT NOOP
3584 #endif
3585 
3586 #ifndef PERL_SYS_INIT3_BODY
3587 #  define PERL_SYS_INIT3_BODY(argvp,argcp,envp) PERL_SYS_INIT_BODY(argvp,argcp)
3588 #endif
3589 
3590 /*
3591 =for apidoc_section $embedding
3592 
3593 =for apidoc   Am|void|PERL_SYS_INIT |int *argc|char*** argv
3594 =for apidoc_item|    |PERL_SYS_INIT3|int *argc|char*** argv|char*** env
3595 
3596 These provide system-specific tune up of the C runtime environment necessary to
3597 run Perl interpreters.  Only one should be used, and it should be called only
3598 once, before creating any Perl interpreters.
3599 
3600 They differ in that C<PERL_SYS_INIT3> also initializes C<env>.
3601 
3602 =for apidoc Am|void|PERL_SYS_TERM|
3603 Provides system-specific clean up of the C runtime environment after
3604 running Perl interpreters.  This should be called only once, after
3605 freeing any remaining Perl interpreters.
3606 
3607 =cut
3608  */
3609 
3610 #define PERL_SYS_INIT(argc, argv)	Perl_sys_init(argc, argv)
3611 #define PERL_SYS_INIT3(argc, argv, env)	Perl_sys_init3(argc, argv, env)
3612 #define PERL_SYS_TERM()			Perl_sys_term()
3613 
3614 #ifndef PERL_WRITE_MSG_TO_CONSOLE
3615 #  define PERL_WRITE_MSG_TO_CONSOLE(io, msg, len) PerlIO_write(io, msg, len)
3616 #endif
3617 
3618 #ifndef MAXPATHLEN
3619 #  ifdef PATH_MAX
3620 #    ifdef _POSIX_PATH_MAX
3621 #       if PATH_MAX > _POSIX_PATH_MAX
3622 /* POSIX 1990 (and pre) was ambiguous about whether PATH_MAX
3623  * included the null byte or not.  Later amendments of POSIX,
3624  * XPG4, the Austin Group, and the Single UNIX Specification
3625  * all explicitly include the null byte in the PATH_MAX.
3626  * Ditto for _POSIX_PATH_MAX. */
3627 #         define MAXPATHLEN PATH_MAX
3628 #       else
3629 #         define MAXPATHLEN _POSIX_PATH_MAX
3630 #       endif
3631 #    else
3632 #      define MAXPATHLEN (PATH_MAX+1)
3633 #    endif
3634 #  else
3635 #    define MAXPATHLEN 1024	/* Err on the large side. */
3636 #  endif
3637 #endif
3638 
3639 /* clang Thread Safety Analysis/Annotations/Attributes
3640  * http://clang.llvm.org/docs/ThreadSafetyAnalysis.html
3641  *
3642  * Available since clang 3.6-ish (appeared in 3.4, but shaky still in 3.5).
3643  * Apple XCode hijacks __clang_major__ and __clang_minor__
3644  * (6.1 means really clang 3.6), so needs extra hijinks
3645  * (could probably also test the contents of __apple_build_version__).
3646  */
3647 #if defined(USE_ITHREADS) && defined(I_PTHREAD) && \
3648     defined(__clang__) && \
3649     !defined(SWIG) && \
3650   ((!defined(__apple_build_version__) &&               \
3651     ((__clang_major__ == 3 && __clang_minor__ >= 6) || \
3652      (__clang_major__ >= 4))) || \
3653    (defined(__apple_build_version__) &&                \
3654     ((__clang_major__ == 6 && __clang_minor__ >= 1) || \
3655      (__clang_major__ >= 7))))
3656 #  define PERL_TSA__(x)   __attribute__((x))
3657 #  define PERL_TSA_ACTIVE
3658 #else
3659 #  define PERL_TSA__(x)   /* No TSA, make TSA attributes no-ops. */
3660 #  undef PERL_TSA_ACTIVE
3661 #endif
3662 
3663 /* PERL_TSA_CAPABILITY() is used to annotate typedefs.
3664  * typedef old_type PERL_TSA_CAPABILITY("mutex") new_type;
3665  */
3666 #define PERL_TSA_CAPABILITY(x) \
3667     PERL_TSA__(capability(x))
3668 
3669 /* In the below examples the mutex must be lexically visible, usually
3670  * either as global variables, or as function arguments. */
3671 
3672 /* PERL_TSA_GUARDED_BY() is used to annotate global variables.
3673  *
3674  * Foo foo PERL_TSA_GUARDED_BY(mutex);
3675  */
3676 #define PERL_TSA_GUARDED_BY(x) \
3677     PERL_TSA__(guarded_by(x))
3678 
3679 /* PERL_TSA_PT_GUARDED_BY() is used to annotate global pointers.
3680  * The data _behind_ the pointer is guarded.
3681  *
3682  * Foo* ptr PERL_TSA_PT_GUARDED_BY(mutex);
3683  */
3684 #define PERL_TSA_PT_GUARDED_BY(x) \
3685     PERL_TSA__(pt_guarded_by(x))
3686 
3687 /* PERL_TSA_REQUIRES() is used to annotate functions.
3688  * The caller MUST hold the resource when calling the function.
3689  *
3690  * void Foo() PERL_TSA_REQUIRES(mutex);
3691  */
3692 #define PERL_TSA_REQUIRES(x) \
3693     PERL_TSA__(requires_capability(x))
3694 
3695 /* PERL_TSA_EXCLUDES() is used to annotate functions.
3696  * The caller MUST NOT hold resource when calling the function.
3697  *
3698  * EXCLUDES should be used when the function first acquires
3699  * the resource and then releases it.  Use to avoid deadlock.
3700  *
3701  * void Foo() PERL_TSA_EXCLUDES(mutex);
3702  */
3703 #define PERL_TSA_EXCLUDES(x) \
3704     PERL_TSA__(locks_excluded(x))
3705 
3706 /* PERL_TSA_ACQUIRE() is used to annotate functions.
3707  * The caller MUST NOT hold the resource when calling the function,
3708  * and the function will acquire the resource.
3709  *
3710  * void Foo() PERL_TSA_ACQUIRE(mutex);
3711  */
3712 #define PERL_TSA_ACQUIRE(x) \
3713     PERL_TSA__(acquire_capability(x))
3714 
3715 /* PERL_TSA_RELEASE() is used to annotate functions.
3716  * The caller MUST hold the resource when calling the function,
3717  * and the function will release the resource.
3718  *
3719  * void Foo() PERL_TSA_RELEASE(mutex);
3720  */
3721 #define PERL_TSA_RELEASE(x) \
3722     PERL_TSA__(release_capability(x))
3723 
3724 /* PERL_TSA_NO_TSA is used to annotate functions.
3725  * Used when being intentionally unsafe, or when the code is too
3726  * complicated for the analysis.  Use sparingly.
3727  *
3728  * void Foo() PERL_TSA_NO_TSA;
3729  */
3730 #define PERL_TSA_NO_TSA \
3731     PERL_TSA__(no_thread_safety_analysis)
3732 
3733 /* There are more annotations/attributes available, see the clang
3734  * documentation for details. */
3735 
3736 #if defined(USE_ITHREADS)
3737 #  if   defined(WIN32)
3738 #    include <win32thread.h>
3739 #  elif defined(OS2)
3740 #    include "os2thread.h"
3741 #  elif defined(I_MACH_CTHREADS)
3742 #    include <mach/cthreads.h>
3743 typedef cthread_t	perl_os_thread;
3744 typedef mutex_t		perl_mutex;
3745 typedef condition_t	perl_cond;
3746 typedef void *		perl_key;
3747 #  elif defined(I_PTHREAD) /* Posix threads */
3748 #    include <pthread.h>
3749 typedef pthread_t	perl_os_thread;
3750 typedef pthread_mutex_t PERL_TSA_CAPABILITY("mutex") perl_mutex;
3751 typedef pthread_cond_t	perl_cond;
3752 typedef pthread_key_t	perl_key;
3753 #  endif
3754 
3755 /* Many readers; single writer */
3756 typedef struct {
3757     perl_mutex lock;
3758     perl_cond  wakeup;
3759     SSize_t    readers_count;
3760 } perl_RnW1_mutex_t;
3761 
3762 
3763 #endif /* USE_ITHREADS */
3764 
3765 #ifdef PERL_TSA_ACTIVE
3766 /* Since most pthread mutex interfaces have not been annotated, we
3767  * need to have these wrappers. The NO_TSA annotation is quite ugly
3768  * but it cannot be avoided in plain C, unlike in C++, where one could
3769  * e.g. use ACQUIRE() with no arg on a mutex lock method.
3770  *
3771  * The bodies of these wrappers are in util.c
3772  *
3773  * TODO: however, some platforms are starting to get these clang
3774  * thread safety annotations for pthreads, for example FreeBSD.
3775  * Do we need a way to a bypass these wrappers? */
3776 EXTERN_C int perl_tsa_mutex_lock(perl_mutex* mutex)
3777   PERL_TSA_ACQUIRE(*mutex)
3778   PERL_TSA_NO_TSA;
3779 EXTERN_C int perl_tsa_mutex_unlock(perl_mutex* mutex)
3780   PERL_TSA_RELEASE(*mutex)
3781   PERL_TSA_NO_TSA;
3782 #endif
3783 
3784 #if defined(WIN32)
3785 #  include "win32.h"
3786 #endif
3787 
3788 #define STATUS_UNIX	PL_statusvalue
3789 #ifdef VMS
3790 #   define STATUS_NATIVE	PL_statusvalue_vms
3791 /*
3792  * vaxc$errno is only guaranteed to be valid if errno == EVMSERR, otherwise
3793  * its contents can not be trusted.  Unfortunately, Perl seems to check
3794  * it on exit, so it when PL_statusvalue_vms is updated, vaxc$errno should
3795  * be updated also.
3796  */
3797 #  include <stsdef.h>
3798 #  include <ssdef.h>
3799 /* Presume this because if VMS changes it, it will require a new
3800  * set of APIs for waiting on children for binary compatibility.
3801  */
3802 #  define child_offset_bits (8)
3803 #  ifndef C_FAC_POSIX
3804 #  define C_FAC_POSIX 0x35A000
3805 #  endif
3806 
3807 /*  STATUS_EXIT - validates and returns a NATIVE exit status code for the
3808  * platform from the existing UNIX or Native status values.
3809  */
3810 
3811 #   define STATUS_EXIT \
3812         (((I32)PL_statusvalue_vms == -1 ? SS$_ABORT : PL_statusvalue_vms) | \
3813            (VMSISH_HUSHED ? STS$M_INHIB_MSG : 0))
3814 
3815 
3816 /* STATUS_NATIVE_CHILD_SET - Calculate UNIX status that matches the child
3817  * exit code and shifts the UNIX value over the correct number of bits to
3818  * be a child status.  Usually the number of bits is 8, but that could be
3819  * platform dependent.  The NATIVE status code is presumed to have either
3820  * from a child process.
3821  */
3822 
3823 /* This is complicated.  The child processes return a true native VMS
3824    status which must be saved.  But there is an assumption in Perl that
3825    the UNIX child status has some relationship to errno values, so
3826    Perl tries to translate it to text in some of the tests.
3827    In order to get the string translation correct, for the error, errno
3828    must be EVMSERR, but that generates a different text message
3829    than what the test programs are expecting.  So an errno value must
3830    be derived from the native status value when an error occurs.
3831    That will hide the true native status message.  With this version of
3832    perl, the true native child status can always be retrieved so that
3833    is not a problem.  But in this case, Pl_statusvalue and errno may
3834    have different values in them.
3835  */
3836 
3837 #   define STATUS_NATIVE_CHILD_SET(n) \
3838         STMT_START {							\
3839             I32 evalue = (I32)n;					\
3840             if (evalue == EVMSERR) {					\
3841               PL_statusvalue_vms = vaxc$errno;				\
3842               PL_statusvalue = evalue;					\
3843             } else {							\
3844               PL_statusvalue_vms = evalue;				\
3845               if (evalue == -1) {					\
3846                 PL_statusvalue = -1;					\
3847                 PL_statusvalue_vms = SS$_ABORT; /* Should not happen */ \
3848               } else							\
3849                 PL_statusvalue = Perl_vms_status_to_unix(evalue, 1);	\
3850               set_vaxc_errno(evalue);					\
3851               if ((PL_statusvalue_vms & C_FAC_POSIX) == C_FAC_POSIX)	\
3852                   set_errno(EVMSERR);					\
3853               else set_errno(Perl_vms_status_to_unix(evalue, 0));	\
3854               PL_statusvalue = PL_statusvalue << child_offset_bits;	\
3855             }								\
3856         } STMT_END
3857 
3858 #   ifdef VMSISH_STATUS
3859 #	define STATUS_CURRENT	(VMSISH_STATUS ? STATUS_NATIVE : STATUS_UNIX)
3860 #   else
3861 #	define STATUS_CURRENT	STATUS_UNIX
3862 #   endif
3863 
3864   /* STATUS_UNIX_SET - takes a UNIX/POSIX errno value and attempts to update
3865    * the NATIVE status to an equivalent value.  Can not be used to translate
3866    * exit code values as exit code values are not guaranteed to have any
3867    * relationship at all to errno values.
3868    * This is used when Perl is forcing errno to have a specific value.
3869    */
3870 #   define STATUS_UNIX_SET(n)				\
3871         STMT_START {					\
3872             I32 evalue = (I32)n;			\
3873             PL_statusvalue = evalue;			\
3874             if (PL_statusvalue != -1) {			\
3875                 if (PL_statusvalue != EVMSERR) {	\
3876                   PL_statusvalue &= 0xFFFF;		\
3877                   if (MY_POSIX_EXIT)			\
3878                     PL_statusvalue_vms=PL_statusvalue ? SS$_ABORT : SS$_NORMAL;\
3879                   else PL_statusvalue_vms = Perl_unix_status_to_vms(evalue); \
3880                 }					\
3881                 else {					\
3882                   PL_statusvalue_vms = vaxc$errno;	\
3883                 }					\
3884             }						\
3885             else PL_statusvalue_vms = SS$_ABORT;	\
3886             set_vaxc_errno(PL_statusvalue_vms);		\
3887         } STMT_END
3888 
3889   /* STATUS_UNIX_EXIT_SET - Takes a UNIX/POSIX exit code and sets
3890    * the NATIVE error status based on it.
3891    *
3892    * When in the default mode to comply with the Perl VMS documentation,
3893    * 0 is a success and any other code sets the NATIVE status to a failure
3894    * code of SS$_ABORT.
3895    *
3896    * In the new POSIX EXIT mode, native status will be set so that the
3897    * actual exit code will can be retrieved by the calling program or
3898    * shell.
3899    *
3900    * If the exit code is not clearly a UNIX parent or child exit status,
3901    * it will be passed through as a VMS status.
3902    */
3903 
3904 #   define STATUS_UNIX_EXIT_SET(n)			\
3905         STMT_START {					\
3906             I32 evalue = (I32)n;			\
3907             PL_statusvalue = evalue;			\
3908             if (MY_POSIX_EXIT) { \
3909               if (evalue <= 0xFF00) {		\
3910                   if (evalue > 0xFF)			\
3911                     evalue = ((U8) (evalue >> child_offset_bits)); \
3912                   PL_statusvalue_vms =		\
3913                     (C_FAC_POSIX | (evalue << 3 ) |	\
3914                     ((evalue == 1) ? (STS$K_ERROR | STS$M_INHIB_MSG) : 1)); \
3915               } else /* forgive them Perl, for they have sinned */ \
3916                 PL_statusvalue_vms = evalue; \
3917             } else { \
3918               if (evalue == 0)			\
3919                 PL_statusvalue_vms = SS$_NORMAL;	\
3920               else if (evalue <= 0xFF00) \
3921                 PL_statusvalue_vms = SS$_ABORT; \
3922               else { /* forgive them Perl, for they have sinned */ \
3923                   if (evalue != EVMSERR) PL_statusvalue_vms = evalue; \
3924                   else PL_statusvalue_vms = vaxc$errno;	\
3925                   /* And obviously used a VMS status value instead of UNIX */ \
3926                   PL_statusvalue = EVMSERR;		\
3927               } \
3928               set_vaxc_errno(PL_statusvalue_vms);	\
3929             }						\
3930         } STMT_END
3931 
3932 
3933   /* STATUS_EXIT_SET - Takes a NATIVE/UNIX/POSIX exit code
3934    * and sets the NATIVE error status based on it.  This special case
3935    * is needed to maintain compatibility with past VMS behavior.
3936    *
3937    * In the default mode on VMS, this number is passed through as
3938    * both the NATIVE and UNIX status.  Which makes it different
3939    * that the STATUS_UNIX_EXIT_SET.
3940    *
3941    * In the new POSIX EXIT mode, native status will be set so that the
3942    * actual exit code will can be retrieved by the calling program or
3943    * shell.
3944    *
3945    * A POSIX exit code is from 0 to 255.  If the exit code is higher
3946    * than this, it needs to be assumed that it is a VMS exit code and
3947    * passed through.
3948    */
3949 
3950 #   define STATUS_EXIT_SET(n)				\
3951         STMT_START {					\
3952             I32 evalue = (I32)n;			\
3953             PL_statusvalue = evalue;			\
3954             if (MY_POSIX_EXIT)				\
3955                 if (evalue > 255) PL_statusvalue_vms = evalue; else {	\
3956                   PL_statusvalue_vms = \
3957                     (C_FAC_POSIX | (evalue << 3 ) |	\
3958                      ((evalue == 1) ? (STS$K_ERROR | STS$M_INHIB_MSG) : 1));} \
3959             else					\
3960                 PL_statusvalue_vms = evalue ? evalue : SS$_NORMAL; \
3961             set_vaxc_errno(PL_statusvalue_vms);		\
3962         } STMT_END
3963 
3964 
3965  /* This macro forces a success status */
3966 #   define STATUS_ALL_SUCCESS	\
3967         (PL_statusvalue = 0, PL_statusvalue_vms = SS$_NORMAL)
3968 
3969  /* This macro forces a failure status */
3970 #   define STATUS_ALL_FAILURE	(PL_statusvalue = 1, \
3971      vaxc$errno = PL_statusvalue_vms = MY_POSIX_EXIT ? \
3972         (C_FAC_POSIX | (1 << 3) | STS$K_ERROR | STS$M_INHIB_MSG) : SS$_ABORT)
3973 
3974 #elif defined(__amigaos4__)
3975  /* A somewhat experimental attempt to simulate posix return code values */
3976 #   define STATUS_NATIVE	PL_statusvalue_posix
3977 #   define STATUS_NATIVE_CHILD_SET(n)                      \
3978         STMT_START {                                       \
3979             PL_statusvalue_posix = (n);                    \
3980             if (PL_statusvalue_posix < 0) {                \
3981                 PL_statusvalue = -1;                       \
3982             }                                              \
3983             else {                                         \
3984                 PL_statusvalue = n << 8;                   \
3985             }                                              \
3986         } STMT_END
3987 #   define STATUS_UNIX_SET(n)		\
3988         STMT_START {			\
3989             PL_statusvalue = (n);		\
3990             if (PL_statusvalue != -1)	\
3991                 PL_statusvalue &= 0xFFFF;	\
3992         } STMT_END
3993 #   define STATUS_UNIX_EXIT_SET(n) STATUS_UNIX_SET(n)
3994 #   define STATUS_EXIT_SET(n) STATUS_UNIX_SET(n)
3995 #   define STATUS_CURRENT STATUS_UNIX
3996 #   define STATUS_EXIT STATUS_UNIX
3997 #   define STATUS_ALL_SUCCESS	(PL_statusvalue = 0, PL_statusvalue_posix = 0)
3998 #   define STATUS_ALL_FAILURE	(PL_statusvalue = 1, PL_statusvalue_posix = 1)
3999 
4000 #else
4001 #   define STATUS_NATIVE	PL_statusvalue_posix
4002 #   if defined(WCOREDUMP)
4003 #       define STATUS_NATIVE_CHILD_SET(n)                  \
4004             STMT_START {                                   \
4005                 PL_statusvalue_posix = (n);                \
4006                 if (PL_statusvalue_posix == -1)            \
4007                     PL_statusvalue = -1;                   \
4008                 else {                                     \
4009                     PL_statusvalue =                       \
4010                         (WIFEXITED(PL_statusvalue_posix) ? (WEXITSTATUS(PL_statusvalue_posix) << 8) : 0) |  \
4011                         (WIFSIGNALED(PL_statusvalue_posix) ? (WTERMSIG(PL_statusvalue_posix) & 0x7F) : 0) | \
4012                         (WIFSIGNALED(PL_statusvalue_posix) && WCOREDUMP(PL_statusvalue_posix) ? 0x80 : 0);  \
4013                 }                                          \
4014             } STMT_END
4015 #   elif defined(WIFEXITED)
4016 #       define STATUS_NATIVE_CHILD_SET(n)                  \
4017             STMT_START {                                   \
4018                 PL_statusvalue_posix = (n);                \
4019                 if (PL_statusvalue_posix == -1)            \
4020                     PL_statusvalue = -1;                   \
4021                 else {                                     \
4022                     PL_statusvalue =                       \
4023                         (WIFEXITED(PL_statusvalue_posix) ? (WEXITSTATUS(PL_statusvalue_posix) << 8) : 0) |  \
4024                         (WIFSIGNALED(PL_statusvalue_posix) ? (WTERMSIG(PL_statusvalue_posix) & 0x7F) : 0);  \
4025                 }                                          \
4026             } STMT_END
4027 #   else
4028 #       define STATUS_NATIVE_CHILD_SET(n)                  \
4029             STMT_START {                                   \
4030                 PL_statusvalue_posix = (n);                \
4031                 if (PL_statusvalue_posix == -1)            \
4032                     PL_statusvalue = -1;                   \
4033                 else {                                     \
4034                     PL_statusvalue =                       \
4035                         PL_statusvalue_posix & 0xFFFF;     \
4036                 }                                          \
4037             } STMT_END
4038 #   endif
4039 #   define STATUS_UNIX_SET(n)		\
4040         STMT_START {			\
4041             PL_statusvalue = (n);		\
4042             if (PL_statusvalue != -1)	\
4043                 PL_statusvalue &= 0xFFFF;	\
4044         } STMT_END
4045 #   define STATUS_UNIX_EXIT_SET(n) STATUS_UNIX_SET(n)
4046 #   define STATUS_EXIT_SET(n) STATUS_UNIX_SET(n)
4047 #   define STATUS_CURRENT STATUS_UNIX
4048 #   define STATUS_EXIT STATUS_UNIX
4049 #   define STATUS_ALL_SUCCESS	(PL_statusvalue = 0, PL_statusvalue_posix = 0)
4050 #   define STATUS_ALL_FAILURE	(PL_statusvalue = 1, PL_statusvalue_posix = 1)
4051 #endif
4052 
4053 /* flags in PL_exit_flags for nature of exit() */
4054 #define PERL_EXIT_EXPECTED	0x01
4055 #define PERL_EXIT_DESTRUCT_END  0x02  /* Run END in perl_destruct */
4056 #define PERL_EXIT_WARN		0x04  /* Warn if Perl_my_exit() or Perl_my_failure_exit() called */
4057 #define PERL_EXIT_ABORT		0x08  /* Call abort() if Perl_my_exit() or Perl_my_failure_exit() called */
4058 
4059 #ifndef PERL_CORE
4060 /* format to use for version numbers in file/directory names */
4061 /* XXX move to Configure? */
4062 /* This was only ever used for the current version, and that can be done at
4063    compile time, as PERL_FS_VERSION, so should we just delete it?  */
4064 #  ifndef PERL_FS_VER_FMT
4065 #    define PERL_FS_VER_FMT	"%d.%d.%d"
4066 #  endif
4067 #endif
4068 
4069 #ifndef PERL_FS_VERSION
4070 #  define PERL_FS_VERSION	PERL_VERSION_STRING
4071 #endif
4072 
4073 /*
4074 
4075 =for apidoc_section $io
4076 =for apidoc Amn|void|PERL_FLUSHALL_FOR_CHILD
4077 
4078 This defines a way to flush all output buffers.  This may be a
4079 performance issue, so we allow people to disable it.  Also, if
4080 we are using stdio, there are broken implementations of fflush(NULL)
4081 out there, Solaris being the most prominent.
4082 
4083 =cut
4084  */
4085 
4086 #ifndef PERL_FLUSHALL_FOR_CHILD
4087 # if defined(USE_PERLIO) || defined(FFLUSH_NULL)
4088 #  define PERL_FLUSHALL_FOR_CHILD	PerlIO_flush((PerlIO*)NULL)
4089 # elif defined(FFLUSH_ALL)
4090 #  define PERL_FLUSHALL_FOR_CHILD	my_fflush_all()
4091 # else
4092 #  define PERL_FLUSHALL_FOR_CHILD	NOOP
4093 # endif
4094 #endif
4095 
4096 #ifndef PERL_WAIT_FOR_CHILDREN
4097 #  define PERL_WAIT_FOR_CHILDREN	NOOP
4098 #endif
4099 
4100 /* the traditional thread-unsafe notion of "current interpreter". */
4101 #ifndef PERL_SET_INTERP
4102 #  define PERL_SET_INTERP(i)                                            \
4103             STMT_START { PL_curinterp = (PerlInterpreter*)(i);          \
4104                          PERL_SET_NON_tTHX_CONTEXT(i);                  \
4105             } STMT_END
4106 #endif
4107 
4108 #ifndef PERL_GET_INTERP
4109 #  define PERL_GET_INTERP		(PL_curinterp)
4110 #endif
4111 
4112 #if defined(MULTIPLICITY) && !defined(PERL_GET_THX)
4113 #  define PERL_GET_THX		((PerlInterpreter *)PERL_GET_CONTEXT)
4114 #  define PERL_SET_THX(t)		PERL_SET_CONTEXT(t)
4115 #endif
4116 
4117 /*
4118     This replaces the previous %_ "hack" by the "%p" hacks.
4119     All that is required is that the perl source does not
4120     use "%-p" or "%-<number>p" or "%<number>p" formats.
4121     These formats will still work in perl code.
4122     See comments in sv.c for further details.
4123 
4124     Robin Barker 2005-07-14
4125 
4126     No longer use %1p for VDf = %vd.  RMB 2007-10-19
4127 */
4128 
4129 #ifndef SVf_
4130 #  define SVf_(n) "-" STRINGIFY(n) "p"
4131 #endif
4132 
4133 #ifndef SVf
4134 #  define SVf "-p"
4135 #endif
4136 
4137 #ifndef SVf32
4138 #  define SVf32 SVf_(32)
4139 #endif
4140 
4141 #ifndef SVf256
4142 #  define SVf256 SVf_(256)
4143 #endif
4144 
4145 #define SVfARG(p) ((void*)(p))
4146 
4147 /* Render an SV as a quoted and escaped string suitable for an error message.
4148  * Only shows the first PERL_QUOTEDPREFIX_LEN characters, and adds ellipses if the
4149  * string is too long.
4150  */
4151 #ifndef PERL_QUOTEDPREFIX_LEN
4152 # define PERL_QUOTEDPREFIX_LEN 256
4153 #endif
4154 #ifndef SVf_QUOTEDPREFIX
4155 #  define SVf_QUOTEDPREFIX "5p"
4156 #endif
4157 
4158 /* like %s but runs through the quoted prefix logic */
4159 #ifndef PVf_QUOTEDPREFIX
4160 #  define PVf_QUOTEDPREFIX "1p"
4161 #endif
4162 
4163 #ifndef HEKf
4164 #  define HEKf "2p"
4165 #endif
4166 
4167 #ifndef HEKf_QUOTEDPREFIX
4168 #  define HEKf_QUOTEDPREFIX "7p"
4169 #endif
4170 
4171 /* Not ideal, but we cannot easily include a number in an already-numeric
4172  * format sequence. */
4173 #ifndef HEKf256
4174 #  define HEKf256 "3p"
4175 #endif
4176 
4177 #ifndef HEKf256_QUOTEDPREFIX
4178 #  define HEKf256_QUOTEDPREFIX "8p"
4179 #endif
4180 
4181 #define HEKfARG(p) ((void*)(p))
4182 
4183 /* Documented in perlguts
4184  *
4185  * %4p and %9p are custom formats for handling UTF8 parameters.
4186  * They only occur when prefixed by specific other formats.
4187  */
4188 #ifndef UTF8f
4189 #  define UTF8f "d%" UVuf "%4p"
4190 #endif
4191 #ifndef UTF8f_QUOTEDPREFIX
4192 #  define UTF8f_QUOTEDPREFIX "d%" UVuf "%9p"
4193 #endif
4194 #define UTF8fARG(u,l,p) (int)cBOOL(u), (UV)(l), (void*)(p)
4195 
4196 #define PNf UTF8f
4197 #define PNfARG(pn) (int)1, (UV)PadnameLEN(pn), (void *)PadnamePV(pn)
4198 
4199 #define HvNAMEf "6p"
4200 #define HvNAMEf_QUOTEDPREFIX "10p"
4201 
4202 #define HvNAMEfARG(hv) ((void*)(hv))
4203 
4204 #ifdef PERL_CORE
4205 /* not used; but needed for backward compatibility with XS code? - RMB
4206 =for apidoc_section $io_formats
4207 =for apidoc AmnD|const char *|UVf
4208 
4209 Obsolete form of C<UVuf>, which you should convert to instead use
4210 
4211 =cut
4212 */
4213 #  undef UVf
4214 #elif !defined(UVf)
4215 #  define UVf UVuf
4216 #endif
4217 
4218 #if !defined(DEBUGGING) && !defined(NDEBUG)
4219 #  define NDEBUG 1
4220 #endif
4221 #include <assert.h>
4222 
4223 /* For functions that are marked as __attribute__noreturn__, it's not
4224    appropriate to call return.  In either case, include the lint directive.
4225  */
4226 #ifdef HASATTRIBUTE_NORETURN
4227 #  define NORETURN_FUNCTION_END NOT_REACHED;
4228 #else
4229 #  define NORETURN_FUNCTION_END NOT_REACHED; return 0
4230 #endif
4231 
4232 #ifdef HAS_BUILTIN_EXPECT
4233 #  define EXPECT(expr,val)                  __builtin_expect(expr,val)
4234 #else
4235 #  define EXPECT(expr,val)                  (expr)
4236 #endif
4237 
4238 /*
4239 =for apidoc_section $directives
4240 
4241 =for apidoc Am||LIKELY|bool expr
4242 
4243 Returns the input unchanged, but at the same time it gives a branch prediction
4244 hint to the compiler that this condition is likely to be true.
4245 
4246 =for apidoc Am||UNLIKELY|bool expr
4247 
4248 Returns the input unchanged, but at the same time it gives a branch prediction
4249 hint to the compiler that this condition is likely to be false.
4250 
4251 =cut
4252 */
4253 #define LIKELY(cond)                        EXPECT(cBOOL(cond),TRUE)
4254 #define UNLIKELY(cond)                      EXPECT(cBOOL(cond),FALSE)
4255 
4256 #ifdef HAS_BUILTIN_CHOOSE_EXPR
4257 /* placeholder */
4258 #endif
4259 
4260 /* STATIC_ASSERT_DECL/STATIC_ASSERT_STMT are like assert(), but for compile
4261    time invariants. That is, their argument must be a constant expression that
4262    can be verified by the compiler. This expression can contain anything that's
4263    known to the compiler, e.g. #define constants, enums, or sizeof (...). If
4264    the expression evaluates to 0, compilation fails.
4265    Because they generate no runtime code (i.e.  their use is "free"), they're
4266    always active, even under non-DEBUGGING builds.
4267    STATIC_ASSERT_DECL expands to a declaration and is suitable for use at
4268    file scope (outside of any function).
4269    STATIC_ASSERT_STMT expands to a statement and is suitable for use inside a
4270    function.
4271 */
4272 #if (! defined(__IBMC__) || __IBMC__ >= 1210)                               \
4273  && ((   defined(static_assert) && (   defined(_ISOC11_SOURCE)              \
4274                                     || (__STDC_VERSION__ - 0) >= 201101L))  \
4275      || (defined(__cplusplus) && __cplusplus >= 201103L))
4276 /* XXX static_assert is a macro defined in <assert.h> in C11 or a compiler
4277    builtin in C++11.  But IBM XL C V11 does not support _Static_assert, no
4278    matter what <assert.h> says.
4279 */
4280 #  define STATIC_ASSERT_DECL(COND) static_assert(COND, #COND)
4281 #else
4282 /* We use a bit-field instead of an array because gcc accepts
4283    'typedef char x[n]' where n is not a compile-time constant.
4284    We want to enforce constantness.
4285 */
4286 #  define STATIC_ASSERT_2(COND, SUFFIX) \
4287     typedef struct { \
4288         unsigned int _static_assertion_failed_##SUFFIX : (COND) ? 1 : -1; \
4289     } _static_assertion_failed_##SUFFIX PERL_UNUSED_DECL
4290 #  define STATIC_ASSERT_1(COND, SUFFIX) STATIC_ASSERT_2(COND, SUFFIX)
4291 #  define STATIC_ASSERT_DECL(COND)    STATIC_ASSERT_1(COND, __LINE__)
4292 #endif
4293 /* We need this wrapper even in C11 because 'case X: static_assert(...);' is an
4294    error (static_assert is a declaration, and only statements can have labels).
4295 */
4296 #define STATIC_ASSERT_STMT(COND)      STMT_START { STATIC_ASSERT_DECL(COND); } STMT_END
4297 
4298 #ifndef __has_builtin
4299 #  define __has_builtin(x) 0 /* not a clang style compiler */
4300 #endif
4301 
4302 #ifdef PERL_STACK_OFFSET_SSIZET
4303   typedef SSize_t Stack_off_t;
4304 #  define Stack_off_t_MAX SSize_t_MAX
4305 #else
4306   typedef I32 Stack_off_t;
4307 #  define Stack_off_t_MAX I32_MAX
4308 #endif
4309 #define PERL_STACK_OFFSET_DEFINED
4310 
4311 /*
4312 =for apidoc Am||ASSUME|bool expr
4313 C<ASSUME> is like C<assert()>, but it has a benefit in a release build. It is a
4314 hint to a compiler about a statement of fact in a function call free
4315 expression, which allows the compiler to generate better machine code.  In a
4316 debug build, C<ASSUME(x)> is a synonym for C<assert(x)>. C<ASSUME(0)> means the
4317 control path is unreachable. In a for loop, C<ASSUME> can be used to hint that
4318 a loop will run at least X times. C<ASSUME> is based off MSVC's C<__assume>
4319 intrinsic function, see its documents for more details.
4320 
4321 =cut
4322 */
4323 
4324 #if __has_builtin(__builtin_unreachable)
4325 #    define HAS_BUILTIN_UNREACHABLE
4326 #elif PERL_GCC_VERSION_GE(4,5,0)
4327 #    define HAS_BUILTIN_UNREACHABLE
4328 #endif
4329 
4330 #ifdef DEBUGGING
4331 #  define ASSUME(x) assert(x)
4332 #elif __has_builtin(__builtin_assume)
4333 #  if defined(__clang__) || defined(__clang)
4334 #    define ASSUME(x)  CLANG_DIAG_IGNORE(-Wassume)      \
4335                        __builtin_assume (x)             \
4336                        CLANG_DIAG_RESTORE
4337 #  else
4338 #    define ASSUME(x)  __builtin_assume(x)
4339 #  endif
4340 #elif defined(_MSC_VER)
4341 #  define ASSUME(x) __assume(x)
4342 #elif defined(__ARMCC_VERSION) /* untested */
4343 #  define ASSUME(x) __promise(x)
4344 #elif defined(HAS_BUILTIN_UNREACHABLE)
4345     /* Compilers can take the hint from something being unreachable */
4346 #    define ASSUME(x) ((x) ? (void) 0 : __builtin_unreachable())
4347 #else
4348     /* Not DEBUGGING, so assert() is a no-op, but a random compiler might
4349      * define assert() to its own special optimization token so pass it through
4350      * to C lib as a last resort */
4351 #  define ASSUME(x) assert(x)
4352 #endif
4353 
4354 #ifdef HAS_BUILTIN_UNREACHABLE
4355 #  define NOT_REACHED                                                       \
4356         STMT_START {                                                        \
4357             ASSUME(!"UNREACHABLE"); __builtin_unreachable();                \
4358         } STMT_END
4359 #  undef HAS_BUILTIN_UNREACHABLE /* Don't leak out this internal symbol */
4360 #elif ! defined(__GNUC__) && (defined(__sun) || defined(__hpux))
4361     /* These just complain that NOT_REACHED isn't reached */
4362 #  define NOT_REACHED
4363 #else
4364 #  define NOT_REACHED  ASSUME(!"UNREACHABLE")
4365 #endif
4366 
4367 /* Some unistd.h's give a prototype for pause() even though
4368    HAS_PAUSE ends up undefined.  This causes the #define
4369    below to be rejected by the compiler.  Sigh.
4370 */
4371 #ifdef HAS_PAUSE
4372 #define Pause	pause
4373 #else
4374 #define Pause() sleep((32767<<16)+32767)
4375 #endif
4376 
4377 #ifndef IOCPARM_LEN
4378 #   ifdef IOCPARM_MASK
4379         /* on BSDish systems we're safe */
4380 #	define IOCPARM_LEN(x)  (((x) >> 16) & IOCPARM_MASK)
4381 #   elif defined(_IOC_SIZE) && defined(__GLIBC__)
4382         /* on Linux systems we're safe; except when we're not [perl #38223] */
4383 #	define IOCPARM_LEN(x) (_IOC_SIZE(x) < 256 ? 256 : _IOC_SIZE(x))
4384 #   else
4385         /* otherwise guess at what's safe */
4386 #	define IOCPARM_LEN(x)	256
4387 #   endif
4388 #endif
4389 
4390 #if defined(__CYGWIN__)
4391 /* USEMYBINMODE
4392  *   This symbol, if defined, indicates that the program should
4393  *   use the routine my_binmode(FILE *fp, char iotype, int mode) to insure
4394  *   that a file is in "binary" mode -- that is, that no translation
4395  *   of bytes occurs on read or write operations.
4396  */
4397 #  define USEMYBINMODE /**/
4398 #  include <io.h> /* for setmode() prototype */
4399 #  define my_binmode(fp, iotype, mode) \
4400             cBOOL(PerlLIO_setmode(fileno(fp), mode) != -1)
4401 #endif
4402 
4403 #ifdef __CYGWIN__
4404 void init_os_extras(void);
4405 #endif
4406 
4407 #ifdef UNION_ANY_DEFINITION
4408 UNION_ANY_DEFINITION;
4409 #else
4410 union any {
4411     void*       any_ptr;
4412     SV*         any_sv;
4413     SV**        any_svp;
4414     GV*         any_gv;
4415     AV*         any_av;
4416     HV*         any_hv;
4417     OP*         any_op;
4418     char*       any_pv;
4419     char**      any_pvp;
4420     I32         any_i32;
4421     U32         any_u32;
4422     IV          any_iv;
4423     UV          any_uv;
4424     long        any_long;
4425     bool        any_bool;
4426     Size_t      any_size;
4427     SSize_t     any_ssize;
4428     STRLEN      any_strlen;
4429     void        (*any_dptr) (void*);
4430     void        (*any_dxptr) (pTHX_ void*);
4431 };
4432 #endif
4433 
4434 typedef I32 (*filter_t) (pTHX_ int, SV *, int);
4435 
4436 #define FILTER_READ(idx, sv, len)  filter_read(idx, sv, len)
4437 #define FILTER_DATA(idx) \
4438             (PL_parser ? AvARRAY(PL_parser->rsfp_filters)[idx] : NULL)
4439 #define FILTER_ISREADER(idx) \
4440             (PL_parser && PL_parser->rsfp_filters \
4441                 && idx >= AvFILLp(PL_parser->rsfp_filters))
4442 #define PERL_FILTER_EXISTS(i) \
4443             (PL_parser && PL_parser->rsfp_filters \
4444                 && (Size_t) (i) < av_count(PL_parser->rsfp_filters))
4445 
4446 #if defined(_AIX) && !defined(_AIX43)
4447 #if defined(USE_REENTRANT) || defined(_REENTRANT) || defined(_THREAD_SAFE)
4448 /* We cannot include <crypt.h> to get the struct crypt_data
4449  * because of setkey prototype problems when threading */
4450 typedef        struct crypt_data {     /* straight from /usr/include/crypt.h */
4451     /* From OSF, Not needed in AIX
4452        char C[28], D[28];
4453     */
4454     char E[48];
4455     char KS[16][48];
4456     char block[66];
4457     char iobuf[16];
4458 } CRYPTD;
4459 #endif /* threading */
4460 #endif /* AIX */
4461 
4462 #ifndef PERL_CALLCONV
4463 #  ifdef __cplusplus
4464 #    define PERL_CALLCONV  EXTERN_C
4465 #  else
4466 #    define PERL_CALLCONV
4467 #  endif
4468 #endif
4469 #ifndef PERL_CALLCONV_NO_RET
4470 #    define PERL_CALLCONV_NO_RET PERL_CALLCONV
4471 #endif
4472 
4473 /* PERL_STATIC_NO_RET is supposed to be equivalent to STATIC on builds that
4474    dont have a noreturn as a declaration specifier
4475 */
4476 #ifndef PERL_STATIC_NO_RET
4477 #  define PERL_STATIC_NO_RET STATIC
4478 #endif
4479 
4480 /* PERL_STATIC_INLINE_NO_RET is supposed to be equivalent to PERL_STATIC_INLINE
4481  * on builds that dont have a noreturn as a declaration specifier
4482 */
4483 #ifndef PERL_STATIC_INLINE_NO_RET
4484 #  define PERL_STATIC_INLINE_NO_RET PERL_STATIC_INLINE
4485 #endif
4486 
4487 #ifndef PERL_STATIC_FORCE_INLINE
4488 #  define PERL_STATIC_FORCE_INLINE PERL_STATIC_INLINE
4489 #endif
4490 
4491 #ifndef PERL_STATIC_FORCE_INLINE_NO_RET
4492 #  define PERL_STATIC_FORCE_INLINE_NO_RET PERL_STATIC_INLINE
4493 #endif
4494 
4495 #if !defined(OS2)
4496 #  include "iperlsys.h"
4497 #endif
4498 
4499 #ifdef __LIBCATAMOUNT__
4500 #undef HAS_PASSWD  /* unixish.h but not unixish enough. */
4501 #undef HAS_GROUP
4502 #define FAKE_BIT_BUCKET
4503 #endif
4504 
4505 /* [perl #22371] Algorithmic Complexity Attack on Perl 5.6.1, 5.8.0.
4506  * Note that the USE_HASH_SEED and similar defines are *NOT* defined by
4507  * Configure, despite their names being similar to other defines like
4508  * USE_ITHREADS.  Configure in fact knows nothing about the randomised
4509  * hashes.  Therefore to enable/disable the hash randomisation defines
4510  * use the Configure -Accflags=... instead. */
4511 #if !defined(NO_HASH_SEED) && !defined(USE_HASH_SEED)
4512 #  define USE_HASH_SEED
4513 #endif
4514 
4515 #include "perly.h"
4516 
4517 
4518 /* macros to define bit-fields in structs. */
4519 #ifndef PERL_BITFIELD8
4520 #  ifdef HAS_NON_INT_BITFIELDS
4521 #  define PERL_BITFIELD8 U8
4522 #  else
4523 #    define PERL_BITFIELD8 unsigned
4524 #  endif
4525 #endif
4526 #ifndef PERL_BITFIELD16
4527 #  ifdef HAS_NON_INT_BITFIELDS
4528 #  define PERL_BITFIELD16 U16
4529 #  else
4530 #    define PERL_BITFIELD16 unsigned
4531 #  endif
4532 #endif
4533 #ifndef PERL_BITFIELD32
4534 #  ifdef HAS_NON_INT_BITFIELDS
4535 #  define PERL_BITFIELD32 U32
4536 #  else
4537 #    define PERL_BITFIELD32 unsigned
4538 #  endif
4539 #endif
4540 
4541 #include "sv.h"
4542 #include "regexp.h"
4543 #include "util.h"
4544 #include "form.h"
4545 #include "gv.h"
4546 #include "pad.h"
4547 #include "cv.h"
4548 #include "opnames.h"
4549 #include "op.h"
4550 #include "hv.h"
4551 #include "cop.h"
4552 #include "av.h"
4553 #include "mg.h"
4554 #include "scope.h"
4555 #include "warnings.h"
4556 #include "utf8.h"
4557 
4558 /* these would be in doio.h if there was such a file */
4559 #define my_stat()  my_stat_flags(SV_GMAGIC)
4560 #define my_lstat() my_lstat_flags(SV_GMAGIC)
4561 
4562 /* defined in sv.c, but also used in [ach]v.c */
4563 #undef _XPV_HEAD
4564 #undef _XPVMG_HEAD
4565 #undef _XPVCV_COMMON
4566 
4567 #include "parser.h"
4568 
4569 typedef struct magic_state MGS;	/* struct magic_state defined in mg.c */
4570 
4571 #if defined(PERL_IN_REGEX_ENGINE) || defined(PERL_EXT_RE_BUILD)
4572 
4573 /* These have to be predeclared, as they are used in proto.h which is #included
4574  * before their definitions in regcomp.h. */
4575 
4576 struct scan_data_t;
4577 typedef struct regnode_charclass regnode_charclass;
4578 
4579 /* A hopefully less confusing name.  The sub-classes are all Posix classes only
4580  * used under /l matching */
4581 typedef struct regnode_charclass_posixl regnode_charclass_class;
4582 typedef struct regnode_charclass_posixl regnode_charclass_posixl;
4583 
4584 typedef struct regnode_ssc regnode_ssc;
4585 typedef struct RExC_state_t RExC_state_t;
4586 struct _reg_trie_data;
4587 typedef struct scan_data_t scan_data_t;
4588 
4589 #endif
4590 
4591 struct ptr_tbl_ent {
4592     struct ptr_tbl_ent*		next;
4593     const void*			oldval;
4594     void*			newval;
4595 };
4596 
4597 struct ptr_tbl {
4598     struct ptr_tbl_ent**	tbl_ary;
4599     UV				tbl_max;
4600     UV				tbl_items;
4601     struct ptr_tbl_arena	*tbl_arena;
4602     struct ptr_tbl_ent		*tbl_arena_next;
4603     struct ptr_tbl_ent		*tbl_arena_end;
4604 };
4605 
4606 #if defined(htonl) && !defined(HAS_HTONL)
4607 #define HAS_HTONL
4608 #endif
4609 #if defined(htons) && !defined(HAS_HTONS)
4610 #define HAS_HTONS
4611 #endif
4612 #if defined(ntohl) && !defined(HAS_NTOHL)
4613 #define HAS_NTOHL
4614 #endif
4615 #if defined(ntohs) && !defined(HAS_NTOHS)
4616 #define HAS_NTOHS
4617 #endif
4618 #ifndef HAS_HTONL
4619 #define HAS_HTONS
4620 #define HAS_HTONL
4621 #define HAS_NTOHS
4622 #define HAS_NTOHL
4623 #  if (BYTEORDER & 0xffff) == 0x4321
4624 /* Big endian system, so ntohl, ntohs, htonl and htons do not need to
4625    re-order their values. However, to behave identically to the alternative
4626    implementations, they should truncate to the correct size.  */
4627 #    define ntohl(x)    ((x)&0xFFFFFFFF)
4628 #    define htonl(x)    ntohl(x)
4629 #    define ntohs(x)    ((x)&0xFFFF)
4630 #    define htons(x)    ntohs(x)
4631 #  elif BYTEORDER == 0x1234 || BYTEORDER == 0x12345678
4632 
4633 /* Note that we can't straight out declare our own htonl and htons because
4634    the Win32 build process forcibly undefines HAS_HTONL etc for its miniperl,
4635    to avoid the overhead of initialising the socket subsystem, but the headers
4636    that *declare* the various functions are still seen. If we declare our own
4637    htonl etc they will clash with the declarations in the Win32 headers.  */
4638 
4639 PERL_STATIC_INLINE U32
my_swap32(const U32 x)4640 my_swap32(const U32 x) {
4641     return ((x & 0xFF) << 24) | ((x >> 24) & 0xFF)
4642         | ((x & 0x0000FF00) << 8) | ((x & 0x00FF0000) >> 8);
4643 }
4644 
4645 PERL_STATIC_INLINE U16
my_swap16(const U16 x)4646 my_swap16(const U16 x) {
4647     return ((x & 0xFF) << 8) | ((x >> 8) & 0xFF);
4648 }
4649 
4650 #    define htonl(x)    my_swap32(x)
4651 #    define ntohl(x)    my_swap32(x)
4652 #    define ntohs(x)    my_swap16(x)
4653 #    define htons(x)    my_swap16(x)
4654 #  else
4655 #    error "Unsupported byteorder"
4656 /* The C pre-processor doesn't let us return the value of BYTEORDER as part of
4657    the error message. Please check the value of the macro BYTEORDER, as defined
4658    in config.h. The values of BYTEORDER we expect are
4659 
4660             big endian  little endian
4661    32 bit       0x4321  0x1234
4662    64 bit   0x87654321  0x12345678
4663 
4664    If you have a system with a different byte order, please see
4665    pod/perlhack.pod for how to submit a patch to add supporting code.
4666 */
4667 #  endif
4668 #endif
4669 
4670 /*
4671  * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
4672  * -DWS
4673  */
4674 #if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678
4675 /* Little endian system, so vtohl, vtohs, htovl and htovs do not need to
4676    re-order their values. However, to behave identically to the alternative
4677    implementations, they should truncate to the correct size.  */
4678 #  define vtohl(x)      ((x)&0xFFFFFFFF)
4679 #  define vtohs(x)      ((x)&0xFFFF)
4680 #  define htovl(x)      vtohl(x)
4681 #  define htovs(x)      vtohs(x)
4682 #elif BYTEORDER == 0x4321 || BYTEORDER == 0x87654321
4683 #  define vtohl(x)	((((x)&0xFF)<<24)	\
4684                         +(((x)>>24)&0xFF)	\
4685                         +(((x)&0x0000FF00)<<8)	\
4686                         +(((x)&0x00FF0000)>>8)	)
4687 #  define vtohs(x)	((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
4688 #  define htovl(x)	vtohl(x)
4689 #  define htovs(x)	vtohs(x)
4690 #else
4691 #  error "Unsupported byteorder"
4692 /* If you have need for current perl on PDP-11 or similar, and can help test
4693    that blead keeps working on a mixed-endian system, then see
4694    pod/perlhack.pod for how to submit patches to things working again.  */
4695 #endif
4696 
4697 /* *MAX Plus 1. A floating point value.
4698    Hopefully expressed in a way that dodgy floating point can't mess up.
4699    >> 2 rather than 1, so that value is safely less than I32_MAX after 1
4700    is added to it
4701    May find that some broken compiler will want the value cast to I32.
4702    [after the shift, as signed >> may not be as secure as unsigned >>]
4703 */
4704 #define I32_MAX_P1 (2.0 * (1 + (((U32)I32_MAX) >> 1)))
4705 #define U32_MAX_P1 (4.0 * (1 + ((U32_MAX) >> 2)))
4706 /* For compilers that can't correctly cast NVs over 0x7FFFFFFF (or
4707    0x7FFFFFFFFFFFFFFF) to an unsigned integer. In the future, sizeof(UV)
4708    may be greater than sizeof(IV), so don't assume that half max UV is max IV.
4709 */
4710 #define U32_MAX_P1_HALF (2.0 * (1 + ((U32_MAX) >> 2)))
4711 
4712 #define UV_MAX_P1 (4.0 * (1 + ((UV_MAX) >> 2)))
4713 #define IV_MAX_P1 (2.0 * (1 + (((UV)IV_MAX) >> 1)))
4714 #define UV_MAX_P1_HALF (2.0 * (1 + ((UV_MAX) >> 2)))
4715 
4716 /* This may look like unnecessary jumping through hoops, but converting
4717    out of range floating point values to integers *is* undefined behaviour,
4718    and it is starting to bite.
4719 
4720 =for apidoc_section $casting
4721 =for apidoc Am|I32|I_32|NV what
4722 Cast an NV to I32 while avoiding undefined C behavior
4723 
4724 =for apidoc Am|U32|U_32|NV what
4725 Cast an NV to U32 while avoiding undefined C behavior
4726 
4727 =for apidoc Am|IV|I_V|NV what
4728 Cast an NV to IV while avoiding undefined C behavior
4729 
4730 =for apidoc Am|UV|U_V|NV what
4731 Cast an NV to UV while avoiding undefined C behavior
4732 
4733 =cut
4734 */
4735 #ifndef CAST_INLINE
4736 #define I_32(what) (cast_i32((NV)(what)))
4737 #define U_32(what) (cast_ulong((NV)(what)))
4738 #define I_V(what) (cast_iv((NV)(what)))
4739 #define U_V(what) (cast_uv((NV)(what)))
4740 #else
4741 #define I_32(n) ((n) < I32_MAX_P1 ? ((n) < I32_MIN ? I32_MIN : (I32) (n)) \
4742                   : ((n) < U32_MAX_P1 ? (I32)(U32) (n) \
4743                      : ((n) > 0 ? (I32) U32_MAX : 0 /* NaN */)))
4744 #define U_32(n) ((n) < 0.0 ? ((n) < I32_MIN ? (UV) I32_MIN : (U32)(I32) (n)) \
4745                   : ((n) < U32_MAX_P1 ? (U32) (n) \
4746                      : ((n) > 0 ? U32_MAX : 0 /* NaN */)))
4747 #define I_V(n) (LIKELY((n) < IV_MAX_P1) ? (UNLIKELY((n) < IV_MIN) ? IV_MIN : (IV) (n)) \
4748                   : (LIKELY((n) < UV_MAX_P1) ? (IV)(UV) (n) \
4749                      : ((n) > 0 ? (IV)UV_MAX : 0 /* NaN */)))
4750 #define U_V(n) ((n) < 0.0 ? (UNLIKELY((n) < IV_MIN) ? (UV) IV_MIN : (UV)(IV) (n)) \
4751                   : (LIKELY((n) < UV_MAX_P1) ? (UV) (n) \
4752                      : ((n) > 0 ? UV_MAX : 0 /* NaN */)))
4753 #endif
4754 
4755 #define U_S(what) ((U16)U_32(what))
4756 #define U_I(what) ((unsigned int)U_32(what))
4757 #define U_L(what) U_32(what)
4758 
4759 /*
4760 =for apidoc_section $integer
4761 =for apidoc Amn|IV|IV_MAX
4762 The largest signed integer that fits in an IV on this platform.
4763 
4764 =for apidoc Amn|IV|IV_MIN
4765 The negative signed integer furthest away from 0 that fits in an IV on this
4766 platform.
4767 
4768 =for apidoc Amn|UV|UV_MAX
4769 The largest unsigned integer that fits in a UV on this platform.
4770 
4771 =for apidoc Amn|UV|UV_MIN
4772 The smallest unsigned integer that fits in a UV on this platform.  It should
4773 equal zero.
4774 
4775 =cut
4776 */
4777 
4778 #ifdef HAS_SIGNBIT
4779 #  ifndef Perl_signbit
4780 #    define Perl_signbit signbit
4781 #  endif
4782 #endif
4783 
4784 /* These do not care about the fractional part, only about the range. */
4785 #define NV_WITHIN_IV(nv) (I_V(nv) >= IV_MIN && I_V(nv) <= IV_MAX)
4786 #define NV_WITHIN_UV(nv) ((nv)>=0.0 && U_V(nv) >= UV_MIN && U_V(nv) <= UV_MAX)
4787 
4788 /* Used with UV/IV arguments: */
4789                                         /* XXXX: need to speed it up */
4790 #define CLUMP_2UV(iv)	((iv) < 0 ? 0 : (UV)(iv))
4791 #define CLUMP_2IV(uv)	((uv) > (UV)IV_MAX ? IV_MAX : (IV)(uv))
4792 
4793 #ifndef MAXSYSFD
4794 #   define MAXSYSFD 2
4795 #endif
4796 
4797 #ifndef __cplusplus
4798 #if !defined(WIN32)
4799 Uid_t getuid (void);
4800 Uid_t geteuid (void);
4801 Gid_t getgid (void);
4802 Gid_t getegid (void);
4803 #endif
4804 #endif
4805 
4806 #ifndef Perl_debug_log
4807 #  define Perl_debug_log	PerlIO_stderr()
4808 #endif
4809 
4810 #ifndef Perl_error_log
4811 #  define Perl_error_log	(PL_stderrgv			\
4812                                  && isGV(PL_stderrgv)		\
4813                                  && GvIOp(PL_stderrgv)          \
4814                                  && IoOFP(GvIOp(PL_stderrgv))	\
4815                                  ? IoOFP(GvIOp(PL_stderrgv))	\
4816                                  : PerlIO_stderr())
4817 #endif
4818 
4819 
4820 #define DEBUG_p_FLAG		0x00000001 /*      1 */
4821 #define DEBUG_s_FLAG		0x00000002 /*      2 */
4822 #define DEBUG_l_FLAG		0x00000004 /*      4 */
4823 #define DEBUG_t_FLAG		0x00000008 /*      8 */
4824 #define DEBUG_o_FLAG		0x00000010 /*     16 */
4825 #define DEBUG_c_FLAG		0x00000020 /*     32 */
4826 #define DEBUG_P_FLAG		0x00000040 /*     64 */
4827 #define DEBUG_m_FLAG		0x00000080 /*    128 */
4828 #define DEBUG_f_FLAG		0x00000100 /*    256 */
4829 #define DEBUG_r_FLAG		0x00000200 /*    512 */
4830 #define DEBUG_x_FLAG		0x00000400 /*   1024 */
4831 #define DEBUG_u_FLAG		0x00000800 /*   2048 */
4832 /* U is reserved for Unofficial, exploratory hacking */
4833 #define DEBUG_U_FLAG		0x00001000 /*   4096 */
4834 #define DEBUG_h_FLAG            0x00002000 /*   8192 */
4835 #define DEBUG_X_FLAG		0x00004000 /*  16384 */
4836 #define DEBUG_D_FLAG		0x00008000 /*  32768 */
4837 #define DEBUG_S_FLAG		0x00010000 /*  65536 */
4838 #define DEBUG_T_FLAG		0x00020000 /* 131072 */
4839 #define DEBUG_R_FLAG		0x00040000 /* 262144 */
4840 #define DEBUG_J_FLAG		0x00080000 /* 524288 */
4841 #define DEBUG_v_FLAG		0x00100000 /*1048576 */
4842 #define DEBUG_C_FLAG		0x00200000 /*2097152 */
4843 #define DEBUG_A_FLAG		0x00400000 /*4194304 */
4844 #define DEBUG_q_FLAG		0x00800000 /*8388608 */
4845 #define DEBUG_M_FLAG		0x01000000 /*16777216*/
4846 #define DEBUG_B_FLAG		0x02000000 /*33554432*/
4847 #define DEBUG_L_FLAG		0x04000000 /*67108864*/
4848 #define DEBUG_i_FLAG		0x08000000 /*134217728*/
4849 #define DEBUG_y_FLAG		0x10000000 /*268435456*/
4850 #define DEBUG_MASK		0x1FFFEFFF /* mask of all the standard flags */
4851 
4852 #define DEBUG_DB_RECURSE_FLAG	0x40000000
4853 #define DEBUG_TOP_FLAG		0x80000000 /* -D was given --> PL_debug |= FLAG */
4854 
4855 /* Both flags have to be set */
4856 #  define DEBUG_BOTH_FLAGS_TEST_(flag1, flag2)              \
4857             UNLIKELY((PL_debug & ((flag1)|(flag2)))         \
4858                               == ((flag1)|(flag2)))
4859 
4860 #  define DEBUG_p_TEST_ UNLIKELY(PL_debug & DEBUG_p_FLAG)
4861 #  define DEBUG_s_TEST_ UNLIKELY(PL_debug & DEBUG_s_FLAG)
4862 #  define DEBUG_l_TEST_ UNLIKELY(PL_debug & DEBUG_l_FLAG)
4863 #  define DEBUG_t_TEST_ UNLIKELY(PL_debug & DEBUG_t_FLAG)
4864 #  define DEBUG_o_TEST_ UNLIKELY(PL_debug & DEBUG_o_FLAG)
4865 #  define DEBUG_c_TEST_ UNLIKELY(PL_debug & DEBUG_c_FLAG)
4866 #  define DEBUG_P_TEST_ UNLIKELY(PL_debug & DEBUG_P_FLAG)
4867 #  define DEBUG_m_TEST_ UNLIKELY(PL_debug & DEBUG_m_FLAG)
4868 #  define DEBUG_f_TEST_ UNLIKELY(PL_debug & DEBUG_f_FLAG)
4869 #  define DEBUG_r_TEST_ UNLIKELY(PL_debug & DEBUG_r_FLAG)
4870 #  define DEBUG_x_TEST_ UNLIKELY(PL_debug & DEBUG_x_FLAG)
4871 #  define DEBUG_u_TEST_ UNLIKELY(PL_debug & DEBUG_u_FLAG)
4872 #  define DEBUG_U_TEST_ UNLIKELY(PL_debug & DEBUG_U_FLAG)
4873 #  define DEBUG_h_TEST_ UNLIKELY(PL_debug & DEBUG_h_FLAG)
4874 #  define DEBUG_X_TEST_ UNLIKELY(PL_debug & DEBUG_X_FLAG)
4875 #  define DEBUG_D_TEST_ UNLIKELY(PL_debug & DEBUG_D_FLAG)
4876 #  define DEBUG_S_TEST_ UNLIKELY(PL_debug & DEBUG_S_FLAG)
4877 #  define DEBUG_T_TEST_ UNLIKELY(PL_debug & DEBUG_T_FLAG)
4878 #  define DEBUG_R_TEST_ UNLIKELY(PL_debug & DEBUG_R_FLAG)
4879 #  define DEBUG_J_TEST_ UNLIKELY(PL_debug & DEBUG_J_FLAG)
4880 #  define DEBUG_v_TEST_ UNLIKELY(PL_debug & DEBUG_v_FLAG)
4881 #  define DEBUG_C_TEST_ UNLIKELY(PL_debug & DEBUG_C_FLAG)
4882 #  define DEBUG_A_TEST_ UNLIKELY(PL_debug & DEBUG_A_FLAG)
4883 #  define DEBUG_q_TEST_ UNLIKELY(PL_debug & DEBUG_q_FLAG)
4884 #  define DEBUG_M_TEST_ UNLIKELY(PL_debug & DEBUG_M_FLAG)
4885 #  define DEBUG_B_TEST_ UNLIKELY(PL_debug & DEBUG_B_FLAG)
4886 
4887 /* Locale initialization comes earlier than PL_debug gets set,
4888  * DEBUG_LOCALE_INITIALIZATION_, if defined, will be set early enough */
4889 #  ifndef DEBUG_LOCALE_INITIALIZATION_
4890 #    define DEBUG_LOCALE_INITIALIZATION_ 0
4891 #  endif
4892 #  define DEBUG_L_TEST_                                                 \
4893         (   UNLIKELY(DEBUG_LOCALE_INITIALIZATION_)                      \
4894          || UNLIKELY(PL_debug & DEBUG_L_FLAG))
4895 #  define DEBUG_Lv_TEST_                                                \
4896         (   UNLIKELY(DEBUG_LOCALE_INITIALIZATION_)                      \
4897          || UNLIKELY(DEBUG_BOTH_FLAGS_TEST_(DEBUG_L_FLAG, DEBUG_v_FLAG)))
4898 #  define DEBUG_i_TEST_ UNLIKELY(PL_debug & DEBUG_i_FLAG)
4899 #  define DEBUG_y_TEST_ UNLIKELY(PL_debug & DEBUG_y_FLAG)
4900 #  define DEBUG_Xv_TEST_ DEBUG_BOTH_FLAGS_TEST_(DEBUG_X_FLAG, DEBUG_v_FLAG)
4901 #  define DEBUG_Uv_TEST_ DEBUG_BOTH_FLAGS_TEST_(DEBUG_U_FLAG, DEBUG_v_FLAG)
4902 #  define DEBUG_Pv_TEST_ DEBUG_BOTH_FLAGS_TEST_(DEBUG_P_FLAG, DEBUG_v_FLAG)
4903 #  define DEBUG_yv_TEST_ DEBUG_BOTH_FLAGS_TEST_(DEBUG_y_FLAG, DEBUG_v_FLAG)
4904 
4905 #ifdef DEBUGGING
4906 
4907 #  define DEBUG_p_TEST DEBUG_p_TEST_
4908 #  define DEBUG_s_TEST DEBUG_s_TEST_
4909 #  define DEBUG_l_TEST DEBUG_l_TEST_
4910 #  define DEBUG_t_TEST DEBUG_t_TEST_
4911 #  define DEBUG_o_TEST DEBUG_o_TEST_
4912 #  define DEBUG_c_TEST DEBUG_c_TEST_
4913 #  define DEBUG_P_TEST DEBUG_P_TEST_
4914 #  define DEBUG_m_TEST DEBUG_m_TEST_
4915 #  define DEBUG_f_TEST DEBUG_f_TEST_
4916 #  define DEBUG_r_TEST DEBUG_r_TEST_
4917 #  define DEBUG_x_TEST DEBUG_x_TEST_
4918 #  define DEBUG_u_TEST DEBUG_u_TEST_
4919 #  define DEBUG_U_TEST DEBUG_U_TEST_
4920 #  define DEBUG_h_TEST DEBUG_h_TEST_
4921 #  define DEBUG_X_TEST DEBUG_X_TEST_
4922 #  define DEBUG_D_TEST DEBUG_D_TEST_
4923 #  define DEBUG_S_TEST DEBUG_S_TEST_
4924 #  define DEBUG_T_TEST DEBUG_T_TEST_
4925 #  define DEBUG_R_TEST DEBUG_R_TEST_
4926 #  define DEBUG_J_TEST DEBUG_J_TEST_
4927 #  define DEBUG_v_TEST DEBUG_v_TEST_
4928 #  define DEBUG_C_TEST DEBUG_C_TEST_
4929 #  define DEBUG_A_TEST DEBUG_A_TEST_
4930 #  define DEBUG_q_TEST DEBUG_q_TEST_
4931 #  define DEBUG_M_TEST DEBUG_M_TEST_
4932 #  define DEBUG_B_TEST DEBUG_B_TEST_
4933 #  define DEBUG_L_TEST DEBUG_L_TEST_
4934 #  define DEBUG_i_TEST DEBUG_i_TEST_
4935 #  define DEBUG_y_TEST DEBUG_y_TEST_
4936 #  define DEBUG_Xv_TEST DEBUG_Xv_TEST_
4937 #  define DEBUG_Uv_TEST DEBUG_Uv_TEST_
4938 #  define DEBUG_Pv_TEST DEBUG_Pv_TEST_
4939 #  define DEBUG_Lv_TEST DEBUG_Lv_TEST_
4940 #  define DEBUG_yv_TEST DEBUG_yv_TEST_
4941 
4942 #  define PERL_DEB(a)                  a
4943 #  define PERL_DEB2(a,b)               a
4944 #  define PERL_DEBUG(a) if (PL_debug)  a
4945 #  define DEBUG_p(a) if (DEBUG_p_TEST) a
4946 #  define DEBUG_s(a) if (DEBUG_s_TEST) a
4947 #  define DEBUG_l(a) if (DEBUG_l_TEST) a
4948 #  define DEBUG_t(a) if (DEBUG_t_TEST) a
4949 #  define DEBUG_o(a) if (DEBUG_o_TEST) a
4950 #  define DEBUG_c(a) if (DEBUG_c_TEST) a
4951 #  define DEBUG_P(a) if (DEBUG_P_TEST) a
4952 
4953      /* Temporarily turn off memory debugging in case the a
4954       * does memory allocation, either directly or indirectly. */
4955 #  define DEBUG_m(a)  \
4956     STMT_START {					                \
4957         if (PERL_GET_INTERP) {                                          \
4958                                 dTHX;                                   \
4959                                 if (DEBUG_m_TEST) {                     \
4960                                     PL_debug &= ~DEBUG_m_FLAG;          \
4961                                     a;                                  \
4962                                     PL_debug |= DEBUG_m_FLAG;           \
4963                                 }                                       \
4964                               }                                         \
4965     } STMT_END
4966 
4967 /* These allow you to customize your debugging output  for specialized,
4968  * generally temporary ad-hoc purposes.  For example, if you need 'errno'
4969  * preserved, you can add definitions to these macros (either in this file for
4970  * the whole program, or before the #include "perl.h" in a particular .c file
4971  * you're trying to debug) and recompile:
4972  *
4973  * #define DEBUG_PRE_STMTS   dSAVE_ERRNO;
4974  * #define DEBUG_POST_STMTS  RESTORE_ERRNO;
4975  *
4976  * Other potential things include displaying timestamps, location information,
4977  * which thread, etc.  Here's an example with both errno and location info:
4978  *
4979  * #define DEBUG_PRE_STMTS   dSAVE_ERRNO;  \
4980  *              PerlIO_printf(Perl_debug_log, "%s:%d: ", __FILE__, __LINE__);
4981  * #define DEBUG_POST  RESTORE_ERRNO;
4982  *
4983  * All DEBUG statements in the compiled scope will have these extra statements
4984  * compiled in; they will be executed only for the DEBUG statements whose flags
4985  * are turned on.
4986  */
4987 #ifndef DEBUG_PRE_STMTS
4988 #  define DEBUG_PRE_STMTS
4989 #endif
4990 #ifndef DEBUG_POST_STMTS
4991 #  define DEBUG_POST_STMTS
4992 #endif
4993 
4994 #  define DEBUG__(t, a)                                                 \
4995         STMT_START {                                                    \
4996             if (t) {                                                    \
4997                 DEBUG_PRE_STMTS a; DEBUG_POST_STMTS                     \
4998             }                                                           \
4999         } STMT_END
5000 
5001 #  define DEBUG_f(a) DEBUG__(DEBUG_f_TEST, a)
5002 
5003 /* For re_comp.c, re_exec.c, assume -Dr has been specified */
5004 #  ifdef PERL_EXT_RE_BUILD
5005 #    define DEBUG_r(a) STMT_START {                                     \
5006                             DEBUG_PRE_STMTS a; DEBUG_POST_STMTS         \
5007                        } STMT_END;
5008 #  else
5009 #    define DEBUG_r(a) DEBUG__(DEBUG_r_TEST, a)
5010 #  endif /* PERL_EXT_RE_BUILD */
5011 
5012 #  define DEBUG_x(a) DEBUG__(DEBUG_x_TEST, a)
5013 #  define DEBUG_u(a) DEBUG__(DEBUG_u_TEST, a)
5014 #  define DEBUG_U(a) DEBUG__(DEBUG_U_TEST, a)
5015 #  define DEBUG_X(a) DEBUG__(DEBUG_X_TEST, a)
5016 #  define DEBUG_D(a) DEBUG__(DEBUG_D_TEST, a)
5017 #  define DEBUG_Xv(a) DEBUG__(DEBUG_Xv_TEST, a)
5018 #  define DEBUG_Uv(a) DEBUG__(DEBUG_Uv_TEST, a)
5019 #  define DEBUG_Pv(a) DEBUG__(DEBUG_Pv_TEST, a)
5020 #  define DEBUG_Lv(a) DEBUG__(DEBUG_Lv_TEST, a)
5021 #  define DEBUG_yv(a) DEBUG__(DEBUG_yv_TEST, a)
5022 
5023 #  define DEBUG_S(a) DEBUG__(DEBUG_S_TEST, a)
5024 #  define DEBUG_T(a) DEBUG__(DEBUG_T_TEST, a)
5025 #  define DEBUG_R(a) DEBUG__(DEBUG_R_TEST, a)
5026 #  define DEBUG_v(a) DEBUG__(DEBUG_v_TEST, a)
5027 #  define DEBUG_C(a) DEBUG__(DEBUG_C_TEST, a)
5028 #  define DEBUG_A(a) DEBUG__(DEBUG_A_TEST, a)
5029 #  define DEBUG_q(a) DEBUG__(DEBUG_q_TEST, a)
5030 #  define DEBUG_M(a) DEBUG__(DEBUG_M_TEST, a)
5031 #  define DEBUG_B(a) DEBUG__(DEBUG_B_TEST, a)
5032 #  define DEBUG_L(a) DEBUG__(DEBUG_L_TEST, a)
5033 #  define DEBUG_i(a) DEBUG__(DEBUG_i_TEST, a)
5034 #  define DEBUG_y(a) DEBUG__(DEBUG_y_TEST, a)
5035 
5036 #else /* ! DEBUGGING below */
5037 
5038 #  define DEBUG_p_TEST (0)
5039 #  define DEBUG_s_TEST (0)
5040 #  define DEBUG_l_TEST (0)
5041 #  define DEBUG_t_TEST (0)
5042 #  define DEBUG_o_TEST (0)
5043 #  define DEBUG_c_TEST (0)
5044 #  define DEBUG_P_TEST (0)
5045 #  define DEBUG_m_TEST (0)
5046 #  define DEBUG_f_TEST (0)
5047 #  define DEBUG_r_TEST (0)
5048 #  define DEBUG_x_TEST (0)
5049 #  define DEBUG_u_TEST (0)
5050 #  define DEBUG_U_TEST (0)
5051 #  define DEBUG_h_TEST (0)
5052 #  define DEBUG_X_TEST (0)
5053 #  define DEBUG_D_TEST (0)
5054 #  define DEBUG_S_TEST (0)
5055 #  define DEBUG_T_TEST (0)
5056 #  define DEBUG_R_TEST (0)
5057 #  define DEBUG_J_TEST (0)
5058 #  define DEBUG_v_TEST (0)
5059 #  define DEBUG_C_TEST (0)
5060 #  define DEBUG_A_TEST (0)
5061 #  define DEBUG_q_TEST (0)
5062 #  define DEBUG_M_TEST (0)
5063 #  define DEBUG_B_TEST (0)
5064 #  define DEBUG_L_TEST (0)
5065 #  define DEBUG_i_TEST (0)
5066 #  define DEBUG_y_TEST (0)
5067 #  define DEBUG_Xv_TEST (0)
5068 #  define DEBUG_Uv_TEST (0)
5069 #  define DEBUG_Pv_TEST (0)
5070 #  define DEBUG_Lv_TEST (0)
5071 #  define DEBUG_yv_TEST (0)
5072 
5073 #  define PERL_DEB(a)
5074 #  define PERL_DEB2(a,b)               b
5075 #  define PERL_DEBUG(a)
5076 #  define DEBUG_p(a)
5077 #  define DEBUG_s(a)
5078 #  define DEBUG_l(a)
5079 #  define DEBUG_t(a)
5080 #  define DEBUG_o(a)
5081 #  define DEBUG_c(a)
5082 #  define DEBUG_P(a)
5083 #  define DEBUG_m(a)
5084 #  define DEBUG_f(a)
5085 #  define DEBUG_r(a)
5086 #  define DEBUG_x(a)
5087 #  define DEBUG_u(a)
5088 #  define DEBUG_U(a)
5089 #  define DEBUG_X(a)
5090 #  define DEBUG_D(a)
5091 #  define DEBUG_S(a)
5092 #  define DEBUG_T(a)
5093 #  define DEBUG_R(a)
5094 #  define DEBUG_v(a)
5095 #  define DEBUG_C(a)
5096 #  define DEBUG_A(a)
5097 #  define DEBUG_q(a)
5098 #  define DEBUG_M(a)
5099 #  define DEBUG_B(a)
5100 #  define DEBUG_L(a)
5101 #  define DEBUG_i(a)
5102 #  define DEBUG_y(a)
5103 #  define DEBUG_Xv(a)
5104 #  define DEBUG_Uv(a)
5105 #  define DEBUG_Pv(a)
5106 #  define DEBUG_Lv(a)
5107 #  define DEBUG_yv(a)
5108 #endif /* DEBUGGING */
5109 
5110 
5111 #define DEBUG_SCOPE(where) \
5112     DEBUG_l( \
5113     Perl_deb(aTHX_ "%s scope %ld (savestack=%ld) at %s:%d\n",	\
5114                     where, (long)PL_scopestack_ix, (long)PL_savestack_ix, \
5115                     __FILE__, __LINE__));
5116 
5117 /* Keep the old croak based assert for those who want it, and as a fallback if
5118    the platform is so heretically non-ANSI that it can't assert.  */
5119 
5120 #define Perl_assert(what)	PERL_DEB2( 				\
5121         ((what) ? ((void) 0) :						\
5122             (Perl_croak_nocontext("Assertion %s failed: file \"" __FILE__ \
5123                         "\", line %d", STRINGIFY(what), __LINE__),	\
5124              (void) 0)), ((void)0))
5125 
5126 /* assert() gets defined if DEBUGGING.
5127  * If no DEBUGGING, the <assert.h> has not been included. */
5128 #ifndef assert
5129 #  define assert(what)	Perl_assert(what)
5130 #endif
5131 #ifdef DEBUGGING
5132 #  define assert_(what)	assert(what),
5133 #else
5134 #  define assert_(what)
5135 #endif
5136 
5137 struct ufuncs {
5138     I32 (*uf_val)(pTHX_ IV, SV*);
5139     I32 (*uf_set)(pTHX_ IV, SV*);
5140     IV uf_index;
5141 };
5142 
5143 /* In pre-5.7-Perls the PERL_MAGIC_uvar magic didn't get the thread context.
5144  * XS code wanting to be backward compatible can do something
5145  * like the following:
5146 
5147 #ifndef PERL_MG_UFUNC
5148 #define PERL_MG_UFUNC(name,ix,sv) I32 name(IV ix, SV *sv)
5149 #endif
5150 
5151 static PERL_MG_UFUNC(foo_get, index, val)
5152 {
5153     sv_setsv(val, ...);
5154     return TRUE;
5155 }
5156 
5157 -- Doug MacEachern
5158 
5159 */
5160 
5161 #ifndef PERL_MG_UFUNC
5162 #define PERL_MG_UFUNC(name,ix,sv) I32 name(pTHX_ IV ix, SV *sv)
5163 #endif
5164 
5165 #include <math.h>
5166 #ifdef __VMS
5167      /* isfinite and others are here rather than in math.h as C99 stipulates */
5168 #    include <fp.h>
5169 #endif
5170 
5171 #ifndef __cplusplus
5172 #  if !defined(WIN32) && !defined(VMS)
5173 #ifndef crypt
5174 char *crypt (const char*, const char*);
5175 #endif
5176 #  endif /* !WIN32 */
5177 #  ifndef WIN32
5178 #    ifndef getlogin
5179 char *getlogin (void);
5180 #    endif
5181 #  endif /* !WIN32 */
5182 #endif /* !__cplusplus */
5183 
5184 /* Fixme on VMS.  This needs to be a run-time, not build time options */
5185 /* Also rename() is affected by this */
5186 #ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */
5187 #define UNLINK unlnk
5188 I32 unlnk (pTHX_ const char*);
5189 #else
5190 #define UNLINK PerlLIO_unlink
5191 #endif
5192 
5193 /* some versions of glibc are missing the setresuid() proto */
5194 #if defined(HAS_SETRESUID) && !defined(HAS_SETRESUID_PROTO)
5195 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
5196 #endif
5197 /* some versions of glibc are missing the setresgid() proto */
5198 #if defined(HAS_SETRESGID) && !defined(HAS_SETRESGID_PROTO)
5199 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
5200 #endif
5201 
5202 #ifndef HAS_SETREUID
5203 #  ifdef HAS_SETRESUID
5204 #    define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
5205 #    define HAS_SETREUID
5206 #  endif
5207 #endif
5208 #ifndef HAS_SETREGID
5209 #  ifdef HAS_SETRESGID
5210 #    define setregid(r,e) setresgid(r,e,(Gid_t)-1)
5211 #    define HAS_SETREGID
5212 #  endif
5213 #endif
5214 
5215 /* Sighandler_t defined in iperlsys.h */
5216 
5217 #ifdef HAS_SIGACTION
5218 typedef struct sigaction Sigsave_t;
5219 #else
5220 typedef Sighandler_t Sigsave_t;
5221 #endif
5222 
5223 #define SCAN_DEF 0
5224 #define SCAN_TR 1
5225 #define SCAN_REPL 2
5226 
5227 #if defined DEBUGGING || defined PERL_USE_HWM
5228 # ifndef register
5229 #  define register
5230 # endif
5231 # define RUNOPS_DEFAULT Perl_runops_debug
5232 #else
5233 # define RUNOPS_DEFAULT Perl_runops_standard
5234 #endif
5235 
5236 #if defined(USE_PERLIO)
5237 EXTERN_C void PerlIO_teardown(void);
5238 # ifdef USE_THREADS
5239 #  define PERLIO_INIT MUTEX_INIT(&PL_perlio_mutex)
5240 #  define PERLIO_TERM 				\
5241         STMT_START {				\
5242                 PerlIO_teardown();		\
5243                 MUTEX_DESTROY(&PL_perlio_mutex);\
5244         } STMT_END
5245 # else
5246 #  define PERLIO_INIT
5247 #  define PERLIO_TERM	PerlIO_teardown()
5248 # endif
5249 #else
5250 #  define PERLIO_INIT
5251 #  define PERLIO_TERM
5252 #endif
5253 
5254 #ifdef MYMALLOC
5255 #  ifdef MUTEX_INIT_CALLS_MALLOC
5256 #    define MALLOC_INIT					\
5257         STMT_START {					\
5258                 PL_malloc_mutex = NULL;			\
5259                 MUTEX_INIT(&PL_malloc_mutex);		\
5260         } STMT_END
5261 #    define MALLOC_TERM					\
5262         STMT_START {					\
5263                 perl_mutex tmp = PL_malloc_mutex;	\
5264                 PL_malloc_mutex = NULL;			\
5265                 MUTEX_DESTROY(&tmp);			\
5266         } STMT_END
5267 #  else
5268 #    define MALLOC_INIT MUTEX_INIT(&PL_malloc_mutex)
5269 #    define MALLOC_TERM MUTEX_DESTROY(&PL_malloc_mutex)
5270 #  endif
5271 #else
5272 #  define MALLOC_INIT
5273 #  define MALLOC_TERM
5274 #endif
5275 
5276 #if defined(MULTIPLICITY)
5277 
5278 struct perl_memory_debug_header;
5279 struct perl_memory_debug_header {
5280   tTHX	interpreter;
5281 #  if defined(PERL_POISON) || defined(PERL_DEBUG_READONLY_COW)
5282   MEM_SIZE size;
5283 #  endif
5284   struct perl_memory_debug_header *prev;
5285   struct perl_memory_debug_header *next;
5286 #  ifdef PERL_DEBUG_READONLY_COW
5287   bool readonly;
5288 #  endif
5289 };
5290 
5291 #elif defined(PERL_DEBUG_READONLY_COW)
5292 
5293 struct perl_memory_debug_header;
5294 struct perl_memory_debug_header {
5295   MEM_SIZE size;
5296 };
5297 
5298 #endif
5299 
5300 #if defined (PERL_TRACK_MEMPOOL) || defined (PERL_DEBUG_READONLY_COW)
5301 
5302 #  define PERL_MEMORY_DEBUG_HEADER_SIZE \
5303         (sizeof(struct perl_memory_debug_header) + \
5304         (MEM_ALIGNBYTES - sizeof(struct perl_memory_debug_header) \
5305          %MEM_ALIGNBYTES) % MEM_ALIGNBYTES)
5306 
5307 #else
5308 #  define PERL_MEMORY_DEBUG_HEADER_SIZE	0
5309 #endif
5310 
5311 #ifdef PERL_TRACK_MEMPOOL
5312 # ifdef PERL_DEBUG_READONLY_COW
5313 #  define INIT_TRACK_MEMPOOL(header, interp)			\
5314         STMT_START {						\
5315                 (header).interpreter = (interp);		\
5316                 (header).prev = (header).next = &(header);	\
5317                 (header).readonly = 0;				\
5318         } STMT_END
5319 # else
5320 #  define INIT_TRACK_MEMPOOL(header, interp)			\
5321         STMT_START {						\
5322                 (header).interpreter = (interp);		\
5323                 (header).prev = (header).next = &(header);	\
5324         } STMT_END
5325 # endif
5326 # else
5327 #  define INIT_TRACK_MEMPOOL(header, interp)
5328 #endif
5329 
5330 #ifdef I_MALLOCMALLOC
5331 /* Needed for malloc_size(), malloc_good_size() on some systems */
5332 #  include <malloc/malloc.h>
5333 #endif
5334 
5335 #ifdef MYMALLOC
5336 #  define Perl_safesysmalloc_size(where)	Perl_malloced_size(where)
5337 #else
5338 #  if defined(HAS_MALLOC_SIZE) && !defined(PERL_DEBUG_READONLY_COW)
5339 #    ifdef PERL_TRACK_MEMPOOL
5340 #	define Perl_safesysmalloc_size(where)			\
5341             (malloc_size(((char *)(where)) - PERL_MEMORY_DEBUG_HEADER_SIZE) - PERL_MEMORY_DEBUG_HEADER_SIZE)
5342 #    else
5343 #	define Perl_safesysmalloc_size(where) malloc_size(where)
5344 #    endif
5345 #  endif
5346 #  ifdef HAS_MALLOC_GOOD_SIZE
5347 #    ifdef PERL_TRACK_MEMPOOL
5348 #	define Perl_malloc_good_size(how_much)			\
5349             (malloc_good_size((how_much) + PERL_MEMORY_DEBUG_HEADER_SIZE) - PERL_MEMORY_DEBUG_HEADER_SIZE)
5350 #    else
5351 #	define Perl_malloc_good_size(how_much) malloc_good_size(how_much)
5352 #    endif
5353 #  else
5354 /* Having this as the identity operation makes some code simpler.  */
5355 #	define Perl_malloc_good_size(how_much)	(how_much)
5356 #  endif
5357 #endif
5358 
5359 typedef int (*runops_proc_t)(pTHX);
5360 typedef void (*share_proc_t) (pTHX_ SV *sv);
5361 typedef int  (*thrhook_proc_t) (pTHX);
5362 typedef OP* (*PPADDR_t[]) (pTHX);
5363 typedef bool (*destroyable_proc_t) (pTHX_ SV *sv);
5364 typedef void (*despatch_signals_proc_t) (pTHX);
5365 
5366 #if defined(__DYNAMIC__) && defined(PERL_DARWIN) && defined(PERL_CORE)
5367 #  include <crt_externs.h>	/* for the env array */
5368 #  define environ (*_NSGetEnviron())
5369 #elif defined(USE_ENVIRON_ARRAY) && !defined(environ)
5370    /* VMS and some other platforms don't use the environ array */
5371 EXTERN_C char **environ;  /* environment variables supplied via exec */
5372 #endif
5373 
5374 #define PERL_PATCHLEVEL_H_IMPLICIT
5375 #include "patchlevel.h"
5376 #undef PERL_PATCHLEVEL_H_IMPLICIT
5377 
5378 #define PERL_VERSION_STRING	STRINGIFY(PERL_REVISION) "." \
5379                                 STRINGIFY(PERL_VERSION) "." \
5380                                 STRINGIFY(PERL_SUBVERSION)
5381 
5382 #define PERL_API_VERSION_STRING	STRINGIFY(PERL_API_REVISION) "." \
5383                                 STRINGIFY(PERL_API_VERSION) "." \
5384                                 STRINGIFY(PERL_API_SUBVERSION)
5385 
5386 START_EXTERN_C
5387 
5388 /* handy constants */
5389 EXTCONST char PL_warn_uninit[]
5390   INIT("Use of uninitialized value%s%s%s");
5391 EXTCONST char PL_warn_uninit_sv[]
5392   INIT("Use of uninitialized value%" SVf "%s%s");
5393 EXTCONST char PL_warn_nosemi[]
5394   INIT("Semicolon seems to be missing");
5395 EXTCONST char PL_warn_reserved[]
5396   INIT("Unquoted string \"%s\" may clash with future reserved word");
5397 EXTCONST char PL_warn_nl[]
5398   INIT("Unsuccessful %s on filename containing newline");
5399 EXTCONST char PL_no_wrongref[]
5400   INIT("Can't use %s ref as %s ref");
5401 /* The core no longer needs this here. If you require the string constant,
5402    please inline a copy into your own code.  */
5403 EXTCONST char PL_no_symref[] __attribute__deprecated__
5404   INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use");
5405 EXTCONST char PL_no_symref_sv[]
5406   INIT("Can't use string (\"%" SVf32 "\"%s) as %s ref while \"strict refs\" in use");
5407 
5408 EXTCONST char PL_no_usym[]
5409   INIT("Can't use an undefined value as %s reference");
5410 EXTCONST char PL_no_aelem[]
5411   INIT("Modification of non-creatable array value attempted, subscript %d");
5412 EXTCONST char PL_no_helem_sv[]
5413   INIT("Modification of non-creatable hash value attempted, subscript \"%" SVf "\"");
5414 EXTCONST char PL_no_modify[]
5415   INIT("Modification of a read-only value attempted");
5416 EXTCONST char PL_no_security[]
5417   INIT("Insecure dependency in %s%s");
5418 EXTCONST char PL_no_sock_func[]
5419   INIT("Unsupported socket function \"%s\" called");
5420 EXTCONST char PL_no_dir_func[]
5421   INIT("Unsupported directory function \"%s\" called");
5422 EXTCONST char PL_no_func[]
5423   INIT("The %s function is unimplemented");
5424 EXTCONST char PL_no_myglob[]
5425   INIT("\"%s\" %s %s can't be in a package");
5426 EXTCONST char PL_no_localize_ref[]
5427   INIT("Can't localize through a reference");
5428 EXTCONST char PL_memory_wrap[]
5429   INIT("panic: memory wrap");
5430 EXTCONST char PL_extended_cp_format[]
5431   INIT("Code point 0x%" UVXf " is not Unicode, requires a Perl extension,"
5432                              " and so is not portable");
5433 EXTCONST char PL_Yes[]
5434   INIT("1");
5435 EXTCONST char PL_No[]
5436   INIT("");
5437 EXTCONST char PL_Zero[]
5438   INIT("0");
5439 
5440 /*
5441 =for apidoc_section $numeric
5442 =for apidoc AmTuU|const char *|PL_hexdigit|U8 value
5443 
5444 This array, indexed by an integer, converts that value into the character that
5445 represents it.  For example, if the input is 8, the return will be a string
5446 whose first character is '8'.  What is actually returned is a pointer into a
5447 string.  All you are interested in is the first character of that string.  To
5448 get uppercase letters (for the values 10..15), add 16 to the index.  Hence,
5449 C<PL_hexdigit[11]> is C<'b'>, and C<PL_hexdigit[11+16]> is C<'B'>.  Adding 16
5450 to an index whose representation is '0'..'9' yields the same as not adding 16.
5451 Indices outside the range 0..31 result in (bad) undedefined behavior.
5452 
5453 =cut
5454 */
5455 EXTCONST char PL_hexdigit[]
5456   INIT("0123456789abcdef0123456789ABCDEF");
5457 
5458 EXT char PL_WARN_ALL
5459   INIT(0);
5460 EXT char PL_WARN_NONE
5461   INIT(0);
5462 
5463 /* This is constant on most architectures, a global on OS/2 */
5464 #ifndef OS2
5465 EXTCONST char PL_sh_path[]
5466   INIT(SH_PATH); /* full path of shell */
5467 #endif
5468 
5469 #ifdef CSH
5470 EXTCONST char PL_cshname[]
5471   INIT(CSH);
5472 #  define PL_cshlen	(sizeof(CSH "") - 1)
5473 #endif
5474 
5475 /* These are baked at compile time into any shared perl library.
5476    In future releases this will allow us in main() to sanity test the
5477    library we're linking against.  */
5478 
5479 EXTCONST U8 PL_revision
5480   INIT(PERL_REVISION);
5481 EXTCONST U8 PL_version
5482   INIT(PERL_VERSION);
5483 EXTCONST U8 PL_subversion
5484   INIT(PERL_SUBVERSION);
5485 
5486 EXTCONST char PL_uuemap[65]
5487   INIT("`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_");
5488 
5489 /* a special string address whose value is "isa", but which perl knows
5490  * to treat as if it were really "DOES" when printing the method name in
5491  *  the "Can't call method '%s'" error message */
5492 EXTCONST char PL_isa_DOES[]
5493   INIT("isa");
5494 
5495 #ifdef DOINIT
5496 EXTCONST char PL_uudmap[256] =
5497 #  include "uudmap.h"
5498 ;
5499 EXTCONST char PL_bitcount[256] =
5500 #  include "bitcount.h"
5501 ;
5502 EXTCONST char* const PL_sig_name[] = { SIG_NAME };
5503 EXTCONST int         PL_sig_num[]  = { SIG_NUM };
5504 #else
5505 EXTCONST char PL_uudmap[256];
5506 EXTCONST char PL_bitcount[256];
5507 EXTCONST char* const PL_sig_name[];
5508 EXTCONST int         PL_sig_num[];
5509 #endif
5510 
5511 /* fast conversion and case folding tables.  The folding tables complement the
5512  * fold, so that 'a' maps to 'A' and 'A' maps to 'a', ignoring more complicated
5513  * folds such as outside the range or to multiple characters. */
5514 
5515 #ifdef DOINIT
5516 #  ifndef EBCDIC
5517 
5518 /* The EBCDIC fold table depends on the code page, and hence is found in
5519  * ebcdic_tables.h */
5520 
5521 EXTCONST  unsigned char PL_fold[] = {
5522         0,	1,	2,	3,	4,	5,	6,	7,
5523         8,	9,	10,	11,	12,	13,	14,	15,
5524         16,	17,	18,	19,	20,	21,	22,	23,
5525         24,	25,	26,	27,	28,	29,	30,	31,
5526         32,	33,	34,	35,	36,	37,	38,	39,
5527         40,	41,	42,	43,	44,	45,	46,	47,
5528         48,	49,	50,	51,	52,	53,	54,	55,
5529         56,	57,	58,	59,	60,	61,	62,	63,
5530         64,	'a',	'b',	'c',	'd',	'e',	'f',	'g',
5531         'h',	'i',	'j',	'k',	'l',	'm',	'n',	'o',
5532         'p',	'q',	'r',	's',	't',	'u',	'v',	'w',
5533         'x',	'y',	'z',	91,	92,	93,	94,	95,
5534         96,	'A',	'B',	'C',	'D',	'E',	'F',	'G',
5535         'H',	'I',	'J',	'K',	'L',	'M',	'N',	'O',
5536         'P',	'Q',	'R',	'S',	'T',	'U',	'V',	'W',
5537         'X',	'Y',	'Z',	123,	124,	125,	126,	127,
5538         128,	129,	130,	131,	132,	133,	134,	135,
5539         136,	137,	138,	139,	140,	141,	142,	143,
5540         144,	145,	146,	147,	148,	149,	150,	151,
5541         152,	153,	154,	155,	156,	157,	158,	159,
5542         160,	161,	162,	163,	164,	165,	166,	167,
5543         168,	169,	170,	171,	172,	173,	174,	175,
5544         176,	177,	178,	179,	180,	181,	182,	183,
5545         184,	185,	186,	187,	188,	189,	190,	191,
5546         192,	193,	194,	195,	196,	197,	198,	199,
5547         200,	201,	202,	203,	204,	205,	206,	207,
5548         208,	209,	210,	211,	212,	213,	214,	215,
5549         216,	217,	218,	219,	220,	221,	222,	223,
5550         224,	225,	226,	227,	228,	229,	230,	231,
5551         232,	233,	234,	235,	236,	237,	238,	239,
5552         240,	241,	242,	243,	244,	245,	246,	247,
5553         248,	249,	250,	251,	252,	253,	254,	255
5554 };
5555 
5556 EXTCONST  unsigned char PL_fold_latin1[] = {
5557     /* Full latin1 complement folding, except for three problematic code points:
5558      *	Micro sign (181 = 0xB5) and y with diearesis (255 = 0xFF) have their
5559      *	fold complements outside the Latin1 range, so can't match something
5560      *	that isn't in utf8.
5561      *	German lower case sharp s (223 = 0xDF) folds to two characters, 'ss',
5562      *	not one, so can't be represented in this table.
5563      *
5564      * All have to be specially handled */
5565         0,	1,	2,	3,	4,	5,	6,	7,
5566         8,	9,	10,	11,	12,	13,	14,	15,
5567         16,	17,	18,	19,	20,	21,	22,	23,
5568         24,	25,	26,	27,	28,	29,	30,	31,
5569         32,	33,	34,	35,	36,	37,	38,	39,
5570         40,	41,	42,	43,	44,	45,	46,	47,
5571         48,	49,	50,	51,	52,	53,	54,	55,
5572         56,	57,	58,	59,	60,	61,	62,	63,
5573         64,	'a',	'b',	'c',	'd',	'e',	'f',	'g',
5574         'h',	'i',	'j',	'k',	'l',	'm',	'n',	'o',
5575         'p',	'q',	'r',	's',	't',	'u',	'v',	'w',
5576         'x',	'y',	'z',	91,	92,	93,	94,	95,
5577         96,	'A',	'B',	'C',	'D',	'E',	'F',	'G',
5578         'H',	'I',	'J',	'K',	'L',	'M',	'N',	'O',
5579         'P',	'Q',	'R',	'S',	'T',	'U',	'V',	'W',
5580         'X',	'Y',	'Z',	123,	124,	125,	126,	127,
5581         128,	129,	130,	131,	132,	133,	134,	135,
5582         136,	137,	138,	139,	140,	141,	142,	143,
5583         144,	145,	146,	147,	148,	149,	150,	151,
5584         152,	153,	154,	155,	156,	157,	158,	159,
5585         160,	161,	162,	163,	164,	165,	166,	167,
5586         168,	169,	170,	171,	172,	173,	174,	175,
5587         176,	177,	178,	179,	180,	181 /*micro */,	182,	183,
5588         184,	185,	186,	187,	188,	189,	190,	191,
5589         192+32,	193+32,	194+32,	195+32,	196+32,	197+32,	198+32,	199+32,
5590         200+32,	201+32,	202+32,	203+32,	204+32,	205+32,	206+32,	207+32,
5591         208+32,	209+32,	210+32,	211+32,	212+32,	213+32,	214+32,	215,
5592         216+32,	217+32,	218+32,	219+32,	220+32,	221+32,	222+32,	223 /* ss */,
5593         224-32,	225-32,	226-32,	227-32,	228-32,	229-32,	230-32,	231-32,
5594         232-32,	233-32,	234-32,	235-32,	236-32,	237-32,	238-32,	239-32,
5595         240-32,	241-32,	242-32,	243-32,	244-32,	245-32,	246-32,	247,
5596         248-32,	249-32,	250-32,	251-32,	252-32,	253-32,	254-32,
5597         255 /* y with diaeresis */
5598 };
5599 
5600 /* If these tables are accessed through ebcdic, the access will be converted to
5601  * latin1 first */
5602 EXTCONST  unsigned char PL_latin1_lc[] = {  /* lowercasing */
5603         0,	1,	2,	3,	4,	5,	6,	7,
5604         8,	9,	10,	11,	12,	13,	14,	15,
5605         16,	17,	18,	19,	20,	21,	22,	23,
5606         24,	25,	26,	27,	28,	29,	30,	31,
5607         32,	33,	34,	35,	36,	37,	38,	39,
5608         40,	41,	42,	43,	44,	45,	46,	47,
5609         48,	49,	50,	51,	52,	53,	54,	55,
5610         56,	57,	58,	59,	60,	61,	62,	63,
5611         64,	'a',	'b',	'c',	'd',	'e',	'f',	'g',
5612         'h',	'i',	'j',	'k',	'l',	'm',	'n',	'o',
5613         'p',	'q',	'r',	's',	't',	'u',	'v',	'w',
5614         'x',	'y',	'z',	91,	92,	93,	94,	95,
5615         96,	97,	98,	99,	100,	101,	102,	103,
5616         104,	105,	106,	107,	108,	109,	110,	111,
5617         112,	113,	114,	115,	116,	117,	118,	119,
5618         120,	121,	122,	123,	124,	125,	126,	127,
5619         128,	129,	130,	131,	132,	133,	134,	135,
5620         136,	137,	138,	139,	140,	141,	142,	143,
5621         144,	145,	146,	147,	148,	149,	150,	151,
5622         152,	153,	154,	155,	156,	157,	158,	159,
5623         160,	161,	162,	163,	164,	165,	166,	167,
5624         168,	169,	170,	171,	172,	173,	174,	175,
5625         176,	177,	178,	179,	180,	181,	182,	183,
5626         184,	185,	186,	187,	188,	189,	190,	191,
5627         192+32,	193+32,	194+32,	195+32,	196+32,	197+32,	198+32,	199+32,
5628         200+32,	201+32,	202+32,	203+32,	204+32,	205+32,	206+32,	207+32,
5629         208+32,	209+32,	210+32,	211+32,	212+32,	213+32,	214+32,	215,
5630         216+32,	217+32,	218+32,	219+32,	220+32,	221+32,	222+32,	223,
5631         224,	225,	226,	227,	228,	229,	230,	231,
5632         232,	233,	234,	235,	236,	237,	238,	239,
5633         240,	241,	242,	243,	244,	245,	246,	247,
5634         248,	249,	250,	251,	252,	253,	254,	255
5635 };
5636 
5637 /* upper and title case of latin1 characters, modified so that the three tricky
5638  * ones are mapped to 255 (which is one of the three) */
5639 EXTCONST  unsigned char PL_mod_latin1_uc[] = {
5640         0,	1,	2,	3,	4,	5,	6,	7,
5641         8,	9,	10,	11,	12,	13,	14,	15,
5642         16,	17,	18,	19,	20,	21,	22,	23,
5643         24,	25,	26,	27,	28,	29,	30,	31,
5644         32,	33,	34,	35,	36,	37,	38,	39,
5645         40,	41,	42,	43,	44,	45,	46,	47,
5646         48,	49,	50,	51,	52,	53,	54,	55,
5647         56,	57,	58,	59,	60,	61,	62,	63,
5648         64,	65,	66,	67,	68,	69,	70,	71,
5649         72,	73,	74,	75,	76,	77,	78,	79,
5650         80,	81,	82,	83,	84,	85,	86,	87,
5651         88,	89,	90,	91,	92,	93,	94,	95,
5652         96,	'A',	'B',	'C',	'D',	'E',	'F',	'G',
5653         'H',	'I',	'J',	'K',	'L',	'M',	'N',	'O',
5654         'P',	'Q',	'R',	'S',	'T',	'U',	'V',	'W',
5655         'X',	'Y',	'Z',	123,	124,	125,	126,	127,
5656         128,	129,	130,	131,	132,	133,	134,	135,
5657         136,	137,	138,	139,	140,	141,	142,	143,
5658         144,	145,	146,	147,	148,	149,	150,	151,
5659         152,	153,	154,	155,	156,	157,	158,	159,
5660         160,	161,	162,	163,	164,	165,	166,	167,
5661         168,	169,	170,	171,	172,	173,	174,	175,
5662         176,	177,	178,	179,	180,	255 /*micro*/,	182,	183,
5663         184,	185,	186,	187,	188,	189,	190,	191,
5664         192,	193,	194,	195,	196,	197,	198,	199,
5665         200,	201,	202,	203,	204,	205,	206,	207,
5666         208,	209,	210,	211,	212,	213,	214,	215,
5667         216,	217,	218,	219,	220,	221,	222,
5668 #    if    UNICODE_MAJOR_VERSION > 2                                        \
5669        || (UNICODE_MAJOR_VERSION == 2 && UNICODE_DOT_VERSION >= 1           \
5670                                       && UNICODE_DOT_DOT_VERSION >= 8)
5671                                                                 255 /*sharp s*/,
5672 #    else   /* uc(sharp s) is 'sharp s' itself in early unicode */
5673                                                                 223,
5674 #    endif
5675         224-32,	225-32,	226-32,	227-32,	228-32,	229-32,	230-32,	231-32,
5676         232-32,	233-32,	234-32,	235-32,	236-32,	237-32,	238-32,	239-32,
5677         240-32,	241-32,	242-32,	243-32,	244-32,	245-32,	246-32,	247,
5678         248-32,	249-32,	250-32,	251-32,	252-32,	253-32,	254-32,	255
5679 };
5680 #  endif  /* !EBCDIC, but still in DOINIT */
5681 #else	/* ! DOINIT */
5682 #  ifndef EBCDIC
5683 EXTCONST unsigned char PL_fold[];
5684 EXTCONST unsigned char PL_fold_latin1[];
5685 EXTCONST unsigned char PL_mod_latin1_uc[];
5686 EXTCONST unsigned char PL_latin1_lc[];
5687 #   endif
5688 #endif
5689 
5690 /* Although only used for debugging, these constants must be available in
5691  * non-debugging builds too, since they're used in ext/re/re_exec.c,
5692  * which has DEBUGGING enabled always */
5693 #ifdef DOINIT
5694 EXTCONST char* const PL_block_type[] = {
5695         "NULL",
5696         "WHEN",
5697         "BLOCK",
5698         "GIVEN",
5699         "LOOP_ARY",
5700         "LOOP_LAZYSV",
5701         "LOOP_LAZYIV",
5702         "LOOP_LIST",
5703         "LOOP_PLAIN",
5704         "SUB",
5705         "FORMAT",
5706         "EVAL",
5707         "SUBST",
5708         "DEFER"
5709 };
5710 #else
5711 EXTCONST char* PL_block_type[];
5712 #endif
5713 
5714 /* These are all the compile time options that affect binary compatibility.
5715    Other compile time options that are binary compatible are in perl.c
5716    (in S_Internals_V()). Both are combined for the output of perl -V
5717    However, this string will be embedded in any shared perl library, which will
5718    allow us add a comparison check in perlmain.c in the near future.  */
5719 #ifdef DOINIT
5720 EXTCONST char PL_bincompat_options[] =
5721 #  ifdef DEBUG_LEAKING_SCALARS
5722                              " DEBUG_LEAKING_SCALARS"
5723 #  endif
5724 #  ifdef DEBUG_LEAKING_SCALARS_FORK_DUMP
5725                              " DEBUG_LEAKING_SCALARS_FORK_DUMP"
5726 #  endif
5727 #  ifdef HAS_TIMES
5728                              " HAS_TIMES"
5729 #  endif
5730 #  ifdef HAVE_INTERP_INTERN
5731                              " HAVE_INTERP_INTERN"
5732 #  endif
5733 #  ifdef MULTIPLICITY
5734                              " MULTIPLICITY"
5735 #  endif
5736 #  ifdef MYMALLOC
5737                              " MYMALLOC"
5738 #  endif
5739 #  ifdef NO_HASH_SEED
5740                              " NO_HASH_SEED"
5741 #  endif
5742 #  ifdef PERLIO_LAYERS
5743                              " PERLIO_LAYERS"
5744 #  endif
5745 #  ifdef PERL_DEBUG_READONLY_COW
5746                              " PERL_DEBUG_READONLY_COW"
5747 #  endif
5748 #  ifdef PERL_DEBUG_READONLY_OPS
5749                              " PERL_DEBUG_READONLY_OPS"
5750 #  endif
5751 #  ifdef PERL_HASH_FUNC_DEFINE
5752 /* note that this is different from the others, PERL_HASH_FUNC_DEFINE
5753  * is a string which says which define was defined. */
5754                              " " PERL_HASH_FUNC_DEFINE
5755 #  endif
5756 #  ifdef PERL_HASH_USE_SBOX32
5757                              " PERL_HASH_USE_SBOX32"
5758 #  else
5759                              " PERL_HASH_NO_SBOX32"
5760 #  endif
5761 #  ifdef PERL_IMPLICIT_SYS
5762                              " PERL_IMPLICIT_SYS"
5763 #  endif
5764 #  ifdef PERL_POISON
5765                              " PERL_POISON"
5766 #  endif
5767 #  ifdef PERL_SAWAMPERSAND
5768                              " PERL_SAWAMPERSAND"
5769 #  endif
5770 #  ifdef PERL_TRACK_MEMPOOL
5771                              " PERL_TRACK_MEMPOOL"
5772 #  endif
5773 #  ifdef PERL_USES_PL_PIDSTATUS
5774                              " PERL_USES_PL_PIDSTATUS"
5775 #  endif
5776 #  ifdef USE_64_BIT_ALL
5777                              " USE_64_BIT_ALL"
5778 #  endif
5779 #  ifdef USE_64_BIT_INT
5780                              " USE_64_BIT_INT"
5781 #  endif
5782 #  ifdef USE_IEEE
5783                              " USE_IEEE"
5784 #  endif
5785 #  ifdef USE_ITHREADS
5786                              " USE_ITHREADS"
5787 #  endif
5788 #  ifdef USE_LARGE_FILES
5789                              " USE_LARGE_FILES"
5790 #  endif
5791 #  ifdef USE_LOCALE_COLLATE
5792                              " USE_LOCALE_COLLATE"
5793 #  endif
5794 #  ifdef USE_LOCALE_NUMERIC
5795                              " USE_LOCALE_NUMERIC"
5796 #  endif
5797 #  ifdef USE_LOCALE_TIME
5798                              " USE_LOCALE_TIME"
5799 #  endif
5800 #  ifdef USE_LONG_DOUBLE
5801                              " USE_LONG_DOUBLE"
5802 #  endif
5803 #  ifdef USE_PERLIO
5804                              " USE_PERLIO"
5805 #  endif
5806 #  ifdef USE_QUADMATH
5807                              " USE_QUADMATH"
5808 #  endif
5809 #  ifdef USE_REENTRANT_API
5810                              " USE_REENTRANT_API"
5811 #  endif
5812 #  ifdef USE_SOCKS
5813                              " USE_SOCKS"
5814 #  endif
5815 #  ifdef VMS_DO_SOCKETS
5816                              " VMS_DO_SOCKETS"
5817 #  endif
5818 #  ifdef VMS_SHORTEN_LONG_SYMBOLS
5819                              " VMS_SHORTEN_LONG_SYMBOLS"
5820 #  endif
5821 #  ifdef VMS_WE_ARE_CASE_SENSITIVE
5822                              " VMS_SYMBOL_CASE_AS_IS"
5823 #  endif
5824     ""; /* keep this on a line by itself, WITH the empty string */
5825 #else
5826 EXTCONST char PL_bincompat_options[];
5827 #endif
5828 
5829 #ifndef PERL_SET_PHASE
5830 #  define PERL_SET_PHASE(new_phase) \
5831     PERL_DTRACE_PROBE_PHASE(new_phase); \
5832     PL_phase = new_phase;
5833 #endif
5834 
5835 /* The interpreter phases. If these ever change, PL_phase_names right below will
5836  * need to be updated accordingly. */
5837 enum perl_phase {
5838     PERL_PHASE_CONSTRUCT	= 0,
5839     PERL_PHASE_START		= 1,
5840     PERL_PHASE_CHECK		= 2,
5841     PERL_PHASE_INIT		= 3,
5842     PERL_PHASE_RUN		= 4,
5843     PERL_PHASE_END		= 5,
5844     PERL_PHASE_DESTRUCT		= 6
5845 };
5846 
5847 #ifdef DOINIT
5848 EXTCONST char *const PL_phase_names[] = {
5849     "CONSTRUCT",
5850     "START",
5851     "CHECK",
5852     "INIT",
5853     "RUN",
5854     "END",
5855     "DESTRUCT"
5856 };
5857 #else
5858 EXTCONST char *const PL_phase_names[];
5859 #endif
5860 
5861 /*
5862 =for apidoc_section $utility
5863 
5864 =for apidoc phase_name
5865 
5866 Returns the given phase's name as a NUL-terminated string.
5867 
5868 For example, to print a stack trace that includes the current
5869 interpreter phase you might do:
5870 
5871     const char* phase_name = phase_name(PL_phase);
5872     mess("This is weird. (Perl phase: %s)", phase_name);
5873 
5874 =cut
5875 */
5876 
5877 #define phase_name(phase) (PL_phase_names[phase])
5878 
5879 #ifndef PERL_CORE
5880 /* Do not use this macro. It only exists for extensions that rely on PL_dirty
5881  * instead of using the newer PL_phase, which provides everything PL_dirty
5882  * provided, and more. */
5883 #  define PL_dirty cBOOL(PL_phase == PERL_PHASE_DESTRUCT)
5884 
5885 #  define PL_amagic_generation PL_na
5886 #  define PL_encoding ((SV *)NULL)
5887 #endif /* !PERL_CORE */
5888 
5889 #define PL_hints PL_compiling.cop_hints
5890 #define PL_maxo  MAXO
5891 
5892 END_EXTERN_C
5893 
5894 /*****************************************************************************/
5895 /* This lexer/parser stuff is currently global since yacc is hard to reenter */
5896 /*****************************************************************************/
5897 /* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
5898 
5899 #ifdef __Lynx__
5900 /* LynxOS defines these in scsi.h which is included via ioctl.h */
5901 #ifdef FORMAT
5902 #undef FORMAT
5903 #endif
5904 #ifdef SPACE
5905 #undef SPACE
5906 #endif
5907 #endif
5908 
5909 #define LEX_NOTPARSING		11	/* borrowed from toke.c */
5910 
5911 typedef enum {
5912     XOPERATOR,
5913     XTERM,
5914     XREF,
5915     XSTATE,
5916     XBLOCK,
5917     XATTRBLOCK, /* next token should be an attribute or block */
5918     XATTRTERM,  /* next token should be an attribute, or block in a term */
5919     XTERMBLOCK,
5920     XBLOCKTERM,
5921     XPOSTDEREF,
5922     XTERMORDORDOR /* evil hack */
5923     /* update exp_name[] in toke.c if adding to this enum */
5924 } expectation;
5925 
5926 #define KEY_sigvar 0xFFFF /* fake keyword representing a signature var */
5927 
5928 /* Hints are now stored in a dedicated U32, so the bottom 8 bits are no longer
5929    special and there is no need for HINT_PRIVATE_MASK for COPs.
5930 
5931     NOTE: The typical module using these has the bit value hard-coded, so don't
5932     blindly change the values of these.
5933 
5934    If we run out of bits, the 2 locale ones could be combined.  The PARTIAL one
5935    is for "use locale 'FOO'" which excludes some categories.  It requires going
5936    to %^H to find out which are in and which are out.  This could be extended
5937    for the normal case of a plain HINT_LOCALE, so that %^H would be used for
5938    any locale form. */
5939 #define HINT_INTEGER		0x00000001 /* integer pragma */
5940 #define HINT_STRICT_REFS	0x00000002 /* strict pragma */
5941 #define HINT_LOCALE		0x00000004 /* locale pragma */
5942 #define HINT_BYTES		0x00000008 /* bytes pragma */
5943 #define HINT_LOCALE_PARTIAL	0x00000010 /* locale, but a subset of categories */
5944 
5945 #define HINT_EXPLICIT_STRICT_REFS	0x00000020 /* strict.pm */
5946 #define HINT_EXPLICIT_STRICT_SUBS	0x00000040 /* strict.pm */
5947 #define HINT_EXPLICIT_STRICT_VARS	0x00000080 /* strict.pm */
5948 
5949 #define HINT_BLOCK_SCOPE	0x00000100
5950 #define HINT_STRICT_SUBS	0x00000200 /* strict pragma */
5951 #define HINT_STRICT_VARS	0x00000400 /* strict pragma */
5952 #define HINT_UNI_8_BIT		0x00000800 /* unicode_strings feature */
5953 
5954 /* The HINT_NEW_* constants are used by the overload pragma */
5955 #define HINT_NEW_INTEGER	0x00001000
5956 #define HINT_NEW_FLOAT		0x00002000
5957 #define HINT_NEW_BINARY		0x00004000
5958 #define HINT_NEW_STRING		0x00008000
5959 #define HINT_NEW_RE		0x00010000
5960 #define HINT_LOCALIZE_HH	0x00020000 /* %^H needs to be copied */
5961 #define HINT_LEXICAL_IO_IN	0x00040000 /* ${^OPEN} is set for input */
5962 #define HINT_LEXICAL_IO_OUT	0x00080000 /* ${^OPEN} is set for output */
5963 
5964 #define HINT_RE_TAINT		0x00100000 /* re pragma */
5965 #define HINT_RE_EVAL		0x00200000 /* re pragma */
5966 
5967 #define HINT_FILETEST_ACCESS	0x00400000 /* filetest pragma */
5968 #define HINT_UTF8		0x00800000 /* utf8 pragma */
5969 
5970 #define HINT_NO_AMAGIC		0x01000000 /* overloading pragma */
5971 
5972 #define HINT_RE_FLAGS		0x02000000 /* re '/xism' pragma */
5973 
5974 #define HINT_FEATURE_MASK	0x3c000000 /* 4 bits for feature bundles */
5975 
5976                                 /* Note: Used for HINT_M_VMSISH_*,
5977                                    currently defined by vms/vmsish.h:
5978                                 0x40000000
5979                                 0x80000000
5980                                  */
5981 
5982 #define HINT_ALL_STRICT       HINT_STRICT_REFS \
5983                             | HINT_STRICT_SUBS \
5984                             | HINT_STRICT_VARS
5985 
5986 #ifdef USE_STRICT_BY_DEFAULT
5987 #define HINTS_DEFAULT            HINT_ALL_STRICT
5988 #else
5989 #define HINTS_DEFAULT            0
5990 #endif
5991 
5992 /* flags for PL_sawampersand */
5993 
5994 #define SAWAMPERSAND_LEFT       1   /* saw $` */
5995 #define SAWAMPERSAND_MIDDLE     2   /* saw $& */
5996 #define SAWAMPERSAND_RIGHT      4   /* saw $' */
5997 
5998 #ifndef PERL_SAWAMPERSAND
5999 # define PL_sawampersand \
6000         (SAWAMPERSAND_LEFT|SAWAMPERSAND_MIDDLE|SAWAMPERSAND_RIGHT)
6001 #endif
6002 
6003 /* Used for debugvar magic */
6004 #define DBVARMG_SINGLE  0
6005 #define DBVARMG_TRACE   1
6006 #define DBVARMG_SIGNAL  2
6007 #define DBVARMG_COUNT   3
6008 
6009 #define PL_DBsingle_iv  (PL_DBcontrol[DBVARMG_SINGLE])
6010 #define PL_DBtrace_iv   (PL_DBcontrol[DBVARMG_TRACE])
6011 #define PL_DBsignal_iv  (PL_DBcontrol[DBVARMG_SIGNAL])
6012 
6013 /* Various states of the input record separator SV (rs) */
6014 #define RsSNARF(sv)   (! SvOK(sv))
6015 #define RsSIMPLE(sv)  (SvOK(sv) && (! SvPOK(sv) || SvCUR(sv)))
6016 #define RsPARA(sv)    (SvPOK(sv) && ! SvCUR(sv))
6017 #define RsRECORD(sv)  (SvROK(sv) && (SvIV(SvRV(sv)) > 0))
6018 
6019 /* A struct for keeping various DEBUGGING related stuff,
6020  * neatly packed.  Currently only scratch variables for
6021  * constructing debug output are included.  Needed always,
6022  * not just when DEBUGGING, though, because of the re extension. c*/
6023 struct perl_debug_pad {
6024   SV pad[3];
6025 };
6026 
6027 #define PERL_DEBUG_PAD(i)	&(PL_debug_pad.pad[i])
6028 #define PERL_DEBUG_PAD_ZERO(i)	(SvPVX(PERL_DEBUG_PAD(i))[0] = 0, \
6029         (((XPV*) SvANY(PERL_DEBUG_PAD(i)))->xpv_cur = 0), \
6030         PERL_DEBUG_PAD(i))
6031 
6032 /* Enable variables which are pointers to functions */
6033 typedef void (*peep_t)(pTHX_ OP* o);
6034 typedef regexp* (*regcomp_t) (pTHX_ char* exp, char* xend, PMOP* pm);
6035 typedef I32     (*regexec_t) (pTHX_ regexp* prog, char* stringarg,
6036                                       char* strend, char* strbeg, I32 minend,
6037                                       SV* screamer, void* data, U32 flags);
6038 typedef char*   (*re_intuit_start_t) (pTHX_ regexp *prog, SV *sv,
6039                                                 char *strpos, char *strend,
6040                                                 U32 flags,
6041                                                 re_scream_pos_data *d);
6042 typedef SV*	(*re_intuit_string_t) (pTHX_ regexp *prog);
6043 typedef void	(*regfree_t) (pTHX_ struct regexp* r);
6044 typedef regexp* (*regdupe_t) (pTHX_ const regexp* r, CLONE_PARAMS *param);
6045 typedef I32     (*re_fold_t)(pTHX_ const char *, char const *, I32);
6046 
6047 typedef void (*DESTRUCTORFUNC_NOCONTEXT_t) (void*);
6048 typedef void (*DESTRUCTORFUNC_t) (pTHX_ void*);
6049 typedef void (*SVFUNC_t) (pTHX_ SV* const);
6050 typedef I32  (*SVCOMPARE_t) (pTHX_ SV* const, SV* const);
6051 typedef void (*XSINIT_t) (pTHX);
6052 typedef void (*ATEXIT_t) (pTHX_ void*);
6053 typedef void (*XSUBADDR_t) (pTHX_ CV *);
6054 
6055 enum Perl_custom_infix_precedence {
6056     /* These numbers are spaced out to give room to insert new values as
6057      * required. They form part of the ABI contract with XS::Parse::Infix so
6058      * they should not be changed within a stable release cycle, but they can
6059      * be freely altered during a development cycle because no ABI guarantees
6060      * are made at that time */
6061     INFIX_PREC_LOW             =  10, /* non-associative */
6062     INFIX_PREC_LOGICAL_OR_LOW  =  30, /* left-associative, as `or` */
6063     INFIX_PREC_LOGICAL_AND_LOW =  40, /* left-associative, as `and` */
6064     INFIX_PREC_ASSIGN          =  50, /* right-associative, as `=` */
6065     INFIX_PREC_LOGICAL_OR      =  70, /* left-associative, as `||` */
6066     INFIX_PREC_LOGICAL_AND     =  80, /* left-associative, as `&&` */
6067     INFIX_PREC_REL             =  90, /* non-associative, just below `==` */
6068     INFIX_PREC_ADD             = 110, /* left-associative, as `+` */
6069     INFIX_PREC_MUL             = 130, /* left-associative, as `*` */
6070     INFIX_PREC_POW             = 150, /* right-associative, as `**` */
6071     INFIX_PREC_HIGH            = 170, /* non-associative */
6072     /* Try to keep within the range of a U8 in case we need to split the field
6073      * and add flags */
6074 };
6075 struct Perl_custom_infix;
6076 struct Perl_custom_infix {
6077     enum Perl_custom_infix_precedence prec;
6078     void (*parse)(pTHX_ SV **opdata, struct Perl_custom_infix *);  /* optional */
6079     OP *(*build_op)(pTHX_ SV **opdata, OP *lhs, OP *rhs, struct Perl_custom_infix *);
6080 };
6081 
6082 typedef OP* (*Perl_ppaddr_t)(pTHX);
6083 typedef OP* (*Perl_check_t) (pTHX_ OP*);
6084 typedef void(*Perl_ophook_t)(pTHX_ OP*);
6085 typedef int (*Perl_keyword_plugin_t)(pTHX_ char*, STRLEN, OP**);
6086 typedef STRLEN (*Perl_infix_plugin_t)(pTHX_ char*, STRLEN, struct Perl_custom_infix **);
6087 typedef void(*Perl_cpeep_t)(pTHX_ OP *, OP *);
6088 
6089 typedef void(*globhook_t)(pTHX);
6090 
6091 #define KEYWORD_PLUGIN_DECLINE 0
6092 #define KEYWORD_PLUGIN_STMT    1
6093 #define KEYWORD_PLUGIN_EXPR    2
6094 
6095 /* Interpreter exitlist entry */
6096 typedef struct exitlistentry {
6097     void (*fn) (pTHX_ void*);
6098     void *ptr;
6099 } PerlExitListEntry;
6100 
6101 /* if you only have signal() and it resets on each signal, FAKE_PERSISTENT_SIGNAL_HANDLERS fixes */
6102 /* These have to be before perlvars.h */
6103 #if !defined(HAS_SIGACTION) && defined(VMS)
6104 #  define  FAKE_PERSISTENT_SIGNAL_HANDLERS
6105 #endif
6106 /* if we're doing kill() with sys$sigprc on VMS, FAKE_DEFAULT_SIGNAL_HANDLERS */
6107 #if defined(KILL_BY_SIGPRC)
6108 #  define  FAKE_DEFAULT_SIGNAL_HANDLERS
6109 #endif
6110 
6111 #if !defined(MULTIPLICITY)
6112 
6113 struct interpreter {
6114     char broiled;
6115 };
6116 
6117 #else
6118 
6119 /* If we have multiple interpreters define a struct
6120    holding variables which must be per-interpreter
6121    If we don't have threads anything that would have
6122    be per-thread is per-interpreter.
6123 */
6124 
6125 /* Set up PERLVAR macros for populating structs */
6126 #  define PERLVAR(prefix,var,type) type prefix##var;
6127 
6128 /* 'var' is an array of length 'n' */
6129 #  define PERLVARA(prefix,var,n,type) type prefix##var[n];
6130 
6131 /* initialize 'var' to init' */
6132 #  define PERLVARI(prefix,var,type,init) type prefix##var;
6133 
6134 /* like PERLVARI, but make 'var' a const */
6135 #  define PERLVARIC(prefix,var,type,init) type prefix##var;
6136 
6137 struct interpreter {
6138 #  include "intrpvar.h"
6139 };
6140 
6141 EXTCONST U16 PL_interp_size
6142   INIT(sizeof(struct interpreter));
6143 
6144 #  define PERL_INTERPRETER_SIZE_UPTO_MEMBER(member)			\
6145     STRUCT_OFFSET(struct interpreter, member) +				\
6146     sizeof(((struct interpreter*)0)->member)
6147 
6148 /* This will be useful for subsequent releases, because this has to be the
6149    same in your libperl as in main(), else you have a mismatch and must abort.
6150 */
6151 EXTCONST U16 PL_interp_size_5_18_0
6152   INIT(PERL_INTERPRETER_SIZE_UPTO_MEMBER(PERL_LAST_5_18_0_INTERP_MEMBER));
6153 
6154 
6155 /* Done with PERLVAR macros for now ... */
6156 #  undef PERLVAR
6157 #  undef PERLVARA
6158 #  undef PERLVARI
6159 #  undef PERLVARIC
6160 
6161 #endif /* MULTIPLICITY */
6162 
6163 struct tempsym; /* defined in pp_pack.c */
6164 
6165 #include "thread.h"
6166 #include "pp.h"
6167 
6168 #undef PERL_CKDEF
6169 #undef PERL_PPDEF
6170 #define PERL_CKDEF(s)	PERL_CALLCONV OP *s (pTHX_ OP *o);
6171 #define PERL_PPDEF(s)	PERL_CALLCONV OP *s (pTHX);
6172 
6173 #ifdef MYMALLOC
6174 #  include "malloc_ctl.h"
6175 #endif
6176 
6177 /*
6178  * This provides a layer of functions and macros to ensure extensions will
6179  * get to use the same RTL functions as the core.
6180  */
6181 #if defined(WIN32)
6182 #  include "win32iop.h"
6183 #endif
6184 
6185 
6186 #include "proto.h"
6187 
6188 /* this has structure inits, so it cannot be included before here */
6189 #include "opcode.h"
6190 
6191 /* The following must follow proto.h as #defines mess up syntax */
6192 
6193 #if !defined(PERL_FOR_X2P)
6194 #  include "embedvar.h"
6195 #endif
6196 
6197 /* Now include all the 'global' variables
6198  * If we don't have threads or multiple interpreters
6199  * these include variables that would have been their struct-s
6200  */
6201 
6202 #define PERLVAR(prefix,var,type) EXT type PL_##var;
6203 #define PERLVARA(prefix,var,n,type) EXT type PL_##var[n];
6204 #define PERLVARI(prefix,var,type,init) EXT type  PL_##var INIT(init);
6205 #define PERLVARIC(prefix,var,type,init) EXTCONST type PL_##var INIT(init);
6206 
6207 #if !defined(MULTIPLICITY)
6208 START_EXTERN_C
6209 #  include "intrpvar.h"
6210 END_EXTERN_C
6211 #  define PL_sv_yes   (PL_sv_immortals[0])
6212 #  define PL_sv_undef (PL_sv_immortals[1])
6213 #  define PL_sv_no    (PL_sv_immortals[2])
6214 #  define PL_sv_zero  (PL_sv_immortals[3])
6215 #endif
6216 
6217 #ifdef PERL_CORE
6218 /* All core uses now exterminated. Ensure no zombies can return:  */
6219 #  undef PL_na
6220 #endif
6221 
6222 /* Now all the config stuff is setup we can include embed.h
6223    In particular, need the relevant *ish file included already, as it may
6224    define HAVE_INTERP_INTERN  */
6225 #include "embed.h"
6226 
6227 START_EXTERN_C
6228 
6229 #  include "perlvars.h"
6230 
6231 END_EXTERN_C
6232 
6233 #undef PERLVAR
6234 #undef PERLVARA
6235 #undef PERLVARI
6236 #undef PERLVARIC
6237 
6238 #if !defined(MULTIPLICITY)
6239 /* Set up PERLVAR macros for populating structs */
6240 #  define PERLVAR(prefix,var,type) type prefix##var;
6241 /* 'var' is an array of length 'n' */
6242 #  define PERLVARA(prefix,var,n,type) type prefix##var[n];
6243 /* initialize 'var' to init' */
6244 #  define PERLVARI(prefix,var,type,init) type prefix##var;
6245 /* like PERLVARI, but make 'var' a const */
6246 #  define PERLVARIC(prefix,var,type,init) type prefix##var;
6247 
6248 /* this is never instantiated, is it just used for sizeof(struct PerlHandShakeInterpreter) */
6249 struct PerlHandShakeInterpreter {
6250 #  include "intrpvar.h"
6251 };
6252 #  undef PERLVAR
6253 #  undef PERLVARA
6254 #  undef PERLVARI
6255 #  undef PERLVARIC
6256 #endif
6257 
6258 START_EXTERN_C
6259 
6260 /* dummy variables that hold pointers to both runops functions, thus forcing
6261  * them *both* to get linked in (useful for Peek.xs, debugging etc) */
6262 
6263 EXTCONST runops_proc_t PL_runops_std
6264   INIT(Perl_runops_standard);
6265 EXTCONST runops_proc_t PL_runops_dbg
6266   INIT(Perl_runops_debug);
6267 
6268 #define EXT_MGVTBL EXTCONST MGVTBL
6269 
6270 #define PERL_MAGIC_READONLY_ACCEPTABLE 0x40
6271 #define PERL_MAGIC_VALUE_MAGIC 0x80
6272 #define PERL_MAGIC_VTABLE_MASK 0x3F
6273 
6274 /* can this type of magic be attached to a readonly SV? */
6275 #define PERL_MAGIC_TYPE_READONLY_ACCEPTABLE(t) \
6276     (PL_magic_data[(U8)(t)] & PERL_MAGIC_READONLY_ACCEPTABLE)
6277 
6278 /* Is this type of magic container magic (%ENV, $1 etc),
6279  * or value magic (pos, taint etc)?
6280  */
6281 #define PERL_MAGIC_TYPE_IS_VALUE_MAGIC(t) \
6282     (PL_magic_data[(U8)(t)] & PERL_MAGIC_VALUE_MAGIC)
6283 
6284 #include "mg_vtable.h"
6285 
6286 #ifdef DOINIT
6287 EXTCONST U8 PL_magic_data[256] =
6288 #  include "mg_data.h"
6289 ;
6290 #else
6291 EXTCONST U8 PL_magic_data[256];
6292 #endif
6293 
6294 #ifdef DOINIT
6295                         /* NL IV NV PV INV PI PN MG RX GV LV AV HV CV FM IO OBJ */
6296 EXTCONST bool
6297 PL_valid_types_IVX[]    = { 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0 };
6298 EXTCONST bool
6299 PL_valid_types_NVX[]    = { 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0 };
6300 EXTCONST bool
6301 PL_valid_types_PVX[]    = { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0 };
6302 EXTCONST bool
6303 PL_valid_types_RV[]     = { 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0 };
6304 EXTCONST bool
6305 PL_valid_types_IV_set[] = { 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0 };
6306 EXTCONST bool
6307 PL_valid_types_NV_set[] = { 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 };
6308 
6309 EXTCONST U8
6310 PL_deBruijn_bitpos_tab32[] = {
6311     /* https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn */
6312     0,   1, 28,  2, 29, 14, 24,  3, 30, 22, 20, 15, 25, 17,  4,  8,
6313     31, 27, 13, 23, 21, 19, 16,  7, 26, 12, 18,  6, 11,  5, 10,  9
6314 };
6315 
6316 EXTCONST U8
6317 PL_deBruijn_bitpos_tab64[] = {
6318     /* https://stackoverflow.com/questions/11376288/fast-computing-of-log2-for-64-bit-integers */
6319     63,  0, 58,  1, 59, 47, 53,  2, 60, 39, 48, 27, 54, 33, 42,  3,
6320     61, 51, 37, 40, 49, 18, 28, 20, 55, 30, 34, 11, 43, 14, 22,  4,
6321     62, 57, 46, 52, 38, 26, 32, 41, 50, 36, 17, 19, 29, 10, 13, 21,
6322     56, 45, 25, 31, 35, 16,  9, 12, 44, 24, 15,  8, 23,  7,  6,  5
6323 };
6324 
6325 #else
6326 
6327 EXTCONST bool PL_valid_types_IVX[];
6328 EXTCONST bool PL_valid_types_NVX[];
6329 EXTCONST bool PL_valid_types_PVX[];
6330 EXTCONST bool PL_valid_types_RV[];
6331 EXTCONST bool PL_valid_types_IV_set[];
6332 EXTCONST bool PL_valid_types_NV_set[];
6333 EXTCONST U8   PL_deBruijn_bitpos_tab32[];
6334 EXTCONST U8   PL_deBruijn_bitpos_tab64[];
6335 
6336 #endif
6337 
6338 /* The constants for using PL_deBruijn_bitpos_tab */
6339 #define PERL_deBruijnMagic32_  0x077CB531
6340 #define PERL_deBruijnShift32_  27
6341 #define PERL_deBruijnMagic64_  0x07EDD5E59A4E28C2
6342 #define PERL_deBruijnShift64_  58
6343 
6344 /* In C99 we could use designated (named field) union initializers.
6345  * In C89 we need to initialize the member declared first.
6346  * In C++ we need extern C initializers.
6347  *
6348  * With the U8_NV version you will want to have inner braces,
6349  * while with the NV_U8 use just the NV. */
6350 
6351 #define INFNAN_U8_NV_DECL EXTCONST union { U8 u8[NVSIZE]; NV nv; }
6352 #define INFNAN_NV_U8_DECL EXTCONST union { NV nv; U8 u8[NVSIZE]; }
6353 
6354 /* if these never got defined, they need defaults */
6355 #ifndef PERL_SET_CONTEXT
6356 #  define PERL_SET_CONTEXT(i)		PERL_SET_INTERP(i)
6357 #endif
6358 
6359 #ifdef USE_PERL_SWITCH_LOCALE_CONTEXT
6360 #  define PERL_SET_LOCALE_CONTEXT(i)                                        \
6361       STMT_START {                                                          \
6362           if (LIKELY(! PL_veto_switch_non_tTHX_context))                    \
6363                 Perl_switch_locale_context(i);                              \
6364       } STMT_END
6365 
6366     /* In some Configurations there may be per-thread information that is
6367      * carried in a library instead of perl's tTHX structure.  This macro is to
6368      * be used to handle those when tTHX is changed.  Only locale handling is
6369      * currently known to be affected. */
6370 #  define PERL_SET_NON_tTHX_CONTEXT(i)                                      \
6371             STMT_START { if (i) PERL_SET_LOCALE_CONTEXT(i); } STMT_END
6372 #else
6373 #  define PERL_SET_LOCALE_CONTEXT(i)   NOOP
6374 #  define PERL_SET_NON_tTHX_CONTEXT(i) NOOP
6375 #endif
6376 
6377 #ifndef PERL_GET_CONTEXT
6378 #  define PERL_GET_CONTEXT		PERL_GET_INTERP
6379 #endif
6380 
6381 #ifndef PERL_GET_THX
6382 #  define PERL_GET_THX			((void*)NULL)
6383 #endif
6384 
6385 #ifndef PERL_SET_THX
6386 #  define PERL_SET_THX(t)		NOOP
6387 #endif
6388 
6389 #ifdef WIN32
6390     /* Windows mutexes are all general semaphores; we don't currently bother
6391      * with reproducing the same panic behavior as on other systems */
6392 #  define PERL_REENTRANT_LOCK(name, mutex, counter,                         \
6393                               cond_to_panic_if_already_locked)              \
6394         MUTEX_LOCK(mutex)
6395 #  define PERL_REENTRANT_UNLOCK(name, mutex, counter)  MUTEX_UNLOCK(mutex)
6396 #else
6397 
6398     /* Simulate a general (or recursive) semaphore on 'mutex' whose name will
6399      * be displayed as 'name' in any messages.  There must be a per-thread
6400      * variable 'counter', initialized to 0 upon thread creation that this
6401      * macro otherwise controls and keeps set to the recursion depth of the
6402      * mutex.  'cond_to_panic_if_already_locked' should be set to '0' for a
6403      * fully reentrant semaphore.  Otherwise set it to a bit of code which will
6404      * be evaluated if the macro is called recursively.  If it evaluates to
6405      * 'true', it means something is seriously wrong, and the process panics.
6406      *
6407      * It locks the mutex if the 'counter' is zero, and then increments
6408      * 'counter'.  Each corresponding UNLOCK decrements 'counter' until it is
6409      * 0, at which point it actually unlocks the mutex.  Since the variable is
6410      * per-thread, initialized to 0, there is no race with other threads.
6411      *
6412      * Clang improperly gives warnings for this, if not silenced:
6413      * https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#conditional-locks
6414      */
6415 #  define PERL_REENTRANT_LOCK(name, mutex, counter,                         \
6416                               cond_to_panic_if_already_locked)              \
6417     STMT_START {                                                            \
6418         CLANG_DIAG_IGNORE(-Wthread-safety)                                  \
6419         if (LIKELY(counter <= 0)) {                                         \
6420             UNLESS_PERL_MEM_LOG(DEBUG_Lv(PerlIO_printf(Perl_debug_log,      \
6421                                 "%s: %d: locking " name "; lock depth=1\n", \
6422                                 __FILE__, __LINE__));                       \
6423             )                                                               \
6424             MUTEX_LOCK(mutex);                                         \
6425             counter = 1;                                                    \
6426             UNLESS_PERL_MEM_LOG(DEBUG_Lv(PerlIO_printf(Perl_debug_log,      \
6427                                 "%s: %d: " name " locked; lock depth=1\n",  \
6428                                 __FILE__, __LINE__));                       \
6429             )                                                               \
6430         }                                                                   \
6431         else {                                                              \
6432             counter++;                                                      \
6433             UNLESS_PERL_MEM_LOG(DEBUG_Lv(PerlIO_printf(Perl_debug_log,      \
6434                             "%s: %d: avoided locking " name "; new lock"    \
6435                             " depth=%d, but will panic if '%s' is true\n",  \
6436                             __FILE__, __LINE__, counter,                    \
6437                             STRINGIFY(cond_to_panic_if_already_locked)));   \
6438             )                                                               \
6439             if (cond_to_panic_if_already_locked) {                          \
6440                 Perl_croak_nocontext("panic: %s: %d: attempting to lock"    \
6441                                 name " incompatibly: %s\n",                 \
6442                                 __FILE__, __LINE__,                         \
6443                                 STRINGIFY(cond_to_panic_if_already_locked));\
6444             }                                                               \
6445         }                                                                   \
6446         CLANG_DIAG_RESTORE                                                  \
6447     } STMT_END
6448 
6449 #  define PERL_REENTRANT_UNLOCK(name, mutex, counter)                       \
6450     STMT_START {                                                            \
6451         if (LIKELY(counter == 1)) {                                         \
6452             UNLESS_PERL_MEM_LOG(DEBUG_Lv(PerlIO_printf(Perl_debug_log,      \
6453                           "%s: %d: unlocking " name "; new lock depth=0\n", \
6454                           __FILE__, __LINE__));                             \
6455             )                                                               \
6456             counter = 0;                                                    \
6457             MUTEX_UNLOCK(mutex);                                       \
6458         }                                                                   \
6459         else if (counter <= 0) {                                            \
6460             Perl_croak_nocontext("panic: %s: %d: attempting to unlock"      \
6461                                  " already unlocked " name "; depth was"    \
6462                                  " %d\n", __FILE__, __LINE__,               \
6463                                  counter);                                  \
6464         }                                                                   \
6465         else {                                                              \
6466             counter--;                                                      \
6467             UNLESS_PERL_MEM_LOG(DEBUG_Lv(PerlIO_printf(Perl_debug_log,      \
6468                 "%s: %d: avoided unlocking " name "; new lock depth=%d\n",  \
6469                 __FILE__, __LINE__, counter));                              \
6470             )                                                               \
6471         }                                                                   \
6472     } STMT_END
6473 
6474 #endif
6475 
6476 #ifndef EBCDIC
6477 
6478 /* The tables below are adapted from
6479  * https://bjoern.hoehrmann.de/utf-8/decoder/dfa/, which requires this copyright
6480  * notice:
6481 
6482 Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
6483 
6484 Permission is hereby granted, free of charge, to any person obtaining a copy of
6485 this software and associated documentation files (the "Software"), to deal in
6486 the Software without restriction, including without limitation the rights to
6487 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
6488 of the Software, and to permit persons to whom the Software is furnished to do
6489 so, subject to the following conditions:
6490 
6491 The above copyright notice and this permission notice shall be included in all
6492 copies or substantial portions of the Software.
6493 
6494 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6495 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6496 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
6497 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
6498 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
6499 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
6500 SOFTWARE.
6501 
6502 */
6503 
6504 #  ifdef DOINIT
6505 #    if 0       /* This is the original table given in
6506                    https://bjoern.hoehrmann.de/utf-8/decoder/dfa/ */
6507 static U8 utf8d_C9[] = {
6508   /* The first part of the table maps bytes to character classes that
6509    * to reduce the size of the transition table and create bitmasks. */
6510    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*-1F*/
6511    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*-3F*/
6512    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*-5F*/
6513    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*-7F*/
6514    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,  9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, /*-9F*/
6515    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,  7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, /*-BF*/
6516    8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2,  2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, /*-DF*/
6517   10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8, /*-FF*/
6518 
6519   /* The second part is a transition table that maps a combination
6520    * of a state of the automaton and a character class to a state. */
6521    0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
6522   12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
6523   12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
6524   12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
6525   12,36,12,12,12,12,12,12,12,12,12,12
6526 };
6527 
6528 #    endif
6529 
6530 /* This is a version of the above table customized for Perl that doesn't
6531  * exclude surrogates and accepts start bytes up through FD (FE on 64-bit
6532  * machines).  The classes have been renumbered so that the patterns are more
6533  * evident in the table.  The class numbers are structured so the values are:
6534  *
6535  *  a) UTF-8 invariant code points
6536  *          0
6537  *  b) Start bytes that always lead to either overlongs or some class of code
6538  *     point that needs outside intervention for handling (such as to raise a
6539  *     warning)
6540  *          1
6541  *  c) Start bytes that never lead to one of the above
6542  *      number of bytes in complete sequence
6543  *  d) Rest of start bytes (they can be resolved through this algorithm) and
6544  *     continuation bytes
6545  *          arbitrary class number chosen to not conflict with the above
6546  *          classes, and to index into the remaining table
6547  *
6548  * It would make the code simpler if start byte FF could also be handled, but
6549  * doing so would mean adding two more classes (one from splitting 80 from 81,
6550  * and one for FF), and nodes for each of 6 new continuation bytes.  The
6551  * current table has 436 entries; the new one would require 140 more = 576 (2
6552  * additional classes for each of the 10 existing nodes, and 20 for each of 6
6553  * new nodes.  The array would have to be made U16 instead of U8, not worth it
6554  * for this rarely encountered case
6555  *
6556  * The classes are
6557  *      00-7F           0   Always legal, single byte sequence
6558  *      80-81           7   Not legal immediately after start bytes E0 F0 F8 FC
6559  *                          FE
6560  *      82-83           8   Not legal immediately after start bytes E0 F0 F8 FC
6561  *      84-87           9   Not legal immediately after start bytes E0 F0 F8
6562  *      88-8F          10   Not legal immediately after start bytes E0 F0
6563  *      90-9F          11   Not legal immediately after start byte E0
6564  *      A0-BF          12   Always legal continuation byte
6565  *      C0,C1           1   Not legal: overlong
6566  *      C2-DF           2   Legal start byte for two byte sequences
6567  *      E0             13   Some sequences are overlong; others legal
6568  *      E1-EF           3   Legal start byte for three byte sequences
6569  *      F0             14   Some sequences are overlong; others legal
6570  *      F1-F7           4   Legal start byte for four byte sequences
6571  *      F8             15   Some sequences are overlong; others legal
6572  *      F9-FB           5   Legal start byte for five byte sequences
6573  *      FC             16   Some sequences are overlong; others legal
6574  *      FD              6   Legal start byte for six byte sequences
6575  *      FE             17   Some sequences are overlong; others legal
6576  *                          (is 1 on 32-bit machines, since it overflows)
6577  *      FF              1   Need to handle specially
6578  */
6579 
6580 EXTCONST U8 PL_extended_utf8_dfa_tab[] = {
6581     /* The first part of the table maps bytes to character classes to reduce
6582      * the size of the transition table and create bitmasks. */
6583    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*00-0F*/
6584    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*10-1F*/
6585    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*20-2F*/
6586    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*30-3F*/
6587    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*40-4F*/
6588    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*50-5F*/
6589    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*60-6F*/
6590    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*70-7F*/
6591    7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10, /*80-8F*/
6592   11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, /*90-9F*/
6593   12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, /*A0-AF*/
6594   12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, /*B0-BF*/
6595    1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /*C0-CF*/
6596    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /*D0-DF*/
6597   13, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /*E0-EF*/
6598   14, 4, 4, 4, 4, 4, 4, 4,15, 5, 5, 5,16, 6,       /*F0-FD*/
6599 #    ifdef UV_IS_QUAD
6600                                             17,    /*FE*/
6601 #    else
6602                                              1,    /*FE*/
6603 #    endif
6604                                                 1, /*FF*/
6605 
6606 /* The second part is a transition table that maps a combination
6607  * of a state of the automaton and a character class to a new state, called a
6608  * node.  The nodes are:
6609  * N0     The initial state, and final accepting one.
6610  * N1     Any one continuation byte (80-BF) left.  This is transitioned to
6611  *        immediately when the start byte indicates a two-byte sequence
6612  * N2     Any two continuation bytes left.
6613  * N3     Any three continuation bytes left.
6614  * N4     Any four continuation bytes left.
6615  * N5     Any five continuation bytes left.
6616  * N6     Start byte is E0.  Continuation bytes 80-9F are illegal (overlong);
6617  *        the other continuations transition to N1
6618  * N7     Start byte is F0.  Continuation bytes 80-8F are illegal (overlong);
6619  *        the other continuations transition to N2
6620  * N8     Start byte is F8.  Continuation bytes 80-87 are illegal (overlong);
6621  *        the other continuations transition to N3
6622  * N9     Start byte is FC.  Continuation bytes 80-83 are illegal (overlong);
6623  *        the other continuations transition to N4
6624  * N10    Start byte is FE.  Continuation bytes 80-81 are illegal (overlong);
6625  *        the other continuations transition to N5
6626  * 1      Reject.  All transitions not mentioned above (except the single
6627  *        byte ones (as they are always legal)) are to this state.
6628  */
6629 
6630 #    if defined(PERL_CORE)
6631 #      define NUM_CLASSES 18
6632 #      define N0 0
6633 #      define N1 ((N0)   + NUM_CLASSES)
6634 #      define N2 ((N1)   + NUM_CLASSES)
6635 #      define N3 ((N2)   + NUM_CLASSES)
6636 #      define N4 ((N3)   + NUM_CLASSES)
6637 #      define N5 ((N4)   + NUM_CLASSES)
6638 #      define N6 ((N5)   + NUM_CLASSES)
6639 #      define N7 ((N6)   + NUM_CLASSES)
6640 #      define N8 ((N7)   + NUM_CLASSES)
6641 #      define N9 ((N8)   + NUM_CLASSES)
6642 #      define N10 ((N9)  + NUM_CLASSES)
6643 
6644 /*Class: 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17  */
6645 /*N0*/   0, 1,N1,N2,N3,N4,N5, 1, 1, 1, 1, 1, 1,N6,N7,N8,N9,N10,
6646 /*N1*/   1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
6647 /*N2*/   1, 1, 1, 1, 1, 1, 1,N1,N1,N1,N1,N1,N1, 1, 1, 1, 1, 1,
6648 /*N3*/   1, 1, 1, 1, 1, 1, 1,N2,N2,N2,N2,N2,N2, 1, 1, 1, 1, 1,
6649 /*N4*/   1, 1, 1, 1, 1, 1, 1,N3,N3,N3,N3,N3,N3, 1, 1, 1, 1, 1,
6650 /*N5*/   1, 1, 1, 1, 1, 1, 1,N4,N4,N4,N4,N4,N4, 1, 1, 1, 1, 1,
6651 
6652 /*N6*/   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,N1, 1, 1, 1, 1, 1,
6653 /*N7*/   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,N2,N2, 1, 1, 1, 1, 1,
6654 /*N8*/   1, 1, 1, 1, 1, 1, 1, 1, 1, 1,N3,N3,N3, 1, 1, 1, 1, 1,
6655 /*N9*/   1, 1, 1, 1, 1, 1, 1, 1, 1,N4,N4,N4,N4, 1, 1, 1, 1, 1,
6656 /*N10*/  1, 1, 1, 1, 1, 1, 1, 1,N5,N5,N5,N5,N5, 1, 1, 1, 1, 1,
6657 };
6658 
6659 /* And below is a version of the above table that accepts only strict UTF-8.
6660  * Hence no surrogates nor non-characters, nor non-Unicode.  Thus, if the input
6661  * passes this dfa, it will be for a well-formed, non-problematic code point
6662  * that can be returned immediately.
6663  *
6664  * The "Implementation details" portion of
6665  * https://bjoern.hoehrmann.de/utf-8/decoder/dfa/ shows how
6666  * the first portion of the table maps each possible byte into a character
6667  * class.  And that the classes for those bytes which are start bytes have been
6668  * carefully chosen so they serve as well to be used as a shift value to mask
6669  * off the leading 1 bits of the start byte.  Unfortunately the addition of
6670  * being able to distinguish non-characters makes this not fully work.  This is
6671  * because, now, the start bytes E1-EF have to be broken into 3 classes instead
6672  * of 2:
6673  *  1) ED because it could be a surrogate
6674  *  2) EF because it could be a non-character
6675  *  3) the rest, which can never evaluate to a problematic code point.
6676  *
6677  * Each of E1-EF has three leading 1 bits, then a 0.  That means we could use a
6678  * shift (and hence class number) of either 3 or 4 to get a mask that works.
6679  * But that only allows two categories, and we need three.  khw made the
6680  * decision to therefore treat the ED start byte as an error, so that the dfa
6681  * drops out immediately for that.  In the dfa, classes 3 and 4 are used to
6682  * distinguish EF vs the rest.  Then special code is used to deal with ED,
6683  * that's executed only when the dfa drops out.  The code points started by ED
6684  * are half surrogates, and half hangul syllables.  This means that 2048 of
6685  * the hangul syllables (about 18%) take longer than all other non-problematic
6686  * code points to handle.
6687  *
6688  * The changes to handle non-characters requires the addition of states and
6689  * classes to the dfa.  (See the section on "Mapping bytes to character
6690  * classes" in the linked-to document for further explanation of the original
6691  * dfa.)
6692  *
6693  * The classes are
6694  *      00-7F           0
6695  *      80-8E           9
6696  *      8F             10
6697  *      90-9E          11
6698  *      9F             12
6699  *      A0-AE          13
6700  *      AF             14
6701  *      B0-B6          15
6702  *      B7             16
6703  *      B8-BD          15
6704  *      BE             17
6705  *      BF             18
6706  *      C0,C1           1
6707  *      C2-DF           2
6708  *      E0              7
6709  *      E1-EC           3
6710  *      ED              1
6711  *      EE              3
6712  *      EF              4
6713  *      F0              8
6714  *      F1-F3           6  (6 bits can be stripped)
6715  *      F4              5  (only 5 can be stripped)
6716  *      F5-FF           1
6717  */
6718 
6719 EXTCONST U8 PL_strict_utf8_dfa_tab[] = {
6720     /* The first part of the table maps bytes to character classes to reduce
6721      * the size of the transition table and create bitmasks. */
6722    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*00-0F*/
6723    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*10-1F*/
6724    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*20-2F*/
6725    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*30-3F*/
6726    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*40-4F*/
6727    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*50-5F*/
6728    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*60-6F*/
6729    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*70-7F*/
6730    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, /*80-8F*/
6731   11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12, /*90-9F*/
6732   13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14, /*A0-AF*/
6733   15,15,15,15,15,15,15,16,15,15,15,15,15,15,17,18, /*B0-BF*/
6734    1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /*C0-CF*/
6735    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /*D0-DF*/
6736    7, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 4, /*E0-EF*/
6737    8, 6, 6, 6, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*F0-FF*/
6738 
6739 /* The second part is a transition table that maps a combination
6740  * of a state of the automaton and a character class to a new state, called a
6741  * node.  The nodes are:
6742  * N0     The initial state, and final accepting one.
6743  * N1     Any one continuation byte (80-BF) left.  This is transitioned to
6744  *        immediately when the start byte indicates a two-byte sequence
6745  * N2     Any two continuation bytes left.
6746  * N3     Start byte is E0.  Continuation bytes 80-9F are illegal (overlong);
6747  *        the other continuations transition to state N1
6748  * N4     Start byte is EF.  Continuation byte B7 transitions to N8; BF to N9;
6749  *        the other continuations transitions to N1
6750  * N5     Start byte is F0.  Continuation bytes 80-8F are illegal (overlong);
6751  *        [9AB]F transition to N10; the other continuations to N2.
6752  * N6     Start byte is F[123].  Continuation bytes [89AB]F transition
6753  *        to N10; the other continuations to N2.
6754  * N7     Start byte is F4.  Continuation bytes 90-BF are illegal
6755  *        (non-unicode); 8F transitions to N10; the other continuations to N2
6756  * N8     Initial sequence is EF B7.  Continuation bytes 90-AF are illegal
6757  *        (non-characters); the other continuations transition to N0.
6758  * N9     Initial sequence is EF BF.  Continuation bytes BE and BF are illegal
6759  *        (non-characters); the other continuations transition to N0.
6760  * N10    Initial sequence is one of: F0 [9-B]F; F[123] [8-B]F; or F4 8F.
6761  *        Continuation byte BF transitions to N11; the other continuations to
6762  *        N1
6763  * N11    Initial sequence is the two bytes given in N10 followed by BF.
6764  *        Continuation bytes BE and BF are illegal (non-characters); the other
6765  *        continuations transition to N0.
6766  * 1      Reject.  All transitions not mentioned above (except the single
6767  *        byte ones (as they are always legal) are to this state.
6768  */
6769 
6770 #      undef N0
6771 #      undef N1
6772 #      undef N2
6773 #      undef N3
6774 #      undef N4
6775 #      undef N5
6776 #      undef N6
6777 #      undef N7
6778 #      undef N8
6779 #      undef N9
6780 #      undef NUM_CLASSES
6781 #      define NUM_CLASSES 19
6782 #      define N0 0
6783 #      define N1  ((N0)  + NUM_CLASSES)
6784 #      define N2  ((N1)  + NUM_CLASSES)
6785 #      define N3  ((N2)  + NUM_CLASSES)
6786 #      define N4  ((N3)  + NUM_CLASSES)
6787 #      define N5  ((N4)  + NUM_CLASSES)
6788 #      define N6  ((N5)  + NUM_CLASSES)
6789 #      define N7  ((N6)  + NUM_CLASSES)
6790 #      define N8  ((N7)  + NUM_CLASSES)
6791 #      define N9  ((N8)  + NUM_CLASSES)
6792 #      define N10 ((N9)  + NUM_CLASSES)
6793 #      define N11 ((N10) + NUM_CLASSES)
6794 
6795 /*Class: 0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18 */
6796 /*N0*/   0,  1, N1, N2, N4, N7, N6, N3, N5,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
6797 /*N1*/   1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
6798 /*N2*/   1,  1,  1,  1,  1,  1,  1,  1,  1, N1, N1, N1, N1, N1, N1, N1, N1, N1, N1,
6799 
6800 /*N3*/   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1, N1, N1, N1, N1, N1, N1,
6801 /*N4*/   1,  1,  1,  1,  1,  1,  1,  1,  1, N1, N1, N1, N1, N1, N1, N1, N8, N1, N9,
6802 /*N5*/   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1, N2,N10, N2,N10, N2, N2, N2,N10,
6803 /*N6*/   1,  1,  1,  1,  1,  1,  1,  1,  1, N2,N10, N2,N10, N2,N10, N2, N2, N2,N10,
6804 /*N7*/   1,  1,  1,  1,  1,  1,  1,  1,  1, N2,N10,  1,  1,  1,  1,  1,  1,  1,  1,
6805 /*N8*/   1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  1,  1,  1,  1,  0,  0,  0,  0,
6806 /*N9*/   1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,
6807 /*N10*/  1,  1,  1,  1,  1,  1,  1,  1,  1, N1, N1, N1, N1, N1, N1, N1, N1, N1,N11,
6808 /*N11*/  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,
6809 };
6810 
6811 /* And below is yet another version of the above tables that accepts only UTF-8
6812  * as defined by Corregidum #9.  Hence no surrogates nor non-Unicode, but
6813  * it allows non-characters.  This is isomorphic to the original table
6814  * in https://bjoern.hoehrmann.de/utf-8/decoder/dfa/
6815  *
6816  * The classes are
6817  *      00-7F           0
6818  *      80-8F           9
6819  *      90-9F          10
6820  *      A0-BF          11
6821  *      C0,C1           1
6822  *      C2-DF           2
6823  *      E0              7
6824  *      E1-EC           3
6825  *      ED              4
6826  *      EE-EF           3
6827  *      F0              8
6828  *      F1-F3           6  (6 bits can be stripped)
6829  *      F4              5  (only 5 can be stripped)
6830  *      F5-FF           1
6831  */
6832 
6833 EXTCONST U8 PL_c9_utf8_dfa_tab[] = {
6834     /* The first part of the table maps bytes to character classes to reduce
6835      * the size of the transition table and create bitmasks. */
6836    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*00-0F*/
6837    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*10-1F*/
6838    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*20-2F*/
6839    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*30-3F*/
6840    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*40-4F*/
6841    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*50-5F*/
6842    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*60-6F*/
6843    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*70-7F*/
6844    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, /*80-8F*/
6845   10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, /*90-9F*/
6846   11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, /*A0-AF*/
6847   11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, /*B0-BF*/
6848    1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /*C0-CF*/
6849    2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /*D0-DF*/
6850    7, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, /*E0-EF*/
6851    8, 6, 6, 6, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*F0-FF*/
6852 
6853 /* The second part is a transition table that maps a combination
6854  * of a state of the automaton and a character class to a new state, called a
6855  * node.  The nodes are:
6856  * N0     The initial state, and final accepting one.
6857  * N1     Any one continuation byte (80-BF) left.  This is transitioned to
6858  *        immediately when the start byte indicates a two-byte sequence
6859  * N2     Any two continuation bytes left.
6860  * N3     Any three continuation bytes left.
6861  * N4     Start byte is E0.  Continuation bytes 80-9F are illegal (overlong);
6862  *        the other continuations transition to state N1
6863  * N5     Start byte is ED.  Continuation bytes A0-BF all lead to surrogates,
6864  *        so are illegal.  The other continuations transition to state N1.
6865  * N6     Start byte is F0.  Continuation bytes 80-8F are illegal (overlong);
6866  *        the other continuations transition to N2
6867  * N7     Start byte is F4.  Continuation bytes 90-BF are illegal
6868  *        (non-unicode); the other continuations transition to N2
6869  * 1      Reject.  All transitions not mentioned above (except the single
6870  *        byte ones (as they are always legal) are to this state.
6871  */
6872 
6873 #      undef N0
6874 #      undef N1
6875 #      undef N2
6876 #      undef N3
6877 #      undef N4
6878 #      undef N5
6879 #      undef N6
6880 #      undef N7
6881 #      undef NUM_CLASSES
6882 #      define NUM_CLASSES 12
6883 #      define N0 0
6884 #      define N1  ((N0)  + NUM_CLASSES)
6885 #      define N2  ((N1)  + NUM_CLASSES)
6886 #      define N3  ((N2)  + NUM_CLASSES)
6887 #      define N4  ((N3)  + NUM_CLASSES)
6888 #      define N5  ((N4)  + NUM_CLASSES)
6889 #      define N6  ((N5)  + NUM_CLASSES)
6890 #      define N7  ((N6)  + NUM_CLASSES)
6891 
6892 /*Class: 0   1   2   3   4   5   6   7   8   9  10  11 */
6893 /*N0*/   0,  1, N1, N2, N5, N7, N3, N4, N6,  1,  1,  1,
6894 /*N1*/   1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,
6895 /*N2*/   1,  1,  1,  1,  1,  1,  1,  1,  1, N1, N1, N1,
6896 /*N3*/   1,  1,  1,  1,  1,  1,  1,  1,  1, N2, N2, N2,
6897 
6898 /*N4*/   1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1, N1,
6899 /*N5*/   1,  1,  1,  1,  1,  1,  1,  1,  1, N1, N1,  1,
6900 /*N6*/   1,  1,  1,  1,  1,  1,  1,  1,  1,  1, N2, N2,
6901 /*N7*/   1,  1,  1,  1,  1,  1,  1,  1,  1, N2,  1,  1,
6902 };
6903 
6904 #    endif /* defined(PERL_CORE) */
6905 #  else     /* End of is DOINIT */
6906 
6907 EXTCONST U8 PL_extended_utf8_dfa_tab[];
6908 EXTCONST U8 PL_strict_utf8_dfa_tab[];
6909 EXTCONST U8 PL_c9_utf8_dfa_tab[];
6910 
6911 #  endif
6912 #endif    /* end of isn't EBCDIC */
6913 
6914 #include "overload.h"
6915 
6916 END_EXTERN_C
6917 
6918 struct am_table {
6919   U8 flags;
6920   U8 fallback;
6921   U16 spare;
6922   U32 was_ok_sub;
6923   CV* table[NofAMmeth];
6924 };
6925 struct am_table_short {
6926   U8 flags;
6927   U8 fallback;
6928   U16 spare;
6929   U32 was_ok_sub;
6930 };
6931 typedef struct am_table AMT;
6932 typedef struct am_table_short AMTS;
6933 
6934 #define AMGfallNEVER	1
6935 #define AMGfallNO	2
6936 #define AMGfallYES	3
6937 
6938 #define AMTf_AMAGIC		1
6939 #define AMT_AMAGIC(amt)		((amt)->flags & AMTf_AMAGIC)
6940 #define AMT_AMAGIC_on(amt)	((amt)->flags |= AMTf_AMAGIC)
6941 #define AMT_AMAGIC_off(amt)	((amt)->flags &= ~AMTf_AMAGIC)
6942 
6943 #define StashHANDLER(stash,meth)	gv_handler((stash),CAT2(meth,_amg))
6944 
6945 /*
6946  * some compilers like to redefine cos et alia as faster
6947  * (and less accurate?) versions called F_cos et cetera (Quidquid
6948  * latine dictum sit, altum viditur.)  This trick collides with
6949  * the Perl overloading (amg).  The following #defines fool both.
6950  */
6951 
6952 #ifdef _FASTMATH
6953 #   ifdef atan2
6954 #       define F_atan2_amg  atan2_amg
6955 #   endif
6956 #   ifdef cos
6957 #       define F_cos_amg    cos_amg
6958 #   endif
6959 #   ifdef exp
6960 #       define F_exp_amg    exp_amg
6961 #   endif
6962 #   ifdef log
6963 #       define F_log_amg    log_amg
6964 #   endif
6965 #   ifdef pow
6966 #       define F_pow_amg    pow_amg
6967 #   endif
6968 #   ifdef sin
6969 #       define F_sin_amg    sin_amg
6970 #   endif
6971 #   ifdef sqrt
6972 #       define F_sqrt_amg   sqrt_amg
6973 #   endif
6974 #endif /* _FASTMATH */
6975 
6976 #define PERLDB_ALL		(PERLDBf_SUB	| PERLDBf_LINE	|	\
6977                                  PERLDBf_NOOPT	| PERLDBf_INTER	|	\
6978                                  PERLDBf_SUBLINE| PERLDBf_SINGLE|	\
6979                                  PERLDBf_NAMEEVAL| PERLDBf_NAMEANON |   \
6980                                  PERLDBf_SAVESRC)
6981                                         /* No _NONAME, _GOTO */
6982 #define PERLDBf_SUB		0x01	/* Debug sub enter/exit */
6983 #define PERLDBf_LINE		0x02	/* Keep line # */
6984 #define PERLDBf_NOOPT		0x04	/* Switch off optimizations */
6985 #define PERLDBf_INTER		0x08	/* Preserve more data for
6986                                            later inspections  */
6987 #define PERLDBf_SUBLINE		0x10	/* Keep subr source lines */
6988 #define PERLDBf_SINGLE		0x20	/* Start with single-step on */
6989 #define PERLDBf_NONAME		0x40	/* For _SUB: no name of the subr */
6990 #define PERLDBf_GOTO		0x80	/* Report goto: call DB::goto */
6991 #define PERLDBf_NAMEEVAL	0x100	/* Informative names for evals */
6992 #define PERLDBf_NAMEANON	0x200	/* Informative names for anon subs */
6993 #define PERLDBf_SAVESRC  	0x400	/* Save source lines into @{"_<$filename"} */
6994 #define PERLDBf_SAVESRC_NOSUBS	0x800	/* Including evals that generate no subroutines */
6995 #define PERLDBf_SAVESRC_INVALID	0x1000	/* Save source that did not compile */
6996 
6997 #define PERLDB_SUB		(PL_perldb & PERLDBf_SUB)
6998 #define PERLDB_LINE		(PL_perldb & PERLDBf_LINE)
6999 #define PERLDB_NOOPT		(PL_perldb & PERLDBf_NOOPT)
7000 #define PERLDB_INTER		(PL_perldb & PERLDBf_INTER)
7001 #define PERLDB_SUBLINE		(PL_perldb & PERLDBf_SUBLINE)
7002 #define PERLDB_SINGLE		(PL_perldb & PERLDBf_SINGLE)
7003 #define PERLDB_SUB_NN		(PL_perldb & PERLDBf_NONAME)
7004 #define PERLDB_GOTO		(PL_perldb & PERLDBf_GOTO)
7005 #define PERLDB_NAMEEVAL 	(PL_perldb & PERLDBf_NAMEEVAL)
7006 #define PERLDB_NAMEANON 	(PL_perldb & PERLDBf_NAMEANON)
7007 #define PERLDB_SAVESRC  	(PL_perldb & PERLDBf_SAVESRC)
7008 #define PERLDB_SAVESRC_NOSUBS	(PL_perldb & PERLDBf_SAVESRC_NOSUBS)
7009 #define PERLDB_SAVESRC_INVALID	(PL_perldb & PERLDBf_SAVESRC_INVALID)
7010 
7011 #define PERLDB_LINE_OR_SAVESRC (PL_perldb & (PERLDBf_LINE | PERLDBf_SAVESRC))
7012 
7013 #ifdef USE_THREADS
7014 #  define KEYWORD_PLUGIN_MUTEX_INIT    MUTEX_INIT(&PL_keyword_plugin_mutex)
7015 #  define KEYWORD_PLUGIN_MUTEX_LOCK    MUTEX_LOCK(&PL_keyword_plugin_mutex)
7016 #  define KEYWORD_PLUGIN_MUTEX_UNLOCK  MUTEX_UNLOCK(&PL_keyword_plugin_mutex)
7017 #  define KEYWORD_PLUGIN_MUTEX_TERM    MUTEX_DESTROY(&PL_keyword_plugin_mutex)
7018 #  define USER_PROP_MUTEX_INIT    MUTEX_INIT(&PL_user_prop_mutex)
7019 #  define USER_PROP_MUTEX_LOCK    MUTEX_LOCK(&PL_user_prop_mutex)
7020 #  define USER_PROP_MUTEX_UNLOCK  MUTEX_UNLOCK(&PL_user_prop_mutex)
7021 #  define USER_PROP_MUTEX_TERM    MUTEX_DESTROY(&PL_user_prop_mutex)
7022 #else
7023 #  define KEYWORD_PLUGIN_MUTEX_INIT    NOOP
7024 #  define KEYWORD_PLUGIN_MUTEX_LOCK    NOOP
7025 #  define KEYWORD_PLUGIN_MUTEX_UNLOCK  NOOP
7026 #  define KEYWORD_PLUGIN_MUTEX_TERM    NOOP
7027 #  define USER_PROP_MUTEX_INIT    NOOP
7028 #  define USER_PROP_MUTEX_LOCK    NOOP
7029 #  define USER_PROP_MUTEX_UNLOCK  NOOP
7030 #  define USER_PROP_MUTEX_TERM    NOOP
7031 #endif
7032 
7033 #ifdef USE_THREADS
7034 #  define ENV_LOCK            PERL_WRITE_LOCK(&PL_env_mutex)
7035 #  define ENV_UNLOCK          PERL_WRITE_UNLOCK(&PL_env_mutex)
7036 #  define ENV_READ_LOCK       PERL_READ_LOCK(&PL_env_mutex)
7037 #  define ENV_READ_UNLOCK     PERL_READ_UNLOCK(&PL_env_mutex)
7038 #  define ENV_INIT            PERL_RW_MUTEX_INIT(&PL_env_mutex)
7039 #  define ENV_TERM            PERL_RW_MUTEX_DESTROY(&PL_env_mutex)
7040 
7041    /* On platforms where the static buffer contained in getenv() is per-thread
7042     * rather than process-wide, another thread executing a getenv() at the same
7043     * time won't destroy ours before we have copied the result safely away and
7044     * unlocked the mutex.  On such platforms (which is most), we can have many
7045     * readers of the environment at the same time. */
7046 #  ifdef GETENV_PRESERVES_OTHER_THREAD
7047 #    define GETENV_LOCK    ENV_READ_LOCK
7048 #    define GETENV_UNLOCK  ENV_READ_UNLOCK
7049 #  else
7050      /* If, on the other hand, another thread could zap our getenv() return, we
7051       * need to keep them from executing until we are done */
7052 #    define GETENV_LOCK    ENV_LOCK
7053 #    define GETENV_UNLOCK  ENV_UNLOCK
7054 #  endif
7055 #else
7056 #  define ENV_LOCK        NOOP
7057 #  define ENV_UNLOCK      NOOP
7058 #  define ENV_READ_LOCK   NOOP
7059 #  define ENV_READ_UNLOCK NOOP
7060 #  define ENV_INIT        NOOP
7061 #  define ENV_TERM        NOOP
7062 #  define GETENV_LOCK     NOOP
7063 #  define GETENV_UNLOCK   NOOP
7064 #endif
7065 
7066 /* Locale/thread synchronization macros. */
7067 #if ! defined(USE_LOCALE_THREADS)   /* No threads, or no locales */
7068 #  define LOCALE_LOCK_(cond)  NOOP
7069 #  define LOCALE_UNLOCK_      NOOP
7070 #  define LOCALE_LOCK         NOOP
7071 #  define LOCALE_UNLOCK       NOOP
7072 #else   /* Below: Threaded, and locales are supported */
7073 
7074     /* A locale mutex is required on all such threaded builds for at least
7075      * situations where there is a global static buffer.  This base lock that
7076      * handles these has a trailing underscore in the name */
7077 #  define LOCALE_LOCK_(cond_to_panic_if_already_locked)                     \
7078        PERL_REENTRANT_LOCK("locale",                                        \
7079                            &PL_locale_mutex, PL_locale_mutex_depth,         \
7080                            cond_to_panic_if_already_locked)
7081 #  define LOCALE_UNLOCK_                                                    \
7082        PERL_REENTRANT_UNLOCK("locale",                                      \
7083                              &PL_locale_mutex, PL_locale_mutex_depth)
7084 #  ifdef USE_THREAD_SAFE_LOCALE
7085     /* But for most situations, we use the macro name without a trailing
7086      * underscore.
7087      *
7088      * In locale thread-safe Configurations, typical operations don't need
7089      * locking */
7090 #    define LOCALE_LOCK         NOOP
7091 #    define LOCALE_UNLOCK       NOOP
7092 #  else
7093      /* Whereas, thread-unsafe Configurations always requires locking */
7094 #    define LOCALE_LOCK_DOES_SOMETHING_
7095 #    define LOCALE_LOCK         LOCALE_LOCK_(0)
7096 #    define LOCALE_UNLOCK       LOCALE_UNLOCK_
7097 #    ifdef USE_LOCALE_NUMERIC
7098 #      define LC_NUMERIC_LOCK(cond_to_panic_if_already_locked)              \
7099                  LOCALE_LOCK_(cond_to_panic_if_already_locked)
7100 #      define LC_NUMERIC_UNLOCK  LOCALE_UNLOCK_
7101 #    endif
7102 #  endif
7103 #endif
7104 
7105 /* There are some locale-related functions which may need locking only because
7106  * they share some common memory across threads, and hence there is the
7107  * potential for a race in accessing that space.  Most are because their return
7108  * points to a global static buffer, but some just use some common space
7109  * internally.  All functions accessing a given space need to have a critical
7110  * section to prevent any other thread from accessing it at the same time.
7111  * Ideally, there would be a separate mutex for each such space, so that
7112  * another thread isn't unnecessarily blocked.  But, most of them need to be
7113  * locked against the locale changing while accessing that space, and it is not
7114  * expected that any will be called frequently, and the locked interval should
7115  * be short, and modern platforms will have reentrant versions (which don't
7116  * lock) for almost all of them, so khw thinks a single mutex should suffice.
7117  * Having a single mutex facilitates that, avoiding potential deadlock
7118  * situations.
7119  *
7120  * This will be a no-op iff the perl is unthreaded. 'gw' stands for 'global
7121  * write', to indicate the caller wants to be able to access memory that isn't
7122  * thread specific, either to write to itself, or to prevent anyone else from
7123  * writing. */
7124 #define gwLOCALE_LOCK    LOCALE_LOCK_(0)
7125 #define gwLOCALE_UNLOCK  LOCALE_UNLOCK_
7126 
7127 /* Similar to gwLOCALE_LOCK, there are functions that require both the locale
7128  * and environment to be constant during their execution, and don't change
7129  * either of those things, but do write to some sort of shared global space.
7130  * They require some sort of exclusive lock against similar functions, and a
7131  * read lock on both the locale and environment.  However, on systems which
7132  * have per-thread locales, the locale is constant during the execution of
7133  * these functions, and so no locale lock is necssary.  For such systems, an
7134  * exclusive ENV lock is necessary and sufficient.  On systems where the locale
7135  * could change out from under us, we use an exclusive LOCALE lock to prevent
7136  * that, and a read ENV lock to prevent other threads that have nothing to do
7137  * with locales here from changing the environment. */
7138 #ifdef LOCALE_LOCK_DOES_SOMETHING
7139 #  define gwENVr_LOCALEr_LOCK                                               \
7140                     STMT_START { LOCALE_LOCK; ENV_READ_LOCK; } STMT_END
7141 #  define gwENVr_LOCALEr_UNLOCK                                             \
7142                 STMT_START { ENV_READ_UNLOCK; LOCALE_UNLOCK; } STMT_END
7143 #else
7144 #  define gwENVr_LOCALEr_LOCK           ENV_LOCK
7145 #  define gwENVr_LOCALEr_UNLOCK         ENV_UNLOCK
7146 #endif
7147 
7148       /* On systems that don't have per-thread locales, even though we don't
7149        * think we are changing the locale ourselves, behind the scenes it does
7150        * get changed to whatever the thread's should be, so it has to be an
7151        * exclusive lock.  By defining it here with this name, we can, for the
7152        * most part, hide this detail from the rest of the code */
7153 /* Currently, the read lock is an exclusive lock */
7154 #define LOCALE_READ_LOCK                LOCALE_LOCK
7155 #define LOCALE_READ_UNLOCK              LOCALE_UNLOCK
7156 
7157 /* setlocale() generally returns in a global static buffer, but not on Windows
7158  * when operating in thread-safe mode */
7159 #if defined(WIN32) && defined(USE_THREAD_SAFE_LOCALE)
7160 #  define POSIX_SETLOCALE_LOCK                                              \
7161             STMT_START {                                                    \
7162                 if (_configthreadlocale(0) == _DISABLE_PER_THREAD_LOCALE)   \
7163                     gwLOCALE_LOCK;                                          \
7164             } STMT_END
7165 #  define POSIX_SETLOCALE_UNLOCK                                            \
7166             STMT_START {                                                    \
7167                 if (_configthreadlocale(0) == _DISABLE_PER_THREAD_LOCALE)   \
7168                     gwLOCALE_UNLOCK;                                        \
7169             } STMT_END
7170 #else
7171 #  define POSIX_SETLOCALE_LOCK      gwLOCALE_LOCK
7172 #  define POSIX_SETLOCALE_UNLOCK    gwLOCALE_UNLOCK
7173 #endif
7174 
7175 /* It handles _wsetlocale() as well */
7176 #define WSETLOCALE_LOCK      POSIX_SETLOCALE_LOCK
7177 #define WSETLOCALE_UNLOCK    POSIX_SETLOCALE_UNLOCK
7178 
7179 
7180 #ifndef LC_NUMERIC_LOCK
7181 #  define LC_NUMERIC_LOCK(cond)   NOOP
7182 #  define LC_NUMERIC_UNLOCK       NOOP
7183 #endif
7184 
7185    /* These non-reentrant versions use global space */
7186 #  define MBLEN_LOCK_                gwLOCALE_LOCK
7187 #  define MBLEN_UNLOCK_              gwLOCALE_UNLOCK
7188 
7189 #  define MBTOWC_LOCK_               gwLOCALE_LOCK
7190 #  define MBTOWC_UNLOCK_             gwLOCALE_UNLOCK
7191 
7192 #  define WCTOMB_LOCK_               gwLOCALE_LOCK
7193 #  define WCTOMB_UNLOCK_             gwLOCALE_UNLOCK
7194 
7195    /* Whereas the reentrant versions don't (assuming they are called with a
7196     * per-thread buffer; some have the capability of being called with a NULL
7197     * parameter, which defeats the reentrancy) */
7198 #  define MBRLEN_LOCK_                  NOOP
7199 #  define MBRLEN_UNLOCK_                NOOP
7200 #  define MBRTOWC_LOCK_                 NOOP
7201 #  define MBRTOWC_UNLOCK_               NOOP
7202 #  define WCRTOMB_LOCK_                 NOOP
7203 #  define WCRTOMB_UNLOCK_               NOOP
7204 
7205 #  define LC_COLLATE_LOCK               LOCALE_LOCK
7206 #  define LC_COLLATE_UNLOCK             LOCALE_UNLOCK
7207 
7208 /* Some critical sections need to lock both the locale and the environment from
7209  * changing, while allowing for any number of readers.  To avoid deadlock, this
7210  * is always done in the same order.  These should always be invoked, like all
7211  * locks really, at such a low level that its just a libc call that is wrapped,
7212  * so as to prevent recursive calls which could deadlock. */
7213 #define ENVr_LOCALEr_LOCK                                               \
7214             STMT_START { LOCALE_READ_LOCK; ENV_READ_LOCK; } STMT_END
7215 #define ENVr_LOCALEr_UNLOCK                                             \
7216         STMT_START { ENV_READ_UNLOCK; LOCALE_READ_UNLOCK; } STMT_END
7217 
7218 #define STRFTIME_LOCK                   ENVr_LOCALEr_LOCK
7219 #define STRFTIME_UNLOCK                 ENVr_LOCALEr_UNLOCK
7220 
7221 /* These time-related functions all requre that the environment and locale
7222  * don't change while they are executing (at least in glibc; this appears to be
7223  * contrary to the POSIX standard).  tzset() writes global variables, so
7224  * always needs to have write locking.  ctime, localtime, mktime, and strftime
7225  * effectively call it, so they too need exclusive access.  The rest need to
7226  * have exclusive locking as well so that they can copy the contents of the
7227  * returned static buffer before releasing the lock.  That leaves asctime and
7228  * gmtime.  There may be reentrant versions of these available on the platform
7229  * which don't require write locking.
7230  */
7231 #ifdef PERL_REENTR_USING_ASCTIME_R
7232 #  define ASCTIME_LOCK     ENVr_LOCALEr_LOCK
7233 #  define ASCTIME_UNLOCK   ENVr_LOCALEr_UNLOCK
7234 #else
7235 #  define ASCTIME_LOCK     gwENVr_LOCALEr_LOCK
7236 #  define ASCTIME_UNLOCK   gwENVr_LOCALEr_UNLOCK
7237 #endif
7238 
7239 #define CTIME_LOCK         gwENVr_LOCALEr_LOCK
7240 #define CTIME_UNLOCK       gwENVr_LOCALEr_UNLOCK
7241 
7242 #ifdef PERL_REENTR_USING_GMTIME_R
7243 #  define GMTIME_LOCK      ENVr_LOCALEr_LOCK
7244 #  define GMTIME_UNLOCK    ENVr_LOCALEr_UNLOCK
7245 #else
7246 #  define GMTIME_LOCK      gwENVr_LOCALEr_LOCK
7247 #  define GMTIME_UNLOCK    gwENVr_LOCALEr_UNLOCK
7248 #endif
7249 
7250 #define LOCALTIME_LOCK     gwENVr_LOCALEr_LOCK
7251 #define LOCALTIME_UNLOCK   gwENVr_LOCALEr_UNLOCK
7252 #define MKTIME_LOCK        gwENVr_LOCALEr_LOCK
7253 #define MKTIME_UNLOCK      gwENVr_LOCALEr_UNLOCK
7254 #define TZSET_LOCK         gwENVr_LOCALEr_LOCK
7255 #define TZSET_UNLOCK       gwENVr_LOCALEr_UNLOCK
7256 
7257 /* Similiarly, these functions need a constant environment and/or locale.  And
7258  * some have a buffer that is shared with another thread executing the same or
7259  * a related call.  A mutex could be created for each class, but for now, share
7260  * the ENV mutex with everything, as none probably gets called so much that
7261  * performance would suffer by a thread being locked out by another thread that
7262  * could have used a different mutex.
7263  *
7264  * But, create a different macro name just to indicate the ones that don't
7265  * actually depend on the environment, but are using its mutex for want of a
7266  * better one */
7267 #define gwLOCALEr_LOCK              gwENVr_LOCALEr_LOCK
7268 #define gwLOCALEr_UNLOCK            gwENVr_LOCALEr_UNLOCK
7269 
7270 #ifdef PERL_REENTR_USING_GETHOSTBYADDR_R
7271 #  define GETHOSTBYADDR_LOCK        ENVr_LOCALEr_LOCK
7272 #  define GETHOSTBYADDR_UNLOCK      ENVr_LOCALEr_UNLOCK
7273 #else
7274 #  define GETHOSTBYADDR_LOCK        gwENVr_LOCALEr_LOCK
7275 #  define GETHOSTBYADDR_UNLOCK      gwENVr_LOCALEr_UNLOCK
7276 #endif
7277 #ifdef PERL_REENTR_USING_GETHOSTBYNAME_R
7278 #  define GETHOSTBYNAME_LOCK        ENVr_LOCALEr_LOCK
7279 #  define GETHOSTBYNAME_UNLOCK      ENVr_LOCALEr_UNLOCK
7280 #else
7281 #  define GETHOSTBYNAME_LOCK        gwENVr_LOCALEr_LOCK
7282 #  define GETHOSTBYNAME_UNLOCK      gwENVr_LOCALEr_UNLOCK
7283 #endif
7284 #ifdef PERL_REENTR_USING_GETNETBYADDR_R
7285 #  define GETNETBYADDR_LOCK         LOCALE_READ_LOCK
7286 #  define GETNETBYADDR_UNLOCK       LOCALE_READ_UNLOCK
7287 #else
7288 #  define GETNETBYADDR_LOCK         gwLOCALEr_LOCK
7289 #  define GETNETBYADDR_UNLOCK       gwLOCALEr_UNLOCK
7290 #endif
7291 #ifdef PERL_REENTR_USING_GETNETBYNAME_R
7292 #  define GETNETBYNAME_LOCK         LOCALE_READ_LOCK
7293 #  define GETNETBYNAME_UNLOCK       LOCALE_READ_UNLOCK
7294 #else
7295 #  define GETNETBYNAME_LOCK         gwLOCALEr_LOCK
7296 #  define GETNETBYNAME_UNLOCK       gwLOCALEr_UNLOCK
7297 #endif
7298 #ifdef PERL_REENTR_USING_GETPROTOBYNAME_R
7299 #  define GETPROTOBYNAME_LOCK       LOCALE_READ_LOCK
7300 #  define GETPROTOBYNAME_UNLOCK     LOCALE_READ_UNLOCK
7301 #else
7302 #  define GETPROTOBYNAME_LOCK       gwLOCALEr_LOCK
7303 #  define GETPROTOBYNAME_UNLOCK     gwLOCALEr_UNLOCK
7304 #endif
7305 #ifdef PERL_REENTR_USING_GETPROTOBYNUMBER_R
7306 #  define GETPROTOBYNUMBER_LOCK     LOCALE_READ_LOCK
7307 #  define GETPROTOBYNUMBER_UNLOCK   LOCALE_READ_UNLOCK
7308 #else
7309 #  define GETPROTOBYNUMBER_LOCK     gwLOCALEr_LOCK
7310 #  define GETPROTOBYNUMBER_UNLOCK   gwLOCALEr_UNLOCK
7311 #endif
7312 #ifdef PERL_REENTR_USING_GETPROTOENT_R
7313 #  define GETPROTOENT_LOCK          LOCALE_READ_LOCK
7314 #  define GETPROTOENT_UNLOCK        LOCALE_READ_UNLOCK
7315 #else
7316 #  define GETPROTOENT_LOCK          gwLOCALEr_LOCK
7317 #  define GETPROTOENT_UNLOCK        gwLOCALEr_UNLOCK
7318 #endif
7319 #ifdef PERL_REENTR_USING_GETPWNAM_R
7320 #  define GETPWNAM_LOCK             LOCALE_READ_LOCK
7321 #  define GETPWNAM_UNLOCK           LOCALE_READ_UNLOCK
7322 #else
7323 #  define GETPWNAM_LOCK             gwLOCALEr_LOCK
7324 #  define GETPWNAM_UNLOCK           gwLOCALEr_UNLOCK
7325 #endif
7326 #ifdef PERL_REENTR_USING_GETPWUID_R
7327 #  define GETPWUID_LOCK             LOCALE_READ_LOCK
7328 #  define GETPWUID_UNLOCK           LOCALE_READ_UNLOCK
7329 #else
7330 #  define GETPWUID_LOCK             gwLOCALEr_LOCK
7331 #  define GETPWUID_UNLOCK           gwLOCALEr_UNLOCK
7332 #endif
7333 #ifdef PERL_REENTR_USING_GETSERVBYNAME_R
7334 #  define GETSERVBYNAME_LOCK        LOCALE_READ_LOCK
7335 #  define GETSERVBYNAME_UNLOCK      LOCALE_READ_UNLOCK
7336 #else
7337 #  define GETSERVBYNAME_LOCK        gwLOCALEr_LOCK
7338 #  define GETSERVBYNAME_UNLOCK      gwLOCALEr_UNLOCK
7339 #endif
7340 #ifdef PERL_REENTR_USING_GETSERVBYPORT_R
7341 #  define GETSERVBYPORT_LOCK        LOCALE_READ_LOCK
7342 #  define GETSERVBYPORT_UNLOCK      LOCALE_READ_UNLOCK
7343 #else
7344 #  define GETSERVBYPORT_LOCK        gwLOCALEr_LOCK
7345 #  define GETSERVBYPORT_UNLOCK      gwLOCALEr_UNLOCK
7346 #endif
7347 #ifdef PERL_REENTR_USING_GETSERVENT_R
7348 #  define GETSERVENT_LOCK           LOCALE_READ_LOCK
7349 #  define GETSERVENT_UNLOCK         LOCALE_READ_UNLOCK
7350 #else
7351 #  define GETSERVENT_LOCK           gwLOCALEr_LOCK
7352 #  define GETSERVENT_UNLOCK         gwLOCALEr_UNLOCK
7353 #endif
7354 #ifdef PERL_REENTR_USING_GETSPNAM_R
7355 #  define GETSPNAM_LOCK             LOCALE_READ_LOCK
7356 #  define GETSPNAM_UNLOCK           LOCALE_READ_UNLOCK
7357 #else
7358 #  define GETSPNAM_LOCK             gwLOCALEr_LOCK
7359 #  define GETSPNAM_UNLOCK           gwLOCALEr_UNLOCK
7360 #endif
7361 
7362 #define STRFMON_LOCK        LC_MONETARY_LOCK
7363 #define STRFMON_UNLOCK      LC_MONETARY_UNLOCK
7364 
7365 /* End of locale/env synchronization */
7366 
7367 #if ! defined(USE_LOCALE_THREADS)
7368 #  define LOCALE_INIT
7369 #  define LOCALE_TERM
7370 #else
7371 #  ifdef WIN32_USE_FAKE_OLD_MINGW_LOCALES
7372     /* This function is coerced by this Configure option into cleaning up
7373      * memory that is static to locale.c.  So we call it at termination.  Doing
7374      * it this way is kludgy but confines having to deal with this
7375      * Configuration to a bare minimum number of places. */
7376 #      define LOCALE_TERM_POSIX_2008_  Perl_thread_locale_term(NULL)
7377 #  elif ! defined(USE_POSIX_2008_LOCALE)
7378 #      define LOCALE_TERM_POSIX_2008_  NOOP
7379 #  else
7380      /* We have a locale object holding the 'C' locale for Posix 2008 */
7381 #    define LOCALE_TERM_POSIX_2008_                                         \
7382                     STMT_START {                                            \
7383                         if (PL_C_locale_obj) {                              \
7384                             /* Make sure we aren't using the locale         \
7385                              * space we are about to free */                \
7386                             uselocale(LC_GLOBAL_LOCALE);                    \
7387                             freelocale(PL_C_locale_obj);                    \
7388                             PL_C_locale_obj = (locale_t) NULL;              \
7389                         }                                                   \
7390                     } STMT_END
7391 #  endif
7392 
7393 #  define LOCALE_INIT           MUTEX_INIT(&PL_locale_mutex)
7394 #  define LOCALE_TERM           STMT_START {                                \
7395                                     LOCALE_TERM_POSIX_2008_;                \
7396                                     MUTEX_DESTROY(&PL_locale_mutex);        \
7397                                 } STMT_END
7398 #endif
7399 
7400 #ifdef USE_LOCALE /* These locale things are all subject to change */
7401 
7402    /* Returns TRUE if the plain locale pragma without a parameter is in effect.
7403     * */
7404 #  define IN_LOCALE_RUNTIME	(PL_curcop                                  \
7405                               && CopHINTS_get(PL_curcop) & HINT_LOCALE)
7406 
7407    /* Returns TRUE if either form of the locale pragma is in effect */
7408 #  define IN_SOME_LOCALE_FORM_RUNTIME                                       \
7409         cBOOL(CopHINTS_get(PL_curcop) & (HINT_LOCALE|HINT_LOCALE_PARTIAL))
7410 
7411 #  define IN_LOCALE_COMPILETIME	cBOOL(PL_hints & HINT_LOCALE)
7412 #  define IN_SOME_LOCALE_FORM_COMPILETIME                                   \
7413                         cBOOL(PL_hints & (HINT_LOCALE|HINT_LOCALE_PARTIAL))
7414 
7415 /*
7416 =for apidoc_section $locale
7417 
7418 =for apidoc Amn|bool|IN_LOCALE
7419 
7420 Evaluates to TRUE if the plain locale pragma without a parameter (S<C<use
7421 locale>>) is in effect.
7422 
7423 =for apidoc Amn|bool|IN_LOCALE_COMPILETIME
7424 
7425 Evaluates to TRUE if, when compiling a perl program (including an C<eval>) if
7426 the plain locale pragma without a parameter (S<C<use locale>>) is in effect.
7427 
7428 =for apidoc Amn|bool|IN_LOCALE_RUNTIME
7429 
7430 Evaluates to TRUE if, when executing a perl program (including an C<eval>) if
7431 the plain locale pragma without a parameter (S<C<use locale>>) is in effect.
7432 
7433 =cut
7434 */
7435 
7436 #  define IN_LOCALE                                                         \
7437         (IN_PERL_COMPILETIME ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME)
7438 #  define IN_SOME_LOCALE_FORM                                               \
7439                     (IN_PERL_COMPILETIME ? IN_SOME_LOCALE_FORM_COMPILETIME  \
7440                                          : IN_SOME_LOCALE_FORM_RUNTIME)
7441 
7442 #  define IN_LC_ALL_COMPILETIME   IN_LOCALE_COMPILETIME
7443 #  define IN_LC_ALL_RUNTIME       IN_LOCALE_RUNTIME
7444 
7445 #  define IN_LC_PARTIAL_COMPILETIME   cBOOL(PL_hints & HINT_LOCALE_PARTIAL)
7446 #  define IN_LC_PARTIAL_RUNTIME                                             \
7447               (PL_curcop && CopHINTS_get(PL_curcop) & HINT_LOCALE_PARTIAL)
7448 
7449 #  define IN_LC_COMPILETIME(category)                                       \
7450        (       IN_LC_ALL_COMPILETIME                                        \
7451         || (   IN_LC_PARTIAL_COMPILETIME                                    \
7452             && Perl__is_in_locale_category(aTHX_ TRUE, (category))))
7453 #  define IN_LC_RUNTIME(category)                                           \
7454       (IN_LC_ALL_RUNTIME || (IN_LC_PARTIAL_RUNTIME                          \
7455                  && Perl__is_in_locale_category(aTHX_ FALSE, (category))))
7456 #  define IN_LC(category)  \
7457                     (IN_LC_COMPILETIME(category) || IN_LC_RUNTIME(category))
7458 
7459 #  if defined (PERL_CORE) || defined (PERL_IN_XSUB_RE) || defined(PERL_EXT_POSIX)
7460 
7461      /* This internal macro should be called from places that operate under
7462       * locale rules.  If there is a problem with the current locale that
7463       * hasn't been raised yet, it will output a warning this time.  Because
7464       * this will so rarely  be true, there is no point to optimize for time;
7465       * instead it makes sense to minimize space used and do all the work in
7466       * the rarely called function */
7467 #    ifdef USE_LOCALE_CTYPE
7468 #      define CHECK_AND_WARN_PROBLEMATIC_LOCALE_                              \
7469                 STMT_START {                                                  \
7470                     if (UNLIKELY(PL_warn_locale)) {                           \
7471                         Perl_warn_problematic_locale();                       \
7472                     }                                                         \
7473                 }  STMT_END
7474 #    else
7475 #      define CHECK_AND_WARN_PROBLEMATIC_LOCALE_
7476 #    endif
7477 
7478 
7479      /* These two internal macros are called when a warning should be raised,
7480       * and will do so if enabled.  The first takes a single code point
7481       * argument; the 2nd, is a pointer to the first byte of the UTF-8 encoded
7482       * string, and an end position which it won't try to read past */
7483 #    define _CHECK_AND_OUTPUT_WIDE_LOCALE_CP_MSG(cp)                        \
7484         STMT_START {                                                        \
7485             if (! IN_UTF8_CTYPE_LOCALE && ckWARN(WARN_LOCALE)) {            \
7486                 Perl_warner(aTHX_ packWARN(WARN_LOCALE),                    \
7487                                        "Wide character (U+%" UVXf ") in %s",\
7488                                        (UV) cp, OP_DESC(PL_op));            \
7489             }                                                               \
7490         }  STMT_END
7491 
7492 #    define _CHECK_AND_OUTPUT_WIDE_LOCALE_UTF8_MSG(s, send)                 \
7493         STMT_START { /* Check if to warn before doing the conversion work */\
7494             if (! IN_UTF8_CTYPE_LOCALE && ckWARN(WARN_LOCALE)) {            \
7495                 UV cp = utf8_to_uvchr_buf((U8 *) (s), (U8 *) (send), NULL); \
7496                 Perl_warner(aTHX_ packWARN(WARN_LOCALE),                    \
7497                     "Wide character (U+%" UVXf ") in %s",                   \
7498                     (cp == 0)                                               \
7499                      ? UNICODE_REPLACEMENT                                  \
7500                      : (UV) cp,                                             \
7501                     OP_DESC(PL_op));                                        \
7502             }                                                               \
7503         }  STMT_END
7504 
7505 #  endif   /* PERL_CORE or PERL_IN_XSUB_RE */
7506 #else   /* No locale usage */
7507 #  define IN_LOCALE_RUNTIME                0
7508 #  define IN_SOME_LOCALE_FORM_RUNTIME      0
7509 #  define IN_LOCALE_COMPILETIME            0
7510 #  define IN_SOME_LOCALE_FORM_COMPILETIME  0
7511 #  define IN_LOCALE                        0
7512 #  define IN_SOME_LOCALE_FORM              0
7513 #  define IN_LC_ALL_COMPILETIME            0
7514 #  define IN_LC_ALL_RUNTIME                0
7515 #  define IN_LC_PARTIAL_COMPILETIME        0
7516 #  define IN_LC_PARTIAL_RUNTIME            0
7517 #  define IN_LC_COMPILETIME(category)      0
7518 #  define IN_LC_RUNTIME(category)          0
7519 #  define IN_LC(category)                  0
7520 #  define CHECK_AND_WARN_PROBLEMATIC_LOCALE_
7521 #  define _CHECK_AND_OUTPUT_WIDE_LOCALE_UTF8_MSG(s, send)
7522 #  define _CHECK_AND_OUTPUT_WIDE_LOCALE_CP_MSG(c)
7523 #endif
7524 
7525 #define locale_panic_via_(m, f, l)  Perl_locale_panic((m), __LINE__, f, l)
7526 #define locale_panic_(m)  locale_panic_via_((m), __FILE__, __LINE__)
7527 
7528 #ifdef USE_LOCALE_NUMERIC
7529 
7530 /* These macros are for toggling between the underlying locale (UNDERLYING or
7531  * LOCAL) and the C locale (STANDARD).  (Actually we don't have to use the C
7532  * locale if the underlying locale is indistinguishable from it in the numeric
7533  * operations used by Perl, namely the decimal point, and even the thousands
7534  * separator.)
7535 
7536 =for apidoc_section $locale
7537 
7538 =for apidoc Amn|void|DECLARATION_FOR_LC_NUMERIC_MANIPULATION
7539 
7540 This macro should be used as a statement.  It declares a private variable
7541 (whose name begins with an underscore) that is needed by the other macros in
7542 this section.  Failing to include this correctly should lead to a syntax error.
7543 For compatibility with C89 C compilers it should be placed in a block before
7544 any executable statements.
7545 
7546 =for apidoc Am|void|STORE_LC_NUMERIC_FORCE_TO_UNDERLYING
7547 
7548 This is used by XS code that is C<LC_NUMERIC> locale-aware to force the
7549 locale for category C<LC_NUMERIC> to be what perl thinks is the current
7550 underlying locale.  (The perl interpreter could be wrong about what the
7551 underlying locale actually is if some C or XS code has called the C library
7552 function L<setlocale(3)> behind its back; calling L</sync_locale> before calling
7553 this macro will update perl's records.)
7554 
7555 A call to L</DECLARATION_FOR_LC_NUMERIC_MANIPULATION> must have been made to
7556 declare at compile time a private variable used by this macro.  This macro
7557 should be called as a single statement, not an expression, but with an empty
7558 argument list, like this:
7559 
7560  {
7561     DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
7562      ...
7563     STORE_LC_NUMERIC_FORCE_TO_UNDERLYING();
7564      ...
7565     RESTORE_LC_NUMERIC();
7566      ...
7567  }
7568 
7569 The private variable is used to save the current locale state, so
7570 that the requisite matching call to L</RESTORE_LC_NUMERIC> can restore it.
7571 
7572 On threaded perls not operating with thread-safe functionality, this macro uses
7573 a mutex to force a critical section.  Therefore the matching RESTORE should be
7574 close by, and guaranteed to be called.
7575 
7576 =for apidoc Am|void|STORE_LC_NUMERIC_SET_TO_NEEDED
7577 
7578 This is used to help wrap XS or C code that is C<LC_NUMERIC> locale-aware.
7579 This locale category is generally kept set to a locale where the decimal radix
7580 character is a dot, and the separator between groups of digits is empty.  This
7581 is because most XS code that reads floating point numbers is expecting them to
7582 have this syntax.
7583 
7584 This macro makes sure the current C<LC_NUMERIC> state is set properly, to be
7585 aware of locale if the call to the XS or C code from the Perl program is
7586 from within the scope of a S<C<use locale>>; or to ignore locale if the call is
7587 instead from outside such scope.
7588 
7589 This macro is the start of wrapping the C or XS code; the wrap ending is done
7590 by calling the L</RESTORE_LC_NUMERIC> macro after the operation.  Otherwise
7591 the state can be changed that will adversely affect other XS code.
7592 
7593 A call to L</DECLARATION_FOR_LC_NUMERIC_MANIPULATION> must have been made to
7594 declare at compile time a private variable used by this macro.  This macro
7595 should be called as a single statement, not an expression, but with an empty
7596 argument list, like this:
7597 
7598  {
7599     DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
7600      ...
7601     STORE_LC_NUMERIC_SET_TO_NEEDED();
7602      ...
7603     RESTORE_LC_NUMERIC();
7604      ...
7605  }
7606 
7607 On threaded perls not operating with thread-safe functionality, this macro uses
7608 a mutex to force a critical section.  Therefore the matching RESTORE should be
7609 close by, and guaranteed to be called; see L</WITH_LC_NUMERIC_SET_TO_NEEDED>
7610 for a more contained way to ensure that.
7611 
7612 =for apidoc Am|void|STORE_LC_NUMERIC_SET_TO_NEEDED_IN|bool in_lc_numeric
7613 
7614 Same as L</STORE_LC_NUMERIC_SET_TO_NEEDED> with in_lc_numeric provided
7615 as the precalculated value of C<IN_LC(LC_NUMERIC)>. It is the caller's
7616 responsibility to ensure that the status of C<PL_compiling> and C<PL_hints>
7617 cannot have changed since the precalculation.
7618 
7619 =for apidoc Am|void|RESTORE_LC_NUMERIC
7620 
7621 This is used in conjunction with one of the macros
7622 L</STORE_LC_NUMERIC_SET_TO_NEEDED>
7623 and L</STORE_LC_NUMERIC_FORCE_TO_UNDERLYING> to properly restore the
7624 C<LC_NUMERIC> state.
7625 
7626 A call to L</DECLARATION_FOR_LC_NUMERIC_MANIPULATION> must have been made to
7627 declare at compile time a private variable used by this macro and the two
7628 C<STORE> ones.  This macro should be called as a single statement, not an
7629 expression, but with an empty argument list, like this:
7630 
7631  {
7632     DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
7633      ...
7634     RESTORE_LC_NUMERIC();
7635      ...
7636  }
7637 
7638 =for apidoc Am|void|WITH_LC_NUMERIC_SET_TO_NEEDED|block
7639 
7640 This macro invokes the supplied statement or block within the context
7641 of a L</STORE_LC_NUMERIC_SET_TO_NEEDED> .. L</RESTORE_LC_NUMERIC> pair
7642 if required, so eg:
7643 
7644   WITH_LC_NUMERIC_SET_TO_NEEDED(
7645     SNPRINTF_G(fv, ebuf, sizeof(ebuf), precis)
7646   );
7647 
7648 is equivalent to:
7649 
7650   {
7651 #ifdef USE_LOCALE_NUMERIC
7652     DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
7653     STORE_LC_NUMERIC_SET_TO_NEEDED();
7654 #endif
7655     SNPRINTF_G(fv, ebuf, sizeof(ebuf), precis);
7656 #ifdef USE_LOCALE_NUMERIC
7657     RESTORE_LC_NUMERIC();
7658 #endif
7659   }
7660 
7661 =for apidoc Am|void|WITH_LC_NUMERIC_SET_TO_NEEDED_IN|bool in_lc_numeric|block
7662 
7663 Same as L</WITH_LC_NUMERIC_SET_TO_NEEDED> with in_lc_numeric provided
7664 as the precalculated value of C<IN_LC(LC_NUMERIC)>. It is the caller's
7665 responsibility to ensure that the status of C<PL_compiling> and C<PL_hints>
7666 cannot have changed since the precalculation.
7667 
7668 =cut
7669 
7670 */
7671 
7672 /* If the underlying numeric locale has a non-dot decimal point or has a
7673  * non-empty floating point thousands separator, the current locale is instead
7674  * generally kept in the C locale instead of that underlying locale.  The
7675  * current status is known by looking at two words.  One is non-zero if the
7676  * current numeric locale is the standard C/POSIX one or is indistinguishable
7677  * from C.  The other is non-zero if the current locale is the underlying
7678  * locale.  Both can be non-zero if, as often happens, the underlying locale is
7679  * C or indistinguishable from it.
7680  *
7681  * khw believes the reason for the variables instead of the bits in a single
7682  * word is to avoid having to have masking instructions. */
7683 
7684 #  define NOT_IN_NUMERIC_STANDARD_ (! PL_numeric_standard)
7685 
7686 /* This macro is designed to be a helper macro when we think an operation needs
7687  * to take place in the underlying numeric locale category.  When 'true', the
7688  * caller will attempt to toggle to that category.  But a later addition was an
7689  * override that prevents that toggle when PL_numeric_standard >= 2.  The name
7690  * of the macro was not changed when this was added. */
7691 #  define NOT_IN_NUMERIC_UNDERLYING_                                        \
7692                     (! PL_numeric_underlying && PL_numeric_standard < 2)
7693 
7694 #  define DECLARATION_FOR_LC_NUMERIC_MANIPULATION                           \
7695     void (*_restore_LC_NUMERIC_function)(pTHX_ const char * const file,     \
7696                                                const line_t line) = NULL
7697 
7698 #  define STORE_LC_NUMERIC_SET_TO_NEEDED_IN(in)                             \
7699         STMT_START {                                                        \
7700             bool _in_lc_numeric = (in);                                     \
7701             LC_NUMERIC_LOCK(                                                \
7702                     (   (  _in_lc_numeric && NOT_IN_NUMERIC_UNDERLYING_)    \
7703                      || (! _in_lc_numeric && NOT_IN_NUMERIC_STANDARD_)));   \
7704             if (_in_lc_numeric) {                                           \
7705                 if (NOT_IN_NUMERIC_UNDERLYING_) {                           \
7706                     Perl_set_numeric_underlying(aTHX_ __FILE__, __LINE__);  \
7707                     _restore_LC_NUMERIC_function                            \
7708                                             = &Perl_set_numeric_standard;   \
7709                 }                                                           \
7710             }                                                               \
7711             else {                                                          \
7712                 if (NOT_IN_NUMERIC_STANDARD_) {                             \
7713                     Perl_set_numeric_standard(aTHX_ __FILE__, __LINE__);    \
7714                     _restore_LC_NUMERIC_function                            \
7715                                             = &Perl_set_numeric_underlying; \
7716                 }                                                           \
7717             }                                                               \
7718         } STMT_END
7719 
7720 #  define STORE_LC_NUMERIC_SET_TO_NEEDED() \
7721         STORE_LC_NUMERIC_SET_TO_NEEDED_IN(IN_LC(LC_NUMERIC))
7722 
7723 #  define RESTORE_LC_NUMERIC()                                              \
7724         STMT_START {                                                        \
7725             if (_restore_LC_NUMERIC_function) {                             \
7726                 _restore_LC_NUMERIC_function(aTHX_ __FILE__, __LINE__);     \
7727             }                                                               \
7728             LC_NUMERIC_UNLOCK;                                              \
7729         } STMT_END
7730 
7731 /* The next two macros should be rarely used, and only after being sure that
7732  * this is what is needed */
7733 #  define SET_NUMERIC_STANDARD()                                            \
7734         STMT_START {                                                        \
7735             DEBUG_Lv(PerlIO_printf(Perl_debug_log,                          \
7736                                "%s: %d: lc_numeric standard=%d\n",          \
7737                                 __FILE__, __LINE__, PL_numeric_standard));  \
7738             if (UNLIKELY(NOT_IN_NUMERIC_STANDARD_)) {                       \
7739                 Perl_set_numeric_standard(aTHX_ __FILE__, __LINE__);        \
7740             }                                                               \
7741             DEBUG_Lv(PerlIO_printf(Perl_debug_log,                          \
7742                                  "%s: %d: lc_numeric standard=%d\n",        \
7743                                  __FILE__, __LINE__, PL_numeric_standard)); \
7744         } STMT_END
7745 
7746 #  define SET_NUMERIC_UNDERLYING()                                          \
7747 	STMT_START {                                                        \
7748           /*assert(PL_locale_mutex_depth > 0);*/                            \
7749             if (NOT_IN_NUMERIC_UNDERLYING_) {                               \
7750                 Perl_set_numeric_underlying(aTHX_ __FILE__, __LINE__);      \
7751             }                                                               \
7752         } STMT_END
7753 
7754 /* The rest of these LC_NUMERIC macros toggle to one or the other state, with
7755  * the RESTORE_foo ones called to switch back, but only if need be */
7756 #  define STORE_LC_NUMERIC_SET_STANDARD()                                   \
7757         STMT_START {                                                        \
7758             LC_NUMERIC_LOCK(NOT_IN_NUMERIC_STANDARD_);                      \
7759             if (NOT_IN_NUMERIC_STANDARD_) {                                 \
7760                 _restore_LC_NUMERIC_function = &Perl_set_numeric_underlying;\
7761                 Perl_set_numeric_standard(aTHX_ __FILE__, __LINE__);        \
7762             }                                                               \
7763         } STMT_END
7764 
7765 /* Rarely, we want to change to the underlying locale even outside of 'use
7766  * locale'.  This is principally in the POSIX:: functions */
7767 #  define STORE_LC_NUMERIC_FORCE_TO_UNDERLYING()                            \
7768 	STMT_START {                                                        \
7769             LC_NUMERIC_LOCK(NOT_IN_NUMERIC_UNDERLYING_);                    \
7770             if (NOT_IN_NUMERIC_UNDERLYING_) {                               \
7771                 Perl_set_numeric_underlying(aTHX_ __FILE__, __LINE__);      \
7772                 _restore_LC_NUMERIC_function = &Perl_set_numeric_standard;  \
7773             }                                                               \
7774         } STMT_END
7775 
7776 /* Lock/unlock changes to LC_NUMERIC.  This needs to be recursively callable.
7777  * The highest level caller is responsible for making sure that LC_NUMERIC is
7778  * set to a locale with a dot radix character.  These deliberately don't check
7779  * for the internal state being so, as they can be called from code that is not
7780  * party to the internal conventions, namely 'version' (vutil.c).
7781  * PL_numeric_standard changing doesn't affect anything about what locale is in
7782  * effect, etc.  [perl #128207] */
7783 #  define DISABLE_LC_NUMERIC_CHANGES()                                      \
7784         STMT_START {                                                        \
7785             DEBUG_Lv(PerlIO_printf(Perl_debug_log,                          \
7786                     "%s: %d: lc_numeric_standard now locked to depth %d\n", \
7787                     __FILE__, __LINE__, PL_numeric_standard));              \
7788             PL_numeric_standard++;                                          \
7789         } STMT_END
7790 
7791 #  define REENABLE_LC_NUMERIC_CHANGES()                                     \
7792         STMT_START {                                                        \
7793             if (PL_numeric_standard > 1) {                                  \
7794                 PL_numeric_standard--;                                      \
7795             }                                                               \
7796             else {                                                          \
7797                 assert(0);                                                  \
7798             }                                                               \
7799             DEBUG_Lv(PerlIO_printf(Perl_debug_log,                          \
7800                                    "%s: %d: ",  __FILE__, __LINE__);        \
7801                     if (PL_numeric_standard <= 1)                           \
7802                         PerlIO_printf(Perl_debug_log,                       \
7803                                       "lc_numeric_standard now unlocked\n");\
7804                     else PerlIO_printf(Perl_debug_log,                      \
7805                      "lc_numeric_standard lock decremented to depth %d\n",  \
7806                                                      PL_numeric_standard););\
7807         } STMT_END
7808 
7809 /* Essentially synonyms for the above.  The LOCK asserts at the top level that
7810  * we are in a locale equivalent to C.  By including the top level, this can be
7811  * recursively called from chains which include DISABLE_LC_NUMERIC_CHANGES().
7812  * */
7813 #  define LOCK_LC_NUMERIC_STANDARD()                                        \
7814         STMT_START {                                                        \
7815             assert(PL_numeric_standard > 0 || PL_numeric_standard);         \
7816             DISABLE_LC_NUMERIC_CHANGES();                                   \
7817         } STMT_END
7818 #  define UNLOCK_LC_NUMERIC_STANDARD()  REENABLE_LC_NUMERIC_CHANGES()
7819 
7820 #  define WITH_LC_NUMERIC_SET_TO_NEEDED_IN(in_lc_numeric, block)            \
7821         STMT_START {                                                        \
7822             DECLARATION_FOR_LC_NUMERIC_MANIPULATION;                        \
7823             STORE_LC_NUMERIC_SET_TO_NEEDED_IN(in_lc_numeric);               \
7824             block;                                                          \
7825             RESTORE_LC_NUMERIC();                                           \
7826         } STMT_END
7827 
7828 #  define WITH_LC_NUMERIC_SET_TO_NEEDED(block) \
7829         WITH_LC_NUMERIC_SET_TO_NEEDED_IN(IN_LC(LC_NUMERIC), block)
7830 
7831 #else /* !USE_LOCALE_NUMERIC */
7832 
7833 #  define SET_NUMERIC_STANDARD()
7834 #  define SET_NUMERIC_UNDERLYING()
7835 #  define IS_NUMERIC_RADIX(a, b)		(0)
7836 #  define DECLARATION_FOR_LC_NUMERIC_MANIPULATION  dNOOP
7837 #  define STORE_LC_NUMERIC_SET_STANDARD()
7838 #  define STORE_LC_NUMERIC_FORCE_TO_UNDERLYING()
7839 #  define STORE_LC_NUMERIC_SET_TO_NEEDED_IN(in_lc_numeric)
7840 #  define STORE_LC_NUMERIC_SET_TO_NEEDED()
7841 #  define RESTORE_LC_NUMERIC()
7842 #  define LOCK_LC_NUMERIC_STANDARD()
7843 #  define UNLOCK_LC_NUMERIC_STANDARD()
7844 #  define DISABLE_LC_NUMERIC_CHANGES()
7845 #  define REENABLE_LC_NUMERIC_CHANGES()
7846 #  define WITH_LC_NUMERIC_SET_TO_NEEDED_IN(in_lc_numeric, block) \
7847     STMT_START { block; } STMT_END
7848 #  define WITH_LC_NUMERIC_SET_TO_NEEDED(block) \
7849     STMT_START { block; } STMT_END
7850 
7851 #endif /* !USE_LOCALE_NUMERIC */
7852 
7853 #ifndef PERL_NO_INLINE_FUNCTIONS
7854 /* Static inline funcs that depend on includes and declarations above.
7855    Some of these reference functions in the perl object files, and some
7856    compilers aren't smart enough to eliminate unused static inline
7857    functions, so including this file in source code can cause link errors
7858    even if the source code uses none of the functions. Hence including these
7859    can be suppressed by setting PERL_NO_INLINE_FUNCTIONS. Doing this will
7860    (obviously) result in unworkable XS code, but allows simple probing code
7861    to continue to work, because it permits tests to include the perl headers
7862    for definitions without creating a link dependency on the perl library
7863    (which may not exist yet).
7864 */
7865 
7866 START_EXTERN_C
7867 
7868 #  include "perlstatic.h"
7869 #  include "inline.h"
7870 #  include "sv_inline.h"
7871 
7872 END_EXTERN_C
7873 
7874 #endif
7875 
7876 /*
7877 
7878 =for apidoc_section $numeric
7879 
7880 =for apidoc AmTR|NV|Strtod|NN const char * const s|NULLOK char ** e
7881 
7882 This is a synonym for L</my_strtod>.
7883 
7884 =for apidoc AmTR|NV|Strtol|NN const char * const s|NULLOK char ** e|int base
7885 
7886 Platform and configuration independent C<strtol>.  This expands to the
7887 appropriate C<strotol>-like function based on the platform and F<Configure>
7888 options>.  For example it could expand to C<strtoll> or C<strtoq> instead of
7889 C<strtol>.
7890 
7891 =for apidoc AmTR|NV|Strtoul|NN const char * const s|NULLOK char ** e|int base
7892 
7893 Platform and configuration independent C<strtoul>.  This expands to the
7894 appropriate C<strotoul>-like function based on the platform and F<Configure>
7895 options>.  For example it could expand to C<strtoull> or C<strtouq> instead of
7896 C<strtoul>.
7897 
7898 =cut
7899 
7900 */
7901 
7902 #define Strtod                          my_strtod
7903 
7904 #if    defined(HAS_STRTOD)                                          \
7905    ||  defined(USE_QUADMATH)                                        \
7906    || (defined(HAS_STRTOLD) && defined(HAS_LONG_DOUBLE)             \
7907                             && defined(USE_LONG_DOUBLE))
7908 #  define Perl_strtod   Strtod
7909 #endif
7910 
7911 #if !defined(Strtol) && defined(USE_64_BIT_INT) && defined(IV_IS_QUAD) && \
7912         (QUADKIND == QUAD_IS_LONG_LONG || QUADKIND == QUAD_IS___INT64)
7913 #    ifdef __hpux
7914 #        define strtoll __strtoll	/* secret handshake */
7915 #    endif
7916 #    if defined(WIN64) && defined(_MSC_VER)
7917 #        define strtoll _strtoi64	/* secret handshake */
7918 #    endif
7919 #   if !defined(Strtol) && defined(HAS_STRTOLL)
7920 #       define Strtol	strtoll
7921 #   endif
7922 #    if !defined(Strtol) && defined(HAS_STRTOQ)
7923 #       define Strtol	strtoq
7924 #    endif
7925 /* is there atoq() anywhere? */
7926 #endif
7927 #if !defined(Strtol) && defined(HAS_STRTOL)
7928 #   define Strtol	strtol
7929 #endif
7930 #ifndef Atol
7931 /* It would be more fashionable to use Strtol() to define atol()
7932  * (as is done for Atoul(), see below) but for backward compatibility
7933  * we just assume atol(). */
7934 #   if defined(USE_64_BIT_INT) && defined(IV_IS_QUAD) && defined(HAS_ATOLL) && \
7935         (QUADKIND == QUAD_IS_LONG_LONG || QUADKIND == QUAD_IS___INT64)
7936 #    ifdef WIN64
7937 #       define atoll    _atoi64		/* secret handshake */
7938 #    endif
7939 #       define Atol	atoll
7940 #   else
7941 #       define Atol	atol
7942 #   endif
7943 #endif
7944 
7945 #if !defined(Strtoul) && defined(USE_64_BIT_INT) && defined(UV_IS_QUAD) && \
7946         (QUADKIND == QUAD_IS_LONG_LONG || QUADKIND == QUAD_IS___INT64)
7947 #    ifdef __hpux
7948 #        define strtoull __strtoull	/* secret handshake */
7949 #    endif
7950 #    if defined(WIN64) && defined(_MSC_VER)
7951 #        define strtoull _strtoui64	/* secret handshake */
7952 #    endif
7953 #    if !defined(Strtoul) && defined(HAS_STRTOULL)
7954 #       define Strtoul	strtoull
7955 #    endif
7956 #    if !defined(Strtoul) && defined(HAS_STRTOUQ)
7957 #       define Strtoul	strtouq
7958 #    endif
7959 /* is there atouq() anywhere? */
7960 #endif
7961 #if !defined(Strtoul) && defined(HAS_STRTOUL)
7962 #   define Strtoul	strtoul
7963 #endif
7964 #if !defined(Strtoul) && defined(HAS_STRTOL) /* Last resort. */
7965 #   define Strtoul(s, e, b)	strchr((s), '-') ? ULONG_MAX : (unsigned long)strtol((s), (e), (b))
7966 #endif
7967 #ifndef Atoul
7968 #   define Atoul(s)	Strtoul(s, NULL, 10)
7969 #endif
7970 
7971 #define grok_bin(s,lp,fp,rp)                                                \
7972                     grok_bin_oct_hex(s, lp, fp, rp, 1, CC_BINDIGIT_, 'b')
7973 #define grok_oct(s,lp,fp,rp)                                                \
7974                     (*(fp) |= PERL_SCAN_DISALLOW_PREFIX,                    \
7975                     grok_bin_oct_hex(s, lp, fp, rp, 3, CC_OCTDIGIT_, '\0'))
7976 #define grok_hex(s,lp,fp,rp)                                                \
7977                     grok_bin_oct_hex(s, lp, fp, rp, 4, CC_XDIGIT_, 'x')
7978 
7979 #ifndef PERL_SCRIPT_MODE
7980 #define PERL_SCRIPT_MODE "r"
7981 #endif
7982 
7983 /* not used. Kept as a NOOP for backcompat */
7984 #define PERL_STACK_OVERFLOW_CHECK()  NOOP
7985 
7986 /*
7987  * Some nonpreemptive operating systems find it convenient to
7988  * check for asynchronous conditions after each op execution.
7989  * Keep this check simple, or it may slow down execution
7990  * massively.
7991  */
7992 
7993 #ifndef PERL_ASYNC_CHECK
7994 #define PERL_ASYNC_CHECK() if (UNLIKELY(PL_sig_pending)) PL_signalhook(aTHX)
7995 #endif
7996 
7997 /*
7998  * On some operating systems, a memory allocation may succeed,
7999  * but put the process too close to the system's comfort limit.
8000  * In this case, PERL_ALLOC_CHECK frees the pointer and sets
8001  * it to NULL.
8002  */
8003 #ifndef PERL_ALLOC_CHECK
8004 #define PERL_ALLOC_CHECK(p)  NOOP
8005 #endif
8006 
8007 #ifdef HAS_SEM
8008 #   include <sys/ipc.h>
8009 #   include <sys/sem.h>
8010 #   ifndef HAS_UNION_SEMUN	/* Provide the union semun. */
8011     union semun {
8012         int		val;
8013         struct semid_ds	*buf;
8014         unsigned short	*array;
8015     };
8016 #   endif
8017 #   ifdef USE_SEMCTL_SEMUN
8018 #	ifdef IRIX32_SEMUN_BROKEN_BY_GCC
8019             union gccbug_semun {
8020                 int             val;
8021                 struct semid_ds *buf;
8022                 unsigned short  *array;
8023                 char            __dummy[5];
8024             };
8025 #           define semun gccbug_semun
8026 #	endif
8027 #       define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun)
8028 #   elif defined(USE_SEMCTL_SEMID_DS)
8029 #           ifdef EXTRA_F_IN_SEMUN_BUF
8030 #               define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buff)
8031 #           else
8032 #               define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buf)
8033 #           endif
8034 #   endif
8035 #endif
8036 
8037 /*
8038  * Boilerplate macros for initializing and accessing interpreter-local
8039  * data from C.  All statics in extensions should be reworked to use
8040  * this, if you want to make the extension thread-safe.  See
8041  * ext/XS/APItest/APItest.xs for an example of the use of these macros,
8042  * and perlxs.pod for more.
8043  *
8044  * Code that uses these macros is responsible for the following:
8045  * 1. #define MY_CXT_KEY to a unique string, e.g.
8046  *    "DynaLoader::_guts" XS_VERSION
8047  *    XXX in the current implementation, this string is ignored.
8048  * 2. Declare a typedef named my_cxt_t that is a structure that contains
8049  *    all the data that needs to be interpreter-local that perl controls.  This
8050  *    doesn't include things that libc controls, such as the uselocale object
8051  *    in Configurations that use it.
8052  * 3. Use the START_MY_CXT macro after the declaration of my_cxt_t.
8053  * 4. Use the MY_CXT_INIT macro such that it is called exactly once
8054  *    (typically put in the BOOT: section).
8055  * 5. Use the members of the my_cxt_t structure everywhere as
8056  *    MY_CXT.member.
8057  * 6. Use the dMY_CXT macro (a declaration) in all the functions that
8058  *    access MY_CXT.
8059  */
8060 
8061 #if defined(MULTIPLICITY)
8062 
8063 /* START_MY_CXT must appear in all extensions that define a my_cxt_t structure,
8064  * right after the definition (i.e. at file scope).  The non-threads
8065  * case below uses it to declare the data as static. */
8066 #    define START_MY_CXT static int my_cxt_index = -1;
8067 #    define MY_CXT_INDEX my_cxt_index
8068 #    define MY_CXT_INIT_ARG &my_cxt_index
8069 
8070 /* Creates and zeroes the per-interpreter data.
8071  * (We allocate my_cxtp in a Perl SV so that it will be released when
8072  * the interpreter goes away.) */
8073 #  define MY_CXT_INIT \
8074         my_cxt_t *my_cxtp = \
8075             (my_cxt_t*)Perl_my_cxt_init(aTHX_ MY_CXT_INIT_ARG, sizeof(my_cxt_t)); \
8076         PERL_UNUSED_VAR(my_cxtp)
8077 #  define MY_CXT_INIT_INTERP(my_perl) \
8078         my_cxt_t *my_cxtp = \
8079             (my_cxt_t*)Perl_my_cxt_init(my_perl, MY_CXT_INIT_ARG, sizeof(my_cxt_t)); \
8080         PERL_UNUSED_VAR(my_cxtp)
8081 
8082 /* This declaration should be used within all functions that use the
8083  * interpreter-local data. */
8084 #  define dMY_CXT	\
8085         my_cxt_t *my_cxtp = (my_cxt_t *)PL_my_cxt_list[MY_CXT_INDEX]
8086 #  define dMY_CXT_INTERP(my_perl)	\
8087         my_cxt_t *my_cxtp = (my_cxt_t *)(my_perl)->Imy_cxt_list[MY_CXT_INDEX]
8088 
8089 /* Clones the per-interpreter data. */
8090 #  define MY_CXT_CLONE \
8091         my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\
8092         void * old_my_cxtp = PL_my_cxt_list[MY_CXT_INDEX];		\
8093         PL_my_cxt_list[MY_CXT_INDEX] = my_cxtp;				\
8094         Copy(old_my_cxtp, my_cxtp, 1, my_cxt_t);
8095 
8096 
8097 
8098 /* This macro must be used to access members of the my_cxt_t structure.
8099  * e.g. MY_CXT.some_data */
8100 #  define MY_CXT		(*my_cxtp)
8101 
8102 /* Judicious use of these macros can reduce the number of times dMY_CXT
8103  * is used.  Use is similar to pTHX, aTHX etc. */
8104 #  define pMY_CXT	my_cxt_t *my_cxtp
8105 #  define pMY_CXT_	pMY_CXT,
8106 #  define _pMY_CXT	,pMY_CXT
8107 #  define aMY_CXT	my_cxtp
8108 #  define aMY_CXT_	aMY_CXT,
8109 #  define _aMY_CXT	,aMY_CXT
8110 
8111 #else /* MULTIPLICITY */
8112 #  define START_MY_CXT		static my_cxt_t my_cxt;
8113 #  define dMY_CXT		dNOOP
8114 #  define dMY_CXT_INTERP(my_perl) dNOOP
8115 #  define MY_CXT_INIT		NOOP
8116 #  define MY_CXT_CLONE		NOOP
8117 #  define MY_CXT		my_cxt
8118 
8119 #  define pMY_CXT		void
8120 #  define pMY_CXT_
8121 #  define _pMY_CXT
8122 #  define aMY_CXT
8123 #  define aMY_CXT_
8124 #  define _aMY_CXT
8125 
8126 #endif /* !defined(MULTIPLICITY) */
8127 
8128 #ifdef I_FCNTL
8129 #  include <fcntl.h>
8130 #endif
8131 
8132 #ifdef __Lynx__
8133 #  include <fcntl.h>
8134 #endif
8135 
8136 #ifdef __amigaos4__
8137 #  undef FD_CLOEXEC /* a lie in AmigaOS */
8138 #endif
8139 
8140 #ifdef I_SYS_FILE
8141 #  include <sys/file.h>
8142 #endif
8143 
8144 #if defined(HAS_FLOCK) && !defined(HAS_FLOCK_PROTO)
8145 EXTERN_C int flock(int fd, int op);
8146 #endif
8147 
8148 #ifndef O_RDONLY
8149 /* Assume UNIX defaults */
8150 #    define O_RDONLY	0000
8151 #    define O_WRONLY	0001
8152 #    define O_RDWR	0002
8153 #    define O_CREAT	0100
8154 #endif
8155 
8156 #ifndef O_BINARY
8157 #  define O_BINARY 0
8158 #endif
8159 
8160 #ifndef O_TEXT
8161 #  define O_TEXT 0
8162 #endif
8163 
8164 #if O_TEXT != O_BINARY
8165     /* If you have different O_TEXT and O_BINARY and you are a CRLF shop,
8166      * that is, you are somehow DOSish. */
8167 #   if defined(__HAIKU__) || defined(__VOS__) || defined(__CYGWIN__)
8168     /* Haiku has O_TEXT != O_BINARY but O_TEXT and O_BINARY have no effect;
8169      * Haiku is always UNIXoid (LF), not DOSish (CRLF). */
8170     /* VOS has O_TEXT != O_BINARY, and they have effect,
8171      * but VOS always uses LF, never CRLF. */
8172     /* If you have O_TEXT different from your O_BINARY but you still are
8173      * not a CRLF shop. */
8174 #       undef PERLIO_USING_CRLF
8175 #   else
8176     /* If you really are DOSish. */
8177 #      define PERLIO_USING_CRLF 1
8178 #   endif
8179 #endif
8180 
8181 #ifdef I_LIBUTIL
8182 #   include <libutil.h>		/* setproctitle() in some FreeBSDs */
8183 #endif
8184 
8185 #ifndef EXEC_ARGV_CAST
8186 #define EXEC_ARGV_CAST(x) (char **)x
8187 #endif
8188 
8189 #define IS_NUMBER_IN_UV		      0x01 /* number within UV range (maybe not
8190                                               int).  value returned in pointed-
8191                                               to UV */
8192 #define IS_NUMBER_GREATER_THAN_UV_MAX 0x02 /* pointed to UV undefined */
8193 #define IS_NUMBER_NOT_INT	      0x04 /* saw . or E notation or infnan */
8194 #define IS_NUMBER_NEG		      0x08 /* leading minus sign */
8195 #define IS_NUMBER_INFINITY	      0x10 /* this is big */
8196 #define IS_NUMBER_NAN                 0x20 /* this is not */
8197 #define IS_NUMBER_TRAILING            0x40 /* number has trailing trash */
8198 
8199 /*
8200 =for apidoc_section $numeric
8201 
8202 =for apidoc AmdR|bool|GROK_NUMERIC_RADIX|NN const char **sp|NN const char *send
8203 
8204 A synonym for L</grok_numeric_radix>
8205 
8206 =cut
8207 */
8208 #define GROK_NUMERIC_RADIX(sp, send) grok_numeric_radix(sp, send)
8209 
8210 /* Number scan flags.  All are used for input, the ones used for output are so
8211  * marked */
8212 #define PERL_SCAN_ALLOW_UNDERSCORES   0x01 /* grok_??? accept _ in numbers */
8213 #define PERL_SCAN_DISALLOW_PREFIX     0x02 /* grok_??? reject 0x in hex etc */
8214 
8215 /* grok_??? input: ignored; output: found overflow */
8216 #define PERL_SCAN_GREATER_THAN_UV_MAX 0x04
8217 
8218 /* grok_??? don't warn about illegal digits.  To preserve total backcompat,
8219  * this isn't set on output if one is found.  Instead, see
8220  * PERL_SCAN_NOTIFY_ILLDIGIT. */
8221 #define PERL_SCAN_SILENT_ILLDIGIT     0x08
8222 
8223 #define PERL_SCAN_TRAILING            0x10 /* grok_number_flags() allow trailing
8224                                               and set IS_NUMBER_TRAILING */
8225 
8226 /* These are considered experimental, so not exposed publicly */
8227 #if defined(PERL_CORE) || defined(PERL_EXT)
8228 /* grok_??? don't warn about very large numbers which are <= UV_MAX;
8229  * output: found such a number */
8230 #  define PERL_SCAN_SILENT_NON_PORTABLE 0x20
8231 
8232 /* If this is set on input, and no illegal digit is found, it will be cleared
8233  * on output; otherwise unchanged */
8234 #  define PERL_SCAN_NOTIFY_ILLDIGIT 0x40
8235 
8236 /* Don't warn on overflow; output flag still set */
8237 #  define PERL_SCAN_SILENT_OVERFLOW 0x80
8238 
8239 /* Forbid a leading underscore, which the other one doesn't */
8240 #  define PERL_SCAN_ALLOW_MEDIAL_UNDERSCORES (0x100|PERL_SCAN_ALLOW_UNDERSCORES)
8241 #endif
8242 
8243 
8244 /* to let user control profiling */
8245 #ifdef PERL_GPROF_CONTROL
8246 extern void moncontrol(int);
8247 #define PERL_GPROF_MONCONTROL(x) moncontrol(x)
8248 #else
8249 #define PERL_GPROF_MONCONTROL(x)
8250 #endif
8251 
8252 /* ISO 6429 NEL - C1 control NExt Line */
8253 /* See https://www.unicode.org/unicode/reports/tr13/ */
8254 #define NEXT_LINE_CHAR	NEXT_LINE_NATIVE
8255 
8256 #ifndef PIPESOCK_MODE
8257 #  define PIPESOCK_MODE
8258 #endif
8259 
8260 #ifndef SOCKET_OPEN_MODE
8261 #  define SOCKET_OPEN_MODE	PIPESOCK_MODE
8262 #endif
8263 
8264 #ifndef PIPE_OPEN_MODE
8265 #  define PIPE_OPEN_MODE	PIPESOCK_MODE
8266 #endif
8267 
8268 #define PERL_MAGIC_UTF8_CACHESIZE	2
8269 
8270 #ifdef PERL_CORE
8271 
8272 #define PERL_UNICODE_STDIN_FLAG			0x0001
8273 #define PERL_UNICODE_STDOUT_FLAG		0x0002
8274 #define PERL_UNICODE_STDERR_FLAG		0x0004
8275 #define PERL_UNICODE_IN_FLAG			0x0008
8276 #define PERL_UNICODE_OUT_FLAG			0x0010
8277 #define PERL_UNICODE_ARGV_FLAG			0x0020
8278 #define PERL_UNICODE_LOCALE_FLAG		0x0040
8279 #define PERL_UNICODE_WIDESYSCALLS_FLAG		0x0080 /* for Sarathy */
8280 #define PERL_UNICODE_UTF8CACHEASSERT_FLAG	0x0100
8281 
8282 #define PERL_UNICODE_STD_FLAG		\
8283         (PERL_UNICODE_STDIN_FLAG	| \
8284          PERL_UNICODE_STDOUT_FLAG	| \
8285          PERL_UNICODE_STDERR_FLAG)
8286 
8287 #define PERL_UNICODE_INOUT_FLAG		\
8288         (PERL_UNICODE_IN_FLAG	| \
8289          PERL_UNICODE_OUT_FLAG)
8290 
8291 #define PERL_UNICODE_DEFAULT_FLAGS	\
8292         (PERL_UNICODE_STD_FLAG		| \
8293          PERL_UNICODE_INOUT_FLAG	| \
8294          PERL_UNICODE_LOCALE_FLAG)
8295 
8296 #define PERL_UNICODE_ALL_FLAGS			0x01ff
8297 
8298 #define PERL_UNICODE_STDIN			'I'
8299 #define PERL_UNICODE_STDOUT			'O'
8300 #define PERL_UNICODE_STDERR			'E'
8301 #define PERL_UNICODE_STD			'S'
8302 #define PERL_UNICODE_IN				'i'
8303 #define PERL_UNICODE_OUT			'o'
8304 #define PERL_UNICODE_INOUT			'D'
8305 #define PERL_UNICODE_ARGV			'A'
8306 #define PERL_UNICODE_LOCALE			'L'
8307 #define PERL_UNICODE_WIDESYSCALLS		'W'
8308 #define PERL_UNICODE_UTF8CACHEASSERT		'a'
8309 
8310 #endif
8311 
8312 /*
8313 =for apidoc_section $signals
8314 =for apidoc Amn|U32|PERL_SIGNALS_UNSAFE_FLAG
8315 If this bit in C<PL_signals> is set, the system is uing the pre-Perl 5.8
8316 unsafe signals.  See L<perlrun/PERL_SIGNALS> and L<perlipc/Deferred Signals
8317 (Safe Signals)>.
8318 
8319 =cut
8320 */
8321 #define PERL_SIGNALS_UNSAFE_FLAG	0x0001
8322 
8323 /*
8324 =for apidoc_section $numeric
8325 
8326 =for apidoc Am|int|PERL_ABS|int x
8327 
8328 Typeless C<abs> or C<fabs>, I<etc>.  (The usage below indicates it is for
8329 integers, but it works for any type.)  Use instead of these, since the C
8330 library ones force their argument to be what it is expecting, potentially
8331 leading to disaster.  But also beware that this evaluates its argument twice,
8332 so no C<x++>.
8333 
8334 =cut
8335 */
8336 
8337 #define PERL_ABS(x) ((x) < 0 ? -(x) : (x))
8338 
8339 #if defined(__DECC) && defined(__osf__)
8340 #pragma message disable (mainparm) /* Perl uses the envp in main(). */
8341 #endif
8342 
8343 #define do_open(g, n, l, a, rm, rp, sf) \
8344         do_openn(g, n, l, a, rm, rp, sf, (SV **) NULL, 0)
8345 #ifdef PERL_DEFAULT_DO_EXEC3_IMPLEMENTATION
8346 #  define do_exec(cmd)			do_exec3(cmd,0,0)
8347 #endif
8348 #ifdef OS2
8349 #  define do_aexec			Perl_do_aexec
8350 #else
8351 #  define do_aexec(really, mark,sp)	do_aexec5(really, mark, sp, 0, 0)
8352 #endif
8353 
8354 
8355 /*
8356 =for apidoc_section $utility
8357 
8358 =for apidoc Am|bool|IS_SAFE_SYSCALL|NN const char *pv|STRLEN len|NN const char *what|NN const char *op_name
8359 
8360 Same as L</is_safe_syscall>.
8361 
8362 =cut
8363 
8364 Allows one ending \0
8365 */
8366 #define IS_SAFE_SYSCALL(p, len, what, op_name) (Perl_is_safe_syscall(aTHX_ (p), (len), (what), (op_name)))
8367 
8368 #define IS_SAFE_PATHNAME(p, len, op_name) IS_SAFE_SYSCALL((p), (len), "pathname", (op_name))
8369 
8370 #if defined(OEMVS) || defined(__amigaos4__)
8371 #define NO_ENV_ARRAY_IN_MAIN
8372 #endif
8373 
8374 /* These are used by Perl_pv_escape() and Perl_pv_pretty()
8375  * are here so that they are available throughout the core
8376  * NOTE that even though some are for _escape and some for _pretty
8377  * there must not be any clashes as the flags from _pretty are
8378  * passed straight through to _escape.
8379  */
8380 
8381 #define PERL_PV_ESCAPE_QUOTE        0x000001
8382 #define PERL_PV_PRETTY_QUOTE        PERL_PV_ESCAPE_QUOTE
8383 
8384 #define PERL_PV_PRETTY_ELLIPSES     0x000002
8385 #define PERL_PV_PRETTY_LTGT         0x000004
8386 #define PERL_PV_PRETTY_EXACTSIZE    0x000008
8387 
8388 #define PERL_PV_ESCAPE_UNI          0x000100
8389 #define PERL_PV_ESCAPE_UNI_DETECT   0x000200
8390 #define PERL_PV_ESCAPE_NONASCII     0x000400
8391 #define PERL_PV_ESCAPE_FIRSTCHAR    0x000800
8392 
8393 #define PERL_PV_ESCAPE_ALL          0x001000
8394 #define PERL_PV_ESCAPE_NOBACKSLASH  0x002000
8395 #define PERL_PV_ESCAPE_NOCLEAR      0x004000
8396 #define PERL_PV_PRETTY_NOCLEAR      PERL_PV_ESCAPE_NOCLEAR
8397 #define PERL_PV_ESCAPE_RE           0x008000
8398 
8399 /* Escape PV with hex, except leave NULs as octal: */
8400 #define PERL_PV_ESCAPE_DWIM         0x010000
8401 
8402 /* Escape PV with all hex, including NUL. */
8403 #define PERL_PV_ESCAPE_DWIM_ALL_HEX 0x020000
8404 
8405 /* Do not escape word characters, alters meaning of other flags */
8406 #define PERL_PV_ESCAPE_NON_WC       0x040000
8407 #define PERL_PV_ESCAPE_TRUNC_MIDDLE 0x080000
8408 
8409 #define PERL_PV_PRETTY_QUOTEDPREFIX (   \
8410         PERL_PV_PRETTY_ELLIPSES |       \
8411         PERL_PV_PRETTY_QUOTE    |       \
8412         PERL_PV_ESCAPE_NONASCII |       \
8413         PERL_PV_ESCAPE_NON_WC   |       \
8414         PERL_PV_ESCAPE_TRUNC_MIDDLE |   \
8415         0)
8416 
8417 
8418 /* used by pv_display in dump.c*/
8419 #define PERL_PV_PRETTY_DUMP  PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_QUOTE
8420 #define PERL_PV_PRETTY_REGPROP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_LTGT|PERL_PV_ESCAPE_RE|PERL_PV_ESCAPE_NONASCII
8421 
8422 #if DOUBLEKIND == DOUBLE_IS_VAX_F_FLOAT || \
8423     DOUBLEKIND == DOUBLE_IS_VAX_D_FLOAT || \
8424     DOUBLEKIND == DOUBLE_IS_VAX_G_FLOAT
8425 #  define DOUBLE_IS_VAX_FLOAT
8426 #else
8427 #  define DOUBLE_IS_IEEE_FORMAT
8428 #endif
8429 
8430 #if DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN || \
8431     DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN || \
8432     DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
8433 #  define DOUBLE_LITTLE_ENDIAN
8434 #endif
8435 
8436 #if DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN || \
8437     DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN || \
8438     DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
8439 #  define DOUBLE_BIG_ENDIAN
8440 #endif
8441 
8442 #if DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE || \
8443     DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE
8444 #  define DOUBLE_MIX_ENDIAN
8445 #endif
8446 
8447 /* The VAX fp formats are neither consistently little-endian nor
8448  * big-endian, and neither are they really IEEE-mixed endian like
8449  * the mixed-endian ARM IEEE formats (with swapped bytes).
8450  * Ultimately, the VAX format came from the PDP-11.
8451  *
8452  * The ordering of the parts in VAX floats is quite vexing.
8453  * In the below the fraction_n are the mantissa bits.
8454  *
8455  * The fraction_1 is the most significant (numbering as by DEC/Digital),
8456  * while the rightmost bit in each fraction is the least significant:
8457  * in other words, big-endian bit order within the fractions.
8458  *
8459  * The fraction segments themselves would be big-endianly, except that
8460  * within 32 bit segments the less significant half comes first, the more
8461  * significant after, except that in the format H (used for long doubles)
8462  * the first fraction segment is alone, because the exponent is wider.
8463  * This means for example that both the most and the least significant
8464  * bits can be in the middle of the floats, not at either end.
8465  *
8466  * References:
8467  * http://nssdc.gsfc.nasa.gov/nssdc/formats/VAXFloatingPoint.htm
8468  * http://www.quadibloc.com/comp/cp0201.htm
8469  * http://h71000.www7.hp.com/doc/82final/6443/6443pro_028.html
8470  * (somebody at HP should be fired for the URLs)
8471  *
8472  * F   fraction_2:16 sign:1 exp:8  fraction_1:7
8473  *     (exponent bias 128, hidden first one-bit)
8474  *
8475  * D   fraction_2:16 sign:1 exp:8  fraction_1:7
8476  *     fraction_4:16               fraction_3:16
8477  *     (exponent bias 128, hidden first one-bit)
8478  *
8479  * G   fraction_2:16 sign:1 exp:11 fraction_1:4
8480  *     fraction_4:16               fraction_3:16
8481  *     (exponent bias 1024, hidden first one-bit)
8482  *
8483  * H   fraction_1:16 sign:1 exp:15
8484  *     fraction_3:16               fraction_2:16
8485  *     fraction_5:16               fraction_4:16
8486  *     fraction_7:16               fraction_6:16
8487  *     (exponent bias 16384, hidden first one-bit)
8488  *     (available only on VAX, and only on Fortran?)
8489  *
8490  * The formats S, T and X are available on the Alpha (and Itanium,
8491  * also known as I64/IA64) and are equivalent with the IEEE-754 formats
8492  * binary32, binary64, and binary128 (commonly: float, double, long double).
8493  *
8494  * S   sign:1 exp:8 mantissa:23
8495  *     (exponent bias 127, hidden first one-bit)
8496  *
8497  * T   sign:1 exp:11 mantissa:52
8498  *     (exponent bias 1022, hidden first one-bit)
8499  *
8500  * X   sign:1 exp:15 mantissa:112
8501  *     (exponent bias 16382, hidden first one-bit)
8502  *
8503  */
8504 
8505 #ifdef DOUBLE_IS_VAX_FLOAT
8506 #  define DOUBLE_VAX_ENDIAN
8507 #endif
8508 
8509 #ifdef DOUBLE_IS_IEEE_FORMAT
8510 /* All the basic IEEE formats have the implicit bit,
8511  * except for the x86 80-bit extended formats, which will undef this.
8512  * Also note that the IEEE 754 subnormals (formerly known as denormals)
8513  * do not have the implicit bit of one. */
8514 #  define NV_IMPLICIT_BIT
8515 #endif
8516 
8517 #if defined(LONG_DOUBLEKIND) && LONG_DOUBLEKIND != LONG_DOUBLE_IS_DOUBLE
8518 
8519 #  if LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN || \
8520       LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN || \
8521       LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE
8522 #    define LONGDOUBLE_LITTLE_ENDIAN
8523 #  endif
8524 
8525 #  if LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN || \
8526       LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN || \
8527       LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE
8528 #    define LONGDOUBLE_BIG_ENDIAN
8529 #  endif
8530 
8531 #  if LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE || \
8532       LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE
8533 #    define LONGDOUBLE_MIX_ENDIAN
8534 #  endif
8535 
8536 #  if LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN || \
8537       LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN
8538 #    define LONGDOUBLE_X86_80_BIT
8539 #    ifdef USE_LONG_DOUBLE
8540 #      undef NV_IMPLICIT_BIT
8541 #      define NV_X86_80_BIT
8542 #    endif
8543 #  endif
8544 
8545 #  if LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE || \
8546       LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE || \
8547       LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE || \
8548       LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE
8549 #    define LONGDOUBLE_DOUBLEDOUBLE
8550 #  endif
8551 
8552 #  if LONG_DOUBLEKIND == LONG_DOUBLE_IS_VAX_H_FLOAT
8553 #    define LONGDOUBLE_VAX_ENDIAN
8554 #  endif
8555 
8556 #endif /* LONG_DOUBLEKIND */
8557 
8558 #ifdef USE_QUADMATH /* assume quadmath endianness == native double endianness */
8559 #  if defined(DOUBLE_LITTLE_ENDIAN)
8560 #    define NV_LITTLE_ENDIAN
8561 #  elif defined(DOUBLE_BIG_ENDIAN)
8562 #    define NV_BIG_ENDIAN
8563 #  elif defined(DOUBLE_MIX_ENDIAN) /* stretch */
8564 #    define NV_MIX_ENDIAN
8565 #  endif
8566 #elif NVSIZE == DOUBLESIZE
8567 #  ifdef DOUBLE_LITTLE_ENDIAN
8568 #    define NV_LITTLE_ENDIAN
8569 #  endif
8570 #  ifdef DOUBLE_BIG_ENDIAN
8571 #    define NV_BIG_ENDIAN
8572 #  endif
8573 #  ifdef DOUBLE_MIX_ENDIAN
8574 #    define NV_MIX_ENDIAN
8575 #  endif
8576 #  ifdef DOUBLE_VAX_ENDIAN
8577 #    define NV_VAX_ENDIAN
8578 #  endif
8579 #elif NVSIZE == LONG_DOUBLESIZE
8580 #  ifdef LONGDOUBLE_LITTLE_ENDIAN
8581 #    define NV_LITTLE_ENDIAN
8582 #  endif
8583 #  ifdef LONGDOUBLE_BIG_ENDIAN
8584 #    define NV_BIG_ENDIAN
8585 #  endif
8586 #  ifdef LONGDOUBLE_MIX_ENDIAN
8587 #    define NV_MIX_ENDIAN
8588 #  endif
8589 #  ifdef LONGDOUBLE_VAX_ENDIAN
8590 #    define NV_VAX_ENDIAN
8591 #  endif
8592 #endif
8593 
8594 /* We have somehow managed not to define the denormal/subnormal
8595  * detection.
8596  *
8597  * This may happen if the compiler doesn't expose the C99 math like
8598  * the fpclassify() without some special switches.  Perl tries to
8599  * stay C89, so for example -std=c99 is not an option.
8600  *
8601  * The Perl_isinf() and Perl_isnan() should have been defined even if
8602  * the C99 isinf() and isnan() are unavailable, and the NV_MIN becomes
8603  * from the C89 DBL_MIN or moral equivalent. */
8604 #if !defined(Perl_fp_class_denorm) && defined(Perl_isinf) && defined(Perl_isnan) && defined(NV_MIN)
8605 #  define Perl_fp_class_denorm(x) ((x) != 0.0 && !Perl_isinf(x) && !Perl_isnan(x) && PERL_ABS(x) < NV_MIN)
8606 #endif
8607 
8608 /* This is not a great fallback: subnormals tests will fail,
8609  * but at least Perl will link and 99.999% of tests will work. */
8610 #if !defined(Perl_fp_class_denorm)
8611 #  define Perl_fp_class_denorm(x) FALSE
8612 #endif
8613 
8614 #ifdef DOUBLE_IS_IEEE_FORMAT
8615 #  define DOUBLE_HAS_INF
8616 #  define DOUBLE_HAS_NAN
8617 #endif
8618 
8619 #ifdef DOUBLE_HAS_NAN
8620 
8621 START_EXTERN_C
8622 
8623 #ifdef DOINIT
8624 
8625 /* PL_inf and PL_nan initialization.
8626  *
8627  * For inf and nan initialization the ultimate fallback is dividing
8628  * one or zero by zero: however, some compilers will warn or even fail
8629  * on divide-by-zero, but hopefully something earlier will work.
8630  *
8631  * If you are thinking of using HUGE_VAL for infinity, or using
8632  * <math.h> functions to generate NV_INF (e.g. exp(1e9), log(-1.0)),
8633  * stop.  Neither will work portably: HUGE_VAL can be just DBL_MAX,
8634  * and the math functions might be just generating DBL_MAX, or even zero.
8635  *
8636  * Also, do NOT try doing NV_NAN based on NV_INF and trying (NV_INF-NV_INF).
8637  * Though logically correct, some compilers (like Visual C 2003)
8638  * falsely misoptimize that to zero (x-x is always zero, right?)
8639  *
8640  * Finally, note that not all floating point formats define Inf (or NaN).
8641  * For the infinity a large number may be used instead.  Operations that
8642  * under the IEEE floating point would return Inf or NaN may return
8643  * either large numbers (positive or negative), or they may cause
8644  * a floating point exception or some other fault.
8645  */
8646 
8647 /* The quadmath literals are anon structs which -Wc++-compat doesn't like. */
8648 #  ifndef USE_CPLUSPLUS
8649 GCC_DIAG_IGNORE_DECL(-Wc++-compat);
8650 #  endif
8651 
8652 #  ifdef USE_QUADMATH
8653 /* Cannot use HUGE_VALQ for PL_inf because not a compile-time
8654  * constant. */
8655 INFNAN_NV_U8_DECL PL_inf = { 1.0Q/0.0Q };
8656 #  elif NVSIZE == LONG_DOUBLESIZE && defined(LONGDBLINFBYTES)
8657 INFNAN_U8_NV_DECL PL_inf = { { LONGDBLINFBYTES } };
8658 #  elif NVSIZE == DOUBLESIZE && defined(DOUBLEINFBYTES)
8659 INFNAN_U8_NV_DECL PL_inf = { { DOUBLEINFBYTES } };
8660 #  else
8661 #    if NVSIZE == LONG_DOUBLESIZE && defined(USE_LONG_DOUBLE)
8662 #      if defined(LDBL_INFINITY)
8663 INFNAN_NV_U8_DECL PL_inf = { LDBL_INFINITY };
8664 #      elif defined(LDBL_INF)
8665 INFNAN_NV_U8_DECL PL_inf = { LDBL_INF };
8666 #      elif defined(INFINITY)
8667 INFNAN_NV_U8_DECL PL_inf = { (NV)INFINITY };
8668 #      elif defined(INF)
8669 INFNAN_NV_U8_DECL PL_inf = { (NV)INF };
8670 #      else
8671 INFNAN_NV_U8_DECL PL_inf = { 1.0L/0.0L }; /* keep last */
8672 #      endif
8673 #    else
8674 #      if defined(DBL_INFINITY)
8675 INFNAN_NV_U8_DECL PL_inf = { DBL_INFINITY };
8676 #      elif defined(DBL_INF)
8677 INFNAN_NV_U8_DECL PL_inf = { DBL_INF };
8678 #      elif defined(INFINITY) /* C99 */
8679 INFNAN_NV_U8_DECL PL_inf = { (NV)INFINITY };
8680 #      elif defined(INF)
8681 INFNAN_NV_U8_DECL PL_inf = { (NV)INF };
8682 #      else
8683 INFNAN_NV_U8_DECL PL_inf = { 1.0/0.0 }; /* keep last */
8684 #      endif
8685 #    endif
8686 #  endif
8687 
8688 #  ifdef USE_QUADMATH
8689 /* Cannot use nanq("0") for PL_nan because not a compile-time
8690  * constant. */
8691 INFNAN_NV_U8_DECL PL_nan = { 0.0Q/0.0Q };
8692 #  elif NVSIZE == LONG_DOUBLESIZE && defined(LONGDBLNANBYTES)
8693 INFNAN_U8_NV_DECL PL_nan = { { LONGDBLNANBYTES } };
8694 #  elif NVSIZE == DOUBLESIZE && defined(DOUBLENANBYTES)
8695 INFNAN_U8_NV_DECL PL_nan = { { DOUBLENANBYTES } };
8696 #  else
8697 #    if NVSIZE == LONG_DOUBLESIZE && defined(USE_LONG_DOUBLE)
8698 #      if defined(LDBL_NAN)
8699 INFNAN_NV_U8_DECL PL_nan = { LDBL_NAN };
8700 #      elif defined(LDBL_QNAN)
8701 INFNAN_NV_U8_DECL PL_nan = { LDBL_QNAN };
8702 #      elif defined(NAN)
8703 INFNAN_NV_U8_DECL PL_nan = { (NV)NAN };
8704 #      else
8705 INFNAN_NV_U8_DECL PL_nan = { 0.0L/0.0L }; /* keep last */
8706 #      endif
8707 #    else
8708 #      if defined(DBL_NAN)
8709 INFNAN_NV_U8_DECL PL_nan = { DBL_NAN };
8710 #      elif defined(DBL_QNAN)
8711 INFNAN_NV_U8_DECL PL_nan = { DBL_QNAN };
8712 #      elif defined(NAN) /* C99 */
8713 INFNAN_NV_U8_DECL PL_nan = { (NV)NAN };
8714 #      else
8715 INFNAN_NV_U8_DECL PL_nan = { 0.0/0.0 }; /* keep last */
8716 #      endif
8717 #    endif
8718 #  endif
8719 
8720 #  ifndef USE_CPLUSPLUS
8721 GCC_DIAG_RESTORE_DECL;
8722 #  endif
8723 
8724 #else
8725 
8726 /* The declarations here need to match the initializations done above,
8727    since a mismatch across compilation units causes undefined
8728    behavior.  It also prevents warnings from LTO builds.
8729 */
8730 #  if !defined(USE_QUADMATH) && \
8731        (NVSIZE == LONG_DOUBLESIZE && defined(LONGDBLINFBYTES) ||   \
8732         NVSIZE == DOUBLESIZE && defined(DOUBLEINFBYTES))
8733 INFNAN_U8_NV_DECL PL_inf;
8734 #  else
8735 INFNAN_NV_U8_DECL PL_inf;
8736 #  endif
8737 
8738 #  if !defined(USE_QUADMATH) && \
8739        (NVSIZE == LONG_DOUBLESIZE && defined(LONGDBLNANBYTES) ||   \
8740         NVSIZE == DOUBLESIZE && defined(DOUBLENANBYTES))
8741 INFNAN_U8_NV_DECL PL_nan;
8742 #  else
8743 INFNAN_NV_U8_DECL PL_nan;
8744 #  endif
8745 
8746 #endif
8747 
8748 END_EXTERN_C
8749 
8750 /* If you have not defined NV_INF/NV_NAN (like for example win32/win32.h),
8751  * we will define NV_INF/NV_NAN as the nv part of the global const
8752  * PL_inf/PL_nan.  Note, however, that the preexisting NV_INF/NV_NAN
8753  * might not be a compile-time constant, in which case it cannot be
8754  * used to initialize PL_inf/PL_nan above. */
8755 #ifndef NV_INF
8756 #  define NV_INF PL_inf.nv
8757 #endif
8758 #ifndef NV_NAN
8759 #  define NV_NAN PL_nan.nv
8760 #endif
8761 
8762 /* NaNs (not-a-numbers) can carry payload bits, in addition to
8763  * "nan-ness".  Part of the payload is the quiet/signaling bit.
8764  * To back up a bit (harhar):
8765  *
8766  * For IEEE 754 64-bit formats [1]:
8767  *
8768  * s 000 (mantissa all-zero)  zero
8769  * s 000 (mantissa non-zero)  subnormals (denormals)
8770  * s 001 ... 7fe              normals
8771  * s 7ff q                    nan
8772  *
8773  * For IEEE 754 128-bit formats:
8774  *
8775  * s 0000 (mantissa all-zero)  zero
8776  * s 0000 (mantissa non-zero)  subnormals (denormals)
8777  * s 0001 ... 7ffe             normals
8778  * s 7fff q                    nan
8779  *
8780  * [1] this looks like big-endian, but applies equally to little-endian.
8781  *
8782  * s = Sign bit.  Yes, zeros and nans can have negative sign,
8783  *     the interpretation is application-specific.
8784  *
8785  * q = Quietness bit, the interpretation is platform-specific.
8786  *     Most platforms have the most significant bit being one
8787  *     meaning quiet, but some (older mips, hppa) have the msb
8788  *     being one meaning signaling.  Note that the above means
8789  *     that on most platforms there cannot be signaling nan with
8790  *     zero payload because that is identical with infinity;
8791  *     while conversely on older mips/hppa there cannot be a quiet nan
8792  *     because that is identical with infinity.
8793  *
8794  *     Moreover, whether there is any behavioral difference
8795  *     between quiet and signaling NaNs, depends on the platform.
8796  *
8797  * x86 80-bit extended precision is different, the mantissa bits:
8798  *
8799  * 63 62 61   30387+    pre-387    visual c
8800  * --------   ----      --------   --------
8801  *  0  0  0   invalid   infinity
8802  *  0  0  1   invalid   snan
8803  *  0  1  0   invalid   snan
8804  *  0  1  1   invalid   snan
8805  *  1  0  0   infinity  snan        1.#INF
8806  *  1  0  1   snan                  1.#SNAN
8807  *  1  1  0   qnan                 -1.#IND  (x86 chooses this to negative)
8808  *  1  1  1   qnan                  1.#QNAN
8809  *
8810  * This means that in this format there are 61 bits available
8811  * for the nan payload.
8812  *
8813  * Note that the 32-bit x86 ABI cannot do signaling nans: the x87
8814  * simply cannot preserve the bit.  You can either use the 80-bit
8815  * extended precision (long double, -Duselongdouble), or use x86-64.
8816  *
8817  * In all platforms, the payload bytes (and bits, some of them are
8818  * often in a partial byte) themselves can be either all zero (x86),
8819  * all one (sparc or mips), or a mixture: in IEEE 754 128-bit double
8820  * or in a double-double, the first half of the payload can follow the
8821  * native double, while in the second half the payload can be all
8822  * zeros.  (Therefore the mask for payload bits is not necessarily
8823  * identical to bit complement of the NaN.)  Another way of putting
8824  * this: the payload for the default NaN might not be zero.
8825  *
8826  * For the x86 80-bit long doubles, the trailing bytes (the 80 bits
8827  * being 'packaged' in either 12 or 16 bytes) can be whatever random
8828  * garbage.
8829  *
8830  * Furthermore, the semantics of the sign bit on NaNs are platform-specific.
8831  * On normal floats, the sign bit being on means negative.  But this may,
8832  * or may not, be reverted on NaNs: in other words, the default NaN might
8833  * have the sign bit on, and therefore look like negative if you look
8834  * at it at the bit level.
8835  *
8836  * NaN payloads are not propagated even on copies, or in arithmetics.
8837  * They *might* be, according to some rules, on your particular
8838  * cpu/os/compiler/libraries, but no guarantees.
8839  *
8840  * To summarize, on most platforms, and for 64-bit doubles
8841  * (using big-endian ordering here):
8842  *
8843  * [7FF8000000000000..7FFFFFFFFFFFFFFF] quiet
8844  * [FFF8000000000000..FFFFFFFFFFFFFFFF] quiet
8845  * [7FF0000000000001..7FF7FFFFFFFFFFFF] signaling
8846  * [FFF0000000000001..FFF7FFFFFFFFFFFF] signaling
8847  *
8848  * The C99 nan() is supposed to generate *quiet* NaNs.
8849  *
8850  * Note the asymmetry:
8851  * The 7FF0000000000000 is positive infinity,
8852  * the FFF0000000000000 is negative infinity.
8853  */
8854 
8855 /* NVMANTBITS is the number of _real_ mantissa bits in an NV.
8856  * For the standard IEEE 754 fp this number is usually one less that
8857  * *DBL_MANT_DIG because of the implicit (aka hidden) bit, which isn't
8858  * real.  For the 80-bit extended precision formats (x86*), the number
8859  * of mantissa bits... depends. For normal floats, it's 64.  But for
8860  * the inf/nan, it's different (zero for inf, 61 for nan).
8861  * NVMANTBITS works for normal floats. */
8862 
8863 /* We do not want to include the quiet/signaling bit. */
8864 #define NV_NAN_BITS (NVMANTBITS - 1)
8865 
8866 #if defined(USE_LONG_DOUBLE) && NVSIZE > DOUBLESIZE
8867 #  if LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
8868 #    define NV_NAN_QS_BYTE_OFFSET 13
8869 #  elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
8870 #    define NV_NAN_QS_BYTE_OFFSET 2
8871 #  elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN
8872 #    define NV_NAN_QS_BYTE_OFFSET 7
8873 #  elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN
8874 #    define NV_NAN_QS_BYTE_OFFSET 2
8875 #  elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE
8876 #    define NV_NAN_QS_BYTE_OFFSET 13
8877 #  elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE
8878 #    define NV_NAN_QS_BYTE_OFFSET 1
8879 #  elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE
8880 #    define NV_NAN_QS_BYTE_OFFSET 9
8881 #  elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE
8882 #    define NV_NAN_QS_BYTE_OFFSET 6
8883 #  else
8884 #    error "Unexpected long double format"
8885 #  endif
8886 #else
8887 #  ifdef USE_QUADMATH
8888 #    ifdef NV_LITTLE_ENDIAN
8889 #      define NV_NAN_QS_BYTE_OFFSET 13
8890 #    elif defined(NV_BIG_ENDIAN)
8891 #      define NV_NAN_QS_BYTE_OFFSET 2
8892 #    else
8893 #      error "Unexpected quadmath format"
8894 #    endif
8895 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN
8896 #    define NV_NAN_QS_BYTE_OFFSET 2
8897 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN
8898 #    define NV_NAN_QS_BYTE_OFFSET 1
8899 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN
8900 #    define NV_NAN_QS_BYTE_OFFSET 6
8901 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN
8902 #    define NV_NAN_QS_BYTE_OFFSET 1
8903 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
8904 #    define NV_NAN_QS_BYTE_OFFSET 13
8905 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
8906 #    define NV_NAN_QS_BYTE_OFFSET 2
8907 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE
8908 #    define NV_NAN_QS_BYTE_OFFSET 2 /* bytes 4 5 6 7 0 1 2 3 (MSB 7) */
8909 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE
8910 #    define NV_NAN_QS_BYTE_OFFSET 5 /* bytes 3 2 1 0 7 6 5 4 (MSB 7) */
8911 #  else
8912 /* For example the VAX formats should never
8913  * get here because they do not have NaN. */
8914 #    error "Unexpected double format"
8915 #  endif
8916 #endif
8917 /* NV_NAN_QS_BYTE is the byte to test for the quiet/signaling */
8918 #define NV_NAN_QS_BYTE(nvp) (((U8*)(nvp))[NV_NAN_QS_BYTE_OFFSET])
8919 /* NV_NAN_QS_BIT is the bit to test in the NV_NAN_QS_BYTE_OFFSET
8920  * for the quiet/signaling */
8921 #if defined(USE_LONG_DOUBLE) && \
8922   (LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN || \
8923    LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN)
8924 #  define NV_NAN_QS_BIT_SHIFT 6 /* 0x40 */
8925 #elif defined(USE_LONG_DOUBLE) && \
8926   (LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE || \
8927    LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE || \
8928    LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE || \
8929    LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE)
8930 #  define NV_NAN_QS_BIT_SHIFT 3 /* 0x08, but not via NV_NAN_BITS */
8931 #else
8932 #  define NV_NAN_QS_BIT_SHIFT ((NV_NAN_BITS) % 8) /* usually 3, or 0x08 */
8933 #endif
8934 #define NV_NAN_QS_BIT (1 << (NV_NAN_QS_BIT_SHIFT))
8935 /* NV_NAN_QS_BIT_OFFSET is the bit offset from the beginning of a NV
8936  * (bytes ordered big-endianly) for the quiet/signaling bit
8937  * for the quiet/signaling */
8938 #define NV_NAN_QS_BIT_OFFSET \
8939     (8 * (NV_NAN_QS_BYTE_OFFSET) + (NV_NAN_QS_BIT_SHIFT))
8940 /* NV_NAN_QS_QUIET (always defined) is true if the NV_NAN_QS_QS_BIT being
8941  * on indicates quiet NaN.  NV_NAN_QS_SIGNALING (also always defined)
8942  * is true if the NV_NAN_QS_BIT being on indicates signaling NaN. */
8943 #define NV_NAN_QS_QUIET \
8944     ((NV_NAN_QS_BYTE(PL_nan.u8) & NV_NAN_QS_BIT) == NV_NAN_QS_BIT)
8945 #define NV_NAN_QS_SIGNALING (!(NV_NAN_QS_QUIET))
8946 #define NV_NAN_QS_TEST(nvp) (NV_NAN_QS_BYTE(nvp) & NV_NAN_QS_BIT)
8947 /* NV_NAN_IS_QUIET() returns true if the NV behind nvp is a NaN,
8948  * whether it is a quiet NaN, NV_NAN_IS_SIGNALING() if a signaling NaN.
8949  * Note however that these do not check whether the nvp is a NaN. */
8950 #define NV_NAN_IS_QUIET(nvp) \
8951     (NV_NAN_QS_TEST(nvp) == (NV_NAN_QS_QUIET ? NV_NAN_QS_BIT : 0))
8952 #define NV_NAN_IS_SIGNALING(nvp) \
8953     (NV_NAN_QS_TEST(nvp) == (NV_NAN_QS_QUIET ? 0 : NV_NAN_QS_BIT))
8954 #define NV_NAN_SET_QUIET(nvp) \
8955     (NV_NAN_QS_QUIET ? \
8956      (NV_NAN_QS_BYTE(nvp) |= NV_NAN_QS_BIT) : \
8957      (NV_NAN_QS_BYTE(nvp) &= ~NV_NAN_QS_BIT))
8958 #define NV_NAN_SET_SIGNALING(nvp) \
8959     (NV_NAN_QS_QUIET ? \
8960      (NV_NAN_QS_BYTE(nvp) &= ~NV_NAN_QS_BIT) : \
8961      (NV_NAN_QS_BYTE(nvp) |= NV_NAN_QS_BIT))
8962 #define NV_NAN_QS_XOR(nvp) (NV_NAN_QS_BYTE(nvp) ^= NV_NAN_QS_BIT)
8963 
8964 /* NV_NAN_PAYLOAD_MASK: masking the nan payload bits.
8965  *
8966  * NV_NAN_PAYLOAD_PERM: permuting the nan payload bytes.
8967  * 0xFF means "don't go here".*/
8968 
8969 /* Shorthands to avoid typoses. */
8970 #define NV_NAN_PAYLOAD_MASK_SKIP_EIGHT \
8971   0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
8972 #define NV_NAN_PAYLOAD_PERM_SKIP_EIGHT \
8973   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8974 #define NV_NAN_PAYLOAD_PERM_0_TO_7 \
8975   0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7
8976 #define NV_NAN_PAYLOAD_PERM_7_TO_0 \
8977   0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0
8978 #define NV_NAN_PAYLOAD_MASK_IEEE_754_128_LE \
8979   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
8980   0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00
8981 #define NV_NAN_PAYLOAD_PERM_IEEE_754_128_LE \
8982   NV_NAN_PAYLOAD_PERM_0_TO_7, \
8983   0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xFF, 0xFF
8984 #define NV_NAN_PAYLOAD_MASK_IEEE_754_128_BE \
8985   0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, \
8986   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8987 #define NV_NAN_PAYLOAD_PERM_IEEE_754_128_BE \
8988   0xFF, 0xFF, 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, \
8989   NV_NAN_PAYLOAD_PERM_7_TO_0
8990 #define NV_NAN_PAYLOAD_MASK_IEEE_754_64_LE \
8991   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00
8992 #define NV_NAN_PAYLOAD_PERM_IEEE_754_64_LE \
8993   0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0xFF
8994 #define NV_NAN_PAYLOAD_MASK_IEEE_754_64_BE \
8995   0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8996 #define NV_NAN_PAYLOAD_PERM_IEEE_754_64_BE \
8997   0xFF, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0
8998 
8999 #if defined(USE_LONG_DOUBLE) && NVSIZE > DOUBLESIZE
9000 #  if LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
9001 #    define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_LE
9002 #    define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_LE
9003 #  elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
9004 #    define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_BE
9005 #    define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_BE
9006 #  elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN
9007 #    if LONG_DOUBLESIZE == 10
9008 #      define NV_NAN_PAYLOAD_MASK \
9009          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, \
9010          0x00, 0x00
9011 #      define NV_NAN_PAYLOAD_PERM \
9012          NV_NAN_PAYLOAD_PERM_0_TO_7, 0xFF, 0xFF
9013 #    elif LONG_DOUBLESIZE == 12
9014 #      define NV_NAN_PAYLOAD_MASK \
9015          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, \
9016          0x00, 0x00, 0x00, 0x00
9017 #      define NV_NAN_PAYLOAD_PERM \
9018          NV_NAN_PAYLOAD_PERM_0_TO_7, 0xFF, 0xFF, 0xFF, 0xFF
9019 #    elif LONG_DOUBLESIZE == 16
9020 #      define NV_NAN_PAYLOAD_MASK \
9021          0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, \
9022          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9023 #      define NV_NAN_PAYLOAD_PERM \
9024          NV_NAN_PAYLOAD_PERM_0_TO_7, \
9025          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
9026 #    else
9027 #      error "Unexpected x86 80-bit little-endian long double format"
9028 #    endif
9029 #  elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN
9030 #    if LONG_DOUBLESIZE == 10
9031 #      define NV_NAN_PAYLOAD_MASK \
9032          0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, \
9033          0xff, 0xff
9034 #      define NV_NAN_PAYLOAD_PERM \
9035          NV_NAN_PAYLOAD_PERM_7_TO_0, 0xFF, 0xFF
9036 #    elif LONG_DOUBLESIZE == 12
9037 #      define NV_NAN_PAYLOAD_MASK \
9038          0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, \
9039          0xff, 0xff, 0x00, 0x00
9040 #      define NV_NAN_PAYLOAD_PERM \
9041          NV_NAN_PAYLOAD_PERM_7_TO_0, 0xFF, 0xFF, 0xFF, 0xFF
9042 #    elif LONG_DOUBLESIZE == 16
9043 #      define NV_NAN_PAYLOAD_MASK \
9044          0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, \
9045          0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9046 #      define NV_NAN_PAYLOAD_PERM \
9047          NV_NAN_PAYLOAD_PERM_7_TO_0, \
9048          0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
9049 #    else
9050 #      error "Unexpected x86 80-bit big-endian long double format"
9051 #    endif
9052 #  elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE
9053 /* For double-double we assume only the first double (in LE or BE terms)
9054  * is used for NaN. */
9055 #    define NV_NAN_PAYLOAD_MASK \
9056        NV_NAN_PAYLOAD_MASK_SKIP_EIGHT, NV_NAN_PAYLOAD_MASK_IEEE_754_64_LE
9057 #    define NV_NAN_PAYLOAD_PERM \
9058        NV_NAN_PAYLOAD_PERM_SKIP_EIGHT, NV_NAN_PAYLOAD_PERM_IEEE_754_64_LE
9059 #  elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE
9060 #    define NV_NAN_PAYLOAD_MASK \
9061        NV_NAN_PAYLOAD_MASK_IEEE_754_64_BE
9062 #    define NV_NAN_PAYLOAD_PERM \
9063        NV_NAN_PAYLOAD_PERM_IEEE_754_64_BE
9064 #  elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE
9065 #    define NV_NAN_PAYLOAD_MASK \
9066        NV_NAN_PAYLOAD_MASK_IEEE_754_64_LE
9067 #    define NV_NAN_PAYLOAD_PERM \
9068        NV_NAN_PAYLOAD_PERM_IEEE_754_64_LE
9069 #  elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE
9070 #    define NV_NAN_PAYLOAD_MASK \
9071        NV_NAN_PAYLOAD_MASK_SKIP_EIGHT, NV_NAN_PAYLOAD_MASK_IEEE_754_64_BE
9072 #    define NV_NAN_PAYLOAD_PERM \
9073        NV_NAN_PAYLOAD_PERM_SKIP_EIGHT, NV_NAN_PAYLOAD_PERM_IEEE_754_64_BE
9074 #  else
9075 #    error "Unexpected long double format"
9076 #  endif
9077 #else
9078 #  ifdef USE_QUADMATH /* quadmath is not long double */
9079 #    ifdef NV_LITTLE_ENDIAN
9080 #      define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_LE
9081 #      define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_LE
9082 #    elif defined(NV_BIG_ENDIAN)
9083 #      define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_BE
9084 #      define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_BE
9085 #    else
9086 #      error "Unexpected quadmath format"
9087 #    endif
9088 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN
9089 #    define NV_NAN_PAYLOAD_MASK 0xff, 0xff, 0x07, 0x00
9090 #    define NV_NAN_PAYLOAD_PERM 0x0, 0x1, 0x2, 0xFF
9091 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN
9092 #    define NV_NAN_PAYLOAD_MASK 0x00, 0x07, 0xff, 0xff
9093 #    define NV_NAN_PAYLOAD_PERM 0xFF, 0x2, 0x1, 0x0
9094 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN
9095 #    define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_64_LE
9096 #    define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_64_LE
9097 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN
9098 #    define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_64_BE
9099 #    define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_64_BE
9100 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
9101 #    define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_LE
9102 #    define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_LE
9103 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
9104 #    define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_BE
9105 #    define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_BE
9106 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE
9107 #    define NV_NAN_PAYLOAD_MASK 0xff, 0xff, 0x07, 0x00, 0xff, 0xff, 0xff, 0xff
9108 #    define NV_NAN_PAYLOAD_PERM 0x4, 0x5, 0x6, 0xFF, 0x0, 0x1, 0x2, 0x3
9109 #  elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE
9110 #    define NV_NAN_PAYLOAD_MASK 0xff, 0xff, 0xff, 0xff, 0x00, 0x07, 0xff, 0xff
9111 #    define NV_NAN_PAYLOAD_PERM 0x3, 0x2, 0x1, 0x0, 0xFF, 0x6, 0x5, 0x4
9112 #  else
9113 #    error "Unexpected double format"
9114 #  endif
9115 #endif
9116 
9117 #endif /* DOUBLE_HAS_NAN */
9118 
9119 /* these are used to faciliate the env var PERL_RAND_SEED,
9120  * which allows consistent behavior from code that calls
9121  * srand() with no arguments, either explicitly or implicitly.
9122  */
9123 #define PERL_SRAND_OVERRIDE_NEXT() PERL_XORSHIFT32_A(PL_srand_override_next);
9124 
9125 #define PERL_SRAND_OVERRIDE_NEXT_INIT() STMT_START {    \
9126     PL_srand_override = PL_srand_override_next;         \
9127     PERL_SRAND_OVERRIDE_NEXT();                         \
9128 } STMT_END
9129 
9130 #define PERL_SRAND_OVERRIDE_GET(into) STMT_START {      \
9131     into= PL_srand_override;                            \
9132     PERL_SRAND_OVERRIDE_NEXT_INIT();                    \
9133 } STMT_END
9134 
9135 #define PERL_SRAND_OVERRIDE_NEXT_CHILD() STMT_START {   \
9136     PERL_XORSHIFT32_B(PL_srand_override_next);          \
9137     PERL_SRAND_OVERRIDE_NEXT_INIT();                    \
9138 } STMT_END
9139 
9140 #define PERL_SRAND_OVERRIDE_NEXT_PARENT() \
9141     PERL_SRAND_OVERRIDE_NEXT()
9142 
9143 /* in something like
9144  *
9145  * perl -le'sub f { eval "BEGIN{ f() }" }'
9146  *
9147  * Each iteration chews up 8 stacks frames, and we will eventually SEGV
9148  * due to C stack overflow.
9149  *
9150  * This define provides a maximum limit to prevent the SEGV. Such code is
9151  * unusual, so it unlikely we need a very large number here.
9152  */
9153 #ifndef PERL_MAX_NESTED_EVAL_BEGIN_BLOCKS_DEFAULT
9154 #define PERL_MAX_NESTED_EVAL_BEGIN_BLOCKS_DEFAULT 1000
9155 #endif
9156 /* ${^MAX_NESTED_EVAL_BEGIN_BLOCKS} */
9157 #define PERL_VAR_MAX_NESTED_EVAL_BEGIN_BLOCKS "\015AX_NESTED_EVAL_BEGIN_BLOCKS"
9158 
9159 /* Defines like this make it easier to do porting/diag.t. They are no-
9160  * ops that return their argument which can be used to hint to diag.t
9161  * that a string is actually an error message. By putting the category
9162  * information into the macro name it considerably simplifies extended
9163  * diag.t to support these cases. Feel free to add more.
9164  *
9165  * While it seems tempting to try to convert all of our diagnostics to
9166  * this format, it would miss part of the point of diag.t in that it
9167  * detects NEW diagnostics, which would not necessarily use these
9168  * macros. The macros instead exist where we know we have an error
9169  * message that isnt being picked up by diag.t because it is declared
9170  * as a string independently of the function it is fed to, something
9171  * diag.t can never handle right without help.
9172  */
9173 #define PERL_DIAG_STR_(x)           ("" x "")
9174 #define PERL_DIAG_WARN_SYNTAX(x)    PERL_DIAG_STR_(x)
9175 #define PERL_DIAG_DIE_SYNTAX(x)     PERL_DIAG_STR_(x)
9176 
9177 #ifndef PERL_STOP_PARSING_AFTER_N_ERRORS
9178 #define PERL_STOP_PARSING_AFTER_N_ERRORS 10
9179 #endif
9180 
9181 #define PERL_PARSE_ERROR_COUNT(f)     (f)
9182 
9183 
9184 /* Work around
9185 
9186   https://github.com/Perl/perl5/issues/21313
9187 
9188   Where gcc when generating code for 32-bit windows assumes the stack
9189   is 16 byte aligned, where the system doesn't guarantee that.
9190 
9191   The code generated by gcc itself does maintain 16 byte alignment,
9192   but callbacks from the CRT or Windows APIs don't, so calls to
9193   code that is generated to SSE instructions (like the quadmath code
9194   by default), crashes when called from a callback.
9195 
9196   Since other code other than quadmath might use SSE instructions,
9197   also enable this outside of quadmath builds.
9198 
9199   This change is a little risky: if an XS module uses callbacks
9200   and those callbacks may also produce alignment errors, if that
9201   becomes a problem we'll need to use the nuclear option: building
9202   32-bit perl with -mstackrealign.
9203 */
9204 #if defined(WIN32) && !defined(WIN64) && defined(__GNUC__)
9205 #  define PERL_STACK_REALIGN __attribute__((force_align_arg_pointer))
9206 #else
9207 #  define PERL_STACK_REALIGN
9208 #endif
9209 
9210 /*
9211 
9212    (KEEP THIS LAST IN perl.h!)
9213 
9214    Mention
9215 
9216    NV_PRESERVES_UV
9217 
9218    HAS_MKSTEMP
9219    HAS_MKSTEMPS
9220    HAS_MKDTEMP
9221 
9222    HAS_GETCWD
9223 
9224    HAS_MMAP
9225    HAS_MPROTECT
9226    HAS_MSYNC
9227    HAS_MADVISE
9228    HAS_MUNMAP
9229    I_SYSMMAN
9230    Mmap_t
9231 
9232    NVef
9233    NVff
9234    NVgf
9235 
9236    HAS_UALARM
9237    HAS_USLEEP
9238 
9239    HAS_SETITIMER
9240    HAS_GETITIMER
9241 
9242    HAS_SENDMSG
9243    HAS_RECVMSG
9244    HAS_READV
9245    HAS_WRITEV
9246    I_SYSUIO
9247    HAS_STRUCT_MSGHDR
9248    HAS_STRUCT_CMSGHDR
9249 
9250    HAS_NL_LANGINFO
9251 
9252    HAS_DIRFD
9253 
9254    so that Configure picks them up.
9255 
9256    (KEEP THIS LAST IN perl.h!)
9257 
9258 */
9259 
9260 #endif /* Include guard */
9261 
9262 /*
9263  * ex: set ts=8 sts=4 sw=4 et:
9264  */
9265