From: Vincent Pit Date: Thu, 19 Feb 2009 15:54:07 +0000 (+0100) Subject: Factor the callback retval retrieval logic into a new VMG_CB_CALL_SET_RET() macro X-Git-Tag: v0.31~3 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=234cf62c8daa5de094f5cbf115037a313203ef5e;p=perl%2Fmodules%2FVariable-Magic.git Factor the callback retval retrieval logic into a new VMG_CB_CALL_SET_RET() macro --- diff --git a/Magic.xs b/Magic.xs index 48c8bdd..fd2046f 100644 --- a/Magic.xs +++ b/Magic.xs @@ -552,6 +552,15 @@ STATIC SV *vmg_op_info(pTHX_ unsigned int opinfo) { /* ... svt callbacks ....................................................... */ +#define VMG_CB_CALL_SET_RET(D) \ + { \ + SV *svr; \ + SPAGAIN; \ + svr = POPs; \ + ret = SvOK(svr) ? SvIV(svr) : (D); \ + PUTBACK; \ + } + #define VMG_CB_CALL_ARGS_MASK 15 #define VMG_CB_CALL_ARGS_SHIFT 4 #define VMG_CB_CALL_OPINFO (VMG_OP_INFO_NAME|VMG_OP_INFO_OBJECT) @@ -559,7 +568,6 @@ STATIC SV *vmg_op_info(pTHX_ unsigned int opinfo) { STATIC int vmg_cb_call(pTHX_ SV *cb, SV *sv, SV *data, unsigned int flags, ...){ va_list ap; - SV *svr; int ret; unsigned int i, args, opinfo, eval, has_err = 0; @@ -600,10 +608,7 @@ STATIC int vmg_cb_call(pTHX_ SV *cb, SV *sv, SV *data, unsigned int flags, ...){ ++PL_error_count; } - SPAGAIN; - svr = POPs; - ret = SvOK(svr) ? SvIV(svr) : 0; - PUTBACK; + VMG_CB_CALL_SET_RET(0); FREETMPS; LEAVE; @@ -640,7 +645,6 @@ STATIC int vmg_svt_set(pTHX_ SV *sv, MAGIC *mg) { } STATIC U32 vmg_svt_len(pTHX_ SV *sv, MAGIC *mg) { - SV *svr; const MGWIZ *w = SV2MGWIZ(mg->mg_ptr); unsigned int opinfo = w->opinfo; U32 len, ret; @@ -676,10 +680,7 @@ STATIC U32 vmg_svt_len(pTHX_ SV *sv, MAGIC *mg) { call_sv(w->cb_len, G_SCALAR); - SPAGAIN; - svr = POPs; - ret = SvOK(svr) ? SvUV(svr) : len; - PUTBACK; + VMG_CB_CALL_SET_RET(len); FREETMPS; LEAVE;