X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=Magic.xs;h=483431e9eaa6925e4561837fc1f26ab66d51e42d;hb=3dac6abb6d4dfdbfe07b780d8b856b1d74eac970;hp=f7917abcad8c9fbde616cc2dd3bcb32f75ffeecd;hpb=ebe9eedb7d7e7f6acaae37c8dbb5c373e9fb6026;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/Magic.xs b/Magic.xs index f7917ab..483431e 100644 --- a/Magic.xs +++ b/Magic.xs @@ -133,6 +133,20 @@ # define IN_PERL_COMPILETIME (PL_curcop == &PL_compiling) #endif +#ifndef OP_NAME +# define OP_NAME(O) (PL_op_name[(O)->op_type]) +#endif + +#ifndef OP_CLASS +# define OP_CLASS(O) (PL_opargs[(O)->op_type] & OA_CLASS_MASK) +#endif + +#ifdef DEBUGGING +# define VMG_ASSERT(C) assert(C) +#else +# define VMG_ASSERT(C) +#endif + /* uvar magic and Hash::Util::FieldHash were commited with 28419, but we only * enable them on 5.10 */ #if VMG_HAS_PERL(5, 10, 0) @@ -317,8 +331,7 @@ static MAGIC *vmg_sv_magicext(pTHX_ SV *sv, SV *obj, const MGVTBL *vtbl, const v static I32 vmg_call_sv(pTHX_ SV *sv, I32 flags, int (*cleanup)(pTHX_ void *), void *ud) { #define vmg_call_sv(S, F, C, U) vmg_call_sv(aTHX_ (S), (F), (C), (U)) - I32 ret, cxix; - PERL_CONTEXT saved_cx; + I32 ret; SV *old_err = NULL; if (SvTRUE(ERRSV)) { @@ -326,15 +339,8 @@ static I32 vmg_call_sv(pTHX_ SV *sv, I32 flags, int (*cleanup)(pTHX_ void *), vo sv_setsv(ERRSV, &PL_sv_undef); } - cxix = (cxstack_ix < cxstack_max) ? (cxstack_ix + 1) : Perl_cxinc(aTHX); - /* The last popped context will be reused by call_sv(), but our callers may - * still need its previous value. Back it up so that it isn't clobbered. */ - saved_cx = cxstack[cxix]; - ret = call_sv(sv, flags | G_EVAL); - cxstack[cxix] = saved_cx; - if (SvTRUE(ERRSV)) { SvREFCNT_dec(old_err); @@ -385,6 +391,9 @@ typedef enum { OPc_COP, #if VMG_HAS_PERL(5, 21, 5) OPc_METHOP, +#endif +#if VMG_HAS_PERL(5, 21, 7) + OPc_UNOP_AUX, #endif OPc_MAX } opclass; @@ -404,18 +413,27 @@ static const char *const vmg_opclassnames[] = { "B::COP", #if VMG_HAS_PERL(5, 21, 5) "B::METHOP", +#endif +#if VMG_HAS_PERL(5, 21, 7) + "B::UNOP_AUX", #endif NULL }; -static opclass vmg_opclass(const OP *o) { +static opclass vmg_opclass(pTHX_ const OP *o) { +#define vmg_opclass(O) vmg_opclass(aTHX_ (O)) #if 0 if (!o) return OPc_NULL; #endif - if (o->op_type == 0) + if (o->op_type == 0) { +#if VMG_HAS_PERL(5, 21, 7) + if (o->op_targ == OP_NEXTSTATE || o->op_targ == OP_DBSTATE) + return OPc_COP; +#endif return (o->op_flags & OPf_KIDS) ? OPc_UNOP : OPc_BASEOP; + } if (o->op_type == OP_SASSIGN) return ((o->op_private & OPpASSIGN_BACKWARDS) ? OPc_UNOP : OPc_BINOP); @@ -438,7 +456,7 @@ static opclass vmg_opclass(const OP *o) { return OPc_PADOP; #endif - switch (PL_opargs[o->op_type] & OA_CLASS_MASK) { + switch (OP_CLASS(o)) { case OA_BASEOP: return OPc_BASEOP; case OA_UNOP: @@ -456,7 +474,16 @@ static opclass vmg_opclass(const OP *o) { case OA_PADOP: return OPc_PADOP; case OA_PVOP_OR_SVOP: - return (o->op_private & (OPpTRANS_TO_UTF|OPpTRANS_FROM_UTF)) ? OPc_SVOP : OPc_PVOP; + return ( +#if VMG_HAS_PERL(5, 13, 7) + (o->op_type != OP_CUSTOM) && +#endif + (o->op_private & (OPpTRANS_TO_UTF|OPpTRANS_FROM_UTF))) +#if defined(USE_ITHREADS) && VMG_HAS_PERL(5, 8, 9) + ? OPc_PADOP : OPc_PVOP; +#else + ? OPc_SVOP : OPc_PVOP; +#endif case OA_LOOP: return OPc_LOOP; case OA_COP: @@ -480,6 +507,10 @@ static opclass vmg_opclass(const OP *o) { #if VMG_HAS_PERL(5, 21, 5) case OA_METHOP: return OPc_METHOP; +#endif +#if VMG_HAS_PERL(5, 21, 7) + case OA_UNOP_AUX: + return OPc_UNOP_AUX; #endif } @@ -818,6 +849,8 @@ static SV *vmg_data_new(pTHX_ SV *ctor, SV *sv, SV **args, I32 items) { ENTER; SAVETMPS; + PUSHSTACKi(PERLSI_MAGIC); + PUSHMARK(SP); EXTEND(SP, items + 1); PUSHs(sv_2mortal(newRV_inc(sv))); @@ -836,6 +869,8 @@ static SV *vmg_data_new(pTHX_ SV *ctor, SV *sv, SV **args, I32 items) { #endif PUTBACK; + POPSTACK; + FREETMPS; LEAVE; @@ -1117,8 +1152,12 @@ static SV *vmg_op_info(pTHX_ unsigned int opinfo) { switch (opinfo) { case VMG_OP_INFO_NAME: { - OPCODE t = PL_op->op_type; - return sv_2mortal(newSVpvn(PL_op_name[t], vmg_op_name_len[t])); + const char *name; + STRLEN name_len; + OPCODE t = PL_op->op_type; + name = OP_NAME(PL_op); + name_len = (t == OP_CUSTOM) ? strlen(name) : vmg_op_name_len[t]; + return sv_2mortal(newSVpvn(name, name_len)); } case VMG_OP_INFO_OBJECT: { dMY_CXT; @@ -1217,6 +1256,8 @@ static int vmg_cb_call(pTHX_ SV *cb, unsigned int flags, SV *sv, ...) { ENTER; SAVETMPS; + PUSHSTACKi(PERLSI_MAGIC); + PUSHMARK(SP); EXTEND(SP, args + 1); PUSHs(sv_2mortal(newRV_inc(sv))); @@ -1251,6 +1292,8 @@ static int vmg_cb_call(pTHX_ SV *cb, unsigned int flags, SV *sv, ...) { svr = NULL; PUTBACK; + POPSTACK; + FREETMPS; LEAVE; @@ -1327,6 +1370,8 @@ static U32 vmg_svt_len(pTHX_ SV *sv, MAGIC *mg) { ENTER; SAVETMPS; + PUSHSTACKi(PERLSI_MAGIC); + PUSHMARK(SP); EXTEND(SP, 3); PUSHs(sv_2mortal(newRV_inc(sv))); @@ -1354,6 +1399,8 @@ static U32 vmg_svt_len(pTHX_ SV *sv, MAGIC *mg) { --ret; PUTBACK; + POPSTACK; + FREETMPS; LEAVE; @@ -1528,6 +1575,8 @@ static int vmg_svt_free(pTHX_ SV *sv, MAGIC *mg) { ENTER; SAVETMPS; + PUSHSTACKi(PERLSI_MAGIC); + PUSHMARK(SP); EXTEND(SP, 2); PUSHs(sv_2mortal(newRV_inc(sv))); @@ -1555,6 +1604,8 @@ static int vmg_svt_free(pTHX_ SV *sv, MAGIC *mg) { ret = (int) SvIV(svr); PUTBACK; + POPSTACK; + FREETMPS; LEAVE; @@ -1861,7 +1912,7 @@ static void vmg_teardown(pTHX_ void *param) { vmg_sv_magicext((SV *) PL_strtab, NULL, &vmg_global_teardown_vtbl, NULL, 0); } } else { - assert(vmg_loaded > 1); + VMG_ASSERT(vmg_loaded > 1); --vmg_loaded; } @@ -1890,7 +1941,7 @@ static void vmg_setup(pTHX) { MUTEX_INIT(&vmg_op_name_init_mutex); vmg_loaded = 1; } else { - assert(vmg_loaded > 0); + VMG_ASSERT(vmg_loaded > 0); ++vmg_loaded; } @@ -2024,7 +2075,7 @@ PPCODE: MY_CXT.depth = old_depth; MY_CXT.freed_tokens = NULL; VMG_LOADED_LOCK; - assert(vmg_loaded > 0); + VMG_ASSERT(vmg_loaded > 0); ++vmg_loaded; VMG_LOADED_UNLOCK; }