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

[perl #54040] Misparsing of sort comparison subroutine intention

Thread Next
From:
Ken Williams
Date:
May 12, 2008 11:03
Subject:
[perl #54040] Misparsing of sort comparison subroutine intention
Message ID:
rt-3.6.HEAD-11257-1210607087-958.54040-75-0@perl.org
# New Ticket Created by  Ken Williams 
# Please include the string:  [perl #54040]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=54040 >


To: perlbug@perl.org
Subject: Misparsing of sort subroutine intention
Reply-To: ken.williams@thomson.com
Message-Id: <5.8.6_1048_1210604177@mailbo2.westgroup.com>

This is a bug report for perl from ken.williams@thomson.com,
generated with the help of perlbug 1.35 running under perl v5.8.6.


-----------------------------------------------------------------
[Please enter your report here]

I was surprised by the following behavior of the parser, which
misinterprets the union() subroutine call as a SUBNAME comparison
routine for the sort() function:

==================
% cat c2.pl
use strict;
my %one = qw(a 1 b 2 c 3);
my %two = qw(a 1 c 2 e 3);
sub union {
  my %h;
  $h{$_}++ for @_;
  keys %h;
}
foreach my $k (sort union(keys(%one), keys(%two)) ) {
  print "$k\n";
}

% perl c2.pl       
c
a
b
e
c
a

% perl -MO=Deparse,-p c2.pl
use strict 'refs';
(my(%one) = ('a', '1', 'b', '2', 'c', '3'));
(my(%two) = ('a', '1', 'c', '2', 'e', '3'));
sub union {
    my(%h);
    (++$h{$_}) foreach (@_);
    keys(%h);
}
foreach my($k) (sort union keys(%one), keys(%two)) {
    print("$k\n");
}
c2.pl syntax OK
==================

Of course, I can use explicit parens for the sort() function, but I
thought the parens I'm using for the union() function should have been
sufficient.

I verified that this same behavior exists with my copy of perl 5.10.0
also.

 -Ken

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
Site configuration information for perl v5.8.6:

Configured by root at Wed Nov  1 16:59:38 PST 2006.

Summary of my perl5 (revision 5 version 8 subversion 6) configuration:
  Platform:
    osname=darwin, osvers=8.0, archname=darwin-thread-multi-2level
    uname='darwin b19.apple.com 8.0 darwin kernel version 8.3.0: mon oct 3
20:04:04 pdt 2005; root:xnu-792.6.22.obj~2release_ppc power macintosh
powerpc '
    config_args='-ds -e -Dprefix=/usr -Dccflags=-g  -pipe
-Dldflags=-Dman3ext=3pm -Duseithreads -Duseshrplib'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-g -pipe -fno-common -DPERL_DARWIN -no-cpp-precomp
-fno-strict-aliasing -I/usr/local/include',
    optimize='-O3',
    cppflags='-no-cpp-precomp -g -pipe -fno-common -DPERL_DARWIN
-no-cpp-precomp -fno-strict-aliasing -I/usr/local/include'
    ccversion='', gccversion='4.0.1 (Apple Computer, Inc. build 5363)',
gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags ='-L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib
    libs=-ldbm -ldl -lm -lc
    perllibs=-ldl -lm -lc
    libc=/usr/lib/libc.dylib, so=dylib, useshrplib=true,
libperl=libperl.dylib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-bundle -undefined dynamic_lookup
-L/usr/local/lib'

Locally applied patches:
    23953 - fix for File::Path::rmtree CAN-2004-0452 security issue
    33990 - fix for setuid perl security issues
    SPRINTF0 - fixes for sprintf formatting issues - CVE-2005-3962

---
@INC for perl v5.8.6:
    /System/Library/Perl/5.8.6/darwin-thread-multi-2level
    /System/Library/Perl/5.8.6
    /Library/Perl/5.8.6/darwin-thread-multi-2level
    /Library/Perl/5.8.6
    /Library/Perl
    /Network/Library/Perl/5.8.6/darwin-thread-multi-2level
    /Network/Library/Perl/5.8.6
    /Network/Library/Perl
    /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level
    /System/Library/Perl/Extras/5.8.6
    /Library/Perl/5.8.1
    .

---
Environment for perl v5.8.6:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/u0048513
    LANG (unset)
    LANGUAGE (unset)
    LC_ALL=C
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    
PATH=/bin:/etc:/usr/bin:/usr/etc:/usr/sbin:/sbin:/Users/u0048513/bin:/usr/lo
cal/bin:/sw/bin:/Users/u0048513/p4/tools/FileTools:/Users/u0048513/p4/tools/
perforce:.
    PERL_BADLANG (unset)
    SHELL=/bin/zsh

-- 
Ken Williams
Research Scientist
The Thomson Corporation
Eagan, MN


Thread Next


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