| 1 |
root |
1.1 |
/* scope.c |
| 2 |
|
|
* |
| 3 |
|
|
* Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
| 4 |
|
|
* 2000, 2001, 2002, 2003, 2004, 2005, 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 |
|
|
*/ |
| 10 |
|
|
|
| 11 |
|
|
/* |
| 12 |
|
|
* "For the fashion of Minas Tirith was such that it was built on seven |
| 13 |
|
|
* levels..." |
| 14 |
|
|
*/ |
| 15 |
|
|
|
| 16 |
|
|
/* This file contains functions to manipulate several of Perl's stacks; |
| 17 |
|
|
* in particular it contains code to push various types of things onto |
| 18 |
|
|
* the savestack, then to pop them off and perform the correct restorative |
| 19 |
|
|
* action for each one. This corresponds to the cleanup Perl does at |
| 20 |
|
|
* each scope exit. |
| 21 |
|
|
*/ |
| 22 |
|
|
|
| 23 |
|
|
#include "EXTERN.h" |
| 24 |
|
|
#define PERL_IN_SCOPE_C |
| 25 |
|
|
#include "perl.h" |
| 26 |
|
|
|
| 27 |
|
|
#if defined(PERL_FLEXIBLE_EXCEPTIONS) |
| 28 |
|
|
void * |
| 29 |
|
|
Perl_default_protect(pTHX_ volatile JMPENV *pcur_env, int *excpt, |
| 30 |
|
|
protect_body_t body, ...) |
| 31 |
|
|
{ |
| 32 |
|
|
void *ret; |
| 33 |
|
|
va_list args; |
| 34 |
|
|
va_start(args, body); |
| 35 |
|
|
ret = vdefault_protect(pcur_env, excpt, body, &args); |
| 36 |
|
|
va_end(args); |
| 37 |
|
|
return ret; |
| 38 |
|
|
} |
| 39 |
|
|
|
| 40 |
|
|
void * |
| 41 |
|
|
Perl_vdefault_protect(pTHX_ volatile JMPENV *pcur_env, int *excpt, |
| 42 |
|
|
protect_body_t body, va_list *args) |
| 43 |
|
|
{ |
| 44 |
|
|
int ex; |
| 45 |
|
|
void *ret; |
| 46 |
|
|
|
| 47 |
|
|
JMPENV_PUSH(ex); |
| 48 |
|
|
if (ex) |
| 49 |
|
|
ret = NULL; |
| 50 |
|
|
else |
| 51 |
|
|
ret = CALL_FPTR(body)(aTHX_ *args); |
| 52 |
|
|
*excpt = ex; |
| 53 |
|
|
JMPENV_POP; |
| 54 |
|
|
return ret; |
| 55 |
|
|
} |
| 56 |
|
|
#endif |
| 57 |
|
|
|
| 58 |
|
|
SV** |
| 59 |
|
|
Perl_stack_grow(pTHX_ SV **sp, SV **p, int n) |
| 60 |
|
|
{ |
| 61 |
|
|
PL_stack_sp = sp; |
| 62 |
|
|
#ifndef STRESS_REALLOC |
| 63 |
|
|
av_extend(PL_curstack, (p - PL_stack_base) + (n) + 128); |
| 64 |
|
|
#else |
| 65 |
|
|
av_extend(PL_curstack, (p - PL_stack_base) + (n) + 1); |
| 66 |
|
|
#endif |
| 67 |
|
|
return PL_stack_sp; |
| 68 |
|
|
} |
| 69 |
|
|
|
| 70 |
|
|
#ifndef STRESS_REALLOC |
| 71 |
|
|
#define GROW(old) ((old) * 3 / 2) |
| 72 |
|
|
#else |
| 73 |
|
|
#define GROW(old) ((old) + 1) |
| 74 |
|
|
#endif |
| 75 |
|
|
|
| 76 |
|
|
PERL_SI * |
| 77 |
|
|
Perl_new_stackinfo(pTHX_ I32 stitems, I32 cxitems) |
| 78 |
|
|
{ |
| 79 |
|
|
PERL_SI *si; |
| 80 |
|
|
New(56, si, 1, PERL_SI); |
| 81 |
|
|
si->si_stack = newAV(); |
| 82 |
|
|
AvREAL_off(si->si_stack); |
| 83 |
|
|
av_extend(si->si_stack, stitems > 0 ? stitems-1 : 0); |
| 84 |
|
|
AvALLOC(si->si_stack)[0] = &PL_sv_undef; |
| 85 |
|
|
AvFILLp(si->si_stack) = 0; |
| 86 |
|
|
si->si_prev = 0; |
| 87 |
|
|
si->si_next = 0; |
| 88 |
|
|
si->si_cxmax = cxitems - 1; |
| 89 |
|
|
si->si_cxix = -1; |
| 90 |
|
|
si->si_type = PERLSI_UNDEF; |
| 91 |
|
|
New(56, si->si_cxstack, cxitems, PERL_CONTEXT); |
| 92 |
|
|
/* Without any kind of initialising PUSHSUBST() |
| 93 |
|
|
* in pp_subst() will read uninitialised heap. */ |
| 94 |
|
|
Poison(si->si_cxstack, cxitems, PERL_CONTEXT); |
| 95 |
|
|
return si; |
| 96 |
|
|
} |
| 97 |
|
|
|
| 98 |
|
|
I32 |
| 99 |
|
|
Perl_cxinc(pTHX) |
| 100 |
|
|
{ |
| 101 |
|
|
IV old_max = cxstack_max; |
| 102 |
|
|
cxstack_max = GROW(cxstack_max); |
| 103 |
|
|
Renew(cxstack, cxstack_max + 1, PERL_CONTEXT); /* XXX should fix CXINC macro */ |
| 104 |
|
|
/* Without any kind of initialising deep enough recursion |
| 105 |
|
|
* will end up reading uninitialised PERL_CONTEXTs. */ |
| 106 |
|
|
Poison(cxstack + old_max + 1, cxstack_max - old_max, PERL_CONTEXT); |
| 107 |
|
|
return cxstack_ix + 1; |
| 108 |
|
|
} |
| 109 |
|
|
|
| 110 |
|
|
void |
| 111 |
|
|
Perl_push_return(pTHX_ OP *retop) |
| 112 |
|
|
{ |
| 113 |
|
|
if (PL_retstack_ix == PL_retstack_max) { |
| 114 |
|
|
PL_retstack_max = GROW(PL_retstack_max); |
| 115 |
|
|
Renew(PL_retstack, PL_retstack_max, OP*); |
| 116 |
|
|
} |
| 117 |
|
|
PL_retstack[PL_retstack_ix++] = retop; |
| 118 |
|
|
} |
| 119 |
|
|
|
| 120 |
|
|
OP * |
| 121 |
|
|
Perl_pop_return(pTHX) |
| 122 |
|
|
{ |
| 123 |
|
|
if (PL_retstack_ix > 0) |
| 124 |
|
|
return PL_retstack[--PL_retstack_ix]; |
| 125 |
|
|
else |
| 126 |
|
|
return Nullop; |
| 127 |
|
|
} |
| 128 |
|
|
|
| 129 |
|
|
void |
| 130 |
|
|
Perl_push_scope(pTHX) |
| 131 |
|
|
{ |
| 132 |
|
|
if (PL_scopestack_ix == PL_scopestack_max) { |
| 133 |
|
|
PL_scopestack_max = GROW(PL_scopestack_max); |
| 134 |
|
|
Renew(PL_scopestack, PL_scopestack_max, I32); |
| 135 |
|
|
} |
| 136 |
|
|
PL_scopestack[PL_scopestack_ix++] = PL_savestack_ix; |
| 137 |
|
|
|
| 138 |
|
|
} |
| 139 |
|
|
|
| 140 |
|
|
void |
| 141 |
|
|
Perl_pop_scope(pTHX) |
| 142 |
|
|
{ |
| 143 |
|
|
I32 oldsave = PL_scopestack[--PL_scopestack_ix]; |
| 144 |
|
|
LEAVE_SCOPE(oldsave); |
| 145 |
|
|
} |
| 146 |
|
|
|
| 147 |
|
|
void |
| 148 |
|
|
Perl_markstack_grow(pTHX) |
| 149 |
|
|
{ |
| 150 |
|
|
I32 oldmax = PL_markstack_max - PL_markstack; |
| 151 |
|
|
I32 newmax = GROW(oldmax); |
| 152 |
|
|
|
| 153 |
|
|
Renew(PL_markstack, newmax, I32); |
| 154 |
|
|
PL_markstack_ptr = PL_markstack + oldmax; |
| 155 |
|
|
PL_markstack_max = PL_markstack + newmax; |
| 156 |
|
|
} |
| 157 |
|
|
|
| 158 |
|
|
void |
| 159 |
|
|
Perl_savestack_grow(pTHX) |
| 160 |
|
|
{ |
| 161 |
|
|
PL_savestack_max = GROW(PL_savestack_max) + 4; |
| 162 |
|
|
Renew(PL_savestack, PL_savestack_max, ANY); |
| 163 |
|
|
} |
| 164 |
|
|
|
| 165 |
|
|
void |
| 166 |
|
|
Perl_savestack_grow_cnt(pTHX_ I32 need) |
| 167 |
|
|
{ |
| 168 |
|
|
PL_savestack_max = PL_savestack_ix + need; |
| 169 |
|
|
Renew(PL_savestack, PL_savestack_max, ANY); |
| 170 |
|
|
} |
| 171 |
|
|
|
| 172 |
|
|
#undef GROW |
| 173 |
|
|
|
| 174 |
|
|
void |
| 175 |
|
|
Perl_tmps_grow(pTHX_ I32 n) |
| 176 |
|
|
{ |
| 177 |
|
|
#ifndef STRESS_REALLOC |
| 178 |
|
|
if (n < 128) |
| 179 |
|
|
n = (PL_tmps_max < 512) ? 128 : 512; |
| 180 |
|
|
#endif |
| 181 |
|
|
PL_tmps_max = PL_tmps_ix + n + 1; |
| 182 |
|
|
Renew(PL_tmps_stack, PL_tmps_max, SV*); |
| 183 |
|
|
} |
| 184 |
|
|
|
| 185 |
|
|
|
| 186 |
|
|
void |
| 187 |
|
|
Perl_free_tmps(pTHX) |
| 188 |
|
|
{ |
| 189 |
|
|
/* XXX should tmps_floor live in cxstack? */ |
| 190 |
|
|
I32 myfloor = PL_tmps_floor; |
| 191 |
|
|
while (PL_tmps_ix > myfloor) { /* clean up after last statement */ |
| 192 |
|
|
SV* sv = PL_tmps_stack[PL_tmps_ix]; |
| 193 |
|
|
PL_tmps_stack[PL_tmps_ix--] = Nullsv; |
| 194 |
|
|
if (sv && sv != &PL_sv_undef) { |
| 195 |
|
|
SvTEMP_off(sv); |
| 196 |
|
|
SvREFCNT_dec(sv); /* note, can modify tmps_ix!!! */ |
| 197 |
|
|
} |
| 198 |
|
|
} |
| 199 |
|
|
} |
| 200 |
|
|
|
| 201 |
|
|
STATIC SV * |
| 202 |
|
|
S_save_scalar_at(pTHX_ SV **sptr) |
| 203 |
|
|
{ |
| 204 |
|
|
register SV *sv; |
| 205 |
|
|
SV *osv = *sptr; |
| 206 |
|
|
|
| 207 |
|
|
sv = *sptr = NEWSV(0,0); |
| 208 |
|
|
if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) { |
| 209 |
|
|
sv_upgrade(sv, SvTYPE(osv)); |
| 210 |
|
|
if (SvGMAGICAL(osv)) { |
| 211 |
|
|
MAGIC* mg; |
| 212 |
|
|
bool oldtainted = PL_tainted; |
| 213 |
|
|
mg_get(osv); /* note, can croak! */ |
| 214 |
|
|
if (PL_tainting && PL_tainted && |
| 215 |
|
|
(mg = mg_find(osv, PERL_MAGIC_taint))) { |
| 216 |
|
|
SAVESPTR(mg->mg_obj); |
| 217 |
|
|
mg->mg_obj = osv; |
| 218 |
|
|
} |
| 219 |
|
|
SvFLAGS(osv) |= (SvFLAGS(osv) & |
| 220 |
|
|
(SVp_NOK|SVp_POK)) >> PRIVSHIFT; |
| 221 |
|
|
PL_tainted = oldtainted; |
| 222 |
|
|
} |
| 223 |
|
|
SvMAGIC(sv) = SvMAGIC(osv); |
| 224 |
|
|
SvFLAGS(sv) |= SvMAGICAL(osv); |
| 225 |
|
|
/* XXX SvMAGIC() is *shared* between osv and sv. This can |
| 226 |
|
|
* lead to coredumps when both SVs are destroyed without one |
| 227 |
|
|
* of their SvMAGIC() slots being NULLed. */ |
| 228 |
|
|
PL_localizing = 1; |
| 229 |
|
|
SvSETMAGIC(sv); |
| 230 |
|
|
PL_localizing = 0; |
| 231 |
|
|
} |
| 232 |
|
|
return sv; |
| 233 |
|
|
} |
| 234 |
|
|
|
| 235 |
|
|
SV * |
| 236 |
|
|
Perl_save_scalar(pTHX_ GV *gv) |
| 237 |
|
|
{ |
| 238 |
|
|
SV **sptr = &GvSV(gv); |
| 239 |
|
|
SSCHECK(3); |
| 240 |
|
|
SSPUSHPTR(SvREFCNT_inc(gv)); |
| 241 |
|
|
SSPUSHPTR(SvREFCNT_inc(*sptr)); |
| 242 |
|
|
SSPUSHINT(SAVEt_SV); |
| 243 |
|
|
return save_scalar_at(sptr); |
| 244 |
|
|
} |
| 245 |
|
|
|
| 246 |
|
|
SV* |
| 247 |
|
|
Perl_save_svref(pTHX_ SV **sptr) |
| 248 |
|
|
{ |
| 249 |
|
|
SSCHECK(3); |
| 250 |
|
|
SSPUSHPTR(sptr); |
| 251 |
|
|
SSPUSHPTR(SvREFCNT_inc(*sptr)); |
| 252 |
|
|
SSPUSHINT(SAVEt_SVREF); |
| 253 |
|
|
return save_scalar_at(sptr); |
| 254 |
|
|
} |
| 255 |
|
|
|
| 256 |
|
|
/* Like save_sptr(), but also SvREFCNT_dec()s the new value. Can be used to |
| 257 |
|
|
* restore a global SV to its prior contents, freeing new value. */ |
| 258 |
|
|
void |
| 259 |
|
|
Perl_save_generic_svref(pTHX_ SV **sptr) |
| 260 |
|
|
{ |
| 261 |
|
|
SSCHECK(3); |
| 262 |
|
|
SSPUSHPTR(sptr); |
| 263 |
|
|
SSPUSHPTR(SvREFCNT_inc(*sptr)); |
| 264 |
|
|
SSPUSHINT(SAVEt_GENERIC_SVREF); |
| 265 |
|
|
} |
| 266 |
|
|
|
| 267 |
|
|
/* Like save_pptr(), but also Safefree()s the new value if it is different |
| 268 |
|
|
* from the old one. Can be used to restore a global char* to its prior |
| 269 |
|
|
* contents, freeing new value. */ |
| 270 |
|
|
void |
| 271 |
|
|
Perl_save_generic_pvref(pTHX_ char **str) |
| 272 |
|
|
{ |
| 273 |
|
|
SSCHECK(3); |
| 274 |
|
|
SSPUSHPTR(str); |
| 275 |
|
|
SSPUSHPTR(*str); |
| 276 |
|
|
SSPUSHINT(SAVEt_GENERIC_PVREF); |
| 277 |
|
|
} |
| 278 |
|
|
|
| 279 |
|
|
/* Like save_generic_pvref(), but uses PerlMemShared_free() rather than Safefree(). |
| 280 |
|
|
* Can be used to restore a shared global char* to its prior |
| 281 |
|
|
* contents, freeing new value. */ |
| 282 |
|
|
void |
| 283 |
|
|
Perl_save_shared_pvref(pTHX_ char **str) |
| 284 |
|
|
{ |
| 285 |
|
|
SSCHECK(3); |
| 286 |
|
|
SSPUSHPTR(str); |
| 287 |
|
|
SSPUSHPTR(*str); |
| 288 |
|
|
SSPUSHINT(SAVEt_SHARED_PVREF); |
| 289 |
|
|
} |
| 290 |
|
|
|
| 291 |
|
|
void |
| 292 |
|
|
Perl_save_gp(pTHX_ GV *gv, I32 empty) |
| 293 |
|
|
{ |
| 294 |
|
|
SSGROW(6); |
| 295 |
|
|
SSPUSHIV((IV)SvLEN(gv)); |
| 296 |
|
|
SvLEN(gv) = 0; /* forget that anything was allocated here */ |
| 297 |
|
|
SSPUSHIV((IV)SvCUR(gv)); |
| 298 |
|
|
SSPUSHPTR(SvPVX(gv)); |
| 299 |
|
|
SvPOK_off(gv); |
| 300 |
|
|
SSPUSHPTR(SvREFCNT_inc(gv)); |
| 301 |
|
|
SSPUSHPTR(GvGP(gv)); |
| 302 |
|
|
SSPUSHINT(SAVEt_GP); |
| 303 |
|
|
|
| 304 |
|
|
if (empty) { |
| 305 |
|
|
register GP *gp; |
| 306 |
|
|
|
| 307 |
|
|
Newz(602, gp, 1, GP); |
| 308 |
|
|
|
| 309 |
|
|
if (GvCVu(gv)) |
| 310 |
|
|
PL_sub_generation++; /* taking a method out of circulation */ |
| 311 |
|
|
if (GvIOp(gv) && (IoFLAGS(GvIOp(gv)) & IOf_ARGV)) { |
| 312 |
|
|
gp->gp_io = newIO(); |
| 313 |
|
|
IoFLAGS(gp->gp_io) |= IOf_ARGV|IOf_START; |
| 314 |
|
|
} |
| 315 |
|
|
GvGP(gv) = gp_ref(gp); |
| 316 |
|
|
GvSV(gv) = NEWSV(72,0); |
| 317 |
|
|
GvLINE(gv) = CopLINE(PL_curcop); |
| 318 |
|
|
GvFILE(gv) = CopFILE(PL_curcop) ? CopFILE(PL_curcop) : ""; |
| 319 |
|
|
GvEGV(gv) = gv; |
| 320 |
|
|
} |
| 321 |
|
|
else { |
| 322 |
|
|
gp_ref(GvGP(gv)); |
| 323 |
|
|
GvINTRO_on(gv); |
| 324 |
|
|
} |
| 325 |
|
|
} |
| 326 |
|
|
|
| 327 |
|
|
AV * |
| 328 |
|
|
Perl_save_ary(pTHX_ GV *gv) |
| 329 |
|
|
{ |
| 330 |
|
|
AV *oav = GvAVn(gv); |
| 331 |
|
|
AV *av; |
| 332 |
|
|
|
| 333 |
|
|
if (!AvREAL(oav) && AvREIFY(oav)) |
| 334 |
|
|
av_reify(oav); |
| 335 |
|
|
SSCHECK(3); |
| 336 |
|
|
SSPUSHPTR(gv); |
| 337 |
|
|
SSPUSHPTR(oav); |
| 338 |
|
|
SSPUSHINT(SAVEt_AV); |
| 339 |
|
|
|
| 340 |
|
|
GvAV(gv) = Null(AV*); |
| 341 |
|
|
av = GvAVn(gv); |
| 342 |
|
|
if (SvMAGIC(oav)) { |
| 343 |
|
|
SvMAGIC(av) = SvMAGIC(oav); |
| 344 |
|
|
SvFLAGS((SV*)av) |= SvMAGICAL(oav); |
| 345 |
|
|
SvMAGICAL_off(oav); |
| 346 |
|
|
SvMAGIC(oav) = 0; |
| 347 |
|
|
PL_localizing = 1; |
| 348 |
|
|
SvSETMAGIC((SV*)av); |
| 349 |
|
|
PL_localizing = 0; |
| 350 |
|
|
} |
| 351 |
|
|
return av; |
| 352 |
|
|
} |
| 353 |
|
|
|
| 354 |
|
|
HV * |
| 355 |
|
|
Perl_save_hash(pTHX_ GV *gv) |
| 356 |
|
|
{ |
| 357 |
|
|
HV *ohv, *hv; |
| 358 |
|
|
|
| 359 |
|
|
SSCHECK(3); |
| 360 |
|
|
SSPUSHPTR(gv); |
| 361 |
|
|
SSPUSHPTR(ohv = GvHVn(gv)); |
| 362 |
|
|
SSPUSHINT(SAVEt_HV); |
| 363 |
|
|
|
| 364 |
|
|
GvHV(gv) = Null(HV*); |
| 365 |
|
|
hv = GvHVn(gv); |
| 366 |
|
|
if (SvMAGIC(ohv)) { |
| 367 |
|
|
SvMAGIC(hv) = SvMAGIC(ohv); |
| 368 |
|
|
SvFLAGS((SV*)hv) |= SvMAGICAL(ohv); |
| 369 |
|
|
SvMAGICAL_off(ohv); |
| 370 |
|
|
SvMAGIC(ohv) = 0; |
| 371 |
|
|
PL_localizing = 1; |
| 372 |
|
|
SvSETMAGIC((SV*)hv); |
| 373 |
|
|
PL_localizing = 0; |
| 374 |
|
|
} |
| 375 |
|
|
return hv; |
| 376 |
|
|
} |
| 377 |
|
|
|
| 378 |
|
|
void |
| 379 |
|
|
Perl_save_item(pTHX_ register SV *item) |
| 380 |
|
|
{ |
| 381 |
|
|
register SV *sv = newSVsv(item); |
| 382 |
|
|
|
| 383 |
|
|
SSCHECK(3); |
| 384 |
|
|
SSPUSHPTR(item); /* remember the pointer */ |
| 385 |
|
|
SSPUSHPTR(sv); /* remember the value */ |
| 386 |
|
|
SSPUSHINT(SAVEt_ITEM); |
| 387 |
|
|
} |
| 388 |
|
|
|
| 389 |
|
|
void |
| 390 |
|
|
Perl_save_int(pTHX_ int *intp) |
| 391 |
|
|
{ |
| 392 |
|
|
SSCHECK(3); |
| 393 |
|
|
SSPUSHINT(*intp); |
| 394 |
|
|
SSPUSHPTR(intp); |
| 395 |
|
|
SSPUSHINT(SAVEt_INT); |
| 396 |
|
|
} |
| 397 |
|
|
|
| 398 |
|
|
void |
| 399 |
|
|
Perl_save_long(pTHX_ long int *longp) |
| 400 |
|
|
{ |
| 401 |
|
|
SSCHECK(3); |
| 402 |
|
|
SSPUSHLONG(*longp); |
| 403 |
|
|
SSPUSHPTR(longp); |
| 404 |
|
|
SSPUSHINT(SAVEt_LONG); |
| 405 |
|
|
} |
| 406 |
|
|
|
| 407 |
|
|
void |
| 408 |
|
|
Perl_save_bool(pTHX_ bool *boolp) |
| 409 |
|
|
{ |
| 410 |
|
|
SSCHECK(3); |
| 411 |
|
|
SSPUSHBOOL(*boolp); |
| 412 |
|
|
SSPUSHPTR(boolp); |
| 413 |
|
|
SSPUSHINT(SAVEt_BOOL); |
| 414 |
|
|
} |
| 415 |
|
|
|
| 416 |
|
|
void |
| 417 |
|
|
Perl_save_I32(pTHX_ I32 *intp) |
| 418 |
|
|
{ |
| 419 |
|
|
SSCHECK(3); |
| 420 |
|
|
SSPUSHINT(*intp); |
| 421 |
|
|
SSPUSHPTR(intp); |
| 422 |
|
|
SSPUSHINT(SAVEt_I32); |
| 423 |
|
|
} |
| 424 |
|
|
|
| 425 |
|
|
void |
| 426 |
|
|
Perl_save_I16(pTHX_ I16 *intp) |
| 427 |
|
|
{ |
| 428 |
|
|
SSCHECK(3); |
| 429 |
|
|
SSPUSHINT(*intp); |
| 430 |
|
|
SSPUSHPTR(intp); |
| 431 |
|
|
SSPUSHINT(SAVEt_I16); |
| 432 |
|
|
} |
| 433 |
|
|
|
| 434 |
|
|
void |
| 435 |
|
|
Perl_save_I8(pTHX_ I8 *bytep) |
| 436 |
|
|
{ |
| 437 |
|
|
SSCHECK(3); |
| 438 |
|
|
SSPUSHINT(*bytep); |
| 439 |
|
|
SSPUSHPTR(bytep); |
| 440 |
|
|
SSPUSHINT(SAVEt_I8); |
| 441 |
|
|
} |
| 442 |
|
|
|
| 443 |
|
|
void |
| 444 |
|
|
Perl_save_iv(pTHX_ IV *ivp) |
| 445 |
|
|
{ |
| 446 |
|
|
SSCHECK(3); |
| 447 |
|
|
SSPUSHIV(*ivp); |
| 448 |
|
|
SSPUSHPTR(ivp); |
| 449 |
|
|
SSPUSHINT(SAVEt_IV); |
| 450 |
|
|
} |
| 451 |
|
|
|
| 452 |
|
|
/* Cannot use save_sptr() to store a char* since the SV** cast will |
| 453 |
|
|
* force word-alignment and we'll miss the pointer. |
| 454 |
|
|
*/ |
| 455 |
|
|
void |
| 456 |
|
|
Perl_save_pptr(pTHX_ char **pptr) |
| 457 |
|
|
{ |
| 458 |
|
|
SSCHECK(3); |
| 459 |
|
|
SSPUSHPTR(*pptr); |
| 460 |
|
|
SSPUSHPTR(pptr); |
| 461 |
|
|
SSPUSHINT(SAVEt_PPTR); |
| 462 |
|
|
} |
| 463 |
|
|
|
| 464 |
|
|
void |
| 465 |
|
|
Perl_save_vptr(pTHX_ void *ptr) |
| 466 |
|
|
{ |
| 467 |
|
|
SSCHECK(3); |
| 468 |
|
|
SSPUSHPTR(*(char**)ptr); |
| 469 |
|
|
SSPUSHPTR(ptr); |
| 470 |
|
|
SSPUSHINT(SAVEt_VPTR); |
| 471 |
|
|
} |
| 472 |
|
|
|
| 473 |
|
|
void |
| 474 |
|
|
Perl_save_sptr(pTHX_ SV **sptr) |
| 475 |
|
|
{ |
| 476 |
|
|
SSCHECK(3); |
| 477 |
|
|
SSPUSHPTR(*sptr); |
| 478 |
|
|
SSPUSHPTR(sptr); |
| 479 |
|
|
SSPUSHINT(SAVEt_SPTR); |
| 480 |
|
|
} |
| 481 |
|
|
|
| 482 |
|
|
void |
| 483 |
|
|
Perl_save_padsv(pTHX_ PADOFFSET off) |
| 484 |
|
|
{ |
| 485 |
|
|
SSCHECK(4); |
| 486 |
|
|
ASSERT_CURPAD_ACTIVE("save_padsv"); |
| 487 |
|
|
SSPUSHPTR(PL_curpad[off]); |
| 488 |
|
|
SSPUSHPTR(PL_comppad); |
| 489 |
|
|
SSPUSHLONG((long)off); |
| 490 |
|
|
SSPUSHINT(SAVEt_PADSV); |
| 491 |
|
|
} |
| 492 |
|
|
|
| 493 |
|
|
SV ** |
| 494 |
|
|
Perl_save_threadsv(pTHX_ PADOFFSET i) |
| 495 |
|
|
{ |
| 496 |
|
|
#ifdef USE_5005THREADS |
| 497 |
|
|
SV **svp = &THREADSV(i); /* XXX Change to save by offset */ |
| 498 |
|
|
DEBUG_S(PerlIO_printf(Perl_debug_log, "save_threadsv %"UVuf": %p %p:%s\n", |
| 499 |
|
|
(UV)i, svp, *svp, SvPEEK(*svp))); |
| 500 |
|
|
save_svref(svp); |
| 501 |
|
|
return svp; |
| 502 |
|
|
#else |
| 503 |
|
|
Perl_croak(aTHX_ "panic: save_threadsv called in non-threaded perl"); |
| 504 |
|
|
return 0; |
| 505 |
|
|
#endif /* USE_5005THREADS */ |
| 506 |
|
|
} |
| 507 |
|
|
|
| 508 |
|
|
void |
| 509 |
|
|
Perl_save_nogv(pTHX_ GV *gv) |
| 510 |
|
|
{ |
| 511 |
|
|
SSCHECK(2); |
| 512 |
|
|
SSPUSHPTR(gv); |
| 513 |
|
|
SSPUSHINT(SAVEt_NSTAB); |
| 514 |
|
|
} |
| 515 |
|
|
|
| 516 |
|
|
void |
| 517 |
|
|
Perl_save_hptr(pTHX_ HV **hptr) |
| 518 |
|
|
{ |
| 519 |
|
|
SSCHECK(3); |
| 520 |
|
|
SSPUSHPTR(*hptr); |
| 521 |
|
|
SSPUSHPTR(hptr); |
| 522 |
|
|
SSPUSHINT(SAVEt_HPTR); |
| 523 |
|
|
} |
| 524 |
|
|
|
| 525 |
|
|
void |
| 526 |
|
|
Perl_save_aptr(pTHX_ AV **aptr) |
| 527 |
|
|
{ |
| 528 |
|
|
SSCHECK(3); |
| 529 |
|
|
SSPUSHPTR(*aptr); |
| 530 |
|
|
SSPUSHPTR(aptr); |
| 531 |
|
|
SSPUSHINT(SAVEt_APTR); |
| 532 |
|
|
} |
| 533 |
|
|
|
| 534 |
|
|
void |
| 535 |
|
|
Perl_save_freesv(pTHX_ SV *sv) |
| 536 |
|
|
{ |
| 537 |
|
|
SSCHECK(2); |
| 538 |
|
|
SSPUSHPTR(sv); |
| 539 |
|
|
SSPUSHINT(SAVEt_FREESV); |
| 540 |
|
|
} |
| 541 |
|
|
|
| 542 |
|
|
void |
| 543 |
|
|
Perl_save_mortalizesv(pTHX_ SV *sv) |
| 544 |
|
|
{ |
| 545 |
|
|
SSCHECK(2); |
| 546 |
|
|
SSPUSHPTR(sv); |
| 547 |
|
|
SSPUSHINT(SAVEt_MORTALIZESV); |
| 548 |
|
|
} |
| 549 |
|
|
|
| 550 |
|
|
void |
| 551 |
|
|
Perl_save_freeop(pTHX_ OP *o) |
| 552 |
|
|
{ |
| 553 |
|
|
SSCHECK(2); |
| 554 |
|
|
SSPUSHPTR(o); |
| 555 |
|
|
SSPUSHINT(SAVEt_FREEOP); |
| 556 |
|
|
} |
| 557 |
|
|
|
| 558 |
|
|
void |
| 559 |
|
|
Perl_save_freepv(pTHX_ char *pv) |
| 560 |
|
|
{ |
| 561 |
|
|
SSCHECK(2); |
| 562 |
|
|
SSPUSHPTR(pv); |
| 563 |
|
|
SSPUSHINT(SAVEt_FREEPV); |
| 564 |
|
|
} |
| 565 |
|
|
|
| 566 |
|
|
void |
| 567 |
|
|
Perl_save_clearsv(pTHX_ SV **svp) |
| 568 |
|
|
{ |
| 569 |
|
|
ASSERT_CURPAD_ACTIVE("save_clearsv"); |
| 570 |
|
|
SSCHECK(2); |
| 571 |
|
|
SSPUSHLONG((long)(svp-PL_curpad)); |
| 572 |
|
|
SSPUSHINT(SAVEt_CLEARSV); |
| 573 |
|
|
} |
| 574 |
|
|
|
| 575 |
|
|
void |
| 576 |
|
|
Perl_save_delete(pTHX_ HV *hv, char *key, I32 klen) |
| 577 |
|
|
{ |
| 578 |
|
|
SSCHECK(4); |
| 579 |
|
|
SSPUSHINT(klen); |
| 580 |
|
|
SSPUSHPTR(key); |
| 581 |
|
|
SSPUSHPTR(SvREFCNT_inc(hv)); |
| 582 |
|
|
SSPUSHINT(SAVEt_DELETE); |
| 583 |
|
|
} |
| 584 |
|
|
|
| 585 |
|
|
void |
| 586 |
|
|
Perl_save_list(pTHX_ register SV **sarg, I32 maxsarg) |
| 587 |
|
|
{ |
| 588 |
|
|
register SV *sv; |
| 589 |
|
|
register I32 i; |
| 590 |
|
|
|
| 591 |
|
|
for (i = 1; i <= maxsarg; i++) { |
| 592 |
|
|
sv = NEWSV(0,0); |
| 593 |
|
|
sv_setsv(sv,sarg[i]); |
| 594 |
|
|
SSCHECK(3); |
| 595 |
|
|
SSPUSHPTR(sarg[i]); /* remember the pointer */ |
| 596 |
|
|
SSPUSHPTR(sv); /* remember the value */ |
| 597 |
|
|
SSPUSHINT(SAVEt_ITEM); |
| 598 |
|
|
} |
| 599 |
|
|
} |
| 600 |
|
|
|
| 601 |
|
|
void |
| 602 |
|
|
Perl_save_destructor(pTHX_ DESTRUCTORFUNC_NOCONTEXT_t f, void* p) |
| 603 |
|
|
{ |
| 604 |
|
|
SSCHECK(3); |
| 605 |
|
|
SSPUSHDPTR(f); |
| 606 |
|
|
SSPUSHPTR(p); |
| 607 |
|
|
SSPUSHINT(SAVEt_DESTRUCTOR); |
| 608 |
|
|
} |
| 609 |
|
|
|
| 610 |
|
|
void |
| 611 |
|
|
Perl_save_destructor_x(pTHX_ DESTRUCTORFUNC_t f, void* p) |
| 612 |
|
|
{ |
| 613 |
|
|
SSCHECK(3); |
| 614 |
|
|
SSPUSHDXPTR(f); |
| 615 |
|
|
SSPUSHPTR(p); |
| 616 |
|
|
SSPUSHINT(SAVEt_DESTRUCTOR_X); |
| 617 |
|
|
} |
| 618 |
|
|
|
| 619 |
|
|
void |
| 620 |
|
|
Perl_save_aelem(pTHX_ AV *av, I32 idx, SV **sptr) |
| 621 |
|
|
{ |
| 622 |
|
|
SV *sv; |
| 623 |
|
|
SSCHECK(4); |
| 624 |
|
|
SSPUSHPTR(SvREFCNT_inc(av)); |
| 625 |
|
|
SSPUSHINT(idx); |
| 626 |
|
|
SSPUSHPTR(SvREFCNT_inc(*sptr)); |
| 627 |
|
|
SSPUSHINT(SAVEt_AELEM); |
| 628 |
|
|
/* if it gets reified later, the restore will have the wrong refcnt */ |
| 629 |
|
|
if (!AvREAL(av) && AvREIFY(av)) |
| 630 |
|
|
SvREFCNT_inc(*sptr); |
| 631 |
|
|
save_scalar_at(sptr); |
| 632 |
|
|
sv = *sptr; |
| 633 |
|
|
/* If we're localizing a tied array element, this new sv |
| 634 |
|
|
* won't actually be stored in the array - so it won't get |
| 635 |
|
|
* reaped when the localize ends. Ensure it gets reaped by |
| 636 |
|
|
* mortifying it instead. DAPM */ |
| 637 |
|
|
if (SvTIED_mg(sv, PERL_MAGIC_tiedelem)) |
| 638 |
|
|
sv_2mortal(sv); |
| 639 |
|
|
} |
| 640 |
|
|
|
| 641 |
|
|
void |
| 642 |
|
|
Perl_save_helem(pTHX_ HV *hv, SV *key, SV **sptr) |
| 643 |
|
|
{ |
| 644 |
|
|
SV *sv; |
| 645 |
|
|
SSCHECK(4); |
| 646 |
|
|
SSPUSHPTR(SvREFCNT_inc(hv)); |
| 647 |
|
|
SSPUSHPTR(SvREFCNT_inc(key)); |
| 648 |
|
|
SSPUSHPTR(SvREFCNT_inc(*sptr)); |
| 649 |
|
|
SSPUSHINT(SAVEt_HELEM); |
| 650 |
|
|
save_scalar_at(sptr); |
| 651 |
|
|
sv = *sptr; |
| 652 |
|
|
/* If we're localizing a tied hash element, this new sv |
| 653 |
|
|
* won't actually be stored in the hash - so it won't get |
| 654 |
|
|
* reaped when the localize ends. Ensure it gets reaped by |
| 655 |
|
|
* mortifying it instead. DAPM */ |
| 656 |
|
|
if (SvTIED_mg(sv, PERL_MAGIC_tiedelem)) |
| 657 |
|
|
sv_2mortal(sv); |
| 658 |
|
|
} |
| 659 |
|
|
|
| 660 |
|
|
void |
| 661 |
|
|
Perl_save_op(pTHX) |
| 662 |
|
|
{ |
| 663 |
|
|
SSCHECK(2); |
| 664 |
|
|
SSPUSHPTR(PL_op); |
| 665 |
|
|
SSPUSHINT(SAVEt_OP); |
| 666 |
|
|
} |
| 667 |
|
|
|
| 668 |
|
|
I32 |
| 669 |
|
|
Perl_save_alloc(pTHX_ I32 size, I32 pad) |
| 670 |
|
|
{ |
| 671 |
|
|
register I32 start = pad + ((char*)&PL_savestack[PL_savestack_ix] |
| 672 |
|
|
- (char*)PL_savestack); |
| 673 |
|
|
register I32 elems = 1 + ((size + pad - 1) / sizeof(*PL_savestack)); |
| 674 |
|
|
|
| 675 |
|
|
/* SSCHECK may not be good enough */ |
| 676 |
|
|
while (PL_savestack_ix + elems + 2 > PL_savestack_max) |
| 677 |
|
|
savestack_grow(); |
| 678 |
|
|
|
| 679 |
|
|
PL_savestack_ix += elems; |
| 680 |
|
|
SSPUSHINT(elems); |
| 681 |
|
|
SSPUSHINT(SAVEt_ALLOC); |
| 682 |
|
|
return start; |
| 683 |
|
|
} |
| 684 |
|
|
|
| 685 |
|
|
void |
| 686 |
|
|
Perl_leave_scope(pTHX_ I32 base) |
| 687 |
|
|
{ |
| 688 |
|
|
register SV *sv; |
| 689 |
|
|
register SV *value; |
| 690 |
|
|
register GV *gv; |
| 691 |
|
|
register AV *av; |
| 692 |
|
|
register HV *hv; |
| 693 |
|
|
register void* ptr; |
| 694 |
|
|
register char* str; |
| 695 |
|
|
I32 i; |
| 696 |
|
|
|
| 697 |
|
|
if (base < -1) |
| 698 |
|
|
Perl_croak(aTHX_ "panic: corrupt saved stack index"); |
| 699 |
|
|
while (PL_savestack_ix > base) { |
| 700 |
|
|
switch (SSPOPINT) { |
| 701 |
|
|
case SAVEt_ITEM: /* normal string */ |
| 702 |
|
|
value = (SV*)SSPOPPTR; |
| 703 |
|
|
sv = (SV*)SSPOPPTR; |
| 704 |
|
|
sv_replace(sv,value); |
| 705 |
|
|
PL_localizing = 2; |
| 706 |
|
|
SvSETMAGIC(sv); |
| 707 |
|
|
PL_localizing = 0; |
| 708 |
|
|
break; |
| 709 |
|
|
case SAVEt_SV: /* scalar reference */ |
| 710 |
|
|
value = (SV*)SSPOPPTR; |
| 711 |
|
|
gv = (GV*)SSPOPPTR; |
| 712 |
|
|
ptr = &GvSV(gv); |
| 713 |
|
|
av = (AV*)gv; /* what to refcnt_dec */ |
| 714 |
|
|
goto restore_sv; |
| 715 |
|
|
case SAVEt_GENERIC_PVREF: /* generic pv */ |
| 716 |
|
|
str = (char*)SSPOPPTR; |
| 717 |
|
|
ptr = SSPOPPTR; |
| 718 |
|
|
if (*(char**)ptr != str) { |
| 719 |
|
|
Safefree(*(char**)ptr); |
| 720 |
|
|
*(char**)ptr = str; |
| 721 |
|
|
} |
| 722 |
|
|
break; |
| 723 |
|
|
case SAVEt_SHARED_PVREF: /* shared pv */ |
| 724 |
|
|
str = (char*)SSPOPPTR; |
| 725 |
|
|
ptr = SSPOPPTR; |
| 726 |
|
|
if (*(char**)ptr != str) { |
| 727 |
|
|
#ifdef NETWARE |
| 728 |
|
|
PerlMem_free(*(char**)ptr); |
| 729 |
|
|
#else |
| 730 |
|
|
PerlMemShared_free(*(char**)ptr); |
| 731 |
|
|
#endif |
| 732 |
|
|
*(char**)ptr = str; |
| 733 |
|
|
} |
| 734 |
|
|
break; |
| 735 |
|
|
case SAVEt_GENERIC_SVREF: /* generic sv */ |
| 736 |
|
|
value = (SV*)SSPOPPTR; |
| 737 |
|
|
ptr = SSPOPPTR; |
| 738 |
|
|
sv = *(SV**)ptr; |
| 739 |
|
|
*(SV**)ptr = value; |
| 740 |
|
|
SvREFCNT_dec(sv); |
| 741 |
|
|
SvREFCNT_dec(value); |
| 742 |
|
|
break; |
| 743 |
|
|
case SAVEt_SVREF: /* scalar reference */ |
| 744 |
|
|
value = (SV*)SSPOPPTR; |
| 745 |
|
|
ptr = SSPOPPTR; |
| 746 |
|
|
av = Nullav; /* what to refcnt_dec */ |
| 747 |
|
|
restore_sv: |
| 748 |
|
|
sv = *(SV**)ptr; |
| 749 |
|
|
DEBUG_S(PerlIO_printf(Perl_debug_log, |
| 750 |
|
|
"restore svref: %p %p:%s -> %p:%s\n", |
| 751 |
|
|
ptr, sv, SvPEEK(sv), value, SvPEEK(value))); |
| 752 |
|
|
if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv) && |
| 753 |
|
|
SvTYPE(sv) != SVt_PVGV) |
| 754 |
|
|
{ |
| 755 |
|
|
(void)SvUPGRADE(value, SvTYPE(sv)); |
| 756 |
|
|
SvMAGIC(value) = SvMAGIC(sv); |
| 757 |
|
|
SvFLAGS(value) |= SvMAGICAL(sv); |
| 758 |
|
|
SvMAGICAL_off(sv); |
| 759 |
|
|
SvMAGIC(sv) = 0; |
| 760 |
|
|
} |
| 761 |
|
|
/* XXX This branch is pretty bogus. This code irretrievably |
| 762 |
|
|
* clears(!) the magic on the SV (either to avoid further |
| 763 |
|
|
* croaking that might ensue when the SvSETMAGIC() below is |
| 764 |
|
|
* called, or to avoid two different SVs pointing at the same |
| 765 |
|
|
* SvMAGIC()). This needs a total rethink. --GSAR */ |
| 766 |
|
|
else if (SvTYPE(value) >= SVt_PVMG && SvMAGIC(value) && |
| 767 |
|
|
SvTYPE(value) != SVt_PVGV) |
| 768 |
|
|
{ |
| 769 |
|
|
SvFLAGS(value) |= (SvFLAGS(value) & |
| 770 |
|
|
(SVp_NOK|SVp_POK)) >> PRIVSHIFT; |
| 771 |
|
|
SvMAGICAL_off(value); |
| 772 |
|
|
/* XXX this is a leak when we get here because the |
| 773 |
|
|
* mg_get() in save_scalar_at() croaked */ |
| 774 |
|
|
SvMAGIC(value) = 0; |
| 775 |
|
|
} |
| 776 |
|
|
*(SV**)ptr = value; |
| 777 |
|
|
SvREFCNT_dec(sv); |
| 778 |
|
|
PL_localizing = 2; |
| 779 |
|
|
SvSETMAGIC(value); |
| 780 |
|
|
PL_localizing = 0; |
| 781 |
|
|
SvREFCNT_dec(value); |
| 782 |
|
|
if (av) /* actually an av, hv or gv */ |
| 783 |
|
|
SvREFCNT_dec(av); |
| 784 |
|
|
break; |
| 785 |
|
|
case SAVEt_AV: /* array reference */ |
| 786 |
|
|
av = (AV*)SSPOPPTR; |
| 787 |
|
|
gv = (GV*)SSPOPPTR; |
| 788 |
|
|
if (GvAV(gv)) { |
| 789 |
|
|
AV *goner = GvAV(gv); |
| 790 |
|
|
SvMAGIC(av) = SvMAGIC(goner); |
| 791 |
|
|
SvFLAGS((SV*)av) |= SvMAGICAL(goner); |
| 792 |
|
|
SvMAGICAL_off(goner); |
| 793 |
|
|
SvMAGIC(goner) = 0; |
| 794 |
|
|
SvREFCNT_dec(goner); |
| 795 |
|
|
} |
| 796 |
|
|
GvAV(gv) = av; |
| 797 |
|
|
if (SvMAGICAL(av)) { |
| 798 |
|
|
PL_localizing = 2; |
| 799 |
|
|
SvSETMAGIC((SV*)av); |
| 800 |
|
|
PL_localizing = 0; |
| 801 |
|
|
} |
| 802 |
|
|
break; |
| 803 |
|
|
case SAVEt_HV: /* hash reference */ |
| 804 |
|
|
hv = (HV*)SSPOPPTR; |
| 805 |
|
|
gv = (GV*)SSPOPPTR; |
| 806 |
|
|
if (GvHV(gv)) { |
| 807 |
|
|
HV *goner = GvHV(gv); |
| 808 |
|
|
SvMAGIC(hv) = SvMAGIC(goner); |
| 809 |
|
|
SvFLAGS(hv) |= SvMAGICAL(goner); |
| 810 |
|
|
SvMAGICAL_off(goner); |
| 811 |
|
|
SvMAGIC(goner) = 0; |
| 812 |
|
|
SvREFCNT_dec(goner); |
| 813 |
|
|
} |
| 814 |
|
|
GvHV(gv) = hv; |
| 815 |
|
|
if (SvMAGICAL(hv)) { |
| 816 |
|
|
PL_localizing = 2; |
| 817 |
|
|
SvSETMAGIC((SV*)hv); |
| 818 |
|
|
PL_localizing = 0; |
| 819 |
|
|
} |
| 820 |
|
|
break; |
| 821 |
|
|
case SAVEt_INT: /* int reference */ |
| 822 |
|
|
ptr = SSPOPPTR; |
| 823 |
|
|
*(int*)ptr = (int)SSPOPINT; |
| 824 |
|
|
break; |
| 825 |
|
|
case SAVEt_LONG: /* long reference */ |
| 826 |
|
|
ptr = SSPOPPTR; |
| 827 |
|
|
*(long*)ptr = (long)SSPOPLONG; |
| 828 |
|
|
break; |
| 829 |
|
|
case SAVEt_BOOL: /* bool reference */ |
| 830 |
|
|
ptr = SSPOPPTR; |
| 831 |
|
|
*(bool*)ptr = (bool)SSPOPBOOL; |
| 832 |
|
|
break; |
| 833 |
|
|
case SAVEt_I32: /* I32 reference */ |
| 834 |
|
|
ptr = SSPOPPTR; |
| 835 |
|
|
*(I32*)ptr = (I32)SSPOPINT; |
| 836 |
|
|
break; |
| 837 |
|
|
case SAVEt_I16: /* I16 reference */ |
| 838 |
|
|
ptr = SSPOPPTR; |
| 839 |
|
|
*(I16*)ptr = (I16)SSPOPINT; |
| 840 |
|
|
break; |
| 841 |
|
|
case SAVEt_I8: /* I8 reference */ |
| 842 |
|
|
ptr = SSPOPPTR; |
| 843 |
|
|
*(I8*)ptr = (I8)SSPOPINT; |
| 844 |
|
|
break; |
| 845 |
|
|
case SAVEt_IV: /* IV reference */ |
| 846 |
|
|
ptr = SSPOPPTR; |
| 847 |
|
|
*(IV*)ptr = (IV)SSPOPIV; |
| 848 |
|
|
break; |
| 849 |
|
|
case SAVEt_SPTR: /* SV* reference */ |
| 850 |
|
|
ptr = SSPOPPTR; |
| 851 |
|
|
*(SV**)ptr = (SV*)SSPOPPTR; |
| 852 |
|
|
break; |
| 853 |
|
|
case SAVEt_VPTR: /* random* reference */ |
| 854 |
|
|
case SAVEt_PPTR: /* char* reference */ |
| 855 |
|
|
ptr = SSPOPPTR; |
| 856 |
|
|
*(char**)ptr = (char*)SSPOPPTR; |
| 857 |
|
|
break; |
| 858 |
|
|
case SAVEt_HPTR: /* HV* reference */ |
| 859 |
|
|
ptr = SSPOPPTR; |
| 860 |
|
|
*(HV**)ptr = (HV*)SSPOPPTR; |
| 861 |
|
|
break; |
| 862 |
|
|
case SAVEt_APTR: /* AV* reference */ |
| 863 |
|
|
ptr = SSPOPPTR; |
| 864 |
|
|
*(AV**)ptr = (AV*)SSPOPPTR; |
| 865 |
|
|
break; |
| 866 |
|
|
case SAVEt_NSTAB: |
| 867 |
|
|
gv = (GV*)SSPOPPTR; |
| 868 |
|
|
(void)sv_clear((SV*)gv); |
| 869 |
|
|
break; |
| 870 |
|
|
case SAVEt_GP: /* scalar reference */ |
| 871 |
|
|
ptr = SSPOPPTR; |
| 872 |
|
|
gv = (GV*)SSPOPPTR; |
| 873 |
|
|
if (SvPVX(gv) && SvLEN(gv) > 0) { |
| 874 |
|
|
Safefree(SvPVX(gv)); |
| 875 |
|
|
} |
| 876 |
|
|
SvPVX(gv) = (char *)SSPOPPTR; |
| 877 |
|
|
SvCUR(gv) = (STRLEN)SSPOPIV; |
| 878 |
|
|
SvLEN(gv) = (STRLEN)SSPOPIV; |
| 879 |
|
|
gp_free(gv); |
| 880 |
|
|
GvGP(gv) = (GP*)ptr; |
| 881 |
|
|
if (GvCVu(gv)) |
| 882 |
|
|
PL_sub_generation++; /* putting a method back into circulation */ |
| 883 |
|
|
SvREFCNT_dec(gv); |
| 884 |
|
|
break; |
| 885 |
|
|
case SAVEt_FREESV: |
| 886 |
|
|
ptr = SSPOPPTR; |
| 887 |
|
|
SvREFCNT_dec((SV*)ptr); |
| 888 |
|
|
break; |
| 889 |
|
|
case SAVEt_MORTALIZESV: |
| 890 |
|
|
ptr = SSPOPPTR; |
| 891 |
|
|
sv_2mortal((SV*)ptr); |
| 892 |
|
|
break; |
| 893 |
|
|
case SAVEt_FREEOP: |
| 894 |
|
|
ptr = SSPOPPTR; |
| 895 |
|
|
ASSERT_CURPAD_LEGAL("SAVEt_FREEOP"); /* XXX DAPM tmp */ |
| 896 |
|
|
op_free((OP*)ptr); |
| 897 |
|
|
break; |
| 898 |
|
|
case SAVEt_FREEPV: |
| 899 |
|
|
ptr = SSPOPPTR; |
| 900 |
|
|
Safefree((char*)ptr); |
| 901 |
|
|
break; |
| 902 |
|
|
case SAVEt_CLEARSV: |
| 903 |
|
|
ptr = (void*)&PL_curpad[SSPOPLONG]; |
| 904 |
|
|
sv = *(SV**)ptr; |
| 905 |
|
|
|
| 906 |
|
|
DEBUG_Xv(PerlIO_printf(Perl_debug_log, |
| 907 |
|
|
"Pad 0x%"UVxf"[0x%"UVxf"] clearsv: %ld sv=0x%"UVxf"<%"IVdf"> %s\n", |
| 908 |
|
|
PTR2UV(PL_comppad), PTR2UV(PL_curpad), |
| 909 |
|
|
(long)((SV **)ptr-PL_curpad), PTR2UV(sv), (IV)SvREFCNT(sv), |
| 910 |
|
|
(SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) ? "clear" : "abandon" |
| 911 |
|
|
)); |
| 912 |
|
|
|
| 913 |
|
|
/* Can clear pad variable in place? */ |
| 914 |
|
|
if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) { |
| 915 |
|
|
/* |
| 916 |
|
|
* if a my variable that was made readonly is going out of |
| 917 |
|
|
* scope, we want to remove the readonlyness so that it can |
| 918 |
|
|
* go out of scope quietly |
| 919 |
|
|
*/ |
| 920 |
|
|
if (SvPADMY(sv) && !SvFAKE(sv)) |
| 921 |
|
|
SvREADONLY_off(sv); |
| 922 |
|
|
|
| 923 |
|
|
if (SvTHINKFIRST(sv)) |
| 924 |
|
|
sv_force_normal_flags(sv, SV_IMMEDIATE_UNREF); |
| 925 |
|
|
if (SvMAGICAL(sv)) |
| 926 |
|
|
mg_free(sv); |
| 927 |
|
|
|
| 928 |
|
|
switch (SvTYPE(sv)) { |
| 929 |
|
|
case SVt_NULL: |
| 930 |
|
|
break; |
| 931 |
|
|
case SVt_PVAV: |
| 932 |
|
|
av_clear((AV*)sv); |
| 933 |
|
|
break; |
| 934 |
|
|
case SVt_PVHV: |
| 935 |
|
|
hv_clear((HV*)sv); |
| 936 |
|
|
break; |
| 937 |
|
|
case SVt_PVCV: |
| 938 |
|
|
Perl_croak(aTHX_ "panic: leave_scope pad code"); |
| 939 |
|
|
default: |
| 940 |
|
|
SvOK_off(sv); |
| 941 |
|
|
break; |
| 942 |
|
|
} |
| 943 |
|
|
} |
| 944 |
|
|
else { /* Someone has a claim on this, so abandon it. */ |
| 945 |
|
|
U32 padflags = SvFLAGS(sv) & (SVs_PADBUSY|SVs_PADMY|SVs_PADTMP); |
| 946 |
|
|
switch (SvTYPE(sv)) { /* Console ourselves with a new value */ |
| 947 |
|
|
case SVt_PVAV: *(SV**)ptr = (SV*)newAV(); break; |
| 948 |
|
|
case SVt_PVHV: *(SV**)ptr = (SV*)newHV(); break; |
| 949 |
|
|
default: *(SV**)ptr = NEWSV(0,0); break; |
| 950 |
|
|
} |
| 951 |
|
|
SvREFCNT_dec(sv); /* Cast current value to the winds. */ |
| 952 |
|
|
SvFLAGS(*(SV**)ptr) |= padflags; /* preserve pad nature */ |
| 953 |
|
|
} |
| 954 |
|
|
break; |
| 955 |
|
|
case SAVEt_DELETE: |
| 956 |
|
|
ptr = SSPOPPTR; |
| 957 |
|
|
hv = (HV*)ptr; |
| 958 |
|
|
ptr = SSPOPPTR; |
| 959 |
|
|
(void)hv_delete(hv, (char*)ptr, (U32)SSPOPINT, G_DISCARD); |
| 960 |
|
|
SvREFCNT_dec(hv); |
| 961 |
|
|
Safefree(ptr); |
| 962 |
|
|
break; |
| 963 |
|
|
case SAVEt_DESTRUCTOR: |
| 964 |
|
|
ptr = SSPOPPTR; |
| 965 |
|
|
(*SSPOPDPTR)(ptr); |
| 966 |
|
|
break; |
| 967 |
|
|
case SAVEt_DESTRUCTOR_X: |
| 968 |
|
|
ptr = SSPOPPTR; |
| 969 |
|
|
(*SSPOPDXPTR)(aTHX_ ptr); |
| 970 |
|
|
break; |
| 971 |
|
|
case SAVEt_REGCONTEXT: |
| 972 |
|
|
case SAVEt_ALLOC: |
| 973 |
|
|
i = SSPOPINT; |
| 974 |
|
|
PL_savestack_ix -= i; /* regexp must have croaked */ |
| 975 |
|
|
break; |
| 976 |
|
|
case SAVEt_STACK_POS: /* Position on Perl stack */ |
| 977 |
|
|
i = SSPOPINT; |
| 978 |
|
|
PL_stack_sp = PL_stack_base + i; |
| 979 |
|
|
break; |
| 980 |
|
|
case SAVEt_AELEM: /* array element */ |
| 981 |
|
|
value = (SV*)SSPOPPTR; |
| 982 |
|
|
i = SSPOPINT; |
| 983 |
|
|
av = (AV*)SSPOPPTR; |
| 984 |
|
|
if (!AvREAL(av) && AvREIFY(av)) /* undo reify guard */ |
| 985 |
|
|
SvREFCNT_dec(value); |
| 986 |
|
|
ptr = av_fetch(av,i,1); |
| 987 |
|
|
if (ptr) { |
| 988 |
|
|
sv = *(SV**)ptr; |
| 989 |
|
|
if (sv && sv != &PL_sv_undef) { |
| 990 |
|
|
if (SvTIED_mg((SV*)av, PERL_MAGIC_tied)) |
| 991 |
|
|
(void)SvREFCNT_inc(sv); |
| 992 |
|
|
goto restore_sv; |
| 993 |
|
|
} |
| 994 |
|
|
} |
| 995 |
|
|
SvREFCNT_dec(av); |
| 996 |
|
|
SvREFCNT_dec(value); |
| 997 |
|
|
break; |
| 998 |
|
|
case SAVEt_HELEM: /* hash element */ |
| 999 |
|
|
value = (SV*)SSPOPPTR; |
| 1000 |
|
|
sv = (SV*)SSPOPPTR; |
| 1001 |
|
|
hv = (HV*)SSPOPPTR; |
| 1002 |
|
|
ptr = hv_fetch_ent(hv, sv, 1, 0); |
| 1003 |
|
|
if (ptr) { |
| 1004 |
|
|
SV *oval = HeVAL((HE*)ptr); |
| 1005 |
|
|
if (oval && oval != &PL_sv_undef) { |
| 1006 |
|
|
ptr = &HeVAL((HE*)ptr); |
| 1007 |
|
|
if (SvTIED_mg((SV*)hv, PERL_MAGIC_tied)) |
| 1008 |
|
|
(void)SvREFCNT_inc(*(SV**)ptr); |
| 1009 |
|
|
SvREFCNT_dec(sv); |
| 1010 |
|
|
av = (AV*)hv; /* what to refcnt_dec */ |
| 1011 |
|
|
goto restore_sv; |
| 1012 |
|
|
} |
| 1013 |
|
|
} |
| 1014 |
|
|
SvREFCNT_dec(hv); |
| 1015 |
|
|
SvREFCNT_dec(sv); |
| 1016 |
|
|
SvREFCNT_dec(value); |
| 1017 |
|
|
break; |
| 1018 |
|
|
case SAVEt_OP: |
| 1019 |
|
|
PL_op = (OP*)SSPOPPTR; |
| 1020 |
|
|
break; |
| 1021 |
|
|
case SAVEt_HINTS: |
| 1022 |
|
|
if ((PL_hints & HINT_LOCALIZE_HH) && GvHV(PL_hintgv)) { |
| 1023 |
|
|
SvREFCNT_dec((SV*)GvHV(PL_hintgv)); |
| 1024 |
|
|
GvHV(PL_hintgv) = NULL; |
| 1025 |
|
|
} |
| 1026 |
|
|
*(I32*)&PL_hints = (I32)SSPOPINT; |
| 1027 |
|
|
if (PL_hints & HINT_LOCALIZE_HH) { |
| 1028 |
|
|
SvREFCNT_dec((SV*)GvHV(PL_hintgv)); |
| 1029 |
|
|
GvHV(PL_hintgv) = (HV*)SSPOPPTR; |
| 1030 |
|
|
} |
| 1031 |
|
|
|
| 1032 |
|
|
break; |
| 1033 |
|
|
case SAVEt_COMPPAD: |
| 1034 |
|
|
PL_comppad = (PAD*)SSPOPPTR; |
| 1035 |
|
|
if (PL_comppad) |
| 1036 |
|
|
PL_curpad = AvARRAY(PL_comppad); |
| 1037 |
|
|
else |
| 1038 |
|
|
PL_curpad = Null(SV**); |
| 1039 |
|
|
break; |
| 1040 |
|
|
case SAVEt_PADSV: |
| 1041 |
|
|
{ |
| 1042 |
|
|
PADOFFSET off = (PADOFFSET)SSPOPLONG; |
| 1043 |
|
|
ptr = SSPOPPTR; |
| 1044 |
|
|
if (ptr) |
| 1045 |
|
|
AvARRAY((PAD*)ptr)[off] = (SV*)SSPOPPTR; |
| 1046 |
|
|
} |
| 1047 |
|
|
break; |
| 1048 |
|
|
case SAVEt_SAVESWITCHSTACK: |
| 1049 |
|
|
{ |
| 1050 |
|
|
dSP; |
| 1051 |
|
|
AV* t = (AV*)SSPOPPTR; |
| 1052 |
|
|
AV* f = (AV*)SSPOPPTR; |
| 1053 |
|
|
SWITCHSTACK(t,f); |
| 1054 |
|
|
PL_curstackinfo->si_stack = f; |
| 1055 |
|
|
} |
| 1056 |
|
|
break; |
| 1057 |
|
|
default: |
| 1058 |
|
|
Perl_croak(aTHX_ "panic: leave_scope inconsistency"); |
| 1059 |
|
|
} |
| 1060 |
|
|
} |
| 1061 |
|
|
} |
| 1062 |
|
|
|
| 1063 |
|
|
void |
| 1064 |
|
|
Perl_cx_dump(pTHX_ PERL_CONTEXT *cx) |
| 1065 |
|
|
{ |
| 1066 |
|
|
#ifdef DEBUGGING |
| 1067 |
|
|
PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), PL_block_type[CxTYPE(cx)]); |
| 1068 |
|
|
if (CxTYPE(cx) != CXt_SUBST) { |
| 1069 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp); |
| 1070 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%"UVxf"\n", |
| 1071 |
|
|
PTR2UV(cx->blk_oldcop)); |
| 1072 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp); |
| 1073 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_OLDSCOPESP = %ld\n", (long)cx->blk_oldscopesp); |
| 1074 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_OLDRETSP = %ld\n", (long)cx->blk_oldretsp); |
| 1075 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%"UVxf"\n", |
| 1076 |
|
|
PTR2UV(cx->blk_oldpm)); |
| 1077 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR"); |
| 1078 |
|
|
} |
| 1079 |
|
|
switch (CxTYPE(cx)) { |
| 1080 |
|
|
case CXt_NULL: |
| 1081 |
|
|
case CXt_BLOCK: |
| 1082 |
|
|
break; |
| 1083 |
|
|
case CXt_FORMAT: |
| 1084 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%"UVxf"\n", |
| 1085 |
|
|
PTR2UV(cx->blk_sub.cv)); |
| 1086 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_SUB.GV = 0x%"UVxf"\n", |
| 1087 |
|
|
PTR2UV(cx->blk_sub.gv)); |
| 1088 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_SUB.DFOUTGV = 0x%"UVxf"\n", |
| 1089 |
|
|
PTR2UV(cx->blk_sub.dfoutgv)); |
| 1090 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n", |
| 1091 |
|
|
(int)cx->blk_sub.hasargs); |
| 1092 |
|
|
break; |
| 1093 |
|
|
case CXt_SUB: |
| 1094 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_SUB.CV = 0x%"UVxf"\n", |
| 1095 |
|
|
PTR2UV(cx->blk_sub.cv)); |
| 1096 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_SUB.OLDDEPTH = %ld\n", |
| 1097 |
|
|
(long)cx->blk_sub.olddepth); |
| 1098 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_SUB.HASARGS = %d\n", |
| 1099 |
|
|
(int)cx->blk_sub.hasargs); |
| 1100 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_SUB.LVAL = %d\n", |
| 1101 |
|
|
(int)cx->blk_sub.lval); |
| 1102 |
|
|
break; |
| 1103 |
|
|
case CXt_EVAL: |
| 1104 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n", |
| 1105 |
|
|
(long)cx->blk_eval.old_in_eval); |
| 1106 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n", |
| 1107 |
|
|
PL_op_name[cx->blk_eval.old_op_type], |
| 1108 |
|
|
PL_op_desc[cx->blk_eval.old_op_type]); |
| 1109 |
|
|
if (cx->blk_eval.old_namesv) |
| 1110 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n", |
| 1111 |
|
|
SvPVX(cx->blk_eval.old_namesv)); |
| 1112 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%"UVxf"\n", |
| 1113 |
|
|
PTR2UV(cx->blk_eval.old_eval_root)); |
| 1114 |
|
|
break; |
| 1115 |
|
|
|
| 1116 |
|
|
case CXt_LOOP: |
| 1117 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n", |
| 1118 |
|
|
cx->blk_loop.label); |
| 1119 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_LOOP.RESETSP = %ld\n", |
| 1120 |
|
|
(long)cx->blk_loop.resetsp); |
| 1121 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_LOOP.REDO_OP = 0x%"UVxf"\n", |
| 1122 |
|
|
PTR2UV(cx->blk_loop.redo_op)); |
| 1123 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_LOOP.NEXT_OP = 0x%"UVxf"\n", |
| 1124 |
|
|
PTR2UV(cx->blk_loop.next_op)); |
| 1125 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_LOOP.LAST_OP = 0x%"UVxf"\n", |
| 1126 |
|
|
PTR2UV(cx->blk_loop.last_op)); |
| 1127 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERIX = %ld\n", |
| 1128 |
|
|
(long)cx->blk_loop.iterix); |
| 1129 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERARY = 0x%"UVxf"\n", |
| 1130 |
|
|
PTR2UV(cx->blk_loop.iterary)); |
| 1131 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERVAR = 0x%"UVxf"\n", |
| 1132 |
|
|
PTR2UV(CxITERVAR(cx))); |
| 1133 |
|
|
if (CxITERVAR(cx)) |
| 1134 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERSAVE = 0x%"UVxf"\n", |
| 1135 |
|
|
PTR2UV(cx->blk_loop.itersave)); |
| 1136 |
|
|
PerlIO_printf(Perl_debug_log, "BLK_LOOP.ITERLVAL = 0x%"UVxf"\n", |
| 1137 |
|
|
PTR2UV(cx->blk_loop.iterlval)); |
| 1138 |
|
|
break; |
| 1139 |
|
|
|
| 1140 |
|
|
case CXt_SUBST: |
| 1141 |
|
|
PerlIO_printf(Perl_debug_log, "SB_ITERS = %ld\n", |
| 1142 |
|
|
(long)cx->sb_iters); |
| 1143 |
|
|
PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n", |
| 1144 |
|
|
(long)cx->sb_maxiters); |
| 1145 |
|
|
PerlIO_printf(Perl_debug_log, "SB_RFLAGS = %ld\n", |
| 1146 |
|
|
(long)cx->sb_rflags); |
| 1147 |
|
|
PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n", |
| 1148 |
|
|
(long)cx->sb_once); |
| 1149 |
|
|
PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n", |
| 1150 |
|
|
cx->sb_orig); |
| 1151 |
|
|
PerlIO_printf(Perl_debug_log, "SB_DSTR = 0x%"UVxf"\n", |
| 1152 |
|
|
PTR2UV(cx->sb_dstr)); |
| 1153 |
|
|
PerlIO_printf(Perl_debug_log, "SB_TARG = 0x%"UVxf"\n", |
| 1154 |
|
|
PTR2UV(cx->sb_targ)); |
| 1155 |
|
|
PerlIO_printf(Perl_debug_log, "SB_S = 0x%"UVxf"\n", |
| 1156 |
|
|
PTR2UV(cx->sb_s)); |
| 1157 |
|
|
PerlIO_printf(Perl_debug_log, "SB_M = 0x%"UVxf"\n", |
| 1158 |
|
|
PTR2UV(cx->sb_m)); |
| 1159 |
|
|
PerlIO_printf(Perl_debug_log, "SB_STREND = 0x%"UVxf"\n", |
| 1160 |
|
|
PTR2UV(cx->sb_strend)); |
| 1161 |
|
|
PerlIO_printf(Perl_debug_log, "SB_RXRES = 0x%"UVxf"\n", |
| 1162 |
|
|
PTR2UV(cx->sb_rxres)); |
| 1163 |
|
|
break; |
| 1164 |
|
|
} |
| 1165 |
|
|
#endif /* DEBUGGING */ |
| 1166 |
|
|
} |
| 1167 |
|
|
|
| 1168 |
|
|
/* |
| 1169 |
|
|
* Local variables: |
| 1170 |
|
|
* c-indentation-style: bsd |
| 1171 |
|
|
* c-basic-offset: 4 |
| 1172 |
|
|
* indent-tabs-mode: t |
| 1173 |
|
|
* End: |
| 1174 |
|
|
* |
| 1175 |
|
|
* vim: shiftwidth=4: |
| 1176 |
|
|
*/ |