From: Vincent Pit Date: Fri, 27 Nov 2009 11:13:53 +0000 (+0100) Subject: Make the wizard store the MGWIZ address as an IV X-Git-Tag: v0.39~13 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=c82a0127ec7ea6da80e943d0bf32bcf4052f429c;p=perl%2Fmodules%2FVariable-Magic.git Make the wizard store the MGWIZ address as an IV Also, since we validated the wizard, use SvIVX to read the address. That way, we no longer need to pass the interpreter to vmg_find(). This results also in some consting goodness. --- diff --git a/Magic.xs b/Magic.xs index caff817..70b2617 100644 --- a/Magic.xs +++ b/Magic.xs @@ -533,7 +533,7 @@ STATIC MGVTBL vmg_wizard_vtbl = { STATIC SV *vmg_wizard_new(pTHX_ const MGWIZ *w) { #define vmg_wizard_new(W) vmg_wizard_new(aTHX_ (W)) - SV *wiz = newSVuv(PTR2UV(w)); + SV *wiz = newSVuv(PTR2IV(w)); if (w) { MAGIC *mg = sv_magicext(wiz, NULL, PERL_MAGIC_ext, &vmg_wizard_vtbl, NULL, 0); @@ -544,7 +544,7 @@ STATIC SV *vmg_wizard_new(pTHX_ const MGWIZ *w) { return wiz; } -STATIC SV *vmg_wizard_validate(pTHX_ SV *wiz) { +STATIC const SV *vmg_wizard_validate(pTHX_ const SV *wiz) { #define vmg_wizard_validate(W) vmg_wizard_validate(aTHX_ (W)) if (SvROK(wiz)) { wiz = SvRV(wiz); @@ -555,7 +555,7 @@ STATIC SV *vmg_wizard_validate(pTHX_ SV *wiz) { croak(vmg_invalid_wiz); } -#define vmg_wizard_id(W) SvUV((SV *) (W)) +#define vmg_wizard_id(W) SvIVX((const SV *) (W)) #define vmg_wizard_main_mgwiz(W) INT2PTR(const MGWIZ *, vmg_wizard_id(W)) /* ... Wizard destructor ................................................... */ @@ -582,8 +582,8 @@ STATIC int vmg_wizard_free(pTHX_ SV *sv, MAGIC *mg) { #if VMG_THREADSAFE -STATIC const MGWIZ *vmg_wizard_mgwiz(pTHX_ SV *wiz) { -#define vmg_wizard_mgwiz(W) vmg_wizard_mgwiz(aTHX_ ((SV *) (W))) +STATIC const MGWIZ *vmg_wizard_mgwiz(pTHX_ const SV *wiz) { +#define vmg_wizard_mgwiz(W) vmg_wizard_mgwiz(aTHX_ ((const SV *) (W))) const MGWIZ *w; w = vmg_wizard_main_mgwiz(wiz); @@ -604,8 +604,7 @@ STATIC const MGWIZ *vmg_wizard_mgwiz(pTHX_ SV *wiz) { /* --- User-level functions implementation --------------------------------- */ -STATIC const MAGIC *vmg_find(pTHX_ const SV *sv, SV *wiz) { -#define vmg_find(S, W) vmg_find(aTHX_ (S), (W)) +STATIC const MAGIC *vmg_find(const SV *sv, const SV *wiz) { const MAGIC *mg, *moremagic; UV wid; @@ -661,7 +660,7 @@ STATIC SV *vmg_data_new(pTHX_ SV *ctor, SV *sv, AV *args) { return nsv; } -STATIC SV *vmg_data_get(pTHX_ SV *sv, SV *wiz) { +STATIC SV *vmg_data_get(pTHX_ SV *sv, const SV *wiz) { #define vmg_data_get(S, W) vmg_data_get(aTHX_ (S), (W)) const MAGIC *mg = vmg_find(sv, wiz); return mg ? mg->mg_obj : NULL; @@ -684,7 +683,7 @@ STATIC void vmg_uvar_del(SV *sv, MAGIC *prevmagic, MAGIC *mg, MAGIC *moremagic) } #endif /* VMG_UVAR */ -STATIC UV vmg_cast(pTHX_ SV *sv, SV *wiz, AV *args) { +STATIC UV vmg_cast(pTHX_ SV *sv, const SV *wiz, AV *args) { #define vmg_cast(S, W, A) vmg_cast(aTHX_ (S), (W), (A)) MAGIC *mg, *moremagic = NULL; SV *data; @@ -766,7 +765,7 @@ done: return 1; } -STATIC UV vmg_dispell(pTHX_ SV *sv, SV *wiz) { +STATIC UV vmg_dispell(pTHX_ SV *sv, const SV *wiz) { #define vmg_dispell(S, W) vmg_dispell(aTHX_ (S), (W)) #if VMG_UVAR U32 uvars = 0; @@ -1426,7 +1425,6 @@ PREINIT: AV *args = NULL; SV *ret; CODE: - wiz = vmg_wizard_validate(wiz); if (items > 2) { I32 i; args = newAV(); @@ -1437,7 +1435,7 @@ CODE: if (av_store(args, i - 2, arg) == NULL) croak(vmg_argstorefailed); } } - ret = newSVuv(vmg_cast(SvRV(sv), wiz, args)); + ret = newSVuv(vmg_cast(SvRV(sv), vmg_wizard_validate(wiz), args)); SvREFCNT_dec(args); RETVAL = ret; OUTPUT: @@ -1449,8 +1447,7 @@ PROTOTYPE: \[$@%&*]$ PREINIT: SV *data; PPCODE: - wiz = vmg_wizard_validate(wiz); - data = vmg_data_get(SvRV(sv), wiz); + data = vmg_data_get(SvRV(sv), vmg_wizard_validate(wiz)); if (!data) XSRETURN_EMPTY; ST(0) = data; @@ -1459,7 +1456,6 @@ PPCODE: SV *dispell(SV *sv, SV *wiz) PROTOTYPE: \[$@%&*]$ CODE: - wiz = vmg_wizard_validate(wiz); - RETVAL = newSVuv(vmg_dispell(SvRV(sv), wiz)); + RETVAL = newSVuv(vmg_dispell(SvRV(sv), vmg_wizard_validate(wiz))); OUTPUT: RETVAL