Change 31472 by [EMAIL PROTECTED] on 2007/06/26 16:10:11

        First patch from:
        Subject: Re: [perl #43357] *DESTROY = sub {} at runtime
        From: "Brandon Black" <[EMAIL PROTECTED]>
        Date: Tue, 26 Jun 2007 11:05:31 -0500
        Message-ID: <[EMAIL PROTECTED]>
        
        Fix problem recently introduced with loosing a DESTROY when redefined
        at runtime.

Affected files ...

... //depot/perl/gv.c#373 edit
... //depot/perl/t/mro/basic.t#4 edit

Differences ...

==== //depot/perl/gv.c#373 (text) ====
Index: perl/gv.c
--- perl/gv.c#372~31341~        2007-06-06 07:42:01.000000000 -0700
+++ perl/gv.c   2007-06-26 09:10:11.000000000 -0700
@@ -1509,9 +1509,10 @@
   dVAR;
   MAGIC* const mg = mg_find((SV*)stash, PERL_MAGIC_overload_table);
   AMT amt;
+  const struct mro_meta* stash_meta = HvMROMETA(stash);
   U32 newgen;
 
-  newgen = PL_sub_generation + HvMROMETA(stash)->cache_gen;
+  newgen = PL_sub_generation + stash_meta->pkg_gen + stash_meta->cache_gen;
   if (mg) {
       const AMT * const amtp = (AMT*)mg->mg_ptr;
       if (amtp->was_ok_am == PL_amagic_generation
@@ -1638,11 +1639,13 @@
     MAGIC *mg;
     AMT *amtp;
     U32 newgen;
+    struct mro_meta* stash_meta;
 
     if (!stash || !HvNAME_get(stash))
         return NULL;
 
-    newgen = PL_sub_generation + HvMROMETA(stash)->cache_gen;
+    stash_meta = HvMROMETA(stash);
+    newgen = PL_sub_generation + stash_meta->pkg_gen + stash_meta->cache_gen;
 
     mg = mg_find((SV*)stash, PERL_MAGIC_overload_table);
     if (!mg) {

==== //depot/perl/t/mro/basic.t#4 (text) ====
Index: perl/t/mro/basic.t
--- perl/t/mro/basic.t#3~31239~ 2007-05-18 18:00:15.000000000 -0700
+++ perl/t/mro/basic.t  2007-06-26 09:10:11.000000000 -0700
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-require q(./test.pl); plan(tests => 12);
+require q(./test.pl); plan(tests => 18);
 
 {
     package MRO_A;
@@ -69,3 +69,59 @@
 # XXX TODO (when there's a way to backtrack through a glob's aliases)
 # push(@MRO_M::ISA, 'MRO_TestOtherBase');
 # is(eval { MRO_N->testfunctwo() }, 321);
+
+# Simple DESTROY Baseline
+{
+    my $x = 0;
+    my $obj;
+
+    {
+        package DESTROY_MRO_Baseline;
+        sub new { bless {} => shift }
+        sub DESTROY { $x++ }
+
+        package DESTROY_MRO_Baseline_Child;
+        our @ISA = qw/DESTROY_MRO_Baseline/;
+    }
+
+    $obj = DESTROY_MRO_Baseline->new();
+    undef $obj;
+    is($x, 1);
+
+    $obj = DESTROY_MRO_Baseline_Child->new();
+    undef $obj;
+    is($x, 2);
+}
+
+# Dynamic DESTROY
+{
+    my $x = 0;
+    my $obj;
+
+    {
+        package DESTROY_MRO_Dynamic;
+        sub new { bless {} => shift }
+
+        package DESTROY_MRO_Dynamic_Child;
+        our @ISA = qw/DESTROY_MRO_Dynamic/;
+    }
+
+    $obj = DESTROY_MRO_Dynamic->new();
+    undef $obj;
+    is($x, 0);
+
+    $obj = DESTROY_MRO_Dynamic_Child->new();
+    undef $obj;
+    is($x, 0);
+
+    no warnings 'once';
+    *DESTROY_MRO_Dynamic::DESTROY = sub { $x++ };
+
+    $obj = DESTROY_MRO_Dynamic->new();
+    undef $obj;
+    is($x, 1);
+
+    $obj = DESTROY_MRO_Dynamic_Child->new();
+    undef $obj;
+    is($x, 2);
+}
End of Patch.

Reply via email to