X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2FSub-Op-Test%2FTest.xs;h=4a7b97028bc17c844a2ee28157bc75c40f7018df;hb=c8f39d20852c85f99aabd8c3df4fb354678c8e99;hp=4750507ad9ce45eb3ba3ed46d0c600d50987cafb;hpb=a4ea0141e593c7b7afc86b15fb96d7f0ec5ab38a;p=perl%2Fmodules%2FSub-Op.git diff --git a/t/Sub-Op-Test/Test.xs b/t/Sub-Op-Test/Test.xs index 4750507..4a7b970 100644 --- a/t/Sub-Op-Test/Test.xs +++ b/t/Sub-Op-Test/Test.xs @@ -11,19 +11,38 @@ #include "sub_op.h" -STATIC SV *sub_op_test_cb = NULL; +STATIC HV *sub_op_test_map = NULL; + +STATIC OP *sub_op_test_check(pTHX_ OP *o, void *ud_) { + char buf[sizeof(void*)*2+1]; + SV *cb = ud_; + + (void) hv_store(sub_op_test_map, buf, sprintf(buf, "%"UVxf, PTR2UV(o)), cb, 0); + + return o; +} STATIC OP *sub_op_test_pp(pTHX) { dSP; dMARK; + SV *cb; int i, items; + { + char buf[sizeof(void*)*2+1]; + SV **svp; + svp = hv_fetch(sub_op_test_map, buf, sprintf(buf, "%"UVxf, PTR2UV(PL_op)), 0); + if (!svp) + RETURN; + cb = *svp; + } + ENTER; SAVETMPS; PUSHMARK(MARK); - items = call_sv(sub_op_test_cb, G_ARRAY); + items = call_sv(cb, G_ARRAY); SPAGAIN; for (i = 0; i < items; ++i) @@ -42,27 +61,25 @@ MODULE = Sub::Op::Test PACKAGE = Sub::Op::Test PROTOTYPES: ENABLE -void -_init(SV *name) -PROTOTYPE: $ -PREINIT: - sub_op_keyword k; -PPCODE: - k.name = SvPV_const(name, k.len); - k.check = 0; - k.pp = sub_op_test_pp; - sub_op_register(aTHX_ &k); - XSRETURN(0); +BOOT: +{ + sub_op_test_map = newHV(); +} void -_callback(SV *cb) -PROTOTYPE: $ +_init(SV *name, SV *cb) +PROTOTYPE: $$ +PREINIT: + sub_op_config_t c; PPCODE: if (SvROK(cb)) { cb = SvRV(cb); if (SvTYPE(cb) >= SVt_PVCV) { - SvREFCNT_dec(sub_op_test_cb); - sub_op_test_cb = SvREFCNT_inc(cb); + c.name = SvPV_const(name, c.len); + c.check = sub_op_test_check; + c.ud = SvREFCNT_inc(cb); + c.pp = sub_op_test_pp; + sub_op_register(aTHX_ &c); } } XSRETURN(0);