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
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.
16 * This file is being used for x2p stuff.
17 * Above symbol is defined via -D in 'x2p/Makefile.SH'
18 * Decouple x2p stuff from some of perls more extreme eccentricities.
23 #endif /* PERL_FOR_X2P */
32 =for apidoc_section $debugging
33 =for apidoc CmnW ||_aDEPTH
34 Some functions when compiled under DEBUGGING take an extra final argument named
35 C<depth>, indicating the C stack depth. This argument is omitted otherwise.
36 This macro expands to either S<C<, depth>> under DEBUGGING, or to nothing at
37 all when not under DEBUGGING, reducing the number of C<#ifdef>'s in the code.
39 The program is responsible for maintaining the correct value for C<depth>.
41 =for apidoc CyW ||_pDEPTH
42 This is used in the prototype declarations for functions that take a L</C<_aDEPTH>>
43 final parameter, much like L<C<pTHX_>|perlguts/Background and MULTIPLICITY>
44 is used in functions that take a thread context initial parameter.
50 # define _pDEPTH ,U32 depth
51 # define _aDEPTH ,depth
57 /* NOTE 1: that with gcc -std=c89 the __STDC_VERSION__ is *not* defined
58 * because the __STDC_VERSION__ became a thing only with C90. Therefore,
59 * with gcc, HAS_C99 will never become true as long as we use -std=c89.
61 * NOTE 2: headers lie. Do not expect that if HAS_C99 gets to be true,
62 * all the C99 features are there and are correct. */
63 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
64 defined(_STDC_C99) || defined(__c99)
68 /* See L<perlguts/"The Perl API"> for detailed notes on
69 * MULTIPLICITY and PERL_IMPLICIT_SYS */
71 /* XXX NOTE that from here --> to <-- the same logic is
72 * repeated in makedef.pl, so be certain to update
73 * both places when editing. */
76 # if !defined(MULTIPLICITY)
81 /* PERL_IMPLICIT_CONTEXT is a legacy synonym for MULTIPLICITY */
83 # ifndef PERL_IMPLICIT_CONTEXT
84 # define PERL_IMPLICIT_CONTEXT
87 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(MULTIPLICITY)
91 /* undef WIN32 when building on Cygwin (for libwin32) - gph */
97 /* Use the reentrant APIs like localtime_r and getpwent_r */
98 /* Win32 has naturally threadsafe libraries, no need to use any _r variants.
99 * XXX KEEP makedef.pl copy of this code in sync */
100 #if defined(USE_ITHREADS) && !defined(USE_REENTRANT_API) && !defined(WIN32)
101 # define USE_REENTRANT_API
104 /* <--- here ends the logic shared by perl.h and makedef.pl */
107 =for apidoc_section $directives
108 =for apidoc AmnUu|void|EXTERN_C
109 When not compiling using C++, expands to nothing.
110 Otherwise is used in a declaration of a function to indicate the function
111 should have external C linkage. This is required for things to work for just
112 about all functions with external linkage compiled into perl.
113 Often, you can use C<L</START_EXTERN_C>> ... C<L</END_EXTERN_C>> blocks
114 surrounding all your code that you need to have this linkage.
118 EXTERN_C int flock(int fd, int op);
120 =for apidoc Amnu||START_EXTERN_C
121 When not compiling using C++, expands to nothing.
122 Otherwise begins a section of code in which every function will effectively
123 have C<L</EXTERN_C>> applied to it, that is to have external C linkage. The
124 section is ended by a C<L</END_EXTERN_C>>.
126 =for apidoc Amnu||END_EXTERN_C
127 When not compiling using C++, expands to nothing.
128 Otherwise ends a section of code already begun by a C<L</START_EXTERN_C>>.
133 #undef START_EXTERN_C
137 # define EXTERN_C extern "C"
138 # define START_EXTERN_C EXTERN_C {
139 # define END_EXTERN_C }
141 # define START_EXTERN_C
142 # define END_EXTERN_C
143 # define EXTERN_C extern
146 /* Fallback definitions in case we don't have definitions from config.h.
147 This should only matter for systems that don't use Configure and
148 haven't been modified to define PERL_STATIC_INLINE yet.
150 #if !defined(PERL_STATIC_INLINE)
151 # ifdef HAS_STATIC_INLINE
152 # define PERL_STATIC_INLINE static inline
154 # define PERL_STATIC_INLINE static
159 =for apidoc_section $concurrency
160 =for apidoc AmU|void|dTHXa|PerlInterpreter * a
161 On threaded perls, set C<pTHX> to C<a>; on unthreaded perls, do nothing
163 =for apidoc AmU|void|dTHXoa|PerlInterpreter * a
164 Now a synonym for C<L</dTHXa>>.
170 # define tTHX PerlInterpreter*
171 # define pTHX tTHX my_perl PERL_UNUSED_DECL
172 # define aTHX my_perl
173 # define aTHXa(a) aTHX = (tTHX)a
174 # define dTHXa(a) pTHX = (tTHX)a
175 # define dTHX pTHX = PERL_GET_THX
188 # if defined(DEBUGGING) && !defined(PERL_TRACK_MEMPOOL)
189 # define PERL_TRACK_MEMPOOL
192 # undef PERL_TRACK_MEMPOOL
196 # define dTHX_DEBUGGING dTHX
198 # define dTHX_DEBUGGING dNOOP
201 #define STATIC static
204 /* Do not use these macros. They were part of PERL_OBJECT, which was an
205 * implementation of multiplicity using C++ objects. They have been left
206 * here solely for the sake of XS code which has incorrectly
209 * The only one Devel::PPPort handles is this; list it as deprecated
211 =for apidoc_section $concurrency
212 =for apidoc AmD|void|CPERLscope|void x
217 # define CPERLscope(x) x
218 # define CPERLarg void
221 # define PERL_OBJECT_THIS
222 # define _PERL_OBJECT_THIS
223 # define PERL_OBJECT_THIS_
224 # define CALL_FPTR(fptr) (*fptr)
225 # define MEMBER_TO_FPTR(name) name
226 #endif /* !PERL_CORE */
228 #define CALLRUNOPS PL_runops
230 #define CALLREGCOMP(sv, flags) Perl_pregcomp(aTHX_ (sv),(flags))
232 #define CALLREGCOMP_ENG(prog, sv, flags) (prog)->comp(aTHX_ sv, flags)
233 #define CALLREGEXEC(prog,stringarg,strend,strbeg,minend,sv,data,flags) \
234 RX_ENGINE(prog)->exec(aTHX_ (prog),(stringarg),(strend), \
235 (strbeg),(minend),(sv),(data),(flags))
236 #define CALLREG_INTUIT_START(prog,sv,strbeg,strpos,strend,flags,data) \
237 RX_ENGINE(prog)->intuit(aTHX_ (prog), (sv), (strbeg), (strpos), \
238 (strend),(flags),(data))
239 #define CALLREG_INTUIT_STRING(prog) \
240 RX_ENGINE(prog)->checkstr(aTHX_ (prog))
242 #define CALLREGFREE(prog) \
243 Perl_pregfree(aTHX_ (prog))
245 #define CALLREGFREE_PVT(prog) \
246 if(prog && RX_ENGINE(prog)) RX_ENGINE(prog)->rxfree(aTHX_ (prog))
248 #define CALLREG_NUMBUF_FETCH(rx,paren,usesv) \
249 RX_ENGINE(rx)->numbered_buff_FETCH(aTHX_ (rx),(paren),(usesv))
251 #define CALLREG_NUMBUF_STORE(rx,paren,value) \
252 RX_ENGINE(rx)->numbered_buff_STORE(aTHX_ (rx),(paren),(value))
254 #define CALLREG_NUMBUF_LENGTH(rx,sv,paren) \
255 RX_ENGINE(rx)->numbered_buff_LENGTH(aTHX_ (rx),(sv),(paren))
257 #define CALLREG_NAMED_BUFF_FETCH(rx, key, flags) \
258 RX_ENGINE(rx)->named_buff(aTHX_ (rx), (key), NULL, ((flags) | RXapif_FETCH))
260 #define CALLREG_NAMED_BUFF_STORE(rx, key, value, flags) \
261 RX_ENGINE(rx)->named_buff(aTHX_ (rx), (key), (value), ((flags) | RXapif_STORE))
263 #define CALLREG_NAMED_BUFF_DELETE(rx, key, flags) \
264 RX_ENGINE(rx)->named_buff(aTHX_ (rx),(key), NULL, ((flags) | RXapif_DELETE))
266 #define CALLREG_NAMED_BUFF_CLEAR(rx, flags) \
267 RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, ((flags) | RXapif_CLEAR))
269 #define CALLREG_NAMED_BUFF_EXISTS(rx, key, flags) \
270 RX_ENGINE(rx)->named_buff(aTHX_ (rx), (key), NULL, ((flags) | RXapif_EXISTS))
272 #define CALLREG_NAMED_BUFF_FIRSTKEY(rx, flags) \
273 RX_ENGINE(rx)->named_buff_iter(aTHX_ (rx), NULL, ((flags) | RXapif_FIRSTKEY))
275 #define CALLREG_NAMED_BUFF_NEXTKEY(rx, lastkey, flags) \
276 RX_ENGINE(rx)->named_buff_iter(aTHX_ (rx), (lastkey), ((flags) | RXapif_NEXTKEY))
278 #define CALLREG_NAMED_BUFF_SCALAR(rx, flags) \
279 RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, ((flags) | RXapif_SCALAR))
281 #define CALLREG_NAMED_BUFF_COUNT(rx) \
282 RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, RXapif_REGNAMES_COUNT)
284 #define CALLREG_NAMED_BUFF_ALL(rx, flags) \
285 RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, flags)
287 #define CALLREG_PACKAGE(rx) \
288 RX_ENGINE(rx)->qr_package(aTHX_ (rx))
290 #if defined(USE_ITHREADS)
291 # define CALLREGDUPE(prog,param) \
292 Perl_re_dup(aTHX_ (prog),(param))
294 # define CALLREGDUPE_PVT(prog,param) \
295 (prog ? RX_ENGINE(prog)->dupe(aTHX_ (prog),(param)) \
299 /* some compilers impersonate gcc */
300 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
301 # define PERL_IS_GCC 1
304 #define PERL_GCC_VERSION_GE(major,minor,patch) \
305 (((100000 * __GNUC__) + (1000 * __GNUC_MINOR__) + __GNUC_PATCHLEVEL__) \
306 >= ((100000 * (major)) + (1000 * (minor)) + (patch)))
307 #define PERL_GCC_VERSION_GT(major,minor,patch) \
308 (((100000 * __GNUC__) + (1000 * __GNUC_MINOR__) + __GNUC_PATCHLEVEL__) \
309 > ((100000 * (major)) + (1000 * (minor)) + (patch)))
310 #define PERL_GCC_VERSION_LE(major,minor,patch) \
311 (((100000 * __GNUC__) + (1000 * __GNUC_MINOR__) + __GNUC_PATCHLEVEL__) \
312 <= ((100000 * (major)) + (1000 * (minor)) + (patch)))
313 #define PERL_GCC_VERSION_LT(major,minor,patch) \
314 (((100000 * __GNUC__) + (1000 * __GNUC_MINOR__) + __GNUC_PATCHLEVEL__) \
315 < ((100000 * (major)) + (1000 * (minor)) + (patch)))
317 /* In case Configure was not used (we are using a "canned config"
318 * such as Win32, or a cross-compilation setup, for example) try going
319 * by the gcc major and minor versions. One useful URL is
320 * http://www.ohse.de/uwe/articles/gcc-attributes.html,
321 * but contrary to this information warn_unused_result seems
322 * not to be in gcc 3.3.5, at least. --jhi
323 * Also, when building extensions with an installed perl, this allows
324 * the user to upgrade gcc and get the right attributes, rather than
325 * relying on the list generated at Configure time. --AD
326 * Set these up now otherwise we get confused when some of the <*thread.h>
327 * includes below indirectly pull in <perlio.h> (which needs to know if we
328 * have HASATTRIBUTE_FORMAT).
332 # if defined __GNUC__ && !defined(__INTEL_COMPILER)
333 # if PERL_GCC_VERSION_GE(3,1,0)
334 # define HASATTRIBUTE_DEPRECATED
336 # if PERL_GCC_VERSION_GE(3,0,0) /* XXX Verify this version */
337 # define HASATTRIBUTE_FORMAT
338 # if defined __MINGW32__
339 # define PRINTF_FORMAT_NULL_OK
342 # if PERL_GCC_VERSION_GE(3,0,0)
343 # define HASATTRIBUTE_MALLOC
345 # if PERL_GCC_VERSION_GE(3,3,0)
346 # define HASATTRIBUTE_NONNULL
348 # if PERL_GCC_VERSION_GE(2,5,0)
349 # define HASATTRIBUTE_NORETURN
351 # if PERL_GCC_VERSION_GE(3,0,0)
352 # define HASATTRIBUTE_PURE
354 # if PERL_GCC_VERSION_GE(3,4,0)
355 # define HASATTRIBUTE_UNUSED
357 # if __GNUC__ == 3 && __GNUC_MINOR__ == 3 && !defined(__cplusplus)
358 # define HASATTRIBUTE_UNUSED /* gcc-3.3, but not g++-3.3. */
360 # if PERL_GCC_VERSION_GE(3,4,0)
361 # define HASATTRIBUTE_WARN_UNUSED_RESULT
363 /* always_inline is buggy in gcc <= 4.6 and causes compilation errors */
364 # if PERL_GCC_VERSION_GE(4,7,0)
365 # define HASATTRIBUTE_ALWAYS_INLINE
367 # if PERL_GCC_VERSION_GE(3,3,0)
368 # define HASATTRIBUTE_VISIBILITY
371 #endif /* #ifndef PERL_MICRO */
373 #ifdef HASATTRIBUTE_DEPRECATED
374 # define __attribute__deprecated__ __attribute__((deprecated))
376 #ifdef HASATTRIBUTE_FORMAT
377 # define __attribute__format__(x,y,z) __attribute__((format(x,y,z)))
379 #ifdef HASATTRIBUTE_MALLOC
380 # define __attribute__malloc__ __attribute__((__malloc__))
382 #ifdef HASATTRIBUTE_NONNULL
383 # define __attribute__nonnull__(a) __attribute__((nonnull(a)))
385 #ifdef HASATTRIBUTE_NORETURN
386 # define __attribute__noreturn__ __attribute__((noreturn))
388 #ifdef HASATTRIBUTE_PURE
389 # define __attribute__pure__ __attribute__((pure))
391 #ifdef HASATTRIBUTE_UNUSED
392 # define __attribute__unused__ __attribute__((unused))
394 #ifdef HASATTRIBUTE_WARN_UNUSED_RESULT
395 # define __attribute__warn_unused_result__ __attribute__((warn_unused_result))
397 #ifdef HASATTRIBUTE_ALWAYS_INLINE
398 /* always_inline is buggy in gcc <= 4.6 and causes compilation errors */
399 # if !defined(PERL_IS_GCC) || PERL_GCC_VERSION_GE(4,7,0)
400 # define __attribute__always_inline__ __attribute__((always_inline))
403 #if defined(HASATTRIBUTE_VISIBILITY) && !defined(_WIN32) && !defined(__CYGWIN__)
404 /* On Windows instead of this, we use __declspec(dllexport) and a .def file
405 * Cygwin works by exporting every global symbol, see the definition of ldflags
406 * near the end of hints/cygwin.sh and the visibility attribute doesn't appear
409 # define __attribute__visibility__(x) __attribute__((visibility(x)))
412 /* If we haven't defined the attributes yet, define them to blank. */
413 #ifndef __attribute__deprecated__
414 # define __attribute__deprecated__
416 #ifndef __attribute__format__
417 # define __attribute__format__(x,y,z)
419 #ifndef __attribute__malloc__
420 # define __attribute__malloc__
422 #ifndef __attribute__nonnull__
423 # define __attribute__nonnull__(a)
425 #ifndef __attribute__noreturn__
426 # define __attribute__noreturn__
428 #ifndef __attribute__pure__
429 # define __attribute__pure__
431 #ifndef __attribute__unused__
432 # define __attribute__unused__
434 #ifndef __attribute__warn_unused_result__
435 # define __attribute__warn_unused_result__
437 #ifndef __attribute__always_inline__
438 # define __attribute__always_inline__
440 #ifndef __attribute__visibility__
441 # define __attribute__visibility__(x)
444 /* Some OS warn on NULL format to printf */
445 #ifdef PRINTF_FORMAT_NULL_OK
446 # define __attribute__format__null_ok__(x,y,z) __attribute__format__(x,y,z)
448 # define __attribute__format__null_ok__(x,y,z)
452 * Because of backward compatibility reasons the PERL_UNUSED_DECL
453 * cannot be changed from postfix to PERL_UNUSED_DECL(x). Sigh.
455 * Note that there are C compilers such as MetroWerks CodeWarrior
456 * which do not have an "inlined" way (like the gcc __attribute__) of
457 * marking unused variables (they need e.g. a #pragma) and therefore
458 * cpp macros like PERL_UNUSED_DECL cannot work for this purpose, even
459 * if it were PERL_UNUSED_DECL(x), which it cannot be (see above).
461 =for apidoc_section $directives
462 =for apidoc AmnU||PERL_UNUSED_DECL
463 Tells the compiler that the parameter in the function prototype just before it
464 is not necessarily expected to be used in the function. Not that many
465 compilers understand this, so this should only be used in cases where
466 C<L</PERL_UNUSED_ARG>> can't conveniently be used.
473 Perl_perly_sighandler(int sig, Siginfo_t *sip PERL_UNUSED_DECL,
474 void *uap PERL_UNUSED_DECL, bool safe)
481 #ifndef PERL_UNUSED_DECL
482 # define PERL_UNUSED_DECL __attribute__unused__
486 * for silencing unused variables that are actually used most of the time,
487 * but we cannot quite get rid of, such as "ax" in PPCODE+noargs xsubs,
488 * or variables/arguments that are used only in certain configurations.
490 =for apidoc Am;||PERL_UNUSED_ARG|void x
491 This is used to suppress compiler warnings that a parameter to a function is
492 not used. This situation can arise, for example, when a parameter is needed
493 under some configuration conditions, but not others, so that C preprocessor
494 conditional compilation causes it be used just some times.
496 =for apidoc Amn;||PERL_UNUSED_CONTEXT
497 This is used to suppress compiler warnings that the thread context parameter to
498 a function is not used. This situation can arise, for example, when a
499 C preprocessor conditional compilation causes it be used just some times.
501 =for apidoc Am;||PERL_UNUSED_VAR|void x
502 This is used to suppress compiler warnings that the variable I<x> is not used.
503 This situation can arise, for example, when a C preprocessor conditional
504 compilation causes it be used just some times.
508 #ifndef PERL_UNUSED_ARG
509 # define PERL_UNUSED_ARG(x) ((void)sizeof(x))
511 #ifndef PERL_UNUSED_VAR
512 # define PERL_UNUSED_VAR(x) ((void)sizeof(x))
515 #if defined(USE_ITHREADS)
516 # define PERL_UNUSED_CONTEXT PERL_UNUSED_ARG(my_perl)
518 # define PERL_UNUSED_CONTEXT
521 /* gcc (-ansi) -pedantic doesn't allow gcc statement expressions,
522 * g++ allows them but seems to have problems with them
523 * (insane errors ensue).
524 * g++ does not give insane errors now (RMB 2008-01-30, gcc 4.2.2).
526 #if defined(PERL_GCC_PEDANTIC) || \
527 (defined(__GNUC__) && defined(__cplusplus) && \
528 (PERL_GCC_VERSION_LT(4,2,0)))
529 # ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN
530 # define PERL_GCC_BRACE_GROUPS_FORBIDDEN
536 =for apidoc Am||PERL_UNUSED_RESULT|void x
538 This macro indicates to discard the return value of the function call inside
541 PERL_UNUSED_RESULT(foo(a, b))
543 The main reason for this is that the combination of C<gcc -Wunused-result>
544 (part of C<-Wall>) and the C<__attribute__((warn_unused_result))> cannot
545 be silenced with casting to C<void>. This causes trouble when the system
546 header files use the attribute.
548 Use C<PERL_UNUSED_RESULT> sparingly, though, since usually the warning
549 is there for a good reason: you might lose success/failure information,
550 or leak resources, or changes in resources.
552 But sometimes you just want to ignore the return value, I<e.g.>, on
553 codepaths soon ending up in abort, or in "best effort" attempts,
554 or in situations where there is no good way to handle failures.
556 Sometimes C<PERL_UNUSED_RESULT> might not be the most natural way:
557 another possibility is that you can capture the return value
558 and use C<L</PERL_UNUSED_VAR>> on that.
562 The __typeof__() is used instead of typeof() since typeof() is not
563 available under strict ISO C, and because of compilers masquerading
564 as gcc (clang and icc), we want exactly the gcc extension
565 __typeof__ and nothing else.
568 #ifndef PERL_UNUSED_RESULT
569 # if defined(__GNUC__) && defined(HASATTRIBUTE_WARN_UNUSED_RESULT)
570 # define PERL_UNUSED_RESULT(v) STMT_START { __typeof__(v) z = (v); (void)sizeof(z); } STMT_END
572 # define PERL_UNUSED_RESULT(v) ((void)(v))
576 /* on gcc (and clang), specify that a warning should be temporarily
579 * GCC_DIAG_IGNORE_DECL(-Wmultichar);
581 * GCC_DIAG_RESTORE_DECL;
583 * based on http://dbp-consulting.com/tutorials/SuppressingGCCWarnings.html
585 * Note that "pragma GCC diagnostic push/pop" was added in GCC 4.6, Mar 2011;
586 * clang only pretends to be GCC 4.2, but still supports push/pop.
588 * Note on usage: all macros must be used at a place where a declaration
589 * or statement can occur, i.e., not in the middle of an expression.
590 * *_DIAG_IGNORE() and *_DIAG_RESTORE can be used in any such place, but
591 * must be used without a following semicolon. *_DIAG_IGNORE_DECL() and
592 * *_DIAG_RESTORE_DECL must be used with a following semicolon, and behave
593 * syntactically as declarations (like dNOOP). *_DIAG_IGNORE_STMT()
594 * and *_DIAG_RESTORE_STMT must be used with a following semicolon,
595 * and behave syntactically as statements (like NOOP).
599 #if defined(__clang__) || defined(__clang) || PERL_GCC_VERSION_GE(4,6,0)
600 # define GCC_DIAG_PRAGMA(x) _Pragma (#x)
601 /* clang has "clang diagnostic" pragmas, but also understands gcc. */
602 # define GCC_DIAG_IGNORE(x) _Pragma("GCC diagnostic push") \
603 GCC_DIAG_PRAGMA(GCC diagnostic ignored #x)
604 # define GCC_DIAG_RESTORE _Pragma("GCC diagnostic pop")
606 # define GCC_DIAG_IGNORE(w)
607 # define GCC_DIAG_RESTORE
609 #define GCC_DIAG_IGNORE_DECL(x) GCC_DIAG_IGNORE(x) dNOOP
610 #define GCC_DIAG_RESTORE_DECL GCC_DIAG_RESTORE dNOOP
611 #define GCC_DIAG_IGNORE_STMT(x) GCC_DIAG_IGNORE(x) NOOP
612 #define GCC_DIAG_RESTORE_STMT GCC_DIAG_RESTORE NOOP
613 /* for clang specific pragmas */
614 #if defined(__clang__) || defined(__clang)
615 # define CLANG_DIAG_PRAGMA(x) _Pragma (#x)
616 # define CLANG_DIAG_IGNORE(x) _Pragma("clang diagnostic push") \
617 CLANG_DIAG_PRAGMA(clang diagnostic ignored #x)
618 # define CLANG_DIAG_RESTORE _Pragma("clang diagnostic pop")
620 # define CLANG_DIAG_IGNORE(w)
621 # define CLANG_DIAG_RESTORE
623 #define CLANG_DIAG_IGNORE_DECL(x) CLANG_DIAG_IGNORE(x) dNOOP
624 #define CLANG_DIAG_RESTORE_DECL CLANG_DIAG_RESTORE dNOOP
625 #define CLANG_DIAG_IGNORE_STMT(x) CLANG_DIAG_IGNORE(x) NOOP
626 #define CLANG_DIAG_RESTORE_STMT CLANG_DIAG_RESTORE NOOP
628 #if defined(_MSC_VER)
629 # define MSVC_DIAG_IGNORE(x) __pragma(warning(push)) \
630 __pragma(warning(disable : x))
631 # define MSVC_DIAG_RESTORE __pragma(warning(pop))
633 # define MSVC_DIAG_IGNORE(x)
634 # define MSVC_DIAG_RESTORE
636 #define MSVC_DIAG_IGNORE_DECL(x) MSVC_DIAG_IGNORE(x) dNOOP
637 #define MSVC_DIAG_RESTORE_DECL MSVC_DIAG_RESTORE dNOOP
638 #define MSVC_DIAG_IGNORE_STMT(x) MSVC_DIAG_IGNORE(x) NOOP
639 #define MSVC_DIAG_RESTORE_STMT MSVC_DIAG_RESTORE NOOP
642 =for apidoc Amn;||NOOP
643 Do nothing; typically used as a placeholder to replace something that used to
646 =for apidoc Amn;||dNOOP
647 Declare nothing; typically used as a placeholder to replace something that used
648 to declare something. Works on compilers that require declarations before any
653 #define NOOP /*EMPTY*/(void)0
654 #define dNOOP struct Perl___notused_struct
657 /* Don't bother defining tTHX ; using it outside
658 * code guarded by MULTIPLICITY is an error.
664 # define aTHXa(a) NOOP
665 # define dTHXa(a) dNOOP
680 =for apidoc_section $concurrency
681 =for apidoc AmnU||dVAR
682 This is now a synonym for dNOOP: declare nothing
684 =for apidoc_section $XS
685 =for apidoc Amn;||dMY_CXT_SV
686 Now a placeholder that declares nothing
692 /* Backwards compatibility macro for XS code. It used to be part of the
693 * PERL_GLOBAL_STRUCT(_PRIVATE) feature, which no longer exists */
696 /* these are only defined for compatibility; should not be used internally.
698 # define dMY_CXT_SV dNOOP
701 # define pTHXo_ pTHX_
703 # define aTHXo_ aTHX_
705 # define dTHXoa(x) dTHXa(x)
710 # define pTHXx PerlInterpreter *my_perl
711 # define pTHXx_ pTHXx,
712 # define aTHXx my_perl
713 # define aTHXx_ aTHXx,
717 /* Under PERL_IMPLICIT_SYS (used in Windows for fork emulation)
718 * PerlIO_foo() expands to PL_StdIO->pFOO(PL_StdIO, ...).
719 * dTHXs is therefore needed for all functions using PerlIO_foo(). */
720 #ifdef PERL_IMPLICIT_SYS
726 #if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__cplusplus)
727 # ifndef PERL_USE_GCC_BRACE_GROUPS
728 # define PERL_USE_GCC_BRACE_GROUPS
733 =for apidoc_section $directives
734 =for apidoc AmnUu|void|STMT_END
735 =for apidoc_item | |STMT_START
737 These allow a series of statements in a macro to be used as a single statement,
740 if (x) STMT_START { ... } STMT_END else ...
742 Note that you can't return a value out of this construct and cannot use it as
743 an operand to the comma operator, which limit its utility. If you need
744 those features, instead use C language C<static inline> functions.
745 But those won't work where the types of the inputs can vary depending on where
746 called from; you'd have to create a separate function for each combination of
749 Subtle bugs can occur due to this being a macro with names evaluated in
750 the context of the caller, unlike a function. These bugs can be eliminated by
751 treating this more like a function. This means that you must only use
752 variables inside it that are either formal parameters or are declared
753 internally within the construct. Thus
759 B<All> references to outside-the-construct variables must be through formal
764 All formal parameters should be used only once. If a value needs to be used in
765 more than one place, instead declare a variable internally, initialized with
766 the formal parameter. Then use that internal variable freely. For example
768 #define warn_if_odd(n) \
773 my_warn(aTHX_ "%d is odd\n", n_); \
777 This prevents issues when the macro is called with a parameter with side
780 Note that the internal variable must have a different name than the formal
781 parameter one. Using a trailing underscore is legal in C, and unobtrusive.
782 C<But> see below for why you should choose a different naming convention if
783 there are multiple parameters.
787 If there are multiple formal parameters, the names of the internal copies need
788 to be something that won't clash with any names outside the macro. This
789 prevents subtle bugs when the caller uses one parameter in terms of another.
791 #define my_best_shot(a, b) \
793 UV my_best_shot_a = a; \
794 UV my_best_shot_b = b; \
802 my_best_shot(a + b + ix, a - b - ix);
804 Without the declarations, the macro call at the end of the example would be
807 This example uses the macro name as part of each variable name that corresponds
808 to a formal parameter. If this convention is followed everywhere, there is no
809 possibility of name collisions.
811 Note that the C<ix> within the construct doesn't interfere with the outside
812 C<ix>, but only because we have declared and initialized variables that are
813 copies of all the formal parameters.
815 Also note that if you forget and use plain C<a> or C<b> in some places, things
816 may well compile, and have subtle run-time bugs.
818 For a concrete example, see L<https://perlmonks.org/?node_id=11144355>.
822 Pass in the type for any declarations if it isn't known at macro definition
823 time. Suppose that the parameters to C<my_best_shot> in the example above
824 didn't have to be UV. This can be handled by changing the signature, something
827 #define my_best_shot(a, a_type, b, b_type) STMT_START { \
829 a_type my_best_shot_a = a; \
830 b_type my_best_shot_b = b; \
838 my_best_shot(a + b + ix, int, a - b - ix, long);
840 You are out of luck if the signature can't be changed to include the types.
841 Best then is to document that the macro cannot safely be called with parameters
842 with side effects. And any internally-declared variables should have names
843 that won't clash with any outside names. C<ix> should then be
844 C<my_best_shot_ix>, for example.
848 =for apidoc_section $genconfig
849 =for apidoc Amn#||PERL_USE_GCC_BRACE_GROUPS
851 This C pre-processor value, if defined, indicates that it is permissible to use
852 the GCC brace groups extension. However, use of this extension is DISCOURAGED.
853 Use a C<static inline> function instead.
855 The extension, of the form
859 turns the block consisting of I<statement ...> into an expression with a
860 value, unlike plain C language blocks. This can present optimization
861 possibilities, B<BUT>, unless you know for sure that this will never be
862 compiled without this extension being available and not forbidden, you need to
863 specify an alternative. Thus two code paths have to be maintained, which can
864 get out-of-sync. All these issues are solved by using a C<static inline>
867 Perl can be configured to not use this feature by passing the parameter
868 C<-Accflags=-DPERL_GCC_BRACE_GROUPS_FORBIDDEN> to F<Configure>.
870 =for apidoc Amnh#||PERL_GCC_BRACE_GROUPS_FORBIDDEN
876 #ifdef PERL_USE_GCC_BRACE_GROUPS
886 Trying to select a version that gives no warnings...
888 #if !(defined(STMT_START) && defined(STMT_END))
889 # define STMT_START do
890 # define STMT_END while (0)
893 #ifndef BYTEORDER /* Should never happen -- byteorder is in config.h */
894 # define BYTEORDER 0x1234
898 =for apidoc_section $genconfig
899 =for apidoc Amn#||ASCIIish
901 A preprocessor symbol that is defined iff the system is an ASCII platform; this
902 symbol would not be defined on C<L</EBCDIC>> platforms.
906 #if 'A' == 65 && 'I' == 73 && 'J' == 74 && 'Z' == 90
913 * The following contortions are brought to you on behalf of all the
914 * standards, semi-standards, de facto standards, not-so-de-facto standards
915 * of the world, as well as all the other botches anyone ever thought of.
916 * The basic theory is that if we work hard enough here, the rest of the
917 * code can be a lot prettier. Well, so much for theory. Sorry, Henry...
920 /* define this once if either system, instead of cluttering up the src */
925 /* These exist only for back-compat with XS modules. */
928 #define CAN_PROTOTYPE
935 /* By compiling a perl with -DNO_TAINT_SUPPORT or -DSILENT_NO_TAINT_SUPPORT,
936 * you get a perl without taint support, but doubtlessly with a lesser
937 * degree of support. Do not do so unless you know exactly what it means
938 * technically, have a good reason to do so, and know exactly how the
939 * perl will be used. perls with -DSILENT_NO_TAINT_SUPPORT are considered
940 * a potential security risk due to flat out ignoring the security-relevant
941 * taint flags. This being said, a perl without taint support compiled in
942 * has marginal run-time performance benefits.
943 * SILENT_NO_TAINT_SUPPORT implies NO_TAINT_SUPPORT.
944 * SILENT_NO_TAINT_SUPPORT is the same as NO_TAINT_SUPPORT except it
945 * silently ignores -t/-T instead of throwing an exception.
947 * DANGER! Using NO_TAINT_SUPPORT or SILENT_NO_TAINT_SUPPORT
948 * voids your nonexistent warranty!
950 #if defined(SILENT_NO_TAINT_SUPPORT) && !defined(NO_TAINT_SUPPORT)
951 # define NO_TAINT_SUPPORT 1
954 /* NO_TAINT_SUPPORT can be set to transform virtually all taint-related
955 * operations into no-ops for a very modest speed-up. Enable only if you
956 * know what you're doing: tests and CPAN modules' tests are bound to fail.
958 #ifdef NO_TAINT_SUPPORT
960 # define TAINT_NOT NOOP
961 # define TAINT_IF(c) NOOP
962 # define TAINT_ENV() NOOP
963 # define TAINT_PROPER(s) NOOP
964 # define TAINT_set(s) NOOP
966 # define TAINTING_get 0
967 # define TAINTING_set(s) NOOP
968 # define TAINT_WARN_get 0
969 # define TAINT_WARN_set(s) NOOP
973 =for apidoc_section $tainting
974 =for apidoc Cm|void|TAINT
976 If we aren't in taint checking mode, do nothing;
977 otherwise indicate to L</C<TAINT_set>> and L</C<TAINT_PROPER>> that some
978 unspecified element is tainted.
980 =for apidoc Cm|void|TAINT_NOT
982 Remove any taintedness previously set by, I<e.g.>, C<TAINT>.
984 =for apidoc Cm|void|TAINT_IF|bool c
986 If C<c> evaluates to true, call L</C<TAINT>> to indicate that something is
987 tainted; otherwise do nothing.
989 =for apidoc Cmn|void|TAINT_ENV
991 Looks at several components of L<C<%ENV>|perlvar/%ENV> for taintedness, and
992 calls L</C<taint_proper>> if any are tainted. The components it searches are
993 things like C<$PATH>.
995 =for apidoc Cm|void|TAINT_PROPER|const char * s
997 If no element is tainted, do nothing;
998 otherwise output a message (containing C<s>) that indicates there is a
999 tainting violation. If such violations are fatal, it croaks.
1001 =for apidoc Cm|void|TAINT_set|bool s
1003 If C<s> is true, L</C<TAINT_get>> returns true;
1004 If C<s> is false, L</C<TAINT_get>> returns false;
1006 =for apidoc Cm|bool|TAINT_get
1008 Returns a boolean as to whether some element is tainted or not.
1010 =for apidoc Cm|bool|TAINTING_get
1012 Returns a boolean as to whether taint checking is enabled or not.
1014 =for apidoc Cm|void|TAINTING_set|bool s
1016 Turn taint checking mode off/on
1018 =for apidoc Cm|bool|TAINT_WARN_get
1020 Returns false if tainting violations are fatal;
1021 Returns true if they're just warnings
1023 =for apidoc Cm|void|TAINT_WARN_set|bool s
1025 C<s> being true indicates L</C<TAINT_WARN_get>> should return that tainting
1026 violations are just warnings
1028 C<s> being false indicates L</C<TAINT_WARN_get>> should return that tainting
1029 violations are fatal.
1033 /* Set to tainted if we are running under tainting mode */
1034 # define TAINT (PL_tainted = PL_tainting)
1036 # define TAINT_NOT (PL_tainted = FALSE) /* Untaint */
1037 # define TAINT_IF(c) if (UNLIKELY(c)) { TAINT; } /* Conditionally taint */
1038 # define TAINT_ENV() if (UNLIKELY(PL_tainting)) { taint_env(); }
1039 /* croak or warn if tainting */
1040 # define TAINT_PROPER(s) if (UNLIKELY(PL_tainting)) { \
1041 taint_proper(NULL, s); \
1043 # define TAINT_set(s) (PL_tainted = cBOOL(s))
1044 # define TAINT_get (cBOOL(UNLIKELY(PL_tainted))) /* Is something tainted? */
1045 # define TAINTING_get (cBOOL(UNLIKELY(PL_tainting)))
1046 # define TAINTING_set(s) (PL_tainting = cBOOL(s))
1047 # define TAINT_WARN_get (PL_taint_warn)
1048 # define TAINT_WARN_set(s) (PL_taint_warn = cBOOL(s))
1051 /* flags used internally only within pp_subst and pp_substcont */
1053 # define SUBST_TAINT_STR 1 /* string tainted */
1054 # define SUBST_TAINT_PAT 2 /* pattern tainted */
1055 # define SUBST_TAINT_REPL 4 /* replacement tainted */
1056 # define SUBST_TAINT_RETAINT 8 /* use re'taint' in scope */
1057 # define SUBST_TAINT_BOOLRET 16 /* return is boolean (don't taint) */
1060 /* XXX All process group stuff is handled in pp_sys.c. Should these
1061 defines move there? If so, I could simplify this a lot. --AD 9/96.
1063 /* Process group stuff changed from traditional BSD to POSIX.
1064 perlfunc.pod documents the traditional BSD-style syntax, so we'll
1065 try to preserve that, if possible.
1068 # define BSD_SETPGRP(pid, pgrp) setpgid((pid), (pgrp))
1069 #elif defined(HAS_SETPGRP) && defined(USE_BSD_SETPGRP)
1070 # define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp))
1071 #elif defined(HAS_SETPGRP2)
1072 # define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp))
1074 #if defined(BSD_SETPGRP) && !defined(HAS_SETPGRP)
1075 # define HAS_SETPGRP /* Well, effectively it does . . . */
1078 /* getpgid isn't POSIX, but at least Solaris and Linux have it, and it makes
1079 our life easier :-) so we'll try it.
1082 # define BSD_GETPGRP(pid) getpgid((pid))
1083 #elif defined(HAS_GETPGRP) && defined(USE_BSD_GETPGRP)
1084 # define BSD_GETPGRP(pid) getpgrp((pid))
1085 #elif defined(HAS_GETPGRP2)
1086 # define BSD_GETPGRP(pid) getpgrp2((pid))
1088 #if defined(BSD_GETPGRP) && !defined(HAS_GETPGRP)
1089 # define HAS_GETPGRP /* Well, effectively it does . . . */
1092 /* These are not exact synonyms, since setpgrp() and getpgrp() may
1093 have different behaviors, but perl.h used to define USE_BSDPGRP
1094 (prior to 5.003_05) so some extension might depend on it.
1096 #if defined(USE_BSD_SETPGRP) || defined(USE_BSD_GETPGRP)
1097 # ifndef USE_BSDPGRP
1098 # define USE_BSDPGRP
1102 /* This define exists only for compatibility. It used to mean "my_setenv and
1103 * friends should use setenv/putenv, instead of manipulating environ directly",
1104 * which is now always the case. It's still defined to prevent XS modules from
1105 * using the no longer existing PL_use_safe_putenv variable.
1107 #define PERL_USE_SAFE_PUTENV
1109 /* HP-UX 10.X CMA (Common Multithreaded Architecture) insists that
1110 pthread.h must be included before all other header files.
1112 #if defined(USE_ITHREADS) && defined(PTHREAD_H_FIRST) && defined(I_PTHREAD)
1113 # include <pthread.h>
1116 #include <sys/types.h>
1122 # include <stdarg.h>
1125 # include <stdint.h>
1132 #ifdef METHOD /* Defined by OSF/1 v3.0 by ctype.h */
1141 # include <locale.h>
1144 #ifdef NEED_XLOCALE_H
1145 # include <xlocale.h>
1148 /* If not forbidden, we enable locale handling if either 1) the POSIX 2008
1149 * functions are available, or 2) just the setlocale() function. This logic is
1150 * repeated in t/loc_tools.pl and makedef.pl; The three should be kept in
1152 #if ! defined(NO_LOCALE)
1154 # if ! defined(NO_POSIX_2008_LOCALE) \
1155 && defined(HAS_NEWLOCALE) \
1156 && defined(HAS_USELOCALE) \
1157 && defined(HAS_DUPLOCALE) \
1158 && defined(HAS_FREELOCALE) \
1159 && defined(LC_ALL_MASK)
1161 /* For simplicity, the code is written to assume that any platform advanced
1162 * enough to have the Posix 2008 locale functions has LC_ALL. The final
1163 * test above makes sure that assumption is valid */
1165 # define HAS_POSIX_2008_LOCALE
1167 # elif defined(HAS_SETLOCALE)
1173 # define HAS_SKIP_LOCALE_INIT /* Solely for XS code to test for this
1175 # if !defined(NO_LOCALE_COLLATE) && defined(LC_COLLATE) \
1176 && defined(HAS_STRXFRM)
1177 # define USE_LOCALE_COLLATE
1179 # if !defined(NO_LOCALE_CTYPE) && defined(LC_CTYPE)
1180 # define USE_LOCALE_CTYPE
1182 # if !defined(NO_LOCALE_NUMERIC) && defined(LC_NUMERIC)
1183 # define USE_LOCALE_NUMERIC
1185 # if !defined(NO_LOCALE_MESSAGES) && defined(LC_MESSAGES)
1186 # define USE_LOCALE_MESSAGES
1188 # if !defined(NO_LOCALE_MONETARY) && defined(LC_MONETARY)
1189 # define USE_LOCALE_MONETARY
1191 # if !defined(NO_LOCALE_TIME) && defined(LC_TIME)
1192 # define USE_LOCALE_TIME
1194 # if !defined(NO_LOCALE_ADDRESS) && defined(LC_ADDRESS)
1195 # define USE_LOCALE_ADDRESS
1197 # if !defined(NO_LOCALE_IDENTIFICATION) && defined(LC_IDENTIFICATION)
1198 # define USE_LOCALE_IDENTIFICATION
1200 # if !defined(NO_LOCALE_MEASUREMENT) && defined(LC_MEASUREMENT)
1201 # define USE_LOCALE_MEASUREMENT
1203 # if !defined(NO_LOCALE_PAPER) && defined(LC_PAPER)
1204 # define USE_LOCALE_PAPER
1206 # if !defined(NO_LOCALE_TELEPHONE) && defined(LC_TELEPHONE)
1207 # define USE_LOCALE_TELEPHONE
1209 # if !defined(NO_LOCALE_SYNTAX) && defined(LC_SYNTAX)
1210 # define USE_LOCALE_SYNTAX
1212 # if !defined(NO_LOCALE_TOD) && defined(LC_TOD)
1213 # define USE_LOCALE_TOD
1216 /* Now create LC_foo_INDEX_ #defines for just those categories on this system */
1217 # ifdef USE_LOCALE_CTYPE
1218 # define LC_CTYPE_INDEX_ 0
1219 # define PERL_DUMMY_CTYPE_ LC_CTYPE_INDEX_
1221 # define PERL_DUMMY_CTYPE_ -1
1223 # ifdef USE_LOCALE_NUMERIC
1224 # define LC_NUMERIC_INDEX_ PERL_DUMMY_CTYPE_ + 1
1225 # define PERL_DUMMY_NUMERIC_ LC_NUMERIC_INDEX_
1227 # define PERL_DUMMY_NUMERIC_ PERL_DUMMY_CTYPE_
1229 # ifdef USE_LOCALE_COLLATE
1230 # define LC_COLLATE_INDEX_ PERL_DUMMY_NUMERIC_ + 1
1231 # define PERL_DUMMY_COLLATE_ LC_COLLATE_INDEX_
1233 # define PERL_DUMMY_COLLATE_ PERL_DUMMY_NUMERIC_
1235 # ifdef USE_LOCALE_TIME
1236 # define LC_TIME_INDEX_ PERL_DUMMY_COLLATE_ + 1
1237 # define PERL_DUMMY_TIME_ LC_TIME_INDEX_
1239 # define PERL_DUMMY_TIME_ PERL_DUMMY_COLLATE_
1241 # ifdef USE_LOCALE_MESSAGES
1242 # define LC_MESSAGES_INDEX_ PERL_DUMMY_TIME_ + 1
1243 # define PERL_DUMMY_MESSAGES_ LC_MESSAGES_INDEX_
1245 # define PERL_DUMMY_MESSAGES_ PERL_DUMMY_TIME_
1247 # ifdef USE_LOCALE_MONETARY
1248 # define LC_MONETARY_INDEX_ PERL_DUMMY_MESSAGES_ + 1
1249 # define PERL_DUMMY_MONETARY_ LC_MONETARY_INDEX_
1251 # define PERL_DUMMY_MONETARY_ PERL_DUMMY_MESSAGES_
1253 # ifdef USE_LOCALE_ADDRESS
1254 # define LC_ADDRESS_INDEX_ PERL_DUMMY_MONETARY_ + 1
1255 # define PERL_DUMMY_ADDRESS_ LC_ADDRESS_INDEX_
1257 # define PERL_DUMMY_ADDRESS_ PERL_DUMMY_MONETARY_
1259 # ifdef USE_LOCALE_IDENTIFICATION
1260 # define LC_IDENTIFICATION_INDEX_ PERL_DUMMY_ADDRESS_ + 1
1261 # define PERL_DUMMY_IDENTIFICATION_ LC_IDENTIFICATION_INDEX_
1263 # define PERL_DUMMY_IDENTIFICATION_ PERL_DUMMY_ADDRESS_
1265 # ifdef USE_LOCALE_MEASUREMENT
1266 # define LC_MEASUREMENT_INDEX_ PERL_DUMMY_IDENTIFICATION_ + 1
1267 # define PERL_DUMMY_MEASUREMENT_ LC_MEASUREMENT_INDEX_
1269 # define PERL_DUMMY_MEASUREMENT_ PERL_DUMMY_IDENTIFICATION_
1271 # ifdef USE_LOCALE_PAPER
1272 # define LC_PAPER_INDEX_ PERL_DUMMY_MEASUREMENT_ + 1
1273 # define PERL_DUMMY_PAPER_ LC_PAPER_INDEX_
1275 # define PERL_DUMMY_PAPER_ PERL_DUMMY_MEASUREMENT_
1277 # ifdef USE_LOCALE_TELEPHONE
1278 # define LC_TELEPHONE_INDEX_ PERL_DUMMY_PAPER_ + 1
1279 # define PERL_DUMMY_TELEPHONE_ LC_TELEPHONE_INDEX_
1281 # define PERL_DUMMY_TELEPHONE_ PERL_DUMMY_PAPER_
1283 # ifdef USE_LOCALE_SYNTAX
1284 # define LC_SYNTAX_INDEX_ PERL_DUMMY_TELEPHONE_ + 1
1285 # define PERL_DUMMY_SYNTAX_ LC_SYNTAX_INDEX_
1287 # define PERL_DUMMY_SYNTAX_ PERL_DUMMY_TELEPHONE_
1289 # ifdef USE_LOCALE_TOD
1290 # define LC_TOD_INDEX_ PERL_DUMMY_SYNTAX_ + 1
1291 # define PERL_DUMMY_TOD_ LC_TOD_INDEX_
1293 # define PERL_DUMMY_TOD_ PERL_DUMMY_SYNTAX_
1296 # define LC_ALL_INDEX_ PERL_DUMMY_TOD_ + 1
1299 /* XXX The next few defines are unfortunately duplicated in makedef.pl, and
1300 * changes here MUST also be made there */
1302 # if defined(USE_ITHREADS) && ! defined(NO_LOCALE_THREADS)
1303 # define USE_LOCALE_THREADS
1305 # if ! defined(HAS_SETLOCALE) && defined(HAS_POSIX_2008_LOCALE)
1306 # define USE_POSIX_2008_LOCALE
1307 # ifndef USE_THREAD_SAFE_LOCALE
1308 # define USE_THREAD_SAFE_LOCALE
1311 * -DUSE_THREAD_SAFE_LOCALE, will do so even
1312 * on unthreaded builds */
1313 # elif (defined(USE_LOCALE_THREADS) || defined(USE_THREAD_SAFE_LOCALE)) \
1314 && ( defined(HAS_POSIX_2008_LOCALE) \
1315 || (defined(WIN32) && defined(_MSC_VER))) \
1316 && ! defined(NO_THREAD_SAFE_LOCALE)
1317 # ifndef USE_THREAD_SAFE_LOCALE
1318 # define USE_THREAD_SAFE_LOCALE
1320 # ifdef HAS_POSIX_2008_LOCALE
1321 # define USE_POSIX_2008_LOCALE
1325 /* Allow use of glib's undocumented querylocale() equivalent if asked for, and
1327 # ifdef USE_POSIX_2008_LOCALE
1328 # if defined(HAS_QUERYLOCALE) \
1329 /* Has this internal undocumented item for nl_langinfo() */ \
1330 || ( defined(_NL_LOCALE_NAME) \
1331 /* And asked for */ \
1332 && defined(USE_NL_LOCALE_NAME) \
1333 /* We need the below because we will be calling it within a \
1334 * macro, can't have it get messed up by another thread. */ \
1335 && defined(HAS_THREAD_SAFE_NL_LANGINFO_L) \
1336 /* On systems that accept any locale name, the real \
1337 * underlying locale is often returned by this internal \
1338 * item, so we can't use it */ \
1339 && ! defined(SETLOCALE_ACCEPTS_ANY_LOCALE_NAME))
1340 # define USE_QUERYLOCALE
1344 /* Microsoft documentation reads in the change log for VS 2015:
1345 * "The localeconv function declared in locale.h now works correctly when
1346 * per-thread locale is enabled. In previous versions of the library, this
1347 * function would return the lconv data for the global locale, not the
1350 # if defined(WIN32) && defined(USE_THREAD_SAFE_LOCALE) && _MSC_VER < 1900
1351 # define TS_W32_BROKEN_LOCALECONV
1357 /* Both typedefs are used in locale.c only, but defined here so that embed.fnc
1358 * can generate the proper prototypes. */
1364 /* Used in tight loops through all sub-categories, where LC_ALL won't be
1365 * fully known until all subcategories are handled. */
1366 RECALCULATE_LC_ALL_ON_FINAL_INTERATION
1370 typedef enum { /* Is the locale UTF8? */
1373 LOCALE_UTF8NESS_UNKNOWN
1374 } locale_utf8ness_t;
1381 # ifdef PARAM_NEEDS_TYPES
1382 # include <sys/types.h>
1384 # include <sys/param.h>
1387 /* On BSD-derived systems, <sys/param.h> defines BSD to a year-month
1388 value something like 199306. This may be useful if no more-specific
1389 feature test is available.
1397 /* Use all the "standard" definitions */
1400 /* If this causes problems, set i_unistd=undef in the hint file. */
1402 # if defined(__amigaos4__)
1403 # ifdef I_NETINET_IN
1404 # include <netinet/in.h>
1407 # include <unistd.h>
1408 # if defined(__amigaos4__)
1409 /* Under AmigaOS 4 newlib.library provides an environ. However using
1410 * it doesn't give us enough control over inheritance of variables by
1411 * subshells etc. so replace with custom version based on abc-shell
1413 extern char **myenviron;
1415 # define environ myenviron
1421 # include <sys/wait.h>
1424 #if defined(HAS_SYSCALL) && !defined(HAS_SYSCALL_PROTO)
1425 EXTERN_C int syscall(int, ...);
1428 #if defined(HAS_USLEEP) && !defined(HAS_USLEEP_PROTO)
1429 EXTERN_C int usleep(unsigned int);
1432 /* Macros for correct constant construction. These are in C99 <stdint.h>
1433 * (so they will not be available in strict C89 mode), but they are nice, so
1434 * let's define them if necessary.
1435 =for apidoc_section $integer
1436 =for apidoc Am|I16|INT16_C|number
1437 =for apidoc_item |I32|INT32_C|number
1438 =for apidoc_item |I64|INT64_C|number
1440 Returns a token the C compiler recognizes for the constant C<number> of the
1441 corresponding integer type on the machine.
1443 If the machine does not have a 64-bit type, C<INT64_C> is undefined.
1444 Use C<L</INTMAX_C>> to get the largest type available on the platform.
1446 =for apidoc Am|U16|UINT16_C|number
1447 =for apidoc_item |U32|UINT32_C|number
1448 =for apidoc_item |U64|UINT64_C|number
1450 Returns a token the C compiler recognizes for the constant C<number> of the
1451 corresponding unsigned integer type on the machine.
1453 If the machine does not have a 64-bit type, C<UINT64_C> is undefined.
1454 Use C<L</UINTMAX_C>> to get the largest type available on the platform.
1461 # define UINT16_C(x) ((U16_TYPE)x##U)
1463 # define UINT16_C(x) ((U16_TYPE)x##UL)
1469 # define UINT32_C(x) ((U32_TYPE)x##U)
1471 # define UINT32_C(x) ((U32_TYPE)x##UL)
1476 typedef intmax_t PERL_INTMAX_T;
1477 typedef uintmax_t PERL_UINTMAX_T;
1480 /* N.B. We use QUADKIND here instead of HAS_QUAD here, because that doesn't
1481 * actually mean what it has always been documented to mean (see RT #119753)
1482 * and is explicitly turned off outside of core with dire warnings about
1483 * removing the undef. */
1485 #if defined(QUADKIND)
1486 # undef PeRl_INT64_C
1487 # undef PeRl_UINT64_C
1488 /* Prefer the native integer types (int and long) over long long
1489 * (which is not C89) and Win32-specific __int64. */
1490 # if QUADKIND == QUAD_IS_INT && INTSIZE == 8
1491 # define PeRl_INT64_C(c) (c)
1492 # define PeRl_UINT64_C(c) CAT2(c,U)
1494 # if QUADKIND == QUAD_IS_LONG && LONGSIZE == 8
1495 # define PeRl_INT64_C(c) CAT2(c,L)
1496 # define PeRl_UINT64_C(c) CAT2(c,UL)
1498 # if QUADKIND == QUAD_IS_LONG_LONG && defined(HAS_LONG_LONG)
1499 # define PeRl_INT64_C(c) CAT2(c,LL)
1500 # define PeRl_UINT64_C(c) CAT2(c,ULL)
1502 # if QUADKIND == QUAD_IS___INT64
1503 # define PeRl_INT64_C(c) CAT2(c,I64)
1504 # define PeRl_UINT64_C(c) CAT2(c,UI64)
1506 # ifndef PeRl_INT64_C
1507 # define PeRl_INT64_C(c) ((I64)(c)) /* last resort */
1508 # define PeRl_UINT64_C(c) ((U64TYPE)(c))
1510 /* In OS X the INT64_C/UINT64_C are defined with LL/ULL, which will
1511 * not fly with C89-pedantic gcc, so let's undefine them first so that
1512 * we can redefine them with our native integer preferring versions. */
1513 # if defined(PERL_DARWIN) && defined(PERL_GCC_PEDANTIC)
1518 # define INT64_C(c) PeRl_INT64_C(c)
1521 # define UINT64_C(c) PeRl_UINT64_C(c)
1525 =for apidoc_section $integer
1526 =for apidoc Am||INTMAX_C|number
1527 Returns a token the C compiler recognizes for the constant C<number> of the
1528 widest integer type on the machine. For example, if the machine has C<long
1529 long>s, C<INTMAX_C(-1)> would yield
1533 See also, for example, C<L</INT32_C>>.
1535 Use L</IV> to declare variables of the maximum usable size on this platform.
1537 =for apidoc Am||UINTMAX_C|number
1538 Returns a token the C compiler recognizes for the constant C<number> of the
1539 widest unsigned integer type on the machine. For example, if the machine has
1540 C<long>s, C<UINTMAX_C(1)> would yield
1544 See also, for example, C<L</UINT32_C>>.
1546 Use L</UV> to declare variables of the maximum usable size on this platform.
1552 typedef I64TYPE PERL_INTMAX_T;
1553 typedef U64TYPE PERL_UINTMAX_T;
1556 # define INTMAX_C(c) INT64_C(c)
1559 # define UINTMAX_C(c) UINT64_C(c)
1562 #else /* below QUADKIND is undefined */
1564 /* Perl doesn't work on 16 bit systems, so must be 32 bit */
1566 typedef I32TYPE PERL_INTMAX_T;
1567 typedef U32TYPE PERL_UINTMAX_T;
1570 # define INTMAX_C(c) INT32_C(c)
1573 # define UINTMAX_C(c) UINT32_C(c)
1576 #endif /* no QUADKIND */
1580 /* byte-swapping functions for big-/little-endian conversion */
1581 # define _swab_16_(x) ((U16)( \
1582 (((U16)(x) & UINT16_C(0x00ff)) << 8) | \
1583 (((U16)(x) & UINT16_C(0xff00)) >> 8) ))
1585 # define _swab_32_(x) ((U32)( \
1586 (((U32)(x) & UINT32_C(0x000000ff)) << 24) | \
1587 (((U32)(x) & UINT32_C(0x0000ff00)) << 8) | \
1588 (((U32)(x) & UINT32_C(0x00ff0000)) >> 8) | \
1589 (((U32)(x) & UINT32_C(0xff000000)) >> 24) ))
1592 # define _swab_64_(x) ((U64)( \
1593 (((U64)(x) & UINT64_C(0x00000000000000ff)) << 56) | \
1594 (((U64)(x) & UINT64_C(0x000000000000ff00)) << 40) | \
1595 (((U64)(x) & UINT64_C(0x0000000000ff0000)) << 24) | \
1596 (((U64)(x) & UINT64_C(0x00000000ff000000)) << 8) | \
1597 (((U64)(x) & UINT64_C(0x000000ff00000000)) >> 8) | \
1598 (((U64)(x) & UINT64_C(0x0000ff0000000000)) >> 24) | \
1599 (((U64)(x) & UINT64_C(0x00ff000000000000)) >> 40) | \
1600 (((U64)(x) & UINT64_C(0xff00000000000000)) >> 56) ))
1603 /* Maximum level of recursion */
1604 #ifndef PERL_SUB_DEPTH_WARN
1605 #define PERL_SUB_DEPTH_WARN 100
1608 #endif /* PERL_CORE */
1610 /* Maximum number of args that may be passed to an OP_MULTICONCAT op.
1611 * It determines the size of local arrays in S_maybe_multiconcat() and
1614 #define PERL_MULTICONCAT_MAXARG 64
1616 /* The indexes of fields of a multiconcat aux struct.
1617 * The fixed fields are followed by nargs+1 const segment lengths,
1618 * and if utf8 and non-utf8 differ, a second nargs+1 set for utf8.
1621 #define PERL_MULTICONCAT_IX_NARGS 0 /* number of arguments */
1622 #define PERL_MULTICONCAT_IX_PLAIN_PV 1 /* non-utf8 constant string */
1623 #define PERL_MULTICONCAT_IX_PLAIN_LEN 2 /* non-utf8 constant string length */
1624 #define PERL_MULTICONCAT_IX_UTF8_PV 3 /* utf8 constant string */
1625 #define PERL_MULTICONCAT_IX_UTF8_LEN 4 /* utf8 constant string length */
1626 #define PERL_MULTICONCAT_IX_LENGTHS 5 /* first of nargs+1 const segment lens */
1627 #define PERL_MULTICONCAT_HEADER_SIZE 5 /* The number of fields of a
1628 multiconcat header */
1630 /* We no longer default to creating a new SV for GvSV.
1631 Do this before embed. */
1632 #ifndef PERL_CREATE_GVSV
1633 # ifndef PERL_DONT_CREATE_GVSV
1634 # define PERL_DONT_CREATE_GVSV
1638 #if !defined(HAS_WAITPID) && !defined(HAS_WAIT4) || defined(HAS_WAITPID_RUNTIME)
1639 #define PERL_USES_PL_PIDSTATUS
1642 #if !defined(OS2) && !defined(WIN32)
1643 #define PERL_DEFAULT_DO_EXEC3_IMPLEMENTATION
1646 #define MEM_SIZE Size_t
1648 /* Round all values passed to malloc up, by default to a multiple of
1651 #ifndef PERL_STRLEN_ROUNDUP_QUANTUM
1652 #define PERL_STRLEN_ROUNDUP_QUANTUM Size_t_size
1655 /* sv_grow() will expand strings by at least a certain percentage of
1656 the previously *used* length to avoid excessive calls to realloc().
1657 The default is 25% of the current length.
1659 #ifndef PERL_STRLEN_EXPAND_SHIFT
1660 # define PERL_STRLEN_EXPAND_SHIFT 2
1663 /* This use of offsetof() requires /Zc:offsetof- for VS2017 (and presumably
1664 * onwards) when building Socket.xs, but we can just use a different definition
1665 * for STRUCT_OFFSET instead. */
1666 #if defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1910
1667 # define STRUCT_OFFSET(s,m) (Size_t)(&(((s *)0)->m))
1669 # include <stddef.h>
1670 # define STRUCT_OFFSET(s,m) offsetof(s,m)
1673 /* ptrdiff_t is C11, so undef it under pedantic builds. (Actually it is
1674 * in C89, but apparently there are platforms where it doesn't exist. See
1675 * thread beginning at http://nntp.perl.org/group/perl.perl5.porters/251541.)
1677 #ifdef PERL_GCC_PEDANTIC
1678 # undef HAS_PTRDIFF_T
1681 #ifdef HAS_PTRDIFF_T
1682 # define Ptrdiff_t ptrdiff_t
1684 # define Ptrdiff_t SSize_t
1687 # include <string.h>
1689 /* This comes after <stdlib.h> so we don't try to change the standard
1690 * library prototypes; we'll use our own in proto.h instead. */
1693 # ifdef PERL_POLLUTE_MALLOC
1694 # ifndef PERL_EXTMALLOC_DEF
1695 # define Perl_malloc malloc
1696 # define Perl_calloc calloc
1697 # define Perl_realloc realloc
1698 # define Perl_mfree free
1701 # define EMBEDMYMALLOC /* for compatibility */
1704 # define safemalloc Perl_malloc
1705 # define safecalloc Perl_calloc
1706 # define saferealloc Perl_realloc
1707 # define safefree Perl_mfree
1708 # define CHECK_MALLOC_TOO_LATE_FOR_(code) STMT_START { \
1709 if (!TAINTING_get && MallocCfg_ptr[MallocCfg_cfg_env_read]) \
1712 # define CHECK_MALLOC_TOO_LATE_FOR(ch) \
1713 CHECK_MALLOC_TOO_LATE_FOR_(MALLOC_TOO_LATE_FOR(ch))
1714 # define panic_write2(s) write(2, s, strlen(s))
1715 # define CHECK_MALLOC_TAINT(newval) \
1716 CHECK_MALLOC_TOO_LATE_FOR_( \
1718 PERL_UNUSED_RESULT(panic_write2("panic: tainting with $ENV{PERL_MALLOC_OPT}\n"));\
1720 # define MALLOC_CHECK_TAINT(argc,argv,env) STMT_START { \
1721 if (doing_taint(argc,argv,env)) { \
1722 MallocCfg_ptr[MallocCfg_skip_cfg_env] = 1; \
1724 #else /* MYMALLOC */
1725 # define safemalloc safesysmalloc
1726 # define safecalloc safesyscalloc
1727 # define saferealloc safesysrealloc
1728 # define safefree safesysfree
1729 # define CHECK_MALLOC_TOO_LATE_FOR(ch) ((void)0)
1730 # define CHECK_MALLOC_TAINT(newval) ((void)0)
1731 # define MALLOC_CHECK_TAINT(argc,argv,env)
1732 #endif /* MYMALLOC */
1734 /* diag_listed_as: "-T" is on the #! line, it must also be used on the command line */
1735 #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)
1736 #define TOO_LATE_FOR(ch) TOO_LATE_FOR_(ch, "")
1737 #define MALLOC_TOO_LATE_FOR(ch) TOO_LATE_FOR_(ch, " with $ENV{PERL_MALLOC_OPT}")
1738 #define MALLOC_CHECK_TAINT2(argc,argv) MALLOC_CHECK_TAINT(argc,argv,NULL)
1741 =for apidoc Am|void|memzero|void * d|Size_t l
1742 Set the C<l> bytes starting at C<*d> to all zeroes.
1747 # define memzero(d,l) memset(d,0,l)
1751 # include <netinet/in.h>
1755 # include <arpa/inet.h>
1759 # include <sys/stat.h>
1762 /* Microsoft VC's sys/stat.h defines all S_Ixxx macros except S_IFIFO.
1763 This definition should ideally go into win32/win32.h, but S_IFIFO is
1764 used later here in perl.h before win32/win32.h is being included. */
1765 #if !defined(S_IFIFO) && defined(_S_IFIFO)
1766 # define S_IFIFO _S_IFIFO
1769 /* The stat macros for Unisoft System V/88 (and derivatives
1770 like UTekV) are broken, sometimes giving false positives. Undefine
1771 them here and let the code below set them to proper values.
1773 The ghs macro stands for GreenHills Software C-1.8.5 which
1774 is the C compiler for sysV88 and the various derivatives.
1775 This header file bug is corrected in gcc-2.5.8 and later versions.
1776 --Kaveh Ghazi (ghazi@noc.rutgers.edu) 10/3/94. */
1778 #if defined(m88k) && defined(ghs)
1790 # ifdef I_SYS_TIME_KERNEL
1793 # include <sys/time.h>
1794 # ifdef I_SYS_TIME_KERNEL
1799 #if defined(HAS_TIMES) && defined(I_SYS_TIMES)
1800 # include <sys/times.h>
1805 #if defined(WIN32) && defined(PERL_IMPLICIT_SYS)
1806 # define WIN32SCK_IS_STDSCK /* don't pull in custom wsock layer */
1809 #if defined(HAS_SOCKET) && !defined(WIN32) /* WIN32 handles sockets via win32.h */
1810 # include <sys/socket.h>
1811 # if defined(USE_SOCKS) && defined(I_SOCKS)
1812 # if !defined(INCLUDE_PROTOTYPES)
1813 # define INCLUDE_PROTOTYPES /* for <socks.h> */
1814 # define PERL_SOCKS_NEED_PROTOTYPES
1817 # ifdef PERL_SOCKS_NEED_PROTOTYPES /* keep cpp space clean */
1818 # undef INCLUDE_PROTOTYPES
1819 # undef PERL_SOCKS_NEED_PROTOTYPES
1827 # include <net/errno.h>
1832 /* sockatmark() is so new (2001) that many places might have it hidden
1833 * behind some -D_BLAH_BLAH_SOURCE guard. The __THROW magic is required
1834 * e.g. in Gentoo, see http://bugs.gentoo.org/show_bug.cgi?id=12605 */
1835 #if defined(HAS_SOCKATMARK) && !defined(HAS_SOCKATMARK_PROTO)
1836 # if defined(__THROW) && defined(__GLIBC__)
1837 int sockatmark(int) __THROW;
1839 int sockatmark(int);
1843 #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. */
1844 EXTERN_C int fchdir(int);
1845 EXTERN_C int flock(int, int);
1846 EXTERN_C int fseeko(FILE *, off_t, int);
1847 EXTERN_C off_t ftello(FILE *);
1850 #if defined(__SUNPRO_CC) /* SUNWspro CC (C++) */
1851 EXTERN_C char *crypt(const char *, const char *);
1854 #if defined(__cplusplus) && defined(__CYGWIN__)
1855 EXTERN_C char *crypt(const char *, const char *);
1859 =for apidoc_section $errno
1861 =for apidoc m|void|SETERRNO|int errcode|int vmserrcode
1863 Set C<errno>, and on VMS set C<vaxc$errno>.
1865 =for apidoc mn|void|dSAVEDERRNO
1867 Declare variables needed to save C<errno> and any operating system
1868 specific error number.
1870 =for apidoc mn|void|dSAVE_ERRNO
1872 Declare variables needed to save C<errno> and any operating system
1873 specific error number, and save them for optional later restoration
1874 by C<RESTORE_ERRNO>.
1876 =for apidoc mn|void|SAVE_ERRNO
1878 Save C<errno> and any operating system specific error number for
1879 optional later restoration by C<RESTORE_ERRNO>. Requires
1880 C<dSAVEDERRNO> or C<dSAVE_ERRNO> in scope.
1882 =for apidoc mn|void|RESTORE_ERRNO
1884 Restore C<errno> and any operating system specific error number that
1885 was saved by C<dSAVE_ERRNO> or C<RESTORE_ERRNO>.
1891 # undef SETERRNO /* SOCKS might have defined this */
1895 # define SETERRNO(errcode,vmserrcode) \
1897 set_errno(errcode); \
1898 set_vaxc_errno(vmserrcode); \
1900 # define dSAVEDERRNO int saved_errno; unsigned saved_vms_errno
1901 # define dSAVE_ERRNO int saved_errno = errno; unsigned saved_vms_errno = vaxc$errno
1902 # define SAVE_ERRNO ( saved_errno = errno, saved_vms_errno = vaxc$errno )
1903 # define RESTORE_ERRNO SETERRNO(saved_errno, saved_vms_errno)
1905 # define LIB_INVARG LIB$_INVARG
1906 # define RMS_DIR RMS$_DIR
1907 # define RMS_FAC RMS$_FAC
1908 # define RMS_FEX RMS$_FEX
1909 # define RMS_FNF RMS$_FNF
1910 # define RMS_IFI RMS$_IFI
1911 # define RMS_ISI RMS$_ISI
1912 # define RMS_PRV RMS$_PRV
1913 # define SS_ACCVIO SS$_ACCVIO
1914 # define SS_DEVOFFLINE SS$_DEVOFFLINE
1915 # define SS_IVCHAN SS$_IVCHAN
1916 # define SS_NORMAL SS$_NORMAL
1917 # define SS_NOPRIV SS$_NOPRIV
1918 # define SS_BUFFEROVF SS$_BUFFEROVF
1920 # define LIB_INVARG 0
1928 # define SS_ACCVIO 0
1929 # define SS_DEVOFFLINE 0
1930 # define SS_IVCHAN 0
1931 # define SS_NORMAL 0
1932 # define SS_NOPRIV 0
1933 # define SS_BUFFEROVF 0
1937 # define dSAVEDERRNO int saved_errno; DWORD saved_win32_errno
1938 # define dSAVE_ERRNO int saved_errno = errno; DWORD saved_win32_errno = GetLastError()
1939 # define SAVE_ERRNO ( saved_errno = errno, saved_win32_errno = GetLastError() )
1940 # define RESTORE_ERRNO ( errno = saved_errno, SetLastError(saved_win32_errno) )
1944 # define dSAVEDERRNO int saved_errno; unsigned long saved_os2_errno
1945 # define dSAVE_ERRNO int saved_errno = errno; unsigned long saved_os2_errno = Perl_rc
1946 # define SAVE_ERRNO ( saved_errno = errno, saved_os2_errno = Perl_rc )
1947 # define RESTORE_ERRNO ( errno = saved_errno, Perl_rc = saved_os2_errno )
1951 # define SETERRNO(errcode,vmserrcode) (errno = (errcode))
1955 # define dSAVEDERRNO int saved_errno
1956 # define dSAVE_ERRNO int saved_errno = errno
1957 # define SAVE_ERRNO (saved_errno = errno)
1958 # define RESTORE_ERRNO (errno = saved_errno)
1962 =for apidoc_section $warning
1964 =for apidoc Amn|SV *|ERRSV
1966 Returns the SV for C<$@>, creating it if needed.
1968 =for apidoc Am|void|CLEAR_ERRSV
1970 Clear the contents of C<$@>, setting it to the empty string.
1972 This replaces any read-only SV with a fresh SV and removes any magic.
1974 =for apidoc Am|void|SANE_ERRSV
1976 Clean up ERRSV so we can safely set it.
1978 This replaces any read-only SV with a fresh writable copy and removes
1984 #define ERRSV GvSVn(PL_errgv)
1986 /* contains inlined gv_add_by_type */
1987 #define CLEAR_ERRSV() STMT_START { \
1988 SV ** const svp = &GvSV(PL_errgv); \
1990 *svp = newSVpvs(""); \
1991 } else if (SvREADONLY(*svp)) { \
1992 SvREFCNT_dec_NN(*svp); \
1993 *svp = newSVpvs(""); \
1995 SV *const errsv = *svp; \
1997 SvPOK_only(errsv); \
1998 if (SvMAGICAL(errsv)) { \
2004 /* contains inlined gv_add_by_type */
2005 #define SANE_ERRSV() STMT_START { \
2006 SV ** const svp = &GvSV(PL_errgv); \
2008 *svp = newSVpvs(""); \
2009 } else if (SvREADONLY(*svp)) { \
2010 SV *dupsv = newSVsv(*svp); \
2011 SvREFCNT_dec_NN(*svp); \
2014 SV *const errsv = *svp; \
2015 if (SvMAGICAL(errsv)) { \
2023 # define DEFSV (0 + GvSVn(PL_defgv))
2024 # define DEFSV_set(sv) \
2025 (SvREFCNT_dec(GvSV(PL_defgv)), GvSV(PL_defgv) = SvREFCNT_inc(sv))
2026 # define SAVE_DEFSV \
2028 save_gp(PL_defgv, 0), \
2029 GvINTRO_off(PL_defgv), \
2030 SAVEGENERICSV(GvSV(PL_defgv)), \
2031 GvSV(PL_defgv) = NULL \
2034 # define DEFSV GvSVn(PL_defgv)
2035 # define DEFSV_set(sv) (GvSV(PL_defgv) = (sv))
2036 # define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
2040 =for apidoc_section $SV
2041 =for apidoc Amn|SV *|DEFSV
2042 Returns the SV associated with C<$_>
2044 =for apidoc Am|void|DEFSV_set|SV * sv
2045 Associate C<sv> with C<$_>
2047 =for apidoc Amn|void|SAVE_DEFSV
2048 Localize C<$_>. See L<perlguts/Localizing changes>.
2054 extern int errno; /* ANSI allows errno to be an lvalue expr.
2055 * For example in multithreaded environments
2056 * something like this might happen:
2057 * extern int *_errno(void);
2058 * #define errno (*_errno()) */
2061 #define UNKNOWN_ERRNO_MSG "(unknown)"
2064 #define Strerror(e) strerror((e), vaxc$errno)
2066 #define Strerror(e) strerror(e)
2071 # include <sys/ioctl.h>
2075 #if defined(mc300) || defined(mc500) || defined(mc700) || defined(mc6000)
2076 # ifdef HAS_SOCKETPAIR
2077 # undef HAS_SOCKETPAIR
2084 #ifndef HAS_SOCKETPAIR
2086 # define socketpair Perl_my_socketpair
2091 # define htoni htons
2092 # define ntohi ntohs
2094 # define htoni htonl
2095 # define ntohi ntohl
2098 /* Configure already sets Direntry_t */
2099 #if defined(I_DIRENT)
2100 # include <dirent.h>
2101 #elif defined(I_SYS_NDIR)
2102 # include <sys/ndir.h>
2103 #elif defined(I_SYS_DIR)
2104 # include <sys/dir.h>
2108 * The following gobbledygook brought to you on behalf of __STDC__.
2109 * (I could just use #ifndef __STDC__, but this is more bulletproof
2110 * in the face of half-implementations.)
2113 #if defined(I_SYSMODE)
2114 #include <sys/mode.h>
2119 # define S_IFMT _S_IFMT
2121 # define S_IFMT 0170000
2126 # define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
2130 # define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
2135 # define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
2137 # define S_ISBLK(m) (0)
2142 # define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
2147 # define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
2149 # define S_ISFIFO(m) (0)
2155 # define S_ISLNK(m) _S_ISLNK(m)
2156 # elif defined(_S_IFLNK)
2157 # define S_ISLNK(m) ((m & S_IFMT) == _S_IFLNK)
2158 # elif defined(S_IFLNK)
2159 # define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
2161 # define S_ISLNK(m) (0)
2167 # define S_ISSOCK(m) _S_ISSOCK(m)
2168 # elif defined(_S_IFSOCK)
2169 # define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
2170 # elif defined(S_IFSOCK)
2171 # define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
2173 # define S_ISSOCK(m) (0)
2179 # define S_IRUSR S_IREAD
2180 # define S_IWUSR S_IWRITE
2181 # define S_IXUSR S_IEXEC
2183 # define S_IRUSR 0400
2184 # define S_IWUSR 0200
2185 # define S_IXUSR 0100
2191 # define S_IRGRP (S_IRUSR>>3)
2192 # define S_IWGRP (S_IWUSR>>3)
2193 # define S_IXGRP (S_IXUSR>>3)
2195 # define S_IRGRP 0040
2196 # define S_IWGRP 0020
2197 # define S_IXGRP 0010
2203 # define S_IROTH (S_IRUSR>>6)
2204 # define S_IWOTH (S_IWUSR>>6)
2205 # define S_IXOTH (S_IXUSR>>6)
2207 # define S_IROTH 0040
2208 # define S_IWOTH 0020
2209 # define S_IXOTH 0010
2214 # define S_ISUID 04000
2218 # define S_ISGID 02000
2222 # define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR)
2226 # define S_IRWXG (S_IRGRP|S_IWGRP|S_IXGRP)
2230 # define S_IRWXO (S_IROTH|S_IWOTH|S_IXOTH)
2233 /* Haiku R1 seems to define S_IREAD and S_IWRITE in <posix/fcntl.h>
2234 * which would get included through <sys/file.h >, but that is 3000
2235 * lines in the future. --jhi */
2237 #if !defined(S_IREAD) && !defined(__HAIKU__)
2238 # define S_IREAD S_IRUSR
2241 #if !defined(S_IWRITE) && !defined(__HAIKU__)
2242 # define S_IWRITE S_IWUSR
2246 # define S_IEXEC S_IXUSR
2249 #if defined(cray) || defined(gould) || defined(i860) || defined(pyr)
2250 # define SLOPPYDIVIDE
2257 /* This used to be conditionally defined based on whether we had a sprintf()
2258 * that correctly returns the string length (as required by C89), but we no
2259 * longer need that. XS modules can (and do) use this name, so it must remain
2260 * a part of the API that's visible to modules.
2262 =for apidoc_section $string
2263 =for apidoc ATmD|int|my_sprintf|NN char *buffer|NN const char *pat|...
2265 Do NOT use this due to the possibility of overflowing C<buffer>. Instead use
2270 #define my_sprintf sprintf
2273 * If we have v?snprintf() and the C99 variadic macros, we can just
2274 * use just the v?snprintf(). It is nice to try to trap the buffer
2275 * overflow, however, so if we are DEBUGGING, and we cannot use the
2276 * gcc statement expressions, then use the function wrappers which try
2277 * to trap the overflow. If we can use the gcc statement expressions,
2278 * we can try that even with the version that uses the C99 variadic
2282 /* Note that we do not check against snprintf()/vsnprintf() returning
2283 * negative values because that is non-standard behaviour and we use
2284 * snprintf/vsnprintf only iff HAS_VSNPRINTF has been defined, and
2285 * that should be true only if the snprintf()/vsnprintf() are true
2286 * to the standard. */
2288 #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
2291 # define my_snprintf Perl_my_snprintf
2292 # define PERL_MY_SNPRINTF_GUARDED
2293 #elif defined(HAS_SNPRINTF) && defined(HAS_C99_VARIADIC_MACROS) && !(defined(DEBUGGING) && !defined(PERL_USE_GCC_BRACE_GROUPS)) && !defined(PERL_GCC_PEDANTIC)
2294 # ifdef PERL_USE_GCC_BRACE_GROUPS
2295 # define my_snprintf(buffer, max, ...) ({ int len = snprintf(buffer, max, __VA_ARGS__); PERL_SNPRINTF_CHECK(len, max, snprintf); len; })
2296 # define PERL_MY_SNPRINTF_GUARDED
2298 # define my_snprintf(buffer, max, ...) snprintf(buffer, max, __VA_ARGS__)
2301 # define my_snprintf Perl_my_snprintf
2302 # define PERL_MY_SNPRINTF_GUARDED
2305 /* There is no quadmath_vsnprintf, and therefore my_vsnprintf()
2306 * dies if called under USE_QUADMATH. */
2307 #if defined(HAS_VSNPRINTF) && defined(HAS_C99_VARIADIC_MACROS) && !(defined(DEBUGGING) && !defined(PERL_USE_GCC_BRACE_GROUPS)) && !defined(PERL_GCC_PEDANTIC)
2308 # ifdef PERL_USE_GCC_BRACE_GROUPS
2309 # define my_vsnprintf(buffer, max, ...) ({ int len = vsnprintf(buffer, max, __VA_ARGS__); PERL_SNPRINTF_CHECK(len, max, vsnprintf); len; })
2310 # define PERL_MY_VSNPRINTF_GUARDED
2312 # define my_vsnprintf(buffer, max, ...) vsnprintf(buffer, max, __VA_ARGS__)
2315 # define my_vsnprintf Perl_my_vsnprintf
2316 # define PERL_MY_VSNPRINTF_GUARDED
2319 /* You will definitely need to use the PERL_MY_SNPRINTF_POST_GUARD()
2320 * or PERL_MY_VSNPRINTF_POST_GUARD() if you otherwise decide to ignore
2321 * the result of my_snprintf() or my_vsnprintf(). (No, you should not
2322 * completely ignore it: otherwise you cannot know whether your output
2325 * int len = my_sprintf(buf, max, ...);
2326 * PERL_MY_SNPRINTF_POST_GUARD(len, max);
2328 * The trick is that in certain platforms [a] the my_sprintf() already
2329 * contains the sanity check, while in certain platforms [b] it needs
2330 * to be done as a separate step. The POST_GUARD is that step-- in [a]
2331 * platforms the POST_GUARD actually does nothing since the check has
2332 * already been done. Watch out for the max being the same in both calls.
2334 * If you actually use the snprintf/vsnprintf return value already,
2335 * you assumedly are checking its validity somehow. But you can
2336 * insert the POST_GUARD() also in that case. */
2338 #ifndef PERL_MY_SNPRINTF_GUARDED
2339 # define PERL_MY_SNPRINTF_POST_GUARD(len, max) PERL_SNPRINTF_CHECK(len, max, snprintf)
2341 # define PERL_MY_SNPRINTF_POST_GUARD(len, max) PERL_UNUSED_VAR(len)
2344 #ifndef PERL_MY_VSNPRINTF_GUARDED
2345 # define PERL_MY_VSNPRINTF_POST_GUARD(len, max) PERL_SNPRINTF_CHECK(len, max, vsnprintf)
2347 # define PERL_MY_VSNPRINTF_POST_GUARD(len, max) PERL_UNUSED_VAR(len)
2351 # define my_strlcat strlcat
2354 #if defined(PERL_CORE) || defined(PERL_EXT)
2356 # define my_memrchr memrchr
2358 # define my_memrchr S_my_memrchr
2363 # define my_strlcpy strlcpy
2367 # define my_strnlen strnlen
2371 The IV type is supposed to be long enough to hold any integral
2373 --Andy Dougherty August 1996
2379 #if defined(USE_64_BIT_INT) && defined(HAS_QUAD)
2380 # if QUADKIND == QUAD_IS_INT64_T && defined(INT64_MAX)
2381 # define IV_MAX ((IV)INT64_MAX)
2382 # define IV_MIN ((IV)INT64_MIN)
2383 # define UV_MAX ((UV)UINT64_MAX)
2385 # define UINT64_MIN 0
2387 # define UV_MIN ((UV)UINT64_MIN)
2389 # define IV_MAX PERL_QUAD_MAX
2390 # define IV_MIN PERL_QUAD_MIN
2391 # define UV_MAX PERL_UQUAD_MAX
2392 # define UV_MIN PERL_UQUAD_MIN
2397 # if defined(INT32_MAX) && IVSIZE == 4
2398 # define IV_MAX ((IV)INT32_MAX)
2399 # define IV_MIN ((IV)INT32_MIN)
2400 # ifndef UINT32_MAX_BROKEN /* e.g. HP-UX with gcc messes this up */
2401 # define UV_MAX ((UV)UINT32_MAX)
2403 # define UV_MAX ((UV)4294967295U)
2406 # define UINT32_MIN 0
2408 # define UV_MIN ((UV)UINT32_MIN)
2410 # define IV_MAX PERL_LONG_MAX
2411 # define IV_MIN PERL_LONG_MIN
2412 # define UV_MAX PERL_ULONG_MAX
2413 # define UV_MIN PERL_ULONG_MIN
2424 #if !defined(PERL_CORE)
2425 /* We think that removing this decade-old undef this will cause too much
2426 breakage on CPAN for too little gain. (See RT #119753)
2427 However, we do need HAS_QUAD in the core for use by the drand48 code. */
2433 #define Size_t_MAX (~(Size_t)0)
2434 #define SSize_t_MAX (SSize_t)(~(Size_t)0 >> 1)
2436 #define IV_DIG (BIT_DIGITS(IVSIZE * 8))
2437 #define UV_DIG (BIT_DIGITS(UVSIZE * 8))
2439 #ifndef NO_PERL_PRESERVE_IVUV
2440 #define PERL_PRESERVE_IVUV /* We like our integers to stay integers. */
2444 =for apidoc AmnU||U32of
2445 =for apidoc_item ||U32uf
2446 =for apidoc_item ||U32xf
2447 =for apidoc_item ||U32Xf
2449 These symbols define the format strings used for printing variables declared
2450 as U32; respectively as octal, unsigned, hex (lowercase C<a-f>), and hex
2456 #if U32SIZE == UVSIZE
2461 #elif U32SIZE == INTSIZE
2466 #elif U32SIZE == LONGSIZE
2472 # error Cant figure out formatting strings for U32SIZE
2476 =for apidoc AmnU||I32df
2478 This symbol defines the format string used for printing a variable declared as
2484 #if I32SIZE == IVSIZE
2486 #elif I32SIZE == INTSIZE
2488 #elif I32SIZE == LONGSIZE
2491 # error Cant figure out formatting string for I32SIZE
2495 * The macros INT2PTR and NUM2PTR are (despite their names)
2496 * bi-directional: they will convert int/float to or from pointers.
2497 * However the conversion to int/float are named explicitly:
2498 * PTR2IV, PTR2UV, PTR2NV.
2500 * For int conversions we do not need two casts if pointers are
2501 * the same size as IV and UV. Otherwise we need an explicit
2502 * cast (PTRV) to avoid compiler warnings.
2504 * These are mentioned in perlguts
2506 #if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE)
2508 # define INT2PTR(any,d) (any)(d)
2509 #elif PTRSIZE == LONGSIZE
2510 # define PTRV unsigned long
2511 # define PTR2ul(p) (unsigned long)(p)
2513 # define PTRV unsigned
2517 # define INT2PTR(any,d) (any)(PTRV)(d)
2521 # define PTR2ul(p) INT2PTR(unsigned long,p)
2525 =for apidoc_section $casting
2526 =for apidoc Cyh|type|NUM2PTR|type|int value
2527 You probably want to be using L<C</INT2PTR>> instead.
2532 #define NUM2PTR(any,d) (any)(PTRV)(d)
2533 #define PTR2IV(p) INT2PTR(IV,p)
2534 #define PTR2UV(p) INT2PTR(UV,p)
2535 #define PTR2NV(p) NUM2PTR(NV,p)
2536 #define PTR2nat(p) (PTRV)(p) /* pointer to integer of PTRSIZE */
2538 /* According to strict ANSI C89 one cannot freely cast between
2539 * data pointers and function (code) pointers. There are at least
2540 * two ways around this. One (used below) is to do two casts,
2541 * first the other pointer to an (unsigned) integer, and then
2542 * the integer to the other pointer. The other way would be
2543 * to use unions to "overlay" the pointers. For an example of
2544 * the latter technique, see union dirpu in struct xpvio in sv.h.
2545 * The only feasible use is probably temporarily storing
2546 * function pointers in a data pointer (such as a void pointer). */
2548 #define DPTR2FPTR(t,p) ((t)PTR2nat(p)) /* data pointer to function pointer */
2549 #define FPTR2DPTR(t,p) ((t)PTR2nat(p)) /* function pointer to data pointer */
2551 #ifdef USE_LONG_DOUBLE
2552 # if LONG_DOUBLESIZE == DOUBLESIZE
2553 # define LONG_DOUBLE_EQUALS_DOUBLE
2554 # undef USE_LONG_DOUBLE /* Ouch! */
2558 /* The following is all to get LDBL_DIG, in order to pick a nice
2559 default value for printing floating point numbers in Gconvert.
2562 #ifndef HAS_LDBL_DIG
2563 # if LONG_DOUBLESIZE == 10
2564 # define LDBL_DIG 18 /* assume IEEE */
2565 # elif LONG_DOUBLESIZE == 12
2566 # define LDBL_DIG 18 /* gcc? */
2567 # elif LONG_DOUBLESIZE == 16
2568 # define LDBL_DIG 33 /* assume IEEE */
2569 # elif LONG_DOUBLESIZE == DOUBLESIZE
2570 # define LDBL_DIG DBL_DIG /* bummer */
2574 /* On MS Windows,with 64-bit mingw-w64 compilers, we
2575 need to attend to a __float128 alignment issue if
2576 USE_QUADMATH is defined. Otherwise we simply:
2578 32-bit mingw.org compilers might also require
2579 aligned(32) - at least that's what I found with my
2580 Math::Foat128 module. But this is as yet untested
2581 here, so no allowance is being made for mingw.org
2582 compilers at this stage. -- sisyphus January 2021
2584 #if (defined(USE_LONG_DOUBLE) || defined(USE_QUADMATH)) && defined(__MINGW64__)
2585 /* 64-bit build, mingw-w64 compiler only */
2586 typedef NVTYPE NV __attribute__ ((aligned(8)));
2592 # include <ieeefp.h>
2595 #if defined(__DECC) && defined(__osf__)
2596 /* Also Tru64 cc has broken NaN comparisons. */
2597 # define NAN_COMPARE_BROKEN
2600 # define NAN_COMPARE_BROKEN
2603 #ifdef USE_LONG_DOUBLE
2605 # include <sunmath.h>
2607 # if defined(LDBL_DIG)
2608 # define NV_DIG LDBL_DIG
2609 # ifdef LDBL_MANT_DIG
2610 # define NV_MANT_DIG LDBL_MANT_DIG
2613 # define NV_MIN LDBL_MIN
2616 # define NV_MAX LDBL_MAX
2618 # ifdef LDBL_MIN_EXP
2619 # define NV_MIN_EXP LDBL_MIN_EXP
2621 # ifdef LDBL_MAX_EXP
2622 # define NV_MAX_EXP LDBL_MAX_EXP
2624 # ifdef LDBL_MIN_10_EXP
2625 # define NV_MIN_10_EXP LDBL_MIN_10_EXP
2627 # ifdef LDBL_MAX_10_EXP
2628 # define NV_MAX_10_EXP LDBL_MAX_10_EXP
2630 # ifdef LDBL_EPSILON
2631 # define NV_EPSILON LDBL_EPSILON
2634 # define NV_MAX LDBL_MAX
2635 /* Having LDBL_MAX doesn't necessarily mean that we have LDBL_MIN... -Allen */
2636 # elif defined(HUGE_VALL)
2637 # define NV_MAX HUGE_VALL
2640 # if defined(HAS_SQRTL)
2641 # define Perl_acos acosl
2642 # define Perl_asin asinl
2643 # define Perl_atan atanl
2644 # define Perl_atan2 atan2l
2645 # define Perl_ceil ceill
2646 # define Perl_cos cosl
2647 # define Perl_cosh coshl
2648 # define Perl_exp expl
2649 # define Perl_fabs fabsl
2650 # define Perl_floor floorl
2651 # define Perl_fmod fmodl
2652 # define Perl_log logl
2653 # define Perl_log10 log10l
2654 # define Perl_pow powl
2655 # define Perl_sin sinl
2656 # define Perl_sinh sinhl
2657 # define Perl_sqrt sqrtl
2658 # define Perl_tan tanl
2659 # define Perl_tanh tanhl
2661 /* e.g. libsunmath doesn't have modfl and frexpl as of mid-March 2000 */
2664 # define Perl_modf(x,y) modfl(x,y)
2665 /* eg glibc 2.2 series seems to provide modfl on ppc and arm, but has no
2666 prototype in <math.h> */
2667 # ifndef HAS_MODFL_PROTO
2668 EXTERN_C long double modfl(long double, long double *);
2670 # elif (defined(HAS_TRUNCL) || defined(HAS_AINTL)) && defined(HAS_COPYSIGNL)
2671 extern long double Perl_my_modfl(long double x, long double *ip);
2672 # define Perl_modf(x,y) Perl_my_modfl(x,y)
2677 # define Perl_frexp(x,y) frexpl(x,y)
2678 # elif defined(HAS_ILOGBL) && defined(HAS_SCALBNL)
2679 extern long double Perl_my_frexpl(long double x, int *e);
2680 # define Perl_frexp(x,y) Perl_my_frexpl(x,y)
2685 # define Perl_ldexp(x, y) ldexpl(x,y)
2686 # elif defined(HAS_SCALBNL) && FLT_RADIX == 2
2687 # define Perl_ldexp(x,y) scalbnl(x,y)
2691 # if defined(HAS_ISNANL) && !(defined(isnan) && defined(HAS_C99))
2692 # define Perl_isnan(x) isnanl(x)
2693 # elif defined(__sgi) && defined(__c99) /* XXX Configure test needed */
2694 # define Perl_isnan(x) isnan(x)
2698 # if defined(HAS_ISINFL) && !(defined(isinf) && defined(HAS_C99))
2699 # define Perl_isinf(x) isinfl(x)
2700 # elif defined(__sgi) && defined(__c99) /* XXX Configure test needed */
2701 # define Perl_isinf(x) isinf(x)
2702 # elif defined(LDBL_MAX) && !defined(NAN_COMPARE_BROKEN)
2703 # define Perl_isinf(x) ((x) > LDBL_MAX || (x) < -LDBL_MAX)
2706 # ifndef Perl_isfinite
2707 # define Perl_isfinite(x) Perl_isfinitel(x)
2709 #elif defined(USE_QUADMATH) && defined(I_QUADMATH)
2710 # include <quadmath.h>
2711 # define NV_DIG FLT128_DIG
2712 # define NV_MANT_DIG FLT128_MANT_DIG
2713 # define NV_MIN FLT128_MIN
2714 # define NV_MAX FLT128_MAX
2715 # define NV_MIN_EXP FLT128_MIN_EXP
2716 # define NV_MAX_EXP FLT128_MAX_EXP
2717 # define NV_EPSILON FLT128_EPSILON
2718 # define NV_MIN_10_EXP FLT128_MIN_10_EXP
2719 # define NV_MAX_10_EXP FLT128_MAX_10_EXP
2720 # define Perl_acos acosq
2721 # define Perl_asin asinq
2722 # define Perl_atan atanq
2723 # define Perl_atan2 atan2q
2724 # define Perl_ceil ceilq
2725 # define Perl_cos cosq
2726 # define Perl_cosh coshq
2727 # define Perl_exp expq
2728 # define Perl_fabs fabsq
2729 # define Perl_floor floorq
2730 # define Perl_fmod fmodq
2731 # define Perl_log logq
2732 # define Perl_log10 log10q
2733 # define Perl_signbit signbitq
2734 # define Perl_pow powq
2735 # define Perl_sin sinq
2736 # define Perl_sinh sinhq
2737 # define Perl_sqrt sqrtq
2738 # define Perl_tan tanq
2739 # define Perl_tanh tanhq
2740 # define Perl_modf(x,y) modfq(x,y)
2741 # define Perl_frexp(x,y) frexpq(x,y)
2742 # define Perl_ldexp(x, y) ldexpq(x,y)
2743 # define Perl_isinf(x) isinfq(x)
2744 # define Perl_isnan(x) isnanq(x)
2745 # define Perl_isfinite(x) !(isnanq(x) || isinfq(x))
2746 # define Perl_fp_class(x) ((x) == 0.0Q ? 0 : isinfq(x) ? 3 : isnanq(x) ? 4 : PERL_ABS(x) < FLT128_MIN ? 2 : 1)
2747 # define Perl_fp_class_inf(x) (Perl_fp_class(x) == 3)
2748 # define Perl_fp_class_nan(x) (Perl_fp_class(x) == 4)
2749 # define Perl_fp_class_norm(x) (Perl_fp_class(x) == 1)
2750 # define Perl_fp_class_denorm(x) (Perl_fp_class(x) == 2)
2751 # define Perl_fp_class_zero(x) (Perl_fp_class(x) == 0)
2753 # define NV_DIG DBL_DIG
2754 # define NV_MANT_DIG DBL_MANT_DIG
2755 # define NV_MIN DBL_MIN
2756 # define NV_MAX DBL_MAX
2757 # define NV_MIN_EXP DBL_MIN_EXP
2758 # define NV_MAX_EXP DBL_MAX_EXP
2759 # define NV_MIN_10_EXP DBL_MIN_10_EXP
2760 # define NV_MAX_10_EXP DBL_MAX_10_EXP
2761 # define NV_EPSILON DBL_EPSILON
2762 # define NV_MAX DBL_MAX
2763 # define NV_MIN DBL_MIN
2765 /* These math interfaces are C89. */
2766 # define Perl_acos acos
2767 # define Perl_asin asin
2768 # define Perl_atan atan
2769 # define Perl_atan2 atan2
2770 # define Perl_ceil ceil
2771 # define Perl_cos cos
2772 # define Perl_cosh cosh
2773 # define Perl_exp exp
2774 # define Perl_fabs fabs
2775 # define Perl_floor floor
2776 # define Perl_fmod fmod
2777 # define Perl_log log
2778 # define Perl_log10 log10
2779 # define Perl_pow pow
2780 # define Perl_sin sin
2781 # define Perl_sinh sinh
2782 # define Perl_sqrt sqrt
2783 # define Perl_tan tan
2784 # define Perl_tanh tanh
2786 # define Perl_modf(x,y) modf(x,y)
2787 # define Perl_frexp(x,y) frexp(x,y)
2788 # define Perl_ldexp(x,y) ldexp(x,y)
2792 # define Perl_isnan(x) isnan(x)
2796 # if defined(HAS_ISINF)
2797 # define Perl_isinf(x) isinf(x)
2798 # elif defined(DBL_MAX) && !defined(NAN_COMPARE_BROKEN)
2799 # define Perl_isinf(x) ((x) > DBL_MAX || (x) < -DBL_MAX)
2802 # ifndef Perl_isfinite
2803 # ifdef HAS_ISFINITE
2804 # define Perl_isfinite(x) isfinite(x)
2805 # elif defined(HAS_FINITE)
2806 # define Perl_isfinite(x) finite(x)
2811 /* fpclassify(): C99. It is supposed to be a macro that switches on
2812 * the sizeof() of its argument, so there's no need for e.g. fpclassifyl().*/
2813 #if !defined(Perl_fp_class) && defined(HAS_FPCLASSIFY)
2815 # if defined(FP_INFINITE) && defined(FP_NAN)
2816 # define Perl_fp_class(x) fpclassify(x)
2817 # define Perl_fp_class_inf(x) (Perl_fp_class(x)==FP_INFINITE)
2818 # define Perl_fp_class_nan(x) (Perl_fp_class(x)==FP_NAN)
2819 # define Perl_fp_class_norm(x) (Perl_fp_class(x)==FP_NORMAL)
2820 # define Perl_fp_class_denorm(x) (Perl_fp_class(x)==FP_SUBNORMAL)
2821 # define Perl_fp_class_zero(x) (Perl_fp_class(x)==FP_ZERO)
2822 # elif defined(FP_PLUS_INF) && defined(FP_QNAN)
2823 /* Some versions of HP-UX (10.20) have (only) fpclassify() but which is
2824 * actually not the C99 fpclassify, with its own set of return defines. */
2825 # define Perl_fp_class(x) fpclassify(x)
2826 # define Perl_fp_class_pinf(x) (Perl_fp_class(x)==FP_PLUS_INF)
2827 # define Perl_fp_class_ninf(x) (Perl_fp_class(x)==FP_MINUS_INF)
2828 # define Perl_fp_class_snan(x) (Perl_fp_class(x)==FP_SNAN)
2829 # define Perl_fp_class_qnan(x) (Perl_fp_class(x)==FP_QNAN)
2830 # define Perl_fp_class_pnorm(x) (Perl_fp_class(x)==FP_PLUS_NORM)
2831 # define Perl_fp_class_nnorm(x) (Perl_fp_class(x)==FP_MINUS_NORM)
2832 # define Perl_fp_class_pdenorm(x) (Perl_fp_class(x)==FP_PLUS_DENORM)
2833 # define Perl_fp_class_ndenorm(x) (Perl_fp_class(x)==FP_MINUS_DENORM)
2834 # define Perl_fp_class_pzero(x) (Perl_fp_class(x)==FP_PLUS_ZERO)
2835 # define Perl_fp_class_nzero(x) (Perl_fp_class(x)==FP_MINUS_ZERO)
2837 # undef Perl_fp_class /* Unknown set of defines */
2841 /* fp_classify(): Legacy: VMS, maybe Unicos? The values, however,
2842 * are identical to the C99 fpclassify(). */
2843 #if !defined(Perl_fp_class) && defined(HAS_FP_CLASSIFY)
2846 /* FP_INFINITE and others are here rather than in math.h as C99 stipulates */
2848 /* oh, and the isnormal macro has a typo in it! */
2850 # define isnormal(x) Perl_fp_class_norm(x)
2852 # if defined(FP_INFINITE) && defined(FP_NAN)
2853 # define Perl_fp_class(x) fp_classify(x)
2854 # define Perl_fp_class_inf(x) (Perl_fp_class(x)==FP_INFINITE)
2855 # define Perl_fp_class_nan(x) (Perl_fp_class(x)==FP_NAN)
2856 # define Perl_fp_class_norm(x) (Perl_fp_class(x)==FP_NORMAL)
2857 # define Perl_fp_class_denorm(x) (Perl_fp_class(x)==FP_SUBNORMAL)
2858 # define Perl_fp_class_zero(x) (Perl_fp_class(x)==FP_ZERO)
2860 # undef Perl_fp_class /* Unknown set of defines */
2864 /* Feel free to check with me for the SGI manpages, SGI testing,
2865 * etcetera, if you want to try getting this to work with IRIX.
2867 * - Allen <allens@cpan.org> */
2869 /* fpclass(): SysV, at least Solaris and some versions of IRIX. */
2870 #if !defined(Perl_fp_class) && (defined(HAS_FPCLASS)||defined(HAS_FPCLASSL))
2871 /* Solaris and IRIX have fpclass/fpclassl, but they are using
2872 * an enum typedef, not cpp symbols, and Configure doesn't detect that.
2873 * Define some symbols also as cpp symbols so we can detect them. */
2874 # if defined(__sun) || defined(__sgi) /* XXX Configure test instead */
2875 # define FP_PINF FP_PINF
2876 # define FP_QNAN FP_QNAN
2880 # include <ieeefp.h>
2885 # if defined(USE_LONG_DOUBLE) && defined(HAS_FPCLASSL)
2886 # define Perl_fp_class(x) fpclassl(x)
2888 # define Perl_fp_class(x) fpclass(x)
2890 # if defined(FP_CLASS_PINF) && defined(FP_CLASS_SNAN)
2891 # define Perl_fp_class_snan(x) (Perl_fp_class(x)==FP_CLASS_SNAN)
2892 # define Perl_fp_class_qnan(x) (Perl_fp_class(x)==FP_CLASS_QNAN)
2893 # define Perl_fp_class_ninf(x) (Perl_fp_class(x)==FP_CLASS_NINF)
2894 # define Perl_fp_class_pinf(x) (Perl_fp_class(x)==FP_CLASS_PINF)
2895 # define Perl_fp_class_nnorm(x) (Perl_fp_class(x)==FP_CLASS_NNORM)
2896 # define Perl_fp_class_pnorm(x) (Perl_fp_class(x)==FP_CLASS_PNORM)
2897 # define Perl_fp_class_ndenorm(x) (Perl_fp_class(x)==FP_CLASS_NDENORM)
2898 # define Perl_fp_class_pdenorm(x) (Perl_fp_class(x)==FP_CLASS_PDENORM)
2899 # define Perl_fp_class_nzero(x) (Perl_fp_class(x)==FP_CLASS_NZERO)
2900 # define Perl_fp_class_pzero(x) (Perl_fp_class(x)==FP_CLASS_PZERO)
2901 # elif defined(FP_PINF) && defined(FP_QNAN)
2902 # define Perl_fp_class_snan(x) (Perl_fp_class(x)==FP_SNAN)
2903 # define Perl_fp_class_qnan(x) (Perl_fp_class(x)==FP_QNAN)
2904 # define Perl_fp_class_ninf(x) (Perl_fp_class(x)==FP_NINF)
2905 # define Perl_fp_class_pinf(x) (Perl_fp_class(x)==FP_PINF)
2906 # define Perl_fp_class_nnorm(x) (Perl_fp_class(x)==FP_NNORM)
2907 # define Perl_fp_class_pnorm(x) (Perl_fp_class(x)==FP_PNORM)
2908 # define Perl_fp_class_ndenorm(x) (Perl_fp_class(x)==FP_NDENORM)
2909 # define Perl_fp_class_pdenorm(x) (Perl_fp_class(x)==FP_PDENORM)
2910 # define Perl_fp_class_nzero(x) (Perl_fp_class(x)==FP_NZERO)
2911 # define Perl_fp_class_pzero(x) (Perl_fp_class(x)==FP_PZERO)
2913 # undef Perl_fp_class /* Unknown set of defines */
2917 /* fp_class(): Legacy: at least Tru64, some versions of IRIX. */
2918 #if !defined(Perl_fp_class) && (defined(HAS_FP_CLASS)||defined(HAS_FP_CLASSL))
2920 # if !defined(FP_SNAN) && defined(I_FP_CLASS)
2921 # include <fp_class.h>
2923 # if defined(FP_POS_INF) && defined(FP_QNAN)
2924 # ifdef __sgi /* XXX Configure test instead */
2925 # ifdef USE_LONG_DOUBLE
2926 # define Perl_fp_class(x) fp_class_l(x)
2928 # define Perl_fp_class(x) fp_class_d(x)
2931 # if defined(USE_LONG_DOUBLE) && defined(HAS_FP_CLASSL)
2932 # define Perl_fp_class(x) fp_classl(x)
2934 # define Perl_fp_class(x) fp_class(x)
2937 # if defined(FP_POS_INF) && defined(FP_QNAN)
2938 # define Perl_fp_class_snan(x) (Perl_fp_class(x)==FP_SNAN)
2939 # define Perl_fp_class_qnan(x) (Perl_fp_class(x)==FP_QNAN)
2940 # define Perl_fp_class_ninf(x) (Perl_fp_class(x)==FP_NEG_INF)
2941 # define Perl_fp_class_pinf(x) (Perl_fp_class(x)==FP_POS_INF)
2942 # define Perl_fp_class_nnorm(x) (Perl_fp_class(x)==FP_NEG_NORM)
2943 # define Perl_fp_class_pnorm(x) (Perl_fp_class(x)==FP_POS_NORM)
2944 # define Perl_fp_class_ndenorm(x) (Perl_fp_class(x)==FP_NEG_DENORM)
2945 # define Perl_fp_class_pdenorm(x) (Perl_fp_class(x)==FP_POS_DENORM)
2946 # define Perl_fp_class_nzero(x) (Perl_fp_class(x)==FP_NEG_ZERO)
2947 # define Perl_fp_class_pzero(x) (Perl_fp_class(x)==FP_POS_ZERO)
2949 # undef Perl_fp_class /* Unknown set of defines */
2954 /* class(), _class(): Legacy: AIX. */
2955 #if !defined(Perl_fp_class) && defined(HAS_CLASS)
2957 # if defined(FP_PLUS_NORM) && defined(FP_PLUS_INF)
2959 # define Perl_fp_class(x) class(x)
2961 # define Perl_fp_class(x) _class(x)
2963 # if defined(FP_PLUS_INF) && defined(FP_NANQ)
2964 # define Perl_fp_class_snan(x) (Perl_fp_class(x)==FP_NANS)
2965 # define Perl_fp_class_qnan(x) (Perl_fp_class(x)==FP_NANQ)
2966 # define Perl_fp_class_ninf(x) (Perl_fp_class(x)==FP_MINUS_INF)
2967 # define Perl_fp_class_pinf(x) (Perl_fp_class(x)==FP_PLUS_INF)
2968 # define Perl_fp_class_nnorm(x) (Perl_fp_class(x)==FP_MINUS_NORM)
2969 # define Perl_fp_class_pnorm(x) (Perl_fp_class(x)==FP_PLUS_NORM)
2970 # define Perl_fp_class_ndenorm(x) (Perl_fp_class(x)==FP_MINUS_DENORM)
2971 # define Perl_fp_class_pdenorm(x) (Perl_fp_class(x)==FP_PLUS_DENORM)
2972 # define Perl_fp_class_nzero(x) (Perl_fp_class(x)==FP_MINUS_ZERO)
2973 # define Perl_fp_class_pzero(x) (Perl_fp_class(x)==FP_PLUS_ZERO)
2975 # undef Perl_fp_class /* Unknown set of defines */
2980 /* Win32: _fpclass(), _isnan(), _finite(). */
2983 # define Perl_isnan(x) _isnan(x)
2985 # ifndef Perl_isfinite
2986 # define Perl_isfinite(x) _finite(x)
2988 # ifndef Perl_fp_class_snan
2989 /* No simple way to #define Perl_fp_class because _fpclass()
2990 * returns a set of bits. */
2991 # define Perl_fp_class_snan(x) (_fpclass(x) & _FPCLASS_SNAN)
2992 # define Perl_fp_class_qnan(x) (_fpclass(x) & _FPCLASS_QNAN)
2993 # define Perl_fp_class_nan(x) (_fpclass(x) & (_FPCLASS_SNAN|_FPCLASS_QNAN))
2994 # define Perl_fp_class_ninf(x) (_fpclass(x) & _FPCLASS_NINF)
2995 # define Perl_fp_class_pinf(x) (_fpclass(x) & _FPCLASS_PINF)
2996 # define Perl_fp_class_inf(x) (_fpclass(x) & (_FPCLASS_NINF|_FPCLASS_PINF))
2997 # define Perl_fp_class_nnorm(x) (_fpclass(x) & _FPCLASS_NN)
2998 # define Perl_fp_class_pnorm(x) (_fpclass(x) & _FPCLASS_PN)
2999 # define Perl_fp_class_norm(x) (_fpclass(x) & (_FPCLASS_NN|_FPCLASS_PN))
3000 # define Perl_fp_class_ndenorm(x) (_fpclass(x) & _FPCLASS_ND)
3001 # define Perl_fp_class_pdenorm(x) (_fpclass(x) & _FPCLASS_PD)
3002 # define Perl_fp_class_denorm(x) (_fpclass(x) & (_FPCLASS_ND|_FPCLASS_PD))
3003 # define Perl_fp_class_nzero(x) (_fpclass(x) & _FPCLASS_NZ)
3004 # define Perl_fp_class_pzero(x) (_fpclass(x) & _FPCLASS_PZ)
3005 # define Perl_fp_class_zero(x) (_fpclass(x) & (_FPCLASS_NZ|_FPCLASS_PZ))
3009 #if !defined(Perl_fp_class_inf) && \
3010 defined(Perl_fp_class_pinf) && defined(Perl_fp_class_ninf)
3011 # define Perl_fp_class_inf(x) \
3012 (Perl_fp_class_pinf(x) || Perl_fp_class_ninf(x))
3015 #if !defined(Perl_fp_class_nan) && \
3016 defined(Perl_fp_class_snan) && defined(Perl_fp_class_qnan)
3017 # define Perl_fp_class_nan(x) \
3018 (Perl_fp_class_snan(x) || Perl_fp_class_qnan(x))
3021 #if !defined(Perl_fp_class_zero) && \
3022 defined(Perl_fp_class_pzero) && defined(Perl_fp_class_nzero)
3023 # define Perl_fp_class_zero(x) \
3024 (Perl_fp_class_pzero(x) || Perl_fp_class_nzero(x))
3027 #if !defined(Perl_fp_class_norm) && \
3028 defined(Perl_fp_class_pnorm) && defined(Perl_fp_class_nnorm)
3029 # define Perl_fp_class_norm(x) \
3030 (Perl_fp_class_pnorm(x) || Perl_fp_class_nnorm(x))
3033 #if !defined(Perl_fp_class_denorm) && \
3034 defined(Perl_fp_class_pdenorm) && defined(Perl_fp_class_ndenorm)
3035 # define Perl_fp_class_denorm(x) \
3036 (Perl_fp_class_pdenorm(x) || Perl_fp_class_ndenorm(x))
3040 # ifdef Perl_fp_class_nan
3041 # define Perl_isnan(x) Perl_fp_class_nan(x)
3042 # elif defined(HAS_UNORDERED)
3043 # define Perl_isnan(x) unordered((x), 0.0)
3045 # define Perl_isnan(x) ((x)!=(x))
3050 # ifdef Perl_fp_class_inf
3051 # define Perl_isinf(x) Perl_fp_class_inf(x)
3055 #ifndef Perl_isfinite
3056 # if defined(HAS_ISFINITE) && !defined(isfinite)
3057 # define Perl_isfinite(x) isfinite((double)(x))
3058 # elif defined(HAS_FINITE)
3059 # define Perl_isfinite(x) finite((double)(x))
3060 # elif defined(Perl_fp_class_finite)
3061 # define Perl_isfinite(x) Perl_fp_class_finite(x)
3063 /* For the infinities the multiplication returns nan,
3064 * for the nan the multiplication also returns nan,
3065 * for everything else (that is, finite) zero should be returned. */
3066 # define Perl_isfinite(x) (((x) * 0) == 0)
3071 # if defined(Perl_isfinite) && defined(Perl_isnan)
3072 # define Perl_isinf(x) !(Perl_isfinite(x)||Perl_isnan(x))
3076 /* We need Perl_isfinitel (ends with ell) (if available) even when
3077 * not USE_LONG_DOUBLE because the printf code (sv_catpvfn_flags)
3079 #if defined(HAS_LONG_DOUBLE) && !defined(Perl_isfinitel)
3080 /* If isfinite() is a macro and looks like we have C99,
3081 * we assume it's the type-aware C99 isfinite(). */
3082 # if defined(HAS_ISFINITE) && defined(isfinite) && defined(HAS_C99)
3083 # define Perl_isfinitel(x) isfinite(x)
3084 # elif defined(HAS_ISFINITEL)
3085 # define Perl_isfinitel(x) isfinitel(x)
3086 # elif defined(HAS_FINITEL)
3087 # define Perl_isfinitel(x) finitel(x)
3088 # elif defined(HAS_ISINFL) && defined(HAS_ISNANL)
3089 # define Perl_isfinitel(x) !(isinfl(x)||isnanl(x))
3091 # define Perl_isfinitel(x) ((x) * 0 == 0) /* See Perl_isfinite. */
3095 /* The default is to use Perl's own atof() implementation (in numeric.c).
3096 * This knows about if 'use locale' is in effect or not, and handles the radix
3097 * character accordingly. On some platforms (e.g. UNICOS) it is however best
3098 * to use the native implementation of atof, as long as you accept that the
3099 * current underlying locale will affect the radix character. Perl's version
3100 * uses a dot for a radix, execpt within the lexical scope of a Perl C<use
3101 * locale> statement.
3103 * You can experiment with using your native one by -DUSE_PERL_ATOF=0.
3104 * Some good tests to try out with either setting are t/base/num.t,
3105 * t/op/numconvert.t, and t/op/pack.t. Note that if using long doubles
3106 * you may need to be using a different function than atof! */
3108 #ifndef USE_PERL_ATOF
3110 # define USE_PERL_ATOF
3113 # if USE_PERL_ATOF == 0
3114 # undef USE_PERL_ATOF
3118 #ifdef USE_PERL_ATOF
3119 # define Perl_atof(s) Perl_my_atof(aTHX_ s)
3120 # define Perl_atof2(s, n) Perl_my_atof3(aTHX_ (s), &(n), 0)
3122 # define Perl_atof(s) (NV)atof(s)
3123 # define Perl_atof2(s, n) ((n) = atof(s))
3125 #define my_atof2(a,b) my_atof3(a,b,0)
3128 =for apidoc AmTR|NV|Atof|NN const char * const s
3130 This is a synonym for L</C<my_atof>>.
3136 #define Atof my_atof
3139 =for apidoc_section $numeric
3140 =for apidoc AmT|NV|Perl_acos|NV x
3141 =for apidoc_item |NV|Perl_asin|NV x
3142 =for apidoc_item |NV|Perl_atan|NV x
3143 =for apidoc_item |NV|Perl_atan2|NV x|NV y
3144 =for apidoc_item |NV|Perl_ceil|NV x
3145 =for apidoc_item |NV|Perl_cos|NV x
3146 =for apidoc_item |NV|Perl_cosh|NV x
3147 =for apidoc_item |NV|Perl_exp|NV x
3148 =for apidoc_item |NV|Perl_floor|NV x
3149 =for apidoc_item |NV|Perl_fmod|NV x|NV y
3150 =for apidoc_item |NV|Perl_frexp|NV x|int *exp
3151 =for apidoc_item |IV|Perl_isfinite|NV x
3152 =for apidoc_item |IV|Perl_isinf|NV x
3153 =for apidoc_item |IV|Perl_isnan|NV x
3154 =for apidoc_item |NV|Perl_ldexp|NV x|int exp
3155 =for apidoc_item |NV|Perl_log|NV x
3156 =for apidoc_item |NV|Perl_log10|NV x
3157 =for apidoc_item |NV|Perl_modf|NV x|NV *iptr
3158 =for apidoc_item |NV|Perl_pow|NV x|NV y
3159 =for apidoc_item |NV|Perl_sin|NV x
3160 =for apidoc_item |NV|Perl_sinh|NV x
3161 =for apidoc_item |NV|Perl_sqrt|NV x
3162 =for apidoc_item |NV|Perl_tan|NV x
3163 =for apidoc_item |NV|Perl_tanh|NV x
3165 These perform the corresponding mathematical operation on the operand(s), using
3166 the libc function designed for the task that has just enough precision for an
3167 NV on this platform. If no such function with sufficient precision exists,
3168 the highest precision one available is used.
3175 * CHAR_MIN and CHAR_MAX are not included here, as the (char) type may be
3176 * ambiguous. It may be equivalent to (signed char) or (unsigned char)
3177 * depending on local options. Until Configure detects this (or at least
3178 * detects whether the "signed" keyword is available) the CHAR ranges
3179 * will not be included. UCHAR functions normally.
3183 #define PERL_UCHAR_MIN ((unsigned char)0)
3184 #define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX)
3186 #define PERL_USHORT_MIN ((unsigned short)0)
3187 #define PERL_USHORT_MAX ((unsigned short)USHRT_MAX)
3189 #define PERL_SHORT_MAX ((short)SHRT_MAX)
3190 #define PERL_SHORT_MIN ((short)SHRT_MIN)
3192 #define PERL_UINT_MAX ((unsigned int)UINT_MAX)
3193 #define PERL_UINT_MIN ((unsigned int)0)
3195 #define PERL_INT_MAX ((int)INT_MAX)
3196 #define PERL_INT_MIN ((int)INT_MIN)
3198 #define PERL_ULONG_MAX ((unsigned long)ULONG_MAX)
3199 #define PERL_ULONG_MIN ((unsigned long)0L)
3201 #define PERL_LONG_MAX ((long)LONG_MAX)
3202 #define PERL_LONG_MIN ((long)LONG_MIN)
3205 # define PERL_UQUAD_MAX (~(UV)0)
3206 # define PERL_UQUAD_MIN ((UV)0)
3207 # define PERL_QUAD_MAX ((IV) (PERL_UQUAD_MAX >> 1))
3208 # define PERL_QUAD_MIN (-PERL_QUAD_MAX - ((3 & -1) == 3))
3212 =for apidoc_section $integer
3214 =for apidoc Amn |int|PERL_INT_MAX
3215 =for apidoc_item |int|PERL_INT_MIN
3216 =for apidoc_item |long|PERL_LONG_MAX
3217 =for apidoc_item |long|PERL_LONG_MIN
3218 =for apidoc_item |IV|PERL_QUAD_MAX
3219 =for apidoc_item |IV|PERL_QUAD_MIN
3220 =for apidoc_item |short|PERL_SHORT_MAX
3221 =for apidoc_item |short|PERL_SHORT_MIN
3222 =for apidoc_item |U8|PERL_UCHAR_MAX
3223 =for apidoc_item |U8|PERL_UCHAR_MIN
3224 =for apidoc_item |unsigned int|PERL_UINT_MAX
3225 =for apidoc_item |unsigned int|PERL_UINT_MIN
3226 =for apidoc_item |unsigned long|PERL_ULONG_MAX
3227 =for apidoc_item |unsigned long|PERL_ULONG_MIN
3228 =for apidoc_item |UV|PERL_UQUAD_MAX
3229 =for apidoc_item |UV|PERL_UQUAD_MIN
3230 =for apidoc_item |unsigned short|PERL_USHORT_MAX
3231 =for apidoc_item |unsigned short|PERL_USHORT_MIN
3233 These give the largest and smallest number representable in the current
3234 platform in variables of the corresponding types.
3236 For signed types, the smallest representable number is the most negative
3237 number, the one furthest away from zero.
3239 For C99 and later compilers, these correspond to things like C<INT_MAX>, which
3240 are available to the C code. But these constants, furnished by Perl,
3241 allow code compiled on earlier compilers to portably have access to the same
3248 typedef MEM_SIZE STRLEN;
3250 typedef struct op OP;
3251 typedef struct cop COP;
3252 typedef struct unop UNOP;
3253 typedef struct unop_aux UNOP_AUX;
3254 typedef struct binop BINOP;
3255 typedef struct listop LISTOP;
3256 typedef struct logop LOGOP;
3257 typedef struct pmop PMOP;
3258 typedef struct svop SVOP;
3259 typedef struct padop PADOP;
3260 typedef struct pvop PVOP;
3261 typedef struct loop LOOP;
3262 typedef struct methop METHOP;
3265 typedef struct opslab OPSLAB;
3266 typedef struct opslot OPSLOT;
3269 typedef struct block_hooks BHK;
3270 typedef struct custom_op XOP;
3272 typedef struct interpreter PerlInterpreter;
3274 /* SGI's <sys/sema.h> has struct sv */
3276 # define STRUCT_SV perl_sv
3278 # define STRUCT_SV sv
3280 typedef struct STRUCT_SV SV;
3281 typedef struct av AV;
3282 typedef struct hv HV;
3283 typedef struct cv CV;
3284 typedef struct p5rx REGEXP;
3285 typedef struct gp GP;
3286 typedef struct gv GV;
3287 typedef struct io IO;
3288 typedef struct context PERL_CONTEXT;
3289 typedef struct block BLOCK;
3290 typedef struct invlist INVLIST;
3292 typedef struct magic MAGIC;
3293 typedef struct xpv XPV;
3294 typedef struct xpviv XPVIV;
3295 typedef struct xpvuv XPVUV;
3296 typedef struct xpvnv XPVNV;
3297 typedef struct xpvmg XPVMG;
3298 typedef struct xpvlv XPVLV;
3299 typedef struct xpvinvlist XINVLIST;
3300 typedef struct xpvav XPVAV;
3301 typedef struct xpvhv XPVHV;
3302 typedef struct xpvgv XPVGV;
3303 typedef struct xpvcv XPVCV;
3304 typedef struct xpvbm XPVBM;
3305 typedef struct xpvfm XPVFM;
3306 typedef struct xpvio XPVIO;
3307 typedef struct mgvtbl MGVTBL;
3308 typedef union any ANY;
3309 typedef struct ptr_tbl_ent PTR_TBL_ENT_t;
3310 typedef struct ptr_tbl PTR_TBL_t;
3311 typedef struct clone_params CLONE_PARAMS;
3313 /* a pad is currently just an AV; but that might change,
3314 * so hide the type. */
3315 typedef struct padlist PADLIST;
3317 typedef struct padnamelist PADNAMELIST;
3318 typedef struct padname PADNAME;
3320 /* always enable PERL_OP_PARENT */
3321 #if !defined(PERL_OP_PARENT)
3322 # define PERL_OP_PARENT
3325 /* enable PERL_COPY_ON_WRITE by default */
3326 #if !defined(PERL_COPY_ON_WRITE) && !defined(PERL_NO_COW)
3327 # define PERL_COPY_ON_WRITE
3330 #ifdef PERL_COPY_ON_WRITE
3331 # define PERL_ANY_COW
3333 # define PERL_SAWAMPERSAND
3336 #if defined(PERL_DEBUG_READONLY_OPS) && !defined(USE_ITHREADS)
3337 # error PERL_DEBUG_READONLY_OPS only works with ithreads
3341 #include "charclass_invlists.h"
3343 #if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_RAWIO)
3344 # if LSEEKSIZE == 8 && !defined(USE_64_BIT_RAWIO)
3345 # define USE_64_BIT_RAWIO /* implicit */
3349 /* Notice the use of HAS_FSEEKO: now we are obligated to always use
3350 * fseeko/ftello if possible. Don't go #defining ftell to ftello yourself,
3351 * however, because operating systems like to do that themself. */
3354 # define FSEEKSIZE LSEEKSIZE
3356 # define FSEEKSIZE LONGSIZE
3360 #if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_STDIO)
3361 # if FSEEKSIZE == 8 && !defined(USE_64_BIT_STDIO)
3362 # define USE_64_BIT_STDIO /* implicit */
3366 #ifdef USE_64_BIT_RAWIO
3369 # define Off_t off64_t
3371 # define LSEEKSIZE 8
3373 /* Most 64-bit environments have defines like _LARGEFILE_SOURCE that
3374 * will trigger defines like the ones below. Some 64-bit environments,
3375 * however, do not. Therefore we have to explicitly mix and match. */
3376 # if defined(USE_OPEN64)
3377 # define open open64
3379 # if defined(USE_LSEEK64)
3380 # define lseek lseek64
3382 # if defined(USE_LLSEEK)
3383 # define lseek llseek
3386 # if defined(USE_STAT64)
3387 # define stat stat64
3389 # if defined(USE_FSTAT64)
3390 # define fstat fstat64
3392 # if defined(USE_LSTAT64)
3393 # define lstat lstat64
3395 # if defined(USE_FLOCK64)
3396 # define flock flock64
3398 # if defined(USE_LOCKF64)
3399 # define lockf lockf64
3401 # if defined(USE_FCNTL64)
3402 # define fcntl fcntl64
3404 # if defined(USE_TRUNCATE64)
3405 # define truncate truncate64
3407 # if defined(USE_FTRUNCATE64)
3408 # define ftruncate ftruncate64
3412 #ifdef USE_64_BIT_STDIO
3413 # ifdef HAS_FPOS64_T
3415 # define Fpos_t fpos64_t
3417 /* Most 64-bit environments have defines like _LARGEFILE_SOURCE that
3418 * will trigger defines like the ones below. Some 64-bit environments,
3419 * however, do not. */
3420 # if defined(USE_FOPEN64)
3421 # define fopen fopen64
3423 # if defined(USE_FSEEK64)
3424 # define fseek fseek64 /* don't do fseeko here, see perlio.c */
3426 # if defined(USE_FTELL64)
3427 # define ftell ftell64 /* don't do ftello here, see perlio.c */
3429 # if defined(USE_FSETPOS64)
3430 # define fsetpos fsetpos64
3432 # if defined(USE_FGETPOS64)
3433 # define fgetpos fgetpos64
3435 # if defined(USE_TMPFILE64)
3436 # define tmpfile tmpfile64
3438 # if defined(USE_FREOPEN64)
3439 # define freopen freopen64
3444 # include "iperlsys.h"
3449 # include "os2ish.h"
3451 # include "dosish.h"
3454 # include "vmsish.h"
3455 #elif defined(PLAN9)
3456 # include "./plan9/plan9ish.h"
3457 #elif defined(__VOS__)
3459 # include "./vos/vosish.h"
3461 # include "vos/vosish.h"
3463 #elif defined(__HAIKU__)
3464 # include "haiku/haikuish.h"
3466 # include "unixish.h"
3470 # include "amigaos.h"
3471 # undef FD_CLOEXEC /* a lie in AmigaOS */
3474 /* NSIG logic from Configure --> */
3477 # define NSIG (_NSIG)
3478 # elif defined(SIGMAX)
3479 # define NSIG (SIGMAX+1)
3480 # elif defined(SIG_MAX)
3481 # define NSIG (SIG_MAX+1)
3482 # elif defined(_SIG_MAX)
3483 # define NSIG (_SIG_MAX+1)
3484 # elif defined(MAXSIG)
3485 # define NSIG (MAXSIG+1)
3486 # elif defined(MAX_SIG)
3487 # define NSIG (MAX_SIG+1)
3488 # elif defined(SIGARRAYSIZE)
3489 # define NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */
3490 # elif defined(_sys_nsig)
3491 # define NSIG (_sys_nsig) /* Solaris 2.5 */
3493 /* Default to some arbitrary number that's big enough to get most
3494 * of the common signals. */
3498 /* <-- NSIG logic from Configure */
3500 #ifndef NO_ENVIRON_ARRAY
3501 # define USE_ENVIRON_ARRAY
3504 #if defined(HAS_SIGACTION) && defined(SA_SIGINFO)
3505 /* having sigaction(2) means that the OS supports both 1-arg and 3-arg
3506 * signal handlers. But the perl core itself only fully supports 1-arg
3507 * handlers, so don't enable for now.
3508 * NB: POSIX::sigaction() supports both.
3510 * # define PERL_USE_3ARG_SIGHANDLER
3515 * This is an alias for the OS's siginfo_t, except that where the OS
3516 * doesn't support it, declare a dummy version instead. This allows us to
3517 * have signal handler functions which always have a Siginfo_t parameter
3518 * regardless of platform, (and which will just be passed a NULL value
3519 * where the OS doesn't support HAS_SIGACTION).
3522 #if defined(HAS_SIGACTION) && defined(SA_SIGINFO)
3523 typedef siginfo_t Siginfo_t;
3525 #ifdef si_signo /* minix */
3535 * initialise to avoid floating-point exceptions from overflow, etc
3537 #ifndef PERL_FPU_INIT
3538 # ifdef HAS_FPSETMASK
3539 # if HAS_FLOATINGPOINT_H
3540 # include <floatingpoint.h>
3542 /* Some operating systems have this as a macro, which in turn expands to a comma
3543 expression, and the last sub-expression is something that gets calculated,
3544 and then they have the gall to warn that a value computed is not used. Hence
3546 # define PERL_FPU_INIT (void)fpsetmask(0)
3547 # elif defined(SIGFPE) && defined(SIG_IGN) && !defined(PERL_MICRO)
3548 # define PERL_FPU_INIT PL_sigfpe_saved = (Sighandler_t) signal(SIGFPE, SIG_IGN)
3549 # define PERL_FPU_PRE_EXEC { Sigsave_t xfpe; rsignal_save(SIGFPE, PL_sigfpe_saved, &xfpe);
3550 # define PERL_FPU_POST_EXEC rsignal_restore(SIGFPE, &xfpe); }
3552 # define PERL_FPU_INIT
3555 #ifndef PERL_FPU_PRE_EXEC
3556 # define PERL_FPU_PRE_EXEC {
3557 # define PERL_FPU_POST_EXEC }
3560 /* In Tru64 the cc -ieee enables the IEEE math but disables traps.
3561 * We need to reenable the "invalid" trap because otherwise generation
3562 * of NaN values leaves the IEEE fp flags in bad state, leaving any further
3563 * fp ops behaving strangely (Inf + 1 resulting in zero, for example). */
3565 # include <machine/fpu.h>
3566 # define PERL_SYS_FPU_INIT \
3568 ieee_set_fp_control(IEEE_TRAP_ENABLE_INV); \
3569 signal(SIGFPE, SIG_IGN); \
3572 /* In IRIX the default for Flush to Zero bit is true,
3573 * which means that results going below the minimum of normal
3574 * floating points go to zero, instead of going denormal/subnormal.
3575 * This is unlike almost any other system running Perl, so let's clear it.
3576 * [perl #123767] IRIX64 blead (ddce084a) opbasic/arith.t failure, originally
3577 * [perl #120426] small numbers shouldn't round to zero if they have extra floating digits
3579 * XXX The flush-to-zero behaviour should be a Configure scan.
3580 * To change the behaviour usually requires some system-specific
3581 * incantation, though, like the below. */
3583 # include <sys/fpu.h>
3584 # define PERL_SYS_FPU_INIT \
3586 union fpc_csr csr; \
3587 csr.fc_word = get_fpc_csr(); \
3588 csr.fc_struct.flush = 0; \
3589 set_fpc_csr(csr.fc_word); \
3593 #ifndef PERL_SYS_FPU_INIT
3594 # define PERL_SYS_FPU_INIT NOOP
3597 #ifndef PERL_SYS_INIT3_BODY
3598 # define PERL_SYS_INIT3_BODY(argvp,argcp,envp) PERL_SYS_INIT_BODY(argvp,argcp)
3602 =for apidoc_section $embedding
3604 =for apidoc Am|void|PERL_SYS_INIT |int *argc|char*** argv
3605 =for apidoc_item| |PERL_SYS_INIT3|int *argc|char*** argv|char*** env
3607 These provide system-specific tune up of the C runtime environment necessary to
3608 run Perl interpreters. Only one should be used, and it should be called only
3609 once, before creating any Perl interpreters.
3611 They differ in that C<PERL_SYS_INIT3> also initializes C<env>.
3613 =for apidoc Am|void|PERL_SYS_TERM|
3614 Provides system-specific clean up of the C runtime environment after
3615 running Perl interpreters. This should be called only once, after
3616 freeing any remaining Perl interpreters.
3621 #define PERL_SYS_INIT(argc, argv) Perl_sys_init(argc, argv)
3622 #define PERL_SYS_INIT3(argc, argv, env) Perl_sys_init3(argc, argv, env)
3623 #define PERL_SYS_TERM() Perl_sys_term()
3625 #ifndef PERL_WRITE_MSG_TO_CONSOLE
3626 # define PERL_WRITE_MSG_TO_CONSOLE(io, msg, len) PerlIO_write(io, msg, len)
3631 # ifdef _POSIX_PATH_MAX
3632 # if PATH_MAX > _POSIX_PATH_MAX
3633 /* POSIX 1990 (and pre) was ambiguous about whether PATH_MAX
3634 * included the null byte or not. Later amendments of POSIX,
3635 * XPG4, the Austin Group, and the Single UNIX Specification
3636 * all explicitly include the null byte in the PATH_MAX.
3637 * Ditto for _POSIX_PATH_MAX. */
3638 # define MAXPATHLEN PATH_MAX
3640 # define MAXPATHLEN _POSIX_PATH_MAX
3643 # define MAXPATHLEN (PATH_MAX+1)
3646 # define MAXPATHLEN 1024 /* Err on the large side. */
3650 /* clang Thread Safety Analysis/Annotations/Attributes
3651 * http://clang.llvm.org/docs/ThreadSafetyAnalysis.html
3653 * Available since clang 3.6-ish (appeared in 3.4, but shaky still in 3.5).
3654 * Apple XCode hijacks __clang_major__ and __clang_minor__
3655 * (6.1 means really clang 3.6), so needs extra hijinks
3656 * (could probably also test the contents of __apple_build_version__).
3658 #if defined(USE_ITHREADS) && defined(I_PTHREAD) && \
3659 defined(__clang__) && \
3661 ((!defined(__apple_build_version__) && \
3662 ((__clang_major__ == 3 && __clang_minor__ >= 6) || \
3663 (__clang_major__ >= 4))) || \
3664 (defined(__apple_build_version__) && \
3665 ((__clang_major__ == 6 && __clang_minor__ >= 1) || \
3666 (__clang_major__ >= 7))))
3667 # define PERL_TSA__(x) __attribute__((x))
3668 # define PERL_TSA_ACTIVE
3670 # define PERL_TSA__(x) /* No TSA, make TSA attributes no-ops. */
3671 # undef PERL_TSA_ACTIVE
3674 /* PERL_TSA_CAPABILITY() is used to annotate typedefs.
3675 * typedef old_type PERL_TSA_CAPABILITY("mutex") new_type;
3677 #define PERL_TSA_CAPABILITY(x) \
3678 PERL_TSA__(capability(x))
3680 /* In the below examples the mutex must be lexically visible, usually
3681 * either as global variables, or as function arguments. */
3683 /* PERL_TSA_GUARDED_BY() is used to annotate global variables.
3685 * Foo foo PERL_TSA_GUARDED_BY(mutex);
3687 #define PERL_TSA_GUARDED_BY(x) \
3688 PERL_TSA__(guarded_by(x))
3690 /* PERL_TSA_PT_GUARDED_BY() is used to annotate global pointers.
3691 * The data _behind_ the pointer is guarded.
3693 * Foo* ptr PERL_TSA_PT_GUARDED_BY(mutex);
3695 #define PERL_TSA_PT_GUARDED_BY(x) \
3696 PERL_TSA__(pt_guarded_by(x))
3698 /* PERL_TSA_REQUIRES() is used to annotate functions.
3699 * The caller MUST hold the resource when calling the function.
3701 * void Foo() PERL_TSA_REQUIRES(mutex);
3703 #define PERL_TSA_REQUIRES(x) \
3704 PERL_TSA__(requires_capability(x))
3706 /* PERL_TSA_EXCLUDES() is used to annotate functions.
3707 * The caller MUST NOT hold resource when calling the function.
3709 * EXCLUDES should be used when the function first acquires
3710 * the resource and then releases it. Use to avoid deadlock.
3712 * void Foo() PERL_TSA_EXCLUDES(mutex);
3714 #define PERL_TSA_EXCLUDES(x) \
3715 PERL_TSA__(locks_excluded(x))
3717 /* PERL_TSA_ACQUIRE() is used to annotate functions.
3718 * The caller MUST NOT hold the resource when calling the function,
3719 * and the function will acquire the resource.
3721 * void Foo() PERL_TSA_ACQUIRE(mutex);
3723 #define PERL_TSA_ACQUIRE(x) \
3724 PERL_TSA__(acquire_capability(x))
3726 /* PERL_TSA_RELEASE() is used to annotate functions.
3727 * The caller MUST hold the resource when calling the function,
3728 * and the function will release the resource.
3730 * void Foo() PERL_TSA_RELEASE(mutex);
3732 #define PERL_TSA_RELEASE(x) \
3733 PERL_TSA__(release_capability(x))
3735 /* PERL_TSA_NO_TSA is used to annotate functions.
3736 * Used when being intentionally unsafe, or when the code is too
3737 * complicated for the analysis. Use sparingly.
3739 * void Foo() PERL_TSA_NO_TSA;
3741 #define PERL_TSA_NO_TSA \
3742 PERL_TSA__(no_thread_safety_analysis)
3744 /* There are more annotations/attributes available, see the clang
3745 * documentation for details. */
3747 #if defined(USE_ITHREADS)
3749 # include <win32thread.h>
3751 # include "os2thread.h"
3752 # elif defined(I_MACH_CTHREADS)
3753 # include <mach/cthreads.h>
3754 typedef cthread_t perl_os_thread;
3755 typedef mutex_t perl_mutex;
3756 typedef condition_t perl_cond;
3757 typedef void * perl_key;
3758 # elif defined(I_PTHREAD) /* Posix threads */
3759 # include <pthread.h>
3760 typedef pthread_t perl_os_thread;
3761 typedef pthread_mutex_t PERL_TSA_CAPABILITY("mutex") perl_mutex;
3762 typedef pthread_cond_t perl_cond;
3763 typedef pthread_key_t perl_key;
3766 /* Many readers; single writer */
3770 SSize_t readers_count;
3771 } perl_RnW1_mutex_t;
3774 #endif /* USE_ITHREADS */
3776 #ifdef PERL_TSA_ACTIVE
3777 /* Since most pthread mutex interfaces have not been annotated, we
3778 * need to have these wrappers. The NO_TSA annotation is quite ugly
3779 * but it cannot be avoided in plain C, unlike in C++, where one could
3780 * e.g. use ACQUIRE() with no arg on a mutex lock method.
3782 * The bodies of these wrappers are in util.c
3784 * TODO: however, some platforms are starting to get these clang
3785 * thread safety annotations for pthreads, for example FreeBSD.
3786 * Do we need a way to a bypass these wrappers? */
3787 EXTERN_C int perl_tsa_mutex_lock(perl_mutex* mutex)
3788 PERL_TSA_ACQUIRE(*mutex)
3790 EXTERN_C int perl_tsa_mutex_unlock(perl_mutex* mutex)
3791 PERL_TSA_RELEASE(*mutex)
3799 #define STATUS_UNIX PL_statusvalue
3801 # define STATUS_NATIVE PL_statusvalue_vms
3803 * vaxc$errno is only guaranteed to be valid if errno == EVMSERR, otherwise
3804 * its contents can not be trusted. Unfortunately, Perl seems to check
3805 * it on exit, so it when PL_statusvalue_vms is updated, vaxc$errno should
3808 # include <stsdef.h>
3810 /* Presume this because if VMS changes it, it will require a new
3811 * set of APIs for waiting on children for binary compatibility.
3813 # define child_offset_bits (8)
3814 # ifndef C_FAC_POSIX
3815 # define C_FAC_POSIX 0x35A000
3818 /* STATUS_EXIT - validates and returns a NATIVE exit status code for the
3819 * platform from the existing UNIX or Native status values.
3822 # define STATUS_EXIT \
3823 (((I32)PL_statusvalue_vms == -1 ? SS$_ABORT : PL_statusvalue_vms) | \
3824 (VMSISH_HUSHED ? STS$M_INHIB_MSG : 0))
3827 /* STATUS_NATIVE_CHILD_SET - Calculate UNIX status that matches the child
3828 * exit code and shifts the UNIX value over the correct number of bits to
3829 * be a child status. Usually the number of bits is 8, but that could be
3830 * platform dependent. The NATIVE status code is presumed to have either
3831 * from a child process.
3834 /* This is complicated. The child processes return a true native VMS
3835 status which must be saved. But there is an assumption in Perl that
3836 the UNIX child status has some relationship to errno values, so
3837 Perl tries to translate it to text in some of the tests.
3838 In order to get the string translation correct, for the error, errno
3839 must be EVMSERR, but that generates a different text message
3840 than what the test programs are expecting. So an errno value must
3841 be derived from the native status value when an error occurs.
3842 That will hide the true native status message. With this version of
3843 perl, the true native child status can always be retrieved so that
3844 is not a problem. But in this case, Pl_statusvalue and errno may
3845 have different values in them.
3848 # define STATUS_NATIVE_CHILD_SET(n) \
3850 I32 evalue = (I32)n; \
3851 if (evalue == EVMSERR) { \
3852 PL_statusvalue_vms = vaxc$errno; \
3853 PL_statusvalue = evalue; \
3855 PL_statusvalue_vms = evalue; \
3856 if (evalue == -1) { \
3857 PL_statusvalue = -1; \
3858 PL_statusvalue_vms = SS$_ABORT; /* Should not happen */ \
3860 PL_statusvalue = Perl_vms_status_to_unix(evalue, 1); \
3861 set_vaxc_errno(evalue); \
3862 if ((PL_statusvalue_vms & C_FAC_POSIX) == C_FAC_POSIX) \
3863 set_errno(EVMSERR); \
3864 else set_errno(Perl_vms_status_to_unix(evalue, 0)); \
3865 PL_statusvalue = PL_statusvalue << child_offset_bits; \
3869 # ifdef VMSISH_STATUS
3870 # define STATUS_CURRENT (VMSISH_STATUS ? STATUS_NATIVE : STATUS_UNIX)
3872 # define STATUS_CURRENT STATUS_UNIX
3875 /* STATUS_UNIX_SET - takes a UNIX/POSIX errno value and attempts to update
3876 * the NATIVE status to an equivalent value. Can not be used to translate
3877 * exit code values as exit code values are not guaranteed to have any
3878 * relationship at all to errno values.
3879 * This is used when Perl is forcing errno to have a specific value.
3881 # define STATUS_UNIX_SET(n) \
3883 I32 evalue = (I32)n; \
3884 PL_statusvalue = evalue; \
3885 if (PL_statusvalue != -1) { \
3886 if (PL_statusvalue != EVMSERR) { \
3887 PL_statusvalue &= 0xFFFF; \
3888 if (MY_POSIX_EXIT) \
3889 PL_statusvalue_vms=PL_statusvalue ? SS$_ABORT : SS$_NORMAL;\
3890 else PL_statusvalue_vms = Perl_unix_status_to_vms(evalue); \
3893 PL_statusvalue_vms = vaxc$errno; \
3896 else PL_statusvalue_vms = SS$_ABORT; \
3897 set_vaxc_errno(PL_statusvalue_vms); \
3900 /* STATUS_UNIX_EXIT_SET - Takes a UNIX/POSIX exit code and sets
3901 * the NATIVE error status based on it.
3903 * When in the default mode to comply with the Perl VMS documentation,
3904 * 0 is a success and any other code sets the NATIVE status to a failure
3905 * code of SS$_ABORT.
3907 * In the new POSIX EXIT mode, native status will be set so that the
3908 * actual exit code will can be retrieved by the calling program or
3911 * If the exit code is not clearly a UNIX parent or child exit status,
3912 * it will be passed through as a VMS status.
3915 # define STATUS_UNIX_EXIT_SET(n) \
3917 I32 evalue = (I32)n; \
3918 PL_statusvalue = evalue; \
3919 if (MY_POSIX_EXIT) { \
3920 if (evalue <= 0xFF00) { \
3921 if (evalue > 0xFF) \
3922 evalue = ((U8) (evalue >> child_offset_bits)); \
3923 PL_statusvalue_vms = \
3924 (C_FAC_POSIX | (evalue << 3 ) | \
3925 ((evalue == 1) ? (STS$K_ERROR | STS$M_INHIB_MSG) : 1)); \
3926 } else /* forgive them Perl, for they have sinned */ \
3927 PL_statusvalue_vms = evalue; \
3930 PL_statusvalue_vms = SS$_NORMAL; \
3931 else if (evalue <= 0xFF00) \
3932 PL_statusvalue_vms = SS$_ABORT; \
3933 else { /* forgive them Perl, for they have sinned */ \
3934 if (evalue != EVMSERR) PL_statusvalue_vms = evalue; \
3935 else PL_statusvalue_vms = vaxc$errno; \
3936 /* And obviously used a VMS status value instead of UNIX */ \
3937 PL_statusvalue = EVMSERR; \
3939 set_vaxc_errno(PL_statusvalue_vms); \
3944 /* STATUS_EXIT_SET - Takes a NATIVE/UNIX/POSIX exit code
3945 * and sets the NATIVE error status based on it. This special case
3946 * is needed to maintain compatibility with past VMS behavior.
3948 * In the default mode on VMS, this number is passed through as
3949 * both the NATIVE and UNIX status. Which makes it different
3950 * that the STATUS_UNIX_EXIT_SET.
3952 * In the new POSIX EXIT mode, native status will be set so that the
3953 * actual exit code will can be retrieved by the calling program or
3956 * A POSIX exit code is from 0 to 255. If the exit code is higher
3957 * than this, it needs to be assumed that it is a VMS exit code and
3961 # define STATUS_EXIT_SET(n) \
3963 I32 evalue = (I32)n; \
3964 PL_statusvalue = evalue; \
3965 if (MY_POSIX_EXIT) \
3966 if (evalue > 255) PL_statusvalue_vms = evalue; else { \
3967 PL_statusvalue_vms = \
3968 (C_FAC_POSIX | (evalue << 3 ) | \
3969 ((evalue == 1) ? (STS$K_ERROR | STS$M_INHIB_MSG) : 1));} \
3971 PL_statusvalue_vms = evalue ? evalue : SS$_NORMAL; \
3972 set_vaxc_errno(PL_statusvalue_vms); \
3976 /* This macro forces a success status */
3977 # define STATUS_ALL_SUCCESS \
3978 (PL_statusvalue = 0, PL_statusvalue_vms = SS$_NORMAL)
3980 /* This macro forces a failure status */
3981 # define STATUS_ALL_FAILURE (PL_statusvalue = 1, \
3982 vaxc$errno = PL_statusvalue_vms = MY_POSIX_EXIT ? \
3983 (C_FAC_POSIX | (1 << 3) | STS$K_ERROR | STS$M_INHIB_MSG) : SS$_ABORT)
3985 #elif defined(__amigaos4__)
3986 /* A somewhat experimental attempt to simulate posix return code values */
3987 # define STATUS_NATIVE PL_statusvalue_posix
3988 # define STATUS_NATIVE_CHILD_SET(n) \
3990 PL_statusvalue_posix = (n); \
3991 if (PL_statusvalue_posix < 0) { \
3992 PL_statusvalue = -1; \
3995 PL_statusvalue = n << 8; \
3998 # define STATUS_UNIX_SET(n) \
4000 PL_statusvalue = (n); \
4001 if (PL_statusvalue != -1) \
4002 PL_statusvalue &= 0xFFFF; \
4004 # define STATUS_UNIX_EXIT_SET(n) STATUS_UNIX_SET(n)
4005 # define STATUS_EXIT_SET(n) STATUS_UNIX_SET(n)
4006 # define STATUS_CURRENT STATUS_UNIX
4007 # define STATUS_EXIT STATUS_UNIX
4008 # define STATUS_ALL_SUCCESS (PL_statusvalue = 0, PL_statusvalue_posix = 0)
4009 # define STATUS_ALL_FAILURE (PL_statusvalue = 1, PL_statusvalue_posix = 1)
4012 # define STATUS_NATIVE PL_statusvalue_posix
4013 # if defined(WCOREDUMP)
4014 # define STATUS_NATIVE_CHILD_SET(n) \
4016 PL_statusvalue_posix = (n); \
4017 if (PL_statusvalue_posix == -1) \
4018 PL_statusvalue = -1; \
4021 (WIFEXITED(PL_statusvalue_posix) ? (WEXITSTATUS(PL_statusvalue_posix) << 8) : 0) | \
4022 (WIFSIGNALED(PL_statusvalue_posix) ? (WTERMSIG(PL_statusvalue_posix) & 0x7F) : 0) | \
4023 (WIFSIGNALED(PL_statusvalue_posix) && WCOREDUMP(PL_statusvalue_posix) ? 0x80 : 0); \
4026 # elif defined(WIFEXITED)
4027 # define STATUS_NATIVE_CHILD_SET(n) \
4029 PL_statusvalue_posix = (n); \
4030 if (PL_statusvalue_posix == -1) \
4031 PL_statusvalue = -1; \
4034 (WIFEXITED(PL_statusvalue_posix) ? (WEXITSTATUS(PL_statusvalue_posix) << 8) : 0) | \
4035 (WIFSIGNALED(PL_statusvalue_posix) ? (WTERMSIG(PL_statusvalue_posix) & 0x7F) : 0); \
4039 # define STATUS_NATIVE_CHILD_SET(n) \
4041 PL_statusvalue_posix = (n); \
4042 if (PL_statusvalue_posix == -1) \
4043 PL_statusvalue = -1; \
4046 PL_statusvalue_posix & 0xFFFF; \
4050 # define STATUS_UNIX_SET(n) \
4052 PL_statusvalue = (n); \
4053 if (PL_statusvalue != -1) \
4054 PL_statusvalue &= 0xFFFF; \
4056 # define STATUS_UNIX_EXIT_SET(n) STATUS_UNIX_SET(n)
4057 # define STATUS_EXIT_SET(n) STATUS_UNIX_SET(n)
4058 # define STATUS_CURRENT STATUS_UNIX
4059 # define STATUS_EXIT STATUS_UNIX
4060 # define STATUS_ALL_SUCCESS (PL_statusvalue = 0, PL_statusvalue_posix = 0)
4061 # define STATUS_ALL_FAILURE (PL_statusvalue = 1, PL_statusvalue_posix = 1)
4064 /* flags in PL_exit_flags for nature of exit() */
4065 #define PERL_EXIT_EXPECTED 0x01
4066 #define PERL_EXIT_DESTRUCT_END 0x02 /* Run END in perl_destruct */
4067 #define PERL_EXIT_WARN 0x04 /* Warn if Perl_my_exit() or Perl_my_failure_exit() called */
4068 #define PERL_EXIT_ABORT 0x08 /* Call abort() if Perl_my_exit() or Perl_my_failure_exit() called */
4071 /* format to use for version numbers in file/directory names */
4072 /* XXX move to Configure? */
4073 /* This was only ever used for the current version, and that can be done at
4074 compile time, as PERL_FS_VERSION, so should we just delete it? */
4075 # ifndef PERL_FS_VER_FMT
4076 # define PERL_FS_VER_FMT "%d.%d.%d"
4080 #ifndef PERL_FS_VERSION
4081 # define PERL_FS_VERSION PERL_VERSION_STRING
4086 =for apidoc_section $io
4087 =for apidoc Amn|void|PERL_FLUSHALL_FOR_CHILD
4089 This defines a way to flush all output buffers. This may be a
4090 performance issue, so we allow people to disable it. Also, if
4091 we are using stdio, there are broken implementations of fflush(NULL)
4092 out there, Solaris being the most prominent.
4097 #ifndef PERL_FLUSHALL_FOR_CHILD
4098 # if defined(USE_PERLIO) || defined(FFLUSH_NULL)
4099 # define PERL_FLUSHALL_FOR_CHILD PerlIO_flush((PerlIO*)NULL)
4100 # elif defined(FFLUSH_ALL)
4101 # define PERL_FLUSHALL_FOR_CHILD my_fflush_all()
4103 # define PERL_FLUSHALL_FOR_CHILD NOOP
4107 #ifndef PERL_WAIT_FOR_CHILDREN
4108 # define PERL_WAIT_FOR_CHILDREN NOOP
4111 /* the traditional thread-unsafe notion of "current interpreter". */
4112 #ifndef PERL_SET_INTERP
4113 # define PERL_SET_INTERP(i) (PL_curinterp = (PerlInterpreter*)(i))
4116 #ifndef PERL_GET_INTERP
4117 # define PERL_GET_INTERP (PL_curinterp)
4120 #if defined(MULTIPLICITY) && !defined(PERL_GET_THX)
4121 # define PERL_GET_THX ((PerlInterpreter *)PERL_GET_CONTEXT)
4122 # define PERL_SET_THX(t) PERL_SET_CONTEXT(t)
4126 This replaces the previous %_ "hack" by the "%p" hacks.
4127 All that is required is that the perl source does not
4128 use "%-p" or "%-<number>p" or "%<number>p" formats.
4129 These formats will still work in perl code.
4130 See comments in sv.c for further details.
4132 Robin Barker 2005-07-14
4134 No longer use %1p for VDf = %vd. RMB 2007-10-19
4138 # define SVf_(n) "-" STRINGIFY(n) "p"
4146 # define SVf32 SVf_(32)
4150 # define SVf256 SVf_(256)
4153 #define SVfARG(p) ((void*)(p))
4155 /* Render an SV as a quoted and escaped string suitable for an error message.
4156 * Only shows the first PERL_QUOTEDPREFIX_LEN characters, and adds ellipses if the
4157 * string is too long.
4159 #ifndef PERL_QUOTEDPREFIX_LEN
4160 # define PERL_QUOTEDPREFIX_LEN 256
4162 #ifndef SVf_QUOTEDPREFIX
4163 # define SVf_QUOTEDPREFIX "5p"
4166 /* like %s but runs through the quoted prefix logic */
4167 #ifndef PVf_QUOTEDPREFIX
4168 # define PVf_QUOTEDPREFIX "1p"
4175 #ifndef HEKf_QUOTEDPREFIX
4176 # define HEKf_QUOTEDPREFIX "7p"
4179 /* Not ideal, but we cannot easily include a number in an already-numeric
4180 * format sequence. */
4182 # define HEKf256 "3p"
4185 #ifndef HEKf256_QUOTEDPREFIX
4186 # define HEKf256_QUOTEDPREFIX "8p"
4189 #define HEKfARG(p) ((void*)(p))
4191 /* Documented in perlguts
4193 * %4p and %9p are custom formats for handling UTF8 parameters.
4194 * They only occur when prefixed by specific other formats.
4197 # define UTF8f "d%" UVuf "%4p"
4199 #ifndef UTF8f_QUOTEDPREFIX
4200 # define UTF8f_QUOTEDPREFIX "d%" UVuf "%9p"
4202 #define UTF8fARG(u,l,p) (int)cBOOL(u), (UV)(l), (void*)(p)
4205 #define PNfARG(pn) (int)1, (UV)PadnameLEN(pn), (void *)PadnamePV(pn)
4209 /* not used; but needed for backward compatibility with XS code? - RMB
4210 =for apidoc_section $io_formats
4211 =for apidoc AmnD|const char *|UVf
4213 Obsolete form of C<UVuf>, which you should convert to instead use
4222 #if !defined(DEBUGGING) && !defined(NDEBUG)
4227 /* For functions that are marked as __attribute__noreturn__, it's not
4228 appropriate to call return. In either case, include the lint directive.
4230 #ifdef HASATTRIBUTE_NORETURN
4231 # define NORETURN_FUNCTION_END NOT_REACHED;
4233 # define NORETURN_FUNCTION_END NOT_REACHED; return 0
4236 #ifdef HAS_BUILTIN_EXPECT
4237 # define EXPECT(expr,val) __builtin_expect(expr,val)
4239 # define EXPECT(expr,val) (expr)
4243 =for apidoc_section $directives
4245 =for apidoc Am||LIKELY|bool expr
4247 Returns the input unchanged, but at the same time it gives a branch prediction
4248 hint to the compiler that this condition is likely to be true.
4250 =for apidoc Am||UNLIKELY|bool expr
4252 Returns the input unchanged, but at the same time it gives a branch prediction
4253 hint to the compiler that this condition is likely to be false.
4257 #define LIKELY(cond) EXPECT(cBOOL(cond),TRUE)
4258 #define UNLIKELY(cond) EXPECT(cBOOL(cond),FALSE)
4260 #ifdef HAS_BUILTIN_CHOOSE_EXPR
4264 /* STATIC_ASSERT_DECL/STATIC_ASSERT_STMT are like assert(), but for compile
4265 time invariants. That is, their argument must be a constant expression that
4266 can be verified by the compiler. This expression can contain anything that's
4267 known to the compiler, e.g. #define constants, enums, or sizeof (...). If
4268 the expression evaluates to 0, compilation fails.
4269 Because they generate no runtime code (i.e. their use is "free"), they're
4270 always active, even under non-DEBUGGING builds.
4271 STATIC_ASSERT_DECL expands to a declaration and is suitable for use at
4272 file scope (outside of any function).
4273 STATIC_ASSERT_STMT expands to a statement and is suitable for use inside a
4276 #if (! defined(__IBMC__) || __IBMC__ >= 1210) \
4277 && (( defined(static_assert) && ( defined(_ISOC11_SOURCE) \
4278 || (__STDC_VERSION__ - 0) >= 201101L)) \
4279 || (defined(__cplusplus) && __cplusplus >= 201103L))
4280 /* XXX static_assert is a macro defined in <assert.h> in C11 or a compiler
4281 builtin in C++11. But IBM XL C V11 does not support _Static_assert, no
4282 matter what <assert.h> says.
4284 # define STATIC_ASSERT_DECL(COND) static_assert(COND, #COND)
4286 /* We use a bit-field instead of an array because gcc accepts
4287 'typedef char x[n]' where n is not a compile-time constant.
4288 We want to enforce constantness.
4290 # define STATIC_ASSERT_2(COND, SUFFIX) \
4292 unsigned int _static_assertion_failed_##SUFFIX : (COND) ? 1 : -1; \
4293 } _static_assertion_failed_##SUFFIX PERL_UNUSED_DECL
4294 # define STATIC_ASSERT_1(COND, SUFFIX) STATIC_ASSERT_2(COND, SUFFIX)
4295 # define STATIC_ASSERT_DECL(COND) STATIC_ASSERT_1(COND, __LINE__)
4297 /* We need this wrapper even in C11 because 'case X: static_assert(...);' is an
4298 error (static_assert is a declaration, and only statements can have labels).
4300 #define STATIC_ASSERT_STMT(COND) STMT_START { STATIC_ASSERT_DECL(COND); } STMT_END
4302 #ifndef __has_builtin
4303 # define __has_builtin(x) 0 /* not a clang style compiler */
4307 =for apidoc Am||ASSUME|bool expr
4308 C<ASSUME> is like C<assert()>, but it has a benefit in a release build. It is a
4309 hint to a compiler about a statement of fact in a function call free
4310 expression, which allows the compiler to generate better machine code. In a
4311 debug build, C<ASSUME(x)> is a synonym for C<assert(x)>. C<ASSUME(0)> means the
4312 control path is unreachable. In a for loop, C<ASSUME> can be used to hint that
4313 a loop will run at least X times. C<ASSUME> is based off MSVC's C<__assume>
4314 intrinsic function, see its documents for more details.
4319 #if __has_builtin(__builtin_unreachable)
4320 # define HAS_BUILTIN_UNREACHABLE
4321 #elif PERL_GCC_VERSION_GE(4,5,0)
4322 # define HAS_BUILTIN_UNREACHABLE
4326 # define ASSUME(x) assert(x)
4327 #elif __has_builtin(__builtin_assume)
4328 # if defined(__clang__) || defined(__clang)
4329 # define ASSUME(x) CLANG_DIAG_IGNORE(-Wassume) \
4330 __builtin_assume (x) \
4333 # define ASSUME(x) __builtin_assume(x)
4335 #elif defined(_MSC_VER)
4336 # define ASSUME(x) __assume(x)
4337 #elif defined(__ARMCC_VERSION) /* untested */
4338 # define ASSUME(x) __promise(x)
4339 #elif defined(HAS_BUILTIN_UNREACHABLE)
4340 /* Compilers can take the hint from something being unreachable */
4341 # define ASSUME(x) ((x) ? (void) 0 : __builtin_unreachable())
4343 /* Not DEBUGGING, so assert() is a no-op, but a random compiler might
4344 * define assert() to its own special optimization token so pass it through
4345 * to C lib as a last resort */
4346 # define ASSUME(x) assert(x)
4349 #ifdef HAS_BUILTIN_UNREACHABLE
4350 # define NOT_REACHED \
4352 ASSUME(!"UNREACHABLE"); __builtin_unreachable(); \
4354 # undef HAS_BUILTIN_UNREACHABLE /* Don't leak out this internal symbol */
4355 #elif ! defined(__GNUC__) && (defined(__sun) || defined(__hpux))
4356 /* These just complain that NOT_REACHED isn't reached */
4357 # define NOT_REACHED
4359 # define NOT_REACHED ASSUME(!"UNREACHABLE")
4362 /* Some unistd.h's give a prototype for pause() even though
4363 HAS_PAUSE ends up undefined. This causes the #define
4364 below to be rejected by the compiler. Sigh.
4369 #define Pause() sleep((32767<<16)+32767)
4373 # ifdef IOCPARM_MASK
4374 /* on BSDish systems we're safe */
4375 # define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
4376 # elif defined(_IOC_SIZE) && defined(__GLIBC__)
4377 /* on Linux systems we're safe; except when we're not [perl #38223] */
4378 # define IOCPARM_LEN(x) (_IOC_SIZE(x) < 256 ? 256 : _IOC_SIZE(x))
4380 /* otherwise guess at what's safe */
4381 # define IOCPARM_LEN(x) 256
4385 #if defined(__CYGWIN__)
4387 * This symbol, if defined, indicates that the program should
4388 * use the routine my_binmode(FILE *fp, char iotype, int mode) to insure
4389 * that a file is in "binary" mode -- that is, that no translation
4390 * of bytes occurs on read or write operations.
4392 # define USEMYBINMODE /**/
4393 # include <io.h> /* for setmode() prototype */
4394 # define my_binmode(fp, iotype, mode) \
4395 cBOOL(PerlLIO_setmode(fileno(fp), mode) != -1)
4399 void init_os_extras(void);
4402 #ifdef UNION_ANY_DEFINITION
4403 UNION_ANY_DEFINITION;
4421 void (*any_dptr) (void*);
4422 void (*any_dxptr) (pTHX_ void*);
4426 typedef I32 (*filter_t) (pTHX_ int, SV *, int);
4428 #define FILTER_READ(idx, sv, len) filter_read(idx, sv, len)
4429 #define FILTER_DATA(idx) \
4430 (PL_parser ? AvARRAY(PL_parser->rsfp_filters)[idx] : NULL)
4431 #define FILTER_ISREADER(idx) \
4432 (PL_parser && PL_parser->rsfp_filters \
4433 && idx >= AvFILLp(PL_parser->rsfp_filters))
4434 #define PERL_FILTER_EXISTS(i) \
4435 (PL_parser && PL_parser->rsfp_filters \
4436 && (Size_t) (i) < av_count(PL_parser->rsfp_filters))
4438 #if defined(_AIX) && !defined(_AIX43)
4439 #if defined(USE_REENTRANT) || defined(_REENTRANT) || defined(_THREAD_SAFE)
4440 /* We cannot include <crypt.h> to get the struct crypt_data
4441 * because of setkey prototype problems when threading */
4442 typedef struct crypt_data { /* straight from /usr/include/crypt.h */
4443 /* From OSF, Not needed in AIX
4451 #endif /* threading */
4454 #ifndef PERL_CALLCONV
4456 # define PERL_CALLCONV EXTERN_C
4458 # define PERL_CALLCONV
4461 #ifndef PERL_CALLCONV_NO_RET
4462 # define PERL_CALLCONV_NO_RET PERL_CALLCONV
4465 /* PERL_STATIC_NO_RET is supposed to be equivalent to STATIC on builds that
4466 dont have a noreturn as a declaration specifier
4468 #ifndef PERL_STATIC_NO_RET
4469 # define PERL_STATIC_NO_RET STATIC
4472 /* PERL_STATIC_INLINE_NO_RET is supposed to be equivalent to PERL_STATIC_INLINE
4473 * on builds that dont have a noreturn as a declaration specifier
4475 #ifndef PERL_STATIC_INLINE_NO_RET
4476 # define PERL_STATIC_INLINE_NO_RET PERL_STATIC_INLINE
4479 #ifndef PERL_STATIC_FORCE_INLINE
4480 # define PERL_STATIC_FORCE_INLINE PERL_STATIC_INLINE
4483 #ifndef PERL_STATIC_FORCE_INLINE_NO_RET
4484 # define PERL_STATIC_FORCE_INLINE_NO_RET PERL_STATIC_INLINE
4488 # include "iperlsys.h"
4491 #ifdef __LIBCATAMOUNT__
4492 #undef HAS_PASSWD /* unixish.h but not unixish enough. */
4494 #define FAKE_BIT_BUCKET
4497 /* [perl #22371] Algorimic Complexity Attack on Perl 5.6.1, 5.8.0.
4498 * Note that the USE_HASH_SEED and similar defines are *NOT* defined by
4499 * Configure, despite their names being similar to other defines like
4500 * USE_ITHREADS. Configure in fact knows nothing about the randomised
4501 * hashes. Therefore to enable/disable the hash randomisation defines
4502 * use the Configure -Accflags=... instead. */
4503 #if !defined(NO_HASH_SEED) && !defined(USE_HASH_SEED)
4504 # define USE_HASH_SEED
4510 /* macros to define bit-fields in structs. */
4511 #ifndef PERL_BITFIELD8
4512 # ifdef HAS_NON_INT_BITFIELDS
4513 # define PERL_BITFIELD8 U8
4515 # define PERL_BITFIELD8 unsigned
4518 #ifndef PERL_BITFIELD16
4519 # ifdef HAS_NON_INT_BITFIELDS
4520 # define PERL_BITFIELD16 U16
4522 # define PERL_BITFIELD16 unsigned
4525 #ifndef PERL_BITFIELD32
4526 # ifdef HAS_NON_INT_BITFIELDS
4527 # define PERL_BITFIELD32 U32
4529 # define PERL_BITFIELD32 unsigned
4540 #include "opnames.h"
4547 #include "warnings.h"
4550 /* these would be in doio.h if there was such a file */
4551 #define my_stat() my_stat_flags(SV_GMAGIC)
4552 #define my_lstat() my_lstat_flags(SV_GMAGIC)
4554 /* defined in sv.c, but also used in [ach]v.c */
4557 #undef _XPVCV_COMMON
4561 typedef struct magic_state MGS; /* struct magic_state defined in mg.c */
4563 #if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C) \
4564 || defined(PERL_EXT_RE_BUILD)
4566 /* These have to be predeclared, as they are used in proto.h which is #included
4567 * before their definitions in regcomp.h. */
4570 typedef struct regnode_charclass regnode_charclass;
4572 /* A hopefully less confusing name. The sub-classes are all Posix classes only
4573 * used under /l matching */
4574 typedef struct regnode_charclass_posixl regnode_charclass_class;
4575 typedef struct regnode_charclass_posixl regnode_charclass_posixl;
4577 typedef struct regnode_ssc regnode_ssc;
4578 typedef struct RExC_state_t RExC_state_t;
4579 struct _reg_trie_data;
4583 struct ptr_tbl_ent {
4584 struct ptr_tbl_ent* next;
4590 struct ptr_tbl_ent** tbl_ary;
4593 struct ptr_tbl_arena *tbl_arena;
4594 struct ptr_tbl_ent *tbl_arena_next;
4595 struct ptr_tbl_ent *tbl_arena_end;
4598 #if defined(htonl) && !defined(HAS_HTONL)
4601 #if defined(htons) && !defined(HAS_HTONS)
4604 #if defined(ntohl) && !defined(HAS_NTOHL)
4607 #if defined(ntohs) && !defined(HAS_NTOHS)
4615 # if (BYTEORDER & 0xffff) == 0x4321
4616 /* Big endian system, so ntohl, ntohs, htonl and htons do not need to
4617 re-order their values. However, to behave identically to the alternative
4618 implementations, they should truncate to the correct size. */
4619 # define ntohl(x) ((x)&0xFFFFFFFF)
4620 # define htonl(x) ntohl(x)
4621 # define ntohs(x) ((x)&0xFFFF)
4622 # define htons(x) ntohs(x)
4623 # elif BYTEORDER == 0x1234 || BYTEORDER == 0x12345678
4625 /* Note that we can't straight out declare our own htonl and htons because
4626 the Win32 build process forcibly undefines HAS_HTONL etc for its miniperl,
4627 to avoid the overhead of initialising the socket subsystem, but the headers
4628 that *declare* the various functions are still seen. If we declare our own
4629 htonl etc they will clash with the declarations in the Win32 headers. */
4631 PERL_STATIC_INLINE U32
4632 my_swap32(const U32 x) {
4633 return ((x & 0xFF) << 24) | ((x >> 24) & 0xFF)
4634 | ((x & 0x0000FF00) << 8) | ((x & 0x00FF0000) >> 8);
4637 PERL_STATIC_INLINE U16
4638 my_swap16(const U16 x) {
4639 return ((x & 0xFF) << 8) | ((x >> 8) & 0xFF);
4642 # define htonl(x) my_swap32(x)
4643 # define ntohl(x) my_swap32(x)
4644 # define ntohs(x) my_swap16(x)
4645 # define htons(x) my_swap16(x)
4647 # error "Unsupported byteorder"
4648 /* The C pre-processor doesn't let us return the value of BYTEORDER as part of
4649 the error message. Please check the value of the macro BYTEORDER, as defined
4650 in config.h. The values of BYTEORDER we expect are
4652 big endian little endian
4653 32 bit 0x4321 0x1234
4654 64 bit 0x87654321 0x12345678
4656 If you have a system with a different byte order, please see
4657 pod/perlhack.pod for how to submit a patch to add supporting code.
4663 * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
4666 #if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678
4667 /* Little endian system, so vtohl, vtohs, htovl and htovs do not need to
4668 re-order their values. However, to behave identically to the alternative
4669 implementations, they should truncate to the correct size. */
4670 # define vtohl(x) ((x)&0xFFFFFFFF)
4671 # define vtohs(x) ((x)&0xFFFF)
4672 # define htovl(x) vtohl(x)
4673 # define htovs(x) vtohs(x)
4674 #elif BYTEORDER == 0x4321 || BYTEORDER == 0x87654321
4675 # define vtohl(x) ((((x)&0xFF)<<24) \
4677 +(((x)&0x0000FF00)<<8) \
4678 +(((x)&0x00FF0000)>>8) )
4679 # define vtohs(x) ((((x)&0xFF)<<8) + (((x)>>8)&0xFF))
4680 # define htovl(x) vtohl(x)
4681 # define htovs(x) vtohs(x)
4683 # error "Unsupported byteorder"
4684 /* If you have need for current perl on PDP-11 or similar, and can help test
4685 that blead keeps working on a mixed-endian system, then see
4686 pod/perlhack.pod for how to submit patches to things working again. */
4689 /* *MAX Plus 1. A floating point value.
4690 Hopefully expressed in a way that dodgy floating point can't mess up.
4691 >> 2 rather than 1, so that value is safely less than I32_MAX after 1
4693 May find that some broken compiler will want the value cast to I32.
4694 [after the shift, as signed >> may not be as secure as unsigned >>]
4696 #define I32_MAX_P1 (2.0 * (1 + (((U32)I32_MAX) >> 1)))
4697 #define U32_MAX_P1 (4.0 * (1 + ((U32_MAX) >> 2)))
4698 /* For compilers that can't correctly cast NVs over 0x7FFFFFFF (or
4699 0x7FFFFFFFFFFFFFFF) to an unsigned integer. In the future, sizeof(UV)
4700 may be greater than sizeof(IV), so don't assume that half max UV is max IV.
4702 #define U32_MAX_P1_HALF (2.0 * (1 + ((U32_MAX) >> 2)))
4704 #define UV_MAX_P1 (4.0 * (1 + ((UV_MAX) >> 2)))
4705 #define IV_MAX_P1 (2.0 * (1 + (((UV)IV_MAX) >> 1)))
4706 #define UV_MAX_P1_HALF (2.0 * (1 + ((UV_MAX) >> 2)))
4708 /* This may look like unnecessary jumping through hoops, but converting
4709 out of range floating point values to integers *is* undefined behaviour,
4710 and it is starting to bite.
4712 =for apidoc_section $casting
4713 =for apidoc Am|I32|I_32|NV what
4714 Cast an NV to I32 while avoiding undefined C behavior
4716 =for apidoc Am|U32|U_32|NV what
4717 Cast an NV to U32 while avoiding undefined C behavior
4719 =for apidoc Am|IV|I_V|NV what
4720 Cast an NV to IV while avoiding undefined C behavior
4722 =for apidoc Am|UV|U_V|NV what
4723 Cast an NV to UV while avoiding undefined C behavior
4728 #define I_32(what) (cast_i32((NV)(what)))
4729 #define U_32(what) (cast_ulong((NV)(what)))
4730 #define I_V(what) (cast_iv((NV)(what)))
4731 #define U_V(what) (cast_uv((NV)(what)))
4733 #define I_32(n) ((n) < I32_MAX_P1 ? ((n) < I32_MIN ? I32_MIN : (I32) (n)) \
4734 : ((n) < U32_MAX_P1 ? (I32)(U32) (n) \
4735 : ((n) > 0 ? (I32) U32_MAX : 0 /* NaN */)))
4736 #define U_32(n) ((n) < 0.0 ? ((n) < I32_MIN ? (UV) I32_MIN : (U32)(I32) (n)) \
4737 : ((n) < U32_MAX_P1 ? (U32) (n) \
4738 : ((n) > 0 ? U32_MAX : 0 /* NaN */)))
4739 #define I_V(n) (LIKELY((n) < IV_MAX_P1) ? (UNLIKELY((n) < IV_MIN) ? IV_MIN : (IV) (n)) \
4740 : (LIKELY((n) < UV_MAX_P1) ? (IV)(UV) (n) \
4741 : ((n) > 0 ? (IV)UV_MAX : 0 /* NaN */)))
4742 #define U_V(n) ((n) < 0.0 ? (UNLIKELY((n) < IV_MIN) ? (UV) IV_MIN : (UV)(IV) (n)) \
4743 : (LIKELY((n) < UV_MAX_P1) ? (UV) (n) \
4744 : ((n) > 0 ? UV_MAX : 0 /* NaN */)))
4747 #define U_S(what) ((U16)U_32(what))
4748 #define U_I(what) ((unsigned int)U_32(what))
4749 #define U_L(what) U_32(what)
4752 =for apidoc_section $integer
4753 =for apidoc Amn|IV|IV_MAX
4754 The largest signed integer that fits in an IV on this platform.
4756 =for apidoc Amn|IV|IV_MIN
4757 The negative signed integer furthest away from 0 that fits in an IV on this
4760 =for apidoc Amn|UV|UV_MAX
4761 The largest unsigned integer that fits in a UV on this platform.
4763 =for apidoc Amn|UV|UV_MIN
4764 The smallest unsigned integer that fits in a UV on this platform. It should
4771 # ifndef Perl_signbit
4772 # define Perl_signbit signbit
4776 /* These do not care about the fractional part, only about the range. */
4777 #define NV_WITHIN_IV(nv) (I_V(nv) >= IV_MIN && I_V(nv) <= IV_MAX)
4778 #define NV_WITHIN_UV(nv) ((nv)>=0.0 && U_V(nv) >= UV_MIN && U_V(nv) <= UV_MAX)
4780 /* Used with UV/IV arguments: */
4781 /* XXXX: need to speed it up */
4782 #define CLUMP_2UV(iv) ((iv) < 0 ? 0 : (UV)(iv))
4783 #define CLUMP_2IV(uv) ((uv) > (UV)IV_MAX ? IV_MAX : (IV)(uv))
4791 Uid_t getuid (void);
4792 Uid_t geteuid (void);
4793 Gid_t getgid (void);
4794 Gid_t getegid (void);
4798 #ifndef Perl_debug_log
4799 # define Perl_debug_log PerlIO_stderr()
4802 #ifndef Perl_error_log
4803 # define Perl_error_log (PL_stderrgv \
4804 && isGV(PL_stderrgv) \
4805 && GvIOp(PL_stderrgv) \
4806 && IoOFP(GvIOp(PL_stderrgv)) \
4807 ? IoOFP(GvIOp(PL_stderrgv)) \
4812 #define DEBUG_p_FLAG 0x00000001 /* 1 */
4813 #define DEBUG_s_FLAG 0x00000002 /* 2 */
4814 #define DEBUG_l_FLAG 0x00000004 /* 4 */
4815 #define DEBUG_t_FLAG 0x00000008 /* 8 */
4816 #define DEBUG_o_FLAG 0x00000010 /* 16 */
4817 #define DEBUG_c_FLAG 0x00000020 /* 32 */
4818 #define DEBUG_P_FLAG 0x00000040 /* 64 */
4819 #define DEBUG_m_FLAG 0x00000080 /* 128 */
4820 #define DEBUG_f_FLAG 0x00000100 /* 256 */
4821 #define DEBUG_r_FLAG 0x00000200 /* 512 */
4822 #define DEBUG_x_FLAG 0x00000400 /* 1024 */
4823 #define DEBUG_u_FLAG 0x00000800 /* 2048 */
4824 /* U is reserved for Unofficial, exploratory hacking */
4825 #define DEBUG_U_FLAG 0x00001000 /* 4096 */
4826 #define DEBUG_h_FLAG 0x00002000 /* 8192 */
4827 #define DEBUG_X_FLAG 0x00004000 /* 16384 */
4828 #define DEBUG_D_FLAG 0x00008000 /* 32768 */
4829 #define DEBUG_S_FLAG 0x00010000 /* 65536 */
4830 #define DEBUG_T_FLAG 0x00020000 /* 131072 */
4831 #define DEBUG_R_FLAG 0x00040000 /* 262144 */
4832 #define DEBUG_J_FLAG 0x00080000 /* 524288 */
4833 #define DEBUG_v_FLAG 0x00100000 /*1048576 */
4834 #define DEBUG_C_FLAG 0x00200000 /*2097152 */
4835 #define DEBUG_A_FLAG 0x00400000 /*4194304 */
4836 #define DEBUG_q_FLAG 0x00800000 /*8388608 */
4837 #define DEBUG_M_FLAG 0x01000000 /*16777216*/
4838 #define DEBUG_B_FLAG 0x02000000 /*33554432*/
4839 #define DEBUG_L_FLAG 0x04000000 /*67108864*/
4840 #define DEBUG_i_FLAG 0x08000000 /*134217728*/
4841 #define DEBUG_y_FLAG 0x10000000 /*268435456*/
4842 #define DEBUG_MASK 0x1FFFEFFF /* mask of all the standard flags */
4844 #define DEBUG_DB_RECURSE_FLAG 0x40000000
4845 #define DEBUG_TOP_FLAG 0x80000000 /* -D was given --> PL_debug |= FLAG */
4847 /* Both flags have to be set */
4848 # define DEBUG_BOTH_FLAGS_TEST_(flag1, flag2) \
4849 UNLIKELY((PL_debug & ((flag1)|(flag2))) \
4850 == ((flag1)|(flag2)))
4852 # define DEBUG_p_TEST_ UNLIKELY(PL_debug & DEBUG_p_FLAG)
4853 # define DEBUG_s_TEST_ UNLIKELY(PL_debug & DEBUG_s_FLAG)
4854 # define DEBUG_l_TEST_ UNLIKELY(PL_debug & DEBUG_l_FLAG)
4855 # define DEBUG_t_TEST_ UNLIKELY(PL_debug & DEBUG_t_FLAG)
4856 # define DEBUG_o_TEST_ UNLIKELY(PL_debug & DEBUG_o_FLAG)
4857 # define DEBUG_c_TEST_ UNLIKELY(PL_debug & DEBUG_c_FLAG)
4858 # define DEBUG_P_TEST_ UNLIKELY(PL_debug & DEBUG_P_FLAG)
4859 # define DEBUG_m_TEST_ UNLIKELY(PL_debug & DEBUG_m_FLAG)
4860 # define DEBUG_f_TEST_ UNLIKELY(PL_debug & DEBUG_f_FLAG)
4861 # define DEBUG_r_TEST_ UNLIKELY(PL_debug & DEBUG_r_FLAG)
4862 # define DEBUG_x_TEST_ UNLIKELY(PL_debug & DEBUG_x_FLAG)
4863 # define DEBUG_u_TEST_ UNLIKELY(PL_debug & DEBUG_u_FLAG)
4864 # define DEBUG_U_TEST_ UNLIKELY(PL_debug & DEBUG_U_FLAG)
4865 # define DEBUG_h_TEST_ UNLIKELY(PL_debug & DEBUG_h_FLAG)
4866 # define DEBUG_X_TEST_ UNLIKELY(PL_debug & DEBUG_X_FLAG)
4867 # define DEBUG_D_TEST_ UNLIKELY(PL_debug & DEBUG_D_FLAG)
4868 # define DEBUG_S_TEST_ UNLIKELY(PL_debug & DEBUG_S_FLAG)
4869 # define DEBUG_T_TEST_ UNLIKELY(PL_debug & DEBUG_T_FLAG)
4870 # define DEBUG_R_TEST_ UNLIKELY(PL_debug & DEBUG_R_FLAG)
4871 # define DEBUG_J_TEST_ UNLIKELY(PL_debug & DEBUG_J_FLAG)
4872 # define DEBUG_v_TEST_ UNLIKELY(PL_debug & DEBUG_v_FLAG)
4873 # define DEBUG_C_TEST_ UNLIKELY(PL_debug & DEBUG_C_FLAG)
4874 # define DEBUG_A_TEST_ UNLIKELY(PL_debug & DEBUG_A_FLAG)
4875 # define DEBUG_q_TEST_ UNLIKELY(PL_debug & DEBUG_q_FLAG)
4876 # define DEBUG_M_TEST_ UNLIKELY(PL_debug & DEBUG_M_FLAG)
4877 # define DEBUG_B_TEST_ UNLIKELY(PL_debug & DEBUG_B_FLAG)
4879 /* Locale initialization comes earlier than PL_debug gets set,
4880 * DEBUG_LOCALE_INITIALIZATION_, if defined, will be set early enough */
4881 # ifndef DEBUG_LOCALE_INITIALIZATION_
4882 # define DEBUG_LOCALE_INITIALIZATION_ 0
4884 # define DEBUG_L_TEST_ \
4885 ( UNLIKELY(DEBUG_LOCALE_INITIALIZATION_) \
4886 || UNLIKELY(PL_debug & DEBUG_L_FLAG))
4887 # define DEBUG_Lv_TEST_ \
4888 ( UNLIKELY(DEBUG_LOCALE_INITIALIZATION_) \
4889 || UNLIKELY(DEBUG_BOTH_FLAGS_TEST_(DEBUG_L_FLAG, DEBUG_v_FLAG)))
4890 # define DEBUG_i_TEST_ UNLIKELY(PL_debug & DEBUG_i_FLAG)
4891 # define DEBUG_y_TEST_ UNLIKELY(PL_debug & DEBUG_y_FLAG)
4892 # define DEBUG_Xv_TEST_ DEBUG_BOTH_FLAGS_TEST_(DEBUG_X_FLAG, DEBUG_v_FLAG)
4893 # define DEBUG_Uv_TEST_ DEBUG_BOTH_FLAGS_TEST_(DEBUG_U_FLAG, DEBUG_v_FLAG)
4894 # define DEBUG_Pv_TEST_ DEBUG_BOTH_FLAGS_TEST_(DEBUG_P_FLAG, DEBUG_v_FLAG)
4895 # define DEBUG_yv_TEST_ DEBUG_BOTH_FLAGS_TEST_(DEBUG_y_FLAG, DEBUG_v_FLAG)
4899 # define DEBUG_p_TEST DEBUG_p_TEST_
4900 # define DEBUG_s_TEST DEBUG_s_TEST_
4901 # define DEBUG_l_TEST DEBUG_l_TEST_
4902 # define DEBUG_t_TEST DEBUG_t_TEST_
4903 # define DEBUG_o_TEST DEBUG_o_TEST_
4904 # define DEBUG_c_TEST DEBUG_c_TEST_
4905 # define DEBUG_P_TEST DEBUG_P_TEST_
4906 # define DEBUG_m_TEST DEBUG_m_TEST_
4907 # define DEBUG_f_TEST DEBUG_f_TEST_
4908 # define DEBUG_r_TEST DEBUG_r_TEST_
4909 # define DEBUG_x_TEST DEBUG_x_TEST_
4910 # define DEBUG_u_TEST DEBUG_u_TEST_
4911 # define DEBUG_U_TEST DEBUG_U_TEST_
4912 # define DEBUG_h_TEST DEBUG_h_TEST_
4913 # define DEBUG_X_TEST DEBUG_X_TEST_
4914 # define DEBUG_D_TEST DEBUG_D_TEST_
4915 # define DEBUG_S_TEST DEBUG_S_TEST_
4916 # define DEBUG_T_TEST DEBUG_T_TEST_
4917 # define DEBUG_R_TEST DEBUG_R_TEST_
4918 # define DEBUG_J_TEST DEBUG_J_TEST_
4919 # define DEBUG_v_TEST DEBUG_v_TEST_
4920 # define DEBUG_C_TEST DEBUG_C_TEST_
4921 # define DEBUG_A_TEST DEBUG_A_TEST_
4922 # define DEBUG_q_TEST DEBUG_q_TEST_
4923 # define DEBUG_M_TEST DEBUG_M_TEST_
4924 # define DEBUG_B_TEST DEBUG_B_TEST_
4925 # define DEBUG_L_TEST DEBUG_L_TEST_
4926 # define DEBUG_i_TEST DEBUG_i_TEST_
4927 # define DEBUG_y_TEST DEBUG_y_TEST_
4928 # define DEBUG_Xv_TEST DEBUG_Xv_TEST_
4929 # define DEBUG_Uv_TEST DEBUG_Uv_TEST_
4930 # define DEBUG_Pv_TEST DEBUG_Pv_TEST_
4931 # define DEBUG_Lv_TEST DEBUG_Lv_TEST_
4932 # define DEBUG_yv_TEST DEBUG_yv_TEST_
4934 # define PERL_DEB(a) a
4935 # define PERL_DEB2(a,b) a
4936 # define PERL_DEBUG(a) if (PL_debug) a
4937 # define DEBUG_p(a) if (DEBUG_p_TEST) a
4938 # define DEBUG_s(a) if (DEBUG_s_TEST) a
4939 # define DEBUG_l(a) if (DEBUG_l_TEST) a
4940 # define DEBUG_t(a) if (DEBUG_t_TEST) a
4941 # define DEBUG_o(a) if (DEBUG_o_TEST) a
4942 # define DEBUG_c(a) if (DEBUG_c_TEST) a
4943 # define DEBUG_P(a) if (DEBUG_P_TEST) a
4945 /* Temporarily turn off memory debugging in case the a
4946 * does memory allocation, either directly or indirectly. */
4947 # define DEBUG_m(a) \
4949 if (PERL_GET_INTERP) { \
4951 if (DEBUG_m_TEST) { \
4952 PL_debug &= ~DEBUG_m_FLAG; \
4954 PL_debug |= DEBUG_m_FLAG; \
4959 /* These allow you to customize your debugging output for specialized,
4960 * generally temporary ad-hoc purposes. For example, if you need 'errno'
4961 * preserved, you can add definitions to these macros (either in this file for
4962 * the whole program, or before the #include "perl.h" in a particular .c file
4963 * you're trying to debug) and recompile:
4965 * #define DEBUG_PRE_STMTS dSAVE_ERRNO;
4966 * #define DEBUG_POST_STMTS RESTORE_ERRNO;
4968 * Other potential things include displaying timestamps, location information,
4969 * which thread, etc. Heres an example with both errno and location info:
4971 * #define DEBUG_PRE_STMTS dSAVE_ERRNO; \
4972 * PerlIO_printf(Perl_debug_log, "%s:%d: ", __FILE__, __LINE__);
4973 * #define DEBUG_POST RESTORE_ERRNO;
4975 * All DEBUG statements in the compiled scope will be have these extra
4976 * statements compiled in; they will be executed only for the DEBUG statements
4977 * whose flags are turned on.
4979 #ifndef DEBUG_PRE_STMTS
4980 # define DEBUG_PRE_STMTS
4982 #ifndef DEBUG_POST_STMTS
4983 # define DEBUG_POST_STMTS
4986 # define DEBUG__(t, a) \
4988 if (t) STMT_START { \
4989 DEBUG_PRE_STMTS a; DEBUG_POST_STMTS \
4993 # define DEBUG_f(a) DEBUG__(DEBUG_f_TEST, a)
4995 /* For re_comp.c, re_exec.c, assume -Dr has been specified */
4996 # ifdef PERL_EXT_RE_BUILD
4997 # define DEBUG_r(a) STMT_START { \
4998 DEBUG_PRE_STMTS a; DEBUG_POST_STMTS \
5001 # define DEBUG_r(a) DEBUG__(DEBUG_r_TEST, a)
5002 # endif /* PERL_EXT_RE_BUILD */
5004 # define DEBUG_x(a) DEBUG__(DEBUG_x_TEST, a)
5005 # define DEBUG_u(a) DEBUG__(DEBUG_u_TEST, a)
5006 # define DEBUG_U(a) DEBUG__(DEBUG_U_TEST, a)
5007 # define DEBUG_X(a) DEBUG__(DEBUG_X_TEST, a)
5008 # define DEBUG_D(a) DEBUG__(DEBUG_D_TEST, a)
5009 # define DEBUG_Xv(a) DEBUG__(DEBUG_Xv_TEST, a)
5010 # define DEBUG_Uv(a) DEBUG__(DEBUG_Uv_TEST, a)
5011 # define DEBUG_Pv(a) DEBUG__(DEBUG_Pv_TEST, a)
5012 # define DEBUG_Lv(a) DEBUG__(DEBUG_Lv_TEST, a)
5013 # define DEBUG_yv(a) DEBUG__(DEBUG_yv_TEST, a)
5015 # define DEBUG_S(a) DEBUG__(DEBUG_S_TEST, a)
5016 # define DEBUG_T(a) DEBUG__(DEBUG_T_TEST, a)
5017 # define DEBUG_R(a) DEBUG__(DEBUG_R_TEST, a)
5018 # define DEBUG_v(a) DEBUG__(DEBUG_v_TEST, a)
5019 # define DEBUG_C(a) DEBUG__(DEBUG_C_TEST, a)
5020 # define DEBUG_A(a) DEBUG__(DEBUG_A_TEST, a)
5021 # define DEBUG_q(a) DEBUG__(DEBUG_q_TEST, a)
5022 # define DEBUG_M(a) DEBUG__(DEBUG_M_TEST, a)
5023 # define DEBUG_B(a) DEBUG__(DEBUG_B_TEST, a)
5024 # define DEBUG_L(a) DEBUG__(DEBUG_L_TEST, a)
5025 # define DEBUG_i(a) DEBUG__(DEBUG_i_TEST, a)
5026 # define DEBUG_y(a) DEBUG__(DEBUG_y_TEST, a)
5028 #else /* ! DEBUGGING below */
5030 # define DEBUG_p_TEST (0)
5031 # define DEBUG_s_TEST (0)
5032 # define DEBUG_l_TEST (0)
5033 # define DEBUG_t_TEST (0)
5034 # define DEBUG_o_TEST (0)
5035 # define DEBUG_c_TEST (0)
5036 # define DEBUG_P_TEST (0)
5037 # define DEBUG_m_TEST (0)
5038 # define DEBUG_f_TEST (0)
5039 # define DEBUG_r_TEST (0)
5040 # define DEBUG_x_TEST (0)
5041 # define DEBUG_u_TEST (0)
5042 # define DEBUG_U_TEST (0)
5043 # define DEBUG_h_TEST (0)
5044 # define DEBUG_X_TEST (0)
5045 # define DEBUG_D_TEST (0)
5046 # define DEBUG_S_TEST (0)
5047 # define DEBUG_T_TEST (0)
5048 # define DEBUG_R_TEST (0)
5049 # define DEBUG_J_TEST (0)
5050 # define DEBUG_v_TEST (0)
5051 # define DEBUG_C_TEST (0)
5052 # define DEBUG_A_TEST (0)
5053 # define DEBUG_q_TEST (0)
5054 # define DEBUG_M_TEST (0)
5055 # define DEBUG_B_TEST (0)
5056 # define DEBUG_L_TEST (0)
5057 # define DEBUG_i_TEST (0)
5058 # define DEBUG_y_TEST (0)
5059 # define DEBUG_Xv_TEST (0)
5060 # define DEBUG_Uv_TEST (0)
5061 # define DEBUG_Pv_TEST (0)
5062 # define DEBUG_Lv_TEST (0)
5063 # define DEBUG_yv_TEST (0)
5065 # define PERL_DEB(a)
5066 # define PERL_DEB2(a,b) b
5067 # define PERL_DEBUG(a)
5095 # define DEBUG_Xv(a)
5096 # define DEBUG_Uv(a)
5097 # define DEBUG_Pv(a)
5098 # define DEBUG_Lv(a)
5099 # define DEBUG_yv(a)
5100 #endif /* DEBUGGING */
5103 #define DEBUG_SCOPE(where) \
5105 Perl_deb(aTHX_ "%s scope %ld (savestack=%ld) at %s:%d\n", \
5106 where, (long)PL_scopestack_ix, (long)PL_savestack_ix, \
5107 __FILE__, __LINE__));
5109 /* Keep the old croak based assert for those who want it, and as a fallback if
5110 the platform is so heretically non-ANSI that it can't assert. */
5112 #define Perl_assert(what) PERL_DEB2( \
5113 ((what) ? ((void) 0) : \
5114 (Perl_croak_nocontext("Assertion %s failed: file \"" __FILE__ \
5115 "\", line %d", STRINGIFY(what), __LINE__), \
5116 (void) 0)), ((void)0))
5118 /* assert() gets defined if DEBUGGING.
5119 * If no DEBUGGING, the <assert.h> has not been included. */
5121 # define assert(what) Perl_assert(what)
5124 # define assert_(what) assert(what),
5126 # define assert_(what)
5130 I32 (*uf_val)(pTHX_ IV, SV*);
5131 I32 (*uf_set)(pTHX_ IV, SV*);
5135 /* In pre-5.7-Perls the PERL_MAGIC_uvar magic didn't get the thread context.
5136 * XS code wanting to be backward compatible can do something
5137 * like the following:
5139 #ifndef PERL_MG_UFUNC
5140 #define PERL_MG_UFUNC(name,ix,sv) I32 name(IV ix, SV *sv)
5143 static PERL_MG_UFUNC(foo_get, index, val)
5153 #ifndef PERL_MG_UFUNC
5154 #define PERL_MG_UFUNC(name,ix,sv) I32 name(pTHX_ IV ix, SV *sv)
5159 /* isfinite and others are here rather than in math.h as C99 stipulates */
5164 # if !defined(WIN32) && !defined(VMS)
5166 char *crypt (const char*, const char*);
5168 # endif /* !WIN32 */
5171 char *getlogin (void);
5173 # endif /* !WIN32 */
5174 #endif /* !__cplusplus */
5176 /* Fixme on VMS. This needs to be a run-time, not build time options */
5177 /* Also rename() is affected by this */
5178 #ifdef UNLINK_ALL_VERSIONS /* Currently only makes sense for VMS */
5179 #define UNLINK unlnk
5180 I32 unlnk (pTHX_ const char*);
5182 #define UNLINK PerlLIO_unlink
5185 /* some versions of glibc are missing the setresuid() proto */
5186 #if defined(HAS_SETRESUID) && !defined(HAS_SETRESUID_PROTO)
5187 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
5189 /* some versions of glibc are missing the setresgid() proto */
5190 #if defined(HAS_SETRESGID) && !defined(HAS_SETRESGID_PROTO)
5191 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
5194 #ifndef HAS_SETREUID
5195 # ifdef HAS_SETRESUID
5196 # define setreuid(r,e) setresuid(r,e,(Uid_t)-1)
5197 # define HAS_SETREUID
5200 #ifndef HAS_SETREGID
5201 # ifdef HAS_SETRESGID
5202 # define setregid(r,e) setresgid(r,e,(Gid_t)-1)
5203 # define HAS_SETREGID
5207 /* Sighandler_t defined in iperlsys.h */
5209 #ifdef HAS_SIGACTION
5210 typedef struct sigaction Sigsave_t;
5212 typedef Sighandler_t Sigsave_t;
5223 # define RUNOPS_DEFAULT Perl_runops_debug
5225 # define RUNOPS_DEFAULT Perl_runops_standard
5228 #if defined(USE_PERLIO)
5229 EXTERN_C void PerlIO_teardown(void);
5230 # ifdef USE_ITHREADS
5231 # define PERLIO_INIT MUTEX_INIT(&PL_perlio_mutex)
5232 # define PERLIO_TERM \
5234 PerlIO_teardown(); \
5235 MUTEX_DESTROY(&PL_perlio_mutex);\
5238 # define PERLIO_INIT
5239 # define PERLIO_TERM PerlIO_teardown()
5242 # define PERLIO_INIT
5243 # define PERLIO_TERM
5247 # ifdef MUTEX_INIT_CALLS_MALLOC
5248 # define MALLOC_INIT \
5250 PL_malloc_mutex = NULL; \
5251 MUTEX_INIT(&PL_malloc_mutex); \
5253 # define MALLOC_TERM \
5255 perl_mutex tmp = PL_malloc_mutex; \
5256 PL_malloc_mutex = NULL; \
5257 MUTEX_DESTROY(&tmp); \
5260 # define MALLOC_INIT MUTEX_INIT(&PL_malloc_mutex)
5261 # define MALLOC_TERM MUTEX_DESTROY(&PL_malloc_mutex)
5264 # define MALLOC_INIT
5265 # define MALLOC_TERM
5268 #if defined(MULTIPLICITY)
5270 struct perl_memory_debug_header;
5271 struct perl_memory_debug_header {
5273 # if defined(PERL_POISON) || defined(PERL_DEBUG_READONLY_COW)
5276 struct perl_memory_debug_header *prev;
5277 struct perl_memory_debug_header *next;
5278 # ifdef PERL_DEBUG_READONLY_COW
5283 #elif defined(PERL_DEBUG_READONLY_COW)
5285 struct perl_memory_debug_header;
5286 struct perl_memory_debug_header {
5292 #if defined (PERL_TRACK_MEMPOOL) || defined (PERL_DEBUG_READONLY_COW)
5294 # define PERL_MEMORY_DEBUG_HEADER_SIZE \
5295 (sizeof(struct perl_memory_debug_header) + \
5296 (MEM_ALIGNBYTES - sizeof(struct perl_memory_debug_header) \
5297 %MEM_ALIGNBYTES) % MEM_ALIGNBYTES)
5300 # define PERL_MEMORY_DEBUG_HEADER_SIZE 0
5303 #ifdef PERL_TRACK_MEMPOOL
5304 # ifdef PERL_DEBUG_READONLY_COW
5305 # define INIT_TRACK_MEMPOOL(header, interp) \
5307 (header).interpreter = (interp); \
5308 (header).prev = (header).next = &(header); \
5309 (header).readonly = 0; \
5312 # define INIT_TRACK_MEMPOOL(header, interp) \
5314 (header).interpreter = (interp); \
5315 (header).prev = (header).next = &(header); \
5319 # define INIT_TRACK_MEMPOOL(header, interp)
5322 #ifdef I_MALLOCMALLOC
5323 /* Needed for malloc_size(), malloc_good_size() on some systems */
5324 # include <malloc/malloc.h>
5328 # define Perl_safesysmalloc_size(where) Perl_malloced_size(where)
5330 # if defined(HAS_MALLOC_SIZE) && !defined(PERL_DEBUG_READONLY_COW)
5331 # ifdef PERL_TRACK_MEMPOOL
5332 # define Perl_safesysmalloc_size(where) \
5333 (malloc_size(((char *)(where)) - PERL_MEMORY_DEBUG_HEADER_SIZE) - PERL_MEMORY_DEBUG_HEADER_SIZE)
5335 # define Perl_safesysmalloc_size(where) malloc_size(where)
5338 # ifdef HAS_MALLOC_GOOD_SIZE
5339 # ifdef PERL_TRACK_MEMPOOL
5340 # define Perl_malloc_good_size(how_much) \
5341 (malloc_good_size((how_much) + PERL_MEMORY_DEBUG_HEADER_SIZE) - PERL_MEMORY_DEBUG_HEADER_SIZE)
5343 # define Perl_malloc_good_size(how_much) malloc_good_size(how_much)
5346 /* Having this as the identity operation makes some code simpler. */
5347 # define Perl_malloc_good_size(how_much) (how_much)
5351 typedef int (*runops_proc_t)(pTHX);
5352 typedef void (*share_proc_t) (pTHX_ SV *sv);
5353 typedef int (*thrhook_proc_t) (pTHX);
5354 typedef OP* (*PPADDR_t[]) (pTHX);
5355 typedef bool (*destroyable_proc_t) (pTHX_ SV *sv);
5356 typedef void (*despatch_signals_proc_t) (pTHX);
5358 #if defined(__DYNAMIC__) && defined(PERL_DARWIN) && defined(PERL_CORE)
5359 # include <crt_externs.h> /* for the env array */
5360 # define environ (*_NSGetEnviron())
5361 #elif defined(USE_ENVIRON_ARRAY) && !defined(environ)
5362 /* VMS and some other platforms don't use the environ array */
5363 EXTERN_C char **environ; /* environment variables supplied via exec */
5366 #define PERL_PATCHLEVEL_H_IMPLICIT
5367 #include "patchlevel.h"
5368 #undef PERL_PATCHLEVEL_H_IMPLICIT
5370 #define PERL_VERSION_STRING STRINGIFY(PERL_REVISION) "." \
5371 STRINGIFY(PERL_VERSION) "." \
5372 STRINGIFY(PERL_SUBVERSION)
5374 #define PERL_API_VERSION_STRING STRINGIFY(PERL_API_REVISION) "." \
5375 STRINGIFY(PERL_API_VERSION) "." \
5376 STRINGIFY(PERL_API_SUBVERSION)
5380 /* handy constants */
5381 EXTCONST char PL_warn_uninit[]
5382 INIT("Use of uninitialized value%s%s%s");
5383 EXTCONST char PL_warn_uninit_sv[]
5384 INIT("Use of uninitialized value%" SVf "%s%s");
5385 EXTCONST char PL_warn_nosemi[]
5386 INIT("Semicolon seems to be missing");
5387 EXTCONST char PL_warn_reserved[]
5388 INIT("Unquoted string \"%s\" may clash with future reserved word");
5389 EXTCONST char PL_warn_nl[]
5390 INIT("Unsuccessful %s on filename containing newline");
5391 EXTCONST char PL_no_wrongref[]
5392 INIT("Can't use %s ref as %s ref");
5393 /* The core no longer needs this here. If you require the string constant,
5394 please inline a copy into your own code. */
5395 EXTCONST char PL_no_symref[] __attribute__deprecated__
5396 INIT("Can't use string (\"%.32s\") as %s ref while \"strict refs\" in use");
5397 EXTCONST char PL_no_symref_sv[]
5398 INIT("Can't use string (\"%" SVf32 "\"%s) as %s ref while \"strict refs\" in use");
5400 EXTCONST char PL_no_usym[]
5401 INIT("Can't use an undefined value as %s reference");
5402 EXTCONST char PL_no_aelem[]
5403 INIT("Modification of non-creatable array value attempted, subscript %d");
5404 EXTCONST char PL_no_helem_sv[]
5405 INIT("Modification of non-creatable hash value attempted, subscript \"%" SVf "\"");
5406 EXTCONST char PL_no_modify[]
5407 INIT("Modification of a read-only value attempted");
5408 EXTCONST char PL_no_mem[sizeof("Out of memory!\n")]
5409 INIT("Out of memory!\n");
5410 EXTCONST char PL_no_security[]
5411 INIT("Insecure dependency in %s%s");
5412 EXTCONST char PL_no_sock_func[]
5413 INIT("Unsupported socket function \"%s\" called");
5414 EXTCONST char PL_no_dir_func[]
5415 INIT("Unsupported directory function \"%s\" called");
5416 EXTCONST char PL_no_func[]
5417 INIT("The %s function is unimplemented");
5418 EXTCONST char PL_no_myglob[]
5419 INIT("\"%s\" %s %s can't be in a package");
5420 EXTCONST char PL_no_localize_ref[]
5421 INIT("Can't localize through a reference");
5422 EXTCONST char PL_memory_wrap[]
5423 INIT("panic: memory wrap");
5424 EXTCONST char PL_extended_cp_format[]
5425 INIT("Code point 0x%" UVXf " is not Unicode, requires a Perl extension,"
5426 " and so is not portable");
5427 EXTCONST char PL_Yes[]
5429 EXTCONST char PL_No[]
5431 EXTCONST char PL_Zero[]
5435 =for apidoc_section $numeric
5436 =for apidoc AmTuU|const char *|PL_hexdigit|U8 value
5438 This array, indexed by an integer, converts that value into the character that
5439 represents it. For example, if the input is 8, the return will be a string
5440 whose first character is '8'. What is actually returned is a pointer into a
5441 string. All you are interested in is the first character of that string. To
5442 get uppercase letters (for the values 10..15), add 16 to the index. Hence,
5443 C<PL_hexdigit[11]> is C<'b'>, and C<PL_hexdigit[11+16]> is C<'B'>. Adding 16
5444 to an index whose representation is '0'..'9' yields the same as not adding 16.
5445 Indices outside the range 0..31 result in (bad) undedefined behavior.
5449 EXTCONST char PL_hexdigit[]
5450 INIT("0123456789abcdef0123456789ABCDEF");
5452 EXTCONST STRLEN PL_WARN_ALL
5454 EXTCONST STRLEN PL_WARN_NONE
5457 /* This is constant on most architectures, a global on OS/2 */
5459 EXTCONST char PL_sh_path[]
5460 INIT(SH_PATH); /* full path of shell */
5464 EXTCONST char PL_cshname[]
5466 # define PL_cshlen (sizeof(CSH "") - 1)
5469 /* These are baked at compile time into any shared perl library.
5470 In future releases this will allow us in main() to sanity test the
5471 library we're linking against. */
5473 EXTCONST U8 PL_revision
5474 INIT(PERL_REVISION);
5475 EXTCONST U8 PL_version
5477 EXTCONST U8 PL_subversion
5478 INIT(PERL_SUBVERSION);
5480 EXTCONST char PL_uuemap[65]
5481 INIT("`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_");
5483 /* a special string address whose value is "isa", but which perl knows
5484 * to treat as if it were really "DOES" when printing the method name in
5485 * the "Can't call method '%s'" error message */
5486 EXTCONST char PL_isa_DOES[]
5490 EXTCONST char PL_uudmap[256] =
5492 # include "uuudmap.h"
5494 # include "uudmap.h"
5497 EXTCONST char PL_bitcount[256] =
5499 # include "ubitcount.h"
5501 # include "bitcount.h"
5504 EXTCONST char* const PL_sig_name[] = { SIG_NAME };
5505 EXTCONST int PL_sig_num[] = { SIG_NUM };
5507 EXTCONST char PL_uudmap[256];
5508 EXTCONST char PL_bitcount[256];
5509 EXTCONST char* const PL_sig_name[];
5510 EXTCONST int PL_sig_num[];
5513 /* fast conversion and case folding tables. The folding tables complement the
5514 * fold, so that 'a' maps to 'A' and 'A' maps to 'a', ignoring more complicated
5515 * folds such as outside the range or to multiple characters. */
5520 /* The EBCDIC fold table depends on the code page, and hence is found in
5521 * ebcdic_tables.h */
5523 EXTCONST unsigned char PL_fold[] = {
5524 0, 1, 2, 3, 4, 5, 6, 7,
5525 8, 9, 10, 11, 12, 13, 14, 15,
5526 16, 17, 18, 19, 20, 21, 22, 23,
5527 24, 25, 26, 27, 28, 29, 30, 31,
5528 32, 33, 34, 35, 36, 37, 38, 39,
5529 40, 41, 42, 43, 44, 45, 46, 47,
5530 48, 49, 50, 51, 52, 53, 54, 55,
5531 56, 57, 58, 59, 60, 61, 62, 63,
5532 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
5533 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
5534 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
5535 'x', 'y', 'z', 91, 92, 93, 94, 95,
5536 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
5537 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
5538 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
5539 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
5540 128, 129, 130, 131, 132, 133, 134, 135,
5541 136, 137, 138, 139, 140, 141, 142, 143,
5542 144, 145, 146, 147, 148, 149, 150, 151,
5543 152, 153, 154, 155, 156, 157, 158, 159,
5544 160, 161, 162, 163, 164, 165, 166, 167,
5545 168, 169, 170, 171, 172, 173, 174, 175,
5546 176, 177, 178, 179, 180, 181, 182, 183,
5547 184, 185, 186, 187, 188, 189, 190, 191,
5548 192, 193, 194, 195, 196, 197, 198, 199,
5549 200, 201, 202, 203, 204, 205, 206, 207,
5550 208, 209, 210, 211, 212, 213, 214, 215,
5551 216, 217, 218, 219, 220, 221, 222, 223,
5552 224, 225, 226, 227, 228, 229, 230, 231,
5553 232, 233, 234, 235, 236, 237, 238, 239,
5554 240, 241, 242, 243, 244, 245, 246, 247,
5555 248, 249, 250, 251, 252, 253, 254, 255
5558 EXTCONST unsigned char PL_fold_latin1[] = {
5559 /* Full latin1 complement folding, except for three problematic code points:
5560 * Micro sign (181 = 0xB5) and y with diearesis (255 = 0xFF) have their
5561 * fold complements outside the Latin1 range, so can't match something
5562 * that isn't in utf8.
5563 * German lower case sharp s (223 = 0xDF) folds to two characters, 'ss',
5564 * not one, so can't be represented in this table.
5566 * All have to be specially handled */
5567 0, 1, 2, 3, 4, 5, 6, 7,
5568 8, 9, 10, 11, 12, 13, 14, 15,
5569 16, 17, 18, 19, 20, 21, 22, 23,
5570 24, 25, 26, 27, 28, 29, 30, 31,
5571 32, 33, 34, 35, 36, 37, 38, 39,
5572 40, 41, 42, 43, 44, 45, 46, 47,
5573 48, 49, 50, 51, 52, 53, 54, 55,
5574 56, 57, 58, 59, 60, 61, 62, 63,
5575 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
5576 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
5577 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
5578 'x', 'y', 'z', 91, 92, 93, 94, 95,
5579 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
5580 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
5581 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
5582 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
5583 128, 129, 130, 131, 132, 133, 134, 135,
5584 136, 137, 138, 139, 140, 141, 142, 143,
5585 144, 145, 146, 147, 148, 149, 150, 151,
5586 152, 153, 154, 155, 156, 157, 158, 159,
5587 160, 161, 162, 163, 164, 165, 166, 167,
5588 168, 169, 170, 171, 172, 173, 174, 175,
5589 176, 177, 178, 179, 180, 181 /*micro */, 182, 183,
5590 184, 185, 186, 187, 188, 189, 190, 191,
5591 192+32, 193+32, 194+32, 195+32, 196+32, 197+32, 198+32, 199+32,
5592 200+32, 201+32, 202+32, 203+32, 204+32, 205+32, 206+32, 207+32,
5593 208+32, 209+32, 210+32, 211+32, 212+32, 213+32, 214+32, 215,
5594 216+32, 217+32, 218+32, 219+32, 220+32, 221+32, 222+32, 223 /* ss */,
5595 224-32, 225-32, 226-32, 227-32, 228-32, 229-32, 230-32, 231-32,
5596 232-32, 233-32, 234-32, 235-32, 236-32, 237-32, 238-32, 239-32,
5597 240-32, 241-32, 242-32, 243-32, 244-32, 245-32, 246-32, 247,
5598 248-32, 249-32, 250-32, 251-32, 252-32, 253-32, 254-32,
5599 255 /* y with diaeresis */
5602 /* If these tables are accessed through ebcdic, the access will be converted to
5604 EXTCONST unsigned char PL_latin1_lc[] = { /* lowercasing */
5605 0, 1, 2, 3, 4, 5, 6, 7,
5606 8, 9, 10, 11, 12, 13, 14, 15,
5607 16, 17, 18, 19, 20, 21, 22, 23,
5608 24, 25, 26, 27, 28, 29, 30, 31,
5609 32, 33, 34, 35, 36, 37, 38, 39,
5610 40, 41, 42, 43, 44, 45, 46, 47,
5611 48, 49, 50, 51, 52, 53, 54, 55,
5612 56, 57, 58, 59, 60, 61, 62, 63,
5613 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
5614 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
5615 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
5616 'x', 'y', 'z', 91, 92, 93, 94, 95,
5617 96, 97, 98, 99, 100, 101, 102, 103,
5618 104, 105, 106, 107, 108, 109, 110, 111,
5619 112, 113, 114, 115, 116, 117, 118, 119,
5620 120, 121, 122, 123, 124, 125, 126, 127,
5621 128, 129, 130, 131, 132, 133, 134, 135,
5622 136, 137, 138, 139, 140, 141, 142, 143,
5623 144, 145, 146, 147, 148, 149, 150, 151,
5624 152, 153, 154, 155, 156, 157, 158, 159,
5625 160, 161, 162, 163, 164, 165, 166, 167,
5626 168, 169, 170, 171, 172, 173, 174, 175,
5627 176, 177, 178, 179, 180, 181, 182, 183,
5628 184, 185, 186, 187, 188, 189, 190, 191,
5629 192+32, 193+32, 194+32, 195+32, 196+32, 197+32, 198+32, 199+32,
5630 200+32, 201+32, 202+32, 203+32, 204+32, 205+32, 206+32, 207+32,
5631 208+32, 209+32, 210+32, 211+32, 212+32, 213+32, 214+32, 215,
5632 216+32, 217+32, 218+32, 219+32, 220+32, 221+32, 222+32, 223,
5633 224, 225, 226, 227, 228, 229, 230, 231,
5634 232, 233, 234, 235, 236, 237, 238, 239,
5635 240, 241, 242, 243, 244, 245, 246, 247,
5636 248, 249, 250, 251, 252, 253, 254, 255
5639 /* upper and title case of latin1 characters, modified so that the three tricky
5640 * ones are mapped to 255 (which is one of the three) */
5641 EXTCONST unsigned char PL_mod_latin1_uc[] = {
5642 0, 1, 2, 3, 4, 5, 6, 7,
5643 8, 9, 10, 11, 12, 13, 14, 15,
5644 16, 17, 18, 19, 20, 21, 22, 23,
5645 24, 25, 26, 27, 28, 29, 30, 31,
5646 32, 33, 34, 35, 36, 37, 38, 39,
5647 40, 41, 42, 43, 44, 45, 46, 47,
5648 48, 49, 50, 51, 52, 53, 54, 55,
5649 56, 57, 58, 59, 60, 61, 62, 63,
5650 64, 65, 66, 67, 68, 69, 70, 71,
5651 72, 73, 74, 75, 76, 77, 78, 79,
5652 80, 81, 82, 83, 84, 85, 86, 87,
5653 88, 89, 90, 91, 92, 93, 94, 95,
5654 96, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
5655 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
5656 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
5657 'X', 'Y', 'Z', 123, 124, 125, 126, 127,
5658 128, 129, 130, 131, 132, 133, 134, 135,
5659 136, 137, 138, 139, 140, 141, 142, 143,
5660 144, 145, 146, 147, 148, 149, 150, 151,
5661 152, 153, 154, 155, 156, 157, 158, 159,
5662 160, 161, 162, 163, 164, 165, 166, 167,
5663 168, 169, 170, 171, 172, 173, 174, 175,
5664 176, 177, 178, 179, 180, 255 /*micro*/, 182, 183,
5665 184, 185, 186, 187, 188, 189, 190, 191,
5666 192, 193, 194, 195, 196, 197, 198, 199,
5667 200, 201, 202, 203, 204, 205, 206, 207,
5668 208, 209, 210, 211, 212, 213, 214, 215,
5669 216, 217, 218, 219, 220, 221, 222,
5670 # if UNICODE_MAJOR_VERSION > 2 \
5671 || (UNICODE_MAJOR_VERSION == 2 && UNICODE_DOT_VERSION >= 1 \
5672 && UNICODE_DOT_DOT_VERSION >= 8)
5674 # else /* uc(sharp s) is 'sharp s' itself in early unicode */
5677 224-32, 225-32, 226-32, 227-32, 228-32, 229-32, 230-32, 231-32,
5678 232-32, 233-32, 234-32, 235-32, 236-32, 237-32, 238-32, 239-32,
5679 240-32, 241-32, 242-32, 243-32, 244-32, 245-32, 246-32, 247,
5680 248-32, 249-32, 250-32, 251-32, 252-32, 253-32, 254-32, 255
5682 # endif /* !EBCDIC, but still in DOINIT */
5683 #else /* ! DOINIT */
5685 EXTCONST unsigned char PL_fold[];
5686 EXTCONST unsigned char PL_fold_latin1[];
5687 EXTCONST unsigned char PL_mod_latin1_uc[];
5688 EXTCONST unsigned char PL_latin1_lc[];
5692 /* Although only used for debugging, these constants must be available in
5693 * non-debugging builds too, since they're used in ext/re/re_exec.c,
5694 * which has DEBUGGING enabled always */
5696 EXTCONST char* const PL_block_type[] = {
5713 EXTCONST char* PL_block_type[];
5716 /* These are all the compile time options that affect binary compatibility.
5717 Other compile time options that are binary compatible are in perl.c
5718 (in S_Internals_V()). Both are combined for the output of perl -V
5719 However, this string will be embedded in any shared perl library, which will
5720 allow us add a comparison check in perlmain.c in the near future. */
5722 EXTCONST char PL_bincompat_options[] =
5723 # ifdef DEBUG_LEAKING_SCALARS
5724 " DEBUG_LEAKING_SCALARS"
5726 # ifdef DEBUG_LEAKING_SCALARS_FORK_DUMP
5727 " DEBUG_LEAKING_SCALARS_FORK_DUMP"
5732 # ifdef HAVE_INTERP_INTERN
5733 " HAVE_INTERP_INTERN"
5735 # ifdef MULTIPLICITY
5741 # ifdef NO_HASH_SEED
5744 # ifdef PERLIO_LAYERS
5747 # ifdef PERL_DEBUG_READONLY_COW
5748 " PERL_DEBUG_READONLY_COW"
5750 # ifdef PERL_DEBUG_READONLY_OPS
5751 " PERL_DEBUG_READONLY_OPS"
5753 # ifdef PERL_HASH_FUNC_DEFINE
5754 /* note that this is different from the others, PERL_HASH_FUNC_DEFINE
5755 * is a string which says which define was defined. */
5756 " " PERL_HASH_FUNC_DEFINE
5758 # ifdef PERL_HASH_USE_SBOX32
5759 " PERL_HASH_USE_SBOX32"
5761 " PERL_HASH_NO_SBOX32"
5763 # ifdef PERL_IMPLICIT_SYS
5764 " PERL_IMPLICIT_SYS"
5772 # ifdef PERL_SAWAMPERSAND
5773 " PERL_SAWAMPERSAND"
5775 # ifdef PERL_TRACK_MEMPOOL
5776 " PERL_TRACK_MEMPOOL"
5778 # ifdef PERL_USES_PL_PIDSTATUS
5779 " PERL_USES_PL_PIDSTATUS"
5781 # ifdef USE_64_BIT_ALL
5784 # ifdef USE_64_BIT_INT
5790 # ifdef USE_ITHREADS
5793 # ifdef USE_LARGE_FILES
5796 # ifdef USE_LOCALE_COLLATE
5797 " USE_LOCALE_COLLATE"
5799 # ifdef USE_LOCALE_NUMERIC
5800 " USE_LOCALE_NUMERIC"
5802 # ifdef USE_LOCALE_TIME
5805 # ifdef USE_LONG_DOUBLE
5811 # ifdef USE_QUADMATH
5814 # ifdef USE_REENTRANT_API
5815 " USE_REENTRANT_API"
5820 # ifdef VMS_DO_SOCKETS
5823 # ifdef VMS_SHORTEN_LONG_SYMBOLS
5824 " VMS_SHORTEN_LONG_SYMBOLS"
5826 # ifdef VMS_WE_ARE_CASE_SENSITIVE
5827 " VMS_SYMBOL_CASE_AS_IS"
5831 EXTCONST char PL_bincompat_options[];
5834 #ifndef PERL_SET_PHASE
5835 # define PERL_SET_PHASE(new_phase) \
5836 PERL_DTRACE_PROBE_PHASE(new_phase); \
5837 PL_phase = new_phase;
5840 /* The interpreter phases. If these ever change, PL_phase_names right below will
5841 * need to be updated accordingly. */
5843 PERL_PHASE_CONSTRUCT = 0,
5844 PERL_PHASE_START = 1,
5845 PERL_PHASE_CHECK = 2,
5846 PERL_PHASE_INIT = 3,
5849 PERL_PHASE_DESTRUCT = 6
5853 EXTCONST char *const PL_phase_names[] = {
5863 EXTCONST char *const PL_phase_names[];
5867 =for apidoc_section $utility
5869 =for apidoc phase_name
5871 Returns the given phase's name as a NUL-terminated string.
5873 For example, to print a stack trace that includes the current
5874 interpreter phase you might do:
5876 const char* phase_name = phase_name(PL_phase);
5877 mess("This is weird. (Perl phase: %s)", phase_name);
5882 #define phase_name(phase) (PL_phase_names[phase])
5885 /* Do not use this macro. It only exists for extensions that rely on PL_dirty
5886 * instead of using the newer PL_phase, which provides everything PL_dirty
5887 * provided, and more. */
5888 # define PL_dirty cBOOL(PL_phase == PERL_PHASE_DESTRUCT)
5890 # define PL_amagic_generation PL_na
5891 # define PL_encoding ((SV *)NULL)
5892 #endif /* !PERL_CORE */
5894 #define PL_hints PL_compiling.cop_hints
5895 #define PL_maxo MAXO
5899 /*****************************************************************************/
5900 /* This lexer/parser stuff is currently global since yacc is hard to reenter */
5901 /*****************************************************************************/
5902 /* XXX This needs to be revisited, since BEGIN makes yacc re-enter... */
5905 /* LynxOS defines these in scsi.h which is included via ioctl.h */
5914 #define LEX_NOTPARSING 11 /* borrowed from toke.c */
5922 XATTRBLOCK, /* next token should be an attribute or block */
5923 XATTRTERM, /* next token should be an attribute, or block in a term */
5927 XTERMORDORDOR /* evil hack */
5928 /* update exp_name[] in toke.c if adding to this enum */
5931 #define KEY_sigvar 0xFFFF /* fake keyword representing a signature var */
5933 /* Hints are now stored in a dedicated U32, so the bottom 8 bits are no longer
5934 special and there is no need for HINT_PRIVATE_MASK for COPs.
5936 NOTE: The typical module using these has the bit value hard-coded, so don't
5937 blindly change the values of these.
5939 If we run out of bits, the 2 locale ones could be combined. The PARTIAL one
5940 is for "use locale 'FOO'" which excludes some categories. It requires going
5941 to %^H to find out which are in and which are out. This could be extended
5942 for the normal case of a plain HINT_LOCALE, so that %^H would be used for
5944 #define HINT_INTEGER 0x00000001 /* integer pragma */
5945 #define HINT_STRICT_REFS 0x00000002 /* strict pragma */
5946 #define HINT_LOCALE 0x00000004 /* locale pragma */
5947 #define HINT_BYTES 0x00000008 /* bytes pragma */
5948 #define HINT_LOCALE_PARTIAL 0x00000010 /* locale, but a subset of categories */
5950 #define HINT_EXPLICIT_STRICT_REFS 0x00000020 /* strict.pm */
5951 #define HINT_EXPLICIT_STRICT_SUBS 0x00000040 /* strict.pm */
5952 #define HINT_EXPLICIT_STRICT_VARS 0x00000080 /* strict.pm */
5954 #define HINT_BLOCK_SCOPE 0x00000100
5955 #define HINT_STRICT_SUBS 0x00000200 /* strict pragma */
5956 #define HINT_STRICT_VARS 0x00000400 /* strict pragma */
5957 #define HINT_UNI_8_BIT 0x00000800 /* unicode_strings feature */
5959 /* The HINT_NEW_* constants are used by the overload pragma */
5960 #define HINT_NEW_INTEGER 0x00001000
5961 #define HINT_NEW_FLOAT 0x00002000
5962 #define HINT_NEW_BINARY 0x00004000
5963 #define HINT_NEW_STRING 0x00008000
5964 #define HINT_NEW_RE 0x00010000
5965 #define HINT_LOCALIZE_HH 0x00020000 /* %^H needs to be copied */
5966 #define HINT_LEXICAL_IO_IN 0x00040000 /* ${^OPEN} is set for input */
5967 #define HINT_LEXICAL_IO_OUT 0x00080000 /* ${^OPEN} is set for output */
5969 #define HINT_RE_TAINT 0x00100000 /* re pragma */
5970 #define HINT_RE_EVAL 0x00200000 /* re pragma */
5972 #define HINT_FILETEST_ACCESS 0x00400000 /* filetest pragma */
5973 #define HINT_UTF8 0x00800000 /* utf8 pragma */
5975 #define HINT_NO_AMAGIC 0x01000000 /* overloading pragma */
5977 #define HINT_RE_FLAGS 0x02000000 /* re '/xism' pragma */
5979 #define HINT_FEATURE_MASK 0x3c000000 /* 4 bits for feature bundles */
5981 /* Note: Used for HINT_M_VMSISH_*,
5982 currently defined by vms/vmsish.h:
5987 #define HINT_ALL_STRICT HINT_STRICT_REFS \
5988 | HINT_STRICT_SUBS \
5991 #ifdef USE_STRICT_BY_DEFAULT
5992 #define HINTS_DEFAULT HINT_ALL_STRICT
5994 #define HINTS_DEFAULT 0
5997 /* flags for PL_sawampersand */
5999 #define SAWAMPERSAND_LEFT 1 /* saw $` */
6000 #define SAWAMPERSAND_MIDDLE 2 /* saw $& */
6001 #define SAWAMPERSAND_RIGHT 4 /* saw $' */
6003 #ifndef PERL_SAWAMPERSAND
6004 # define PL_sawampersand \
6005 (SAWAMPERSAND_LEFT|SAWAMPERSAND_MIDDLE|SAWAMPERSAND_RIGHT)
6008 /* Used for debugvar magic */
6009 #define DBVARMG_SINGLE 0
6010 #define DBVARMG_TRACE 1
6011 #define DBVARMG_SIGNAL 2
6012 #define DBVARMG_COUNT 3
6014 #define PL_DBsingle_iv (PL_DBcontrol[DBVARMG_SINGLE])
6015 #define PL_DBtrace_iv (PL_DBcontrol[DBVARMG_TRACE])
6016 #define PL_DBsignal_iv (PL_DBcontrol[DBVARMG_SIGNAL])
6018 /* Various states of the input record separator SV (rs) */
6019 #define RsSNARF(sv) (! SvOK(sv))
6020 #define RsSIMPLE(sv) (SvOK(sv) && (! SvPOK(sv) || SvCUR(sv)))
6021 #define RsPARA(sv) (SvPOK(sv) && ! SvCUR(sv))
6022 #define RsRECORD(sv) (SvROK(sv) && (SvIV(SvRV(sv)) > 0))
6024 /* A struct for keeping various DEBUGGING related stuff,
6025 * neatly packed. Currently only scratch variables for
6026 * constructing debug output are included. Needed always,
6027 * not just when DEBUGGING, though, because of the re extension. c*/
6028 struct perl_debug_pad {
6032 #define PERL_DEBUG_PAD(i) &(PL_debug_pad.pad[i])
6033 #define PERL_DEBUG_PAD_ZERO(i) (SvPVX(PERL_DEBUG_PAD(i))[0] = 0, \
6034 (((XPV*) SvANY(PERL_DEBUG_PAD(i)))->xpv_cur = 0), \
6037 /* Enable variables which are pointers to functions */
6038 typedef void (*peep_t)(pTHX_ OP* o);
6039 typedef regexp* (*regcomp_t) (pTHX_ char* exp, char* xend, PMOP* pm);
6040 typedef I32 (*regexec_t) (pTHX_ regexp* prog, char* stringarg,
6041 char* strend, char* strbeg, I32 minend,
6042 SV* screamer, void* data, U32 flags);
6043 typedef char* (*re_intuit_start_t) (pTHX_ regexp *prog, SV *sv,
6044 char *strpos, char *strend,
6046 re_scream_pos_data *d);
6047 typedef SV* (*re_intuit_string_t) (pTHX_ regexp *prog);
6048 typedef void (*regfree_t) (pTHX_ struct regexp* r);
6049 typedef regexp* (*regdupe_t) (pTHX_ const regexp* r, CLONE_PARAMS *param);
6050 typedef I32 (*re_fold_t)(pTHX_ const char *, char const *, I32);
6052 typedef void (*DESTRUCTORFUNC_NOCONTEXT_t) (void*);
6053 typedef void (*DESTRUCTORFUNC_t) (pTHX_ void*);
6054 typedef void (*SVFUNC_t) (pTHX_ SV* const);
6055 typedef I32 (*SVCOMPARE_t) (pTHX_ SV* const, SV* const);
6056 typedef void (*XSINIT_t) (pTHX);
6057 typedef void (*ATEXIT_t) (pTHX_ void*);
6058 typedef void (*XSUBADDR_t) (pTHX_ CV *);
6060 typedef OP* (*Perl_ppaddr_t)(pTHX);
6061 typedef OP* (*Perl_check_t) (pTHX_ OP*);
6062 typedef void(*Perl_ophook_t)(pTHX_ OP*);
6063 typedef int (*Perl_keyword_plugin_t)(pTHX_ char*, STRLEN, OP**);
6064 typedef void(*Perl_cpeep_t)(pTHX_ OP *, OP *);
6066 typedef void(*globhook_t)(pTHX);
6068 #define KEYWORD_PLUGIN_DECLINE 0
6069 #define KEYWORD_PLUGIN_STMT 1
6070 #define KEYWORD_PLUGIN_EXPR 2
6072 /* Interpreter exitlist entry */
6073 typedef struct exitlistentry {
6074 void (*fn) (pTHX_ void*);
6076 } PerlExitListEntry;
6078 /* if you only have signal() and it resets on each signal, FAKE_PERSISTENT_SIGNAL_HANDLERS fixes */
6079 /* These have to be before perlvars.h */
6080 #if !defined(HAS_SIGACTION) && defined(VMS)
6081 # define FAKE_PERSISTENT_SIGNAL_HANDLERS
6083 /* if we're doing kill() with sys$sigprc on VMS, FAKE_DEFAULT_SIGNAL_HANDLERS */
6084 #if defined(KILL_BY_SIGPRC)
6085 # define FAKE_DEFAULT_SIGNAL_HANDLERS
6088 #if !defined(MULTIPLICITY)
6090 struct interpreter {
6096 /* If we have multiple interpreters define a struct
6097 holding variables which must be per-interpreter
6098 If we don't have threads anything that would have
6099 be per-thread is per-interpreter.
6102 /* Set up PERLVAR macros for populating structs */
6103 # define PERLVAR(prefix,var,type) type prefix##var;
6105 /* 'var' is an array of length 'n' */
6106 # define PERLVARA(prefix,var,n,type) type prefix##var[n];
6108 /* initialize 'var' to init' */
6109 # define PERLVARI(prefix,var,type,init) type prefix##var;
6111 /* like PERLVARI, but make 'var' a const */
6112 # define PERLVARIC(prefix,var,type,init) type prefix##var;
6114 struct interpreter {
6115 # include "intrpvar.h"
6118 EXTCONST U16 PL_interp_size
6119 INIT(sizeof(struct interpreter));
6121 # define PERL_INTERPRETER_SIZE_UPTO_MEMBER(member) \
6122 STRUCT_OFFSET(struct interpreter, member) + \
6123 sizeof(((struct interpreter*)0)->member)
6125 /* This will be useful for subsequent releases, because this has to be the
6126 same in your libperl as in main(), else you have a mismatch and must abort.
6128 EXTCONST U16 PL_interp_size_5_18_0
6129 INIT(PERL_INTERPRETER_SIZE_UPTO_MEMBER(PERL_LAST_5_18_0_INTERP_MEMBER));
6132 /* Done with PERLVAR macros for now ... */
6138 #endif /* MULTIPLICITY */
6140 struct tempsym; /* defined in pp_pack.c */
6147 #define PERL_CKDEF(s) PERL_CALLCONV OP *s (pTHX_ OP *o);
6148 #define PERL_PPDEF(s) PERL_CALLCONV OP *s (pTHX);
6151 # include "malloc_ctl.h"
6155 * This provides a layer of functions and macros to ensure extensions will
6156 * get to use the same RTL functions as the core.
6159 # include "win32iop.h"
6165 /* this has structure inits, so it cannot be included before here */
6168 /* The following must follow proto.h as #defines mess up syntax */
6170 #if !defined(PERL_FOR_X2P)
6171 # include "embedvar.h"
6174 /* Now include all the 'global' variables
6175 * If we don't have threads or multiple interpreters
6176 * these include variables that would have been their struct-s
6179 #define PERLVAR(prefix,var,type) EXT type PL_##var;
6180 #define PERLVARA(prefix,var,n,type) EXT type PL_##var[n];
6181 #define PERLVARI(prefix,var,type,init) EXT type PL_##var INIT(init);
6182 #define PERLVARIC(prefix,var,type,init) EXTCONST type PL_##var INIT(init);
6184 #if !defined(MULTIPLICITY)
6186 # include "intrpvar.h"
6188 # define PL_sv_yes (PL_sv_immortals[0])
6189 # define PL_sv_undef (PL_sv_immortals[1])
6190 # define PL_sv_no (PL_sv_immortals[2])
6191 # define PL_sv_zero (PL_sv_immortals[3])
6195 /* All core uses now exterminated. Ensure no zombies can return: */
6199 /* Now all the config stuff is setup we can include embed.h
6200 In particular, need the relevant *ish file included already, as it may
6201 define HAVE_INTERP_INTERN */
6206 # include "perlvars.h"
6215 #if !defined(MULTIPLICITY)
6216 /* Set up PERLVAR macros for populating structs */
6217 # define PERLVAR(prefix,var,type) type prefix##var;
6218 /* 'var' is an array of length 'n' */
6219 # define PERLVARA(prefix,var,n,type) type prefix##var[n];
6220 /* initialize 'var' to init' */
6221 # define PERLVARI(prefix,var,type,init) type prefix##var;
6222 /* like PERLVARI, but make 'var' a const */
6223 # define PERLVARIC(prefix,var,type,init) type prefix##var;
6225 /* this is never instantiated, is it just used for sizeof(struct PerlHandShakeInterpreter) */
6226 struct PerlHandShakeInterpreter {
6227 # include "intrpvar.h"
6237 /* dummy variables that hold pointers to both runops functions, thus forcing
6238 * them *both* to get linked in (useful for Peek.xs, debugging etc) */
6240 EXTCONST runops_proc_t PL_runops_std
6241 INIT(Perl_runops_standard);
6242 EXTCONST runops_proc_t PL_runops_dbg
6243 INIT(Perl_runops_debug);
6245 #define EXT_MGVTBL EXTCONST MGVTBL
6247 #define PERL_MAGIC_READONLY_ACCEPTABLE 0x40
6248 #define PERL_MAGIC_VALUE_MAGIC 0x80
6249 #define PERL_MAGIC_VTABLE_MASK 0x3F
6251 /* can this type of magic be attached to a readonly SV? */
6252 #define PERL_MAGIC_TYPE_READONLY_ACCEPTABLE(t) \
6253 (PL_magic_data[(U8)(t)] & PERL_MAGIC_READONLY_ACCEPTABLE)
6255 /* Is this type of magic container magic (%ENV, $1 etc),
6256 * or value magic (pos, taint etc)?
6258 #define PERL_MAGIC_TYPE_IS_VALUE_MAGIC(t) \
6259 (PL_magic_data[(U8)(t)] & PERL_MAGIC_VALUE_MAGIC)
6261 #include "mg_vtable.h"
6264 EXTCONST U8 PL_magic_data[256] =
6266 # include "umg_data.h"
6268 # include "mg_data.h"
6272 EXTCONST U8 PL_magic_data[256];
6276 /* NL IV NV PV INV PI PN MG RX GV LV AV HV CV FM IO */
6278 PL_valid_types_IVX[] = { 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0 };
6280 PL_valid_types_NVX[] = { 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0 };
6282 PL_valid_types_PVX[] = { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1 };
6284 PL_valid_types_RV[] = { 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1 };
6286 PL_valid_types_IV_set[] = { 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1 };
6288 PL_valid_types_NV_set[] = { 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
6291 PL_deBruijn_bitpos_tab32[] = {
6292 /* https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn */
6293 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
6294 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
6298 PL_deBruijn_bitpos_tab64[] = {
6299 /* https://stackoverflow.com/questions/11376288/fast-computing-of-log2-for-64-bit-integers */
6300 63, 0, 58, 1, 59, 47, 53, 2, 60, 39, 48, 27, 54, 33, 42, 3,
6301 61, 51, 37, 40, 49, 18, 28, 20, 55, 30, 34, 11, 43, 14, 22, 4,
6302 62, 57, 46, 52, 38, 26, 32, 41, 50, 36, 17, 19, 29, 10, 13, 21,
6303 56, 45, 25, 31, 35, 16, 9, 12, 44, 24, 15, 8, 23, 7, 6, 5
6308 EXTCONST bool PL_valid_types_IVX[];
6309 EXTCONST bool PL_valid_types_NVX[];
6310 EXTCONST bool PL_valid_types_PVX[];
6311 EXTCONST bool PL_valid_types_RV[];
6312 EXTCONST bool PL_valid_types_IV_set[];
6313 EXTCONST bool PL_valid_types_NV_set[];
6314 EXTCONST U8 PL_deBruijn_bitpos_tab32[];
6315 EXTCONST U8 PL_deBruijn_bitpos_tab64[];
6319 /* The constants for using PL_deBruijn_bitpos_tab */
6320 #define PERL_deBruijnMagic32_ 0x077CB531
6321 #define PERL_deBruijnShift32_ 27
6322 #define PERL_deBruijnMagic64_ 0x07EDD5E59A4E28C2
6323 #define PERL_deBruijnShift64_ 58
6325 /* In C99 we could use designated (named field) union initializers.
6326 * In C89 we need to initialize the member declared first.
6327 * In C++ we need extern C initializers.
6329 * With the U8_NV version you will want to have inner braces,
6330 * while with the NV_U8 use just the NV. */
6332 #define INFNAN_U8_NV_DECL EXTCONST union { U8 u8[NVSIZE]; NV nv; }
6333 #define INFNAN_NV_U8_DECL EXTCONST union { NV nv; U8 u8[NVSIZE]; }
6335 /* if these never got defined, they need defaults */
6336 #ifndef PERL_SET_CONTEXT
6337 # define PERL_SET_CONTEXT(i) PERL_SET_INTERP(i)
6340 #ifndef PERL_GET_CONTEXT
6341 # define PERL_GET_CONTEXT PERL_GET_INTERP
6344 #ifndef PERL_GET_THX
6345 # define PERL_GET_THX ((void*)NULL)
6348 #ifndef PERL_SET_THX
6349 # define PERL_SET_THX(t) NOOP
6354 /* The tables below are adapted from
6355 * https://bjoern.hoehrmann.de/utf-8/decoder/dfa/, which requires this copyright
6358 Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
6360 Permission is hereby granted, free of charge, to any person obtaining a copy of
6361 this software and associated documentation files (the "Software"), to deal in
6362 the Software without restriction, including without limitation the rights to
6363 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
6364 of the Software, and to permit persons to whom the Software is furnished to do
6365 so, subject to the following conditions:
6367 The above copyright notice and this permission notice shall be included in all
6368 copies or substantial portions of the Software.
6370 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6371 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6372 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
6373 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
6374 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
6375 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
6381 # if 0 /* This is the original table given in
6382 https://bjoern.hoehrmann.de/utf-8/decoder/dfa/ */
6383 static U8 utf8d_C9[] = {
6384 /* The first part of the table maps bytes to character classes that
6385 * to reduce the size of the transition table and create bitmasks. */
6386 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*/
6387 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*/
6388 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*/
6389 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*/
6390 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*/
6391 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*/
6392 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*/
6393 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*/
6395 /* The second part is a transition table that maps a combination
6396 * of a state of the automaton and a character class to a state. */
6397 0,12,24,36,60,96,84,12,12,12,48,72, 12,12,12,12,12,12,12,12,12,12,12,12,
6398 12, 0,12,12,12,12,12, 0,12, 0,12,12, 12,24,12,12,12,12,12,24,12,24,12,12,
6399 12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
6400 12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
6401 12,36,12,12,12,12,12,12,12,12,12,12
6406 /* This is a version of the above table customized for Perl that doesn't
6407 * exclude surrogates and accepts start bytes up through FD (FE on 64-bit
6408 * machines). The classes have been renumbered so that the patterns are more
6409 * evident in the table. The class numbers are structured so the values are:
6411 * a) UTF-8 invariant code points
6413 * b) Start bytes that always lead to either overlongs or some class of code
6414 * point that needs outside intervention for handling (such as to raise a
6417 * c) Start bytes that never lead to one of the above
6418 * number of bytes in complete sequence
6419 * d) Rest of start bytes (they can be resolved through this algorithm) and
6420 * continuation bytes
6421 * arbitrary class number chosen to not conflict with the above
6422 * classes, and to index into the remaining table
6424 * It would make the code simpler if start byte FF could also be handled, but
6425 * doing so would mean adding two more classes (one from splitting 80 from 81,
6426 * and one for FF), and nodes for each of 6 new continuation bytes. The
6427 * current table has 436 entries; the new one would require 140 more = 576 (2
6428 * additional classes for each of the 10 existing nodes, and 20 for each of 6
6429 * new nodes. The array would have to be made U16 instead of U8, not worth it
6430 * for this rarely encountered case
6433 * 00-7F 0 Always legal, single byte sequence
6434 * 80-81 7 Not legal immediately after start bytes E0 F0 F8 FC
6436 * 82-83 8 Not legal immediately after start bytes E0 F0 F8 FC
6437 * 84-87 9 Not legal immediately after start bytes E0 F0 F8
6438 * 88-8F 10 Not legal immediately after start bytes E0 F0
6439 * 90-9F 11 Not legal immediately after start byte E0
6440 * A0-BF 12 Always legal continuation byte
6441 * C0,C1 1 Not legal: overlong
6442 * C2-DF 2 Legal start byte for two byte sequences
6443 * E0 13 Some sequences are overlong; others legal
6444 * E1-EF 3 Legal start byte for three byte sequences
6445 * F0 14 Some sequences are overlong; others legal
6446 * F1-F7 4 Legal start byte for four byte sequences
6447 * F8 15 Some sequences are overlong; others legal
6448 * F9-FB 5 Legal start byte for five byte sequences
6449 * FC 16 Some sequences are overlong; others legal
6450 * FD 6 Legal start byte for six byte sequences
6451 * FE 17 Some sequences are overlong; others legal
6452 * (is 1 on 32-bit machines, since it overflows)
6453 * FF 1 Need to handle specially
6456 EXTCONST U8 PL_extended_utf8_dfa_tab[] = {
6457 /* The first part of the table maps bytes to character classes to reduce
6458 * the size of the transition table and create bitmasks. */
6459 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*00-0F*/
6460 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*10-1F*/
6461 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*20-2F*/
6462 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*30-3F*/
6463 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*40-4F*/
6464 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*50-5F*/
6465 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*60-6F*/
6466 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*70-7F*/
6467 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10, /*80-8F*/
6468 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, /*90-9F*/
6469 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, /*A0-AF*/
6470 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, /*B0-BF*/
6471 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /*C0-CF*/
6472 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /*D0-DF*/
6473 13, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /*E0-EF*/
6474 14, 4, 4, 4, 4, 4, 4, 4,15, 5, 5, 5,16, 6, /*F0-FD*/
6482 /* The second part is a transition table that maps a combination
6483 * of a state of the automaton and a character class to a new state, called a
6484 * node. The nodes are:
6485 * N0 The initial state, and final accepting one.
6486 * N1 Any one continuation byte (80-BF) left. This is transitioned to
6487 * immediately when the start byte indicates a two-byte sequence
6488 * N2 Any two continuation bytes left.
6489 * N3 Any three continuation bytes left.
6490 * N4 Any four continuation bytes left.
6491 * N5 Any five continuation bytes left.
6492 * N6 Start byte is E0. Continuation bytes 80-9F are illegal (overlong);
6493 * the other continuations transition to N1
6494 * N7 Start byte is F0. Continuation bytes 80-8F are illegal (overlong);
6495 * the other continuations transition to N2
6496 * N8 Start byte is F8. Continuation bytes 80-87 are illegal (overlong);
6497 * the other continuations transition to N3
6498 * N9 Start byte is FC. Continuation bytes 80-83 are illegal (overlong);
6499 * the other continuations transition to N4
6500 * N10 Start byte is FE. Continuation bytes 80-81 are illegal (overlong);
6501 * the other continuations transition to N5
6502 * 1 Reject. All transitions not mentioned above (except the single
6503 * byte ones (as they are always legal)) are to this state.
6506 # if defined(PERL_CORE)
6507 # define NUM_CLASSES 18
6509 # define N1 ((N0) + NUM_CLASSES)
6510 # define N2 ((N1) + NUM_CLASSES)
6511 # define N3 ((N2) + NUM_CLASSES)
6512 # define N4 ((N3) + NUM_CLASSES)
6513 # define N5 ((N4) + NUM_CLASSES)
6514 # define N6 ((N5) + NUM_CLASSES)
6515 # define N7 ((N6) + NUM_CLASSES)
6516 # define N8 ((N7) + NUM_CLASSES)
6517 # define N9 ((N8) + NUM_CLASSES)
6518 # define N10 ((N9) + NUM_CLASSES)
6520 /*Class: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 */
6521 /*N0*/ 0, 1,N1,N2,N3,N4,N5, 1, 1, 1, 1, 1, 1,N6,N7,N8,N9,N10,
6522 /*N1*/ 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
6523 /*N2*/ 1, 1, 1, 1, 1, 1, 1,N1,N1,N1,N1,N1,N1, 1, 1, 1, 1, 1,
6524 /*N3*/ 1, 1, 1, 1, 1, 1, 1,N2,N2,N2,N2,N2,N2, 1, 1, 1, 1, 1,
6525 /*N4*/ 1, 1, 1, 1, 1, 1, 1,N3,N3,N3,N3,N3,N3, 1, 1, 1, 1, 1,
6526 /*N5*/ 1, 1, 1, 1, 1, 1, 1,N4,N4,N4,N4,N4,N4, 1, 1, 1, 1, 1,
6528 /*N6*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,N1, 1, 1, 1, 1, 1,
6529 /*N7*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,N2,N2, 1, 1, 1, 1, 1,
6530 /*N8*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,N3,N3,N3, 1, 1, 1, 1, 1,
6531 /*N9*/ 1, 1, 1, 1, 1, 1, 1, 1, 1,N4,N4,N4,N4, 1, 1, 1, 1, 1,
6532 /*N10*/ 1, 1, 1, 1, 1, 1, 1, 1,N5,N5,N5,N5,N5, 1, 1, 1, 1, 1,
6535 /* And below is a version of the above table that accepts only strict UTF-8.
6536 * Hence no surrogates nor non-characters, nor non-Unicode. Thus, if the input
6537 * passes this dfa, it will be for a well-formed, non-problematic code point
6538 * that can be returned immediately.
6540 * The "Implementation details" portion of
6541 * https://bjoern.hoehrmann.de/utf-8/decoder/dfa/ shows how
6542 * the first portion of the table maps each possible byte into a character
6543 * class. And that the classes for those bytes which are start bytes have been
6544 * carefully chosen so they serve as well to be used as a shift value to mask
6545 * off the leading 1 bits of the start byte. Unfortunately the addition of
6546 * being able to distinguish non-characters makes this not fully work. This is
6547 * because, now, the start bytes E1-EF have to be broken into 3 classes instead
6549 * 1) ED because it could be a surrogate
6550 * 2) EF because it could be a non-character
6551 * 3) the rest, which can never evaluate to a problematic code point.
6553 * Each of E1-EF has three leading 1 bits, then a 0. That means we could use a
6554 * shift (and hence class number) of either 3 or 4 to get a mask that works.
6555 * But that only allows two categories, and we need three. khw made the
6556 * decision to therefore treat the ED start byte as an error, so that the dfa
6557 * drops out immediately for that. In the dfa, classes 3 and 4 are used to
6558 * distinguish EF vs the rest. Then special code is used to deal with ED,
6559 * that's executed only when the dfa drops out. The code points started by ED
6560 * are half surrogates, and half hangul syllables. This means that 2048 of
6561 * the hangul syllables (about 18%) take longer than all other non-problematic
6562 * code points to handle.
6564 * The changes to handle non-characters requires the addition of states and
6565 * classes to the dfa. (See the section on "Mapping bytes to character
6566 * classes" in the linked-to document for further explanation of the original
6590 * F1-F3 6 (6 bits can be stripped)
6591 * F4 5 (only 5 can be stripped)
6595 EXTCONST U8 PL_strict_utf8_dfa_tab[] = {
6596 /* The first part of the table maps bytes to character classes to reduce
6597 * the size of the transition table and create bitmasks. */
6598 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*00-0F*/
6599 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*10-1F*/
6600 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*20-2F*/
6601 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*30-3F*/
6602 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*40-4F*/
6603 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*50-5F*/
6604 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*60-6F*/
6605 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*70-7F*/
6606 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, /*80-8F*/
6607 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12, /*90-9F*/
6608 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14, /*A0-AF*/
6609 15,15,15,15,15,15,15,16,15,15,15,15,15,15,17,18, /*B0-BF*/
6610 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /*C0-CF*/
6611 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /*D0-DF*/
6612 7, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 4, /*E0-EF*/
6613 8, 6, 6, 6, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*F0-FF*/
6615 /* The second part is a transition table that maps a combination
6616 * of a state of the automaton and a character class to a new state, called a
6617 * node. The nodes are:
6618 * N0 The initial state, and final accepting one.
6619 * N1 Any one continuation byte (80-BF) left. This is transitioned to
6620 * immediately when the start byte indicates a two-byte sequence
6621 * N2 Any two continuation bytes left.
6622 * N3 Start byte is E0. Continuation bytes 80-9F are illegal (overlong);
6623 * the other continuations transition to state N1
6624 * N4 Start byte is EF. Continuation byte B7 transitions to N8; BF to N9;
6625 * the other continuations transitions to N1
6626 * N5 Start byte is F0. Continuation bytes 80-8F are illegal (overlong);
6627 * [9AB]F transition to N10; the other continuations to N2.
6628 * N6 Start byte is F[123]. Continuation bytes [89AB]F transition
6629 * to N10; the other continuations to N2.
6630 * N7 Start byte is F4. Continuation bytes 90-BF are illegal
6631 * (non-unicode); 8F transitions to N10; the other continuations to N2
6632 * N8 Initial sequence is EF B7. Continuation bytes 90-AF are illegal
6633 * (non-characters); the other continuations transition to N0.
6634 * N9 Initial sequence is EF BF. Continuation bytes BE and BF are illegal
6635 * (non-characters); the other continuations transition to N0.
6636 * N10 Initial sequence is one of: F0 [9-B]F; F[123] [8-B]F; or F4 8F.
6637 * Continuation byte BF transitions to N11; the other continuations to
6639 * N11 Initial sequence is the two bytes given in N10 followed by BF.
6640 * Continuation bytes BE and BF are illegal (non-characters); the other
6641 * continuations transition to N0.
6642 * 1 Reject. All transitions not mentioned above (except the single
6643 * byte ones (as they are always legal) are to this state.
6657 # define NUM_CLASSES 19
6659 # define N1 ((N0) + NUM_CLASSES)
6660 # define N2 ((N1) + NUM_CLASSES)
6661 # define N3 ((N2) + NUM_CLASSES)
6662 # define N4 ((N3) + NUM_CLASSES)
6663 # define N5 ((N4) + NUM_CLASSES)
6664 # define N6 ((N5) + NUM_CLASSES)
6665 # define N7 ((N6) + NUM_CLASSES)
6666 # define N8 ((N7) + NUM_CLASSES)
6667 # define N9 ((N8) + NUM_CLASSES)
6668 # define N10 ((N9) + NUM_CLASSES)
6669 # define N11 ((N10) + NUM_CLASSES)
6671 /*Class: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 */
6672 /*N0*/ 0, 1, N1, N2, N4, N7, N6, N3, N5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
6673 /*N1*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6674 /*N2*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, N1, N1, N1, N1, N1, N1, N1, N1, N1, N1,
6676 /*N3*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, N1, N1, N1, N1, N1, N1,
6677 /*N4*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, N1, N1, N1, N1, N1, N1, N1, N8, N1, N9,
6678 /*N5*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, N2,N10, N2,N10, N2, N2, N2,N10,
6679 /*N6*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, N2,N10, N2,N10, N2,N10, N2, N2, N2,N10,
6680 /*N7*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, N2,N10, 1, 1, 1, 1, 1, 1, 1, 1,
6681 /*N8*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0,
6682 /*N9*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
6683 /*N10*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, N1, N1, N1, N1, N1, N1, N1, N1, N1,N11,
6684 /*N11*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
6687 /* And below is yet another version of the above tables that accepts only UTF-8
6688 * as defined by Corregidum #9. Hence no surrogates nor non-Unicode, but
6689 * it allows non-characters. This is isomorphic to the original table
6690 * in https://bjoern.hoehrmann.de/utf-8/decoder/dfa/
6704 * F1-F3 6 (6 bits can be stripped)
6705 * F4 5 (only 5 can be stripped)
6709 EXTCONST U8 PL_c9_utf8_dfa_tab[] = {
6710 /* The first part of the table maps bytes to character classes to reduce
6711 * the size of the transition table and create bitmasks. */
6712 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*00-0F*/
6713 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*10-1F*/
6714 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*20-2F*/
6715 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*30-3F*/
6716 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*40-4F*/
6717 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*50-5F*/
6718 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*60-6F*/
6719 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*70-7F*/
6720 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, /*80-8F*/
6721 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, /*90-9F*/
6722 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, /*A0-AF*/
6723 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11, /*B0-BF*/
6724 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /*C0-CF*/
6725 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /*D0-DF*/
6726 7, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, /*E0-EF*/
6727 8, 6, 6, 6, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /*F0-FF*/
6729 /* The second part is a transition table that maps a combination
6730 * of a state of the automaton and a character class to a new state, called a
6731 * node. The nodes are:
6732 * N0 The initial state, and final accepting one.
6733 * N1 Any one continuation byte (80-BF) left. This is transitioned to
6734 * immediately when the start byte indicates a two-byte sequence
6735 * N2 Any two continuation bytes left.
6736 * N3 Any three continuation bytes left.
6737 * N4 Start byte is E0. Continuation bytes 80-9F are illegal (overlong);
6738 * the other continuations transition to state N1
6739 * N5 Start byte is ED. Continuation bytes A0-BF all lead to surrogates,
6740 * so are illegal. The other continuations transition to state N1.
6741 * N6 Start byte is F0. Continuation bytes 80-8F are illegal (overlong);
6742 * the other continuations transition to N2
6743 * N7 Start byte is F4. Continuation bytes 90-BF are illegal
6744 * (non-unicode); the other continuations transition to N2
6745 * 1 Reject. All transitions not mentioned above (except the single
6746 * byte ones (as they are always legal) are to this state.
6758 # define NUM_CLASSES 12
6760 # define N1 ((N0) + NUM_CLASSES)
6761 # define N2 ((N1) + NUM_CLASSES)
6762 # define N3 ((N2) + NUM_CLASSES)
6763 # define N4 ((N3) + NUM_CLASSES)
6764 # define N5 ((N4) + NUM_CLASSES)
6765 # define N6 ((N5) + NUM_CLASSES)
6766 # define N7 ((N6) + NUM_CLASSES)
6768 /*Class: 0 1 2 3 4 5 6 7 8 9 10 11 */
6769 /*N0*/ 0, 1, N1, N2, N5, N7, N3, N4, N6, 1, 1, 1,
6770 /*N1*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
6771 /*N2*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, N1, N1, N1,
6772 /*N3*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, N2, N2, N2,
6774 /*N4*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, N1,
6775 /*N5*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, N1, N1, 1,
6776 /*N6*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, N2, N2,
6777 /*N7*/ 1, 1, 1, 1, 1, 1, 1, 1, 1, N2, 1, 1,
6780 # endif /* defined(PERL_CORE) */
6781 # else /* End of is DOINIT */
6783 EXTCONST U8 PL_extended_utf8_dfa_tab[];
6784 EXTCONST U8 PL_strict_utf8_dfa_tab[];
6785 EXTCONST U8 PL_c9_utf8_dfa_tab[];
6788 #endif /* end of isn't EBCDIC */
6790 #include "overload.h"
6799 CV* table[NofAMmeth];
6801 struct am_table_short {
6807 typedef struct am_table AMT;
6808 typedef struct am_table_short AMTS;
6810 #define AMGfallNEVER 1
6812 #define AMGfallYES 3
6814 #define AMTf_AMAGIC 1
6815 #define AMT_AMAGIC(amt) ((amt)->flags & AMTf_AMAGIC)
6816 #define AMT_AMAGIC_on(amt) ((amt)->flags |= AMTf_AMAGIC)
6817 #define AMT_AMAGIC_off(amt) ((amt)->flags &= ~AMTf_AMAGIC)
6819 #define StashHANDLER(stash,meth) gv_handler((stash),CAT2(meth,_amg))
6822 * some compilers like to redefine cos et alia as faster
6823 * (and less accurate?) versions called F_cos et cetera (Quidquid
6824 * latine dictum sit, altum viditur.) This trick collides with
6825 * the Perl overloading (amg). The following #defines fool both.
6830 # define F_atan2_amg atan2_amg
6833 # define F_cos_amg cos_amg
6836 # define F_exp_amg exp_amg
6839 # define F_log_amg log_amg
6842 # define F_pow_amg pow_amg
6845 # define F_sin_amg sin_amg
6848 # define F_sqrt_amg sqrt_amg
6850 #endif /* _FASTMATH */
6852 #define PERLDB_ALL (PERLDBf_SUB | PERLDBf_LINE | \
6853 PERLDBf_NOOPT | PERLDBf_INTER | \
6854 PERLDBf_SUBLINE| PERLDBf_SINGLE| \
6855 PERLDBf_NAMEEVAL| PERLDBf_NAMEANON | \
6857 /* No _NONAME, _GOTO */
6858 #define PERLDBf_SUB 0x01 /* Debug sub enter/exit */
6859 #define PERLDBf_LINE 0x02 /* Keep line # */
6860 #define PERLDBf_NOOPT 0x04 /* Switch off optimizations */
6861 #define PERLDBf_INTER 0x08 /* Preserve more data for
6862 later inspections */
6863 #define PERLDBf_SUBLINE 0x10 /* Keep subr source lines */
6864 #define PERLDBf_SINGLE 0x20 /* Start with single-step on */
6865 #define PERLDBf_NONAME 0x40 /* For _SUB: no name of the subr */
6866 #define PERLDBf_GOTO 0x80 /* Report goto: call DB::goto */
6867 #define PERLDBf_NAMEEVAL 0x100 /* Informative names for evals */
6868 #define PERLDBf_NAMEANON 0x200 /* Informative names for anon subs */
6869 #define PERLDBf_SAVESRC 0x400 /* Save source lines into @{"_<$filename"} */
6870 #define PERLDBf_SAVESRC_NOSUBS 0x800 /* Including evals that generate no subroutines */
6871 #define PERLDBf_SAVESRC_INVALID 0x1000 /* Save source that did not compile */
6873 #define PERLDB_SUB (PL_perldb & PERLDBf_SUB)
6874 #define PERLDB_LINE (PL_perldb & PERLDBf_LINE)
6875 #define PERLDB_NOOPT (PL_perldb & PERLDBf_NOOPT)
6876 #define PERLDB_INTER (PL_perldb & PERLDBf_INTER)
6877 #define PERLDB_SUBLINE (PL_perldb & PERLDBf_SUBLINE)
6878 #define PERLDB_SINGLE (PL_perldb & PERLDBf_SINGLE)
6879 #define PERLDB_SUB_NN (PL_perldb & PERLDBf_NONAME)
6880 #define PERLDB_GOTO (PL_perldb & PERLDBf_GOTO)
6881 #define PERLDB_NAMEEVAL (PL_perldb & PERLDBf_NAMEEVAL)
6882 #define PERLDB_NAMEANON (PL_perldb & PERLDBf_NAMEANON)
6883 #define PERLDB_SAVESRC (PL_perldb & PERLDBf_SAVESRC)
6884 #define PERLDB_SAVESRC_NOSUBS (PL_perldb & PERLDBf_SAVESRC_NOSUBS)
6885 #define PERLDB_SAVESRC_INVALID (PL_perldb & PERLDBf_SAVESRC_INVALID)
6887 #define PERLDB_LINE_OR_SAVESRC (PL_perldb & (PERLDBf_LINE | PERLDBf_SAVESRC))
6890 # define KEYWORD_PLUGIN_MUTEX_INIT MUTEX_INIT(&PL_keyword_plugin_mutex)
6891 # define KEYWORD_PLUGIN_MUTEX_LOCK MUTEX_LOCK(&PL_keyword_plugin_mutex)
6892 # define KEYWORD_PLUGIN_MUTEX_UNLOCK MUTEX_UNLOCK(&PL_keyword_plugin_mutex)
6893 # define KEYWORD_PLUGIN_MUTEX_TERM MUTEX_DESTROY(&PL_keyword_plugin_mutex)
6894 # define USER_PROP_MUTEX_INIT MUTEX_INIT(&PL_user_prop_mutex)
6895 # define USER_PROP_MUTEX_LOCK MUTEX_LOCK(&PL_user_prop_mutex)
6896 # define USER_PROP_MUTEX_UNLOCK MUTEX_UNLOCK(&PL_user_prop_mutex)
6897 # define USER_PROP_MUTEX_TERM MUTEX_DESTROY(&PL_user_prop_mutex)
6899 # define KEYWORD_PLUGIN_MUTEX_INIT NOOP
6900 # define KEYWORD_PLUGIN_MUTEX_LOCK NOOP
6901 # define KEYWORD_PLUGIN_MUTEX_UNLOCK NOOP
6902 # define KEYWORD_PLUGIN_MUTEX_TERM NOOP
6903 # define USER_PROP_MUTEX_INIT NOOP
6904 # define USER_PROP_MUTEX_LOCK NOOP
6905 # define USER_PROP_MUTEX_UNLOCK NOOP
6906 # define USER_PROP_MUTEX_TERM NOOP
6909 #ifdef USE_LOCALE /* These locale things are all subject to change */
6911 /* Returns TRUE if the plain locale pragma without a parameter is in effect.
6913 # define IN_LOCALE_RUNTIME (PL_curcop \
6914 && CopHINTS_get(PL_curcop) & HINT_LOCALE)
6916 /* Returns TRUE if either form of the locale pragma is in effect */
6917 # define IN_SOME_LOCALE_FORM_RUNTIME \
6918 cBOOL(CopHINTS_get(PL_curcop) & (HINT_LOCALE|HINT_LOCALE_PARTIAL))
6920 # define IN_LOCALE_COMPILETIME cBOOL(PL_hints & HINT_LOCALE)
6921 # define IN_SOME_LOCALE_FORM_COMPILETIME \
6922 cBOOL(PL_hints & (HINT_LOCALE|HINT_LOCALE_PARTIAL))
6925 =for apidoc_section $locale
6927 =for apidoc Amn|bool|IN_LOCALE
6929 Evaluates to TRUE if the plain locale pragma without a parameter (S<C<use
6930 locale>>) is in effect.
6932 =for apidoc Amn|bool|IN_LOCALE_COMPILETIME
6934 Evaluates to TRUE if, when compiling a perl program (including an C<eval>) if
6935 the plain locale pragma without a parameter (S<C<use locale>>) is in effect.
6937 =for apidoc Amn|bool|IN_LOCALE_RUNTIME
6939 Evaluates to TRUE if, when executing a perl program (including an C<eval>) if
6940 the plain locale pragma without a parameter (S<C<use locale>>) is in effect.
6945 # define IN_LOCALE \
6946 (IN_PERL_COMPILETIME ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME)
6947 # define IN_SOME_LOCALE_FORM \
6948 (IN_PERL_COMPILETIME ? IN_SOME_LOCALE_FORM_COMPILETIME \
6949 : IN_SOME_LOCALE_FORM_RUNTIME)
6951 # define IN_LC_ALL_COMPILETIME IN_LOCALE_COMPILETIME
6952 # define IN_LC_ALL_RUNTIME IN_LOCALE_RUNTIME
6954 # define IN_LC_PARTIAL_COMPILETIME cBOOL(PL_hints & HINT_LOCALE_PARTIAL)
6955 # define IN_LC_PARTIAL_RUNTIME \
6956 (PL_curcop && CopHINTS_get(PL_curcop) & HINT_LOCALE_PARTIAL)
6958 # define IN_LC_COMPILETIME(category) \
6959 ( IN_LC_ALL_COMPILETIME \
6960 || ( IN_LC_PARTIAL_COMPILETIME \
6961 && Perl__is_in_locale_category(aTHX_ TRUE, (category))))
6962 # define IN_LC_RUNTIME(category) \
6963 (IN_LC_ALL_RUNTIME || (IN_LC_PARTIAL_RUNTIME \
6964 && Perl__is_in_locale_category(aTHX_ FALSE, (category))))
6965 # define IN_LC(category) \
6966 (IN_LC_COMPILETIME(category) || IN_LC_RUNTIME(category))
6968 # if defined (PERL_CORE) || defined (PERL_IN_XSUB_RE)
6970 /* This internal macro should be called from places that operate under
6971 * locale rules. If there is a problem with the current locale that
6972 * hasn't been raised yet, it will output a warning this time. Because
6973 * this will so rarely be true, there is no point to optimize for time;
6974 * instead it makes sense to minimize space used and do all the work in
6975 * the rarely called function */
6976 # ifdef USE_LOCALE_CTYPE
6977 # define CHECK_AND_WARN_PROBLEMATIC_LOCALE_ \
6979 if (UNLIKELY(PL_warn_locale)) { \
6980 Perl__warn_problematic_locale(); \
6984 # define CHECK_AND_WARN_PROBLEMATIC_LOCALE_
6988 /* These two internal macros are called when a warning should be raised,
6989 * and will do so if enabled. The first takes a single code point
6990 * argument; the 2nd, is a pointer to the first byte of the UTF-8 encoded
6991 * string, and an end position which it won't try to read past */
6992 # define _CHECK_AND_OUTPUT_WIDE_LOCALE_CP_MSG(cp) \
6994 if (! PL_in_utf8_CTYPE_locale && ckWARN(WARN_LOCALE)) { \
6995 Perl_warner(aTHX_ packWARN(WARN_LOCALE), \
6996 "Wide character (U+%" UVXf ") in %s",\
6997 (UV) cp, OP_DESC(PL_op)); \
7001 # define _CHECK_AND_OUTPUT_WIDE_LOCALE_UTF8_MSG(s, send) \
7002 STMT_START { /* Check if to warn before doing the conversion work */\
7003 if (! PL_in_utf8_CTYPE_locale && ckWARN(WARN_LOCALE)) { \
7004 UV cp = utf8_to_uvchr_buf((U8 *) (s), (U8 *) (send), NULL); \
7005 Perl_warner(aTHX_ packWARN(WARN_LOCALE), \
7006 "Wide character (U+%" UVXf ") in %s", \
7008 ? UNICODE_REPLACEMENT \
7014 # endif /* PERL_CORE or PERL_IN_XSUB_RE */
7015 #else /* No locale usage */
7016 # define IN_LOCALE_RUNTIME 0
7017 # define IN_SOME_LOCALE_FORM_RUNTIME 0
7018 # define IN_LOCALE_COMPILETIME 0
7019 # define IN_SOME_LOCALE_FORM_COMPILETIME 0
7020 # define IN_LOCALE 0
7021 # define IN_SOME_LOCALE_FORM 0
7022 # define IN_LC_ALL_COMPILETIME 0
7023 # define IN_LC_ALL_RUNTIME 0
7024 # define IN_LC_PARTIAL_COMPILETIME 0
7025 # define IN_LC_PARTIAL_RUNTIME 0
7026 # define IN_LC_COMPILETIME(category) 0
7027 # define IN_LC_RUNTIME(category) 0
7028 # define IN_LC(category) 0
7029 # define CHECK_AND_WARN_PROBLEMATIC_LOCALE_
7030 # define _CHECK_AND_OUTPUT_WIDE_LOCALE_UTF8_MSG(s, send)
7031 # define _CHECK_AND_OUTPUT_WIDE_LOCALE_CP_MSG(c)
7034 #define locale_panic_(m) Perl_locale_panic((m), __FILE__, __LINE__, errno)
7036 /* Locale/thread synchronization macros. */
7037 #if ! ( defined(USE_LOCALE) \
7038 && defined(USE_LOCALE_THREADS) \
7039 && ( ! defined(USE_THREAD_SAFE_LOCALE) \
7040 || ( defined(HAS_LOCALECONV) \
7041 && ( ! defined(HAS_LOCALECONV_L) \
7042 || defined(TS_W32_BROKEN_LOCALECONV))) \
7043 || ( defined(HAS_NL_LANGINFO) \
7044 && ! defined(HAS_THREAD_SAFE_NL_LANGINFO_L)) \
7045 || (defined(HAS_MBLEN) && ! defined(HAS_MBRLEN)) \
7046 || (defined(HAS_MBTOWC) && ! defined(HAS_MBRTOWC)) \
7047 || (defined(HAS_WCTOMB) && ! defined(HAS_WCRTOMB))))
7049 /* The whole expression just above was complemented, so here we have no need
7050 * for thread synchronization, most likely it would be that this isn't a
7051 * threaded build. */
7052 # define LOCALE_INIT
7053 # define LOCALE_TERM
7054 # define LC_NUMERIC_LOCK(cond) NOOP
7055 # define LC_NUMERIC_UNLOCK NOOP
7056 # define LOCALECONV_LOCK NOOP
7057 # define LOCALECONV_UNLOCK NOOP
7058 # define LOCALE_READ_LOCK NOOP
7059 # define LOCALE_READ_UNLOCK NOOP
7060 # define MBLEN_LOCK NOOP
7061 # define MBLEN_UNLOCK NOOP
7062 # define MBTOWC_LOCK NOOP
7063 # define MBTOWC_UNLOCK NOOP
7064 # define NL_LANGINFO_LOCK NOOP
7065 # define NL_LANGINFO_UNLOCK NOOP
7066 # define SETLOCALE_LOCK NOOP
7067 # define SETLOCALE_UNLOCK NOOP
7068 # define WCTOMB_LOCK NOOP
7069 # define WCTOMB_UNLOCK NOOP
7072 /* Here, we will need critical sections in locale handling, because one or
7073 * more of the above conditions are true. This could be because the
7074 * platform doesn't have thread-safe locales, or that at least one of the
7075 * locale-dependent functions in the core isn't thread-safe. The latter
7076 * case is generally because they return a pointer to a static buffer, which
7077 * may be per-process instead of per-thread. There are supposedly
7078 * re-entrant, safe versions for all of them Perl currently uses (which the
7079 * #if above checks for), but most platforms don't have all the needed ones
7080 * available, and the Posix standard doesn't require nl_langinfo_l() to be
7081 * fully thread-safe, so a Configure probe was written. localeconv_l() is
7082 * uncommon, and judging by bug reports on the web, some earlier library
7083 * localeconv_l versions were broken, so perhaps a probe is in order for
7084 * that, but it would be a pain to write.
7086 * On non-thread-safe systems, some of the above functions are vulnerable to
7087 * races should another thread get control and change the locale in the
7088 * middle of their execution.
7090 * We currently use a single mutex for all these cases. This solves both
7091 * the problem of another thread changing the locale, and the buffer being
7092 * overwritten (the code copies the results to a safe place before releasing
7093 * the mutex). Ideally, for locale thread-safe platforms where the only
7094 * issue is another thread clobbering the function's static buffer, there
7095 * would be a separate mutex for each such buffer. Otherwise, things get
7096 * locked that don't need to. But, it is not expected that any of these
7097 * will be called frequently, and the locked interval should be short, and
7098 * modern platforms will have reentrant versions (which don't lock) for
7099 * almost all of them, so khw thinks a single mutex should suffice. */
7100 # define LOCALE_LOCK_ \
7102 DEBUG_Lv(PerlIO_printf(Perl_debug_log, \
7103 "%s: %d: locking locale\n", __FILE__, __LINE__)); \
7104 MUTEX_LOCK(&PL_locale_mutex); \
7106 # define LOCALE_UNLOCK_ \
7108 DEBUG_Lv(PerlIO_printf(Perl_debug_log, \
7109 "%s: %d: unlocking locale\n", __FILE__, __LINE__)); \
7110 MUTEX_UNLOCK(&PL_locale_mutex); \
7113 /* We do define a different macro for each case; then if we want to have
7114 * separate mutexes for some of them, the only changes needed are here.
7115 * Define just the necessary macros. The compiler should then croak if the
7116 * #ifdef's in the code are incorrect */
7117 # if defined(HAS_LOCALECONV) && ( ! defined(USE_POSIX_2008_LOCALE) \
7118 || ! defined(HAS_LOCALECONV_L) \
7119 || defined(TS_W32_BROKEN_LOCALECONV))
7120 # define LOCALECONV_LOCK LOCALE_LOCK_
7121 # define LOCALECONV_UNLOCK LOCALE_UNLOCK_
7123 # if defined(HAS_NL_LANGINFO) && ( ! defined(HAS_THREAD_SAFE_NL_LANGINFO_L) \
7124 || ! defined(USE_POSIX_2008_LOCALE))
7125 # define NL_LANGINFO_LOCK LOCALE_LOCK_
7126 # define NL_LANGINFO_UNLOCK LOCALE_UNLOCK_
7128 # if defined(HAS_MBLEN) && ! defined(HAS_MBRLEN)
7129 # define MBLEN_LOCK LOCALE_LOCK_
7130 # define MBLEN_UNLOCK LOCALE_UNLOCK_
7132 # if defined(HAS_MBTOWC) && ! defined(HAS_MBRTOWC)
7133 # define MBTOWC_LOCK LOCALE_LOCK_
7134 # define MBTOWC_UNLOCK LOCALE_UNLOCK_
7136 # if defined(HAS_WCTOMB) && ! defined(HAS_WCRTOMB)
7137 # define WCTOMB_LOCK LOCALE_LOCK_
7138 # define WCTOMB_UNLOCK LOCALE_UNLOCK_
7140 # if defined(USE_THREAD_SAFE_LOCALE)
7141 /* On locale thread-safe systems, we don't need these workarounds */
7142 # define LOCALE_TERM_LC_NUMERIC_ NOOP
7143 # define LOCALE_INIT_LC_NUMERIC_ NOOP
7144 # define LC_NUMERIC_LOCK(cond) NOOP
7145 # define LC_NUMERIC_UNLOCK NOOP
7146 # define LOCALE_INIT_LC_NUMERIC_ NOOP
7147 # define LOCALE_TERM_LC_NUMERIC_ NOOP
7149 /* There may be instance core where we this is invoked yet should do
7150 * nothing. Rather than have #ifdef's around them, define it here */
7151 # define SETLOCALE_LOCK NOOP
7152 # define SETLOCALE_UNLOCK NOOP
7154 # define SETLOCALE_LOCK LOCALE_LOCK_
7155 # define SETLOCALE_UNLOCK LOCALE_UNLOCK_
7157 /* On platforms without per-thread locales, when another thread can switch
7158 * our locale, we need another mutex to create critical sections where we
7159 * want the LC_NUMERIC locale to be locked into either the C (standard)
7160 * locale, or the underlying locale, so that other threads interrupting
7161 * this one don't change it to the wrong state before we've had a chance to
7162 * complete our operation. It can stay locked over an entire printf
7163 * operation, for example. And so is made distinct from the LOCALE_LOCK
7166 * This simulates kind of a general semaphore. The current thread will
7167 * lock the mutex if the per-thread variable is zero, and then increments
7168 * that variable. Each corresponding UNLOCK decrements the variable until
7169 * it is 0, at which point it actually unlocks the mutex. Since the
7170 * variable is per-thread, there is no race with other threads.
7172 * The single argument is a condition to test for, and if true, to panic,
7173 * as this would be an attempt to complement the LC_NUMERIC state, and
7174 * we're not supposed to because it's locked.
7176 * Clang improperly gives warnings for this, if not silenced:
7177 * https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#conditional-locks
7179 * If LC_NUMERIC_LOCK is combined with one of the LOCKs above, calls to
7180 * that and its corresponding unlock should be contained entirely within
7181 * the locked portion of LC_NUMERIC. Those mutexes should be used only in
7182 * very short sections of code, while LC_NUMERIC_LOCK may span more
7183 * operations. By always following this convention, deadlock should be
7184 * impossible. But if necessary, the two mutexes could be combined. */
7185 # define LC_NUMERIC_LOCK(cond_to_panic_if_already_locked) \
7186 CLANG_DIAG_IGNORE(-Wthread-safety) \
7188 if (PL_lc_numeric_mutex_depth <= 0) { \
7189 MUTEX_LOCK(&PL_lc_numeric_mutex); \
7190 PL_lc_numeric_mutex_depth = 1; \
7191 DEBUG_Lv(PerlIO_printf(Perl_debug_log, \
7192 "%s: %d: locking lc_numeric; depth=1\n", \
7193 __FILE__, __LINE__)); \
7196 PL_lc_numeric_mutex_depth++; \
7197 DEBUG_Lv(PerlIO_printf(Perl_debug_log, \
7198 "%s: %d: avoided lc_numeric_lock; new depth=%d\n", \
7199 __FILE__, __LINE__, PL_lc_numeric_mutex_depth)); \
7200 if (cond_to_panic_if_already_locked) { \
7201 locale_panic_("Trying to change LC_NUMERIC incompatibly");\
7206 # define LC_NUMERIC_UNLOCK \
7208 if (PL_lc_numeric_mutex_depth <= 1) { \
7209 MUTEX_UNLOCK(&PL_lc_numeric_mutex); \
7210 PL_lc_numeric_mutex_depth = 0; \
7211 DEBUG_Lv(PerlIO_printf(Perl_debug_log, \
7212 "%s: %d: unlocking lc_numeric; depth=0\n", \
7213 __FILE__, __LINE__)); \
7216 PL_lc_numeric_mutex_depth--; \
7217 DEBUG_Lv(PerlIO_printf(Perl_debug_log, \
7218 "%s: %d: avoided lc_numeric_unlock; new depth=%d\n",\
7219 __FILE__, __LINE__, PL_lc_numeric_mutex_depth)); \
7224 # define LOCALE_INIT_LC_NUMERIC_ MUTEX_INIT(&PL_lc_numeric_mutex)
7225 # define LOCALE_TERM_LC_NUMERIC_ MUTEX_DESTROY(&PL_lc_numeric_mutex)
7228 # ifdef USE_POSIX_2008_LOCALE
7229 /* We have a locale object holding the 'C' locale for Posix 2008 */
7230 # define LOCALE_TERM_POSIX_2008_ \
7232 if (PL_C_locale_obj) { \
7233 /* Make sure we aren't using the locale \
7234 * space we are about to free */ \
7235 uselocale(LC_GLOBAL_LOCALE); \
7236 freelocale(PL_C_locale_obj); \
7237 PL_C_locale_obj = (locale_t) NULL; \
7241 # define LOCALE_TERM_POSIX_2008_ NOOP
7244 # define LOCALE_INIT STMT_START { \
7245 MUTEX_INIT(&PL_locale_mutex); \
7246 LOCALE_INIT_LC_NUMERIC_; \
7249 # define LOCALE_TERM STMT_START { \
7250 LOCALE_TERM_POSIX_2008_; \
7251 LOCALE_TERM_LC_NUMERIC_; \
7252 MUTEX_DESTROY(&PL_locale_mutex); \
7256 #ifdef USE_LOCALE_NUMERIC
7258 /* These macros are for toggling between the underlying locale (UNDERLYING or
7259 * LOCAL) and the C locale (STANDARD). (Actually we don't have to use the C
7260 * locale if the underlying locale is indistinguishable from it in the numeric
7261 * operations used by Perl, namely the decimal point, and even the thousands
7264 =for apidoc_section $locale
7266 =for apidoc Amn|void|DECLARATION_FOR_LC_NUMERIC_MANIPULATION
7268 This macro should be used as a statement. It declares a private variable
7269 (whose name begins with an underscore) that is needed by the other macros in
7270 this section. Failing to include this correctly should lead to a syntax error.
7271 For compatibility with C89 C compilers it should be placed in a block before
7272 any executable statements.
7274 =for apidoc Am|void|STORE_LC_NUMERIC_FORCE_TO_UNDERLYING
7276 This is used by XS code that is C<LC_NUMERIC> locale-aware to force the
7277 locale for category C<LC_NUMERIC> to be what perl thinks is the current
7278 underlying locale. (The perl interpreter could be wrong about what the
7279 underlying locale actually is if some C or XS code has called the C library
7280 function L<setlocale(3)> behind its back; calling L</sync_locale> before calling
7281 this macro will update perl's records.)
7283 A call to L</DECLARATION_FOR_LC_NUMERIC_MANIPULATION> must have been made to
7284 declare at compile time a private variable used by this macro. This macro
7285 should be called as a single statement, not an expression, but with an empty
7286 argument list, like this:
7289 DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
7291 STORE_LC_NUMERIC_FORCE_TO_UNDERLYING();
7293 RESTORE_LC_NUMERIC();
7297 The private variable is used to save the current locale state, so
7298 that the requisite matching call to L</RESTORE_LC_NUMERIC> can restore it.
7300 On threaded perls not operating with thread-safe functionality, this macro uses
7301 a mutex to force a critical section. Therefore the matching RESTORE should be
7302 close by, and guaranteed to be called.
7304 =for apidoc Am|void|STORE_LC_NUMERIC_SET_TO_NEEDED
7306 This is used to help wrap XS or C code that is C<LC_NUMERIC> locale-aware.
7307 This locale category is generally kept set to a locale where the decimal radix
7308 character is a dot, and the separator between groups of digits is empty. This
7309 is because most XS code that reads floating point numbers is expecting them to
7312 This macro makes sure the current C<LC_NUMERIC> state is set properly, to be
7313 aware of locale if the call to the XS or C code from the Perl program is
7314 from within the scope of a S<C<use locale>>; or to ignore locale if the call is
7315 instead from outside such scope.
7317 This macro is the start of wrapping the C or XS code; the wrap ending is done
7318 by calling the L</RESTORE_LC_NUMERIC> macro after the operation. Otherwise
7319 the state can be changed that will adversely affect other XS code.
7321 A call to L</DECLARATION_FOR_LC_NUMERIC_MANIPULATION> must have been made to
7322 declare at compile time a private variable used by this macro. This macro
7323 should be called as a single statement, not an expression, but with an empty
7324 argument list, like this:
7327 DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
7329 STORE_LC_NUMERIC_SET_TO_NEEDED();
7331 RESTORE_LC_NUMERIC();
7335 On threaded perls not operating with thread-safe functionality, this macro uses
7336 a mutex to force a critical section. Therefore the matching RESTORE should be
7337 close by, and guaranteed to be called; see L</WITH_LC_NUMERIC_SET_TO_NEEDED>
7338 for a more contained way to ensure that.
7340 =for apidoc Am|void|STORE_LC_NUMERIC_SET_TO_NEEDED_IN|bool in_lc_numeric
7342 Same as L</STORE_LC_NUMERIC_SET_TO_NEEDED> with in_lc_numeric provided
7343 as the precalculated value of C<IN_LC(LC_NUMERIC)>. It is the caller's
7344 responsibility to ensure that the status of C<PL_compiling> and C<PL_hints>
7345 cannot have changed since the precalculation.
7347 =for apidoc Am|void|RESTORE_LC_NUMERIC
7349 This is used in conjunction with one of the macros
7350 L</STORE_LC_NUMERIC_SET_TO_NEEDED>
7351 and L</STORE_LC_NUMERIC_FORCE_TO_UNDERLYING> to properly restore the
7352 C<LC_NUMERIC> state.
7354 A call to L</DECLARATION_FOR_LC_NUMERIC_MANIPULATION> must have been made to
7355 declare at compile time a private variable used by this macro and the two
7356 C<STORE> ones. This macro should be called as a single statement, not an
7357 expression, but with an empty argument list, like this:
7360 DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
7362 RESTORE_LC_NUMERIC();
7366 =for apidoc Am|void|WITH_LC_NUMERIC_SET_TO_NEEDED|block
7368 This macro invokes the supplied statement or block within the context
7369 of a L</STORE_LC_NUMERIC_SET_TO_NEEDED> .. L</RESTORE_LC_NUMERIC> pair
7372 WITH_LC_NUMERIC_SET_TO_NEEDED(
7373 SNPRINTF_G(fv, ebuf, sizeof(ebuf), precis)
7379 #ifdef USE_LOCALE_NUMERIC
7380 DECLARATION_FOR_LC_NUMERIC_MANIPULATION;
7381 STORE_LC_NUMERIC_SET_TO_NEEDED();
7383 SNPRINTF_G(fv, ebuf, sizeof(ebuf), precis);
7384 #ifdef USE_LOCALE_NUMERIC
7385 RESTORE_LC_NUMERIC();
7389 =for apidoc Am|void|WITH_LC_NUMERIC_SET_TO_NEEDED_IN|bool in_lc_numeric|block
7391 Same as L</WITH_LC_NUMERIC_SET_TO_NEEDED> with in_lc_numeric provided
7392 as the precalculated value of C<IN_LC(LC_NUMERIC)>. It is the caller's
7393 responsibility to ensure that the status of C<PL_compiling> and C<PL_hints>
7394 cannot have changed since the precalculation.
7400 /* If the underlying numeric locale has a non-dot decimal point or has a
7401 * non-empty floating point thousands separator, the current locale is instead
7402 * generally kept in the C locale instead of that underlying locale. The
7403 * current status is known by looking at two words. One is non-zero if the
7404 * current numeric locale is the standard C/POSIX one or is indistinguishable
7405 * from C. The other is non-zero if the current locale is the underlying
7406 * locale. Both can be non-zero if, as often happens, the underlying locale is
7407 * C or indistinguishable from it.
7409 * khw believes the reason for the variables instead of the bits in a single
7410 * word is to avoid having to have masking instructions. */
7412 # define NOT_IN_NUMERIC_STANDARD_ (! PL_numeric_standard)
7414 /* We can lock the category to stay in the C locale, making requests to the
7415 * contrary be noops, in the dynamic scope by setting PL_numeric_standard to 2.
7417 # define NOT_IN_NUMERIC_UNDERLYING_ \
7418 (! PL_numeric_underlying && PL_numeric_standard < 2)
7420 # define DECLARATION_FOR_LC_NUMERIC_MANIPULATION \
7421 void (*_restore_LC_NUMERIC_function)(pTHX) = NULL
7423 # define STORE_LC_NUMERIC_SET_TO_NEEDED_IN(in) \
7425 bool _in_lc_numeric = (in); \
7427 ( ( _in_lc_numeric && NOT_IN_NUMERIC_UNDERLYING_) \
7428 || (! _in_lc_numeric && NOT_IN_NUMERIC_STANDARD_))); \
7429 if (_in_lc_numeric) { \
7430 if (NOT_IN_NUMERIC_UNDERLYING_) { \
7431 Perl_set_numeric_underlying(aTHX); \
7432 _restore_LC_NUMERIC_function \
7433 = &Perl_set_numeric_standard; \
7437 if (NOT_IN_NUMERIC_STANDARD_) { \
7438 Perl_set_numeric_standard(aTHX); \
7439 _restore_LC_NUMERIC_function \
7440 = &Perl_set_numeric_underlying; \
7445 # define STORE_LC_NUMERIC_SET_TO_NEEDED() \
7446 STORE_LC_NUMERIC_SET_TO_NEEDED_IN(IN_LC(LC_NUMERIC))
7448 # define RESTORE_LC_NUMERIC() \
7450 if (_restore_LC_NUMERIC_function) { \
7451 _restore_LC_NUMERIC_function(aTHX); \
7453 LC_NUMERIC_UNLOCK; \
7456 /* The next two macros should be rarely used, and only after being sure that
7457 * this is what is needed */
7458 # define SET_NUMERIC_STANDARD() \
7460 DEBUG_Lv(PerlIO_printf(Perl_debug_log, \
7461 "%s: %d: lc_numeric standard=%d\n", \
7462 __FILE__, __LINE__, PL_numeric_standard)); \
7463 if (UNLIKELY(NOT_IN_NUMERIC_STANDARD_)) { \
7464 Perl_set_numeric_standard(aTHX); \
7466 DEBUG_Lv(PerlIO_printf(Perl_debug_log, \
7467 "%s: %d: lc_numeric standard=%d\n", \
7468 __FILE__, __LINE__, PL_numeric_standard)); \
7471 # define SET_NUMERIC_UNDERLYING() \
7473 /*assert(PL_locale_mutex_depth > 0);*/ \
7474 if (NOT_IN_NUMERIC_UNDERLYING_) { \
7475 Perl_set_numeric_underlying(aTHX); \
7479 /* The rest of these LC_NUMERIC macros toggle to one or the other state, with
7480 * the RESTORE_foo ones called to switch back, but only if need be */
7481 # define STORE_LC_NUMERIC_SET_STANDARD() \
7483 LC_NUMERIC_LOCK(NOT_IN_NUMERIC_STANDARD_); \
7484 if (NOT_IN_NUMERIC_STANDARD_) { \
7485 _restore_LC_NUMERIC_function = &Perl_set_numeric_underlying;\
7486 Perl_set_numeric_standard(aTHX); \
7490 /* Rarely, we want to change to the underlying locale even outside of 'use
7491 * locale'. This is principally in the POSIX:: functions */
7492 # define STORE_LC_NUMERIC_FORCE_TO_UNDERLYING() \
7494 LC_NUMERIC_LOCK(NOT_IN_NUMERIC_UNDERLYING_); \
7495 if (NOT_IN_NUMERIC_UNDERLYING_) { \
7496 Perl_set_numeric_underlying(aTHX); \
7497 _restore_LC_NUMERIC_function = &Perl_set_numeric_standard; \
7501 /* Lock/unlock to the C locale until unlock is called. This needs to be
7502 * recursively callable. [perl #128207] */
7503 # define LOCK_LC_NUMERIC_STANDARD() \
7505 DEBUG_Lv(PerlIO_printf(Perl_debug_log, \
7506 "%s: %d: lc_numeric_standard now locked to depth %d\n", \
7507 __FILE__, __LINE__, PL_numeric_standard)); \
7508 __ASSERT_(PL_numeric_standard) \
7509 PL_numeric_standard++; \
7512 # define UNLOCK_LC_NUMERIC_STANDARD() \
7514 if (PL_numeric_standard > 1) { \
7515 PL_numeric_standard--; \
7520 DEBUG_Lv(PerlIO_printf(Perl_debug_log, \
7521 "%s: %d: ", __FILE__, __LINE__); \
7522 if (PL_numeric_standard <= 1) \
7523 PerlIO_printf(Perl_debug_log, \
7524 "lc_numeric_standard now unlocked\n");\
7525 else PerlIO_printf(Perl_debug_log, \
7526 "lc_numeric_standard lock decremented to depth %d\n", \
7527 PL_numeric_standard););\
7530 # define WITH_LC_NUMERIC_SET_TO_NEEDED_IN(in_lc_numeric, block) \
7532 DECLARATION_FOR_LC_NUMERIC_MANIPULATION; \
7533 STORE_LC_NUMERIC_SET_TO_NEEDED_IN(in_lc_numeric); \
7535 RESTORE_LC_NUMERIC(); \
7538 # define WITH_LC_NUMERIC_SET_TO_NEEDED(block) \
7539 WITH_LC_NUMERIC_SET_TO_NEEDED_IN(IN_LC(LC_NUMERIC), block)
7541 #else /* !USE_LOCALE_NUMERIC */
7543 # define SET_NUMERIC_STANDARD()
7544 # define SET_NUMERIC_UNDERLYING()
7545 # define IS_NUMERIC_RADIX(a, b) (0)
7546 # define DECLARATION_FOR_LC_NUMERIC_MANIPULATION dNOOP
7547 # define STORE_LC_NUMERIC_SET_STANDARD()
7548 # define STORE_LC_NUMERIC_FORCE_TO_UNDERLYING()
7549 # define STORE_LC_NUMERIC_SET_TO_NEEDED_IN(in_lc_numeric)
7550 # define STORE_LC_NUMERIC_SET_TO_NEEDED()
7551 # define RESTORE_LC_NUMERIC()
7552 # define LOCK_LC_NUMERIC_STANDARD()
7553 # define UNLOCK_LC_NUMERIC_STANDARD()
7554 # define WITH_LC_NUMERIC_SET_TO_NEEDED_IN(in_lc_numeric, block) \
7555 STMT_START { block; } STMT_END
7556 # define WITH_LC_NUMERIC_SET_TO_NEEDED(block) \
7557 STMT_START { block; } STMT_END
7559 #endif /* !USE_LOCALE_NUMERIC */
7561 #ifdef USE_LOCALE_THREADS
7562 # define ENV_LOCK PERL_WRITE_LOCK(&PL_env_mutex)
7563 # define ENV_UNLOCK PERL_WRITE_UNLOCK(&PL_env_mutex)
7564 # define ENV_READ_LOCK PERL_READ_LOCK(&PL_env_mutex)
7565 # define ENV_READ_UNLOCK PERL_READ_UNLOCK(&PL_env_mutex)
7566 # define ENV_INIT PERL_RW_MUTEX_INIT(&PL_env_mutex)
7567 # define ENV_TERM PERL_RW_MUTEX_DESTROY(&PL_env_mutex)
7569 /* On platforms where the static buffer contained in getenv() is per-thread
7570 * rather than process-wide, another thread executing a getenv() at the same
7571 * time won't destroy ours before we have copied the result safely away and
7572 * unlocked the mutex. On such platforms (which is most), we can have many
7573 * readers of the environment at the same time. */
7574 # ifdef GETENV_PRESERVES_OTHER_THREAD
7575 # define GETENV_LOCK ENV_READ_LOCK
7576 # define GETENV_UNLOCK ENV_READ_UNLOCK
7578 /* If, on the other hand, another thread could zap our getenv() return, we
7579 * need to keep them from executing until we are done */
7580 # define GETENV_LOCK ENV_LOCK
7581 # define GETENV_UNLOCK ENV_UNLOCK
7584 # define ENV_LOCK NOOP
7585 # define ENV_UNLOCK NOOP
7586 # define ENV_READ_LOCK NOOP
7587 # define ENV_READ_UNLOCK NOOP
7588 # define ENV_INIT NOOP
7589 # define ENV_TERM NOOP
7590 # define GETENV_LOCK NOOP
7591 # define GETENV_UNLOCK NOOP
7594 #ifndef PERL_NO_INLINE_FUNCTIONS
7595 /* Static inline funcs that depend on includes and declarations above.
7596 Some of these reference functions in the perl object files, and some
7597 compilers aren't smart enough to eliminate unused static inline
7598 functions, so including this file in source code can cause link errors
7599 even if the source code uses none of the functions. Hence including these
7600 can be suppressed by setting PERL_NO_INLINE_FUNCTIONS. Doing this will
7601 (obviously) result in unworkable XS code, but allows simple probing code
7602 to continue to work, because it permits tests to include the perl headers
7603 for definitions without creating a link dependency on the perl library
7604 (which may not exist yet).
7609 # include "perlstatic.h"
7610 # include "inline.h"
7611 # include "sv_inline.h"
7617 /* Some critical sections need to lock both the locale and the environment.
7618 * XXX khw intends to change this to lock both mutexes, but that brings up
7619 * issues of potential deadlock, so should be done at the beginning of a
7620 * development cycle. So for now, it just locks the environment. Note that
7621 * many modern platforms are locale-thread-safe anyway, so locking the locale
7622 * mutex is a no-op anyway */
7623 #define ENV_LOCALE_LOCK ENV_LOCK
7624 #define ENV_LOCALE_UNLOCK ENV_UNLOCK
7626 /* And some critical sections care only that no one else is writing either the
7627 * locale nor the environment. XXX Again this is for the future. This can be
7628 * simulated with using COND_WAIT in thread.h */
7629 #define ENV_LOCALE_READ_LOCK ENV_LOCALE_LOCK
7630 #define ENV_LOCALE_READ_UNLOCK ENV_LOCALE_UNLOCK
7634 =for apidoc_section $numeric
7636 =for apidoc AmTR|NV|Strtod|NN const char * const s|NULLOK char ** e
7638 This is a synonym for L</my_strtod>.
7640 =for apidoc AmTR|NV|Strtol|NN const char * const s|NULLOK char ** e|int base
7642 Platform and configuration independent C<strtol>. This expands to the
7643 appropriate C<strotol>-like function based on the platform and F<Configure>
7644 options>. For example it could expand to C<strtoll> or C<strtoq> instead of
7647 =for apidoc AmTR|NV|Strtoul|NN const char * const s|NULLOK char ** e|int base
7649 Platform and configuration independent C<strtoul>. This expands to the
7650 appropriate C<strotoul>-like function based on the platform and F<Configure>
7651 options>. For example it could expand to C<strtoull> or C<strtouq> instead of
7658 #define Strtod my_strtod
7660 #if defined(HAS_STRTOD) \
7661 || defined(USE_QUADMATH) \
7662 || (defined(HAS_STRTOLD) && defined(HAS_LONG_DOUBLE) \
7663 && defined(USE_LONG_DOUBLE))
7664 # define Perl_strtod Strtod
7667 #if !defined(Strtol) && defined(USE_64_BIT_INT) && defined(IV_IS_QUAD) && \
7668 (QUADKIND == QUAD_IS_LONG_LONG || QUADKIND == QUAD_IS___INT64)
7670 # define strtoll __strtoll /* secret handshake */
7672 # if defined(WIN64) && defined(_MSC_VER)
7673 # define strtoll _strtoi64 /* secret handshake */
7675 # if !defined(Strtol) && defined(HAS_STRTOLL)
7676 # define Strtol strtoll
7678 # if !defined(Strtol) && defined(HAS_STRTOQ)
7679 # define Strtol strtoq
7681 /* is there atoq() anywhere? */
7683 #if !defined(Strtol) && defined(HAS_STRTOL)
7684 # define Strtol strtol
7687 /* It would be more fashionable to use Strtol() to define atol()
7688 * (as is done for Atoul(), see below) but for backward compatibility
7689 * we just assume atol(). */
7690 # if defined(USE_64_BIT_INT) && defined(IV_IS_QUAD) && defined(HAS_ATOLL) && \
7691 (QUADKIND == QUAD_IS_LONG_LONG || QUADKIND == QUAD_IS___INT64)
7693 # define atoll _atoi64 /* secret handshake */
7701 #if !defined(Strtoul) && defined(USE_64_BIT_INT) && defined(UV_IS_QUAD) && \
7702 (QUADKIND == QUAD_IS_LONG_LONG || QUADKIND == QUAD_IS___INT64)
7704 # define strtoull __strtoull /* secret handshake */
7706 # if defined(WIN64) && defined(_MSC_VER)
7707 # define strtoull _strtoui64 /* secret handshake */
7709 # if !defined(Strtoul) && defined(HAS_STRTOULL)
7710 # define Strtoul strtoull
7712 # if !defined(Strtoul) && defined(HAS_STRTOUQ)
7713 # define Strtoul strtouq
7715 /* is there atouq() anywhere? */
7717 #if !defined(Strtoul) && defined(HAS_STRTOUL)
7718 # define Strtoul strtoul
7720 #if !defined(Strtoul) && defined(HAS_STRTOL) /* Last resort. */
7721 # define Strtoul(s, e, b) strchr((s), '-') ? ULONG_MAX : (unsigned long)strtol((s), (e), (b))
7724 # define Atoul(s) Strtoul(s, NULL, 10)
7727 #define grok_bin(s,lp,fp,rp) \
7728 grok_bin_oct_hex(s, lp, fp, rp, 1, CC_BINDIGIT_, 'b')
7729 #define grok_oct(s,lp,fp,rp) \
7730 (*(fp) |= PERL_SCAN_DISALLOW_PREFIX, \
7731 grok_bin_oct_hex(s, lp, fp, rp, 3, CC_OCTDIGIT_, '\0'))
7732 #define grok_hex(s,lp,fp,rp) \
7733 grok_bin_oct_hex(s, lp, fp, rp, 4, CC_XDIGIT_, 'x')
7735 #ifndef PERL_SCRIPT_MODE
7736 #define PERL_SCRIPT_MODE "r"
7739 /* not used. Kept as a NOOP for backcompat */
7740 #define PERL_STACK_OVERFLOW_CHECK() NOOP
7743 * Some nonpreemptive operating systems find it convenient to
7744 * check for asynchronous conditions after each op execution.
7745 * Keep this check simple, or it may slow down execution
7750 # ifndef PERL_ASYNC_CHECK
7751 # define PERL_ASYNC_CHECK() if (UNLIKELY(PL_sig_pending)) PL_signalhook(aTHX)
7755 #ifndef PERL_ASYNC_CHECK
7756 # define PERL_ASYNC_CHECK() NOOP
7760 * On some operating systems, a memory allocation may succeed,
7761 * but put the process too close to the system's comfort limit.
7762 * In this case, PERL_ALLOC_CHECK frees the pointer and sets
7765 #ifndef PERL_ALLOC_CHECK
7766 #define PERL_ALLOC_CHECK(p) NOOP
7770 # include <sys/ipc.h>
7771 # include <sys/sem.h>
7772 # ifndef HAS_UNION_SEMUN /* Provide the union semun. */
7775 struct semid_ds *buf;
7776 unsigned short *array;
7779 # ifdef USE_SEMCTL_SEMUN
7780 # ifdef IRIX32_SEMUN_BROKEN_BY_GCC
7781 union gccbug_semun {
7783 struct semid_ds *buf;
7784 unsigned short *array;
7787 # define semun gccbug_semun
7789 # define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun)
7790 # elif defined(USE_SEMCTL_SEMID_DS)
7791 # ifdef EXTRA_F_IN_SEMUN_BUF
7792 # define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buff)
7794 # define Semctl(id, num, cmd, semun) semctl(id, num, cmd, semun.buf)
7800 * Boilerplate macros for initializing and accessing interpreter-local
7801 * data from C. All statics in extensions should be reworked to use
7802 * this, if you want to make the extension thread-safe. See
7803 * ext/XS/APItest/APItest.xs for an example of the use of these macros,
7804 * and perlxs.pod for more.
7806 * Code that uses these macros is responsible for the following:
7807 * 1. #define MY_CXT_KEY to a unique string, e.g.
7808 * "DynaLoader::_guts" XS_VERSION
7809 * XXX in the current implementation, this string is ignored.
7810 * 2. Declare a typedef named my_cxt_t that is a structure that contains
7811 * all the data that needs to be interpreter-local.
7812 * 3. Use the START_MY_CXT macro after the declaration of my_cxt_t.
7813 * 4. Use the MY_CXT_INIT macro such that it is called exactly once
7814 * (typically put in the BOOT: section).
7815 * 5. Use the members of the my_cxt_t structure everywhere as
7817 * 6. Use the dMY_CXT macro (a declaration) in all the functions that
7821 #if defined(MULTIPLICITY)
7823 /* START_MY_CXT must appear in all extensions that define a my_cxt_t structure,
7824 * right after the definition (i.e. at file scope). The non-threads
7825 * case below uses it to declare the data as static. */
7826 # define START_MY_CXT static int my_cxt_index = -1;
7827 # define MY_CXT_INDEX my_cxt_index
7828 # define MY_CXT_INIT_ARG &my_cxt_index
7830 /* Creates and zeroes the per-interpreter data.
7831 * (We allocate my_cxtp in a Perl SV so that it will be released when
7832 * the interpreter goes away.) */
7833 # define MY_CXT_INIT \
7834 my_cxt_t *my_cxtp = \
7835 (my_cxt_t*)Perl_my_cxt_init(aTHX_ MY_CXT_INIT_ARG, sizeof(my_cxt_t)); \
7836 PERL_UNUSED_VAR(my_cxtp)
7837 # define MY_CXT_INIT_INTERP(my_perl) \
7838 my_cxt_t *my_cxtp = \
7839 (my_cxt_t*)Perl_my_cxt_init(my_perl, MY_CXT_INIT_ARG, sizeof(my_cxt_t)); \
7840 PERL_UNUSED_VAR(my_cxtp)
7842 /* This declaration should be used within all functions that use the
7843 * interpreter-local data. */
7845 my_cxt_t *my_cxtp = (my_cxt_t *)PL_my_cxt_list[MY_CXT_INDEX]
7846 # define dMY_CXT_INTERP(my_perl) \
7847 my_cxt_t *my_cxtp = (my_cxt_t *)(my_perl)->Imy_cxt_list[MY_CXT_INDEX]
7849 /* Clones the per-interpreter data. */
7850 # define MY_CXT_CLONE \
7851 my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\
7852 void * old_my_cxtp = PL_my_cxt_list[MY_CXT_INDEX]; \
7853 PL_my_cxt_list[MY_CXT_INDEX] = my_cxtp; \
7854 Copy(old_my_cxtp, my_cxtp, 1, my_cxt_t);
7858 /* This macro must be used to access members of the my_cxt_t structure.
7859 * e.g. MY_CXT.some_data */
7860 # define MY_CXT (*my_cxtp)
7862 /* Judicious use of these macros can reduce the number of times dMY_CXT
7863 * is used. Use is similar to pTHX, aTHX etc. */
7864 # define pMY_CXT my_cxt_t *my_cxtp
7865 # define pMY_CXT_ pMY_CXT,
7866 # define _pMY_CXT ,pMY_CXT
7867 # define aMY_CXT my_cxtp
7868 # define aMY_CXT_ aMY_CXT,
7869 # define _aMY_CXT ,aMY_CXT
7871 #else /* MULTIPLICITY */
7872 # define START_MY_CXT static my_cxt_t my_cxt;
7873 # define dMY_CXT dNOOP
7874 # define dMY_CXT_INTERP(my_perl) dNOOP
7875 # define MY_CXT_INIT NOOP
7876 # define MY_CXT_CLONE NOOP
7877 # define MY_CXT my_cxt
7879 # define pMY_CXT void
7886 #endif /* !defined(MULTIPLICITY) */
7897 # undef FD_CLOEXEC /* a lie in AmigaOS */
7901 # include <sys/file.h>
7904 #if defined(HAS_FLOCK) && !defined(HAS_FLOCK_PROTO)
7905 EXTERN_C int flock(int fd, int op);
7909 /* Assume UNIX defaults */
7910 # define O_RDONLY 0000
7911 # define O_WRONLY 0001
7912 # define O_RDWR 0002
7913 # define O_CREAT 0100
7924 #if O_TEXT != O_BINARY
7925 /* If you have different O_TEXT and O_BINARY and you are a CRLF shop,
7926 * that is, you are somehow DOSish. */
7927 # if defined(__HAIKU__) || defined(__VOS__) || defined(__CYGWIN__)
7928 /* Haiku has O_TEXT != O_BINARY but O_TEXT and O_BINARY have no effect;
7929 * Haiku is always UNIXoid (LF), not DOSish (CRLF). */
7930 /* VOS has O_TEXT != O_BINARY, and they have effect,
7931 * but VOS always uses LF, never CRLF. */
7932 /* If you have O_TEXT different from your O_BINARY but you still are
7933 * not a CRLF shop. */
7934 # undef PERLIO_USING_CRLF
7936 /* If you really are DOSish. */
7937 # define PERLIO_USING_CRLF 1
7942 # include <libutil.h> /* setproctitle() in some FreeBSDs */
7945 #ifndef EXEC_ARGV_CAST
7946 #define EXEC_ARGV_CAST(x) (char **)x
7949 #define IS_NUMBER_IN_UV 0x01 /* number within UV range (maybe not
7950 int). value returned in pointed-
7952 #define IS_NUMBER_GREATER_THAN_UV_MAX 0x02 /* pointed to UV undefined */
7953 #define IS_NUMBER_NOT_INT 0x04 /* saw . or E notation or infnan */
7954 #define IS_NUMBER_NEG 0x08 /* leading minus sign */
7955 #define IS_NUMBER_INFINITY 0x10 /* this is big */
7956 #define IS_NUMBER_NAN 0x20 /* this is not */
7957 #define IS_NUMBER_TRAILING 0x40 /* number has trailing trash */
7960 =for apidoc_section $numeric
7962 =for apidoc AmdR|bool|GROK_NUMERIC_RADIX|NN const char **sp|NN const char *send
7964 A synonym for L</grok_numeric_radix>
7968 #define GROK_NUMERIC_RADIX(sp, send) grok_numeric_radix(sp, send)
7970 /* Number scan flags. All are used for input, the ones used for output are so
7972 #define PERL_SCAN_ALLOW_UNDERSCORES 0x01 /* grok_??? accept _ in numbers */
7973 #define PERL_SCAN_DISALLOW_PREFIX 0x02 /* grok_??? reject 0x in hex etc */
7975 /* grok_??? input: ignored; output: found overflow */
7976 #define PERL_SCAN_GREATER_THAN_UV_MAX 0x04
7978 /* grok_??? don't warn about illegal digits. To preserve total backcompat,
7979 * this isn't set on output if one is found. Instead, see
7980 * PERL_SCAN_NOTIFY_ILLDIGIT. */
7981 #define PERL_SCAN_SILENT_ILLDIGIT 0x08
7983 #define PERL_SCAN_TRAILING 0x10 /* grok_number_flags() allow trailing
7984 and set IS_NUMBER_TRAILING */
7986 /* These are considered experimental, so not exposed publicly */
7987 #if defined(PERL_CORE) || defined(PERL_EXT)
7988 /* grok_??? don't warn about very large numbers which are <= UV_MAX;
7989 * output: found such a number */
7990 # define PERL_SCAN_SILENT_NON_PORTABLE 0x20
7992 /* If this is set on input, and no illegal digit is found, it will be cleared
7993 * on output; otherwise unchanged */
7994 # define PERL_SCAN_NOTIFY_ILLDIGIT 0x40
7996 /* Don't warn on overflow; output flag still set */
7997 # define PERL_SCAN_SILENT_OVERFLOW 0x80
7999 /* Forbid a leading underscore, which the other one doesn't */
8000 # define PERL_SCAN_ALLOW_MEDIAL_UNDERSCORES (0x100|PERL_SCAN_ALLOW_UNDERSCORES)
8004 /* to let user control profiling */
8005 #ifdef PERL_GPROF_CONTROL
8006 extern void moncontrol(int);
8007 #define PERL_GPROF_MONCONTROL(x) moncontrol(x)
8009 #define PERL_GPROF_MONCONTROL(x)
8012 /* ISO 6429 NEL - C1 control NExt Line */
8013 /* See https://www.unicode.org/unicode/reports/tr13/ */
8014 #define NEXT_LINE_CHAR NEXT_LINE_NATIVE
8016 #ifndef PIPESOCK_MODE
8017 # define PIPESOCK_MODE
8020 #ifndef SOCKET_OPEN_MODE
8021 # define SOCKET_OPEN_MODE PIPESOCK_MODE
8024 #ifndef PIPE_OPEN_MODE
8025 # define PIPE_OPEN_MODE PIPESOCK_MODE
8028 #define PERL_MAGIC_UTF8_CACHESIZE 2
8032 #define PERL_UNICODE_STDIN_FLAG 0x0001
8033 #define PERL_UNICODE_STDOUT_FLAG 0x0002
8034 #define PERL_UNICODE_STDERR_FLAG 0x0004
8035 #define PERL_UNICODE_IN_FLAG 0x0008
8036 #define PERL_UNICODE_OUT_FLAG 0x0010
8037 #define PERL_UNICODE_ARGV_FLAG 0x0020
8038 #define PERL_UNICODE_LOCALE_FLAG 0x0040
8039 #define PERL_UNICODE_WIDESYSCALLS_FLAG 0x0080 /* for Sarathy */
8040 #define PERL_UNICODE_UTF8CACHEASSERT_FLAG 0x0100
8042 #define PERL_UNICODE_STD_FLAG \
8043 (PERL_UNICODE_STDIN_FLAG | \
8044 PERL_UNICODE_STDOUT_FLAG | \
8045 PERL_UNICODE_STDERR_FLAG)
8047 #define PERL_UNICODE_INOUT_FLAG \
8048 (PERL_UNICODE_IN_FLAG | \
8049 PERL_UNICODE_OUT_FLAG)
8051 #define PERL_UNICODE_DEFAULT_FLAGS \
8052 (PERL_UNICODE_STD_FLAG | \
8053 PERL_UNICODE_INOUT_FLAG | \
8054 PERL_UNICODE_LOCALE_FLAG)
8056 #define PERL_UNICODE_ALL_FLAGS 0x01ff
8058 #define PERL_UNICODE_STDIN 'I'
8059 #define PERL_UNICODE_STDOUT 'O'
8060 #define PERL_UNICODE_STDERR 'E'
8061 #define PERL_UNICODE_STD 'S'
8062 #define PERL_UNICODE_IN 'i'
8063 #define PERL_UNICODE_OUT 'o'
8064 #define PERL_UNICODE_INOUT 'D'
8065 #define PERL_UNICODE_ARGV 'A'
8066 #define PERL_UNICODE_LOCALE 'L'
8067 #define PERL_UNICODE_WIDESYSCALLS 'W'
8068 #define PERL_UNICODE_UTF8CACHEASSERT 'a'
8073 =for apidoc_section $signals
8074 =for apidoc Amn|U32|PERL_SIGNALS_UNSAFE_FLAG
8075 If this bit in C<PL_signals> is set, the system is uing the pre-Perl 5.8
8076 unsafe signals. See L<perlrun/PERL_SIGNALS> and L<perlipc/Deferred Signals
8081 #define PERL_SIGNALS_UNSAFE_FLAG 0x0001
8084 =for apidoc_section $numeric
8086 =for apidoc Am|int|PERL_ABS|int x
8088 Typeless C<abs> or C<fabs>, I<etc>. (The usage below indicates it is for
8089 integers, but it works for any type.) Use instead of these, since the C
8090 library ones force their argument to be what it is expecting, potentially
8091 leading to disaster. But also beware that this evaluates its argument twice,
8097 #define PERL_ABS(x) ((x) < 0 ? -(x) : (x))
8099 #if defined(__DECC) && defined(__osf__)
8100 #pragma message disable (mainparm) /* Perl uses the envp in main(). */
8103 #define do_open(g, n, l, a, rm, rp, sf) \
8104 do_openn(g, n, l, a, rm, rp, sf, (SV **) NULL, 0)
8105 #ifdef PERL_DEFAULT_DO_EXEC3_IMPLEMENTATION
8106 # define do_exec(cmd) do_exec3(cmd,0,0)
8109 # define do_aexec Perl_do_aexec
8111 # define do_aexec(really, mark,sp) do_aexec5(really, mark, sp, 0, 0)
8116 =for apidoc_section $utility
8118 =for apidoc Am|bool|IS_SAFE_SYSCALL|NN const char *pv|STRLEN len|NN const char *what|NN const char *op_name
8120 Same as L</is_safe_syscall>.
8124 Allows one ending \0
8126 #define IS_SAFE_SYSCALL(p, len, what, op_name) (Perl_is_safe_syscall(aTHX_ (p), (len), (what), (op_name)))
8128 #define IS_SAFE_PATHNAME(p, len, op_name) IS_SAFE_SYSCALL((p), (len), "pathname", (op_name))
8130 #if defined(OEMVS) || defined(__amigaos4__)
8131 #define NO_ENV_ARRAY_IN_MAIN
8134 /* These are used by Perl_pv_escape() and Perl_pv_pretty()
8135 * are here so that they are available throughout the core
8136 * NOTE that even though some are for _escape and some for _pretty
8137 * there must not be any clashes as the flags from _pretty are
8138 * passed straight through to _escape.
8141 #define PERL_PV_ESCAPE_QUOTE 0x000001
8142 #define PERL_PV_PRETTY_QUOTE PERL_PV_ESCAPE_QUOTE
8144 #define PERL_PV_PRETTY_ELLIPSES 0x000002
8145 #define PERL_PV_PRETTY_LTGT 0x000004
8146 #define PERL_PV_PRETTY_EXACTSIZE 0x000008
8148 #define PERL_PV_ESCAPE_UNI 0x000100
8149 #define PERL_PV_ESCAPE_UNI_DETECT 0x000200
8150 #define PERL_PV_ESCAPE_NONASCII 0x000400
8151 #define PERL_PV_ESCAPE_FIRSTCHAR 0x000800
8153 #define PERL_PV_ESCAPE_ALL 0x001000
8154 #define PERL_PV_ESCAPE_NOBACKSLASH 0x002000
8155 #define PERL_PV_ESCAPE_NOCLEAR 0x004000
8156 #define PERL_PV_PRETTY_NOCLEAR PERL_PV_ESCAPE_NOCLEAR
8157 #define PERL_PV_ESCAPE_RE 0x008000
8159 /* Escape PV with hex, except leave NULs as octal: */
8160 #define PERL_PV_ESCAPE_DWIM 0x010000
8162 /* Escape PV with all hex, including NUL. */
8163 #define PERL_PV_ESCAPE_DWIM_ALL_HEX 0x020000
8165 /* Do not escape word characters, alters meaning of other flags */
8166 #define PERL_PV_ESCAPE_NON_WC 0x040000
8167 #define PERL_PV_ESCAPE_TRUNC_MIDDLE 0x080000
8169 #define PERL_PV_PRETTY_QUOTEDPREFIX ( \
8170 PERL_PV_PRETTY_ELLIPSES | \
8171 PERL_PV_PRETTY_QUOTE | \
8172 PERL_PV_ESCAPE_NONASCII | \
8173 PERL_PV_ESCAPE_NON_WC | \
8174 PERL_PV_ESCAPE_TRUNC_MIDDLE | \
8178 /* used by pv_display in dump.c*/
8179 #define PERL_PV_PRETTY_DUMP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_QUOTE
8180 #define PERL_PV_PRETTY_REGPROP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_LTGT|PERL_PV_ESCAPE_RE|PERL_PV_ESCAPE_NONASCII
8182 #if DOUBLEKIND == DOUBLE_IS_VAX_F_FLOAT || \
8183 DOUBLEKIND == DOUBLE_IS_VAX_D_FLOAT || \
8184 DOUBLEKIND == DOUBLE_IS_VAX_G_FLOAT
8185 # define DOUBLE_IS_VAX_FLOAT
8187 # define DOUBLE_IS_IEEE_FORMAT
8190 #if DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN || \
8191 DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN || \
8192 DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
8193 # define DOUBLE_LITTLE_ENDIAN
8196 #if DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN || \
8197 DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN || \
8198 DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
8199 # define DOUBLE_BIG_ENDIAN
8202 #if DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE || \
8203 DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE
8204 # define DOUBLE_MIX_ENDIAN
8207 /* The VAX fp formats are neither consistently little-endian nor
8208 * big-endian, and neither are they really IEEE-mixed endian like
8209 * the mixed-endian ARM IEEE formats (with swapped bytes).
8210 * Ultimately, the VAX format came from the PDP-11.
8212 * The ordering of the parts in VAX floats is quite vexing.
8213 * In the below the fraction_n are the mantissa bits.
8215 * The fraction_1 is the most significant (numbering as by DEC/Digital),
8216 * while the rightmost bit in each fraction is the least significant:
8217 * in other words, big-endian bit order within the fractions.
8219 * The fraction segments themselves would be big-endianly, except that
8220 * within 32 bit segments the less significant half comes first, the more
8221 * significant after, except that in the format H (used for long doubles)
8222 * the first fraction segment is alone, because the exponent is wider.
8223 * This means for example that both the most and the least significant
8224 * bits can be in the middle of the floats, not at either end.
8227 * http://nssdc.gsfc.nasa.gov/nssdc/formats/VAXFloatingPoint.htm
8228 * http://www.quadibloc.com/comp/cp0201.htm
8229 * http://h71000.www7.hp.com/doc/82final/6443/6443pro_028.html
8230 * (somebody at HP should be fired for the URLs)
8232 * F fraction_2:16 sign:1 exp:8 fraction_1:7
8233 * (exponent bias 128, hidden first one-bit)
8235 * D fraction_2:16 sign:1 exp:8 fraction_1:7
8236 * fraction_4:16 fraction_3:16
8237 * (exponent bias 128, hidden first one-bit)
8239 * G fraction_2:16 sign:1 exp:11 fraction_1:4
8240 * fraction_4:16 fraction_3:16
8241 * (exponent bias 1024, hidden first one-bit)
8243 * H fraction_1:16 sign:1 exp:15
8244 * fraction_3:16 fraction_2:16
8245 * fraction_5:16 fraction_4:16
8246 * fraction_7:16 fraction_6:16
8247 * (exponent bias 16384, hidden first one-bit)
8248 * (available only on VAX, and only on Fortran?)
8250 * The formats S, T and X are available on the Alpha (and Itanium,
8251 * also known as I64/IA64) and are equivalent with the IEEE-754 formats
8252 * binary32, binary64, and binary128 (commonly: float, double, long double).
8254 * S sign:1 exp:8 mantissa:23
8255 * (exponent bias 127, hidden first one-bit)
8257 * T sign:1 exp:11 mantissa:52
8258 * (exponent bias 1022, hidden first one-bit)
8260 * X sign:1 exp:15 mantissa:112
8261 * (exponent bias 16382, hidden first one-bit)
8265 #ifdef DOUBLE_IS_VAX_FLOAT
8266 # define DOUBLE_VAX_ENDIAN
8269 #ifdef DOUBLE_IS_IEEE_FORMAT
8270 /* All the basic IEEE formats have the implicit bit,
8271 * except for the x86 80-bit extended formats, which will undef this.
8272 * Also note that the IEEE 754 subnormals (formerly known as denormals)
8273 * do not have the implicit bit of one. */
8274 # define NV_IMPLICIT_BIT
8277 #if defined(LONG_DOUBLEKIND) && LONG_DOUBLEKIND != LONG_DOUBLE_IS_DOUBLE
8279 # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN || \
8280 LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN || \
8281 LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE
8282 # define LONGDOUBLE_LITTLE_ENDIAN
8285 # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN || \
8286 LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN || \
8287 LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE
8288 # define LONGDOUBLE_BIG_ENDIAN
8291 # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE || \
8292 LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE
8293 # define LONGDOUBLE_MIX_ENDIAN
8296 # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN || \
8297 LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN
8298 # define LONGDOUBLE_X86_80_BIT
8299 # ifdef USE_LONG_DOUBLE
8300 # undef NV_IMPLICIT_BIT
8301 # define NV_X86_80_BIT
8305 # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE || \
8306 LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE || \
8307 LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE || \
8308 LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE
8309 # define LONGDOUBLE_DOUBLEDOUBLE
8312 # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_VAX_H_FLOAT
8313 # define LONGDOUBLE_VAX_ENDIAN
8316 #endif /* LONG_DOUBLEKIND */
8318 #ifdef USE_QUADMATH /* assume quadmath endianness == native double endianness */
8319 # if defined(DOUBLE_LITTLE_ENDIAN)
8320 # define NV_LITTLE_ENDIAN
8321 # elif defined(DOUBLE_BIG_ENDIAN)
8322 # define NV_BIG_ENDIAN
8323 # elif defined(DOUBLE_MIX_ENDIAN) /* stretch */
8324 # define NV_MIX_ENDIAN
8326 #elif NVSIZE == DOUBLESIZE
8327 # ifdef DOUBLE_LITTLE_ENDIAN
8328 # define NV_LITTLE_ENDIAN
8330 # ifdef DOUBLE_BIG_ENDIAN
8331 # define NV_BIG_ENDIAN
8333 # ifdef DOUBLE_MIX_ENDIAN
8334 # define NV_MIX_ENDIAN
8336 # ifdef DOUBLE_VAX_ENDIAN
8337 # define NV_VAX_ENDIAN
8339 #elif NVSIZE == LONG_DOUBLESIZE
8340 # ifdef LONGDOUBLE_LITTLE_ENDIAN
8341 # define NV_LITTLE_ENDIAN
8343 # ifdef LONGDOUBLE_BIG_ENDIAN
8344 # define NV_BIG_ENDIAN
8346 # ifdef LONGDOUBLE_MIX_ENDIAN
8347 # define NV_MIX_ENDIAN
8349 # ifdef LONGDOUBLE_VAX_ENDIAN
8350 # define NV_VAX_ENDIAN
8354 /* We have somehow managed not to define the denormal/subnormal
8357 * This may happen if the compiler doesn't expose the C99 math like
8358 * the fpclassify() without some special switches. Perl tries to
8359 * stay C89, so for example -std=c99 is not an option.
8361 * The Perl_isinf() and Perl_isnan() should have been defined even if
8362 * the C99 isinf() and isnan() are unavailable, and the NV_MIN becomes
8363 * from the C89 DBL_MIN or moral equivalent. */
8364 #if !defined(Perl_fp_class_denorm) && defined(Perl_isinf) && defined(Perl_isnan) && defined(NV_MIN)
8365 # define Perl_fp_class_denorm(x) ((x) != 0.0 && !Perl_isinf(x) && !Perl_isnan(x) && PERL_ABS(x) < NV_MIN)
8368 /* This is not a great fallback: subnormals tests will fail,
8369 * but at least Perl will link and 99.999% of tests will work. */
8370 #if !defined(Perl_fp_class_denorm)
8371 # define Perl_fp_class_denorm(x) FALSE
8374 #ifdef DOUBLE_IS_IEEE_FORMAT
8375 # define DOUBLE_HAS_INF
8376 # define DOUBLE_HAS_NAN
8379 #ifdef DOUBLE_HAS_NAN
8385 /* PL_inf and PL_nan initialization.
8387 * For inf and nan initialization the ultimate fallback is dividing
8388 * one or zero by zero: however, some compilers will warn or even fail
8389 * on divide-by-zero, but hopefully something earlier will work.
8391 * If you are thinking of using HUGE_VAL for infinity, or using
8392 * <math.h> functions to generate NV_INF (e.g. exp(1e9), log(-1.0)),
8393 * stop. Neither will work portably: HUGE_VAL can be just DBL_MAX,
8394 * and the math functions might be just generating DBL_MAX, or even zero.
8396 * Also, do NOT try doing NV_NAN based on NV_INF and trying (NV_INF-NV_INF).
8397 * Though logically correct, some compilers (like Visual C 2003)
8398 * falsely misoptimize that to zero (x-x is always zero, right?)
8400 * Finally, note that not all floating point formats define Inf (or NaN).
8401 * For the infinity a large number may be used instead. Operations that
8402 * under the IEEE floating point would return Inf or NaN may return
8403 * either large numbers (positive or negative), or they may cause
8404 * a floating point exception or some other fault.
8407 /* The quadmath literals are anon structs which -Wc++-compat doesn't like. */
8408 # ifndef USE_CPLUSPLUS
8409 GCC_DIAG_IGNORE_DECL(-Wc++-compat);
8412 # ifdef USE_QUADMATH
8413 /* Cannot use HUGE_VALQ for PL_inf because not a compile-time
8415 INFNAN_NV_U8_DECL PL_inf = { 1.0Q/0.0Q };
8416 # elif NVSIZE == LONG_DOUBLESIZE && defined(LONGDBLINFBYTES)
8417 INFNAN_U8_NV_DECL PL_inf = { { LONGDBLINFBYTES } };
8418 # elif NVSIZE == DOUBLESIZE && defined(DOUBLEINFBYTES)
8419 INFNAN_U8_NV_DECL PL_inf = { { DOUBLEINFBYTES } };
8421 # if NVSIZE == LONG_DOUBLESIZE && defined(USE_LONG_DOUBLE)
8422 # if defined(LDBL_INFINITY)
8423 INFNAN_NV_U8_DECL PL_inf = { LDBL_INFINITY };
8424 # elif defined(LDBL_INF)
8425 INFNAN_NV_U8_DECL PL_inf = { LDBL_INF };
8426 # elif defined(INFINITY)
8427 INFNAN_NV_U8_DECL PL_inf = { (NV)INFINITY };
8429 INFNAN_NV_U8_DECL PL_inf = { (NV)INF };
8431 INFNAN_NV_U8_DECL PL_inf = { 1.0L/0.0L }; /* keep last */
8434 # if defined(DBL_INFINITY)
8435 INFNAN_NV_U8_DECL PL_inf = { DBL_INFINITY };
8436 # elif defined(DBL_INF)
8437 INFNAN_NV_U8_DECL PL_inf = { DBL_INF };
8438 # elif defined(INFINITY) /* C99 */
8439 INFNAN_NV_U8_DECL PL_inf = { (NV)INFINITY };
8441 INFNAN_NV_U8_DECL PL_inf = { (NV)INF };
8443 INFNAN_NV_U8_DECL PL_inf = { 1.0/0.0 }; /* keep last */
8448 # ifdef USE_QUADMATH
8449 /* Cannot use nanq("0") for PL_nan because not a compile-time
8451 INFNAN_NV_U8_DECL PL_nan = { 0.0Q/0.0Q };
8452 # elif NVSIZE == LONG_DOUBLESIZE && defined(LONGDBLNANBYTES)
8453 INFNAN_U8_NV_DECL PL_nan = { { LONGDBLNANBYTES } };
8454 # elif NVSIZE == DOUBLESIZE && defined(DOUBLENANBYTES)
8455 INFNAN_U8_NV_DECL PL_nan = { { DOUBLENANBYTES } };
8457 # if NVSIZE == LONG_DOUBLESIZE && defined(USE_LONG_DOUBLE)
8458 # if defined(LDBL_NAN)
8459 INFNAN_NV_U8_DECL PL_nan = { LDBL_NAN };
8460 # elif defined(LDBL_QNAN)
8461 INFNAN_NV_U8_DECL PL_nan = { LDBL_QNAN };
8463 INFNAN_NV_U8_DECL PL_nan = { (NV)NAN };
8465 INFNAN_NV_U8_DECL PL_nan = { 0.0L/0.0L }; /* keep last */
8468 # if defined(DBL_NAN)
8469 INFNAN_NV_U8_DECL PL_nan = { DBL_NAN };
8470 # elif defined(DBL_QNAN)
8471 INFNAN_NV_U8_DECL PL_nan = { DBL_QNAN };
8472 # elif defined(NAN) /* C99 */
8473 INFNAN_NV_U8_DECL PL_nan = { (NV)NAN };
8475 INFNAN_NV_U8_DECL PL_nan = { 0.0/0.0 }; /* keep last */
8480 # ifndef USE_CPLUSPLUS
8481 GCC_DIAG_RESTORE_DECL;
8486 /* The declarations here need to match the initializations done above,
8487 since a mismatch across compilation units causes undefined
8488 behavior. It also prevents warnings from LTO builds.
8490 # if !defined(USE_QUADMATH) && \
8491 (NVSIZE == LONG_DOUBLESIZE && defined(LONGDBLINFBYTES) || \
8492 NVSIZE == DOUBLESIZE && defined(DOUBLEINFBYTES))
8493 INFNAN_U8_NV_DECL PL_inf;
8495 INFNAN_NV_U8_DECL PL_inf;
8498 # if !defined(USE_QUADMATH) && \
8499 (NVSIZE == LONG_DOUBLESIZE && defined(LONGDBLNANBYTES) || \
8500 NVSIZE == DOUBLESIZE && defined(DOUBLENANBYTES))
8501 INFNAN_U8_NV_DECL PL_nan;
8503 INFNAN_NV_U8_DECL PL_nan;
8510 /* If you have not defined NV_INF/NV_NAN (like for example win32/win32.h),
8511 * we will define NV_INF/NV_NAN as the nv part of the global const
8512 * PL_inf/PL_nan. Note, however, that the preexisting NV_INF/NV_NAN
8513 * might not be a compile-time constant, in which case it cannot be
8514 * used to initialize PL_inf/PL_nan above. */
8516 # define NV_INF PL_inf.nv
8519 # define NV_NAN PL_nan.nv
8522 /* NaNs (not-a-numbers) can carry payload bits, in addition to
8523 * "nan-ness". Part of the payload is the quiet/signaling bit.
8524 * To back up a bit (harhar):
8526 * For IEEE 754 64-bit formats [1]:
8528 * s 000 (mantissa all-zero) zero
8529 * s 000 (mantissa non-zero) subnormals (denormals)
8530 * s 001 ... 7fe normals
8533 * For IEEE 754 128-bit formats:
8535 * s 0000 (mantissa all-zero) zero
8536 * s 0000 (mantissa non-zero) subnormals (denormals)
8537 * s 0001 ... 7ffe normals
8540 * [1] this looks like big-endian, but applies equally to little-endian.
8542 * s = Sign bit. Yes, zeros and nans can have negative sign,
8543 * the interpretation is application-specific.
8545 * q = Quietness bit, the interpretation is platform-specific.
8546 * Most platforms have the most significant bit being one
8547 * meaning quiet, but some (older mips, hppa) have the msb
8548 * being one meaning signaling. Note that the above means
8549 * that on most platforms there cannot be signaling nan with
8550 * zero payload because that is identical with infinity;
8551 * while conversely on older mips/hppa there cannot be a quiet nan
8552 * because that is identical with infinity.
8554 * Moreover, whether there is any behavioral difference
8555 * between quiet and signaling NaNs, depends on the platform.
8557 * x86 80-bit extended precision is different, the mantissa bits:
8559 * 63 62 61 30387+ pre-387 visual c
8560 * -------- ---- -------- --------
8561 * 0 0 0 invalid infinity
8562 * 0 0 1 invalid snan
8563 * 0 1 0 invalid snan
8564 * 0 1 1 invalid snan
8565 * 1 0 0 infinity snan 1.#INF
8566 * 1 0 1 snan 1.#SNAN
8567 * 1 1 0 qnan -1.#IND (x86 chooses this to negative)
8568 * 1 1 1 qnan 1.#QNAN
8570 * This means that in this format there are 61 bits available
8571 * for the nan payload.
8573 * Note that the 32-bit x86 ABI cannot do signaling nans: the x87
8574 * simply cannot preserve the bit. You can either use the 80-bit
8575 * extended precision (long double, -Duselongdouble), or use x86-64.
8577 * In all platforms, the payload bytes (and bits, some of them are
8578 * often in a partial byte) themselves can be either all zero (x86),
8579 * all one (sparc or mips), or a mixture: in IEEE 754 128-bit double
8580 * or in a double-double, the first half of the payload can follow the
8581 * native double, while in the second half the payload can be all
8582 * zeros. (Therefore the mask for payload bits is not necessarily
8583 * identical to bit complement of the NaN.) Another way of putting
8584 * this: the payload for the default NaN might not be zero.
8586 * For the x86 80-bit long doubles, the trailing bytes (the 80 bits
8587 * being 'packaged' in either 12 or 16 bytes) can be whatever random
8590 * Furthermore, the semantics of the sign bit on NaNs are platform-specific.
8591 * On normal floats, the sign bit being on means negative. But this may,
8592 * or may not, be reverted on NaNs: in other words, the default NaN might
8593 * have the sign bit on, and therefore look like negative if you look
8594 * at it at the bit level.
8596 * NaN payloads are not propagated even on copies, or in arithmetics.
8597 * They *might* be, according to some rules, on your particular
8598 * cpu/os/compiler/libraries, but no guarantees.
8600 * To summarize, on most platforms, and for 64-bit doubles
8601 * (using big-endian ordering here):
8603 * [7FF8000000000000..7FFFFFFFFFFFFFFF] quiet
8604 * [FFF8000000000000..FFFFFFFFFFFFFFFF] quiet
8605 * [7FF0000000000001..7FF7FFFFFFFFFFFF] signaling
8606 * [FFF0000000000001..FFF7FFFFFFFFFFFF] signaling
8608 * The C99 nan() is supposed to generate *quiet* NaNs.
8610 * Note the asymmetry:
8611 * The 7FF0000000000000 is positive infinity,
8612 * the FFF0000000000000 is negative infinity.
8615 /* NVMANTBITS is the number of _real_ mantissa bits in an NV.
8616 * For the standard IEEE 754 fp this number is usually one less that
8617 * *DBL_MANT_DIG because of the implicit (aka hidden) bit, which isn't
8618 * real. For the 80-bit extended precision formats (x86*), the number
8619 * of mantissa bits... depends. For normal floats, it's 64. But for
8620 * the inf/nan, it's different (zero for inf, 61 for nan).
8621 * NVMANTBITS works for normal floats. */
8623 /* We do not want to include the quiet/signaling bit. */
8624 #define NV_NAN_BITS (NVMANTBITS - 1)
8626 #if defined(USE_LONG_DOUBLE) && NVSIZE > DOUBLESIZE
8627 # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
8628 # define NV_NAN_QS_BYTE_OFFSET 13
8629 # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
8630 # define NV_NAN_QS_BYTE_OFFSET 2
8631 # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN
8632 # define NV_NAN_QS_BYTE_OFFSET 7
8633 # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN
8634 # define NV_NAN_QS_BYTE_OFFSET 2
8635 # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE
8636 # define NV_NAN_QS_BYTE_OFFSET 13
8637 # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE
8638 # define NV_NAN_QS_BYTE_OFFSET 1
8639 # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE
8640 # define NV_NAN_QS_BYTE_OFFSET 9
8641 # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE
8642 # define NV_NAN_QS_BYTE_OFFSET 6
8644 # error "Unexpected long double format"
8647 # ifdef USE_QUADMATH
8648 # ifdef NV_LITTLE_ENDIAN
8649 # define NV_NAN_QS_BYTE_OFFSET 13
8650 # elif defined(NV_BIG_ENDIAN)
8651 # define NV_NAN_QS_BYTE_OFFSET 2
8653 # error "Unexpected quadmath format"
8655 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN
8656 # define NV_NAN_QS_BYTE_OFFSET 2
8657 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN
8658 # define NV_NAN_QS_BYTE_OFFSET 1
8659 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN
8660 # define NV_NAN_QS_BYTE_OFFSET 6
8661 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN
8662 # define NV_NAN_QS_BYTE_OFFSET 1
8663 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
8664 # define NV_NAN_QS_BYTE_OFFSET 13
8665 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
8666 # define NV_NAN_QS_BYTE_OFFSET 2
8667 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE
8668 # define NV_NAN_QS_BYTE_OFFSET 2 /* bytes 4 5 6 7 0 1 2 3 (MSB 7) */
8669 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE
8670 # define NV_NAN_QS_BYTE_OFFSET 5 /* bytes 3 2 1 0 7 6 5 4 (MSB 7) */
8672 /* For example the VAX formats should never
8673 * get here because they do not have NaN. */
8674 # error "Unexpected double format"
8677 /* NV_NAN_QS_BYTE is the byte to test for the quiet/signaling */
8678 #define NV_NAN_QS_BYTE(nvp) (((U8*)(nvp))[NV_NAN_QS_BYTE_OFFSET])
8679 /* NV_NAN_QS_BIT is the bit to test in the NV_NAN_QS_BYTE_OFFSET
8680 * for the quiet/signaling */
8681 #if defined(USE_LONG_DOUBLE) && \
8682 (LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN || \
8683 LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN)
8684 # define NV_NAN_QS_BIT_SHIFT 6 /* 0x40 */
8685 #elif defined(USE_LONG_DOUBLE) && \
8686 (LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE || \
8687 LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE || \
8688 LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE || \
8689 LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE)
8690 # define NV_NAN_QS_BIT_SHIFT 3 /* 0x08, but not via NV_NAN_BITS */
8692 # define NV_NAN_QS_BIT_SHIFT ((NV_NAN_BITS) % 8) /* usually 3, or 0x08 */
8694 #define NV_NAN_QS_BIT (1 << (NV_NAN_QS_BIT_SHIFT))
8695 /* NV_NAN_QS_BIT_OFFSET is the bit offset from the beginning of a NV
8696 * (bytes ordered big-endianly) for the quiet/signaling bit
8697 * for the quiet/signaling */
8698 #define NV_NAN_QS_BIT_OFFSET \
8699 (8 * (NV_NAN_QS_BYTE_OFFSET) + (NV_NAN_QS_BIT_SHIFT))
8700 /* NV_NAN_QS_QUIET (always defined) is true if the NV_NAN_QS_QS_BIT being
8701 * on indicates quiet NaN. NV_NAN_QS_SIGNALING (also always defined)
8702 * is true if the NV_NAN_QS_BIT being on indicates signaling NaN. */
8703 #define NV_NAN_QS_QUIET \
8704 ((NV_NAN_QS_BYTE(PL_nan.u8) & NV_NAN_QS_BIT) == NV_NAN_QS_BIT)
8705 #define NV_NAN_QS_SIGNALING (!(NV_NAN_QS_QUIET))
8706 #define NV_NAN_QS_TEST(nvp) (NV_NAN_QS_BYTE(nvp) & NV_NAN_QS_BIT)
8707 /* NV_NAN_IS_QUIET() returns true if the NV behind nvp is a NaN,
8708 * whether it is a quiet NaN, NV_NAN_IS_SIGNALING() if a signaling NaN.
8709 * Note however that these do not check whether the nvp is a NaN. */
8710 #define NV_NAN_IS_QUIET(nvp) \
8711 (NV_NAN_QS_TEST(nvp) == (NV_NAN_QS_QUIET ? NV_NAN_QS_BIT : 0))
8712 #define NV_NAN_IS_SIGNALING(nvp) \
8713 (NV_NAN_QS_TEST(nvp) == (NV_NAN_QS_QUIET ? 0 : NV_NAN_QS_BIT))
8714 #define NV_NAN_SET_QUIET(nvp) \
8715 (NV_NAN_QS_QUIET ? \
8716 (NV_NAN_QS_BYTE(nvp) |= NV_NAN_QS_BIT) : \
8717 (NV_NAN_QS_BYTE(nvp) &= ~NV_NAN_QS_BIT))
8718 #define NV_NAN_SET_SIGNALING(nvp) \
8719 (NV_NAN_QS_QUIET ? \
8720 (NV_NAN_QS_BYTE(nvp) &= ~NV_NAN_QS_BIT) : \
8721 (NV_NAN_QS_BYTE(nvp) |= NV_NAN_QS_BIT))
8722 #define NV_NAN_QS_XOR(nvp) (NV_NAN_QS_BYTE(nvp) ^= NV_NAN_QS_BIT)
8724 /* NV_NAN_PAYLOAD_MASK: masking the nan payload bits.
8726 * NV_NAN_PAYLOAD_PERM: permuting the nan payload bytes.
8727 * 0xFF means "don't go here".*/
8729 /* Shorthands to avoid typoses. */
8730 #define NV_NAN_PAYLOAD_MASK_SKIP_EIGHT \
8731 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
8732 #define NV_NAN_PAYLOAD_PERM_SKIP_EIGHT \
8733 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8734 #define NV_NAN_PAYLOAD_PERM_0_TO_7 \
8735 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7
8736 #define NV_NAN_PAYLOAD_PERM_7_TO_0 \
8737 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0
8738 #define NV_NAN_PAYLOAD_MASK_IEEE_754_128_LE \
8739 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
8740 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00
8741 #define NV_NAN_PAYLOAD_PERM_IEEE_754_128_LE \
8742 NV_NAN_PAYLOAD_PERM_0_TO_7, \
8743 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xFF, 0xFF
8744 #define NV_NAN_PAYLOAD_MASK_IEEE_754_128_BE \
8745 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, \
8746 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8747 #define NV_NAN_PAYLOAD_PERM_IEEE_754_128_BE \
8748 0xFF, 0xFF, 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, \
8749 NV_NAN_PAYLOAD_PERM_7_TO_0
8750 #define NV_NAN_PAYLOAD_MASK_IEEE_754_64_LE \
8751 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00
8752 #define NV_NAN_PAYLOAD_PERM_IEEE_754_64_LE \
8753 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0xFF
8754 #define NV_NAN_PAYLOAD_MASK_IEEE_754_64_BE \
8755 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8756 #define NV_NAN_PAYLOAD_PERM_IEEE_754_64_BE \
8757 0xFF, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0
8759 #if defined(USE_LONG_DOUBLE) && NVSIZE > DOUBLESIZE
8760 # if LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
8761 # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_LE
8762 # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_LE
8763 # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
8764 # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_BE
8765 # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_BE
8766 # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN
8767 # if LONG_DOUBLESIZE == 10
8768 # define NV_NAN_PAYLOAD_MASK \
8769 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, \
8771 # define NV_NAN_PAYLOAD_PERM \
8772 NV_NAN_PAYLOAD_PERM_0_TO_7, 0xFF, 0xFF
8773 # elif LONG_DOUBLESIZE == 12
8774 # define NV_NAN_PAYLOAD_MASK \
8775 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, \
8776 0x00, 0x00, 0x00, 0x00
8777 # define NV_NAN_PAYLOAD_PERM \
8778 NV_NAN_PAYLOAD_PERM_0_TO_7, 0xFF, 0xFF, 0xFF, 0xFF
8779 # elif LONG_DOUBLESIZE == 16
8780 # define NV_NAN_PAYLOAD_MASK \
8781 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, \
8782 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8783 # define NV_NAN_PAYLOAD_PERM \
8784 NV_NAN_PAYLOAD_PERM_0_TO_7, \
8785 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
8787 # error "Unexpected x86 80-bit little-endian long double format"
8789 # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN
8790 # if LONG_DOUBLESIZE == 10
8791 # define NV_NAN_PAYLOAD_MASK \
8792 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, \
8794 # define NV_NAN_PAYLOAD_PERM \
8795 NV_NAN_PAYLOAD_PERM_7_TO_0, 0xFF, 0xFF
8796 # elif LONG_DOUBLESIZE == 12
8797 # define NV_NAN_PAYLOAD_MASK \
8798 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, \
8799 0xff, 0xff, 0x00, 0x00
8800 # define NV_NAN_PAYLOAD_PERM \
8801 NV_NAN_PAYLOAD_PERM_7_TO_0, 0xFF, 0xFF, 0xFF, 0xFF
8802 # elif LONG_DOUBLESIZE == 16
8803 # define NV_NAN_PAYLOAD_MASK \
8804 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, \
8805 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8806 # define NV_NAN_PAYLOAD_PERM \
8807 NV_NAN_PAYLOAD_PERM_7_TO_0, \
8808 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
8810 # error "Unexpected x86 80-bit big-endian long double format"
8812 # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE
8813 /* For double-double we assume only the first double (in LE or BE terms)
8814 * is used for NaN. */
8815 # define NV_NAN_PAYLOAD_MASK \
8816 NV_NAN_PAYLOAD_MASK_SKIP_EIGHT, NV_NAN_PAYLOAD_MASK_IEEE_754_64_LE
8817 # define NV_NAN_PAYLOAD_PERM \
8818 NV_NAN_PAYLOAD_PERM_SKIP_EIGHT, NV_NAN_PAYLOAD_PERM_IEEE_754_64_LE
8819 # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE
8820 # define NV_NAN_PAYLOAD_MASK \
8821 NV_NAN_PAYLOAD_MASK_IEEE_754_64_BE
8822 # define NV_NAN_PAYLOAD_PERM \
8823 NV_NAN_PAYLOAD_PERM_IEEE_754_64_BE
8824 # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE
8825 # define NV_NAN_PAYLOAD_MASK \
8826 NV_NAN_PAYLOAD_MASK_IEEE_754_64_LE
8827 # define NV_NAN_PAYLOAD_PERM \
8828 NV_NAN_PAYLOAD_PERM_IEEE_754_64_LE
8829 # elif LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE
8830 # define NV_NAN_PAYLOAD_MASK \
8831 NV_NAN_PAYLOAD_MASK_SKIP_EIGHT, NV_NAN_PAYLOAD_MASK_IEEE_754_64_BE
8832 # define NV_NAN_PAYLOAD_PERM \
8833 NV_NAN_PAYLOAD_PERM_SKIP_EIGHT, NV_NAN_PAYLOAD_PERM_IEEE_754_64_BE
8835 # error "Unexpected long double format"
8838 # ifdef USE_QUADMATH /* quadmath is not long double */
8839 # ifdef NV_LITTLE_ENDIAN
8840 # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_LE
8841 # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_LE
8842 # elif defined(NV_BIG_ENDIAN)
8843 # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_BE
8844 # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_BE
8846 # error "Unexpected quadmath format"
8848 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN
8849 # define NV_NAN_PAYLOAD_MASK 0xff, 0xff, 0x07, 0x00
8850 # define NV_NAN_PAYLOAD_PERM 0x0, 0x1, 0x2, 0xFF
8851 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN
8852 # define NV_NAN_PAYLOAD_MASK 0x00, 0x07, 0xff, 0xff
8853 # define NV_NAN_PAYLOAD_PERM 0xFF, 0x2, 0x1, 0x0
8854 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN
8855 # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_64_LE
8856 # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_64_LE
8857 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN
8858 # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_64_BE
8859 # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_64_BE
8860 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
8861 # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_LE
8862 # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_LE
8863 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
8864 # define NV_NAN_PAYLOAD_MASK NV_NAN_PAYLOAD_MASK_IEEE_754_128_BE
8865 # define NV_NAN_PAYLOAD_PERM NV_NAN_PAYLOAD_PERM_IEEE_754_128_BE
8866 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE
8867 # define NV_NAN_PAYLOAD_MASK 0xff, 0xff, 0x07, 0x00, 0xff, 0xff, 0xff, 0xff
8868 # define NV_NAN_PAYLOAD_PERM 0x4, 0x5, 0x6, 0xFF, 0x0, 0x1, 0x2, 0x3
8869 # elif DOUBLEKIND == DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE
8870 # define NV_NAN_PAYLOAD_MASK 0xff, 0xff, 0xff, 0xff, 0x00, 0x07, 0xff, 0xff
8871 # define NV_NAN_PAYLOAD_PERM 0x3, 0x2, 0x1, 0x0, 0xFF, 0x6, 0x5, 0x4
8873 # error "Unexpected double format"
8877 #endif /* DOUBLE_HAS_NAN */
8879 /* these are used to faciliate the env var PERL_RAND_SEED,
8880 * which allows consistent behavior from code that calls
8881 * srand() with no arguments, either explicitly or implicitly.
8883 #define PERL_SRAND_OVERRIDE_NEXT() PERL_XORSHIFT32_A(PL_srand_override_next);
8885 #define PERL_SRAND_OVERRIDE_NEXT_INIT() STMT_START { \
8886 PL_srand_override = PL_srand_override_next; \
8887 PERL_SRAND_OVERRIDE_NEXT(); \
8890 #define PERL_SRAND_OVERRIDE_GET(into) STMT_START { \
8891 into= PL_srand_override; \
8892 PERL_SRAND_OVERRIDE_NEXT_INIT(); \
8895 #define PERL_SRAND_OVERRIDE_NEXT_CHILD() STMT_START { \
8896 PERL_XORSHIFT32_B(PL_srand_override_next); \
8897 PERL_SRAND_OVERRIDE_NEXT_INIT(); \
8900 #define PERL_SRAND_OVERRIDE_NEXT_PARENT() \
8901 PERL_SRAND_OVERRIDE_NEXT()
8906 (KEEP THIS LAST IN perl.h!)
8948 so that Configure picks them up.
8950 (KEEP THIS LAST IN perl.h!)
8954 #endif /* Include guard */
8957 * ex: set ts=8 sts=4 sw=4 et: