1N/A/* pad.h
1N/A *
1N/A * Copyright (C) 2002, by Larry Wall and others
1N/A *
1N/A * You may distribute under the terms of either the GNU General Public
1N/A * License or the Artistic License, as specified in the README file.
1N/A *
1N/A * This file defines the types and macros associated with the API for
1N/A * manipulating scratchpads, which are used by perl to store lexical
1N/A * variables, op targets and constants.
1N/A */
1N/A
1N/A
1N/A
1N/A
1N/A/* a padlist is currently just an AV; but that might change,
1N/A * so hide the type. Ditto a pad. */
1N/A
1N/Atypedef AV PADLIST;
1N/Atypedef AV PAD;
1N/A
1N/A
1N/A/* offsets within a pad */
1N/A
1N/A#if PTRSIZE == 4
1N/Atypedef U32TYPE PADOFFSET;
1N/A#else
1N/A# if PTRSIZE == 8
1N/Atypedef U64TYPE PADOFFSET;
1N/A# endif
1N/A#endif
1N/A#define NOT_IN_PAD ((PADOFFSET) -1)
1N/A
1N/A
1N/A/* flags for the pad_new() function */
1N/A
1N/A#define padnew_CLONE 1 /* this pad is for a cloned CV */
1N/A#define padnew_SAVE 2 /* save old globals */
1N/A#define padnew_SAVESUB 4 /* also save extra stuff for start of sub */
1N/A
1N/A/* values for the pad_tidy() function */
1N/A
1N/Atypedef enum {
1N/A padtidy_SUB, /* tidy up a pad for a sub, */
1N/A padtidy_SUBCLONE, /* a cloned sub, */
1N/A padtidy_FORMAT /* or a format */
1N/A} padtidy_type;
1N/A
1N/A/* ASSERT_CURPAD_LEGAL and ASSERT_CURPAD_ACTIVE respectively determine
1N/A * whether PL_comppad and PL_curpad are consistent and whether they have
1N/A * active values */
1N/A
1N/A#ifdef DEBUGGING
1N/A# define ASSERT_CURPAD_LEGAL(label) \
1N/A if (PL_comppad ? (AvARRAY(PL_comppad) != PL_curpad) : (PL_curpad != 0)) \
1N/A Perl_croak(aTHX_ "panic: illegal pad in %s: 0x%"UVxf"[0x%"UVxf"]",\
1N/A label, PTR2UV(PL_comppad), PTR2UV(PL_curpad));
1N/A
1N/A
1N/A# define ASSERT_CURPAD_ACTIVE(label) \
1N/A if (!PL_comppad || (AvARRAY(PL_comppad) != PL_curpad)) \
1N/A Perl_croak(aTHX_ "panic: invalid pad in %s: 0x%"UVxf"[0x%"UVxf"]",\
1N/A label, PTR2UV(PL_comppad), PTR2UV(PL_curpad));
1N/A#else
1N/A# define ASSERT_CURPAD_LEGAL(label)
1N/A# define ASSERT_CURPAD_ACTIVE(label)
1N/A#endif
1N/A
1N/A
1N/A
1N/A/* Note: the following three macros are actually defined in scope.h, but
1N/A * they are documented here for completeness, since they directly or
1N/A * indirectly affect pads.
1N/A
1N/A=for apidoc m|void|SAVEPADSV |PADOFFSET po
1N/ASave a pad slot (used to restore after an iteration)
1N/A
1N/AXXX DAPM it would make more sense to make the arg a PADOFFSET
1N/A=for apidoc m|void|SAVECLEARSV |SV **svp
1N/AClear the pointed to pad value on scope exit. (ie the runtime action of 'my')
1N/A
1N/A=for apidoc m|void|SAVECOMPPAD
1N/Asave PL_comppad and PL_curpad
1N/A
1N/A
1N/A
1N/A
1N/A
1N/A=for apidoc m|SV *|PAD_SETSV |PADOFFSET po|SV* sv
1N/ASet the slot at offset C<po> in the current pad to C<sv>
1N/A
1N/A=for apidoc m|void|PAD_SV |PADOFFSET po
1N/AGet the value at offset C<po> in the current pad
1N/A
1N/A=for apidoc m|SV *|PAD_SVl |PADOFFSET po
1N/ALightweight and lvalue version of C<PAD_SV>.
1N/AGet or set the value at offset C<po> in the current pad.
1N/AUnlike C<PAD_SV>, does not print diagnostics with -DX.
1N/AFor internal use only.
1N/A
1N/A=for apidoc m|SV *|PAD_BASE_SV |PADLIST padlist|PADOFFSET po
1N/AGet the value from slot C<po> in the base (DEPTH=1) pad of a padlist
1N/A
1N/A=for apidoc m|void|PAD_SET_CUR |PADLIST padlist|I32 n
1N/ASet the current pad to be pad C<n> in the padlist, saving
1N/Athe previous current pad.
1N/A
1N/A=for apidoc m|void|PAD_SET_CUR_NOSAVE |PADLIST padlist|I32 n
1N/Alike PAD_SET_CUR, but without the save
1N/A
1N/A=for apidoc m|void|PAD_SAVE_SETNULLPAD
1N/ASave the current pad then set it to null.
1N/A
1N/A=for apidoc m|void|PAD_SAVE_LOCAL|PAD *opad|PAD *npad
1N/ASave the current pad to the local variable opad, then make the
1N/Acurrent pad equal to npad
1N/A
1N/A=for apidoc m|void|PAD_RESTORE_LOCAL|PAD *opad
1N/ARestore the old pad saved into the local variable opad by PAD_SAVE_LOCAL()
1N/A
1N/A=cut
1N/A*/
1N/A
1N/A#ifdef DEBUGGING
1N/A# define PAD_SV(po) pad_sv(po)
1N/A# define PAD_SETSV(po,sv) pad_setsv(po,sv)
1N/A#else
1N/A# define PAD_SV(po) (PL_curpad[po])
1N/A# define PAD_SETSV(po,sv) PL_curpad[po] = (sv)
1N/A#endif
1N/A
1N/A#define PAD_SVl(po) (PL_curpad[po])
1N/A
1N/A#define PAD_BASE_SV(padlist, po) \
1N/A (AvARRAY(padlist)[1]) \
1N/A ? AvARRAY((AV*)(AvARRAY(padlist)[1]))[po] : Nullsv;
1N/A
1N/A
1N/A#define PAD_SET_CUR_NOSAVE(padlist,n) \
1N/A PL_comppad = (PAD*) (AvARRAY(padlist)[n]); \
1N/A PL_curpad = AvARRAY(PL_comppad); \
1N/A DEBUG_Xv(PerlIO_printf(Perl_debug_log, \
1N/A "Pad 0x%"UVxf"[0x%"UVxf"] set_cur depth=%d\n", \
1N/A PTR2UV(PL_comppad), PTR2UV(PL_curpad), (int)(n)));
1N/A
1N/A
1N/A#define PAD_SET_CUR(padlist,n) \
1N/A SAVECOMPPAD(); \
1N/A PAD_SET_CUR_NOSAVE(padlist,n);
1N/A
1N/A
1N/A#define PAD_SAVE_SETNULLPAD() SAVECOMPPAD(); \
1N/A PL_comppad = Null(PAD*); PL_curpad = Null(SV**); \
1N/A DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad set_null\n"));
1N/A
1N/A#define PAD_SAVE_LOCAL(opad,npad) \
1N/A opad = PL_comppad; \
1N/A PL_comppad = (npad); \
1N/A PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : Null(SV**); \
1N/A DEBUG_Xv(PerlIO_printf(Perl_debug_log, \
1N/A "Pad 0x%"UVxf"[0x%"UVxf"] save_local\n", \
1N/A PTR2UV(PL_comppad), PTR2UV(PL_curpad)));
1N/A
1N/A#define PAD_RESTORE_LOCAL(opad) \
1N/A PL_comppad = opad; \
1N/A PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : Null(SV**); \
1N/A DEBUG_Xv(PerlIO_printf(Perl_debug_log, \
1N/A "Pad 0x%"UVxf"[0x%"UVxf"] restore_local\n", \
1N/A PTR2UV(PL_comppad), PTR2UV(PL_curpad)));
1N/A
1N/A
1N/A/*
1N/A=for apidoc m|void|CX_CURPAD_SAVE|struct context
1N/ASave the current pad in the given context block structure.
1N/A
1N/A=for apidoc m|SV *|CX_CURPAD_SV|struct context|PADOFFSET po
1N/AAccess the SV at offset po in the saved current pad in the given
1N/Acontext block structure (can be used as an lvalue).
1N/A
1N/A=cut
1N/A*/
1N/A
1N/A#define CX_CURPAD_SAVE(block) (block).oldcomppad = PL_comppad
1N/A#define CX_CURPAD_SV(block,po) (AvARRAY((AV*)((block).oldcomppad))[po])
1N/A
1N/A
1N/A/*
1N/A=for apidoc m|U32|PAD_COMPNAME_FLAGS|PADOFFSET po
1N/AReturn the flags for the current compiling pad name
1N/Aat offset C<po>. Assumes a valid slot entry.
1N/A
1N/A=for apidoc m|char *|PAD_COMPNAME_PV|PADOFFSET po
1N/AReturn the name of the current compiling pad name
1N/Aat offset C<po>. Assumes a valid slot entry.
1N/A
1N/A=for apidoc m|HV *|PAD_COMPNAME_TYPE|PADOFFSET po
1N/AReturn the type (stash) of the current compiling pad name at offset
1N/AC<po>. Must be a valid name. Returns null if not typed.
1N/A
1N/A=for apidoc m|HV *|PAD_COMPNAME_OURSTASH|PADOFFSET po
1N/AReturn the stash associated with an C<our> variable.
1N/AAssumes the slot entry is a valid C<our> lexical.
1N/A
1N/A=for apidoc m|STRLEN|PAD_COMPNAME_GEN|PADOFFSET po
1N/AThe generation number of the name at offset C<po> in the current
1N/Acompiling pad (lvalue). Note that C<SvCUR> is hijacked for this purpose.
1N/A
1N/A=cut
1N/A*/
1N/A
1N/A#define PAD_COMPNAME_FLAGS(po) SvFLAGS(*av_fetch(PL_comppad_name, (po), FALSE))
1N/A#define PAD_COMPNAME_PV(po) SvPV_nolen(*av_fetch(PL_comppad_name, (po), FALSE))
1N/A
1N/A/* XXX DAPM yuk - using av_fetch twice. Is there a better way? */
1N/A#define PAD_COMPNAME_TYPE(po) \
1N/A ((SvFLAGS(*av_fetch(PL_comppad_name, (po), FALSE)) & SVpad_TYPED) \
1N/A ? (SvSTASH(*av_fetch(PL_comppad_name, (po), FALSE))) : Nullhv)
1N/A
1N/A#define PAD_COMPNAME_OURSTASH(po) \
1N/A (GvSTASH(*av_fetch(PL_comppad_name, (po), FALSE)))
1N/A
1N/A#define PAD_COMPNAME_GEN(po) SvCUR(AvARRAY(PL_comppad_name)[po])
1N/A
1N/A
1N/A
1N/A
1N/A/*
1N/A=for apidoc m|void|PAD_DUP|PADLIST dstpad|PADLIST srcpad|CLONE_PARAMS* param
1N/AClone a padlist.
1N/A
1N/A=for apidoc m|void|PAD_CLONE_VARS|PerlInterpreter *proto_perl \
1N/A|CLONE_PARAMS* param
1N/AClone the state variables associated with running and compiling pads.
1N/A
1N/A=cut
1N/A*/
1N/A
1N/A
1N/A#define PAD_DUP(dstpad, srcpad, param) \
1N/A if ((srcpad) && !AvREAL(srcpad)) { \
1N/A /* XXX padlists are real, but pretend to be not */ \
1N/A AvREAL_on(srcpad); \
1N/A (dstpad) = av_dup_inc((srcpad), param); \
1N/A AvREAL_off(srcpad); \
1N/A AvREAL_off(dstpad); \
1N/A } \
1N/A else \
1N/A (dstpad) = av_dup_inc((srcpad), param);
1N/A
1N/A/* NB - we set PL_comppad to null unless it points at a value that
1N/A * has already been dup'ed, ie it points to part of an active padlist.
1N/A * Otherwise PL_comppad ends up being a leaked scalar in code like
1N/A * the following:
1N/A * threads->create(sub { threads->create(sub {...} ) } );
1N/A * where the second thread dups the outer sub's comppad but not the
1N/A * sub's CV or padlist. */
1N/A
1N/A#define PAD_CLONE_VARS(proto_perl, param) \
1N/A PL_comppad = ptr_table_fetch(PL_ptr_table, proto_perl->Tcomppad); \
1N/A PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : Null(SV**); \
1N/A PL_comppad_name = av_dup(proto_perl->Icomppad_name, param); \
1N/A PL_comppad_name_fill = proto_perl->Icomppad_name_fill; \
1N/A PL_comppad_name_floor = proto_perl->Icomppad_name_floor; \
1N/A PL_min_intro_pending = proto_perl->Imin_intro_pending; \
1N/A PL_max_intro_pending = proto_perl->Imax_intro_pending; \
1N/A PL_padix = proto_perl->Ipadix; \
1N/A PL_padix_floor = proto_perl->Ipadix_floor; \
1N/A PL_pad_reset_pending = proto_perl->Ipad_reset_pending; \
1N/A PL_cop_seqmax = proto_perl->Icop_seqmax;