Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't let pp_entersub overwrite the stack with the elements of @_

  • Loading branch information...
commit 65062e29ae04fc31a47b053025b4b1aa22b6f4b7 1 parent 43bffc3
@vpit vpit authored committed
Showing with 28 additions and 1 deletion.
  1. +7 −1 TryCatch.xs
  2. +21 −0 t/method.t
View
8 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);
}
View
21 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");
Please sign in to comment.
Something went wrong with that request. Please try again.