summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sv.c3
-rw-r--r--t/op/gmagic.t24
2 files changed, 26 insertions, 1 deletions
diff --git a/sv.c b/sv.c
index b8f0b100f5..31bda3b2d3 100644
--- a/sv.c
+++ b/sv.c
@@ -9014,6 +9014,7 @@ Perl_sv_pvn_force_flags(pTHX_ SV *const sv, STRLEN *const lp, const I32 flags)
PERL_ARGS_ASSERT_SV_PVN_FORCE_FLAGS;
+ if (flags & SV_GMAGIC) SvGETMAGIC(sv);
if (SvTHINKFIRST(sv) && !SvROK(sv))
sv_force_normal_flags(sv, 0);
@@ -9038,7 +9039,7 @@ Perl_sv_pvn_force_flags(pTHX_ SV *const sv, STRLEN *const lp, const I32 flags)
/* diag_listed_as: Can't coerce %s to %s in %s */
Perl_croak(aTHX_ "Can't coerce %s to string in %s", sv_reftype(sv,0),
OP_DESC(PL_op));
- s = sv_2pv_flags(sv, &len, flags);
+ s = sv_2pv_flags(sv, &len, flags &~ SV_GMAGIC);
if (lp)
*lp = len;
diff --git a/t/op/gmagic.t b/t/op/gmagic.t
index daebae4cb8..c50205267c 100644
--- a/t/op/gmagic.t
+++ b/t/op/gmagic.t
@@ -61,6 +61,30 @@ $c = bless [], o::;
chomp $c;
expected_tie_calls(tied $c, 1, 2, 'chomping a ref');
+{
+ my $outfile = tempfile();
+ open my $h, ">$outfile" or die "$0 cannot close $outfile: $!";
+ print $h "bar\n";
+ close $h or die "$0 cannot close $outfile: $!";
+
+ $c = *foo; # 1 write
+ open $h, $outfile;
+ sysread $h, $c, 3, 7; # 1 read; 1 write
+ is $c, "*main::bar", 'what sysread wrote'; # 1 read
+ expected_tie_calls(tied $c, 2, 2, 'calling sysread with tied buf');
+ close $h or die "$0 cannot close $outfile: $!";
+
+ # Do this again, with a utf8 handle
+ $c = *finish; # 1 write
+ open $h, "<:utf8", $outfile;
+ sysread $h, $c, 3, 7; # 1 read; 1 write
+ is $c, "*main::bar", 'what sysread wrote'; # 1 read
+ expected_tie_calls(tied $c, 2, 2, 'calling sysread with tied buf');
+ close $h or die "$0 cannot close $outfile: $!";
+
+ unlink_all $outfile;
+}
+
# autovivication of aelem, helem, of rv2sv combined with get-magic
{
my $true = 1;