This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t crash with existent but undefined &DB::DB
authorFather Chrysostomos <sprout@cpan.org>
Mon, 24 Sep 2012 15:46:56 +0000 (08:46 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 24 Sep 2012 16:37:11 +0000 (09:37 -0700)
This is a follow-up to 432d4561c48, which fixed *DB::DB without
&DB::DB, but not &DB::DB without body.

pp_ctl.c
t/run/switchd.t

index b26e557..3faa9b0 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1969,7 +1969,7 @@ PP(pp_dbstate)
         if (gv && isGV_with_GP(gv))
             cv = GvCV(gv);
 
-       if (!cv)
+       if (!cv || (!CvROOT(cv) && !CvXSUB(cv)))
            DIE(aTHX_ "No DB::DB routine defined");
 
        if (CvDEPTH(cv) >= 1 && !(PL_debug & DEBUG_DB_RECURSE_FLAG))
index 1dffb2d..9194062 100644 (file)
@@ -9,7 +9,7 @@ BEGIN { require "./test.pl"; }
 
 # This test depends on t/lib/Devel/switchd*.pm.
 
-plan(tests => 8);
+plan(tests => 9);
 
 my $r;
 
@@ -119,5 +119,14 @@ like(
     stderr   => 1,
   ),
   qr/^No DB::DB routine defined/,
-  "No crash when DB::DB isn't actually defined",
+  "No crash when *DB::DB exists but not &DB::DB",
+);
+like(
+  runperl(
+    switches => [ '-Ilib' ],
+    prog     => 'sub DB::DB; BEGIN { $^P = 0x22; } for(0..9){ warn }',
+    stderr   => 1,
+  ),
+  qr/^No DB::DB routine defined/,
+  "No crash when &DB::DB exists but isn't actually defined",
 );