develooper Front page | perl.perl5.porters | Postings from September 2005

[perl #37274] The "CORE" in CORE::require is ignored.

Thread Next
From:
Michael G Schwern
Date:
September 25, 2005 17:12
Subject:
[perl #37274] The "CORE" in CORE::require is ignored.
Message ID:
rt-3.0.11-37274-121402.2.62629620280229@perl.org
# New Ticket Created by  Michael G Schwern 
# Please include the string:  [perl #37274]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=37274 >


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

This code works.

BEGIN { 
        *CORE::GLOBAL::require = sub { 
            my $thing = shift; 
            return CORE::require $thing; 
        }; 
} 
 
require LWP;


This code does not.  It goes into deep recursion.

BEGIN { 
        *CORE::GLOBAL::require = sub { 
            my $thing = shift; 
            return eval 'CORE::require $thing;'; 
        }; 
} 
 
require LWP;


This recurses, too.

BEGIN { 
        *CORE::GLOBAL::require = sub { 
            my $thing = shift; 
            return _my_require($thing); 
        }; 
} 
 
sub _my_require { 
    return CORE::require($thing); 
} 
 
require LWP;


This does not recurse, even though it should.

BEGIN { 
        *CORE::GLOBAL::require = sub { 
            my $thing = shift; 
            return require($thing); 
        }; 
} 
 
require LWP; 


This goes into CORE::GLOBAL::require even though it shouldn't.

BEGIN { 
        *CORE::GLOBAL::require = sub { 
            print "CORE::GLOBAL::require called!\n"; 
            my $thing = shift; 
            return require($thing); 
        }; 
} 
 
CORE::require 5; 



The problem in the cases that go into deep recursion is that CORE::require 
is calling CORE::GLOBAL::require instead of CORE::require.  It appears that
there's some sort of special case for CORE::require in that Perl completely
ignores the "CORE" part and instead determines whether or not to call
require() or CORE::require() based on whether or not the calls is inside
CORE::GLOBAL::require.  This is very, very, very broken.  It appears the
brokenness happened between 5.6 and 5.8 (which is when the argument passing
of CORE::GLOBAL::require was fixed to do the bareword processing for you).

Attached is a test for this behavior, though it doesn't get very far
because the first test recurses.  A proper test program would use alarm()
to catch them.


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

Configured by schwern at Tue May 10 16:13:13 PDT 2005.

Summary of my perl5 (revision 5 version 8 subversion 6) configuration:
  Platform:
    osname=darwin, osvers=7.9.0, archname=darwin-thread-multi-2level
    uname='darwin windhund.schwern.org 7.9.0 darwin kernel version 7.9.0: wed mar 30 20:11:17 pst 2005; root:xnuxnu-517.12.7.obj~1release_ppc power macintosh powerpc '
    config_args='-des -Dcc=gcc-3.3 -Dcpp=gcc-3.3 -E -Dprefix=/sw -Dvendorprefix=/sw -Dccflags=-I/sw/include -Dldflags=-L/sw/lib -Dperladmin=none -Uinstallusrbinperl -Dprivlib=/sw/lib/perl5-core/5.8.6 -Dman3dir=/sw/lib/perl5-core/5.8.6/man/man3 -Dman3ext=3pm -Dvendorlib=/sw/lib/perl5/5.8.6 -Dvendorman3dir=/sw/lib/perl5/5.8.6/man/man3 -Duseithreads -Dinc_version_list=5.8.1 5.8.0 5.6.0 -Adefine:startperl=#!/sw/bin/perl5.8.6 -Dotherlibdirs=/Library/Perl'
    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='gcc-3.3', ccflags ='-I/sw/include -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe',
    optimize='-Os',
    cppflags='-no-cpp-precomp -I/sw/include -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe'
    ccversion='', gccversion='3.3 20030304 (Apple Computer, Inc. build 1671)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
    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/sw/lib -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=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-L/sw/lib -bundle -undefined dynamic_lookup -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl v5.8.6:
    /sw/lib/perl5/5.8.6/darwin-thread-multi-2level
    /sw/lib/perl5/5.8.6
    /sw/lib/perl5/5.8.1
    /sw/lib/perl5
    /sw/lib/perl5/darwin
    /sw/lib/perl5-core/5.8.6/darwin-thread-multi-2level
    /sw/lib/perl5-core/5.8.6
    /sw/lib/perl5/site_perl/5.8.6/darwin-thread-multi-2level
    /sw/lib/perl5/site_perl/5.8.6
    /sw/lib/perl5/site_perl
    /sw/lib/perl5/5.8.6/darwin-thread-multi-2level
    /sw/lib/perl5/5.8.6
    /sw/lib/perl5/5.8.1
    /sw/lib/perl5
    /Library/Perl/5.8.1
    /Library/Perl
    .

---
Environment for perl v5.8.6:
    DYLD_LIBRARY_PATH=/usr/local/oracle/instantclient/lib
    HOME=/Users/schwern
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/Users/schwern/bin:/usr/local/bin:/sw/bin:/sw/sbin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:.
    PERL5LIB=/sw/lib/perl5:/sw/lib/perl5/darwin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


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