X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=Magic.xs;h=3622e9031d715785621310644fcdc6d6e52d3c3e;hb=3d0d76b6305e2053de8a95afa896b2d72d5844be;hp=731c084da72274a381041bcc86dcf054795b723d;hpb=7b1220ee669f6512dea7d451111083763344094d;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/Magic.xs b/Magic.xs index 731c084..3622e90 100644 --- a/Magic.xs +++ b/Magic.xs @@ -38,13 +38,15 @@ # define dNOOP #endif -#if defined(MULTIPLICITY) || defined(PERL_IMPLICIT_CONTEXT) -# define VMG_MULTIPLICITY 1 -# ifndef tTHX -# define tTHX PerlInterpreter* +#ifndef VMG_MULTIPLICITY +# if defined(MULTIPLICITY) || defined(PERL_IMPLICIT_CONTEXT) +# define VMG_MULTIPLICITY 1 +# else +# define VMG_MULTIPLICITY 0 # endif -#else -# define VMG_MULTIPLICITY 0 +#endif +#if VMG_MULTIPLICITY && !defined(tTHX) +# define tTHX PerlInterpreter* #endif #if VMG_MULTIPLICITY && defined(dMY_CXT) && defined(MY_CXT) && defined(START_MY_CXT) && defined(MY_CXT_INIT) && (defined(MY_CXT_CLONE) || defined(dMY_CXT_SV)) @@ -548,6 +550,12 @@ STATIC int vmg_svt_clear(pTHX_ SV *sv, MAGIC *mg) { STATIC int vmg_svt_free(pTHX_ SV *sv, MAGIC *mg) { /* So that it can survive tmp cleanup in vmg_cb_call */ SvREFCNT_inc(sv); +#if !VMG_HAS_PERL_AND(32686, 5, 11, 0) + /* The previous magic tokens were freed but the magic chain wasn't updated, so + * if you access the sv from the callback the old deleted magics will trigger + * and cause memory misreads. Change 32686 solved it that way : */ + SvMAGIC_set(sv, mg); +#endif /* Perl_mg_free will get rid of the magic and decrement mg->mg_obj and * mg->mg_ptr reference count */ return vmg_cb_call1(SV2MGWIZ(mg->mg_ptr)->cb_free, sv, mg->mg_obj); @@ -652,8 +660,11 @@ STATIC int vmg_wizard_free(pTHX_ SV *wiz, MAGIC *mg) { w->owner = NULL; #endif /* VMG_MULTIPLICITY */ - dMY_CXT; - wiz = hv_delete(MY_CXT, buf, sprintf(buf, "%u", w->sig), 0); + { + dMY_CXT; + if (hv_delete(MY_CXT, buf, sprintf(buf, "%u", w->sig), 0) != wiz) + return 0; + } SvFLAGS(wiz) |= SVf_BREAK; FREETMPS; @@ -741,11 +752,11 @@ STATIC U16 vmg_wizard_sig(pTHX_ SV *wiz) { croak(vmg_invalid_wiz); } - dMY_CXT; - - if (!hv_fetch(MY_CXT, buf, sprintf(buf, "%u", sig), 0)) - sig = 0; - + { + dMY_CXT; + if (!hv_fetch(MY_CXT, buf, sprintf(buf, "%u", sig), 0)) + sig = 0; + } return sig; } @@ -768,10 +779,11 @@ STATIC SV *vmg_wizard_wiz(pTHX_ SV *wiz) { croak(vmg_invalid_wiz); } - dMY_CXT; - - return (old = hv_fetch(MY_CXT, buf, sprintf(buf, "%u", sig), 0)) - ? *old : NULL; + { + dMY_CXT; + return (old = hv_fetch(MY_CXT, buf, sprintf(buf, "%u", sig), 0)) + ? *old : NULL; + } } #define VMG_SET_CB(S, N) \ @@ -870,7 +882,6 @@ CLONE(...) PROTOTYPE: DISABLE PREINIT: HV *hv; - U16 count; CODE: #if VMG_THREADSAFE { @@ -879,12 +890,11 @@ CODE: hv = newHV(); hv_iterinit(hv); /* Allocate iterator */ hv_iterinit(MY_CXT); - while (key = hv_iternext(MY_CXT)) { + while ((key = hv_iternext(MY_CXT))) { STRLEN len; char *sig = HePV(key, len); SV *sv; MAGIC *mg; - MGWIZ *w; sv = MGWIZ2SV(vmg_wizard_clone(SV2MGWIZ(HeVAL(key)))); mg = sv_magicext(sv, NULL, PERL_MAGIC_ext, &vmg_wizard_vtbl, NULL, 0); mg->mg_private = SIG_WIZ;