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
tr/// against $1 causes persistent data #1964
Comments
From rootbeer@redcat.comThis is a bug report for perl from rootbeer@redcat.com, The substitution near the end of this chunk of code should change $_ from $_ = "fred"; It's entertaining to run this to completion in the debugger (not stepping Flags: Site configuration information for perl v5.6.0: Configured by rootbeer at Sun Apr 23 14:09:13 PDT 2000. Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration: Locally applied patches: @INC for perl v5.6.0: Environment for perl v5.6.0: |
From @vanstynIn <Pine.GSO.4.10.10005111759110.16364-100000@user2.teleport.com>, Tom Phoenix This appears to occur because the tr/// sets POK on $1, which bypasses I'm not sure quite why this line exists, since removing it does not Hugo Inline Patch--- doop.c.old Sun Mar 12 03:36:32 2000
+++ doop.c Fri May 12 10:41:04 2000
@@ -592,7 +592,8 @@
return 0;
if (!SvPOKp(sv))
(void)SvPV_force(sv, len);
- (void)SvPOK_only(sv);
+ if (!SvGMAGICAL(sv))
+ (void)SvPOK_only(sv);
DEBUG_t( Perl_deb(aTHX_ "2.TBL\n"));
|
From [Unknown Contact. See original ticket]Hugo <hv@crypt.compulink.co.uk> wrote
It exists to ensure that the attached tests pass. :-) And I think the "correct" fix is to avoid the SvPOK_only in the Patch for 5.6.0 and new tests attached. And I've added comments to the new tests - perhaps that'll start Mike Guy Inline Patch--- ./t/op/tr.t.orig Fri May 12 17:28:34 2000
+++ ./t/op/tr.t Fri May 12 17:34:18 2000
@@ -5,7 +5,7 @@
unshift @INC, "../lib";
}
-print "1..4\n";
+print "1..6\n";
$_ = "abcdefghijklmnopqrstuvwxyz";
@@ -37,3 +37,19 @@
print "ok 4\n";
}
#
+
+# make sure that tr cancels IOK and NOK
+($x = 12) =~ tr/1/3/;
+(my $y = 12) =~ tr/1/3/;
+($f = 1.5) =~ tr/1/3/;
+(my $g = 1.5) =~ tr/1/3/;
+print "not " unless $x + $y + $f + $g == 71;
+print "ok 5\n";
+
+# make sure tr is harmless if not updating - see [ID 20000511.005]
+$_ = 'fred';
+/([a-z]{2})/;
+$1 =~ tr/A-Z//;
+s/^(\s*)f/$1F/;
+print "not " if $_ ne 'Fred';
+print "ok 6\n";
--- ./doop.c.orig Fri May 12 15:41:40 2000
+++ ./doop.c Fri May 12 17:40:21 2000
@@ -592,7 +592,8 @@
return 0;
if (!SvPOKp(sv))
(void)SvPV_force(sv, len);
- (void)SvPOK_only(sv);
+ if (!(PL_op->op_private & OPpTRANS_IDENTICAL))
+ (void)SvPOK_only(sv);
DEBUG_t( Perl_deb(aTHX_ "2.TBL\n"));
End of patch |
From [Unknown Contact. See original ticket]I wrote
For some values of "correct" only. This second try ensures that I note that Robin Barker, in his recent patch to vec(), uses SvNIOK_off [*] Though I did find some strange examples of "correct" behaviour. ($! = 28) =~ tr/2/3/ will do? Mike Guy Inline Patch--- ./t/op/tr.t.orig Fri May 12 19:06:02 2000
+++ ./t/op/tr.t Sat May 13 09:48:39 2000
@@ -5,7 +5,7 @@
unshift @INC, "../lib";
}
-print "1..4\n";
+print "1..8\n";
$_ = "abcdefghijklmnopqrstuvwxyz";
@@ -37,3 +37,27 @@
print "ok 4\n";
}
#
+
+# make sure that tr cancels IOK and NOK
+($x = 12) =~ tr/1/3/;
+(my $y = 12) =~ tr/1/3/;
+($f = 1.5) =~ tr/1/3/;
+(my $g = 1.5) =~ tr/1/3/;
+print "not " unless $x + $y + $f + $g == 71;
+print "ok 5\n";
+
+# make sure tr is harmless if not updating - see [ID 20000511.005]
+$_ = 'fred';
+/([a-z]{2})/;
+$1 =~ tr/A-Z//;
+s/^(\s*)f/$1F/;
+print "not " if $_ ne 'Fred';
+print "ok 6\n";
+
+# check tr handles UTF8 correctly
+($x = 256.65.258) =~ tr/a/b/;
+print "not " if $x ne 256.65.258 or length $x != 3;
+print "ok 7\n";
+$x =~ tr/A/B/;
+print "not " if $x ne 256.66.258 or length $x != 3;
+print "ok 8\n";
--- ./doop.c.orig Fri May 12 19:06:03 2000
+++ ./doop.c Sat May 13 09:54:44 2000
@@ -592,7 +592,8 @@
return 0;
if (!SvPOKp(sv))
(void)SvPV_force(sv, len);
- (void)SvPOK_only(sv);
+ if (!(PL_op->op_private & OPpTRANS_IDENTICAL))
+ (void)SvPOK_only_UTF8(sv);
DEBUG_t( Perl_deb(aTHX_ "2.TBL\n"));
End of patch |
From [Unknown Contact. See original ticket]M.J.T. Guy writes:
Lemme try to predict what it *should* do. $! is assignable as a In the first case numerical value of the message (thus 0) is put in Checking... I get Argument "Disk full" isn't numeric in trans at -e line 1. So there is no skip-assignment optimization... Ilya |
From @smpeters
It looks like this patch or the other patch in this ticket thread were Change 17984 by rgs@rgs-home on 2002/10/09 19:17:08 Fix bug #17823 : non-modifying tr/// stringifies references Affected files ... ... //depot/perl/doop.c#129 edit Differences ... ==== //depot/perl/doop.c#129 (text) ==== @@ -608,10 +608,11 @@ DEBUG_t( Perl_deb(aTHX_ "2.TBL\n")); ==== //depot/perl/t/op/tr.t#33 (xtext) ==== @@ -6,7 +6,7 @@ -plan tests => 97; my $Is_EBCDIC = (ord('i') == 0x89 & ord('J') == 0xd1); @@ -379,3 +379,7 @@ |
@smpeters - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#3237 (status was 'resolved')
Searchable as RT3237$
The text was updated successfully, but these errors were encountered: