X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=Magic.xs;h=4574c23e83cdae060dd6f2b5b78503e15d892dc9;hb=bcc72c6633aec36f391f879f8145c48bf7c9c4dc;hp=6c5b61672c7f74af71b52f5adcc44cdd766bcaea;hpb=72f4e75c55424386dea278545b88d459fe9c9915;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/Magic.xs b/Magic.xs index 6c5b616..4574c23 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)) @@ -70,7 +72,7 @@ # define MY_CXT_CLONE NOOP #endif -#if VMG_MULTIPLICITY +#if VMG_THREADSAFE STATIC SV *vmg_clone(pTHX_ SV *sv, tTHX owner) { #define vmg_clone(P, O) vmg_clone(aTHX_ (P), (O)) @@ -81,7 +83,7 @@ STATIC SV *vmg_clone(pTHX_ SV *sv, tTHX owner) { return sv_dup(sv, ¶m); } -#endif /* VMG_MULTIPLICITY */ +#endif /* VMG_THREADSAFE */ /* --- Compatibility ------------------------------------------------------- */ @@ -316,7 +318,7 @@ STATIC UV vmg_cast(pTHX_ SV *sv, SV *wiz, AV *args) { if (w->cb_copy) mg->mg_flags |= MGf_COPY; #endif /* MGf_COPY */ -#if MGf_DUP +#if 0 /* MGf_DUP */ if (w->cb_dup) mg->mg_flags |= MGf_DUP; #endif /* MGf_DUP */ @@ -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); @@ -669,7 +677,7 @@ STATIC int vmg_wizard_free(pTHX_ SV *wiz, MAGIC *mg) { #if MGf_COPY if (w->cb_copy != NULL) { SvREFCNT_dec(SvRV(w->cb_copy)); } #endif /* MGf_COPY */ -#if MGf_DUP +#if 0 /* MGf_DUP */ if (w->cb_dup != NULL) { SvREFCNT_dec(SvRV(w->cb_dup)); } #endif /* MGf_DUP */ #if MGf_LOCAL @@ -792,7 +800,7 @@ STATIC SV *vmg_wizard_wiz(pTHX_ SV *wiz) { w->cb_ ## N = NULL; \ } -#if VMG_MULTIPLICITY +#if VMG_THREADSAFE #define VMG_CLONE_CB(N) \ z->cb_ ## N = (w->cb_ ## N) ? newRV_noinc(vmg_clone(SvRV(w->cb_ ## N), \ @@ -837,7 +845,7 @@ STATIC MGWIZ *vmg_wizard_clone(pTHX_ const MGWIZ *w) { return z; } -#endif /* VMG_MULTIPLICITY */ +#endif /* VMG_THREADSAFE */ /* --- XS ------------------------------------------------------------------ */ @@ -874,7 +882,6 @@ CLONE(...) PROTOTYPE: DISABLE PREINIT: HV *hv; - U16 count; CODE: #if VMG_THREADSAFE { @@ -883,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;