develooper Front page | perl.perl5.porters | Postings from February 2000

Re: handle autoviv bug + proposed fix

From:
Gurusamy Sarathy
Date:
February 26, 2000 10:22
Subject:
Re: handle autoviv bug + proposed fix
Message ID:
200002261824.KAA26569@maul.activestate.com
On Sat, 26 Feb 2000 06:41:27 MST, Tom Christiansen wrote:
>What this ends up meaning is that if you let your handle autovivify,
>you can't do the things on it you can do on real ones.  For example:
>
>    use IO::Handle qw/:DEFAULT autoflush/;
>    open(my $fh, "> /dev/null") 
>        or die "can't open /dev/null: $!";
>    for $handle ($fh, *$fh{IO}) {
>        printf "Calling autoflush function on %12s ", $handle;
>        eval { autoflush($handle) };
>        print $@ ? $@ : "successfully.\n";
>        printf "Calling autoflush method on   %12s ", $handle;
>        eval { $handle->autoflush() };
>        print $@ ? $@ : "successfully.\n";
>        print "\n";
>    } 
>
>When run, that produces this output:
>
>    Calling autoflush function on GLOB(0xa14b4) successfully.
>    Calling autoflush method on   GLOB(0xa14b4) Can't call method "autoflush" on unbless
>ed reference at /tmp/blesstest line 44.
>
>    Calling autoflush function on IO::Handle=IO(0xa14a8) successfully.
>    Calling autoflush method on   IO::Handle=IO(0xa14a8) successfully.

Try this.


Sarathy
gsar@ActiveState.com
-----------------------------------8<-----------------------------------
Change 5276 by gsar@auger on 2000/02/26 18:18:16

	allow $fh->autoflush on globrefs, and thence autovivified filehandles
	(from Tom Christiansen)

Affected files ...

... //depot/perl/pp_hot.c#162 edit

Differences ...

==== //depot/perl/pp_hot.c#162 (text) ====
Index: perl/pp_hot.c
--- perl/pp_hot.c.~1~	Sat Feb 26 10:18:22 2000
+++ perl/pp_hot.c	Sat Feb 26 10:18:22 2000
@@ -2757,9 +2757,13 @@
 	*(PL_stack_base + TOPMARK + 1) = sv_2mortal(newRV((SV*)iogv));
     }
 
-    if (!ob || !SvOBJECT(ob))
+    if (!ob || !(SvOBJECT(ob)
+		 || (SvTYPE(ob) == SVt_PVGV && (ob = (SV*)GvIO((GV*)ob))
+		     && SvOBJECT(ob))))
+    {
 	Perl_croak(aTHX_ "Can't call method \"%s\" on unblessed reference",
 		   name);
+    }
 
     stash = SvSTASH(ob);
 
End of Patch.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About