From: Nicholas Clark Date: Fri, 15 Oct 2004 17:11:08 +0000 (+0000) Subject: Implement sv_svset _nosteal variants by passing a flag into X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5fcdf167f4386a3583bf0db9d98b989639295a45;p=p5sagit%2Fp5-mst-13.2.git Implement sv_svset _nosteal variants by passing a flag into sv_set_flags rather than messing with the SvTEMP() flag on either side of the call. p4raw-id: //depot/perl@23373 --- diff --git a/sv.c b/sv.c index 3fac004..aec9802 100644 --- a/sv.c +++ b/sv.c @@ -4130,8 +4130,9 @@ function if the source SV needs to be reused. Does not handle 'set' magic. Loosely speaking, it performs a copy-by-value, obliterating any previous content of the destination. If the C parameter has the C bit set, will C on -C if appropriate, else not. C and C are -implemented in terms of this function. +C if appropriate, else not. If the C parameter has the +C bit set then the buffers of temps will not be stolen. +and C are implemented in terms of this function. You probably want to use one of the assortment of wrappers, such as C, C, C and @@ -4515,6 +4516,8 @@ Perl_sv_setsv_flags(pTHX_ SV *dstr, register SV *sstr, I32 flags) !(isSwipe = (sflags & SVs_TEMP) && /* slated for free anyway? */ !(sflags & SVf_OOK) && /* and not involved in OOK hack? */ + (!(flags & SV_NOSTEAL)) && + /* and we're allowed to steal temps */ SvREFCNT(sstr) == 1 && /* and no other references to it? */ SvLEN(sstr) && /* and really is a string */ /* and won't be needed again, potentially */ diff --git a/sv.h b/sv.h index c26da9d..e80c755 100644 --- a/sv.h +++ b/sv.h @@ -1103,6 +1103,7 @@ Like C but doesn't process magic. #define SV_GMAGIC 2 #define SV_COW_DROP_PV 4 #define SV_UTF8_NO_ENCODING 8 +#define SV_NOSTEAL 16 /* We are about to replace the SV's current value. So if it's copy on write we need to normalise it. Use the SV_COW_DROP_PV flag hint to say that @@ -1242,10 +1243,7 @@ Returns a pointer to the character buffer. #define SvSetSV_nosteal_and(dst,src,finally) \ STMT_START { \ if ((dst) != (src)) { \ - U32 tMpF = SvFLAGS(src) & SVs_TEMP; \ - SvTEMP_off(src); \ - sv_setsv(dst, src); \ - SvFLAGS(src) |= tMpF; \ + sv_setsv_flags(dst, src, SV_GMAGIC | SV_NOSTEAL); \ finally; \ } \ } STMT_END