NAME
perlintern - autogenerated documentation of purely iinntteerrnnaall
Perl functionsDESCRIPTION
This file is the autogenerated documentation of functions in the Perl interpreter that are documented using Perl's internal documentation format but are not marked as part of the Perl API. In other words, tthheeyy aarree nnoott ffoorr uussee iinn eexxtteennssiioonnss! CCVV rreeffeerreennccee ccoouunnttss aanndd CCvvOOUUTTSSIIDDEE CvWEAKOUTSIDEEach CV has a pointer, "CvOUTSIDE()", to its lexically enclos-
ing CV (if any). Because pointers to anonymous sub prototypes are stored in "&" pad slots, it is a possible to get a circular reference, with the parent pointing to the child andvice-versa. To avoid the ensuing memory leak, we do not incre-
ment the reference count of the CV pointed to by "CvOUTSIDE" in the one specific instance that the parent has a "&" pad slot pointing back to us. In this case, we set the "CvWEAKOUTSIDE"flag in the child. This allows us to determine under what cir-
cumstances we should decrement the refcount of the parent when freeing the child.There is a further complication with non-closure anonymous subs
(ie those that do not refer to any lexicals outside that sub). In this case, the anonymous prototype is shared rather than being cloned. This has the consequence that the parent may be freed while there are still active children, egBEGIN { $a = sub { eval '$x' } }
In this case, the BEGIN is freed immediately after executionsince there are no active references to it: the anon sub proto-
type has "CvWEAKOUTSIDE" set since it's not a closure, and $a
points to the same CV, so it doesn't contribute to BEGIN's ref-
count either. When $a is executed, the "eval '$x'" causes the
chain of "CvOUTSIDE"s to be followed, and the freed BEGIN is accessed. To avoid this, whenever a CV and its associated pad is freed, any "&" entries in the pad are explicitly removed from the pad,and if the refcount of the pointed-to anon sub is still posi-
tive, then that child's "CvOUTSIDE" is set to point to its grandparent. This will only occur in the single specific caseof a non-closure anon prototype having one or more active ref-
erences (such as $a above).
One other thing to consider is that a CV may be merely unde-
fined rather than freed, eg "undef &foo". In this case, its refcount may not have reached zero, but we still delete its pad and its "CvROOT" etc. Since various children may still have their "CvOUTSIDE" pointing at this undefined CV, we keep itsown "CvOUTSIDE" for the time being, so that the chain of lexi-
cal scopes is unbroken. For example, the following should print 123:my $x = 123;
sub tmp { sub { eval '$x' } }
my $a = tmp();
undef &tmp;print $a->();
bool CvWEAKOUTSIDE(CV *cv) FFuunnccttiioonnss iinn ffiillee ppaadd..hh CXCURPADSAVE Save the current pad in the given context block structure. void CXCURPADSAVE(struct context) CXCURPADSV Access the SV at offset po in the saved current pad in the given context block structure (can be used as an lvalue). SV * CXCURPADSV(struct context, PADOFFSET po) PADBASESV Get the value from slot "po" in the base (DEPTH=1) pad of a padlist SV * PADBASESV (PADLIST padlist, PADOFFSET po) PADCLONEVARS |CLONEPARAMS* param Clone the state variables associated with running and compiling pads. void PADCLONEVARS(PerlInterpreter *protoperl \)PADCOMPNAMEFLAGS
Return the flags for the current compiling pad name at offset "po". Assumes a valid slot entry.U32 PADCOMPNAMEFLAGS(PADOFFSET po)
PADCOMPNAMEGEN
The generation number of the name at offset "po" in the current compiling pad (lvalue). Note that "SvCUR" is hijacked for this purpose.STRLEN PADCOMPNAMEGEN(PADOFFSET po)
PADCOMPNAMEOURSTASH
Return the stash associated with an "our" variable. Assumes the slot entry is a valid "our" lexical.HV * PADCOMPNAMEOURSTASH(PADOFFSET po)
PADCOMPNAMEPV
Return the name of the current compiling pad name at offset "po". Assumes a valid slot entry.char * PADCOMPNAMEPV(PADOFFSET po)
PADCOMPNAMETYPE
Return the type (stash) of the current compiling pad name at offset "po". Must be a valid name. Returns null if not typed.HV * PADCOMPNAMETYPE(PADOFFSET po)
PADDUP Clone a padlist. void PADDUP(PADLIST dstpad, PADLIST srcpad, CLONEPARAMS* param) PADRESTORELOCAL Restore the old pad saved into the local variable opad by PADSAVELOCAL() void PADRESTORELOCAL(PAD *opad) PADSAVELOCAL Save the current pad to the local variable opad, then make the current pad equal to npad void PADSAVELOCAL(PAD *opad, PAD *npad) PADSAVESETNULLPAD Save the current pad then set it to null. void PADSAVESETNULLPAD() PADSETSV Set the slot at offset "po" in the current pad to "sv" SV * PADSETSV (PADOFFSET po, SV* sv) PADSETCUR Set the current pad to be pad "n" in the padlist, saving the previous current pad. void PADSETCUR (PADLIST padlist, I32 n) PADSETCURNOSAVE like PADSETCUR, but without the save void PADSETCURNOSAVE (PADLIST padlist, I32 n) PADSV Get the value at offset "po" in the current pad void PADSV (PADOFFSET po) PADSVl Lightweight and lvalue version of "PADSV". Get or set the value at offset "po" in the current pad. Unlike "PADSV", doesnot print diagnostics with -DX. For internal use only.
SV * PADSVl (PADOFFSET po) SAVECLEARSV Clear the pointed to pad value on scope exit. (ie the runtime action of 'my') void SAVECLEARSV (SV **svp) SAVECOMPPAD save PLcomppad and PLcurpad void SAVECOMPPAD() SAVEPADSV Save a pad slot (used to restore after an iteration) XXX DAPM it would make more sense to make the arg a PADOFFSET void SAVEPADSV (PADOFFSET po) FFuunnccttiioonnss iinn ffiillee ppppccttll..cc findruncv Locate the CV corresponding to the currently executing sub or eval. If dbseqp is nonnull, skip CVs that are in the DB package and populate *dbseqp with the cop sequence number at the point that the DB:: code was entered. (allows debuggers to eval in the scope of the breakpoint rather than in in the scope of the debugger itself). CV* findruncv(U32 *dbseqp) GGlloobbaall VVaarriiaabblleess PLDBsingleWhen Perl is run in debugging mode, with the -dd switch, this SV
is a boolean which indicates whether subs are being sin-
gle-stepped. Single-stepping is automatically turned on after
every step. This is the C variable which corresponds to Perl's$DB::single variable. See "PLDBsub".
SV * PLDBsingle PLDBsubWhen Perl is run in debugging mode, with the -dd switch, this GV
contains the SV which holds the name of the sub being debugged.This is the C variable which corresponds to Perl's $DB::sub
variable. See "PLDBsingle". GV * PLDBsub PLDBtrace Trace variable used when Perl is run in debugging mode, withthe -dd switch. This is the C variable which corresponds to
Perl's $DB::trace variable. See "PLDBsingle".
SV * PLDBtrace PLdowarnThe C variable which corresponds to Perl's $^W warning vari-
able. bool PLdowarn PLlastingv The GV which was last used for a filehandle input operation. ("") GV* PLlastingv PLofssv The output field separator - $, in Perl space.
SV* PLofssvPLrs The input record separator - $/ in Perl space.
SV* PLrs GGVV FFuunnccttiioonnss isgvmagical Returns "TRUE" if given the name of a magical GV. Currently only useful internally when determining if a GV should be created even in rvalue contexts."flags" is not used at present but available for future exten-
sion to allow selecting particular classes of magical variable. bool isgvmagical(char *name, STRLEN len, U32 flags) IIOO FFuunnccttiioonnss startglob Function called by "doreadline" to spawn a glob (or do the glob inside perl on VMS). This code used to be inline, but now perl uses "File::Glob" this glob starter is only used by miniperl during the build process. Moving it away shrinks pphot.c; shrinking pphot.c helps speed perl up. PerlIO* startglob(SV* pattern, IO *io) PPaadd DDaattaa SSttrruuccttuurreess CvPADLIST CV's can have CvPADLIST(cv) set to point to an AV.For these purposes "forms" are a kind-of CV, eval""s are too
(except they're not callable at will and are always thrown away after the eval"" is done executing).XSUBs don't have CvPADLIST set - dXSTARG fetches values from
PLcurpad, but that is really the callers pad (a slot of which is allocated by every entersub). The CvPADLIST AV has does not have AvREAL set, so REFCNT of component items is managed "manual" (mostly in pad.c) rather than normal av.c rules. The items in the AV are not SVs as for a normal AV, but other AVs: 0'th Entry of the CvPADLIST is an AV which represents the "names" or rather the "static type information" for lexicals. The CvDEPTH'th entry of CvPADLIST AV is an AV which is the stack frame at that depth of recursion into the CV. The 0'th slot of a frame AV is an AV which is @. other entries are storage for variables and op targets. During compilation: "PLcomppadname" is set to the names AV. "PLcomppad" is set to the frame AV for the frame CvDEPTH == 1."PLcurpad" is set to the body of the frame AV (i.e. AvAR-
RAY(PLcomppad)). During execution, "PLcomppad" and "PLcurpad" refer to the live frame of the currently executing sub. Iterating over the names AV iterates over all possible pad items. Pad slots that are SVsPADTMP (targets/GVs/constants) end up having &PLsvundef "names" (see padalloc()). Only my/our variable (SVsPADMY/SVsPADOUR) slots get validnames. The rest are op targets/GVs/constants which are stati-
cally allocated or resolved at compile time. These don't have names by which they can be looked up from Perl code at run time through eval"" like my/our variables can be. Since they can't be looked up by "name" but only by their index allocated atcompile time (which is usually in PLop->optarg), wasting a
name SV for them doesn't make sense. The SVs in the names AV have their PV being the name of the variable. NV+1..IV inclusive is a range of copseq numbers for which the name is valid. For typed lexicals name SV is SVtPVMG and SvSTASH points at the type. For "our" lexicals, the type is SVtPVGV, and GvSTASH points at the stash of the associated global (so that duplicate "our" delarations in the same package can be detected). SvCUR is sometimes hijacked to store the generation number during compilation. If SvFAKE is set on the name SV then slot in the frame AVs are a REFCNT'ed references to a lexical from "outside". In this case, the name SV does not have a copseq range, since it is in scope throughout. If the 'name' is '&' the corresponding entry in frame AV is a CV representing a possible closure. (SvFAKE and name of '&' is not a meaningful combination currently but could become so if "my sub foo {}" is implemented.) The flag SVfPADSTALE is cleared on lexicals each time the my() is executed, and set on scope exit. This allows the 'Variable$x is not available' warning to be generated in evals, such as
{ my $x = 1; sub f { eval '$x'} } f();
AV * CvPADLIST(CV *cv) cvclone Clone a CV: make a new CV which points to the same code etc,but which has a newly-created pad built by copying the proto-
type pad and capturing any outer lexicals. CV* cvclone(CV* proto) cvdump dump the contents of a CV void cvdump(CV *cv, char *title) dodumppad Dump the contents of a padlist void dodumppad(I32 level, PerlIO *file, PADLIST *padlist, int full) intromy "Introduce" my variables to visible status. U32 intromy() padaddanon Add an anon code entry to the current compiling pad PADOFFSET padaddanon(SV* sv, OPCODE optype) padaddname Create a new name in the current pad at the specified offset. If "typestash" is valid, the name is for a typed lexical; set the name's stash to that value. If "ourstash" is valid, it's an our lexical, set the name's GvSTASH to that valueAlso, if the name is @.. or %.., create a new array or hash for
that slot If fake, it means we're cloning an existing entry PADOFFSET padaddname(char *name, HV* typestash, HV* ourstash, bool clone) padalloc Allocate a new my or tmp pad entry. For a my, simply push a null SV onto the end of PLcomppad, but for a tmp, scan the pad from PLpadix upwards for a slot which has no name and and no active value. PADOFFSET padalloc(I32 optype, U32 tmptype) padblockstart Update the pad compilation state variables on entry to a new block void padblockstart(int full) padcheckdup Check for duplicate declarations: report any of: * a my in the current scope with the same name; * an our (anywhere in the pad) with the same name and the same stash as "ourstash" "isour" indicates that the name to check is an 'our' declaration void padcheckdup(char* name, bool isour, HV* ourstash) padfindlex Find a named lexical anywhere in a chain of nested pads. Add fake entries in the inner pads if it's found in an outer one. innercv is the CV *inside* the chain of outer CVs to besearched. If newoff is non-null, this is a run-time cloning:
don't add fake entries, just find the lexical and add a ref to it at newoff in the current pad. PADOFFSET padfindlex(char* name, PADOFFSET newoff, CV* innercv) padfindmyGiven a lexical name, try to find its offset, first in the cur-
rent pad, or failing that, in the pads of any lexically enclos-
ing subs (including the complications introduced by eval). If the name is found in an outer pad, then a fake entry is added to the current pad. Returns the offset in the current pad, or NOTINPAD on failure. PADOFFSET padfindmy(char* name) padfixupinneranons For any anon CVs in the pad, change CvOUTSIDE of that CV fromoldcv to newcv if necessary. Needed when a newly-compiled CV
has to be moved to a pre-existing CV struct.
void padfixupinneranons(PADLIST *padlist, CV *oldcv, CV *newcv) padfree Free the SV at offet po in the current pad. void padfree(PADOFFSET po) padleavemy Cleanup at end of scope during compilation: set the max seq number for lexicals in this scope and warn of any lexicals that never got introduced. void padleavemy() padnew Create a new compiling padlist, saving and updating the various global vars at the same time as creating the pad itself. The following flags can be OR'ed together: padnewCLONE this pad is for a cloned CV padnewSAVE save old globals padnewSAVESUB also save extra stuff for start of sub PADLIST* padnew(int flags) padpush Push a new pad frame onto the padlist, unless there's already a pad at this depth, in which case don't bother creating a new one. If hasargs is true, give the new pad an @ in slot zero. void padpush(PADLIST *padlist, int depth, int hasargs) padreset Mark all the current temporaries for reuse void padreset() padsetsv Set the entry at offset po in the current pad to sv. Use the macro PADSETSV() rather than calling this function directly. void padsetsv(PADOFFSET po, SV* sv) padswipe Abandon the tmp in the current pad at offset po and replace with a new one. void padswipe(PADOFFSET po, bool refadjust) padtidy Tidy up a pad after we've finished compiling it: * remove most stuff from the pads of anonsub prototypes; * give it a @; * mark tmps as such. void padtidy(padtidytype type) padundef Free the padlist associated with a CV. If parts of it happen to be current, we null the relevant PL*pad* global vars so that we don't have any dangling references left. We alsorepoint the CvOUTSIDE of any about-to-be-orphaned inner subs to
the outer of this cv. (This function should really be called padfree, but the name was already taken) void padundef(CV* cv) SSttaacckk MMaanniippuullaattiioonn MMaaccrrooss djSP Declare Just "SP". This is actually identical to "dSP", and declares a local copy of perl's stack pointer, available via the "SP" macro. See "SP". (Available for backward source code compatibility with the old (Perl 5.005) thread model.) djSP;LVRET True if this op will be the return value of an lvalue subrou-
tine SSVV MMaanniippuullaattiioonn FFuunnccttiioonnss reportuninit Print appropriate "Use of uninitialized variable" warning void reportuninit() svaddarena Given a chunk of memory, link it to the head of the list of arenas, and split it into a list of free SVs. void svaddarena(char* ptr, U32 size, U32 flags) svcleanall Decrement the refcnt of each remaining SV, possibly triggering a cleanup. This function may have to be called multiple timesto free SVs which are in complex self-referential hierarchies.
I32 svcleanall() svcleanobjs Attempt to destroy all objects not yet freed void svcleanobjs() svfreearenas Deallocate the memory used by all arenas. Note that all the individual SV heads and bodies within the arenas must already have been freed. void svfreearenas() AUTHORS The autodocumentation system was originally added to the Perl core by Benjamin Stuhl. Documentation is by whoever was kind enough to document their functions.SEE ALSO
perlguts(1), perlapi(1)perl v5.8.6 2004-11-05 PERLINTERN(1)