Checking in changes prior to tagging of version 0.57.
[gitmo/Mouse.git] / xs-src / MouseUtil.xs
index 8587b64..e562748 100644 (file)
@@ -120,6 +120,29 @@ mouse_throw_error(SV* const metaobject, SV* const data /* not used */, const cha
     }
 }
 
+/* workaround RT #69939 */
+I32
+mouse_call_sv_safe(pTHX_ SV* const sv, I32 const flags) {
+    const PERL_CONTEXT* const cx = &cxstack[cxstack_ix];
+    assert( (flags & G_EVAL) == 0 );
+    //warn("%d 0x%x 0x%x", (int)cx->cx_type, (int)cx->cx_type, (int)PL_in_eval);
+    if(!(cx->cx_type & (CXt_EVAL|CXp_TRYBLOCK))) {
+        I32 count;
+        //SAVESPTR(ERRSV);
+        //ERRSV = sv_newmortal();
+
+        count = Perl_call_sv(aTHX_ sv, flags | G_EVAL);
+
+        if(sv_true(ERRSV)){
+            croak(NULL); /* rethrow */
+        }
+        return count;
+    }
+    else {
+        return Perl_call_sv(aTHX_ sv, flags);
+    }
+}
+
 void
 mouse_must_defined(pTHX_ SV* const value, const char* const name) {
     assert(value);
@@ -199,7 +222,7 @@ mouse_call0 (pTHX_ SV* const self, SV* const method) {
     XPUSHs(self);
     PUTBACK;
 
-    call_sv(method, G_SCALAR | G_METHOD);
+    call_sv_safe(method, G_SCALAR | G_METHOD);
 
     SPAGAIN;
     ret = POPs;
@@ -219,7 +242,7 @@ mouse_call1 (pTHX_ SV* const self, SV* const method, SV* const arg1) {
     PUSHs(arg1);
     PUTBACK;
 
-    call_sv(method, G_SCALAR | G_METHOD);
+    call_sv_safe(method, G_SCALAR | G_METHOD);
 
     SPAGAIN;
     ret = POPs;