Skip to content

Commit

Permalink
In PerlIO::Scalar’s write, stringify refs
Browse files Browse the repository at this point in the history
Otherwise, it won’t work with an overloaded object.
  • Loading branch information
Father Chrysostomos committed Jan 6, 2012
1 parent 89a3b50 commit 726c8e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ext/PerlIO-scalar/scalar.xs
Expand Up @@ -163,7 +163,8 @@ PerlIOScalar_write(pTHX_ PerlIO * f, const void *vbuf, Size_t count)
SV *sv = s->var;
char *dst;
SvGETMAGIC(sv);
sv_force_normal(sv);
if (SvROK(sv)) SvPV_force_nomg_nolen(sv);
else sv_force_normal(sv);
if ((PerlIOBase(f)->flags) & PERLIO_F_APPEND) {
dst = SvGROW(sv, SvCUR(sv) + count);
offset = SvCUR(sv);
Expand Down
9 changes: 7 additions & 2 deletions ext/PerlIO-scalar/t/scalar.t
Expand Up @@ -16,7 +16,7 @@ use Fcntl qw(SEEK_SET SEEK_CUR SEEK_END); # Not 0, 1, 2 everywhere.

$| = 1;

use Test::More tests => 73;
use Test::More tests => 74;

my $fh;
my $var = "aaa\n";
Expand Down Expand Up @@ -285,12 +285,17 @@ EOF
'seek beyond end end of string followed by read';
}

# Writing to COW scalars
# Writing to COW scalars and refs
{
my $bovid = __PACKAGE__;
open my $handel, ">", \$bovid;
print $handel "the COW with the crumpled horn";
is $bovid, "the COW with the crumpled horn", 'writing to COW scalars';
package lrcg { use overload fallback => 1, '""'=>sub { 'chin' } }
seek $handel, 3, 0;
$bovid = bless [], lrcg::;
print $handel 'mney';
is $bovid, 'chimney', 'writing to refs';
}

# [perl #92706]
Expand Down

0 comments on commit 726c8e7

Please sign in to comment.