| PERLAPI(1) | Perl Programmers Reference Guide | PERLAPI(1) |
In Perl, unlike C, a string of characters may generally contain embedded "NUL" characters. Sometimes in the documentation a Perl string is referred to as a "buffer" to distinguish it from a C string, but sometimes they are both just referred to as strings.
Note that all Perl API global variables must be referenced with the "PL_" prefix. Again, those not listed here are not to be used by extension writers, and can be changed or removed without notice; same with macros. Some macros are provided for compatibility with the older, unadorned names, but this support may be disabled in a future release.
Perl was originally written to handle US-ASCII only (that is characters whose ordinal numbers are in the range 0 - 127). And documentation and comments may still use the term ASCII, when sometimes in fact the entire range from 0 - 255 is meant.
The non-ASCII characters below 256 can have various meanings, depending on various things. (See, most notably, perllocale.) But usually the whole range can be referred to as ISO-8859-1. Often, the term "Latin-1" (or "Latin1") is used as an equivalent for ISO-8859-1. But some people treat "Latin1" as referring just to the characters in the range 128 through 255, or somethimes from 160 through 255. This documentation uses "Latin1" and "Latin-1" to refer to all 256 characters.
Note that Perl can be compiled and run under either ASCII or EBCDIC (See perlebcdic). Most of the documentation (and even comments in the code) ignore the EBCDIC possibility. For almost all purposes the differences are transparent. As an example, under EBCDIC, instead of UTF-8, UTF-EBCDIC is used to encode Unicode strings, and so whenever this documentation refers to "utf8" (and variants of that name, including in function names), it also (essentially transparently) means "UTF-EBCDIC". But the ordinals of characters differ between ASCII, EBCDIC, and the UTF- encodings, and a string encoded in UTF-EBCDIC may occupy a different number of bytes than in UTF-8.
The listing below is alphabetical, case insensitive.
Note that it is possible that the actions of a destructor called directly or indirectly by freeing an element of the array could cause the reference count of the array itself to be reduced (e.g. by deleting an entry in the symbol table). So it is a possibility that the AV could have been freed (or even reallocated) on return from the call unless you hold a reference to it.
void av_clear(AV *av)
Push an SV onto the end of the array, creating the array if necessary. A small internal helper function to remove a commonly duplicated idiom.
void av_create_and_push(AV **const avp, SV *const val)
Unshifts an SV onto the beginning of the array, creating the array if necessary. A small internal helper function to remove a commonly duplicated idiom.
SV** av_create_and_unshift_one(AV **const avp, SV *const val)
Perl equivalent: "splice(@myarray, $key, 1, undef)" (with the "splice" in void context if "G_DISCARD" is present).
SV* av_delete(AV *av, SSize_t key, I32 flags)
This relies on the fact that uninitialized array elements are set to "NULL".
Perl equivalent: "exists($myarray[$key])".
bool av_exists(AV *av, SSize_t key)
void av_extend(AV *av, SSize_t key)
See "Understanding the Magic of Tied Hashes and Arrays" in perlguts for more information on how to use this function on tied arrays.
The rough perl equivalent is $myarray[$key].
SV** av_fetch(AV *av, SSize_t key, I32 lval)
int AvFILL(AV* av)
The number of elements in the array will be "fill + 1" after "av_fill()" returns. If the array was previously shorter, then the additional elements appended are set to NULL. If the array was longer, then the excess elements are freed. "av_fill(av, -1)" is the same as "av_clear(av)".
void av_fill(AV *av, SSize_t fill)
SSize_t av_len(AV *av)
Perl equivalent: "my @new_array = ($scalar1, $scalar2, $scalar3...);"
AV* av_make(SSize_t size, SV **strp)
Perl equivalent: "pop(@myarray);"
SV* av_pop(AV *av)
Perl equivalent: "push @myarray, $val;".
void av_push(AV *av, SV *val)
Perl equivalent: "shift(@myarray);"
SV* av_shift(AV *av)
Note that the caller is responsible for suitably incrementing the reference count of "val" before the call, and decrementing it if the function returned "NULL".
Approximate Perl equivalent: "splice(@myarray, $key, 1, $val)".
See "Understanding the Magic of Tied Hashes and Arrays" in perlguts for more information on how to use this function on tied arrays.
SV** av_store(AV *av, SSize_t key, SV *val)
int av_tindex(AV* av)
The Perl equivalent for this is $#myarray.
(A slightly shorter form is "av_tindex".)
SSize_t av_top_index(AV *av)
As well as freeing all the elements of the array (like "av_clear()"), this also frees the memory used by the av to store its list of scalars.
See "av_clear" for a note about the array possibly being invalid on return.
void av_undef(AV *av)
Perl equivalent: "unshift @myarray, ((undef) x $num);"
void av_unshift(AV *av, SSize_t num)
Perl equivalent: "@{"$name"}".
NOTE: the perl_ form of this function is deprecated.
AV* get_av(const char *name, I32 flags)
Perl equivalent: "my @array;".
AV* newAV()
Currently this always uses mergesort. See "sortsv_flags" for a more flexible routine.
void sortsv(SV** array, size_t num_elts, SVCOMPARE_t cmp)
Approximate Perl equivalent: "&{"$sub_name"}(@$argv)".
NOTE: the perl_ form of this function is deprecated.
I32 call_argv(const char* sub_name, I32 flags, char** argv)
NOTE: the perl_ form of this function is deprecated.
I32 call_method(const char* methname, I32 flags)
NOTE: the perl_ form of this function is deprecated.
I32 call_pv(const char* sub_name, I32 flags)
If neither the "G_METHOD" nor "G_METHOD_NAMED" flag is supplied, the SV may be any of a CV, a GV, a reference to a CV, a reference to a GV or "SvPV(sv)" will be used as the name of the sub to call.
If the "G_METHOD" flag is supplied, the SV may be a reference to a CV or "SvPV(sv)" will be used as the name of the method to call.
If the "G_METHOD_NAMED" flag is supplied, "SvPV(sv)" will be used as the name of the method to call.
Some other values are treated specially for internal use and should not be depended on.
See perlcall.
NOTE: the perl_ form of this function is deprecated.
I32 call_sv(SV* sv, volatile I32 flags)
ENTER;
ENTER_with_name(name);
NOTE: the perl_ form of this function is deprecated.
SV* eval_pv(const char* p, I32 croak_on_error)
NOTE: the perl_ form of this function is deprecated.
I32 eval_sv(SV* sv, I32 flags)
FREETMPS;
LEAVE;
LEAVE_with_name(name);
SAVETMPS;
U8 toFOLD(U8 ch)
UV toFOLD_utf8(U8* p, U8* s, STRLEN* lenp)
The first code point of the foldcased version is returned (but note, as explained at the top of this section, that there may be more).
The suffix "_safe" in the function's name indicates that it will not attempt to read beyond "e - 1", provided that the constraint "s < e" is true (this is asserted for in "-DDEBUGGING" builds). If the UTF-8 for the input character is malformed in some way, the program may croak, or the function may return the REPLACEMENT CHARACTER, at the discretion of the implementation, and subject to change in future releases.
UV toFOLD_utf8_safe(U8* p, U8* e, U8* s, STRLEN* lenp)
The first code point of the foldcased version is returned (but note, as explained at the top of this section, that there may be more).
UV toFOLD_uvchr(UV cp, U8* s, STRLEN* lenp)
U8 toLOWER(U8 ch)
U8 toLOWER_L1(U8 ch)
U8 toLOWER_LC(U8 ch)
UV toLOWER_utf8(U8* p, U8* s, STRLEN* lenp)
The first code point of the lowercased version is returned (but note, as explained at the top of this section, that there may be more).
The suffix "_safe" in the function's name indicates that it will not attempt to read beyond "e - 1", provided that the constraint "s < e" is true (this is asserted for in "-DDEBUGGING" builds). If the UTF-8 for the input character is malformed in some way, the program may croak, or the function may return the REPLACEMENT CHARACTER, at the discretion of the implementation, and subject to change in future releases.
UV toLOWER_utf8_safe(U8* p, U8* e, U8* s, STRLEN* lenp)
The first code point of the lowercased version is returned (but note, as explained at the top of this section, that there may be more).
UV toLOWER_uvchr(UV cp, U8* s, STRLEN* lenp)
U8 toTITLE(U8 ch)
UV toTITLE_utf8(U8* p, U8* s, STRLEN* lenp)
The first code point of the titlecased version is returned (but note, as explained at the top of this section, that there may be more).
The suffix "_safe" in the function's name indicates that it will not attempt to read beyond "e - 1", provided that the constraint "s < e" is true (this is asserted for in "-DDEBUGGING" builds). If the UTF-8 for the input character is malformed in some way, the program may croak, or the function may return the REPLACEMENT CHARACTER, at the discretion of the implementation, and subject to change in future releases.
UV toTITLE_utf8_safe(U8* p, U8* e, U8* s, STRLEN* lenp)
The first code point of the titlecased version is returned (but note, as explained at the top of this section, that there may be more).
UV toTITLE_uvchr(UV cp, U8* s, STRLEN* lenp)
U8 toUPPER(U8 ch)
UV toUPPER_utf8(U8* p, U8* s, STRLEN* lenp)
The first code point of the uppercased version is returned (but note, as explained at the top of this section, that there may be more).
The suffix "_safe" in the function's name indicates that it will not attempt to read beyond "e - 1", provided that the constraint "s < e" is true (this is asserted for in "-DDEBUGGING" builds). If the UTF-8 for the input character is malformed in some way, the program may croak, or the function may return the REPLACEMENT CHARACTER, at the discretion of the implementation, and subject to change in future releases.
UV toUPPER_utf8_safe(U8* p, U8* e, U8* s, STRLEN* lenp)
The first code point of the uppercased version is returned (but note, as explained at the top of this section, that there may be more.)
UV toUPPER_uvchr(UV cp, U8* s, STRLEN* lenp)
The base function, e.g., "isALPHA()", takes an octet (either a "char" or a "U8") as input and returns a boolean as to whether or not the character represented by that octet is (or on non-ASCII platforms, corresponds to) an ASCII character in the named class based on platform, Unicode, and Perl rules. If the input is a number that doesn't fit in an octet, FALSE is returned.
Variant "isFOO_A" (e.g., "isALPHA_A()") is identical to the base function with no suffix "_A". This variant is used to emphasize by its name that only ASCII-range characters can return TRUE.
Variant "isFOO_L1" imposes the Latin-1 (or EBCDIC equivalent) character set onto the platform. That is, the code points that are ASCII are unaffected, since ASCII is a subset of Latin-1. But the non-ASCII code points are treated as if they are Latin-1 characters. For example, "isWORDCHAR_L1()" will return true when called with the code point 0xDF, which is a word character in both ASCII and EBCDIC (though it represents different characters in each).
Variant "isFOO_uvchr" is like the "isFOO_L1" variant, but accepts any UV code point as input. If the code point is larger than 255, Unicode rules are used to determine if it is in the character class. For example, "isWORDCHAR_uvchr(0x100)" returns TRUE, since 0x100 is LATIN CAPITAL LETTER A WITH MACRON in Unicode, and is a word character.
Variant "isFOO_utf8_safe" is like "isFOO_uvchr", but is used for UTF-8 encoded strings. Each call classifies one character, even if the string contains many. This variant takes two parameters. The first, "p", is a pointer to the first byte of the character to be classified. (Recall that it may take more than one byte to represent a character in UTF-8 strings.) The second parameter, "e", points to anywhere in the string beyond the first character, up to one byte past the end of the entire string. The suffix "_safe" in the function's name indicates that it will not attempt to read beyond "e - 1", provided that the constraint "s < e" is true (this is asserted for in "-DDEBUGGING" builds). If the UTF-8 for the input character is malformed in some way, the program may croak, or the function may return FALSE, at the discretion of the implementation, and subject to change in future releases.
Variant "isFOO_utf8" is like "isFOO_utf8_safe", but takes just a single parameter, "p", which has the same meaning as the corresponding parameter does in "isFOO_utf8_safe". The function therefore can't check if it is reading beyond the end of the string. Starting in Perl v5.30, it will take a second parameter, becoming a synonym for "isFOO_utf8_safe". At that time every program that uses it will have to be changed to successfully compile. In the meantime, the first runtime call to "isFOO_utf8" from each call point in the program will raise a deprecation warning, enabled by default. You can convert your program now to use "isFOO_utf8_safe", and avoid the warnings, and get an extra measure of protection, or you can wait until v5.30, when you'll be forced to add the "e" parameter.
Variant "isFOO_LC" is like the "isFOO_A" and "isFOO_L1" variants, but the result is based on the current locale, which is what "LC" in the name stands for. If Perl can determine that the current locale is a UTF-8 locale, it uses the published Unicode rules; otherwise, it uses the C library function that gives the named classification. For example, "isDIGIT_LC()" when not in a UTF-8 locale returns the result of calling "isdigit()". FALSE is always returned if the input won't fit into an octet. On some platforms where the C library function is known to be defective, Perl changes its result to follow the POSIX standard's rules.
Variant "isFOO_LC_uvchr" is like "isFOO_LC", but is defined on any UV. It returns the same as "is FOO_LC" for input code points less than 256, and returns the hard-coded, not-affected-by-locale, Unicode results for larger ones.
Variant "isFOO_LC_utf8_safe" is like "isFOO_LC_uvchr", but is used for UTF-8 encoded strings. Each call classifies one character, even if the string contains many. This variant takes two parameters. The first, "p", is a pointer to the first byte of the character to be classified. (Recall that it may take more than one byte to represent a character in UTF-8 strings.) The second parameter, "e", points to anywhere in the string beyond the first character, up to one byte past the end of the entire string. The suffix "_safe" in the function's name indicates that it will not attempt to read beyond "e - 1", provided that the constraint "s < e" is true (this is asserted for in "-DDEBUGGING" builds). If the UTF-8 for the input character is malformed in some way, the program may croak, or the function may return FALSE, at the discretion of the implementation, and subject to change in future releases.
Variant "isFOO_LC_utf8" is like "isFOO_LC_utf8_safe", but takes just a single parameter, "p", which has the same meaning as the corresponding parameter does in "isFOO_LC_utf8_safe". The function therefore can't check if it is reading beyond the end of the string. Starting in Perl v5.30, it will take a second parameter, becoming a synonym for "isFOO_LC_utf8_safe". At that time every program that uses it will have to be changed to successfully compile. In the meantime, the first runtime call to "isFOO_LC_utf8" from each call point in the program will raise a deprecation warning, enabled by default. You can convert your program now to use "isFOO_LC_utf8_safe", and avoid the warnings, and get an extra measure of protection, or you can wait until v5.30, when you'll be forced to add the "e" parameter.
bool isALPHA(char ch)
bool isALPHANUMERIC(char ch)
Also note, that because all ASCII characters are UTF-8 invariant (meaning they have the exact same representation (always a single byte) whether encoded in UTF-8 or not), "isASCII" will give the correct results when called with any byte in any string encoded or not in UTF-8. And similarly "isASCII_utf8_safe" will work properly on any string encoded or not in UTF-8.
bool isASCII(char ch)
bool isBLANK(char ch)
bool isCNTRL(char ch)
bool isDIGIT(char ch)
bool isGRAPH(char ch)
bool isIDCONT(char ch)
bool isIDFIRST(char ch)
bool isLOWER(char ch)
bool isOCTAL(char ch)
bool isPRINT(char ch)
bool isPSXSPC(char ch)
bool isPUNCT(char ch)
bool isSPACE(char ch)
bool isUPPER(char ch)
bool isWORDCHAR(char ch)
bool isXDIGIT(char ch)
"perl_clone" takes these flags as parameters:
"CLONEf_COPY_STACKS" - is used to, well, copy the stacks also, without it we only clone the data and zero the stacks, with it we copy the stacks and the new perl interpreter is ready to run at the exact same point as the previous one. The pseudo-fork code uses "COPY_STACKS" while the threads->create doesn't.
"CLONEf_KEEP_PTR_TABLE" - "perl_clone" keeps a ptr_table with the pointer of the old variable as a key and the new variable as a value, this allows it to check if something has been cloned and not clone it again but rather just use the value and increase the refcount. If "KEEP_PTR_TABLE" is not set then "perl_clone" will kill the ptr_table using the function "ptr_table_free(PL_ptr_table); PL_ptr_table = NULL;", reason to keep it around is if you want to dup some of your own variable who are outside the graph perl scans, an example of this code is in threads.xs create.
"CLONEf_CLONE_HOST" - This is a win32 thing, it is ignored on unix, it tells perls win32host code (which is c++) to clone itself, this is needed on win32 if you want to run two threads at the same time, if you just want to do some stuff in a separate perl interpreter and then throw it away and return to the original one, you don't need to do anything.
PerlInterpreter* perl_clone( PerlInterpreter *proto_perl, UV flags )
Temporarily disable an entry in this BHK structure, by clearing the appropriate flag. "which" is a preprocessor token indicating which entry to disable.
void BhkDISABLE(BHK *hk, which)
Re-enable an entry in this BHK structure, by setting the appropriate flag. "which" is a preprocessor token indicating which entry to enable. This will assert (under -DDEBUGGING) if the entry doesn't contain a valid pointer.
void BhkENABLE(BHK *hk, which)
Set an entry in the BHK structure, and set the flags to indicate it is valid. "which" is a preprocessing token indicating which entry to set. The type of "ptr" depends on the entry.
void BhkENTRY_set(BHK *hk, which, void *ptr)
Register a set of hooks to be called when the Perl lexical scope changes at compile time. See "Compile-time scope hooks" in perlguts.
NOTE: this function must be explicitly called as Perl_blockhook_register with an aTHX_ parameter.
void Perl_blockhook_register(pTHX_ BHK *hk)
Generates and returns a standard Perl hash representing the full set of key/value pairs in the cop hints hash "cophh". "flags" is currently unused and must be zero.
HV * cophh_2hv(const COPHH *cophh, U32 flags)
Make and return a complete copy of the cop hints hash "cophh".
COPHH * cophh_copy(COPHH *cophh)
Like "cophh_delete_pvn", but takes a nul-terminated string instead of a string/length pair.
COPHH * cophh_delete_pv(const COPHH *cophh, const char *key, U32 hash, U32 flags)
Delete a key and its associated value from the cop hints hash "cophh", and returns the modified hash. The returned hash pointer is in general not the same as the hash pointer that was passed in. The input hash is consumed by the function, and the pointer to it must not be subsequently used. Use "cophh_copy" if you need both hashes.
The key is specified by "keypv" and "keylen". If "flags" has the "COPHH_KEY_UTF8" bit set, the key octets are interpreted as UTF-8, otherwise they are interpreted as Latin-1. "hash" is a precomputed hash of the key string, or zero if it has not been precomputed.
COPHH * cophh_delete_pvn(COPHH *cophh, const char *keypv, STRLEN keylen, U32 hash, U32 flags)
Like "cophh_delete_pvn", but takes a literal string instead of a string/length pair, and no precomputed hash.
COPHH * cophh_delete_pvs(const COPHH *cophh, "literal string" key, U32 flags)
Like "cophh_delete_pvn", but takes a Perl scalar instead of a string/length pair.
COPHH * cophh_delete_sv(const COPHH *cophh, SV *key, U32 hash, U32 flags)
Like "cophh_fetch_pvn", but takes a nul-terminated string instead of a string/length pair.
SV * cophh_fetch_pv(const COPHH *cophh, const char *key, U32 hash, U32 flags)
Look up the entry in the cop hints hash "cophh" with the key specified by "keypv" and "keylen". If "flags" has the "COPHH_KEY_UTF8" bit set, the key octets are interpreted as UTF-8, otherwise they are interpreted as Latin-1. "hash" is a precomputed hash of the key string, or zero if it has not been precomputed. Returns a mortal scalar copy of the value associated with the key, or &PL_sv_placeholder if there is no value associated with the key.
SV * cophh_fetch_pvn(const COPHH *cophh, const char *keypv, STRLEN keylen, U32 hash, U32 flags)
Like "cophh_fetch_pvn", but takes a literal string instead of a string/length pair, and no precomputed hash.
SV * cophh_fetch_pvs(const COPHH *cophh, "literal string" key, U32 flags)
Like "cophh_fetch_pvn", but takes a Perl scalar instead of a string/length pair.
SV * cophh_fetch_sv(const COPHH *cophh, SV *key, U32 hash, U32 flags)
Discard the cop hints hash "cophh", freeing all resources associated with it.
void cophh_free(COPHH *cophh)
Generate and return a fresh cop hints hash containing no entries.
COPHH * cophh_new_empty()
Like "cophh_store_pvn", but takes a nul-terminated string instead of a string/length pair.
COPHH * cophh_store_pv(const COPHH *cophh, const char *key, U32 hash, SV *value, U32 flags)
Stores a value, associated with a key, in the cop hints hash "cophh", and returns the modified hash. The returned hash pointer is in general not the same as the hash pointer that was passed in. The input hash is consumed by the function, and the pointer to it must not be subsequently used. Use "cophh_copy" if you need both hashes.
The key is specified by "keypv" and "keylen". If "flags" has the "COPHH_KEY_UTF8" bit set, the key octets are interpreted as UTF-8, otherwise they are interpreted as Latin-1. "hash" is a precomputed hash of the key string, or zero if it has not been precomputed.
"value" is the scalar value to store for this key. "value" is copied by this function, which thus does not take ownership of any reference to it, and later changes to the scalar will not be reflected in the value visible in the cop hints hash. Complex types of scalar will not be stored with referential integrity, but will be coerced to strings.
COPHH * cophh_store_pvn(COPHH *cophh, const char *keypv, STRLEN keylen, U32 hash, SV *value, U32 flags)
Like "cophh_store_pvn", but takes a literal string instead of a string/length pair, and no precomputed hash.
COPHH * cophh_store_pvs(const COPHH *cophh, "literal string" key, SV *value, U32 flags)
Like "cophh_store_pvn", but takes a Perl scalar instead of a string/length pair.
COPHH * cophh_store_sv(const COPHH *cophh, SV *key, U32 hash, SV *value, U32 flags)
HV * cop_hints_2hv(const COP *cop, U32 flags)
SV * cop_hints_fetch_pv(const COP *cop, const char *key, U32 hash, U32 flags)
SV * cop_hints_fetch_pvn(const COP *cop, const char *keypv, STRLEN keylen, U32 hash, U32 flags)
SV * cop_hints_fetch_pvs(const COP *cop, "literal string" key, U32 flags)
SV * cop_hints_fetch_sv(const COP *cop, SV *key, U32 hash, U32 flags)
NOTE: this function must be explicitly called as Perl_custom_op_register with an aTHX_ parameter.
void Perl_custom_op_register(pTHX_ Perl_ppaddr_t ppaddr, const XOP *xop)
NOTE: this function must be explicitly called as Perl_custom_op_xop with an aTHX_ parameter.
const XOP * Perl_custom_op_xop(pTHX_ const OP *o)
void XopDISABLE(XOP *xop, which)
void XopENABLE(XOP *xop, which)
XopENTRY(XOP *xop, which)
XopENTRYCUSTOM(const OP *o, which)
void XopENTRY_set(XOP *xop, which, value)
U32 XopFLAGS(XOP *xop)
This function skips over the automatic calls to &DB::sub made on the behalf of the debugger. If the stack frame requested was a sub called by "DB::sub", the return value will be the frame for the call to "DB::sub", since that has the correct line number/etc. for the call site. If dbcxp is non-"NULL", it will be set to a pointer to the frame for the sub call itself.
const PERL_CONTEXT * caller_cx( I32 level, const PERL_CONTEXT **dbcxp )
This also has a special use with XS AUTOLOAD subs. See "Autoloading with XSUBs" in perlguts.
HV* CvSTASH(CV* cv)
CV* find_runcv(U32 *db_seqp)
NOTE: the perl_ form of this function is deprecated.
CV* get_cv(const char* name, I32 flags)
NOTE: the perl_ form of this function is deprecated.
CV* get_cvn_flags(const char* name, STRLEN len, I32 flags)
I32 ax
char* CLASS
dAX;
dAXMARK;
dITEMS;
dUNDERBAR;
dXSARGS;
dXSI32;
I32 items
I32 ix
(whatever) RETVAL
SV* ST(int ix)
(whatever) THIS
void dump_all()
void dump_packsubs(const HV* stash)
OPclass op_class(const OP *o)
void op_dump(const OP *o)
For an example of its output, see Devel::Peek.
void sv_dump(SV* sv)
pv_escape(dsv,pv,cur,pvlim,PERL_PV_ESCAPE_QUOTE);
except that an additional "\0" will be appended to the string when len > cur and pv[cur] is "\0".
Note that the final string may be up to 7 chars longer than pvlim.
char* pv_display(SV *dsv, const char *pv, STRLEN cur, STRLEN len, STRLEN pvlim)
If flags contains "PERL_PV_ESCAPE_QUOTE" then any double quotes in the string will also be escaped.
Normally the SV will be cleared before the escaped string is prepared, but when "PERL_PV_ESCAPE_NOCLEAR" is set this will not occur.
If "PERL_PV_ESCAPE_UNI" is set then the input string is treated as UTF-8 if "PERL_PV_ESCAPE_UNI_DETECT" is set then the input string is scanned using "is_utf8_string()" to determine if it is UTF-8.
If "PERL_PV_ESCAPE_ALL" is set then all input chars will be output using "\x01F1" style escapes, otherwise if "PERL_PV_ESCAPE_NONASCII" is set, only non-ASCII chars will be escaped using this style; otherwise, only chars above 255 will be so escaped; other non printable chars will use octal or common escaped patterns like "\n". Otherwise, if "PERL_PV_ESCAPE_NOBACKSLASH" then all chars below 255 will be treated as printable and will be output as literals.
If "PERL_PV_ESCAPE_FIRSTCHAR" is set then only the first char of the string will be escaped, regardless of max. If the output is to be in hex, then it will be returned as a plain hex sequence. Thus the output will either be a single char, an octal escape sequence, a special escape like "\n" or a hex value.
If "PERL_PV_ESCAPE_RE" is set then the escape char used will be a "%" and not a "\\". This is because regexes very often contain backslashed sequences, whereas "%" is not a particularly common character in patterns.
Returns a pointer to the escaped text as held by "dsv".
char* pv_escape(SV *dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags)
If the "PERL_PV_PRETTY_QUOTE" flag is set then the result will be double quoted with any double quotes in the string escaped. Otherwise if the "PERL_PV_PRETTY_LTGT" flag is set then the result be wrapped in angle brackets.
If the "PERL_PV_PRETTY_ELLIPSES" flag is set and not all characters in string were output then an ellipsis "..." will be appended to the string. Note that this happens AFTER it has been quoted.
If "start_color" is non-null then it will be inserted after the opening quote (if there is one) but before the escaped text. If "end_color" is non-null then it will be inserted after the escaped text but before any quotes or ellipses.
Returns a pointer to the prettified text as held by "dsv".
char* pv_pretty(SV *dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags)
CV * cv_clone(CV *proto)
An SV may be passed as a second argument. If so, the name will be assigned to it and it will be returned. Otherwise the returned SV will be a new mortal.
If "flags" has the "CV_NAME_NOTQUAL" bit set, then the package name will not be included. If the first argument is neither a CV nor a GV, this flag is ignored (subject to change).
SV * cv_name(CV *cv, SV *sv, U32 flags)
void cv_undef(CV* cv)
SV * find_rundefsv()
Until the lexical $_ feature was removed, this function would find the position of the lexical $_ in the pad of the currently-executing function and return the offset in the current pad, or "NOT_IN_PAD".
Now it always returns "NOT_IN_PAD".
NOTE: the perl_ form of this function is deprecated.
PADOFFSET find_rundefsvoffset()
U32 intro_my()
If "PERL_LOADMOD_NOIMPORT" is set, the module is loaded as if with an empty import list, as in "use Foo::Bar ()"; this is the only circumstance in which the trailing optional arguments may be omitted entirely. Otherwise, if "PERL_LOADMOD_IMPORT_OPS" is set, the trailing arguments must consist of exactly one "OP*", containing the op tree that produces the relevant import arguments. Otherwise, the trailing arguments must all be "SV*" values that will be used as import arguments; and the list must be terminated with "(SV*) NULL". If neither "PERL_LOADMOD_NOIMPORT" nor "PERL_LOADMOD_IMPORT_OPS" is set, the trailing "NULL" pointer is needed even if no import arguments are desired. The reference count for each specified "SV*" argument is decremented. In addition, the "name" argument is modified.
If "PERL_LOADMOD_DENY" is set, the module is loaded as if with "no" rather than "use".
void load_module(U32 flags, SV* name, SV* ver, ...)
Creates a new pad name list. "max" is the highest index for which space is allocated.
PADNAMELIST * newPADNAMELIST(size_t max)
Constructs and returns a new pad name. Only use this function for names that refer to outer lexicals. (See also "newPADNAMEpvn".) "outer" is the outer pad name that this one mirrors. The returned pad name has the "PADNAMEt_OUTER" flag already set.
PADNAME * newPADNAMEouter(PADNAME *outer)
Constructs and returns a new pad name. "s" must be a UTF-8 string. Do not use this for pad names that point to outer lexicals. See "newPADNAMEouter".
PADNAME * newPADNAMEpvn(const char *s, STRLEN len)
int nothreadhook()
One reference count is stolen, so you may need to do "SvREFCNT_inc(func)".
"optype" should be an opcode indicating the type of operation that the pad entry is to support. This doesn't affect operational semantics, but is used for debugging.
PADOFFSET pad_add_anon(CV *func, I32 optype)
PADOFFSET pad_add_name_pv(const char *name, U32 flags, HV *typestash, HV *ourstash)
"namepv"/"namelen" specify the variable's name, including leading sigil. If "typestash" is non-null, the name is for a typed lexical, and this identifies the type. If "ourstash" is non-null, it's a lexical reference to a package variable, and this identifies the package. The following flags can be OR'ed together:
padadd_OUR redundantly specifies if it's a package var padadd_STATE variable will retain value persistently padadd_NO_DUP_CHECK skip check for lexical shadowing PADOFFSET pad_add_name_pvn(const char *namepv, STRLEN namelen, U32 flags, HV *typestash, HV *ourstash)
PADOFFSET pad_add_name_sv(SV *name, U32 flags, HV *typestash, HV *ourstash)
Allocates a place in the currently-compiling pad, returning the offset of the allocated pad slot. No name is initially attached to the pad slot. "tmptype" is a set of flags indicating the kind of pad entry required, which will be set in the value SV for the allocated pad entry:
SVs_PADMY named lexical variable ("my", "our", "state") SVs_PADTMP unnamed temporary store SVf_READONLY constant shared between recursion levels
"SVf_READONLY" has been supported here only since perl 5.20. To work with earlier versions as well, use "SVf_READONLY|SVs_PADTMP". "SVf_READONLY" does not cause the SV in the pad slot to be marked read-only, but simply tells "pad_alloc" that it will be made read-only (by the caller), or at least should be treated as such.
"optype" should be an opcode indicating the type of operation that the pad entry is to support. This doesn't affect operational semantics, but is used for debugging.
PADOFFSET pad_alloc(I32 optype, U32 tmptype)
PADOFFSET pad_findmy_pv(const char *name, U32 flags)
PADOFFSET pad_findmy_pvn(const char *namepv, STRLEN namelen, U32 flags)
PADOFFSET pad_findmy_sv(SV *name, U32 flags)
Fetches the pad name from the given index.
PADNAME * padnamelist_fetch(PADNAMELIST *pnl, SSize_t key)
Stores the pad name (which may be null) at the given index, freeing any existing pad name in that slot.
PADNAME ** padnamelist_store(PADNAMELIST *pnl, SSize_t key, PADNAME *val)
void pad_setsv(PADOFFSET po, SV *sv)
SV * pad_sv(PADOFFSET po)
Tidy up a pad at the end of compilation of the code to which it belongs. Jobs performed here are: remove most stuff from the pads of anonsub prototypes; give it a @_; mark temporaries as such. "type" indicates the kind of subroutine:
padtidy_SUB ordinary subroutine padtidy_SUBCLONE prototype for lexical closure padtidy_FORMAT format void pad_tidy(padtidy_type type)
PerlInterpreter* perl_alloc()
void perl_construct(PerlInterpreter *my_perl)
"my_perl" points to the Perl interpreter. It must have been previously created through the use of "perl_alloc" and "perl_construct". It may have been initialised through "perl_parse", and may have been used through "perl_run" and other means. This function should be called for any Perl interpreter that has been constructed with "perl_construct", even if subsequent operations on it failed, for example if "perl_parse" returned a non-zero value.
If the interpreter's "PL_exit_flags" word has the "PERL_EXIT_DESTRUCT_END" flag set, then this function will execute code in "END" blocks before performing the rest of destruction. If it is desired to make any use of the interpreter between "perl_parse" and "perl_destruct" other than just calling "perl_run", then this flag should be set early on. This matters if "perl_run" will not be called, or if anything else will be done in addition to calling "perl_run".
Returns a value be a suitable value to pass to the C library function "exit" (or to return from "main"), to serve as an exit code indicating the nature of the way the interpreter terminated. This takes into account any failure of "perl_parse" and any early exit from "perl_run". The exit code is of the type required by the host operating system, so because of differing exit code conventions it is not portable to interpret specific numeric values as having specific meanings.
int perl_destruct(PerlInterpreter *my_perl)
void perl_free(PerlInterpreter *my_perl)
"my_perl" points to the Perl interpreter that is to parse the script. It must have been previously created through the use of "perl_alloc" and "perl_construct". "xsinit" points to a callback function that will be called to set up the ability for this Perl interpreter to load XS extensions, or may be null to perform no such setup.
"argc" and "argv" supply a set of command-line arguments to the Perl interpreter, as would normally be passed to the "main" function of a C program. "argv[argc]" must be null. These arguments are where the script to parse is specified, either by naming a script file or by providing a script in a "-e" option. If $0 will be written to in the Perl interpreter, then the argument strings must be in writable memory, and so mustn't just be string constants.
"env" specifies a set of environment variables that will be used by this Perl interpreter. If non-null, it must point to a null-terminated array of environment strings. If null, the Perl interpreter will use the environment supplied by the "environ" global variable.
This function initialises the interpreter, and parses and compiles the script specified by the command-line arguments. This includes executing code in "BEGIN", "UNITCHECK", and "CHECK" blocks. It does not execute "INIT" blocks or the main program.
Returns an integer of slightly tricky interpretation. The correct use of the return value is as a truth value indicating whether there was a failure in initialisation. If zero is returned, this indicates that initialisation was successful, and it is safe to proceed to call "perl_run" and make other use of it. If a non-zero value is returned, this indicates some problem that means the interpreter wants to terminate. The interpreter should not be just abandoned upon such failure; the caller should proceed to shut the interpreter down cleanly with "perl_destruct" and free it with "perl_free".
For historical reasons, the non-zero return value also attempts to be a suitable value to pass to the C library function "exit" (or to return from "main"), to serve as an exit code indicating the nature of the way initialisation terminated. However, this isn't portable, due to differing exit code conventions. A historical bug is preserved for the time being: if the Perl built-in "exit" is called during this function's execution, with a type of exit entailing a zero exit code under the host operating system's conventions, then this function returns zero rather than a non-zero value. This bug, [perl #2754], leads to "perl_run" being called (and therefore "INIT" blocks and the main program running) despite a call to "exit". It has been preserved because a popular module-installing module has come to rely on it and needs time to be fixed. This issue is [perl #132577], and the original bug is due to be fixed in Perl 5.30.
int perl_parse(PerlInterpreter *my_perl, XSINIT_t xsinit, int argc, char **argv, char **env)
"my_perl" points to the Perl interpreter. It must have been previously created through the use of "perl_alloc" and "perl_construct", and initialised through "perl_parse". This function should not be called if "perl_parse" returned a non-zero value, indicating a failure in initialisation or compilation.
This function executes code in "INIT" blocks, and then executes the main program. The code to be executed is that established by the prior call to "perl_parse". If the interpreter's "PL_exit_flags" word does not have the "PERL_EXIT_DESTRUCT_END" flag set, then this function will also execute code in "END" blocks. If it is desired to make any further use of the interpreter after calling this function, then "END" blocks should be postponed to "perl_destruct" time by setting that flag.
Returns an integer of slightly tricky interpretation. The correct use of the return value is as a truth value indicating whether the program terminated non-locally. If zero is returned, this indicates that the program ran to completion, and it is safe to make other use of the interpreter (provided that the "PERL_EXIT_DESTRUCT_END" flag was set as described above). If a non-zero value is returned, this indicates that the interpreter wants to terminate early. The interpreter should not be just abandoned because of this desire to terminate; the caller should proceed to shut the interpreter down cleanly with "perl_destruct" and free it with "perl_free".
For historical reasons, the non-zero return value also attempts to be a suitable value to pass to the C library function "exit" (or to return from "main"), to serve as an exit code indicating the nature of the way the program terminated. However, this isn't portable, due to differing exit code conventions. An attempt is made to return an exit code of the type required by the host operating system, but because it is constrained to be non-zero, it is not necessarily possible to indicate every type of exit. It is only reliable on Unix, where a zero exit code can be augmented with a set bit that will be ignored. In any case, this function is not the correct place to acquire an exit code: one should get that from "perl_destruct".
int perl_run(PerlInterpreter *my_perl)
NOTE: the perl_ form of this function is deprecated.
void require_pv(const char* pv)
dXCPT;
XCPT_RETHROW;
void sortsv_flags(SV** array, size_t num_elts, SVCOMPARE_t cmp, U32 flags)
If empty is true, replace the GP with a new GP.
If empty is false, mark gv with GVf_INTRO so the next reference assigned is localized, which is how " local *foo = $someref; " works.
void save_gp(GV* gv, I32 empty)
SV *sv = new_version(SV *ver);
Does not alter the passed in ver SV. See "upg_version" if you want to upgrade the SV.
SV* new_version(SV *ver)
const char* prescan_version(const char *s, bool strict, const char** errstr, bool *sqv, int *ssaw_decimal, int *swidth, bool *salpha)
Function must be called with an already existing SV like
sv = newSV(0); s = scan_version(s, SV *sv, bool qv);
Performs some preprocessing to the string to ensure that it has the correct characteristics of a version. Flags the object if it contains an underscore (which denotes this is an alpha version). The boolean qv denotes that the version should be interpreted as if it had multiple decimals, even if it doesn't.
const char* scan_version(const char *s, SV *rv, bool qv)
SV *sv = upg_version(SV *sv, bool qv);
Returns a pointer to the upgraded SV. Set the boolean qv if you want to force this SV to be interpreted as an "extended" version.
SV* upg_version(SV *ver, bool qv)
int vcmp(SV *lhv, SV *rhv)
sv = vnormal(rv);
NOTE: you can pass either the object directly or the SV contained within the RV.
The SV returned has a refcount of 1.
SV* vnormal(SV *vs)
sv = vnumify(rv);
NOTE: you can pass either the object directly or the SV contained within the RV.
The SV returned has a refcount of 1.
SV* vnumify(SV *vs)
The SV returned has a refcount of 1.
SV* vstringify(SV *vs)
SV *hv = vverify(sv);
Note that it only confirms the bare minimum structure (so as not to get confused by derived classes which may contain additional hash entries):
SV* vverify(SV *vs)
U32 GIMME
U32 GIMME_V
This array of function pointers is a convenient place to hook into the compilation process. An XS module can put its own custom check function in place of any of the standard ones, to influence the compilation of a particular type of op. However, a custom check function must never fully replace a standard check function (or even a custom check function from another module). A module modifying checking must instead wrap the preexisting check function. A custom check function must be selective about when to apply its custom behaviour. In the usual case where it decides not to do anything special with an op, it must chain the preexisting op function. Check functions are thus linked in a chain, with the core's base checker at the end.
For thread safety, modules should not write directly to this array. Instead, use the function "wrap_op_checker".
Function pointer, pointing at a function used to handle extended keywords. The function should be declared as
int keyword_plugin_function(pTHX_ char *keyword_ptr, STRLEN keyword_len, OP **op_ptr)
The function is called from the tokeniser, whenever a possible keyword is seen. "keyword_ptr" points at the word in the parser's input buffer, and "keyword_len" gives its length; it is not null-terminated. The function is expected to examine the word, and possibly other state such as %^H, to decide whether it wants to handle it as an extended keyword. If it does not, the function should return "KEYWORD_PLUGIN_DECLINE", and the normal parser process will continue.
If the function wants to handle the keyword, it first must parse anything following the keyword that is part of the syntax introduced by the keyword. See "Lexer interface" for details.
When a keyword is being handled, the plugin function must build a tree of "OP" structures, representing the code that was parsed. The root of the tree must be stored in *op_ptr. The function then returns a constant indicating the syntactic role of the construct that it has parsed: "KEYWORD_PLUGIN_STMT" if it is a complete statement, or "KEYWORD_PLUGIN_EXPR" if it is an expression. Note that a statement construct cannot be used inside an expression (except via "do BLOCK" and similar), and an expression is not a complete statement (it requires at least a terminating semicolon).
When a keyword is handled, the plugin function may also have (compile-time) side effects. It may modify "%^H", define functions, and so on. Typically, if side effects are the main purpose of a handler, it does not wish to generate any ops to be included in the normal compilation. In this case it is still required to supply an op tree, but it suffices to generate a single null op.
That's how the *PL_keyword_plugin function needs to behave overall. Conventionally, however, one does not completely replace the existing handler function. Instead, take a copy of "PL_keyword_plugin" before assigning your own function pointer to it. Your handler function should look for keywords that it is interested in and handle those. Where it is not interested, it should call the saved plugin function, passing on the arguments it received. Thus "PL_keyword_plugin" actually points at a chain of handler functions, all of which have an opportunity to handle keywords, and only the last function in the chain (built into the Perl core) will normally return "KEYWORD_PLUGIN_DECLINE".
For thread safety, modules should not set this variable directly. Instead, use the function "wrap_keyword_plugin".
GVs are usually found as values in stashes (symbol table hashes) where Perl stores its global variables.
AV* GvAV(GV* gv)
SV* gv_const_sv(GV* gv)
CV* GvCV(GV* gv)
GV* gv_fetchmeth(HV* stash, const char* name, STRLEN len, I32 level)
The third parameter of "gv_fetchmethod_autoload" determines whether AUTOLOAD lookup is performed if the given method is not present: non-zero means yes, look for AUTOLOAD; zero means no, don't look for AUTOLOAD. Calling "gv_fetchmethod" is equivalent to calling "gv_fetchmethod_autoload" with a non-zero "autoload" parameter.
These functions grant "SUPER" token as a prefix of the method name. Note that if you want to keep the returned glob for a long time, you need to check for it being "AUTOLOAD", since at the later time the call may load a different subroutine due to $AUTOLOAD changing its value. Use the glob created as a side effect to do this.
These functions have the same side-effects as "gv_fetchmeth" with "level==0". The warning against passing the GV returned by "gv_fetchmeth" to "call_sv" applies equally to these functions.
GV* gv_fetchmethod_autoload(HV* stash, const char* name, I32 autoload)
GV* gv_fetchmeth_autoload(HV* stash, const char* name, STRLEN len, I32 level)
GV* gv_fetchmeth_pv(HV* stash, const char* name, I32 level, U32 flags)
The argument "level" should be either 0 or -1. If "level==0", as a side-effect creates a glob with the given "name" in the given "stash" which in the case of success contains an alias for the subroutine, and sets up caching info for this glob.
The only significant values for "flags" are "GV_SUPER" and "SVf_UTF8".
"GV_SUPER" indicates that we want to look up the method in the superclasses of the "stash".
The GV returned from "gv_fetchmeth" may be a method cache entry, which is not visible to Perl code. So when calling "call_sv", you should not use the GV directly; instead, you should use the method's CV, which can be obtained from the GV with the "GvCV" macro.
GV* gv_fetchmeth_pvn(HV* stash, const char* name, STRLEN len, I32 level, U32 flags)
For an autoloaded subroutine without a GV, will create a GV even if "level < 0". For an autoloaded subroutine without a stub, "GvCV()" of the result may be zero.
Currently, the only significant value for "flags" is "SVf_UTF8".
GV* gv_fetchmeth_pvn_autoload(HV* stash, const char* name, STRLEN len, I32 level, U32 flags)
GV* gv_fetchmeth_pv_autoload(HV* stash, const char* name, I32 level, U32 flags)
GV* gv_fetchmeth_sv(HV* stash, SV* namesv, I32 level, U32 flags)
GV* gv_fetchmeth_sv_autoload(HV* stash, SV* namesv, I32 level, U32 flags)
HV* GvHV(GV* gv)
void gv_init(GV* gv, HV* stash, const char* name, STRLEN len, int multi)
void gv_init_pv(GV* gv, HV* stash, const char* name, U32 flags)
"gv" is the scalar to be converted.
"stash" is the parent stash/package, if any.
"name" and "len" give the name. The name must be unqualified; that is, it must not include the package name. If "gv" is a stash element, it is the caller's responsibility to ensure that the name passed to this function matches the name of the element. If it does not match, perl's internal bookkeeping will get out of sync.
"flags" can be set to "SVf_UTF8" if "name" is a UTF-8 string, or the return value of SvUTF8(sv). It can also take the "GV_ADDMULTI" flag, which means to pretend that the GV has been seen before (i.e., suppress "Used once" warnings).
void gv_init_pvn(GV* gv, HV* stash, const char* name, STRLEN len, U32 flags)
void gv_init_sv(GV* gv, HV* stash, SV* namesv, U32 flags)
HV* gv_stashpv(const char* name, I32 flags)
Flags may be one of:
GV_ADD SVf_UTF8 GV_NOADD_NOINIT GV_NOINIT GV_NOEXPAND GV_ADDMG
The most important of which are probably "GV_ADD" and "SVf_UTF8".
Note, use of "gv_stashsv" instead of "gv_stashpvn" where possible is strongly recommended for performance reasons.
HV* gv_stashpvn(const char* name, U32 namelen, I32 flags)
HV* gv_stashpvs("literal string" name, I32 create)
Note this interface is strongly preferred over "gv_stashpvn" for performance reasons.
HV* gv_stashsv(SV* sv, I32 flags)
SV* GvSV(GV* gv)
void setdefout(GV* gv)
(deprecated - use "(AV *)NULL" instead)
(deprecated - use "(CV *)NULL" instead)
(deprecated - use "(HV *)NULL" instead)
Returns the label attached to a cop. The flags pointer may be set to "SVf_UTF8" or 0.
const char * cop_fetch_label(COP *const cop, STRLEN *len, U32 *flags)
Save a label into a "cop_hints_hash". You need to set flags to "SVf_UTF8" for a UTF-8 label.
void cop_store_label(COP *const cop, const char *label, STRLEN len, U32 flags)
NOTE: the perl_ form of this function is deprecated.
HV* get_hv(const char *name, I32 flags)
U32 HeHASH(HE* he)
void* HeKEY(HE* he)
STRLEN HeKLEN(HE* he)
If you are using "HePV" to get values to pass to "newSVpvn()" to create a new SV, you should consider using "newSVhek(HeKEY_hek(he))" as it is more efficient.
char* HePV(HE* he, STRLEN len)
SV* HeSVKEY(HE* he)
SV* HeSVKEY_force(HE* he)
SV* HeSVKEY_set(HE* he, SV* sv)
U32 HeUTF8(HE* he)
SV *foo= HeVAL(hv); HeVAL(hv)= sv; SV* HeVAL(HE* he)
void hv_assert(HV *hv)
If the hash is tied dispatches through to the SCALAR tied method, otherwise if the hash contains no keys returns 0, otherwise returns a mortal sv containing a string specifying the number of used buckets, followed by a slash, followed by the number of available buckets.
This function is expensive, it must scan all of the buckets to determine which are used, and the count is NOT cached. In a large hash this could be a lot of buckets.
SV* hv_bucket_ratio(HV *hv)
See "av_clear" for a note about the hash possibly being invalid on return.
void hv_clear(HV *hv)
void hv_clear_placeholders(HV *hv)
HV * hv_copy_hints_hv(HV *ohv)
SV* hv_delete(HV *hv, const char *key, I32 klen, I32 flags)
SV* hv_delete_ent(HV *hv, SV *keysv, I32 flags, U32 hash)
char* HvENAME(HV* stash)
STRLEN HvENAMELEN(HV *stash)
unsigned char HvENAMEUTF8(HV *stash)
bool hv_exists(HV *hv, const char *key, I32 klen)
bool hv_exists_ent(HV *hv, SV *keysv, U32 hash)
See "Understanding the Magic of Tied Hashes and Arrays" in perlguts for more information on how to use this function on tied hashes.
SV** hv_fetch(HV *hv, const char *key, I32 klen, I32 lval)
SV** hv_fetchs(HV* tb, "literal string" key, I32 lval)
See "Understanding the Magic of Tied Hashes and Arrays" in perlguts for more information on how to use this function on tied hashes.
HE* hv_fetch_ent(HV *hv, SV *keysv, I32 lval, U32 hash)
This function is wrapped by the macro "HvFILL".
As of perl 5.25 this function is used only for debugging purposes, and the number of used hash buckets is not in any way cached, thus this function can be costly to execute as it must iterate over all the buckets in the hash.
STRLEN hv_fill(HV *const hv)
NOTE: Before version 5.004_65, "hv_iterinit" used to return the number of hash buckets that happen to be in use. If you still need that esoteric value, you can get it through the macro "HvFILL(hv)".
I32 hv_iterinit(HV *hv)
char* hv_iterkey(HE* entry, I32* retlen)
SV* hv_iterkeysv(HE* entry)
You may call "hv_delete" or "hv_delete_ent" on the hash entry that the iterator currently points to, without losing your place or invalidating your iterator. Note that in this case the current entry is deleted from the hash with your iterator holding the last reference to it. Your iterator is flagged to free the entry on the next call to "hv_iternext", so you must not discard your iterator immediately else the entry will leak - call "hv_iternext" to trigger the resource deallocation.
HE* hv_iternext(HV *hv)
SV* hv_iternextsv(HV *hv, char **key, I32 *retlen)
Returns entries from a hash iterator. See "hv_iterinit" and "hv_iternext". The "flags" value will normally be zero; if "HV_ITERNEXT_WANTPLACEHOLDERS" is set the placeholders keys (for restricted hashes) will be returned in addition to normal keys. By default placeholders are automatically skipped over. Currently a placeholder is implemented with a value that is &PL_sv_placeholder. Note that the implementation of placeholders and restricted hashes may change, and the implementation currently is insufficiently abstracted for any change to be tidy.
HE* hv_iternext_flags(HV *hv, I32 flags)
SV* hv_iterval(HV *hv, HE *entry)
void hv_magic(HV *hv, GV *gv, int how)
char* HvNAME(HV* stash)
STRLEN HvNAMELEN(HV *stash)
unsigned char HvNAMEUTF8(HV *stash)
When the hash is tied dispatches through to the SCALAR method, otherwise returns a mortal SV containing the number of keys in the hash.
Note, prior to 5.25 this function returned what is now returned by the hv_bucket_ratio() function.
SV* hv_scalar(HV *hv)
The return value will be "NULL" if the operation failed or if the value did not need to be actually stored within the hash (as in the case of tied hashes). Otherwise it can be dereferenced to get the original "SV*". Note that the caller is responsible for suitably incrementing the reference count of "val" before the call, and decrementing it if the function returned "NULL". Effectively a successful "hv_store" takes ownership of one reference to "val". This is usually what you want; a newly created SV has a reference count of one, so if all your code does is create SVs then store them in a hash, "hv_store" will own the only reference to the new SV, and your code doesn't need to do anything further to tidy up. "hv_store" is not implemented as a call to "hv_store_ent", and does not create a temporary SV for the key, so if your key data is not already in SV form then use "hv_store" in preference to "hv_store_ent".
See "Understanding the Magic of Tied Hashes and Arrays" in perlguts for more information on how to use this function on tied hashes.
SV** hv_store(HV *hv, const char *key, I32 klen, SV *val, U32 hash)
SV** hv_stores(HV* tb, "literal string" key, SV* val)
See "Understanding the Magic of Tied Hashes and Arrays" in perlguts for more information on how to use this function on tied hashes.
HE* hv_store_ent(HV *hv, SV *key, SV *val, U32 hash)
As well as freeing all the elements of the hash (like "hv_clear()"), this also frees any auxiliary data and storage associated with the hash.
See "av_clear" for a note about the hash possibly being invalid on return.
void hv_undef(HV *hv)
HV* newHV()
"PL_check" is global to an entire process, and a module wishing to hook op checking may find itself invoked more than once per process, typically in different threads. To handle that situation, this function is idempotent. The location *old_checker_p must initially (once per process) contain a null pointer. A C variable of static duration (declared at file scope, typically also marked "static" to give it internal linkage) will be implicitly initialised appropriately, if it does not have an explicit initialiser. This function will only actually modify the check chain if it finds *old_checker_p to be null. This function is also thread safe on the small scale. It uses appropriate locking to avoid race conditions in accessing "PL_check".
When this function is called, the function referenced by "new_checker" must be ready to be called, except for *old_checker_p being unfilled. In a threading situation, "new_checker" may be called immediately, even before this function has returned. *old_checker_p will always be appropriately set before "new_checker" is called. If "new_checker" decides not to do anything special with an op that it is given (which is the usual case for most uses of op check hooking), it must chain the check function referenced by *old_checker_p.
Taken all together, XS code to hook an op checker should typically look something like this:
static Perl_check_t nxck_frob; static OP *myck_frob(pTHX_ OP *op) { ... op = nxck_frob(aTHX_ op); ... return op; } BOOT: wrap_op_checker(OP_FROB, myck_frob, &nxck_frob);
If you want to influence compilation of calls to a specific subroutine, then use "cv_set_call_checker_flags" rather than hooking checking of all "entersub" ops.
void wrap_op_checker(Optype opcode, Perl_check_t new_checker, Perl_check_t *old_checker_p)
Indicates whether the octets in the lexer buffer ("PL_parser->linestr") should be interpreted as the UTF-8 encoding of Unicode characters. If not, they should be interpreted as Latin-1 characters. This is analogous to the "SvUTF8" flag for scalars.
In UTF-8 mode, it is not guaranteed that the lexer buffer actually contains valid UTF-8. Lexing code must be robust in the face of invalid encoding.
The actual "SvUTF8" flag of the "PL_parser->linestr" scalar is significant, but not the whole story regarding the input character encoding. Normally, when a file is being read, the scalar contains octets and its "SvUTF8" flag is off, but the octets should be interpreted as UTF-8 if the "use utf8" pragma is in effect. During a string eval, however, the scalar may have the "SvUTF8" flag on, and in this case its octets should be interpreted as UTF-8 unless the "use bytes" pragma is in effect. This logic may change in the future; use this function instead of implementing the logic yourself.
bool lex_bufutf8()
Discards the first part of the "PL_parser->linestr" buffer, up to "ptr". The remaining content of the buffer will be moved, and all pointers into the buffer updated appropriately. "ptr" must not be later in the buffer than the position of "PL_parser->bufptr": it is not permitted to discard text that has yet to be lexed.
Normally it is not necessarily to do this directly, because it suffices to use the implicit discarding behaviour of "lex_next_chunk" and things based on it. However, if a token stretches across multiple lines, and the lexing code has kept multiple lines of text in the buffer for that purpose, then after completion of the token it would be wise to explicitly discard the now-unneeded earlier lines, to avoid future multi-line tokens growing the buffer without bound.
void lex_discard_to(char *ptr)
Reallocates the lexer buffer ("PL_parser->linestr") to accommodate at least "len" octets (including terminating "NUL"). Returns a pointer to the reallocated buffer. This is necessary before making any direct modification of the buffer that would increase its length. "lex_stuff_pvn" provides a more convenient way to insert text into the buffer.
Do not use "SvGROW" or "sv_grow" directly on "PL_parser->linestr"; this function updates all of the lexer's variables that point directly into the buffer.
char * lex_grow_linestr(STRLEN len)
Reads in the next chunk of text to be lexed, appending it to "PL_parser->linestr". This should be called when lexing code has looked to the end of the current chunk and wants to know more. It is usual, but not necessary, for lexing to have consumed the entirety of the current chunk at this time.
If "PL_parser->bufptr" is pointing to the very end of the current chunk (i.e., the current chunk has been entirely consumed), normally the current chunk will be discarded at the same time that the new chunk is read in. If "flags" has the "LEX_KEEP_PREVIOUS" bit set, the current chunk will not be discarded. If the current chunk has not been entirely consumed, then it will not be discarded regardless of the flag.
Returns true if some new text was added to the buffer, or false if the buffer has reached the end of the input text.
bool lex_next_chunk(U32 flags)
Looks ahead one (Unicode) character in the text currently being lexed. Returns the codepoint (unsigned integer value) of the next character, or -1 if lexing has reached the end of the input text. To consume the peeked character, use "lex_read_unichar".
If the next character is in (or extends into) the next chunk of input text, the next chunk will be read in. Normally the current chunk will be discarded at the same time, but if "flags" has the "LEX_KEEP_PREVIOUS" bit set, then the current chunk will not be discarded.
If the input is being interpreted as UTF-8 and a UTF-8 encoding error is encountered, an exception is generated.
I32 lex_peek_unichar(U32 flags)
Reads optional spaces, in Perl style, in the text currently being lexed. The spaces may include ordinary whitespace characters and Perl-style comments. "#line" directives are processed if encountered. "PL_parser->bufptr" is moved past the spaces, so that it points at a non-space character (or the end of the input text).
If spaces extend into the next chunk of input text, the next chunk will be read in. Normally the current chunk will be discarded at the same time, but if "flags" has the "LEX_KEEP_PREVIOUS" bit set, then the current chunk will not be discarded.
void lex_read_space(U32 flags)
Consume text in the lexer buffer, from "PL_parser->bufptr" up to "ptr". This advances "PL_parser->bufptr" to match "ptr", performing the correct bookkeeping whenever a newline character is passed. This is the normal way to consume lexed text.
Interpretation of the buffer's octets can be abstracted out by using the slightly higher-level functions "lex_peek_unichar" and "lex_read_unichar".
void lex_read_to(char *ptr)
Reads the next (Unicode) character in the text currently being lexed. Returns the codepoint (unsigned integer value) of the character read, and moves "PL_parser->bufptr" past the character, or returns -1 if lexing has reached the end of the input text. To non-destructively examine the next character, use "lex_peek_unichar" instead.
If the next character is in (or extends into) the next chunk of input text, the next chunk will be read in. Normally the current chunk will be discarded at the same time, but if "flags" has the "LEX_KEEP_PREVIOUS" bit set, then the current chunk will not be discarded.
If the input is being interpreted as UTF-8 and a UTF-8 encoding error is encountered, an exception is generated.
I32 lex_read_unichar(U32 flags)
Creates and initialises a new lexer/parser state object, supplying a context in which to lex and parse from a new source of Perl code. A pointer to the new state object is placed in "PL_parser". An entry is made on the save stack so that upon unwinding, the new state object will be destroyed and the former value of "PL_parser" will be restored. Nothing else need be done to clean up the parsing context.
The code to be parsed comes from "line" and "rsfp". "line", if non-null, provides a string (in SV form) containing code to be parsed. A copy of the string is made, so subsequent modification of "line" does not affect parsing. "rsfp", if non-null, provides an input stream from which code will be read to be parsed. If both are non-null, the code in "line" comes first and must consist of complete lines of input, and "rsfp" supplies the remainder of the source.
The "flags" parameter is reserved for future use. Currently it is only used by perl internally, so extensions should always pass zero.
void lex_start(SV *line, PerlIO *rsfp, U32 flags)
Insert characters into the lexer buffer ("PL_parser->linestr"), immediately after the current lexing point ("PL_parser->bufptr"), reallocating the buffer if necessary. This means that lexing code that runs later will see the characters as if they had appeared in the input. It is not recommended to do this as part of normal parsing, and most uses of this facility run the risk of the inserted characters being interpreted in an unintended manner.
The string to be inserted is represented by octets starting at "pv" and continuing to the first nul. These octets are interpreted as either UTF-8 or Latin-1, according to whether the "LEX_STUFF_UTF8" flag is set in "flags". The characters are recoded for the lexer buffer, according to how the buffer is currently being interpreted ("lex_bufutf8"). If it is not convenient to nul-terminate a string to be inserted, the "lex_stuff_pvn" function is more appropriate.
void lex_stuff_pv(const char *pv, U32 flags)
Insert characters into the lexer buffer ("PL_parser->linestr"), immediately after the current lexing point ("PL_parser->bufptr"), reallocating the buffer if necessary. This means that lexing code that runs later will see the characters as if they had appeared in the input. It is not recommended to do this as part of normal parsing, and most uses of this facility run the risk of the inserted characters being interpreted in an unintended manner.
The string to be inserted is represented by "len" octets starting at "pv". These octets are interpreted as either UTF-8 or Latin-1, according to whether the "LEX_STUFF_UTF8" flag is set in "flags". The characters are recoded for the lexer buffer, according to how the buffer is currently being interpreted ("lex_bufutf8"). If a string to be inserted is available as a Perl scalar, the "lex_stuff_sv" function is more convenient.
void lex_stuff_pvn(const char *pv, STRLEN len, U32 flags)
Like "lex_stuff_pvn", but takes a literal string instead of a string/length pair.
void lex_stuff_pvs("literal string" pv, U32 flags)
Insert characters into the lexer buffer ("PL_parser->linestr"), immediately after the current lexing point ("PL_parser->bufptr"), reallocating the buffer if necessary. This means that lexing code that runs later will see the characters as if they had appeared in the input. It is not recommended to do this as part of normal parsing, and most uses of this facility run the risk of the inserted characters being interpreted in an unintended manner.
The string to be inserted is the string value of "sv". The characters are recoded for the lexer buffer, according to how the buffer is currently being interpreted ("lex_bufutf8"). If a string to be inserted is not already a Perl scalar, the "lex_stuff_pvn" function avoids the need to construct a scalar.
void lex_stuff_sv(SV *sv, U32 flags)
Discards text about to be lexed, from "PL_parser->bufptr" up to "ptr". Text following "ptr" will be moved, and the buffer shortened. This hides the discarded text from any lexing code that runs later, as if the text had never appeared.
This is not the normal way to consume lexed text. For that, use "lex_read_to".
void lex_unstuff(char *ptr)
Parse a Perl arithmetic expression. This may contain operators of precedence down to the bit shift operators. The expression must be followed (and thus terminated) either by a comparison or lower-precedence operator or by something that would normally terminate an expression such as semicolon. If "flags" has the "PARSE_OPTIONAL" bit set, then the expression is optional, otherwise it is mandatory. It is up to the caller to ensure that the dynamic parser state ("PL_parser" et al) is correctly set to reflect the source of the code to be parsed and the lexical context for the expression.
The op tree representing the expression is returned. If an optional expression is absent, a null pointer is returned, otherwise the pointer will be non-null.
If an error occurs in parsing or compilation, in most cases a valid op tree is returned anyway. The error is reflected in the parser state, normally resulting in a single exception at the top level of parsing which covers all the compilation errors that occurred. Some compilation errors, however, will throw an exception immediately.
OP * parse_arithexpr(U32 flags)
Parse a single unadorned Perl statement. This may be a normal imperative statement or a declaration that has compile-time effect. It does not include any label or other affixture. It is up to the caller to ensure that the dynamic parser state ("PL_parser" et al) is correctly set to reflect the source of the code to be parsed and the lexical context for the statement.
The op tree representing the statement is returned. This may be a null pointer if the statement is null, for example if it was actually a subroutine definition (which has compile-time side effects). If not null, it will be ops directly implementing the statement, suitable to pass to "newSTATEOP". It will not normally include a "nextstate" or equivalent op (except for those embedded in a scope contained entirely within the statement).
If an error occurs in parsing or compilation, in most cases a valid op tree (most likely null) is returned anyway. The error is reflected in the parser state, normally resulting in a single exception at the top level of parsing which covers all the compilation errors that occurred. Some compilation errors, however, will throw an exception immediately.
The "flags" parameter is reserved for future use, and must always be zero.
OP * parse_barestmt(U32 flags)
Parse a single complete Perl code block. This consists of an opening brace, a sequence of statements, and a closing brace. The block constitutes a lexical scope, so "my" variables and various compile-time effects can be contained within it. It is up to the caller to ensure that the dynamic parser state ("PL_parser" et al) is correctly set to reflect the source of the code to be parsed and the lexical context for the statement.
The op tree representing the code block is returned. This is always a real op, never a null pointer. It will normally be a "lineseq" list, including "nextstate" or equivalent ops. No ops to construct any kind of runtime scope are included by virtue of it being a block.
If an error occurs in parsing or compilation, in most cases a valid op tree (most likely null) is returned anyway. The error is reflected in the parser state, normally resulting in a single exception at the top level of parsing which covers all the compilation errors that occurred. Some compilation errors, however, will throw an exception immediately.
The "flags" parameter is reserved for future use, and must always be zero.
OP * parse_block(U32 flags)
Parse a single complete Perl expression. This allows the full expression grammar, including the lowest-precedence operators such as "or". The expression must be followed (and thus terminated) by a token that an expression would normally be terminated by: end-of-file, closing bracketing punctuation, semicolon, or one of the keywords that signals a postfix expression-statement modifier. If "flags" has the "PARSE_OPTIONAL" bit set, then the expression is optional, otherwise it is mandatory. It is up to the caller to ensure that the dynamic parser state ("PL_parser" et al) is correctly set to reflect the source of the code to be parsed and the lexical context for the expression.
The op tree representing the expression is returned. If an optional expression is absent, a null pointer is returned, otherwise the pointer will be non-null.
If an error occurs in parsing or compilation, in most cases a valid op tree is returned anyway. The error is reflected in the parser state, normally resulting in a single exception at the top level of parsing which covers all the compilation errors that occurred. Some compilation errors, however, will throw an exception immediately.
OP * parse_fullexpr(U32 flags)
Parse a single complete Perl statement. This may be a normal imperative statement or a declaration that has compile-time effect, and may include optional labels. It is up to the caller to ensure that the dynamic parser state ("PL_parser" et al) is correctly set to reflect the source of the code to be parsed and the lexical context for the statement.
The op tree representing the statement is returned. This may be a null pointer if the statement is null, for example if it was actually a subroutine definition (which has compile-time side effects). If not null, it will be the result of a "newSTATEOP" call, normally including a "nextstate" or equivalent op.
If an error occurs in parsing or compilation, in most cases a valid op tree (most likely null) is returned anyway. The error is reflected in the parser state, normally resulting in a single exception at the top level of parsing which covers all the compilation errors that occurred. Some compilation errors, however, will throw an exception immediately.
The "flags" parameter is reserved for future use, and must always be zero.
OP * parse_fullstmt(U32 flags)
Parse a single label, possibly optional, of the type that may prefix a Perl statement. It is up to the caller to ensure that the dynamic parser state ("PL_parser" et al) is correctly set to reflect the source of the code to be parsed. If "flags" has the "PARSE_OPTIONAL" bit set, then the label is optional, otherwise it is mandatory.
The name of the label is returned in the form of a fresh scalar. If an optional label is absent, a null pointer is returned.
If an error occurs in parsing, which can only occur if the label is mandatory, a valid label is returned anyway. The error is reflected in the parser state, normally resulting in a single exception at the top level of parsing which covers all the compilation errors that occurred.
SV * parse_label(U32 flags)
Parse a Perl list expression. This may contain operators of precedence down to the comma operator. The expression must be followed (and thus terminated) either by a low-precedence logic operator such as "or" or by something that would normally terminate an expression such as semicolon. If "flags" has the "PARSE_OPTIONAL" bit set, then the expression is optional, otherwise it is mandatory. It is up to the caller to ensure that the dynamic parser state ("PL_parser" et al) is correctly set to reflect the source of the code to be parsed and the lexical context for the expression.
The op tree representing the expression is returned. If an optional expression is absent, a null pointer is returned, otherwise the pointer will be non-null.
If an error occurs in parsing or compilation, in most cases a valid op tree is returned anyway. The error is reflected in the parser state, normally resulting in a single exception at the top level of parsing which covers all the compilation errors that occurred. Some compilation errors, however, will throw an exception immediately.
OP * parse_listexpr(U32 flags)
Parse a sequence of zero or more Perl statements. These may be normal imperative statements, including optional labels, or declarations that have compile-time effect, or any mixture thereof. The statement sequence ends when a closing brace or end-of-file is encountered in a place where a new statement could have validly started. It is up to the caller to ensure that the dynamic parser state ("PL_parser" et al) is correctly set to reflect the source of the code to be parsed and the lexical context for the statements.
The op tree representing the statement sequence is returned. This may be a null pointer if the statements were all null, for example if there were no statements or if there were only subroutine definitions (which have compile-time side effects). If not null, it will be a "lineseq" list, normally including "nextstate" or equivalent ops.
If an error occurs in parsing or compilation, in most cases a valid op tree is returned anyway. The error is reflected in the parser state, normally resulting in a single exception at the top level of parsing which covers all the compilation errors that occurred. Some compilation errors, however, will throw an exception immediately.
The "flags" parameter is reserved for future use, and must always be zero.
OP * parse_stmtseq(U32 flags)
Parse a Perl term expression. This may contain operators of precedence down to the assignment operators. The expression must be followed (and thus terminated) either by a comma or lower-precedence operator or by something that would normally terminate an expression such as semicolon. If "flags" has the "PARSE_OPTIONAL" bit set, then the expression is optional, otherwise it is mandatory. It is up to the caller to ensure that the dynamic parser state ("PL_parser" et al) is correctly set to reflect the source of the code to be parsed and the lexical context for the expression.
The op tree representing the expression is returned. If an optional expression is absent, a null pointer is returned, otherwise the pointer will be non-null.
If an error occurs in parsing or compilation, in most cases a valid op tree is returned anyway. The error is reflected in the parser state, normally resulting in a single exception at the top level of parsing which covers all the compilation errors that occurred. Some compilation errors, however, will throw an exception immediately.
OP * parse_termexpr(U32 flags)
Direct pointer to the end of the chunk of text currently being lexed, the end of the lexer buffer. This is equal to "SvPVX(PL_parser->linestr) + SvCUR(PL_parser->linestr)". A "NUL" character (zero octet) is always located at the end of the buffer, and does not count as part of the buffer's contents.
Points to the current position of lexing inside the lexer buffer. Characters around this point may be freely examined, within the range delimited by "SvPVX("PL_parser->linestr")" and "PL_parser->bufend". The octets of the buffer may be intended to be interpreted as either UTF-8 or Latin-1, as indicated by "lex_bufutf8".
Lexing code (whether in the Perl core or not) moves this pointer past the characters that it consumes. It is also expected to perform some bookkeeping whenever a newline character is consumed. This movement can be more conveniently performed by the function "lex_read_to", which handles newlines appropriately.
Interpretation of the buffer's octets can be abstracted out by using the slightly higher-level functions "lex_peek_unichar" and "lex_read_unichar".
Points to the start of the current line inside the lexer buffer. This is useful for indicating at which column an error occurred, and not much else. This must be updated by any lexing code that consumes a newline; the function "lex_read_to" handles this detail.
Buffer scalar containing the chunk currently under consideration of the text currently being lexed. This is always a plain string scalar (for which "SvPOK" is true). It is not intended to be used as a scalar by normal scalar means; instead refer to the buffer directly by the pointer variables described below.
The lexer maintains various "char*" pointers to things in the "PL_parser->linestr" buffer. If "PL_parser->linestr" is ever reallocated, all of these pointers must be updated. Don't attempt to do this manually, but rather use "lex_grow_linestr" if you need to reallocate the buffer.
The content of the text chunk in the buffer is commonly exactly one complete line of input, up to and including a newline terminator, but there are situations where it is otherwise. The octets of the buffer may be intended to be interpreted as either UTF-8 or Latin-1. The function "lex_bufutf8" tells you which. Do not use the "SvUTF8" flag on this scalar, which may disagree with it.
For direct examination of the buffer, the variable "PL_parser->bufend" points to the end of the buffer. The current lexing position is pointed to by "PL_parser->bufptr". Direct use of these pointers is usually preferable to examination of the scalar through normal scalar means.
Puts a C function into the chain of keyword plugins. This is the preferred way to manipulate the "PL_keyword_plugin" variable. "new_plugin" is a pointer to the C function that is to be added to the keyword plugin chain, and "old_plugin_p" points to the storage location where a pointer to the next function in the chain will be stored. The value of "new_plugin" is written into the "PL_keyword_plugin" variable, while the value previously stored there is written to *old_plugin_p.
"PL_keyword_plugin" is global to an entire process, and a module wishing to hook keyword parsing may find itself invoked more than once per process, typically in different threads. To handle that situation, this function is idempotent. The location *old_plugin_p must initially (once per process) contain a null pointer. A C variable of static duration (declared at file scope, typically also marked "static" to give it internal linkage) will be implicitly initialised appropriately, if it does not have an explicit initialiser. This function will only actually modify the plugin chain if it finds *old_plugin_p to be null. This function is also thread safe on the small scale. It uses appropriate locking to avoid race conditions in accessing "PL_keyword_plugin".
When this function is called, the function referenced by "new_plugin" must be ready to be called, except for *old_plugin_p being unfilled. In a threading situation, "new_plugin" may be called immediately, even before this function has returned. *old_plugin_p will always be appropriately set before "new_plugin" is called. If "new_plugin" decides not to do anything special with the identifier that it is given (which is the usual case for most calls to a keyword plugin), it must chain the plugin function referenced by *old_plugin_p.
Taken all together, XS code to install a keyword plugin should typically look something like this:
static Perl_keyword_plugin_t next_keyword_plugin; static OP *my_keyword_plugin(pTHX_ char *keyword_plugin, STRLEN keyword_len, OP **op_ptr) { if (memEQs(keyword_ptr, keyword_len, "my_new_keyword")) { ... } else { return next_keyword_plugin(aTHX_ keyword_ptr, keyword_len, op_ptr); } } BOOT: wrap_keyword_plugin(my_keyword_plugin, &next_keyword_plugin);
Direct access to "PL_keyword_plugin" should be avoided.
void wrap_keyword_plugin( Perl_keyword_plugin_t new_plugin, Perl_keyword_plugin_t *old_plugin_p )
void DECLARATION_FOR_LC_NUMERIC_MANIPULATION
Expanding on these:
It is important to note that when called with an item that is recovered by using "localeconv", the buffer from any previous explicit call to "localeconv" will be overwritten. This means you must save that buffer's contents if you need to access them after a call to this function. (But note that you might not want to be using "localeconv()" directly anyway, because of issues like the ones listed in the second item of this list (above) for "RADIXCHAR" and "THOUSEP". You can use the methods given in perlcall to call "localeconv" in POSIX and avoid all the issues, but then you have a hash to unpack).
The details for those items which may deviate from what this emulation returns and what a native "nl_langinfo()" would return are specified in I18N::Langinfo.
When using "Perl_langinfo" on systems that don't have a native "nl_langinfo()", you must
#include "perl_langinfo.h"
before the "perl.h" "#include". You can replace your "langinfo.h" "#include" with this one. (Doing it this way keeps out the symbols that plain "langinfo.h" would try to import into the namespace for code that doesn't need it.)
The original impetus for "Perl_langinfo()" was so that code that needs to find out the current currency symbol, floating point radix character, or digit grouping separator can use, on all systems, the simpler and more thread-friendly "nl_langinfo" API instead of localeconv(3) which is a pain to make thread-friendly. For other fields returned by "localeconv", it is better to use the methods given in perlcall to call "POSIX::localeconv()", which is thread-friendly.
const char* Perl_langinfo(const nl_item item)
Another reason it isn't completely a drop-in replacement is that it is declared to return "const char *", whereas the system setlocale omits the "const" (presumably because its API was specified long ago, and can't be updated; it is illegal to change the information "setlocale" returns; doing so leads to segfaults.)
Finally, "Perl_setlocale" works under all circumstances, whereas plain "setlocale" can be completely ineffective on some platforms under some configurations.
"Perl_setlocale" should not be used to change the locale except on systems where the predefined variable "${^SAFE_LOCALES}" is 1. On some such systems, the system "setlocale()" is ineffective, returning the wrong information, and failing to actually change the locale. "Perl_setlocale", however works properly in all circumstances.
The return points to a per-thread static buffer, which is overwritten the next time "Perl_setlocale" is called from the same thread.
const char* Perl_setlocale(const int category, const char* locale)
A call to "DECLARATION_FOR_LC_NUMERIC_MANIPULATION" must have been made to declare at compile time a private variable used by this macro and the two "STORE" ones. This macro should be called as a single statement, not an expression, but with an empty argument list, like this:
{ DECLARATION_FOR_LC_NUMERIC_MANIPULATION; ... RESTORE_LC_NUMERIC(); ... } void RESTORE_LC_NUMERIC()
A call to "DECLARATION_FOR_LC_NUMERIC_MANIPULATION" must have been made to declare at compile time a private variable used by this macro. This macro should be called as a single statement, not an expression, but with an empty argument list, like this:
{ DECLARATION_FOR_LC_NUMERIC_MANIPULATION; ... STORE_LC_NUMERIC_FORCE_TO_UNDERLYING(); ... RESTORE_LC_NUMERIC(); ... }
The private variable is used to save the current locale state, so that the requisite matching call to "RESTORE_LC_NUMERIC" can restore it.
On threaded perls not operating with thread-safe functionality, this macro uses a mutex to force a critical section. Therefore the matching RESTORE should be close by, and guaranteed to be called.
void STORE_LC_NUMERIC_FORCE_TO_UNDERLYING()
This macro makes sure the current "LC_NUMERIC" state is set properly, to be aware of locale if the call to the XS or C code from the Perl program is from within the scope of a "use locale"; or to ignore locale if the call is instead from outside such scope.
This macro is the start of wrapping the C or XS code; the wrap ending is done by calling the "RESTORE_LC_NUMERIC" macro after the operation. Otherwise the state can be changed that will adversely affect other XS code.
A call to "DECLARATION_FOR_LC_NUMERIC_MANIPULATION" must have been made to declare at compile time a private variable used by this macro. This macro should be called as a single statement, not an expression, but with an empty argument list, like this:
{ DECLARATION_FOR_LC_NUMERIC_MANIPULATION; ... STORE_LC_NUMERIC_SET_TO_NEEDED(); ... RESTORE_LC_NUMERIC(); ... }
On threaded perls not operating with thread-safe functionality, this macro uses a mutex to force a critical section. Therefore the matching RESTORE should be close by, and guaranteed to be called.
void STORE_LC_NUMERIC_SET_TO_NEEDED()
On multi-threaded builds on systems that do have per-thread locale operations, this function converts the thread it is running in to use the global locale. This is for code that has not yet or cannot be updated to handle multi-threaded locale operation. As long as only a single thread is so-converted, everything works fine, as all the other threads continue to ignore the global one, so only this thread looks at it.
However, on Windows systems this isn't quite true prior to Visual Studio 15, at which point Microsoft fixed a bug. A race can occur if you use the following operations on earlier Windows platforms:
The first item is not fixable (except by upgrading to a later Visual Studio release), but it would be possible to work around the latter two items by using the Windows API functions "GetNumberFormat" and "GetCurrencyFormat"; patches welcome.
Without this function call, threads that use the setlocale(3) system function will not work properly, as all the locale-sensitive functions will look at the per-thread locale, and "setlocale" will have no effect on this thread.
Perl code should convert to either call "Perl_setlocale" (which is a drop-in for the system "setlocale") or use the methods given in perlcall to call "POSIX::setlocale". Either one will transparently properly handle all cases of single- vs multi-thread, POSIX 2008-supported or not.
Non-Perl libraries, such as "gtk", that call the system "setlocale" can continue to work if this function is called before transferring control to the library.
Upon return from the code that needs to use the global locale, "sync_locale()" should be called to restore the safe multi-thread operation.
void switch_to_global_locale()
The return value is a boolean: TRUE if the global locale at the time of call was in effect; and FALSE if a per-thread locale was in effect. This can be used by the caller that needs to restore things as-they-were to decide whether or not to call "Perl_switch_to_global_locale".
bool sync_locale()
int mg_clear(SV* sv)
int mg_copy(SV *sv, SV *nsv, const char *key, I32 klen)
MAGIC* mg_find(const SV* sv, int type)
MAGIC* mg_findext(const SV* sv, int type, const MGVTBL *vtbl)
int mg_free(SV* sv)
"mg_freeext(sv, how, NULL)" is equivalent to "mg_free_type(sv, how)".
void mg_freeext(SV* sv, int how, const MGVTBL *vtbl)
void mg_free_type(SV *sv, int how)
int mg_get(SV* sv)
Reports on the SV's length in bytes, calling length magic if available, but does not set the UTF8 flag on "sv". It will fall back to 'get' magic if there is no 'length' magic, but with no indication as to whether it called 'get' magic. It assumes "sv" is a "PVMG" or higher. Use "sv_len()" instead.
U32 mg_length(SV* sv)
void mg_magical(SV* sv)
int mg_set(SV* sv)
void SvGETMAGIC(SV* sv)
void SvLOCK(SV* sv)
void SvSETMAGIC(SV* sv)
void SvSetMagicSV(SV* dsv, SV* ssv)
void SvSetMagicSV_nosteal(SV* dsv, SV* ssv)
void SvSetSV(SV* dsv, SV* ssv)
void SvSetSV_nosteal(SV* dsv, SV* ssv)
void SvSHARE(SV* sv)
If "tgtsv" is non-null then the string will be written into that SV (overwriting existing content) and it will be returned. If "tgtsv" is a null pointer then the string will be written into a new mortal SV which will be returned.
The message will be taken from whatever locale would be used by $!, and will be encoded in the SV in whatever manner would be used by $!. The details of this process are subject to future change. Currently, the message is taken from the C locale by default (usually producing an English message), and from the currently selected locale when in the scope of the "use locale" pragma. A heuristic attempt is made to decode the message from the locale's character encoding, but it will only be decoded as either UTF-8 or ISO-8859-1. It is always correctly decoded in a UTF-8 locale, usually in an ISO-8859-1 locale, and never in any other locale.
The SV is always returned containing an actual string, and with no other OK bits set.
SV * sv_string_from_errnum(int errnum, SV *tgtsv)
void SvUNLOCK(SV* sv)
void Copy(void* src, void* dest, int nitems, type)
void * CopyD(void* src, void* dest, int nitems, type)
void Move(void* src, void* dest, int nitems, type)
void * MoveD(void* src, void* dest, int nitems, type)
Memory obtained by this should ONLY be freed with "Safefree".
In 5.9.3, Newx() and friends replace the older New() API, and drops the first parameter, x, a debug aid which allowed callers to identify themselves. This aid has been superseded by a new build option, PERL_MEM_LOG (see "PERL_MEM_LOG" in perlhacktips). The older API is still there for use in XS modules supporting older perls.
void Newx(void* ptr, int nitems, type)
Memory obtained by this should ONLY be freed with "Safefree".
void Newxc(void* ptr, int nitems, type, cast)
Memory obtained by this should ONLY be freed with "Safefree".
void Newxz(void* ptr, int nitems, type)
void Poison(void* dest, int nitems, type)
void PoisonFree(void* dest, int nitems, type)
void PoisonNew(void* dest, int nitems, type)
void PoisonWith(void* dest, int nitems, type, U8 byte)
Memory obtained by this should ONLY be freed with "Safefree".
void Renew(void* ptr, int nitems, type)
Memory obtained by this should ONLY be freed with "Safefree".
void Renewc(void* ptr, int nitems, type, cast)
This should ONLY be used on memory obtained using "Newx" and friends.
void Safefree(void* ptr)
On some platforms, Windows for example, all allocated memory owned by a thread is deallocated when that thread ends. So if you need that not to happen, you need to use the shared memory functions, such as "savesharedpv".
char* savepv(const char* pv)
On some platforms, Windows for example, all allocated memory owned by a thread is deallocated when that thread ends. So if you need that not to happen, you need to use the shared memory functions, such as "savesharedpvn".
char* savepvn(const char* pv, I32 len)
char* savepvs("literal string" s)
char* savesharedpv(const char* pv)
char* savesharedpvn(const char *const pv, const STRLEN len)
char* savesharedpvs("literal string" s)
char* savesharedsvpv(SV *sv)
On some platforms, Windows for example, all allocated memory owned by a thread is deallocated when that thread ends. So if you need that not to happen, you need to use the shared memory functions, such as "savesharedsvpv".
char* savesvpv(SV* sv)
void StructCopy(type *src, type *dest, type)
void Zero(void* dest, int nitems, type)
void * ZeroD(void* dest, int nitems, type)
Returns true if a backtrace could be retrieved, false if not.
bool dump_c_backtrace(PerlIO* fp, int max_depth, int skip)
void fbm_compile(SV* sv, U32 flags)
char* fbm_instr(unsigned char* big, unsigned char* bigend, SV* littlestr, U32 flags)
I32 foldEQ(const char* a, const char* b, I32 len)
I32 foldEQ_locale(const char* a, const char* b, I32 len)
(char *) Perl_form(pTHX_ const char* pat, ...)
can be used any place a string (char *) is required:
char * s = Perl_form("%d.%d",major,minor);
Uses a single private buffer so if you want to format several strings you must explicitly copy the earlier strings away (and free the copies when you are done).
char* form(const char* pat, ...)
int getcwd_sv(SV* sv)
The appended output looks like:
... 1 10e004812:0082 Perl_croak util.c:1716 /usr/bin/perl 2 10df8d6d2:1d72 perl_parse perl.c:3975 /usr/bin/perl ...
The fields are tab-separated. The first column is the depth (zero being the innermost non-skipped frame). In the hex:offset, the hex is where the program counter was in "S_parse_body", and the :offset (might be missing) tells how much inside the "S_parse_body" the program counter was.
The "util.c:1716" is the source code file and line number.
The /usr/bin/perl is obvious (hopefully).
Unknowns are "-". Unknowns can happen unfortunately quite easily: if the platform doesn't support retrieving the information; if the binary is missing the debug information; if the optimizer has transformed the code by for example inlining.
SV* get_c_backtrace_dump(int max_depth, int skip)
I32 ibcmp(const char* a, const char* b, I32 len)
I32 ibcmp_locale(const char* a, const char* b, I32 len)
Return TRUE if the name is safe.
Used by the "IS_SAFE_SYSCALL()" macro.
bool is_safe_syscall(const char *pv, STRLEN len, const char *what, const char *op_name)
bool memEQ(char* s1, char* s2, STRLEN len)
bool memNE(char* s1, char* s2, STRLEN len)
Normally, the resulting message is returned in a new mortal SV. During global destruction a single SV may be shared between uses of this function.
SV * mess(const char *pat, ...)
"basemsg" is the initial message or object. If it is a reference, it will be used as-is and will be the result of this function. Otherwise it is used as a string, and if it already ends with a newline, it is taken to be complete, and the result of this function will be the same string. If the message does not end with a newline, then a segment such as "at foo.pl line 37" will be appended, and possibly other clauses indicating the current state of execution. The resulting message will end with a dot and a newline.
Normally, the resulting message is returned in a new mortal SV. During global destruction a single SV may be shared between uses of this function. If "consume" is true, then the function is permitted (but not required) to modify and return "basemsg" instead of allocating a new SV.
SV * mess_sv(SV *basemsg, bool consume)
int my_snprintf(char *buffer, const Size_t len, const char *format, ...)
"my_strlcat()" appends string "src" to the end of "dst". It will append at most "size - strlen(dst) - 1" characters. It will then "NUL"-terminate, unless "size" is 0 or the original "dst" string was longer than "size" (in practice this should not happen as it means that either "size" is incorrect or that "dst" is not a proper "NUL"-terminated string).
Note that "size" is the full size of the destination buffer and the result is guaranteed to be "NUL"-terminated if there is room. Note that room for the "NUL" should be included in "size".
The return value is the total length that "dst" would have if "size" is sufficiently large. Thus it is the initial length of "dst" plus the length of "src". If "size" is smaller than the return, the excess was not appended.
Size_t my_strlcat(char *dst, const char *src, Size_t size)
"my_strlcpy()" copies up to "size - 1" characters from the string "src" to "dst", "NUL"-terminating the result if "size" is not 0.
The return value is the total length "src" would be if the copy completely succeeded. If it is larger than "size", the excess was not copied.
Size_t my_strlcpy(char *dst, const char *src, Size_t size)
"my_strnlen()" computes the length of the string, up to "maxlen" characters. It will will never attempt to address more than "maxlen" characters, making it suitable for use with strings that are not guaranteed to be NUL-terminated.
Size_t my_strnlen(const char *str, Size_t maxlen)
int my_vsnprintf(char *buffer, const Size_t len, const char *format, va_list ap)
Another way of thinking about this function is finding a needle in a haystack. "big" points to the first byte in the haystack. "big_end" points to one byte beyond the final byte in the haystack. "little" points to the first byte in the needle. "little_end" points to one byte beyond the final byte in the needle. All the parameters must be non-"NULL".
The function returns "NULL" if there is no occurrence of "little" within "big". If "little" is the empty string, "big" is returned.
Because this function operates at the byte level, and because of the inherent characteristics of UTF-8 (or UTF-EBCDIC), it will work properly if both the needle and the haystack are strings with the same UTF-8ness, but not if the UTF-8ness differs.
char * ninstr(char * big, char * bigend, char * little, char * little_end)
void PERL_SYS_INIT(int *argc, char*** argv)
void PERL_SYS_INIT3(int *argc, char*** argv, char*** env)
void PERL_SYS_TERM()
The format specifier detection is not complete printf-syntax detection, but it should catch most common cases.
If true is returned, those arguments should in theory be processed with "quadmath_snprintf()", but in case there is more than one such format specifier (see "quadmath_format_single"), and if there is anything else beyond that one (even just a single byte), they cannot be processed because "quadmath_snprintf()" is very strict, accepting only one format spec, and nothing else. In this case, the code should probably fail.
bool quadmath_format_needed(const char* format)
"quadmath_format_single()" checks that the intended single spec looks sane: begins with "%", has only one "%", ends with "[efgaEFGA]", and has "Q" before it. This is not a full "printf syntax check", just the basics.
Returns the format if it is valid, NULL if not.
"quadmath_format_single()" can and will actually patch in the missing "Q", if necessary. In this case it will return the modified copy of the format, which the caller will need to free.
See also "quadmath_format_needed".
const char* quadmath_format_single(const char* format)
U8 READ_XDIGIT(char str*)
char * rninstr(char * big, char * bigend, char * little, char * little_end)
bool strEQ(char* s1, char* s2)
bool strGE(char* s1, char* s2)
bool strGT(char* s1, char* s2)
bool strLE(char* s1, char* s2)
bool strLT(char* s1, char* s2)
bool strNE(char* s1, char* s2)
bool strnEQ(char* s1, char* s2, STRLEN len)
bool strnNE(char* s1, char* s2, STRLEN len)
bool sv_destroyable(SV *sv)
void sv_nosharing(SV *sv)
Normally, the resulting message is returned in a new mortal SV. During global destruction a single SV may be shared between uses of this function.
SV * vmess(const char *pat, va_list *args)
You are responsible for "SvREFCNT_inc()" on the return value if you plan to store it anywhere semi-permanently (otherwise it might be deleted out from under you the next time the cache is invalidated).
AV* mro_get_linear_isa(HV* stash)
Ideally, all instances of "PL_sub_generation++" in perl source outside of mro.c should be replaced by calls to this.
Perl automatically handles most of the common ways a method might be redefined. However, there are a few ways you could change a method in a stash without the cache code noticing, in which case you need to call this method afterwards:
1) Directly manipulating the stash HV entries from XS code.
2) Assigning a reference to a readonly scalar constant into a stash entry in order to create a constant subroutine (like constant.pm does).
This same method is available from pure perl via, "mro::method_changed_in(classname)".
void mro_method_changed_in(HV* stash)
void mro_register(const struct mro_alg *mro)
dMULTICALL;
MULTICALL;
POP_MULTICALL;
PUSH_MULTICALL;
On entry "start" and *len give the string to scan, *flags gives conversion flags, and "result" should be "NULL" or a pointer to an NV. The scan stops at the end of the string, or the first invalid character. Unless "PERL_SCAN_SILENT_ILLDIGIT" is set in *flags, encountering an invalid character will also trigger a warning. On return *len is set to the length of the scanned string, and *flags gives output flags.
If the value is <= "UV_MAX" it is returned as a UV, the output flags are clear, and nothing is written to *result. If the value is > "UV_MAX", "grok_bin" returns "UV_MAX", sets "PERL_SCAN_GREATER_THAN_UV_MAX" in the output flags, and writes the value to *result (or the value is discarded if "result" is NULL).
The binary number may optionally be prefixed with "0b" or "b" unless "PERL_SCAN_DISALLOW_PREFIX" is set in *flags on entry. If "PERL_SCAN_ALLOW_UNDERSCORES" is set in *flags then the binary number may use "_" characters to separate digits.
UV grok_bin(const char* start, STRLEN* len_p, I32* flags, NV *result)
On entry "start" and *len_p give the string to scan, *flags gives conversion flags, and "result" should be "NULL" or a pointer to an NV. The scan stops at the end of the string, or the first invalid character. Unless "PERL_SCAN_SILENT_ILLDIGIT" is set in *flags, encountering an invalid character will also trigger a warning. On return *len is set to the length of the scanned string, and *flags gives output flags.
If the value is <= "UV_MAX" it is returned as a UV, the output flags are clear, and nothing is written to *result. If the value is > "UV_MAX", "grok_hex" returns "UV_MAX", sets "PERL_SCAN_GREATER_THAN_UV_MAX" in the output flags, and writes the value to *result (or the value is discarded if "result" is "NULL").
The hex number may optionally be prefixed with "0x" or "x" unless "PERL_SCAN_DISALLOW_PREFIX" is set in *flags on entry. If "PERL_SCAN_ALLOW_UNDERSCORES" is set in *flags then the hex number may use "_" characters to separate digits.
UV grok_hex(const char* start, STRLEN* len_p, I32* flags, NV *result)
IS_NUMBER_INFINITY IS_NUMBER_NAN IS_NUMBER_INFINITY | IS_NUMBER_NEG IS_NUMBER_NAN | IS_NUMBER_NEG 0
possibly |-ed with "IS_NUMBER_TRAILING".
If an infinity or a not-a-number is recognized, *sp will point to one byte past the end of the recognized string. If the recognition fails, zero is returned, and *sp will not move.
int grok_infnan(const char** sp, const char *send)
int grok_number(const char *pv, STRLEN len, UV *valuep)
If the value of the number can fit in a UV, it is returned in *valuep. "IS_NUMBER_IN_UV" will be set to indicate that *valuep is valid, "IS_NUMBER_IN_UV" will never be set unless *valuep is valid, but *valuep may have been assigned to during processing even though "IS_NUMBER_IN_UV" is not set on return. If "valuep" is "NULL", "IS_NUMBER_IN_UV" will be set for the same cases as when "valuep" is non-"NULL", but no actual assignment (or SEGV) will occur.
"IS_NUMBER_NOT_INT" will be set with "IS_NUMBER_IN_UV" if trailing decimals were seen (in which case *valuep gives the true value truncated to an integer), and "IS_NUMBER_NEG" if the number is negative (in which case *valuep holds the absolute value). "IS_NUMBER_IN_UV" is not set if e notation was used or the number is larger than a UV.
"flags" allows only "PERL_SCAN_TRAILING", which allows for trailing non-numeric text on an otherwise successful grok, setting "IS_NUMBER_TRAILING" on the result.
int grok_number_flags(const char *pv, STRLEN len, UV *valuep, U32 flags)
bool grok_numeric_radix(const char **sp, const char *send)
On entry "start" and *len give the string to scan, *flags gives conversion flags, and "result" should be "NULL" or a pointer to an NV. The scan stops at the end of the string, or the first invalid character. Unless "PERL_SCAN_SILENT_ILLDIGIT" is set in *flags, encountering an 8 or 9 will also trigger a warning. On return *len is set to the length of the scanned string, and *flags gives output flags.
If the value is <= "UV_MAX" it is returned as a UV, the output flags are clear, and nothing is written to *result. If the value is > "UV_MAX", "grok_oct" returns "UV_MAX", sets "PERL_SCAN_GREATER_THAN_UV_MAX" in the output flags, and writes the value to *result (or the value is discarded if "result" is "NULL").
If "PERL_SCAN_ALLOW_UNDERSCORES" is set in *flags then the octal number may use "_" characters to separate digits.
UV grok_oct(const char* start, STRLEN* len_p, I32* flags, NV *result)
This is also the logical inverse of Perl_isfinite().
bool isinfnan(NV nv)
It properly handles the locale radix character, meaning it expects a dot except when called from within the scope of "use locale", in which case the radix character should be that specified by the current locale.
The synonym Strod() may be used instead.
NV my_strtod(const char * const s, char ** e)
Return a non-zero integer if the sign bit on an NV is set, and 0 if it is not.
If Configure detects this system has a "signbit()" that will work with our NVs, then we just use it via the "#define" in perl.h. Otherwise, fall back on this implementation. The main use of this function is catching "-0.0".
"Configure" notes: This function is called 'Perl_signbit' instead of a plain 'signbit' because it is easy to imagine a system having a "signbit()" function or macro that doesn't happen to work with our particular choice of NVs. We shouldn't just re-"#define" "signbit" as "Perl_signbit" and expect the standard system headers to be happy. Also, this is a no-context function (no "pTHX_") because "Perl_signbit()" is usually re-"#defined" in perl.h as a simple macro call to the system's "signbit()". Users should just always call "Perl_signbit()".
int Perl_signbit(NV f)
NV scan_bin(const char* start, STRLEN len, STRLEN* retlen)
NV scan_hex(const char* start, STRLEN len, STRLEN* retlen)
NV scan_oct(const char* start, STRLEN len, STRLEN* retlen)
const char * custom_op_desc(const OP *o)
const char * custom_op_name(const OP *o)
GV* gv_fetchmethod(HV* stash, const char* name)
Tests if some arbitrary number of bytes begins in a valid UTF-8 character. Note that an INVARIANT (i.e. ASCII on non-EBCDIC machines) character is a valid UTF-8 character. The actual number of bytes in the UTF-8 character will be returned if it is valid, otherwise 0.
This function is deprecated due to the possibility that malformed input could cause reading beyond the end of the input buffer. Use "isUTF8_CHAR" instead.
STRLEN is_utf8_char(const U8 *s)
STRLEN is_utf8_char_buf(const U8 *buf, const U8 *buf_end)
void pack_cat(SV *cat, const char *pat, const char *patend, SV **beglist, SV **endlist, SV ***next_in_list, U32 flags)
HV * pad_compname_type(PADOFFSET po)
Usually accessed via the "SvPVbyte_nolen" macro.
char* sv_2pvbyte_nolen(SV* sv)
Usually accessed via the "SvPVutf8_nolen" macro.
char* sv_2pvutf8_nolen(SV* sv)
char* sv_2pv_nolen(SV* sv)
void sv_catpvn_mg(SV *sv, const char *ptr, STRLEN len)
void sv_catsv_mg(SV *dsv, SV *ssv)
void sv_force_normal(SV *sv)
IV sv_iv(SV* sv)
"Superseded" by "sv_nosharing()".
void sv_nolocking(SV *sv)
"Superseded" by "sv_nosharing()".
void sv_nounlocking(SV *sv)
NV sv_nv(SV* sv)
char* sv_pv(SV *sv)
char* sv_pvbyte(SV *sv)
char* sv_pvbyten(SV *sv, STRLEN *lp)
char* sv_pvn(SV *sv, STRLEN *lp)
char* sv_pvutf8(SV *sv)
char* sv_pvutf8n(SV *sv, STRLEN *lp)
void sv_taint(SV* sv)
void sv_unref(SV* sv)
void sv_usepvn(SV* sv, char* ptr, STRLEN len)
void sv_usepvn_mg(SV *sv, char *ptr, STRLEN len)
UV sv_uv(SV* sv)
SSize_t unpack_str(const char *pat, const char *patend, const char *s, const char *strbeg, const char *strend, char **new_s, I32 ocnt, U32 flags)
Returns the Unicode code point of the first character in the string "s" which is assumed to be in UTF-8 encoding; "retlen" will be set to the length, in bytes, of that character.
Some, but not all, UTF-8 malformations are detected, and in fact, some malformed input could cause reading beyond the end of the input buffer, which is one reason why this function is deprecated. The other is that only in extremely limited circumstances should the Unicode versus native code point be of any interest to you. See "utf8_to_uvuni_buf" for alternatives.
If "s" points to one of the detected malformations, and UTF8 warnings are enabled, zero is returned and *retlen is set (if "retlen" doesn't point to NULL) to -1. If those warnings are off, the computed value if well-defined (or the Unicode REPLACEMENT CHARACTER, if not) is silently returned, and *retlen is set (if "retlen" isn't NULL) so that ("s" + *retlen) is the next possible position in "s" that could begin a non-malformed character. See "utf8n_to_uvchr" for details on when the REPLACEMENT CHARACTER is returned.
UV utf8_to_uvuni(const U8 *s, STRLEN *retlen)
If "optype" is "OP_ANDASSIGN", "OP_ORASSIGN", or "OP_DORASSIGN", then a suitable conditional optree is constructed. If "optype" is the opcode of a binary operator, such as "OP_BIT_OR", then an op is constructed that performs the binary operation and assigns the result to the left argument. Either way, if "optype" is non-zero then "flags" has no effect.
If "optype" is zero, then a plain scalar or list assignment is constructed. Which type of assignment it is is automatically determined. "flags" gives the eight bits of "op_flags", except that "OPf_KIDS" will be set automatically, and, shifted up eight bits, the eight bits of "op_private", except that the bit with value 1 or 2 is automatically set as required.
OP * newASSIGNOP(I32 flags, OP *left, I32 optype, OP *right)
OP * newBINOP(I32 type, I32 flags, OP *first, OP *last)
OP * newCONDOP(I32 flags, OP *first, OP *trueop, OP *falseop)
OP * newDEFSVOP()
"sv" optionally supplies the variable that will be aliased to each item in turn; if null, it defaults to $_. "expr" supplies the list of values to iterate over. "block" supplies the main body of the loop, and "cont" optionally supplies a "continue" block that operates as a second half of the body. All of these optree inputs are consumed by this function and become part of the constructed op tree.
"flags" gives the eight bits of "op_flags" for the "leaveloop" op and, shifted up eight bits, the eight bits of "op_private" for the "leaveloop" op, except that (in both cases) some bits will be set automatically.
OP * newFOROP(I32 flags, OP *sv, OP *expr, OP *block, OP *cont)
OP * newGIVENOP(OP *cond, OP *block, PADOFFSET defsv_off)
OP * newGVOP(I32 type, I32 flags, GV *gv)
For most list operators, the check function expects all the kid ops to be present already, so calling "newLISTOP(OP_JOIN, ...)" (e.g.) is not appropriate. What you want to do in that case is create an op of type "OP_LIST", append more children to it, and then call "op_convert_list". See "op_convert_list" for more information.
OP * newLISTOP(I32 type, I32 flags, OP *first, OP *last)
OP * newLOGOP(I32 type, I32 flags, OP *first, OP *other)
OP * newLOOPEX(I32 type, OP *label)
OP * newLOOPOP(I32 flags, I32 debuggable, OP *expr, OP *block)
OP * newMETHOP(I32 type, I32 flags, OP *first)
OP * newMETHOP_named(I32 type, I32 flags, SV *const_meth)
OP * newNULLLIST()
OP * newOP(I32 type, I32 flags)
This function only exists if Perl has been compiled to use ithreads.
OP * newPADOP(I32 type, I32 flags, SV *sv)
OP * newPMOP(I32 type, I32 flags)
OP * newPVOP(I32 type, I32 flags, char *pv)
OP * newRANGE(I32 flags, OP *left, OP *right)
OP * newSLICEOP(I32 flags, OP *subscript, OP *listval)
If "o" is null, the state op is returned. Otherwise the state op is combined with "o" into a "lineseq" list op, which is returned. "o" is consumed by this function and becomes part of the returned op tree.
OP * newSTATEOP(I32 flags, char *label, OP *o)
OP * newSVOP(I32 type, I32 flags, SV *sv)
OP * newUNOP(I32 type, I32 flags, OP *first)
OP* newUNOP_AUX(I32 type, I32 flags, OP* first, UNOP_AUX_item *aux)
OP * newWHENOP(OP *cond, OP *block)
"loop" is an optional preconstructed "enterloop" op to use in the loop; if it is null then a suitable op will be constructed automatically. "expr" supplies the loop's controlling expression. "block" supplies the main body of the loop, and "cont" optionally supplies a "continue" block that operates as a second half of the body. All of these optree inputs are consumed by this function and become part of the constructed op tree.
"flags" gives the eight bits of "op_flags" for the "leaveloop" op and, shifted up eight bits, the eight bits of "op_private" for the "leaveloop" op, except that (in both cases) some bits will be set automatically. "debuggable" is currently unused and should always be 1. "has_my" can be supplied as true to force the loop body to be enclosed in its own scope.
OP * newWHILEOP(I32 flags, I32 debuggable, LOOP *loop, OP *expr, OP *block, OP *cont, I32 has_my)
Available only under threaded builds, this function allocates an entry in "PL_stashpad" for the stash passed to it.
PADOFFSET alloccopstash(HV *hv)
OP * block_end(I32 floor, OP *seq)
int block_start(int full)
OP * ck_entersub_args_list(OP *entersubop)
"protosv" supplies the subroutine prototype to be applied to the call. It may be a normal defined scalar, of which the string value will be used. Alternatively, for convenience, it may be a subroutine object (a "CV*" that has been cast to "SV*") which has a prototype. The prototype supplied, in whichever form, does not need to match the actual callee referenced by the op tree.
If the argument ops disagree with the prototype, for example by having an unacceptable number of arguments, a valid op tree is returned anyway. The error is reflected in the parser state, normally resulting in a single exception at the top level of parsing which covers all the compilation errors that occurred. In the error message, the callee is referred to by the name defined by the "namegv" parameter.
OP * ck_entersub_args_proto(OP *entersubop, GV *namegv, SV *protosv)
"protosv" supplies the subroutine prototype to be applied to the call, or indicates that there is no prototype. It may be a normal scalar, in which case if it is defined then the string value will be used as a prototype, and if it is undefined then there is no prototype. Alternatively, for convenience, it may be a subroutine object (a "CV*" that has been cast to "SV*"), of which the prototype will be used if it has one. The prototype (or lack thereof) supplied, in whichever form, does not need to match the actual callee referenced by the op tree.
If the argument ops disagree with the prototype, for example by having an unacceptable number of arguments, a valid op tree is returned anyway. The error is reflected in the parser state, normally resulting in a single exception at the top level of parsing which covers all the compilation errors that occurred. In the error message, the callee is referred to by the name defined by the "namegv" parameter.
OP * ck_entersub_args_proto_or_list(OP *entersubop, GV *namegv, SV *protosv)
Constant subs can be created with "newCONSTSUB" or as described in "Constant Functions" in perlsub.
SV* cv_const_sv(const CV *const cv)
void cv_get_call_checker(CV *cv, Perl_call_checker *ckfun_p, SV **ckobj_p)
The C-level function pointer is returned in *ckfun_p, an SV argument for it is returned in *ckobj_p, and control flags are returned in *ckflags_p. The function is intended to be called in this manner:
entersubop = (*ckfun_p)(aTHX_ entersubop, namegv, (*ckobj_p));
In this call, "entersubop" is a pointer to the "entersub" op, which may be replaced by the check function, and "namegv" supplies the name that should be used by the check function to refer to the callee of the "entersub" op if it needs to emit any diagnostics. It is permitted to apply the check function in non-standard situations, such as to a call to a different subroutine or to a method call.
"namegv" may not actually be a GV. If the "CALL_CHECKER_REQUIRE_GV" bit is clear in *ckflags_p, it is permitted to pass a CV or other SV instead, anything that can be used as the first argument to "cv_name". If the "CALL_CHECKER_REQUIRE_GV" bit is set in *ckflags_p then the check function requires "namegv" to be a genuine GV.
By default, the check function is Perl_ck_entersub_args_proto_or_list, the SV parameter is "cv" itself, and the "CALL_CHECKER_REQUIRE_GV" flag is clear. This implements standard prototype processing. It can be changed, for a particular subroutine, by "cv_set_call_checker_flags".
If the "CALL_CHECKER_REQUIRE_GV" bit is set in "gflags" then it indicates that the caller only knows about the genuine GV version of "namegv", and accordingly the corresponding bit will always be set in *ckflags_p, regardless of the check function's recorded requirements. If the "CALL_CHECKER_REQUIRE_GV" bit is clear in "gflags" then it indicates the caller knows about the possibility of passing something other than a GV as "namegv", and accordingly the corresponding bit may be either set or clear in *ckflags_p, indicating the check function's recorded requirements.
"gflags" is a bitset passed into "cv_get_call_checker_flags", in which only the "CALL_CHECKER_REQUIRE_GV" bit currently has a defined meaning (for which see above). All other bits should be clear.
void cv_get_call_checker_flags( CV *cv, U32 gflags, Perl_call_checker *ckfun_p, SV **ckobj_p, U32 *ckflags_p )
void cv_set_call_checker(CV *cv, Perl_call_checker ckfun, SV *ckobj)
The C-level function pointer is supplied in "ckfun", an SV argument for it is supplied in "ckobj", and control flags are supplied in "ckflags". The function should be defined like this:
STATIC OP * ckfun(pTHX_ OP *op, GV *namegv, SV *ckobj)
It is intended to be called in this manner:
entersubop = ckfun(aTHX_ entersubop, namegv, ckobj);
In this call, "entersubop" is a pointer to the "entersub" op, which may be replaced by the check function, and "namegv" supplies the name that should be used by the check function to refer to the callee of the "entersub" op if it needs to emit any diagnostics. It is permitted to apply the check function in non-standard situations, such as to a call to a different subroutine or to a method call.
"namegv" may not actually be a GV. For efficiency, perl may pass a CV or other SV instead. Whatever is passed can be used as the first argument to "cv_name". You can force perl to pass a GV by including "CALL_CHECKER_REQUIRE_GV" in the "ckflags".
"ckflags" is a bitset, in which only the "CALL_CHECKER_REQUIRE_GV" bit currently has a defined meaning (for which see above). All other bits should be clear.
The current setting for a particular CV can be retrieved by "cv_get_call_checker_flags".
void cv_set_call_checker_flags( CV *cv, Perl_call_checker ckfun, SV *ckobj, U32 ckflags )
OP* LINKLIST(OP *o)
CV * newCONSTSUB(HV *stash, const char *name, SV *sv)
The subroutine will have an empty prototype and will ignore any arguments when called. Its constant behaviour is determined by "sv". If "sv" is null, the subroutine will yield an empty list. If "sv" points to a scalar, the subroutine will always yield that scalar. If "sv" points to an array, the subroutine will always yield a list of the elements of that array in list context, or the number of elements in the array in scalar context. This function takes ownership of one counted reference to the scalar or array, and will arrange for the object to live as long as the subroutine does. If "sv" points to a scalar then the inlining assumes that the value of the scalar will never change, so the caller must ensure that the scalar is not subsequently written to. If "sv" points to an array then no such assumption is made, so it is ostensibly safe to mutate the array or its elements, but whether this is really supported has not been determined.
The subroutine will have "CvFILE" set according to "PL_curcop". Other aspects of the subroutine will be left in their default state. The caller is free to mutate the subroutine beyond its initial state after this function has returned.
If "name" is null then the subroutine will be anonymous, with its "CvGV" referring to an "__ANON__" glob. If "name" is non-null then the subroutine will be named accordingly, referenced by the appropriate glob. "name" is a string of length "len" bytes giving a sigilless symbol name, in UTF-8 if "flags" has the "SVf_UTF8" bit set and in Latin-1 otherwise. The name may be either qualified or unqualified. If the name is unqualified then it defaults to being in the stash specified by "stash" if that is non-null, or to "PL_curstash" if "stash" is null. The symbol is always added to the stash if necessary, with "GV_ADDMULTI" semantics.
"flags" should not have bits set other than "SVf_UTF8".
If there is already a subroutine of the specified name, then the new sub will replace the existing one in the glob. A warning may be generated about the redefinition.
If the subroutine has one of a few special names, such as "BEGIN" or "END", then it will be claimed by the appropriate queue for automatic running of phase-related subroutines. In this case the relevant glob will be left not containing any subroutine, even if it did contain one before. Execution of the subroutine will likely be a no-op, unless "sv" was a tied array or the caller modified the subroutine in some interesting way before it was executed. In the case of "BEGIN", the treatment is buggy: the sub will be executed when only half built, and may be deleted prematurely, possibly causing a crash.
The function returns a pointer to the constructed subroutine. If the sub is anonymous then ownership of one counted reference to the subroutine is transferred to the caller. If the sub is named then the caller does not get ownership of a reference. In most such cases, where the sub has a non-phase name, the sub will be alive at the point it is returned by virtue of being contained in the glob that names it. A phase-named subroutine will usually be alive by virtue of the reference owned by the phase's automatic run queue. A "BEGIN" subroutine may have been destroyed already by the time this function returns, but currently bugs occur in that case before the caller gets control. It is the caller's responsibility to ensure that it knows which of these situations applies.
CV * newCONSTSUB_flags(HV *stash, const char *name, STRLEN len, U32 flags, SV *sv)
OP * op_append_elem(I32 optype, OP *first, OP *last)
OP * op_append_list(I32 optype, OP *first, OP *last)
For custom ops the type is returned from the registration, and it is up to the registree to ensure it is accurate. The value returned will be one of the "OA_"* constants from op.h.
U32 OP_CLASS(OP *o)
OP * op_contextualize(OP *o, I32 context)
A list-type op is usually constructed one kid at a time via "newLISTOP", "op_prepend_elem" and "op_append_elem". Then finally it is passed to "op_convert_list" to make it the right type.
OP * op_convert_list(I32 type, I32 flags, OP *o)
const char * OP_DESC(OP *o)
void op_free(OP *o)
bool OpHAS_SIBLING(OP *o)
void OpLASTSIB_set(OP *o, OP *parent)
OP* op_linklist(OP *o)
Propagate lvalue ("modifiable") context to an op and its children. "type" represents the context type, roughly based on the type of op that would do the modifying, although "local()" is represented by "OP_NULL", because it has no op type of its own (it is signalled by a flag on the lvalue op).
This function detects things that can't be modified, such as "$x+1", and generates errors for them. For example, "$x+1 = 2" would cause it to be called with an op of type "OP_ADD" and a "type" argument of "OP_SASSIGN".
It also flags things that need to behave specially in an lvalue context, such as "$$x = 5" which might have to vivify a reference in $x.
OP * op_lvalue(OP *o, I32 type)
void OpMAYBESIB_set(OP *o, OP *sib, OP *parent)
void OpMORESIB_set(OP *o, OP *sib)
const char * OP_NAME(OP *o)
void op_null(OP *o)
OP* op_parent(OP *o)
OP * op_prepend_elem(I32 optype, OP *first, OP *last)
Wraps up an op tree with some additional ops so that at runtime a dynamic scope will be created. The original ops run in the new dynamic scope, and then, provided that they exit normally, the scope will be unwound. The additional ops used to create and unwind the dynamic scope will normally be an "enter"/"leave" pair, but a "scope" op may be used instead if the ops are simple enough to not need the full dynamic scope structure.
OP * op_scope(OP *o)
OP* OpSIBLING(OP *o)
Note that op_next is not manipulated, and nodes are not freed; that is the responsibility of the caller. It also won't create a new list op for an empty list etc; use higher-level functions like op_append_elem() for that.
"parent" is the parent node of the sibling chain. It may passed as "NULL" if the splicing doesn't affect the first or last op in the chain.
"start" is the node preceding the first node to be spliced. Node(s) following it will be deleted, and ops will be inserted after it. If it is "NULL", the first node onwards is deleted, and nodes are inserted at the beginning.
"del_count" is the number of nodes to delete. If zero, no nodes are deleted. If -1 or greater than or equal to the number of remaining kids, all remaining kids are deleted.
"insert" is the first of a chain of nodes to be inserted in place of the nodes. If "NULL", no nodes are inserted.
The head of the chain of deleted ops is returned, or "NULL" if no ops were deleted.
For example:
action before after returns ------ ----- ----- ------- P P splice(P, A, 2, X-Y-Z) | | B-C A-B-C-D A-X-Y-Z-D P P splice(P, NULL, 1, X-Y) | | A A-B-C-D X-Y-B-C-D P P splice(P, NULL, 3, NULL) | | A-B-C A-B-C-D D P P splice(P, B, 0, X-Y) | | NULL A-B-C-D A-B-X-Y-C-D
For lower-level direct manipulation of "op_sibparent" and "op_moresib", see "OpMORESIB_set", "OpLASTSIB_set", "OpMAYBESIB_set".
OP* op_sibling_splice(OP *parent, OP *start, int del_count, OP* insert)
The negation of this macro, "OP_TYPE_ISNT" is also available as well as "OP_TYPE_IS_NN" and "OP_TYPE_ISNT_NN" which elide the NULL pointer check.
bool OP_TYPE_IS(OP *o, Optype type)
The negation of this macro, "OP_TYPE_ISNT_AND_WASNT" is also available as well as "OP_TYPE_IS_OR_WAS_NN" and "OP_TYPE_ISNT_AND_WASNT_NN" which elide the "NULL" pointer check.
bool OP_TYPE_IS_OR_WAS(OP *o, Optype type)