This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add a test for gv_try_downgrade()
authorDavid Mitchell <davem@iabyn.com>
Wed, 21 Sep 2016 08:22:13 +0000 (09:22 +0100)
committerDavid Mitchell <davem@iabyn.com>
Mon, 26 Sep 2016 08:20:23 +0000 (09:20 +0100)
Previously, making gv_try_downgrade() just immediately return didn't cause
any tests to fail.

t/op/gv.t

index 9bdc711..8d5e7dc 100644 (file)
--- a/t/op/gv.t
+++ b/t/op/gv.t
@@ -12,7 +12,7 @@ BEGIN {
 
 use warnings;
 
-plan(tests => 277 );
+plan(tests => 280);
 
 # type coercion on assignment
 $foo = 'foo';
@@ -1170,6 +1170,23 @@ SKIP: {
     is ($? & 127, 0,"[perl #128597] No crash when gp_free calls ckWARN_d");
 }
 
+# test gv_try_downgrade()
+# If a GV can be stored in a stash in a compact, non-GV form, then
+# whenever ops are freed which reference the GV, an attempt is made to
+# downgrade the GV to something simpler. Made sure this happens.
+
+package GV_DOWNGRADE {
+    use constant FOO => 1;
+
+    ::like "$GV_DOWNGRADE::{FOO}", qr/SCALAR/, "gv_downgrade: pre";
+    eval q{
+        my $x = \&FOO; # upgrades compact to full GV
+        ::like "$GV_DOWNGRADE::{FOO}", qr/^\*/, "gv_downgrade: full";
+    };
+    # after the eval's ops are freed, the GV should get downgraded again
+    ::like "$GV_DOWNGRADE::{FOO}", qr/SCALAR/, "gv_downgrade: post";
+}
+
 __END__
 Perl
 Rules