* Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
* 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by Larry Wall and others
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
* This file is being used for x2p stuff.
* Above symbol is defined via -D in 'x2p/Makefile.SH'
* Decouple x2p stuff from some of perls more extreme eccentricities.
#endif /* PERL_FOR_X2P */
/* this is used for functions which take a depth trailing
* argument under debugging */
#define _pDEPTH ,U32 depth
/* NOTE 1: that with gcc -std=c89 the __STDC_VERSION__ is *not* defined
* because the __STDC_VERSION__ became a thing only with C90. Therefore,
* with gcc, HAS_C99 will never become true as long as we use -std=c89.
* NOTE 2: headers lie. Do not expect that if HAS_C99 gets to be true,
* all the C99 features are there and are correct. */
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
defined(_STDC_C99) || defined(__c99)
/* See L<perlguts/"The Perl API"> for detailed notes on
* PERL_IMPLICIT_CONTEXT and PERL_IMPLICIT_SYS */
/* Note that from here --> to <-- the same logic is
* repeated in makedef.pl, so be certain to update
* both places when editing. */
# if !defined(MULTIPLICITY)
#ifdef PERL_GLOBAL_STRUCT_PRIVATE
# ifndef PERL_GLOBAL_STRUCT
# define PERL_GLOBAL_STRUCT
#ifdef PERL_GLOBAL_STRUCT
# ifndef PERL_IMPLICIT_CONTEXT
# define PERL_IMPLICIT_CONTEXT
/* undef WIN32 when building on Cygwin (for libwin32) - gph */
#if defined(__SYMBIAN32__) || (defined(__VC32__) && defined(WINS))
# include "symbian/symbian_proto.h"
/* Any stack-challenged places. The limit varies (and often
* is configurable), but using more than a kilobyte of stack
* is usually dubious in these systems. */
#if defined(__SYMBIAN32__)
/* Symbian: need to work around the SDK features. *
* On WINS: MS VC5 generates calls to _chkstk, *
* if a "large" stack frame is allocated. *
* gcc on MARM does not generate calls like these. */
# define USE_HEAP_INSTEAD_OF_STACK
/* Use the reentrant APIs like localtime_r and getpwent_r */
/* Win32 has naturally threadsafe libraries, no need to use any _r variants. */
#if defined(USE_ITHREADS) && !defined(USE_REENTRANT_API) && !defined(NETWARE) && !defined(WIN32) && !defined(PERL_DARWIN)
# define USE_REENTRANT_API
/* <--- here ends the logic shared by perl.h and makedef.pl */
/* Microsoft Visual C++ 6.0 needs special treatment in numerous places */
#if defined(WIN32) && defined(_MSC_VER) && _MSC_VER >= 1200 && _MSC_VER < 1300
# define START_EXTERN_C extern "C" {
# define EXTERN_C extern "C"
/* Fallback definitions in case we don't have definitions from config.h.
This should only matter for systems that don't use Configure and
haven't been modified to define PERL_STATIC_INLINE yet.
#if !defined(PERL_STATIC_INLINE)
# ifdef HAS_STATIC_INLINE
# define PERL_STATIC_INLINE static inline
# define PERL_STATIC_INLINE static
#ifdef PERL_GLOBAL_STRUCT
# ifdef PERL_GLOBAL_STRUCT_PRIVATE
EXTERN_C struct perl_vars* Perl_GetVarsPrivate();
# define PERL_GET_VARS() Perl_GetVarsPrivate() /* see miniperlmain.c */
# define PERL_GET_VARS() PL_VarsPtr
/* this used to be off by default, now its on, see perlio.h */
#define PERLIO_FUNCS_CONST
#define pVAR struct perl_vars* my_vars PERL_UNUSED_DECL
#ifdef PERL_GLOBAL_STRUCT
# define dVAR pVAR = (struct perl_vars*)PERL_GET_VARS()
#ifdef PERL_IMPLICIT_CONTEXT
# define tTHX PerlInterpreter*
# define pTHX tTHX my_perl PERL_UNUSED_DECL
# define aTHXa(a) aTHX = (tTHX)a
# ifdef PERL_GLOBAL_STRUCT
# define dTHXa(a) dVAR; pTHX = (tTHX)a
# define dTHXa(a) pTHX = (tTHX)a
# ifdef PERL_GLOBAL_STRUCT
# define dTHX dVAR; pTHX = PERL_GET_THX
# define dTHX pTHX = PERL_GET_THX
# if defined(DEBUGGING) && !defined(PERL_TRACK_MEMPOOL)
# define PERL_TRACK_MEMPOOL
# undef PERL_TRACK_MEMPOOL
/* Do not use these macros. They were part of PERL_OBJECT, which was an
* implementation of multiplicity using C++ objects. They have been left
* here solely for the sake of XS code which has incorrectly
#define _PERL_OBJECT_THIS
#define PERL_OBJECT_THIS_
#define CALL_FPTR(fptr) (*fptr)
#define MEMBER_TO_FPTR(name) name
#define CALLRUNOPS PL_runops
#define CALLREGCOMP(sv, flags) Perl_pregcomp(aTHX_ (sv),(flags))
#define CALLREGCOMP_ENG(prog, sv, flags) (prog)->comp(aTHX_ sv, flags)
#define CALLREGEXEC(prog,stringarg,strend,strbeg,minend,sv,data,flags) \
RX_ENGINE(prog)->exec(aTHX_ (prog),(stringarg),(strend), \
(strbeg),(minend),(sv),(data),(flags))
#define CALLREG_INTUIT_START(prog,sv,strbeg,strpos,strend,flags,data) \
RX_ENGINE(prog)->intuit(aTHX_ (prog), (sv), (strbeg), (strpos), \
#define CALLREG_INTUIT_STRING(prog) \
RX_ENGINE(prog)->checkstr(aTHX_ (prog))
#define CALLREGFREE(prog) \
Perl_pregfree(aTHX_ (prog))
#define CALLREGFREE_PVT(prog) \
if(prog) RX_ENGINE(prog)->rxfree(aTHX_ (prog))
#define CALLREG_NUMBUF_FETCH(rx,paren,usesv) \
RX_ENGINE(rx)->numbered_buff_FETCH(aTHX_ (rx),(paren),(usesv))
#define CALLREG_NUMBUF_STORE(rx,paren,value) \
RX_ENGINE(rx)->numbered_buff_STORE(aTHX_ (rx),(paren),(value))
#define CALLREG_NUMBUF_LENGTH(rx,sv,paren) \
RX_ENGINE(rx)->numbered_buff_LENGTH(aTHX_ (rx),(sv),(paren))
#define CALLREG_NAMED_BUFF_FETCH(rx, key, flags) \
RX_ENGINE(rx)->named_buff(aTHX_ (rx), (key), NULL, ((flags) | RXapif_FETCH))
#define CALLREG_NAMED_BUFF_STORE(rx, key, value, flags) \
RX_ENGINE(rx)->named_buff(aTHX_ (rx), (key), (value), ((flags) | RXapif_STORE))
#define CALLREG_NAMED_BUFF_DELETE(rx, key, flags) \
RX_ENGINE(rx)->named_buff(aTHX_ (rx),(key), NULL, ((flags) | RXapif_DELETE))
#define CALLREG_NAMED_BUFF_CLEAR(rx, flags) \
RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, ((flags) | RXapif_CLEAR))
#define CALLREG_NAMED_BUFF_EXISTS(rx, key, flags) \
RX_ENGINE(rx)->named_buff(aTHX_ (rx), (key), NULL, ((flags) | RXapif_EXISTS))
#define CALLREG_NAMED_BUFF_FIRSTKEY(rx, flags) \
RX_ENGINE(rx)->named_buff_iter(aTHX_ (rx), NULL, ((flags) | RXapif_FIRSTKEY))
#define CALLREG_NAMED_BUFF_NEXTKEY(rx, lastkey, flags) \
RX_ENGINE(rx)->named_buff_iter(aTHX_ (rx), (lastkey), ((flags) | RXapif_NEXTKEY))
#define CALLREG_NAMED_BUFF_SCALAR(rx, flags) \
RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, ((flags) | RXapif_SCALAR))
#define CALLREG_NAMED_BUFF_COUNT(rx) \
RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, RXapif_REGNAMES_COUNT)
#define CALLREG_NAMED_BUFF_ALL(rx, flags) \
RX_ENGINE(rx)->named_buff(aTHX_ (rx), NULL, NULL, flags)
#define CALLREG_PACKAGE(rx) \
RX_ENGINE(rx)->qr_package(aTHX_ (rx))
#if defined(USE_ITHREADS)
#define CALLREGDUPE(prog,param) \
Perl_re_dup(aTHX_ (prog),(param))
#define CALLREGDUPE_PVT(prog,param) \
(prog ? RX_ENGINE(prog)->dupe(aTHX_ (prog),(param)) \
* Because of backward compatibility reasons the PERL_UNUSED_DECL
* cannot be changed from postfix to PERL_UNUSED_DECL(x). Sigh.
* Note that there are C compilers such as MetroWerks CodeWarrior
* which do not have an "inlined" way (like the gcc __attribute__) of
* marking unused variables (they need e.g. a #pragma) and therefore
* cpp macros like PERL_UNUSED_DECL cannot work for this purpose, even
* if it were PERL_UNUSED_DECL(x), which it cannot be (see above).
#if defined(__SYMBIAN32__) && defined(__GNUC__)
# define PERL_UNUSED_DECL
# define PERL_UNUSED_DECL __attribute__((unused))
# if defined(HASATTRIBUTE_UNUSED) && (!defined(__cplusplus) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
# define PERL_UNUSED_DECL __attribute__unused__
# define PERL_UNUSED_DECL
* for silencing unused variables that are actually used most of the time,
* but we cannot quite get rid of, such as "ax" in PPCODE+noargs xsubs,
* or variables/arguments that are used only in certain configurations.
# define PERL_UNUSED_ARG(x) ((void)sizeof(x))
# define PERL_UNUSED_VAR(x) ((void)sizeof(x))
#if defined(USE_ITHREADS) || defined(PERL_GLOBAL_STRUCT)
# define PERL_UNUSED_CONTEXT PERL_UNUSED_ARG(my_perl)
# define PERL_UNUSED_CONTEXT
/* gcc (-ansi) -pedantic doesn't allow gcc statement expressions,
* g++ allows them but seems to have problems with them
* g++ does not give insane errors now (RMB 2008-01-30, gcc 4.2.2).
#if defined(PERL_GCC_PEDANTIC) || \
(defined(__GNUC__) && defined(__cplusplus) && \
((__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 2))))
# ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN
# define PERL_GCC_BRACE_GROUPS_FORBIDDEN
/* Use PERL_UNUSED_RESULT() to suppress the warnings about unused results
* of function calls, e.g. PERL_UNUSED_RESULT(foo(a, b)).
* The main reason for this is that the combination of gcc -Wunused-result
* (part of -Wall) and the __attribute__((warn_unused_result)) cannot
* be silenced with casting to void. This causes trouble when the system
* header files use the attribute.
* Use PERL_UNUSED_RESULT sparingly, though, since usually the warning
* is there for a good reason: you might lose success/failure information,
* or leak resources, or changes in resources.
* But sometimes you just want to ignore the return value, e.g. on
* codepaths soon ending up in abort, or in "best effort" attempts,
* or in situations where there is no good way to handle failures.
* Sometimes PERL_UNUSED_RESULT might not be the most natural way:
* another possibility is that you can capture the return value
* and use PERL_UNUSED_VAR on that.
* The __typeof__() is used instead of typeof() since typeof() is not
* available under strict C89, and because of compilers masquerading
* as gcc (clang and icc), we want exactly the gcc extension
* __typeof__ and nothing else.
#ifndef PERL_UNUSED_RESULT
# if defined(__GNUC__) && defined(HASATTRIBUTE_WARN_UNUSED_RESULT)
# define PERL_UNUSED_RESULT(v) STMT_START { __typeof__(v) z = (v); (void)sizeof(z); } STMT_END
# define PERL_UNUSED_RESULT(v) ((void)(v))
/* on gcc (and clang), specify that a warning should be temporarily
* GCC_DIAG_IGNORE(-Wmultichar);
* based on http://dbp-consulting.com/tutorials/SuppressingGCCWarnings.html
* Note that "pragma GCC diagnostic push/pop" was added in GCC 4.6, Mar 2011;
* clang only pretends to be GCC 4.2, but still supports push/pop.
* Note on usage: on non-gcc (or lookalike, like clang) compilers
* one cannot use these at file (global) level without warnings
* since they are defined as empty, which leads into the terminating
* semicolon being left alone on a line:
* which makes compilers mildly cranky. Therefore at file level one
* should use the GCC_DIAG_IGNORE and GCC_DIAG_RESTORE_FILE *without*
* (A dead-on-arrival solution would be to try to define the macros as
* NOOP or dNOOP, those don't work both inside functions and outside.)
#if defined(__clang__) || defined(__clang) || \
(defined( __GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406)
# define GCC_DIAG_PRAGMA(x) _Pragma (#x)
/* clang has "clang diagnostic" pragmas, but also understands gcc. */
# define GCC_DIAG_IGNORE(x) _Pragma("GCC diagnostic push") \
GCC_DIAG_PRAGMA(GCC diagnostic ignored #x)
# define GCC_DIAG_RESTORE _Pragma("GCC diagnostic pop")
# define GCC_DIAG_IGNORE(w)
# define GCC_DIAG_RESTORE
/* for clang specific pragmas */
#if defined(__clang__) || defined(__clang)
# define CLANG_DIAG_PRAGMA(x) _Pragma (#x)
# define CLANG_DIAG_IGNORE(x) _Pragma("clang diagnostic push") \
CLANG_DIAG_PRAGMA(clang diagnostic ignored #x)
# define CLANG_DIAG_RESTORE _Pragma("clang diagnostic pop")
# define CLANG_DIAG_IGNORE(w)
# define CLANG_DIAG_RESTORE
#define NOOP /*EMPTY*/(void)0
/* cea2e8a9dd23747f accidentally lost the comment originally from the first
check in of thread.h, explaining why we need dNOOP at all: */
/* Rats: if dTHR is just blank then the subsequent ";" throws an error */
/* Declaring a *function*, instead of a variable, ensures that we don't rely
on being able to suppress "unused" warnings. */
#define dNOOP extern int Perl___notused(void)
/* Don't bother defining tTHX ; using it outside
* code guarded by PERL_IMPLICIT_CONTEXT is an error.
/* these are only defined for compatibility; should not be used internally */
#if !defined(pTHXo) && !defined(PERL_CORE)
# define dTHXoa(x) dTHXa(x)
# define pTHXx PerlInterpreter *my_perl
/* Under PERL_IMPLICIT_SYS (used in Windows for fork emulation)
* PerlIO_foo() expands to PL_StdIO->pFOO(PL_StdIO, ...).
* dTHXs is therefore needed for all functions using PerlIO_foo(). */