develooper Front page | perl.perl5.porters | Postings from April 2008

Re: [perl #51568] Scalar::Util::looks_like_number vs. Optimzation in regex?

Thread Previous
From:
Nicholas Clark
Date:
April 23, 2008 14:23
Subject:
Re: [perl #51568] Scalar::Util::looks_like_number vs. Optimzation in regex?
Message ID:
20080423212300.GB79799@plum.flirble.org
On Mon, Mar 10, 2008 at 03:59:28AM -0700, Steffen_Ullrich @ genua. de wrote:
> # New Ticket Created by  Steffen_Ullrich@genua.de 
> # Please include the string:  [perl #51568]
> # in the subject line of all future correspondence about this issue. 
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=51568 >
> 
> 
> 
> This is a bug report for perl from Steffen_Ullrich@genua.de,
> generated with the help of perlbug 1.35 running under perl v5.8.8.
> 
> 
> -----------------------------------------------------------------
> [Please enter your report here]
> 
> Hi,
> looks like I've triggered a problem with a regex followed by a looks_like_number.
> With the example program (below) I can trigger the problem on perl5.8.8 on Linux,
> OpenBSD, and MacOSX and with perl5.10 on MacOSX (no other platforms tested).
> 
> If I use this example program the call of test1 on line 5 gives shows, that
> looks_like_number gives false, while the same call in line 7 gives true.
> If I slightly modify the call to have a temporary variable in the call of
> looks_like_number it succeedes. 
> Playing with the order of the calls of test1 and test2 I get:
> - test2 (with the temp variable=) succeedes every time
> - test1 fails if called as the first test
> - test1 succeeds if called after a (successful) test2 or after a (failed) test1

Succeeds a second time. Curious...

On Mon, Mar 10, 2008 at 03:55:06PM -0400, Eric Brine wrote:

> Don't pass globals (especially, $!, $1 and $@) to functions. Pass a copy
> instead. The problem arises because Perl passes arguments by reference (uses
> aliasing) and (probably) because looks_like_number changes $3.

Yes, I thought this at first, but I think that actually it's a bug in
Scalar::Util. If I make the appended change, the example code passes every
time (and all existing tests pass)

==== //depot/perl/ext/List/Util/Util.xs#37 - /Volumes/Stuff/p4perl/perl/ext/List/Util/Util.xs ====
--- /tmp/tmp.88918.40   2008-04-23 22:14:38.000000000 +0100
+++ /Volumes/Stuff/p4perl/perl/ext/List/Util/Util.xs    2008-04-23 18:28:24.000000000 +0100
@@ -485,6 +485,7 @@ looks_like_number(sv)
        SV *sv
 PROTOTYPE: $
 CODE:
+  SvGETMAGIC(sv);
 #if (PERL_VERSION < 8) || (PERL_VERSION == 8 && PERL_SUBVERSION <5)
   if (SvPOK(sv) || SvPOKp(sv)) {
     RETVAL = looks_like_number(sv);


I'll let Graham Barr apply this upstream, if he thinks that it's the correct
fix, and then we'll merge from there into the Perl core.

Nicholas Clark

Thread Previous


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