Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sv.c
Original file line number Diff line number Diff line change
Expand Up @@ -10126,7 +10126,10 @@ Perl_sv_resetpvn(pTHX_ const char *s, STRLEN len, HV * const stash)
sv = GvSV(gv);
if (sv && !SvREADONLY(sv)) {
SV_CHECK_THINKFIRST_COW_DROP(sv);
if (!isGV(sv)) SvOK_off(sv);
if (!isGV(sv)) {
SvOK_off(sv);
SvSETMAGIC(sv);
}
}
if (GvAV(gv)) {
av_clear(GvAV(gv));
Expand Down
26 changes: 25 additions & 1 deletion t/op/reset.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ BEGIN {
}
use strict;

plan tests => 40;
plan tests => 45;

package aiieee;

Expand Down Expand Up @@ -190,6 +190,30 @@ SKIP:
}
}

# magic reset #20763
{
{
local $^W = 1; # we're resetting this
my $warn = '';
local $SIG{__WARN__} = sub { $warn .= "@_\n" };
reset "\cW";
like($warn, qr/uninitialized/, "magic tries to SvIV() the new value");
$warn = '';
is($^W, 0, q"check $^W has been zeroed");
is($warn, '', "should be no more warnings");
}
{
local $| = 1;
no warnings 'uninitialized';
reset '|';
is($|, 0, q"check magic applied to $|");
}

eval { reset "1" };
like($@, qr/Modification of a read-only value attempted/,
"\$1 isn't marked read-only, but throws on set magic");
}

__DATA__
#!perl
use warnings;
Expand Down