From: Vincent Pit Date: Mon, 30 Nov 2009 20:02:04 +0000 (+0100) Subject: Stop passing arguments to the data callback through an AV X-Git-Tag: v0.39~7 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=480d76182c123d90242fc84e0ee3d94733f11a99;p=perl%2Fmodules%2FVariable-Magic.git Stop passing arguments to the data callback through an AV --- diff --git a/Magic.xs b/Magic.xs index 35bc61c..6ec752b 100644 --- a/Magic.xs +++ b/Magic.xs @@ -609,10 +609,10 @@ STATIC const MAGIC *vmg_find(const SV *sv, const SV *wiz) { /* ... Construct private data .............................................. */ -STATIC SV *vmg_data_new(pTHX_ SV *ctor, SV *sv, AV *args) { -#define vmg_data_new(C, S, A) vmg_data_new(aTHX_ (C), (S), (A)) +STATIC SV *vmg_data_new(pTHX_ SV *ctor, SV *sv, SV **args, I32 items) { +#define vmg_data_new(C, S, A, I) vmg_data_new(aTHX_ (C), (S), (A), (I)) + I32 i; SV *nsv; - I32 i, alen = (args == NULL) ? 0 : av_len(args); dSP; @@ -620,10 +620,10 @@ STATIC SV *vmg_data_new(pTHX_ SV *ctor, SV *sv, AV *args) { SAVETMPS; PUSHMARK(SP); - EXTEND(SP, alen + 1); + EXTEND(SP, items + 1); PUSHs(sv_2mortal(newRV_inc(sv))); - for (i = 0; i < alen; ++i) - PUSHs(*av_fetch(args, i, 0)); + for (i = 0; i < items; ++i) + PUSHs(args[i]); PUTBACK; call_sv(ctor, G_SCALAR); @@ -666,8 +666,8 @@ STATIC void vmg_uvar_del(SV *sv, MAGIC *prevmagic, MAGIC *mg, MAGIC *moremagic) } #endif /* VMG_UVAR */ -STATIC UV vmg_cast(pTHX_ SV *sv, const SV *wiz, AV *args) { -#define vmg_cast(S, W, A) vmg_cast(aTHX_ (S), (W), (A)) +STATIC UV vmg_cast(pTHX_ SV *sv, const SV *wiz, SV **args, I32 items) { +#define vmg_cast(S, W, A, I) vmg_cast(aTHX_ (S), (W), (A), (I)) MAGIC *mg, *moremagic = NULL; SV *data; const MGWIZ *w; @@ -679,7 +679,7 @@ STATIC UV vmg_cast(pTHX_ SV *sv, const SV *wiz, AV *args) { w = vmg_wizard_mgwiz(wiz); oldgmg = SvGMAGICAL(sv); - data = (w->cb_data) ? vmg_data_new(w->cb_data, sv, args) : NULL; + data = (w->cb_data) ? vmg_data_new(w->cb_data, sv, args, items) : NULL; mg = sv_magicext(sv, data, PERL_MAGIC_ext, w->vtbl, (const char *) wiz, HEf_SVKEY); mg->mg_private = SIG_WIZ; #if MGf_COPY @@ -1409,20 +1409,15 @@ OUTPUT: SV *cast(SV *sv, SV *wiz, ...) PROTOTYPE: \[$@%&*]$@ PREINIT: - AV *args = NULL; + SV **args = NULL; + I32 i = 0; SV *ret; CODE: if (items > 2) { - I32 i; - args = newAV(); - av_fill(args, items - 2); - for (i = 2; i < items; ++i) { - SV *arg = ST(i); - SvREFCNT_inc(arg); - if (av_store(args, i - 2, arg) == NULL) croak(vmg_argstorefailed); - } + i = items - 2; + args = &ST(2); } - ret = newSVuv(vmg_cast(SvRV(sv), vmg_wizard_validate(wiz), args)); + ret = newSVuv(vmg_cast(SvRV(sv), vmg_wizard_validate(wiz), args, i)); SvREFCNT_dec(args); RETVAL = ret; OUTPUT: