X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=autovivification.xs;h=a8367a0a961e07b2f0b8665f4dec351e0c92e12d;hb=212cf2f8511a55f57224f4e043d2328a1f840693;hp=ae8db121e2527d6c57bfdc0b0511111068ecb857;hpb=68e31f8ce73ddedf82977b4e05ec550c1cfe5688;p=perl%2Fmodules%2Fautovivification.git diff --git a/autovivification.xs b/autovivification.xs index ae8db12..a8367a0 100644 --- a/autovivification.xs +++ b/autovivification.xs @@ -33,13 +33,10 @@ while (len > 0) \ (U) = ((U) << 8) | (B)[--len]; -STATIC SV *a_tag(pTHX_ UV bits) { -#define a_tag(B) a_tag(aTHX_ (B)) - SV *hint; +#if A_WORKAROUND_REQUIRE_PROPAGATION +STATIC UV a_require_tag(pTHX) { +#define a_require_tag() a_require_tag(aTHX) const PERL_SI *si; - UV requires = 0; - unsigned char buf[sizeof(UV) * 2]; - STRLEN len; for (si = PL_curstackinfo; si; si = si->si_prev) { I32 cxix; @@ -48,11 +45,24 @@ STATIC SV *a_tag(pTHX_ UV bits) { const PERL_CONTEXT *cx = si->si_cxstack + cxix; if (CxTYPE(cx) == CXt_EVAL && cx->blk_eval.old_op_type == OP_REQUIRE) - ++requires; + return PTR2UV(cx); } } - A_ENCODE_UV(buf, requires); + return PTR2UV(NULL); +} +#endif /* A_WORKAROUND_REQUIRE_PROPAGATION */ + +STATIC SV *a_tag(pTHX_ UV bits) { +#define a_tag(B) a_tag(aTHX_ (B)) + SV *hint; + const PERL_SI *si; + UV cxreq; + unsigned char buf[sizeof(UV) * 2]; + STRLEN len; + + cxreq = a_require_tag(); + A_ENCODE_UV(buf, cxreq); A_ENCODE_UV(buf + sizeof(UV), bits); hint = newSVpvn(buf, sizeof buf); SvREADONLY_on(hint); @@ -63,7 +73,7 @@ STATIC SV *a_tag(pTHX_ UV bits) { STATIC UV a_detag(pTHX_ const SV *hint) { #define a_detag(H) a_detag(aTHX_ (H)) const PERL_SI *si; - UV requires = 0, requires_max = 0, bits = 0; + UV cxreq = 0, bits = 0; unsigned char *buf; STRLEN len; @@ -71,21 +81,12 @@ STATIC UV a_detag(pTHX_ const SV *hint) { return 0; buf = SvPVX(hint); - A_DECODE_UV(requires_max, buf); - - for (si = PL_curstackinfo; si; si = si->si_prev) { - I32 cxix; - for (cxix = si->si_cxix; cxix >= 0; --cxix) { - const PERL_CONTEXT *cx = si->si_cxstack + cxix; - - if (CxTYPE(cx) == CXt_EVAL && cx->blk_eval.old_op_type == OP_REQUIRE - && ++requires > requires_max) - return 0; - } - } + A_DECODE_UV(cxreq, buf); + if (a_require_tag() != cxreq) + return 0; - A_DECODE_UV(bits, buf + sizeof(UV)); + A_DECODE_UV(bits, buf + sizeof(UV)); return bits; } @@ -93,7 +94,18 @@ STATIC UV a_detag(pTHX_ const SV *hint) { #else /* A_WORKAROUND_REQUIRE_PROPAGATION */ #define a_tag(B) newSVuv(B) -#define a_detag(H) (((H) && SvOK(H)) ? SvUVX(H) : 0) +/* PVs fetched from the hints chain have their SvLEN set to zero, so get the UV + * from a copy. */ +#define a_detag(H) \ + ((H) \ + ? (SvIOK(H) \ + ? SvUVX(H) \ + : (SvPOK(H) \ + ? sv_2uv(SvLEN(H) ? (H) : sv_mortalcopy(H)) \ + : 0 \ + ) \ + ) \ + : 0) #endif /* !A_WORKAROUND_REQUIRE_PROPAGATION */