X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=scope.c;h=d0646bc248252e3507c7532e5aa34cfcc92752e9;hb=9e42cd940458e44df25d811d7ba17ca86ab5c8c5;hp=e976f3c9fae554dc86d6f60803256e6f2bde1e03;hpb=0e5484613ee35059bacf1903360ea858c68d8ed9;p=p5sagit%2Fp5-mst-13.2.git diff --git a/scope.c b/scope.c index e976f3c..d0646bc 100644 --- a/scope.c +++ b/scope.c @@ -1,6 +1,6 @@ /* scope.c * - * Copyright (c) 1991-2001, Larry Wall + * Copyright (c) 1991-2002, Larry Wall * * You may distribute under the terms of either the GNU General Public * License or the Artistic License, as specified in the README file. @@ -254,6 +254,18 @@ Perl_save_generic_pvref(pTHX_ char **str) SSPUSHINT(SAVEt_GENERIC_PVREF); } +/* Like save_generic_pvref(), but uses PerlMemShared_free() rather than Safefree(). + * Can be used to restore a shared global char* to its prior + * contents, freeing new value. */ +void +Perl_save_shared_pvref(pTHX_ char **str) +{ + SSCHECK(3); + SSPUSHPTR(str); + SSPUSHPTR(*str); + SSPUSHINT(SAVEt_SHARED_PVREF); +} + void Perl_save_gp(pTHX_ GV *gv, I32 empty) { @@ -657,6 +669,14 @@ Perl_leave_scope(pTHX_ I32 base) *(char**)ptr = str; } break; + case SAVEt_SHARED_PVREF: /* shared pv */ + str = (char*)SSPOPPTR; + ptr = SSPOPPTR; + if (*(char**)ptr != str) { + PerlMemShared_free(*(char**)ptr); + *(char**)ptr = str; + } + break; case SAVEt_GENERIC_SVREF: /* generic sv */ value = (SV*)SSPOPPTR; ptr = SSPOPPTR; @@ -673,7 +693,9 @@ Perl_leave_scope(pTHX_ I32 base) DEBUG_S(PerlIO_printf(Perl_debug_log, "restore svref: %p %p:%s -> %p:%s\n", ptr, sv, SvPEEK(sv), value, SvPEEK(value))); - if (SvTYPE(sv) == SVt_PVMG && SvMAGIC(sv)) { + if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv) && + SvTYPE(sv) != SVt_PVGV) + { (void)SvUPGRADE(value, SvTYPE(sv)); SvMAGIC(value) = SvMAGIC(sv); SvFLAGS(value) |= SvMAGICAL(sv); @@ -685,7 +707,9 @@ Perl_leave_scope(pTHX_ I32 base) * croaking that might ensue when the SvSETMAGIC() below is * called, or to avoid two different SVs pointing at the same * SvMAGIC()). This needs a total rethink. --GSAR */ - else if (SvTYPE(value) == SVt_PVMG && SvMAGIC(value)) { + else if (SvTYPE(value) >= SVt_PVMG && SvMAGIC(value) && + SvTYPE(value) != SVt_PVGV) + { SvFLAGS(value) |= (SvFLAGS(value) & (SVp_NOK|SVp_POK)) >> PRIVSHIFT; SvMAGICAL_off(value);