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

[perl #51072] Method dispatch breaks with defined(\&sub)

Thread Next
nagler @ bivio . biz
February 21, 2008 08:08
[perl #51072] Method dispatch breaks with defined(\&sub)
Message ID:
# New Ticket Created by 
# Please include the string:  [perl #51072]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.35 running under perl v5.8.5.

[Please enter your report here]
From: Rob Nagler <>
Subject: Re: [] mod_perl package lexicals becoming corrupt
Date: Wed, 20 Feb 2008 12:49:32 -0700

Found the bug.  Here's what demonstrates it:

    package T1;
    use strict;
    sub s1 {}

    package T2;
    use base 'T1';
    use strict;

    package main;
    print("not reached\n");

The \&T2:s1 autovivifies something in the package hash, which is
"nasty", and actually ends up corrupting the package hash so that
lexicals disappear.  We had a function called super_for_method, which
did this:

    foreach my $a (@{$proto->inheritance_ancestors}) {
 	my($sub) = \&{$a . '::' . $method};
 	next unless defined(&$sub);
 	return ($sub, $a);

The fact that \&{} seems to autovivify an invalid package hash entry
is the problem.  You can implement the above this way:

    foreach my $a (@{$proto->inheritance_ancestors}) {
	my($sub) = $a . '::' . $method;
	do {
	    no strict 'refs';
	    next unless defined(&$sub);
	return (\&$sub, $a);

The above code does not corrupt the the package hash.  Both pieces of
code autovivify the glob for $sub, but in the former case, the
autovivification has a dangerous side effect of corrupting the entire
symbol table (in a subtle way, of course, which is why I got confused
by the number of lexicals).


[Please do not change anything below this line]
This perlbug was built using Perl v5.8.5 in the Red Hat build system.
It is being executed now by Perl v5.8.5 - Wed Nov  7 16:36:26 EST 2007.

Site configuration information for perl v5.8.5:

Configured by Red Hat, Inc. at Wed Nov  7 16:36:26 EST 2007.

Summary of my perl5 (revision 5 version 8 subversion 5) configuration:
    osname=linux, osvers=2.6.9-55.0.9.elsmp, archname=i386-linux-thread-multi
    uname='linux 2.6.9-55.0.9.elsmp #1 smp thu sep 27 18:27:41 edt 2007 i686 i686 i386 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -m32 -march=i386 -mtune=pentium4 -Dversion=5.8.5 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dinc_version_list=5.8.4 5.8.3 5.8.2 5.8.1 5.8.0'
    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
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2 -g -pipe -m32 -march=i386 -mtune=pentium4',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='3.4.6 20060404 (Red Hat 3.4.6-8)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/, so=so, useshrplib=true,
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.8.5/i386-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:

@INC for perl v5.8.5:

Environment for perl v5.8.5:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)
    PERL_MM_OPT=PREFIX=/home/nagler INSTALLMAN1DIR=/home/nagler/man/man1 INSTALLMAN3DIR=/home/nagler/man/man3

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About