Repository: lucy-clownfish
Updated Branches:
  refs/heads/master 0e8aa921a -> ab9d38830


Fix global destruction check again

The best we can do is to check for PL_dirty and the refcount.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/ab9d3883
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/ab9d3883
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/ab9d3883

Branch: refs/heads/master
Commit: ab9d38830c696c9ec4169c40c79efbdcd343948c
Parents: 0e8aa92
Author: Nick Wellnhofer <wellnho...@aevum.de>
Authored: Tue Mar 7 19:17:16 2017 +0100
Committer: Nick Wellnhofer <wellnho...@aevum.de>
Committed: Thu Mar 9 22:22:12 2017 +0100

----------------------------------------------------------------------
 .../perl/buildlib/Clownfish/Build/Binding.pm    | 10 +++++++-
 runtime/perl/t/binding/019-obj.t                | 24 +++++++++++++++++++-
 2 files changed, 32 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ab9d3883/runtime/perl/buildlib/Clownfish/Build/Binding.pm
----------------------------------------------------------------------
diff --git a/runtime/perl/buildlib/Clownfish/Build/Binding.pm 
b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
index dd976b5..9fa4942 100644
--- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm
+++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm
@@ -756,9 +756,17 @@ PPCODE:
          * objects remaining because of refcount leaks or circular references.
          * This can cause memory corruption with Clownfish objects, so better
          * leak instead of corrupting memory.
+         *
+         * Unfortunately, Perl's global destruction is still severely broken
+         * as of early 2017. Global "our" variables are destroyed in random
+         * order even without circular references. The following check will
+         * skip some objects that could be safely destroyed, but it's the
+         * best we can do.
+         *
+         * See https://rt.perl.org/Ticket/Display.html?id=32714
          */
         SV *inner = SvRV(sv);
-        if (SvREFCNT(inner) <= 1) {
+        if (!PL_dirty || SvREFCNT(inner) <= 1) {
             cfish_Obj *self = INT2PTR(cfish_Obj*, SvIV(inner));
             CFISH_Obj_Destroy(self);
         }

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/ab9d3883/runtime/perl/t/binding/019-obj.t
----------------------------------------------------------------------
diff --git a/runtime/perl/t/binding/019-obj.t b/runtime/perl/t/binding/019-obj.t
index 357984b..ee1be19 100644
--- a/runtime/perl/t/binding/019-obj.t
+++ b/runtime/perl/t/binding/019-obj.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 26;
+use Test::More tests => 27;
 use Clownfish::Test;
 
 package TestObj;
@@ -174,3 +174,25 @@ SKIP: {
     pass ( "Created circular reference" );
 }
 
+SKIP: {
+    skip( "Global destruction check doesn't work reliably", 1 )
+        if $ENV{CLOWNFISH_VALGRIND};
+
+    {
+        package LeakyObj;
+        use base qw( Clownfish::Obj );
+
+        sub DESTROY {
+            # The assignment increases the object's refcount.
+            my $self = shift;
+            $self->SUPER::DESTROY;
+        }
+    }
+
+    # Will unfortunately be destroyed during global destruction, not in the
+    # END phase as one would expect.
+    # See https://rt.perl.org/Ticket/Display.html?id=32714
+    our $leaky = LeakyObj->new;
+    pass( "Created LeakyObj" );
+}
+

Reply via email to