Skip Menu |

This queue is for tickets about the Test-Weaken CPAN distribution.

Report information
The Basics
Id: 44835
Status: resolved
Priority: 0/
Queue: Test-Weaken

People
Owner: jkegl [...] cpan.org
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: 3.002000



Subject: suggest descend into tied() of scalar/array/hash/filehandle
Date: Tue, 07 Apr 2009 08:43:21 +1000
To: bug-Test-Weaken [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
It'd be good if Test::Weaken looked at tied() to notice the object associated with a tied scalar, array, hash or filehandle. That tie object should in most cases have the same lifespan as the variable and so could be helpfully included in the weakening (recursively as usual). Some possible exercise for such a feature below.
#!/usr/bin/perl package MyTie; use strict; use warnings; my $leaky; sub TIESCALAR { my ($class) = @_; my $tobj = bless {}, $class; $leaky = $tobj; return $tobj; } sub TIEHASH { goto \&TIESCALAR; } sub FIRSTKEY { return; # no keys } sub TIEARRAY { goto \&TIESCALAR; } sub FETCHSIZE { return 0; # no array elements } sub TIEHANDLE { goto \&TIESCALAR; } package main; use strict; use warnings; use Test::Weaken; use Test::More tests => 4; { my $test = Test::Weaken::leaks (sub { my $var; tie $var, 'MyTie'; return \$var; }); my $unfreed_count = $test ? $test->unfreed_count() : 0; is ($unfreed_count, 1, 'notice scalar tied() not freed'); } { my $test = Test::Weaken::leaks (sub { my %var; tie %var, 'MyTie'; return \%var; }); my $unfreed_count = $test ? $test->unfreed_count() : 0; is ($unfreed_count, 1, 'notice hash tied() not freed'); } { my $test = Test::Weaken::leaks (sub { my @var; tie @var, 'MyTie'; return \@var; }); my $unfreed_count = $test ? $test->unfreed_count() : 0; is ($unfreed_count, 1, 'notice array tied() not freed'); } { my $test = Test::Weaken::leaks (sub { tie *MYFILEHANDLE, 'MyTie'; return \*MYFILEHANDLE; }); my $unfreed_count = $test ? $test->unfreed_count() : 0; is ($unfreed_count, 1, 'notice file handle typeglob tied() not freed'); } exit 0;
I'm marking this as stalled because I am giving ticket #43885 priority. Once I've completed 43885, I'll "unstall" this ticket.
Re: typeglobs and filehandles. Unless persuaded otherwise, I plan to track, follow and/or ignore the underlying objects according to what I'd currently do with them if they were the referent of a reference. In particular, this means I will ignore filehandles. (For details on what's tracked/followed/ignored see the documentation.) The documentation gives my reasoning for ignoring file handles. Summarizing, they are closely connected with typeglobs which part of the symbol table which is global. It's hard to say what their life expectancy should be, but it's certainly far from a sure thing it's the same as the object which refers to them.
Subject: Re: [rt.cpan.org #44835] suggest descend into tied() of scalar/array/hash/filehandle
Date: Thu, 23 Apr 2009 08:30:16 +1000
To: bug-Test-Weaken [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Jeffrey Kegler via RT" <bug-Test-Weaken@rt.cpan.org> writes: Show quoted text
> > Re: typeglobs and filehandles. Unless persuaded otherwise, I plan to > track, follow and/or ignore the underlying objects according to what I'd > currently do with them if they were the referent of a reference.
Sounds fair. Show quoted text
> The documentation gives my reasoning for ignoring file handles.
I suspect anonymous globs live or die by the usual rules, eg. the one referred to by $out here goes away when $out is weakened use Scalar::Util; my $out; open $out, '/dev/null' or die; print 'x',$out,"\n"; Scalar::Util::weaken ($out); print 'x',$out,"\n"; Something like that might helpfully be tracked, to detect a leak of an opened file handle. Possible test program below. But I suppose you'd want exceptions for references to \*STDOUT etc, since they'd arise fairly often, and of course aren't leaks. An 'ignore' func could skip them, but being very builtin perl features you'd probably prefer leaks() to do that itself. You oculd think about tracking the underlying *FOO{IO} handle thingie too, which is umm, some sort of object. But I'm pretty fuzzy on when that would get used explicitly :-). Show quoted text
> Summarizing, they are closely connected with typeglobs which part of the > symbol table which is global.
If globs were tracked then I suppose anyone mucking about with references to actual symbol table entries would have to 'ignore' such globs. That'd be a moderately unusual thing would it? And not dissimilar to keeping a ref to any global thing? The benefit of noticing anon file handles might outweigh any inconvenience.
#!/usr/bin/perl package MyObject; use strict; use warnings; use Scalar::Util; sub new { my ($class) = @_; my $out; open $out, '/dev/null' or die; return bless { fh => $out }, $class; } package main; use strict; use warnings; use Test::Weaken; use Test::More tests => 2; { my $leak; my $test = Test::Weaken::leaks (sub { my $obj = MyObject->new; $leak = $obj->{'fh'} or die; return $obj; }); ok ($test, 'leaky file handle detection'); is ($test && $test->unfreed_count, 1, 'one object leaked'); } exit 0;
Stalled while I work on other wishlist items.
Stalled while I work on other wishlist items.
Work underway. I've done a first implementation, which passes all tests. I'll document, then do a developer's release. I'm fighting a flu, so the documentation might go a bit slowly.
I just uploaded 3.001_000. It has the fix, along with a first draft of the documentation. Ties "just work", without interface changes. (I hope.) There is now a tracked_types named argument, which allows you to track builtin types not tracked by default, specifically GLOB, IO, FORMAT and LVALUE. Thanks, Kevin, your tests were useful without major changes, except for the one on tied filehandles. This is a release candidate, although odds are there'll be at least one or two documentation touch-ups before the official release.
Subject: Re: [rt.cpan.org #44835] suggest descend into tied() of scalar/array/hash/filehandle
Date: Thu, 23 Jul 2009 07:21:34 +1000
To: bug-Test-Weaken [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Jeffrey Kegler via RT" <bug-Test-Weaken@rt.cpan.org> writes: Show quoted text
> > Ties "just work", without interface changes.
Works for me, descending into one of my tied gtk thingies. Show quoted text
> There is now a tracked_types named argument, which allows you to track > builtin types not tracked by default, specifically GLOB, IO, FORMAT and > LVALUE.
I suppose ideally they'ed be automatically tracked when "anonymous", but I think I've now got even less idea than before how that might be done. Show quoted text
> except for the one on tied filehandles.
Err, umm, it's been a while, I can't remember exactly what it was meant to be there. I suppose it was to notice freeing of the tie object, without worrying whether the glob handle as such is freed or not ...
I'll look at the two new tickets and see if either justify holding up this official release. There are minor documentation tweaks anyway, so there will be another developer's release.
I just uploaded 3.001_001. This is a release candidate. There were a few small changes in comments. Looking at tickets 48125 and 48127, I don't see anything that should hold up an official release. If I don't get any feedback suggesting otherwise, in a few days I will make this release 3.002000.
I just uploaded 3.002000, an official release with the fix. If no issues appear, I will mark this ticket resolved in a few days.
Stalled, because it's in the "TO DO" queue.
Disregard message of Sat Aug 01 19:03:04 2009. It was intended for another ticket. This ticket is "open" pending feedback from the official release with the fix. On Sat Aug 01 19:03:04 2009, JKEGL wrote: Show quoted text
> Stalled, because it's in the "TO DO" queue.
Subject: Re: [rt.cpan.org #44835] suggest descend into tied() of scalar/array/hash/filehandle
Date: Sun, 02 Aug 2009 12:01:42 +1000
To: bug-Test-Weaken [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Jeffrey Kegler via RT" <bug-Test-Weaken@rt.cpan.org> writes: Show quoted text
> > I just uploaded 3.002000,
Seems to go for me ...
Resolved in 3.002000.