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