Closed p5pRT closed 17 years ago
If you run:
\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\< perl -wle 'my $h = "Hello"; print for sort { lc($a) ? 0 : 0 } "$h"\, "";'
You'll get the output of:
{{{{{ hello }}}}}
Which indicates that the output result of the string "$h" that was given as input to sort were changed as a result of the lc($a) operation. It also happens with uc($a).
It doesn't seem to affect a simple $h\, without the quotes.
On 13/06/07\, via RT Shlomi Fish \perlbug\-followup@​perl\.org wrote:
If you run:
\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\< perl -wle 'my $h = "Hello"; print for sort { lc($a) ? 0 : 0 } "$h"\, "";'
You'll get the output of:
{{{{{ hello }}}}}
Which indicates that the output result of the string "$h" that was given as input to sort were changed as a result of the lc($a) operation. It also happens with uc($a).
I don't understand your report\, but it looks like you want a stable sort. For that\, look at the sort pragma.
The RT System itself - Status changed from 'new' to 'open'
Rafael Garcia-Suarez skribis 2007-06-13 15:52 (+0200):
perl -wle 'my $h = "Hello"; print for sort { lc($a) ? 0 : 0 } "$h"\, "";' hello I don't understand your report\, but it looks like you want a stable sort. For that\, look at the sort pragma.
"$h" should be Hello\, but hello is printed. Apparently lc($a) mutated $h\, although that effect is not there if $h is used without quotes. -- korajn salutojn\,
juerd waalboer: perl hacker \juerd@​juerd\.nl \<http://juerd.nl/sig> convolution: ict solutions and consultancy \sales@​convolution\.nl
On 13/06/07\, Juerd Waalboer \juerd@​convolution\.nl wrote:
Rafael Garcia-Suarez skribis 2007-06-13 15:52 (+0200):
perl -wle 'my $h = "Hello"; print for sort { lc($a) ? 0 : 0 } "$h"\, "";' hello I don't understand your report\, but it looks like you want a stable sort. For that\, look at the sort pragma.
"$h" should be Hello\, but hello is printed. Apparently lc($a) mutated $h\, although that effect is not there if $h is used without quotes.
aah\, yes. Very odd.
On 6/13/07\, Rafael Garcia-Suarez \rgarciasuarez@​gmail\.com wrote:
On 13/06/07\, via RT Shlomi Fish \perlbug\-followup@​perl\.org wrote:
If you run:
\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\< perl -wle 'my $h = "Hello"; print for sort { lc($a) ? 0 : 0 } "$h"\, "";'
You'll get the output of:
{{{{{ hello }}}}}
Which indicates that the output result of the string "$h" that was given as input to sort were changed as a result of the lc($a) operation. It also happens with uc($a).
I don't understand your report\, but it looks like you want a stable sort. For that\, look at the sort pragma.
Nope. The issue was lc() changing its argument. The example with sort was only a way to demonstrate it.
Here's another:
$ perl -e ' $a = "Hello"; for ("$a") { lc $_; print }' hello
When the "$a" gets aliased\, it is being changed in place.
It does not happen without quotes or with constants:
$ perl -e ' $a = "Hello"; for ($a) { lc $_; print }' Hello
$ perl -e ' for ("Hello") { lc $_; print }' Hello
On 13/06/07\, Adriano Ferreira \a\.r\.ferreira@​gmail\.com wrote:
Nope. The issue was lc() changing its argument. The example with sort was only a way to demonstrate it.
Here's another:
$ perl -e ' $a = "Hello"; for ("$a") { lc $_; print }' hello
Yes\, it seems that the logic in pp_lc is flawed:
if (SvPADTMP(source) && !SvREADONLY(source) && !SvAMAGIC(source) && !DO_UTF8(source)) { /* We can convert in place. */ dest = source;
Maybe we should add an SvTEMP check here too...
@rgs - Status changed from 'open' to 'resolved'
On 13/06/07\, Rafael Garcia-Suarez \rgarciasuarez@​gmail\.com wrote:
On 13/06/07\, Adriano Ferreira \a\.r\.ferreira@​gmail\.com wrote:
Nope. The issue was lc() changing its argument. The example with sort was only a way to demonstrate it.
Here's another:
$ perl -e ' $a = "Hello"; for ("$a") { lc $_; print }' hello
Yes\, it seems that the logic in pp_lc is flawed:
if \(SvPADTMP\(source\) && \!SvREADONLY\(source\) && \!SvAMAGIC\(source\) && \!DO\_UTF8\(source\)\) \{ /\* We can convert in place\. \*/ dest = source;
Maybe we should add an SvTEMP check here too...
Now added (and to uc/lcfirst/ucfirst too) as change #31377.
On Thu Jun 14 04:26:54 2007\, rafael wrote:
On 13/06/07\, Rafael Garcia-Suarez \rgarciasuarez@​gmail\.com wrote:
On 13/06/07\, Adriano Ferreira \a\.r\.ferreira@​gmail\.com wrote:
Nope. The issue was lc() changing its argument. The example with sort was only a way to demonstrate it.
Here's another:
$ perl -e ' $a = "Hello"; for ("$a") { lc $_; print }' hello
Yes\, it seems that the logic in pp_lc is flawed:
if \(SvPADTMP\(source\) && \!SvREADONLY\(source\) && \!SvAMAGIC\(source\) && \!DO\_UTF8\(source\)\) \{ /\* We can convert in place\. \*/ dest = source;
Maybe we should add an SvTEMP check here too...
Now added (and to uc/lcfirst/ucfirst too) as change #31377.
(aka 17fa077605)
But PADTMPs are never SvTEMP\, so now this optimisation never happens. I tried adding assert(0)\, and all tests passed.
This bug is actually related to #78194. If we make for() and ()x... (and other operations) copy the PADTMP ahead of time\, preventing it ever from appearing on the stack twice\, this bug would be fixed as a result\, and 17fa077605 could be reverted.
--
Father Chrysostomos
On Sun Jul 29 11:04:32 2012\, sprout wrote:
On Thu Jun 14 04:26:54 2007\, rafael wrote:
On 13/06/07\, Rafael Garcia-Suarez \rgarciasuarez@​gmail\.com wrote:
On 13/06/07\, Adriano Ferreira \a\.r\.ferreira@​gmail\.com wrote:
Nope. The issue was lc() changing its argument. The example with sort was only a way to demonstrate it.
Here's another:
$ perl -e ' $a = "Hello"; for ("$a") { lc $_; print }' hello
Yes\, it seems that the logic in pp_lc is flawed:
if \(SvPADTMP\(source\) && \!SvREADONLY\(source\) && \!SvAMAGIC\(source\) && \!DO\_UTF8\(source\)\) \{ /\* We can convert in place\. \*/ dest = source;
Maybe we should add an SvTEMP check here too...
Now added (and to uc/lcfirst/ucfirst too) as change #31377.
(aka 17fa077605)
But PADTMPs are never SvTEMP\, so now this optimisation never happens. I tried adding assert(0)\, and all tests passed.
This bug is actually related to #78194. If we make for() and ()x... (and other operations) copy the PADTMP ahead of time\, preventing it ever from appearing on the stack twice\, this bug would be fixed as a result\, and 17fa077605 could be reverted.
I have reënabled in-place uc/lc in commit 5cd5e2d630.
--
Father Chrysostomos
Migrated from rt.perl.org#43207 (status was 'resolved')
Searchable as RT43207$