pad.h revision 7c478bd95313f5f23a4c958a745db2134aa03244
/* pad.h
*
* Copyright (C) 2002, by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
* This file defines the types and macros associated with the API for
* manipulating scratchpads, which are used by perl to store lexical
* variables, op targets and constants.
*/
/* a padlist is currently just an AV; but that might change,
* so hide the type. Ditto a pad. */
/* offsets within a pad */
#if PTRSIZE == 4
#else
# if PTRSIZE == 8
# endif
#endif
/* flags for the pad_new() function */
/* values for the pad_tidy() function */
typedef enum {
padtidy_SUB, /* tidy up a pad for a sub, */
padtidy_SUBCLONE, /* a cloned sub, */
padtidy_FORMAT /* or a format */
} padtidy_type;
/* ASSERT_CURPAD_LEGAL and ASSERT_CURPAD_ACTIVE respectively determine
* whether PL_comppad and PL_curpad are consistent and whether they have
* active values */
#ifdef DEBUGGING
# define ASSERT_CURPAD_LEGAL(label) \
# define ASSERT_CURPAD_ACTIVE(label) \
#else
# define ASSERT_CURPAD_LEGAL(label)
# define ASSERT_CURPAD_ACTIVE(label)
#endif
/* Note: the following three macros are actually defined in scope.h, but
* they are documented here for completeness, since they directly or
* indirectly affect pads.
=for apidoc m|void|SAVEPADSV |PADOFFSET po
Save a pad slot (used to restore after an iteration)
XXX DAPM it would make more sense to make the arg a PADOFFSET
=for apidoc m|void|SAVECLEARSV |SV **svp
Clear the pointed to pad value on scope exit. (ie the runtime action of 'my')
=for apidoc m|void|SAVECOMPPAD
save PL_comppad and PL_curpad
=for apidoc m|SV *|PAD_SETSV |PADOFFSET po|SV* sv
Set the slot at offset C<po> in the current pad to C<sv>
=for apidoc m|void|PAD_SV |PADOFFSET po
Get the value at offset C<po> in the current pad
=for apidoc m|SV *|PAD_SVl |PADOFFSET po
Lightweight and lvalue version of C<PAD_SV>.
Get or set the value at offset C<po> in the current pad.
Unlike C<PAD_SV>, does not print diagnostics with -DX.
For internal use only.
=for apidoc m|SV *|PAD_BASE_SV |PADLIST padlist|PADOFFSET po
Get the value from slot C<po> in the base (DEPTH=1) pad of a padlist
=for apidoc m|void|PAD_SET_CUR |PADLIST padlist|I32 n
Set the current pad to be pad C<n> in the padlist, saving
the previous current pad.
=for apidoc m|void|PAD_SET_CUR_NOSAVE |PADLIST padlist|I32 n
like PAD_SET_CUR, but without the save
=for apidoc m|void|PAD_SAVE_SETNULLPAD
Save the current pad then set it to null.
=for apidoc m|void|PAD_SAVE_LOCAL|PAD *opad|PAD *npad
Save the current pad to the local variable opad, then make the
current pad equal to npad
=for apidoc m|void|PAD_RESTORE_LOCAL|PAD *opad
Restore the old pad saved into the local variable opad by PAD_SAVE_LOCAL()
=cut
*/
#ifdef DEBUGGING
#else
#endif
#define PAD_SET_CUR_NOSAVE(padlist,n) \
#define PAD_SET_CUR(padlist,n) \
SAVECOMPPAD(); \
#define PAD_SAVE_SETNULLPAD() SAVECOMPPAD(); \
opad = PL_comppad; \
PL_comppad = (npad); \
#define PAD_RESTORE_LOCAL(opad) \
PL_comppad = opad; \
/*
=for apidoc m|void|CX_CURPAD_SAVE|struct context
Save the current pad in the given context block structure.
=for apidoc m|SV *|CX_CURPAD_SV|struct context|PADOFFSET po
Access the SV at offset po in the saved current pad in the given
context block structure (can be used as an lvalue).
=cut
*/
/*
=for apidoc m|U32|PAD_COMPNAME_FLAGS|PADOFFSET po
Return the flags for the current compiling pad name
at offset C<po>. Assumes a valid slot entry.
=for apidoc m|char *|PAD_COMPNAME_PV|PADOFFSET po
Return the name of the current compiling pad name
at offset C<po>. Assumes a valid slot entry.
=for apidoc m|HV *|PAD_COMPNAME_TYPE|PADOFFSET po
Return the type (stash) of the current compiling pad name at offset
C<po>. Must be a valid name. Returns null if not typed.
=for apidoc m|HV *|PAD_COMPNAME_OURSTASH|PADOFFSET po
Return the stash associated with an C<our> variable.
Assumes the slot entry is a valid C<our> lexical.
=for apidoc m|STRLEN|PAD_COMPNAME_GEN|PADOFFSET po
The generation number of the name at offset C<po> in the current
compiling pad (lvalue). Note that C<SvCUR> is hijacked for this purpose.
=cut
*/
/* XXX DAPM yuk - using av_fetch twice. Is there a better way? */
#define PAD_COMPNAME_TYPE(po) \
#define PAD_COMPNAME_OURSTASH(po) \
/*
=for apidoc m|void|PAD_DUP|PADLIST dstpad|PADLIST srcpad|CLONE_PARAMS* param
Clone a padlist.
=for apidoc m|void|PAD_CLONE_VARS|PerlInterpreter *proto_perl \
|CLONE_PARAMS* param
Clone the state variables associated with running and compiling pads.
=cut
*/
/* XXX padlists are real, but pretend to be not */ \
AvREAL_off(srcpad); \
AvREAL_off(dstpad); \
} \
else \
/* NB - we set PL_comppad to null unless it points at a value that
* has already been dup'ed, ie it points to part of an active padlist.
* Otherwise PL_comppad ends up being a leaked scalar in code like
* the following:
* threads->create(sub { threads->create(sub {...} ) } );
* where the second thread dups the outer sub's comppad but not the
* sub's CV or padlist. */