Merge branch 'master' into xs_reorg
Florian Ragwitz [Tue, 10 Mar 2009 00:25:42 +0000 (01:25 +0100)]
* master:
  Stop segfaulting when trying to get the name from a sub that's still being compiled.
  Remove optional test plan.
  Testcase for get_code_info on a sub that's still being compiled
  Make brace style consistent

Conflicts:
MOP.xs

mop.c
t/082_get_code_info.t

diff --git a/mop.c b/mop.c
index 11a856b..425cd48 100644 (file)
--- a/mop.c
+++ b/mop.c
@@ -83,6 +83,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)
index 47dfa9e..a0026de 100644 (file)
@@ -1,16 +1,11 @@
 use strict;
 use warnings;
 
-use Test::More;
+use Test::More tests => 6;
+use Sub::Name 'subname';
 
 BEGIN {
     $^P &= ~0x200; # Don't munger anonymous sub names
-    if ( eval 'use Sub::Name qw(subname); 1;' ) {
-        plan tests => 5;
-    }
-    else {
-        plan skip_all => 'These tests require Sub::Name';
-    }
 }
 
 BEGIN { use_ok("Class::MOP") }
@@ -36,3 +31,14 @@ code_name_is( subname("", sub {}), "main" => "" );
 require Class::MOP::Method;
 code_name_is( \&Class::MOP::Method::name, "Class::MOP::Method", "name" );
 
+{
+    package Foo;
+
+    sub MODIFY_CODE_ATTRIBUTES {
+        my ($class, $code) = @_;
+        ::ok(!Class::MOP::get_code_info($code), "no name for a coderef that's still compiling");
+        return ();
+    }
+
+    sub foo : Bar {}
+}