PerlIO::scalar: stringify refs
authorDavid Mitchell <davem@iabyn.com>
Thu, 17 Oct 2013 14:35:14 +0000 (15:35 +0100)
committerDavid Mitchell <davem@iabyn.com>
Thu, 17 Oct 2013 14:46:05 +0000 (15:46 +0100)
commit552908b17471877454d99aa32f7ac5c29ea2efbb
tree988d8f90022ec5a4ee46d36a9e8d2aaac6b00ae5
parentd5c46415f51e41dac449b28a8d3ac610822fd836
PerlIO::scalar: stringify refs

If $s in
    open my $fh, "<",  \$s
or similar is a ref, then
stringify that ref: i.e. convert it from a ref into the string
"SCALAR(0x....)" or whatever.

This fixes

    RT #119529 Filehandle opened from ref to ref hangs on reading

which in this case was looping forever, since it kept thinking that
the var was a string ("SCALAR.."), but whose length was 0.

I haven't gone for a complete "always force var into a string" approach,
since PerlIO::scalar has quite a tolerance for "bad" vars; e.g.
it won't warn if $var is undef or a read-only constant number etc;
and it already normalises under some circumstances and not others.
So I've just increased the cases somewhat where it normalises.

Also, I didn't look to closely at the code that was looping (or to put it
another way, I looked at it but didn't understand it), so it could
conceivably still behave badly on some other strange type of variable that
manages to avoid getting normalised.
ext/PerlIO-scalar/scalar.pm
ext/PerlIO-scalar/scalar.xs
ext/PerlIO-scalar/t/scalar.t