1 /* pad.h 2 * 3 * Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008, 4 * 2009, 2010, 2011 by Larry Wall and others 5 * 6 * You may distribute under the terms of either the GNU General Public 7 * License or the Artistic License, as specified in the README file. 8 * 9 * This file defines the types and macros associated with the API for 10 * manipulating scratchpads, which are used by perl to store lexical 11 * variables, op targets and constants. 12 */ 13 14 /* offsets within a pad */ 15 16 typedef SSize_t PADOFFSET; /* signed so that -1 is a valid value */ 17 #define NOT_IN_PAD ((PADOFFSET) -1) 18 19 /* B.xs expects the first members of these two structs to line up 20 (xpadl_max with xpadnl_fill). 21 */ 22 23 struct padlist { 24 SSize_t xpadl_max; /* max index for which array has space */ 25 union { 26 PAD ** xpadlarr_alloc; /* Pointer to beginning of array of AVs. 27 Note that a 'padnamelist *' is stored 28 in the 0 index of the AV. */ 29 struct { 30 PADNAMELIST * padnl; 31 PAD * pad_1; /* this slice of PAD * array always alloced */ 32 PAD * pad_2; /* maybe unalloced */ 33 } * xpadlarr_dbg; /* for use with a C debugger only */ 34 } xpadl_arr; 35 U32 xpadl_id; /* Semi-unique ID, shared between clones */ 36 U32 xpadl_outid; /* ID of outer pad */ 37 }; 38 39 struct padnamelist { 40 SSize_t xpadnl_fill; /* max index in use */ 41 PADNAME ** xpadnl_alloc; /* pointer to beginning of array */ 42 SSize_t xpadnl_max; /* max index for which array has space */ 43 PADOFFSET xpadnl_max_named; /* highest index with len > 0 */ 44 U32 xpadnl_refcnt; 45 }; 46 47 /* PERL_PADNAME_MINIMAL uses less memory, but on some platforms 48 PERL_PADNAME_ALIGNED may be faster, so platform-specific hints can 49 define one or the other. */ 50 #if defined(PERL_PADNAME_MINIMAL) && defined (PERL_PADNAME_ALIGNED) 51 # error PERL_PADNAME_MINIMAL and PERL_PADNAME_ALIGNED are exclusive 52 #endif 53 54 #if !defined(PERL_PADNAME_MINIMAL) && !defined(PERL_PADNAME_ALIGNED) 55 # define PERL_PADNAME_MINIMAL 56 #endif 57 58 struct padname_fieldinfo; 59 60 #define _PADNAME_BASE \ 61 char * xpadn_pv; \ 62 HV * xpadn_ourstash; \ 63 union { \ 64 HV * xpadn_typestash; \ 65 CV * xpadn_protocv; \ 66 } xpadn_type_u; \ 67 struct padname_fieldinfo *xpadn_fieldinfo; \ 68 U32 xpadn_low; \ 69 U32 xpadn_high; \ 70 U32 xpadn_refcnt; \ 71 int xpadn_gen; \ 72 U8 xpadn_len; \ 73 U8 xpadn_flags 74 75 struct padname { 76 _PADNAME_BASE; 77 }; 78 79 struct padname_with_str { 80 #ifdef PERL_PADNAME_MINIMAL 81 _PADNAME_BASE; 82 #else 83 struct padname xpadn_padname; 84 #endif 85 char xpadn_str[1]; 86 }; 87 88 #undef _PADNAME_BASE 89 90 #define PADNAME_FROM_PV(s) \ 91 ((PADNAME *)((s) - STRUCT_OFFSET(struct padname_with_str, xpadn_str))) 92 93 /* Most padnames are not field names. Keep all the field-related info in its 94 * own substructure, stored in ->xpadn_fieldinfo. 95 */ 96 struct padname_fieldinfo { 97 U32 refcount; 98 PADOFFSET fieldix; /* index of this field within ObjectFIELDS() array */ 99 HV *fieldstash; /* original class package which added this field */ 100 OP *defop; /* optree fragment for defaulting expression */ 101 SV *paramname; /* name of the :param to look for in constructor */ 102 int def_if_undef : 1; /* default op uses //= */ 103 int def_if_false : 1; /* default op uses ||= */ 104 }; 105 106 107 /* a value that PL_cop_seqmax is guaranteed never to be, 108 * flagging that a lexical is being introduced, or has not yet left scope 109 */ 110 #define PERL_PADSEQ_INTRO U32_MAX 111 #define COP_SEQMAX_INC \ 112 (PL_cop_seqmax++, \ 113 (void)(PL_cop_seqmax == PERL_PADSEQ_INTRO && PL_cop_seqmax++)) 114 115 116 /* B.xs needs these for the benefit of B::Deparse */ 117 /* Low range end is exclusive (valid from the cop seq after this one) */ 118 /* High range end is inclusive (valid up to this cop seq) */ 119 120 #define COP_SEQ_RANGE_LOW(pn) (pn)->xpadn_low 121 #define COP_SEQ_RANGE_HIGH(pn) (pn)->xpadn_high 122 #define PARENT_PAD_INDEX(pn) (pn)->xpadn_low 123 #define PARENT_FAKELEX_FLAGS(pn) (pn)->xpadn_high 124 125 /* Flags set in the SvIVX field of FAKE namesvs */ 126 127 #define PAD_FAKELEX_ANON 1 /* the lex is declared in an ANON, or ... */ 128 #define PAD_FAKELEX_MULTI 2 /* the lex can be instantiated multiple times */ 129 130 /* flags for the pad_new() function */ 131 132 #define padnew_CLONE 1 /* this pad is for a cloned CV */ 133 #define padnew_SAVE 2 /* save old globals */ 134 #define padnew_SAVESUB 4 /* also save extra stuff for start of sub */ 135 136 /* values for the pad_tidy() function */ 137 138 typedef enum { 139 padtidy_SUB, /* tidy up a pad for a sub, */ 140 padtidy_SUBCLONE, /* a cloned sub, */ 141 padtidy_FORMAT /* or a format */ 142 } padtidy_type; 143 144 /* flags for pad_add_name_pvn. */ 145 146 #define padadd_OUR 0x01 /* our declaration. */ 147 #define padadd_STATE 0x02 /* state declaration. */ 148 #define padadd_NO_DUP_CHECK 0x04 /* skip warning on dups. */ 149 #define padadd_STALEOK 0x08 /* allow stale lexical in active 150 * sub, but only one level up */ 151 #define padadd_FIELD 0x10 /* set PADNAMEt_FIELD */ 152 #define padfind_FIELD_OK 0x20 /* pad_findlex is permitted to see fields */ 153 154 /* ASSERT_CURPAD_LEGAL and ASSERT_CURPAD_ACTIVE respectively determine 155 * whether PL_comppad and PL_curpad are consistent and whether they have 156 * active values */ 157 158 #ifdef DEBUGGING 159 # define ASSERT_CURPAD_LEGAL(label) \ 160 if (PL_comppad ? (AvARRAY(PL_comppad) != PL_curpad) : (PL_curpad != 0)) \ 161 Perl_croak(aTHX_ "panic: illegal pad in %s: 0x%" UVxf "[0x%" UVxf "]",\ 162 label, PTR2UV(PL_comppad), PTR2UV(PL_curpad)); 163 164 165 # define ASSERT_CURPAD_ACTIVE(label) \ 166 if (!PL_comppad || (AvARRAY(PL_comppad) != PL_curpad)) \ 167 Perl_croak(aTHX_ "panic: invalid pad in %s: 0x%" UVxf "[0x%" UVxf "]",\ 168 label, PTR2UV(PL_comppad), PTR2UV(PL_curpad)); 169 #else 170 # define ASSERT_CURPAD_LEGAL(label) 171 # define ASSERT_CURPAD_ACTIVE(label) 172 #endif 173 174 175 176 /* Note: the following three macros are actually defined in scope.h, but 177 * they are documented here for completeness, since they directly or 178 * indirectly affect pads. */ 179 180 /* 181 =for apidoc m|void|SAVEPADSV |PADOFFSET po 182 Save a pad slot (used to restore after an iteration) 183 184 =cut 185 186 XXX DAPM it would make more sense to make the arg a PADOFFSET 187 188 =for apidoc m|void|SAVECLEARSV |SV **svp 189 Clear the pointed to pad value on scope exit. (i.e. the runtime action of 190 C<my>) 191 192 =for apidoc m|void|SAVECOMPPAD 193 save C<PL_comppad> and C<PL_curpad> 194 195 196 =for apidoc Amx|PAD **|PadlistARRAY|PADLIST * padlist 197 The C array of a padlist, containing the pads. Only subscript it with 198 numbers >= 1, as the 0th entry is not guaranteed to remain usable. 199 200 =for apidoc Amx|SSize_t|PadlistMAX|PADLIST * padlist 201 The index of the last allocated space in the padlist. Note that the last 202 pad may be in an earlier slot. Any entries following it will be C<NULL> in 203 that case. 204 205 =for apidoc Amx|PADNAMELIST *|PadlistNAMES|PADLIST * padlist 206 The names associated with pad entries. 207 208 =for apidoc Amx|PADNAME **|PadlistNAMESARRAY|PADLIST * padlist 209 The C array of pad names. 210 211 =for apidoc Amx|SSize_t|PadlistNAMESMAX|PADLIST * padlist 212 The index of the last pad name. 213 214 =for apidoc Amx|U32|PadlistREFCNT|PADLIST * padlist 215 The reference count of the padlist. Currently this is always 1. 216 217 =for apidoc Amx|PADNAME **|PadnamelistARRAY|PADNAMELIST * pnl 218 The C array of pad names. 219 220 =for apidoc Amx|SSize_t|PadnamelistMAX|PADNAMELIST * pnl 221 The index of the last pad name. 222 223 =for apidoc Amx|SSize_t|PadnamelistREFCNT|PADNAMELIST * pnl 224 The reference count of the pad name list. 225 226 =for apidoc Amx|void|PadnamelistREFCNT_dec|PADNAMELIST * pnl 227 Lowers the reference count of the pad name list. 228 229 =for apidoc Amx|SV **|PadARRAY|PAD * pad 230 The C array of pad entries. 231 232 =for apidoc Amx|SSize_t|PadMAX|PAD * pad 233 The index of the last pad entry. 234 235 =for apidoc Amx|char *|PadnamePV|PADNAME * pn 236 The name stored in the pad name struct. This returns C<NULL> for a target 237 slot. 238 239 =for apidoc Amx|STRLEN|PadnameLEN|PADNAME * pn 240 The length of the name. 241 242 =for apidoc Amx|bool|PadnameUTF8|PADNAME * pn 243 Whether PadnamePV is in UTF-8. Currently, this is always true. 244 245 =for apidoc Amx|SV *|PadnameSV|PADNAME * pn 246 Returns the pad name as a mortal SV. 247 248 =for apidoc m|bool|PadnameIsOUR|PADNAME * pn 249 Whether this is an "our" variable. 250 251 =for apidoc m|HV *|PadnameOURSTASH|PADNAME * pn 252 The stash in which this "our" variable was declared. 253 254 =for apidoc m|bool|PadnameOUTER|PADNAME * pn 255 Whether this entry belongs to an outer pad. Entries for which this is true 256 are often referred to as 'fake'. 257 258 =for apidoc m|bool|PadnameIsSTATE|PADNAME * pn 259 Whether this is a "state" variable. 260 261 =for apidoc m|bool|PadnameIsFIELD|PADNAME * pn 262 Whether this is a "field" variable. PADNAMEs where this is true will 263 have additional information available via C<PadnameFIELDINFO>. 264 265 =for apidoc m|HV *|PadnameTYPE|PADNAME * pn 266 The stash associated with a typed lexical. This returns the C<%Foo::> hash 267 for C<my Foo $bar>. 268 269 =for apidoc Amx|SSize_t|PadnameREFCNT|PADNAME * pn 270 The reference count of the pad name. 271 272 =for apidoc Amx|PADNAME *|PadnameREFCNT_inc|PADNAME * pn 273 Increases the reference count of the pad name. Returns the pad name itself. 274 275 =for apidoc Amx|void|PadnameREFCNT_dec|PADNAME * pn 276 Lowers the reference count of the pad name. 277 278 279 =for apidoc m|SV *|PAD_SETSV |PADOFFSET po|SV* sv 280 Set the slot at offset C<po> in the current pad to C<sv> 281 282 =for apidoc m|SV *|PAD_SV |PADOFFSET po 283 Get the value at offset C<po> in the current pad 284 285 =for apidoc m|SV *|PAD_SVl |PADOFFSET po 286 Lightweight and lvalue version of C<PAD_SV>. 287 Get or set the value at offset C<po> in the current pad. 288 Unlike C<PAD_SV>, does not print diagnostics with -DX. 289 For internal use only. 290 291 =for apidoc m|SV *|PAD_BASE_SV |PADLIST padlist|PADOFFSET po 292 Get the value from slot C<po> in the base (DEPTH=1) pad of a padlist 293 294 =for apidoc m|void|PAD_SET_CUR |PADLIST padlist|I32 n 295 Set the current pad to be pad C<n> in the padlist, saving 296 the previous current pad. NB currently this macro expands to a string too 297 long for some compilers, so it's best to replace it with 298 299 SAVECOMPPAD(); 300 PAD_SET_CUR_NOSAVE(padlist,n); 301 302 303 =for apidoc m|void|PAD_SET_CUR_NOSAVE |PADLIST padlist|I32 n 304 like PAD_SET_CUR, but without the save 305 306 =for apidoc m|void|PAD_SAVE_SETNULLPAD 307 Save the current pad then set it to null. 308 309 =for apidoc m|void|PAD_SAVE_LOCAL|PAD *opad|PAD *npad 310 Save the current pad to the local variable C<opad>, then make the 311 current pad equal to C<npad> 312 313 =for apidoc m|void|PAD_RESTORE_LOCAL|PAD *opad 314 Restore the old pad saved into the local variable C<opad> by C<PAD_SAVE_LOCAL()> 315 316 =cut 317 */ 318 319 #define PadlistARRAY(pl) (pl)->xpadl_arr.xpadlarr_alloc 320 #define PadlistMAX(pl) (pl)->xpadl_max 321 #define PadlistNAMES(pl) *((PADNAMELIST **)PadlistARRAY(pl)) 322 #define PadlistNAMESARRAY(pl) PadnamelistARRAY(PadlistNAMES(pl)) 323 #define PadlistNAMESMAX(pl) PadnamelistMAX(PadlistNAMES(pl)) 324 #define PadlistREFCNT(pl) 1 /* reserved for future use */ 325 326 #define PadnamelistARRAY(pnl) (pnl)->xpadnl_alloc 327 #define PadnamelistMAX(pnl) (pnl)->xpadnl_fill 328 #define PadnamelistMAXNAMED(pnl) (pnl)->xpadnl_max_named 329 #define PadnamelistREFCNT(pnl) (pnl)->xpadnl_refcnt 330 #define PadnamelistREFCNT_inc(pnl) Perl_padnamelist_refcnt_inc(pnl) 331 #define PadnamelistREFCNT_dec(pnl) Perl_padnamelist_free(aTHX_ pnl) 332 333 #define PadARRAY(pad) AvARRAY(pad) 334 #define PadMAX(pad) AvFILLp(pad) 335 336 #define PadnamePV(pn) (pn)->xpadn_pv 337 #define PadnameLEN(pn) (pn)->xpadn_len 338 #define PadnameUTF8(pn) 1 339 #define PadnameSV(pn) \ 340 newSVpvn_flags(PadnamePV(pn), PadnameLEN(pn), SVs_TEMP|SVf_UTF8) 341 #define PadnameFLAGS(pn) (pn)->xpadn_flags 342 #define PadnameIsOUR(pn) cBOOL((pn)->xpadn_ourstash) 343 #define PadnameOURSTASH(pn) (pn)->xpadn_ourstash 344 #define PadnameTYPE(pn) (pn)->xpadn_type_u.xpadn_typestash 345 #define PadnameHasTYPE(pn) cBOOL(PadnameTYPE(pn)) 346 #define PadnamePROTOCV(pn) (pn)->xpadn_type_u.xpadn_protocv 347 #define PadnameREFCNT(pn) (pn)->xpadn_refcnt 348 #define PadnameREFCNT_inc(pn) Perl_padname_refcnt_inc(pn) 349 #define PadnameREFCNT_dec(pn) Perl_padname_free(aTHX_ pn) 350 #define PadnameOURSTASH_set(pn,s) (PadnameOURSTASH(pn) = (s)) 351 #define PadnameTYPE_set(pn,s) (PadnameTYPE(pn) = (s)) 352 #define PadnameFIELDINFO(pn) (pn)->xpadn_fieldinfo 353 #define PadnameOUTER(pn) (PadnameFLAGS(pn) & PADNAMEf_OUTER) 354 #define PadnameIsSTATE(pn) (PadnameFLAGS(pn) & PADNAMEf_STATE) 355 #define PadnameLVALUE(pn) (PadnameFLAGS(pn) & PADNAMEf_LVALUE) 356 #define PadnameIsFIELD(pn) (PadnameFLAGS(pn) & PADNAMEf_FIELD) 357 358 #define PadnameLVALUE_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_LVALUE) 359 #define PadnameIsSTATE_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_STATE) 360 361 #define PADNAMEf_OUTER 0x01 /* outer lexical var */ 362 #define PADNAMEf_STATE 0x02 /* state var */ 363 #define PADNAMEf_LVALUE 0x04 /* used as lvalue */ 364 #define PADNAMEf_TYPED 0x08 /* for B; unused by core */ 365 #define PADNAMEf_OUR 0x10 /* for B; unused by core */ 366 #define PADNAMEf_FIELD 0x20 /* field var */ 367 368 /* backward compatibility */ 369 #ifndef PERL_CORE 370 # define SvPAD_STATE PadnameIsSTATE 371 # define SvPAD_TYPED PadnameHasTYPE 372 # define SvPAD_OUR(pn) cBOOL(PadnameOURSTASH(pn)) 373 # define SvPAD_STATE_on PadnameIsSTATE_on 374 # define SvPAD_TYPED_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_TYPED) 375 # define SvPAD_OUR_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_OUR) 376 # define SvOURSTASH PadnameOURSTASH 377 # define SvOURSTASH_set PadnameOURSTASH_set 378 # define SVpad_STATE PADNAMEf_STATE 379 # define SVpad_TYPED PADNAMEf_TYPED 380 # define SVpad_OUR PADNAMEf_OUR 381 # define PADNAMEt_OUTER PADNAMEf_OUTER 382 # define PADNAMEt_STATE PADNAMEf_STATE 383 # define PADNAMEt_LVALUE PADNAMEf_LVALUE 384 # define PADNAMEt_TYPED PADNAMEf_TYPED 385 # define PADNAMEt_OUR PADNAMEf_OUR 386 #endif 387 388 #ifdef USE_ITHREADS 389 # define padnamelist_dup_inc(pnl,param) PadnamelistREFCNT_inc(padnamelist_dup(pnl,param)) 390 # define padname_dup_inc(pn,param) PadnameREFCNT_inc(padname_dup(pn,param)) 391 #endif 392 393 #ifdef DEBUGGING 394 # define PAD_SV(po) pad_sv(po) 395 # define PAD_SETSV(po,sv) pad_setsv(po,sv) 396 #else 397 # define PAD_SV(po) (PL_curpad[po]) 398 # define PAD_SETSV(po,sv) PL_curpad[po] = (sv) 399 #endif 400 401 #define PAD_SVl(po) (PL_curpad[po]) 402 403 #define PAD_BASE_SV(padlist, po) \ 404 (PadlistARRAY(padlist)[1]) \ 405 ? AvARRAY(MUTABLE_AV((PadlistARRAY(padlist)[1])))[po] \ 406 : NULL; 407 408 409 #define PAD_SET_CUR_NOSAVE(padlist,nth) \ 410 PL_comppad = (PAD*) (PadlistARRAY(padlist)[nth]); \ 411 PL_curpad = AvARRAY(PL_comppad); \ 412 DEBUG_Xv(PerlIO_printf(Perl_debug_log, \ 413 "Pad 0x%" UVxf "[0x%" UVxf "] set_cur depth=%d\n", \ 414 PTR2UV(PL_comppad), PTR2UV(PL_curpad), (int)(nth))); 415 416 417 #define PAD_SET_CUR(padlist,nth) \ 418 SAVECOMPPAD(); \ 419 PAD_SET_CUR_NOSAVE(padlist,nth); 420 421 422 #define PAD_SAVE_SETNULLPAD() SAVECOMPPAD(); \ 423 PL_comppad = NULL; PL_curpad = NULL; \ 424 DEBUG_Xv(PerlIO_printf(Perl_debug_log, "Pad set_null\n")); 425 426 #define PAD_SAVE_LOCAL(opad,npad) \ 427 opad = PL_comppad; \ 428 PL_comppad = (npad); \ 429 PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \ 430 DEBUG_Xv(PerlIO_printf(Perl_debug_log, \ 431 "Pad 0x%" UVxf "[0x%" UVxf "] save_local\n", \ 432 PTR2UV(PL_comppad), PTR2UV(PL_curpad))); 433 434 #define PAD_RESTORE_LOCAL(opad) \ 435 assert(!opad || !SvIS_FREED(opad)); \ 436 PL_comppad = opad; \ 437 PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \ 438 DEBUG_Xv(PerlIO_printf(Perl_debug_log, \ 439 "Pad 0x%" UVxf "[0x%" UVxf "] restore_local\n", \ 440 PTR2UV(PL_comppad), PTR2UV(PL_curpad))); 441 442 443 /* 444 =for apidoc m|void|CX_CURPAD_SAVE|struct context 445 Save the current pad in the given context block structure. 446 447 =for apidoc m|SV *|CX_CURPAD_SV|struct context|PADOFFSET po 448 Access the SV at offset C<po> in the saved current pad in the given 449 context block structure (can be used as an lvalue). 450 451 =cut 452 */ 453 454 #define CX_CURPAD_SAVE(block) (block).oldcomppad = PL_comppad 455 #define CX_CURPAD_SV(block,po) (AvARRAY(MUTABLE_AV(((block).oldcomppad)))[po]) 456 457 458 /* 459 =for apidoc m|U32|PAD_COMPNAME_FLAGS|PADOFFSET po 460 Return the flags for the current compiling pad name 461 at offset C<po>. Assumes a valid slot entry. 462 463 =for apidoc m|char *|PAD_COMPNAME_PV|PADOFFSET po 464 Return the name of the current compiling pad name 465 at offset C<po>. Assumes a valid slot entry. 466 467 =for apidoc m|HV *|PAD_COMPNAME_TYPE|PADOFFSET po 468 Return the type (stash) of the current compiling pad name at offset 469 C<po>. Must be a valid name. Returns null if not typed. 470 471 =for apidoc m|HV *|PAD_COMPNAME_OURSTASH|PADOFFSET po 472 Return the stash associated with an C<our> variable. 473 Assumes the slot entry is a valid C<our> lexical. 474 475 =for apidoc m|STRLEN|PAD_COMPNAME_GEN|PADOFFSET po 476 The generation number of the name at offset C<po> in the current 477 compiling pad (lvalue). 478 479 =for apidoc m|STRLEN|PAD_COMPNAME_GEN_set|PADOFFSET po|int gen 480 Sets the generation number of the name at offset C<po> in the current 481 ling pad (lvalue) to C<gen>. 482 =cut 483 484 */ 485 486 #define PAD_COMPNAME(po) PAD_COMPNAME_SV(po) 487 #define PAD_COMPNAME_SV(po) (PadnamelistARRAY(PL_comppad_name)[(po)]) 488 #define PAD_COMPNAME_FLAGS(po) PadnameFLAGS(PAD_COMPNAME(po)) 489 #define PAD_COMPNAME_FLAGS_isOUR(po) PadnameIsOUR(PAD_COMPNAME_SV(po)) 490 #define PAD_COMPNAME_PV(po) PadnamePV(PAD_COMPNAME(po)) 491 492 #define PAD_COMPNAME_TYPE(po) PadnameTYPE(PAD_COMPNAME(po)) 493 494 #define PAD_COMPNAME_OURSTASH(po) (PadnameOURSTASH(PAD_COMPNAME_SV(po))) 495 496 #define PAD_COMPNAME_GEN(po) \ 497 ((STRLEN)PadnamelistARRAY(PL_comppad_name)[po]->xpadn_gen) 498 499 #define PAD_COMPNAME_GEN_set(po, gen) \ 500 (PadnamelistARRAY(PL_comppad_name)[po]->xpadn_gen = (gen)) 501 502 503 /* 504 =for apidoc m|void|PAD_CLONE_VARS|PerlInterpreter *proto_perl|CLONE_PARAMS* param 505 Clone the state variables associated with running and compiling pads. 506 507 =cut 508 */ 509 510 /* NB - we set PL_comppad to null unless it points at a value that 511 * has already been dup'ed, ie it points to part of an active padlist. 512 * Otherwise PL_comppad ends up being a leaked scalar in code like 513 * the following: 514 * threads->create(sub { threads->create(sub {...} ) } ); 515 * where the second thread dups the outer sub's comppad but not the 516 * sub's CV or padlist. */ 517 518 #define PAD_CLONE_VARS(proto_perl, param) \ 519 PL_comppad = av_dup(proto_perl->Icomppad, param); \ 520 PL_curpad = PL_comppad ? AvARRAY(PL_comppad) : NULL; \ 521 PL_comppad_name = \ 522 padnamelist_dup(proto_perl->Icomppad_name, param); \ 523 PL_comppad_name_fill = proto_perl->Icomppad_name_fill; \ 524 PL_comppad_name_floor = proto_perl->Icomppad_name_floor; \ 525 PL_min_intro_pending = proto_perl->Imin_intro_pending; \ 526 PL_max_intro_pending = proto_perl->Imax_intro_pending; \ 527 PL_padix = proto_perl->Ipadix; \ 528 PL_padix_floor = proto_perl->Ipadix_floor; \ 529 PL_pad_reset_pending = proto_perl->Ipad_reset_pending; \ 530 PL_cop_seqmax = proto_perl->Icop_seqmax; 531 532 /* 533 =for apidoc Am|PADOFFSET|pad_add_name_pvs|"name"|U32 flags|HV *typestash|HV *ourstash 534 535 Exactly like L</pad_add_name_pvn>, but takes a literal string 536 instead of a string/length pair. 537 538 =cut 539 */ 540 541 #define pad_add_name_pvs(name,flags,typestash,ourstash) \ 542 Perl_pad_add_name_pvn(aTHX_ STR_WITH_LEN(name), flags, typestash, ourstash) 543 544 /* 545 =for apidoc Am|PADOFFSET|pad_findmy_pvs|"name"|U32 flags 546 547 Exactly like L</pad_findmy_pvn>, but takes a literal string 548 instead of a string/length pair. 549 550 =cut 551 */ 552 553 #define pad_findmy_pvs(name,flags) \ 554 Perl_pad_findmy_pvn(aTHX_ STR_WITH_LEN(name), flags) 555 556 struct suspended_compcv 557 { 558 CV *compcv; 559 STRLEN padix, constpadix; 560 STRLEN comppad_name_fill; 561 STRLEN min_intro_pending, max_intro_pending; 562 bool cv_has_eval, pad_reset_pending; 563 }; 564 565 #define resume_compcv_final(buffer) Perl_resume_compcv(aTHX_ buffer, false) 566 #define resume_compcv_and_save(buffer) Perl_resume_compcv(aTHX_ buffer, true) 567 568 /* 569 * ex: set ts=8 sts=4 sw=4 et: 570 */ 571