diff --git a/TryCatch.xs b/TryCatch.xs index 96f14ac..06a8f96 100644 --- a/TryCatch.xs +++ b/TryCatch.xs @@ -88,7 +88,13 @@ STATIC OP* unwind_return (pTHX_ OP *op, void *user_data) { XPUSHs( (SV*)unwind); PUTBACK; - return CALL_FPTR(PL_ppaddr[OP_ENTERSUB])(aTHXR); + /* pp_entersub gets the XSUB arguments from @_ if there are any. + * Bypass this as we pushed the arguments directly on the stack. */ + + if (CvISXSUB(unwind)) + AvFILLp(GvAV(PL_defgv)) = -1; + + return CALL_FPTR(PL_ppaddr[OP_ENTERSUB])(aTHX); } diff --git a/t/method.t b/t/method.t new file mode 100644 index 0000000..d12d229 --- /dev/null +++ b/t/method.t @@ -0,0 +1,21 @@ +#!perl + +use Test::More tests => 3; + +use strict; +use warnings; + +use TryCatch; + +sub content { + try { + return "pass"; + } catch ($e) { + return "'an error occurred'"; + } + return "fail"; +} + +is (main::content(), "pass", "function"); +is (main->content(), "pass", "class method"); +is ((bless {})->content(), "pass", "instance method");