From: Vincent Pit Date: Thu, 19 Feb 2009 20:17:00 +0000 (+0100) Subject: Explicitely pass the flags to vmg_cb_call(). Also pass data in the va_args X-Git-Tag: v0.31~1 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=9882f778c50f889617229a8f2093dc10502de766;p=perl%2Fmodules%2FVariable-Magic.git Explicitely pass the flags to vmg_cb_call(). Also pass data in the va_args --- diff --git a/Magic.xs b/Magic.xs index 28873dd..3b9adfc 100644 --- a/Magic.xs +++ b/Magic.xs @@ -565,7 +565,7 @@ STATIC SV *vmg_op_info(pTHX_ unsigned int opinfo) { #define VMG_CB_CALL_ARGS_SHIFT 4 #define VMG_CB_CALL_OPINFO (VMG_OP_INFO_NAME|VMG_OP_INFO_OBJECT) -STATIC int vmg_cb_call(pTHX_ SV *cb, SV *sv, SV *data, unsigned int flags, ...){ +STATIC int vmg_cb_call(pTHX_ SV *cb, unsigned int flags, SV *sv, ...) { va_list ap; int ret; unsigned int i, args, opinfo; @@ -580,10 +580,9 @@ STATIC int vmg_cb_call(pTHX_ SV *cb, SV *sv, SV *data, unsigned int flags, ...){ SAVETMPS; PUSHMARK(SP); - EXTEND(SP, args + 2); + EXTEND(SP, args + 1); PUSHs(sv_2mortal(newRV_inc(sv))); - PUSHs(data ? data : &PL_sv_undef); - va_start(ap, flags); + va_start(ap, sv); for (i = 0; i < args; ++i) { SV *sva = va_arg(ap, SV *); PUSHs(sva ? sva : &PL_sv_undef); @@ -603,23 +602,21 @@ STATIC int vmg_cb_call(pTHX_ SV *cb, SV *sv, SV *data, unsigned int flags, ...){ return ret; } -#define vmg_cb_call1(I, S, D) \ - vmg_cb_call(aTHX_ (I), (S), (D), (flags << VMG_CB_CALL_ARGS_SHIFT)) -#define vmg_cb_call2(I, S, D, S2) \ - vmg_cb_call(aTHX_ (I), (S), (D), ((flags << VMG_CB_CALL_ARGS_SHIFT) | 1), (S2)) -#define vmg_cb_call3(I, S, D, S2, S3) \ - vmg_cb_call(aTHX_ (I), (S), (D), ((flags << VMG_CB_CALL_ARGS_SHIFT) | 2), (S2), (S3)) +#define vmg_cb_call1(I, F, S, A1) \ + vmg_cb_call(aTHX_ (I), (((F) << VMG_CB_CALL_ARGS_SHIFT) | 1), (S), (A1)) +#define vmg_cb_call2(I, F, S, A1, A2) \ + vmg_cb_call(aTHX_ (I), (((F) << VMG_CB_CALL_ARGS_SHIFT) | 2), (S), (A1), (A2)) +#define vmg_cb_call3(I, F, S, A1, A2, A3) \ + vmg_cb_call(aTHX_ (I), (((F) << VMG_CB_CALL_ARGS_SHIFT) | 3), (S), (A1), (A2), (A3)) STATIC int vmg_svt_get(pTHX_ SV *sv, MAGIC *mg) { const MGWIZ *w = SV2MGWIZ(mg->mg_ptr); - unsigned int flags = w->opinfo; - return vmg_cb_call1(w->cb_get, sv, mg->mg_obj); + return vmg_cb_call1(w->cb_get, w->opinfo, sv, mg->mg_obj); } STATIC int vmg_svt_set(pTHX_ SV *sv, MAGIC *mg) { const MGWIZ *w = SV2MGWIZ(mg->mg_ptr); - unsigned int flags = w->opinfo; - return vmg_cb_call1(w->cb_set, sv, mg->mg_obj); + return vmg_cb_call1(w->cb_set, w->opinfo, sv, mg->mg_obj); } STATIC U32 vmg_svt_len(pTHX_ SV *sv, MAGIC *mg) { @@ -668,8 +665,7 @@ STATIC U32 vmg_svt_len(pTHX_ SV *sv, MAGIC *mg) { STATIC int vmg_svt_clear(pTHX_ SV *sv, MAGIC *mg) { const MGWIZ *w = SV2MGWIZ(mg->mg_ptr); - unsigned int flags = w->opinfo; - return vmg_cb_call1(w->cb_clear, sv, mg->mg_obj); + return vmg_cb_call1(w->cb_clear, w->opinfo, sv, mg->mg_obj); } STATIC int vmg_svt_free(pTHX_ SV *sv, MAGIC *mg) { @@ -750,7 +746,6 @@ STATIC int vmg_svt_copy(pTHX_ SV *sv, MAGIC *mg, SV *nsv, const char *key, ) { SV *keysv; const MGWIZ *w = SV2MGWIZ(mg->mg_ptr); - unsigned int flags = w->opinfo; int ret; if (keylen == HEf_SVKEY) { @@ -759,7 +754,7 @@ STATIC int vmg_svt_copy(pTHX_ SV *sv, MAGIC *mg, SV *nsv, const char *key, keysv = newSVpvn(key, keylen); } - ret = vmg_cb_call3(w->cb_copy, sv, mg->mg_obj, keysv, nsv); + ret = vmg_cb_call3(w->cb_copy, w->opinfo, sv, mg->mg_obj, keysv, nsv); if (keylen != HEf_SVKEY) { SvREFCNT_dec(keysv); @@ -778,8 +773,7 @@ STATIC int vmg_svt_dup(pTHX_ MAGIC *mg, CLONE_PARAMS *param) { #if MGf_LOCAL STATIC int vmg_svt_local(pTHX_ SV *nsv, MAGIC *mg) { const MGWIZ *w = SV2MGWIZ(mg->mg_ptr); - unsigned int flags = w->opinfo; - return vmg_cb_call1(w->cb_local, nsv, mg->mg_obj); + return vmg_cb_call1(w->cb_local, w->opinfo, nsv, mg->mg_obj); } #endif /* MGf_LOCAL */ @@ -806,7 +800,6 @@ STATIC I32 vmg_svt_val(pTHX_ IV action, SV *sv) { action &= HV_FETCH_ISSTORE | HV_FETCH_ISEXISTS | HV_FETCH_LVALUE | HV_DELETE; for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) { const MGWIZ *w; - unsigned int flags; switch (mg->mg_type) { case PERL_MAGIC_ext: break; @@ -819,7 +812,6 @@ STATIC I32 vmg_svt_val(pTHX_ IV action, SV *sv) { if (mg->mg_private < SIG_MIN || mg->mg_private > SIG_MAX) continue; w = SV2MGWIZ(mg->mg_ptr); - flags = w->opinfo; switch (w->uvar) { case 0: continue; @@ -829,18 +821,22 @@ STATIC I32 vmg_svt_val(pTHX_ IV action, SV *sv) { } switch (action) { case 0: - if (w->cb_fetch) { vmg_cb_call2(w->cb_fetch, sv, mg->mg_obj, key); } + if (w->cb_fetch) + vmg_cb_call2(w->cb_fetch, w->opinfo, sv, mg->mg_obj, key); break; case HV_FETCH_ISSTORE: case HV_FETCH_LVALUE: case (HV_FETCH_ISSTORE|HV_FETCH_LVALUE): - if (w->cb_store) { vmg_cb_call2(w->cb_store, sv, mg->mg_obj, key); } + if (w->cb_store) + vmg_cb_call2(w->cb_store, w->opinfo, sv, mg->mg_obj, key); break; case HV_FETCH_ISEXISTS: - if (w->cb_exists) { vmg_cb_call2(w->cb_exists, sv, mg->mg_obj, key); } + if (w->cb_exists) + vmg_cb_call2(w->cb_exists, w->opinfo, sv, mg->mg_obj, key); break; case HV_DELETE: - if (w->cb_delete) { vmg_cb_call2(w->cb_delete, sv, mg->mg_obj, key); } + if (w->cb_delete) + vmg_cb_call2(w->cb_delete, w->opinfo, sv, mg->mg_obj, key); break; } }