From 93fb77c98e002f21858fe9efa1bf6a8ce2144178 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 7 Jul 2011 00:32:38 -0500 Subject: oops, need a new ref to the cv for each op --- smartmatch.xs | 9 +++++++-- t/basic.t | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/smartmatch.xs b/smartmatch.xs index b3e12c5..28cf0e0 100644 --- a/smartmatch.xs +++ b/smartmatch.xs @@ -17,7 +17,7 @@ smartmatch_cb(pTHX_ OP *o, void *user_data) o->op_flags &= ~OPf_KIDS; op_free(o); - cb_op = newSVOP(OP_CONST, 0, (SV*)user_data); + cb_op = newSVOP(OP_CONST, 0, newSVsv(user_data)); list = newLISTOP(OP_LIST, 0, left, right); new = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, list, cb_op)); @@ -56,5 +56,10 @@ register (cb) void unregister (id) UV id; + PREINIT: + SV *cb; CODE: - hook_op_check_smartmatch_remove(id); + cb = hook_op_check_smartmatch_remove(id); + if (cb) { + SvREFCNT_dec(cb); + } diff --git a/t/basic.t b/t/basic.t index b7010e2..1de7d8f 100644 --- a/t/basic.t +++ b/t/basic.t @@ -7,12 +7,14 @@ ok(1 ~~ 1); { use smartmatch sub { 0 }; ok(!(1 ~~ 1)); + ok(!(1 ~~ 2)); } ok(1 ~~ 1); { use smartmatch 'core'; ok(1 ~~ 1); + ok(!(1 ~~ 2)); } done_testing; -- cgit v1.2.3