Repository: lucy-clownfish Updated Branches: refs/heads/master 4aea9977c -> 45be7f49b
Fix global destruction check PL_dirty is already set during the first phase of global destruction when it's still safe and even expected to destroy objects. Change the test to check the refcount. This fixes destruction of "our" variables like in Lucy's t/308-simple.t. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/cd847f24 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/cd847f24 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/cd847f24 Branch: refs/heads/master Commit: cd847f2425f2410c16606d19738d19dac1f5f3db Parents: 4aea997 Author: Nick Wellnhofer <wellnho...@aevum.de> Authored: Thu Feb 23 23:18:33 2017 +0100 Committer: Nick Wellnhofer <wellnho...@aevum.de> Committed: Sat Feb 25 17:24:55 2017 +0100 ---------------------------------------------------------------------- .../perl/buildlib/Clownfish/Build/Binding.pm | 24 ++++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/cd847f24/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 4a00766..dd976b5 100644 --- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm +++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm @@ -747,17 +747,21 @@ END_POD MODULE = Clownfish PACKAGE = Clownfish::Obj void -DESTROY(self) - cfish_Obj *self +DESTROY(sv) + SV *sv PPCODE: - /* - * During global destruction, DESTROY is called in random order on - * objects remaining because of refcount leaks or circular references. - * This can cause memory corruption with Clownfish objects, so better - * leak instead of corrupting memory. - */ - if (!PL_dirty) { - CFISH_Obj_Destroy(self); + if (sv_derived_from(sv, "Clownfish::Obj")) { + /* + * During global destruction, DESTROY is called in random order on + * objects remaining because of refcount leaks or circular references. + * This can cause memory corruption with Clownfish objects, so better + * leak instead of corrupting memory. + */ + SV *inner = SvRV(sv); + if (SvREFCNT(inner) <= 1) { + cfish_Obj *self = INT2PTR(cfish_Obj*, SvIV(inner)); + CFISH_Obj_Destroy(self); + } } SV*