Stop segfaulting when trying to get the name from a sub that's still being compiled.
Florian Ragwitz [Tue, 10 Mar 2009 00:13:35 +0000 (01:13 +0100)]
MOP.xs

diff --git a/MOP.xs b/MOP.xs
index 7d82305..c86a013 100644 (file)
--- a/MOP.xs
+++ b/MOP.xs
@@ -120,6 +120,12 @@ get_code_info (SV *coderef, char **pkg, char **name)
     }
 
     coderef = SvRV(coderef);
+
+    /* sub is still being compiled */
+    if (!CvGV(coderef)) {
+        return 0;
+    }
+
     /* I think this only gets triggered with a mangled coderef, but if
        we hit it without the guard, we segfault. The slightly odd return
        value strikes me as an improvement (mst)