From 05aec8291a7533e7b44683ab3bcbbd1c0a43e5d2 Mon Sep 17 00:00:00 2001 From: Slaven Rezic Date: Wed, 10 Dec 2008 11:06:15 +0100 Subject: [PATCH] * new: ListSV function --- Leak.xs | 32 +++++++++++++++++++++++++++++++- t/basic.t | 17 ++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/Leak.xs b/Leak.xs index 006adbe..48e4929 100644 --- a/Leak.xs +++ b/Leak.xs @@ -182,6 +182,23 @@ check_used(hash_ptr **x) return count; } +static long +add_to_AV(void *p, SV *sv, long av) +{ + char *state = lookup(p,sv,new); + if (state != old) + { +#if 0 + SV* sv_ptr = newSViv((IV)sv); + note_sv(p,sv_ptr,0); /* tricky: avoid that the newly created SV is also counted... */ + av_push((AV*)av, sv_ptr); +#else + av_push((AV*)av, SvREFCNT_inc(sv)); +#endif + } + return av; /* pass over */ +} + MODULE = Devel::Leak PACKAGE = Devel::Leak PROTOTYPES: Enable @@ -220,4 +237,17 @@ OUTPUT: void check_arenas() - +AV* +ListSV(obj) +hash_ptr * obj +CODE: + { + hash_ptr **x = &obj; + hash_ptr *ht = *x; + RETVAL = newAV(); + note_sv(ht,RETVAL,0); /* tricky: avoid that the newly created AV is also counted... */ + sv_apply_to_used(ht, add_to_AV, (long)RETVAL); /* misuse long for pointer --- should be always large enough */ + sv_2mortal((SV*)RETVAL); + } +OUTPUT: + RETVAL diff --git a/t/basic.t b/t/basic.t index 4041702..cdfd3d4 100755 --- a/t/basic.t +++ b/t/basic.t @@ -1,5 +1,5 @@ use Test; -plan test => 5; +plan test => 8; eval { require Devel::Leak }; ok($@, "", "loading module"); eval { import Devel::Leak }; @@ -20,3 +20,18 @@ ok($now, $count+2, "Number of SVs created unexpected"); eval { Devel::Leak::CheckSV($handle) }; ok($@ =~ /\QPlease call Devel::Check::NoteSV() before calling Devel::Check::CheckSV()/, 1, "cannot call CheckSV() twice"); + +{ + my @somewhere_else = (); + my $handle2; + my $count = Devel::Leak::NoteSV($handle2); + print "$count SVs so far\n"; + for my $i (1..10) + { + @somewhere_else = qw(one two); + } + my $sv_list = Devel::Leak::ListSV($handle2); + ok($sv_list->[0], "one", "First leaked SV"); + ok($sv_list->[1], "two", "Second leaked SV"); + ok(@$sv_list, 2, "Count of leaked SVs"); +} -- 2.11.4.GIT