[perl #113764] Make &= duping work with PerlIO::scalar
authorFather Chrysostomos <sprout@cpan.org>
Thu, 21 Jun 2012 06:33:28 +0000 (23:33 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 21 Jun 2012 06:33:28 +0000 (23:33 -0700)
commit7b3cf1c058e25efdde99ad84398db2e7bc9892b4
tree3a096026eb3af6820d708f1958ed7ea50308117a
parent55f7f8abb06cb51dcd206c39ec3da610565bca68
[perl #113764] Make &= duping work with PerlIO::scalar

In trying to fix bug #112780, I made in-memory handle duplication tem-
porarily hide the underlying scalar so it wouldn’t be set to the empty
string (commit 49b69fb3a).

I used PerlIO_sv_dup in j rather than PerlIOScalar_arg.  The for-
mer is usually what is called anyway.  There is only one branch of
PerlIOScalar_arg that doesn’t call PerlIO_sv_dup.  I don’t remember
what I was thinking back then, but I think I thought that branch
was there for paranoia.  But actually, it is used for "&=", so this
started failing:

open FILE, '>', \my $content or die "Couldn't open scalar filehandle";
open my $fh, ">&=FILE" or die "Couldn't open: $!";
print $fh "Foo-Bar\n";
close $fh;
close FILE;
print $content;

This commit fixes the bug in the smallest way possible, which means
switching from PerlIO_sv_dup to PerlIOScalar_arg in PerlIOScalar_arg,
which, in turn, entails fiddling with RVs.
ext/PerlIO-scalar/scalar.xs
ext/PerlIO-scalar/t/scalar.t