develooper Front page | perl.perl5.porters | Postings from June 2003

[perl #22811] Assignment to $0 broken

From:
Andreas Koenig
Date:
June 26, 2003 12:32
Subject:
[perl #22811] Assignment to $0 broken
Message ID:
rt-22811-59909.15.8446484522842@rt.perl.org
# New Ticket Created by  Andreas Koenig 
# Please include the string:  [perl #22811]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=22811 >


I'm trying to perlbug this dialog for future references. There's more to come.


-------------------- Start of forwarded message --------------------
Date: Thu Jun 26 15:54:42 2003
From: Various
Subject: Digested Articles

Topics:
   Assignment to $0 still broken
   Re: Assignment to $0 still broken
   the $0
   Re: the $0


----------------------------------------------------------------------

Date: Wed, 25 Jun 2003 02:20:41 +0200
From: Andreas J Koenig <andreas.koenig@anima.de>
To: The Perl5 Porters Mailing List <perl5-porters@perl.org>
Subject: Assignment to $0 still broken
Message-ID: <87znk7j9d2.fsf@franz.ak.mind.de>
Content-Type: text/plain; charset=us-ascii
MIME-Version: 1.0

18229 fixed the bug that had disabled assigning to $0. But the fix is
incomplete. Setting $0 to a string that is shorter than the original
$0 sets the value that is visible from outside to that string but pads
it with blanks. This testscript demonstrates the bug on Linux for me
(depends on external ps):

% cat ak-dollarzero.pl  
#!/usr/bin/perl

use strict;
use warnings;
my $verbose = 0;
$verbose = 1 if @ARGV && $ARGV[0] eq "-v";
sub myps {
  my($arg) = shift;
  $0 = $arg;
  chomp(my $ps = `ps -o command= -p $$`);
  printf "%sok\n", $0 ne $arg || $ps ne $arg ? "not " : "";
  printf "  [%s]\n", $ps if $verbose;
}

myps("x");
myps(join("", 0..9) x 4);
myps("x");


% perl ak-dollarzero.pl -v
not ok
  [x                       ]
ok
  [0123456789012345678901234567890123456789]
not ok
  [x                       ]

Interestingly, the test in ext/threads/t/join.t might be aware of this
problem, since it tests

        if (/\sfoobar\b/) {

and not the more appropriate /\sfoobar$/.

The above testscript printed 3 times "ok" for perl 5.6.0


- - 
andreas


------------------------------

Date: Wed, 25 Jun 2003 19:50:19 +0300
From: Jarkko Hietaniemi <jhi@iki.fi>
To: andreas.koenig@anima.de
Cc: perl5-porters@perl.org
Subject: Re: Assignment to $0 still broken
Message-ID: <20030625165019.GA8944@vipunen.hut.fi>
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
Content-Disposition: inline

> Setting $0 to a string that is shorter than the original $0 sets the
> value that is visible from outside to that string but pads it with
> blanks.

Confirmed in Debian/x86 3.0.

But right now I have no idea of why this is not working.  If I set
a breakpoint to Perl_mg_set(), the '0' branch of the switch statement,
I see the code doing the right modifications to the PL_origargv.
After the modifications are done, I climb upwards in the call stack
all the way to main() and the argv[] has been modified (argv[0] set
to the myps() argument and argv[1] and [2] to empty strings).
And that particular code has not changed functionally since 5.6.1.

- - 
Jarkko Hietaniemi <jhi@iki.fi> http://www.iki.fi/jhi/ "There is this special
biologist word we use for 'stable'.  It is 'dead'." -- Jack Cohen


------------------------------

Date: Wed, 25 Jun 2003 23:33:38 +0300
From: Jarkko Hietaniemi <jhi@iki.fi>
To: andreas.koenig@anima.de
Subject: the $0
Message-ID: <20030625203338.GB8944@vipunen.hut.fi>
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
Content-Disposition: inline

Try binsearchaperl to see which patch between 5.6.0 and 5.8.0 broke
the $0 padding, was it the same that broke the $0 setting in general?

- - 
Jarkko Hietaniemi <jhi@iki.fi> http://www.iki.fi/jhi/ "There is this special
biologist word we use for 'stable'.  It is 'dead'." -- Jack Cohen


------------------------------

Date: Thu, 26 Jun 2003 11:01:24 +0200
From: Andreas J Koenig <andreas.koenig@anima.de>
To: jhi@iki.fi
Cc: andreas.koenig@anima.de
Subject: Re: the $0
Message-ID: <873chxb4bf.fsf@franz.ak.mind.de>
References: <20030625203338.GB8944@vipunen.hut.fi>
Content-Type: text/plain; charset=us-ascii
MIME-Version: 1.0

Jarkko Hietaniemi <jhi@iki.fi> writes:

> Try binsearchaperl to see which patch between 5.6.0 and 5.8.0 broke
> the $0 padding, was it the same that broke the $0 setting in general?

Yes, it was the same: 11559. At least I see no change in behaviour
between 11559 and your 18229.

Ahh, now I understand what you probably mean: Reverse apply 11559
during the binary search and see where the padding was introduced. I
manually tried that with the randomly chosen 15226 and 18228: yes,
15226 was OK, 18228 was not OK. So I'm on an interesting track.

You'll hear from me again soon.

- - 
andreas


------------------------------

End of forward5051isv Digest
****************************

-------------------- End of forwarded message --------------------

-- 
andreas




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About