New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
regression in print length undef #11177
Comments
From @nwc10Created by @nwc10In fixing a related bug, d88e091 introduced a regression when printing $ ./perl -wle 'print length undef' $ ./perl -wle 'print length $a' $ ./perl^ -wle 'print length undef' $ ./perl^ -wle 'print length $a' It's not obvious to me why this code change causes this behaviour change. commit d88e091 Fix my $x = 3; $x = length(undef);. Inline Patchdiff --git a/pp.c b/pp.c
index 0da8bba..fcb7ff2 100644
--- a/pp.c
+++ b/pp.c
@@ -3105,8 +3105,10 @@ PP(pp_length)
= sv_2pv_flags(sv, &len,
SV_UNDEF_RETURNS_NULL|SV_CONST_RETURN|SV_GMAGIC);
- if (!p)
- SETs(&PL_sv_undef);
+ if (!p) {
+ sv_setsv(TARG, &PL_sv_undef);
+ SETTARG;
+ }
else if (DO_UTF8(sv)) {
SETi(utf8_length((U8*)p, (U8*)p + len));
}
@@ -3119,7 +3121,8 @@ PP(pp_length)
else
SETi(sv_len(sv));
} else {
- SETs(&PL_sv_undef);
+ sv_setsv_nomg(TARG, &PL_sv_undef);
+ SETTARG;
}
RETURN;
}
Nicholas Clark Perl Info
|
From @dglOn 6 Mar 2011, at 12:35, Nicholas Clark (via RT) wrote:
It looks like it's because it results in returning a temporary 'undef' which is neither &PL_sv_undef nor readonly, which seems to be expected by other bits of code. Making TARG be the copy and returning the actual PL_sv_undef seems to fix it. (Plus it seemed like a good idea to avoid the copy to TARG when it doesn't make sense, although maybe slightly premature optimisation.) |
From @dgl0001-Fix-perl-85508-regression-in-print-length-undef.patchFrom 0ce9891599f473abedd59f087eafc4414ba53dd7 Mon Sep 17 00:00:00 2001
From: David Leadbeater <dgl@dgl.cx>
Date: Sun, 6 Mar 2011 15:19:57 +0000
Subject: [PATCH] Fix [perl #85508] regression in print length undef
length was returning a temporary copy of undef, this meant it didn't
generate a warning when used uninitialised. Return PL_sv_undef but
also ensure TARG is cleared if needed.
---
pp.c | 14 ++++++++++----
t/op/length.t | 13 ++++++++++---
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/pp.c b/pp.c
index d857c7e..bea4551 100644
--- a/pp.c
+++ b/pp.c
@@ -3330,8 +3330,11 @@ PP(pp_length)
SV_UNDEF_RETURNS_NULL|SV_CONST_RETURN|SV_GMAGIC);
if (!p) {
- sv_setsv(TARG, &PL_sv_undef);
- SETTARG;
+ if (!SvPADTMP(TARG)) {
+ sv_setsv(TARG, &PL_sv_undef);
+ SETTARG;
+ }
+ SETs(&PL_sv_undef);
}
else if (DO_UTF8(sv)) {
SETi(utf8_length((U8*)p, (U8*)p + len));
@@ -3345,8 +3348,11 @@ PP(pp_length)
else
SETi(sv_len(sv));
} else {
- sv_setsv_nomg(TARG, &PL_sv_undef);
- SETTARG;
+ if (!SvPADTMP(TARG)) {
+ sv_setsv_nomg(TARG, &PL_sv_undef);
+ SETTARG;
+ }
+ SETs(&PL_sv_undef);
}
RETURN;
}
diff --git a/t/op/length.t b/t/op/length.t
index 705b9d5..0288bec 100644
--- a/t/op/length.t
+++ b/t/op/length.t
@@ -6,7 +6,7 @@ BEGIN {
@INC = '../lib';
}
-plan (tests => 36);
+plan (tests => 37);
print "not " unless length("") == 0;
print "ok 1\n";
@@ -210,11 +210,18 @@ is($ul, undef, "Assigned length of overloaded undef with result in TARG");
# ok(!defined $uo); Turns you can't test this. FIXME for pp_defined?
-is($warnings, 0, "There were no warnings");
-
{
my $y = "\x{100}BC";
is(index($y, "B"), 1, 'adds an intermediate position to the offset cache');
is(length $y, 3,
'Check that sv_len_utf8() can take advantage of the offset cache');
}
+
+{
+ local $SIG{__WARN__} = sub {
+ pass("'print length undef' warned");
+ };
+ print length undef;
+}
+
+is($warnings, 0, "There were no other warnings");
--
1.7.3.5
|
The RT System itself - Status changed from 'new' to 'open' |
From @cpansproutOn Sun Mar 06 07:23:23 2011, dgl wrote:
Thank you. Applied as 9407f9c. |
@cpansprout - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#85508 (status was 'resolved')
Searchable as RT85508$
The text was updated successfully, but these errors were encountered: