From: Peter Rabbitson Date: Thu, 16 Jun 2016 22:21:23 +0000 (+0200) Subject: Remove useless eval in the leaktracer on 5.8.3+ X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7bba735de0eb5d431bb3b36e6aec4b19370f9158;p=dbsrgits%2FDBIx-Class-Historic.git Remove useless eval in the leaktracer on 5.8.3+ As a bonus fix a subtle bug where the very first ref encountered was never traced, as the postincrement caused its slot to be deleted - ARGH! --- diff --git a/lib/DBIx/Class/_Util.pm b/lib/DBIx/Class/_Util.pm index f6e04fe..d077124 100644 --- a/lib/DBIx/Class/_Util.pm +++ b/lib/DBIx/Class/_Util.pm @@ -23,6 +23,9 @@ BEGIN { BROKEN_GOTO => ( "$]" < 5.008003 ) ? 1 : 0, + # perl -MScalar::Util=weaken -e 'weaken( $hash{key} = \"value" )' + BROKEN_WEAK_SCALARREF_VALUES => ( "$]" < 5.008003 ) ? 1 : 0, + HAS_ITHREADS => $Config{useithreads} ? 1 : 0, UNSTABLE_DOLLARAT => ( "$]" < 5.013002 ) ? 1 : 0, diff --git a/t/lib/DBICTest/Util/LeakTracer.pm b/t/lib/DBICTest/Util/LeakTracer.pm index 6f1bcb6..8002e69 100644 --- a/t/lib/DBICTest/Util/LeakTracer.pm +++ b/t/lib/DBICTest/Util/LeakTracer.pm @@ -48,18 +48,23 @@ sub populate_weakregistry { for keys %$reg; } + return $target if ( + DBIx::Class::_ENV_::BROKEN_WEAK_SCALARREF_VALUES + and + ref $target eq 'SCALAR' + ); + if (! defined $weak_registry->{$refaddr}{weakref}) { + + # replace slot entirely $weak_registry->{$refaddr} = { stacktrace => stacktrace(1), weakref => $target, }; - # on perl < 5.8.3 sometimes a weaken can throw (can't find RT) - # so guard against that unlikely event - local $SIG{__DIE__} if $SIG{__DIE__}; - local $@; - eval { weaken( $weak_registry->{$refaddr}{weakref} ); $refs_traced++ } - or delete $weak_registry->{$refaddr}; + weaken( $weak_registry->{$refaddr}{weakref} ); + + $refs_traced++; } my $desc = refdesc $target;