Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carp inadvertently autovivifies CORE::GLOBAL::caller #10672

Closed
p5pRT opened this issue Sep 27, 2010 · 5 comments
Closed

Carp inadvertently autovivifies CORE::GLOBAL::caller #10672

p5pRT opened this issue Sep 27, 2010 · 5 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented Sep 27, 2010

Migrated from rt.perl.org#78082 (status was 'resolved')

Searchable as RT78082$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Sep 27, 2010

From @arc

Created by @arc

As of bf236c8, lib/Carp.pm contains a bare
reference to \&CORE​::GLOBAL​::caller. This autovivifies
$CORE​::GLOBAL​::{caller}, which could be annoying in some situations.

The attached patch fixes that, and adds a test to prevent it happening again.

Perl Info

Flags:
    category=library
    severity=low
    module=Carp

Site configuration information for perl 5.13.5:

Configured by aaron at Fri Sep 24 09:48:49 BST 2010.

Summary of my perl5 (revision 5 version 13 subversion 5) configuration:
  Commit id: 6481ebaf76d95c32fd79e91c0f39c17b16bd73e4
  Platform:
    osname=darwin, osvers=10.4.0, archname=darwin-2level
    uname='darwin zzz 10.4.0 darwin kernel version 10.4.0: fri apr 23
18:28:53 pdt 2010; r
    config_args='-des -Dprefix=/opt/bleadperl -Dusedevel'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-common -DPERL_DARWIN -no-cpp-precomp
-fno-strict-aliasing -pip
    optimize='-O3',
    cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN
-no-cpp-precomp -fno-strict-aliasi
    ccversion='', gccversion='4.2.1 (Apple Inc. build 5664)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, 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 ='
-fstack-protector -L/opt/local/l
    libpth=/opt/local/lib /usr/lib
    libs=-lgdbm -ldbm -ldl -lm -lutil -lc
    perllibs=-ldl -lm -lutil -lc
    libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup
-L/opt/local/lib -fstack

Locally applied patches:



@INC for perl 5.13.5:
    /opt/bleadperl/lib/site_perl/5.13.5/darwin-2level
    /opt/bleadperl/lib/site_perl/5.13.5
    /opt/bleadperl/lib/5.13.5/darwin-2level
    /opt/bleadperl/lib/5.13.5
    /opt/bleadperl/lib/site_perl
    .


Environment for perl 5.13.5:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/zzz
    LANG=en_GB.UTF-8
    LANGUAGE (unset)
    LC_COLLATE=C
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

-- 
Aaron Crane ** http://aaroncrane.co.uk/

Loading

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Sep 27, 2010

From @arc

0001-lib-Carp.pm-Avoid-autovivification-of-CORE-GLOBAL-ca.patch
From 93553813cde1bf59b3422a33435f467cc3c23dfb Mon Sep 17 00:00:00 2001
From: Aaron Crane <arc@cpan.org>
Date: Mon, 27 Sep 2010 12:02:01 +0100
Subject: [PATCH] lib/Carp.pm: Avoid autovivification of CORE::GLOBAL::caller

And add a test to prevent this happening again.
---
 lib/Carp.pm |    3 ++-
 lib/Carp.t  |    9 +++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/Carp.pm b/lib/Carp.pm
index 0e9105a..6aba427 100644
--- a/lib/Carp.pm
+++ b/lib/Carp.pm
@@ -86,7 +86,8 @@ sub caller_info {
       @DB::args = (); # Don't let anyone see the address of $i
       local $@;
       my $where = eval {
-	my $gv = B::svref_2object(\&CORE::GLOBAL::caller)->GV;
+	my $func = defined &{"CORE::GLOBAL::caller"} ? \&{"CORE::GLOBAL::caller"} : return '';
+	my $gv = B::svref_2object($func)->GV;
 	my $package = $gv->STASH->NAME;
 	my $subname = $gv->NAME;
 	return unless defined $package && defined $subname;
diff --git a/lib/Carp.t b/lib/Carp.t
index 1c59987..8240cd3 100644
--- a/lib/Carp.t
+++ b/lib/Carp.t
@@ -11,9 +11,14 @@ my $Is_VMS = $^O eq 'VMS';
 
 use Carp qw(carp cluck croak confess);
 
-plan tests => 56;
+BEGIN {
+	plan tests => 56;
 
-ok 1;
+	# This test must be run at BEGIN time, because code later in this file
+	# sets CORE::GLOBAL::caller
+	ok !exists $CORE::GLOBAL::{caller},
+	  "Loading doesn't create CORE::GLOBAL::caller"
+}
 
 { local $SIG{__WARN__} = sub {
     like $_[0], qr/ok (\d+)\n at.+\b(?i:carp\.t) line \d+$/, 'ok 2\n' };
-- 
1.7.3

Loading

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Sep 27, 2010

From @cpansprout

On Mon Sep 27 04​:19​:47 2010, arc wrote​:

As of bf236c8, lib/Carp.pm contains a
bare
reference to \&CORE​::GLOBAL​::caller. This autovivifies
$CORE​::GLOBAL​::{caller}, which could be annoying in some situations.

The attached patch fixes that, and adds a test to prevent it happening
again.

Thank you. I’ve applied this as 39d0b21ca5a59dba7652555c425faec6c7a5e653.

Loading

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Sep 27, 2010

The RT System itself - Status changed from 'new' to 'open'

Loading

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Sep 27, 2010

@cpansprout - Status changed from 'open' to 'resolved'

Loading

@p5pRT p5pRT closed this Sep 27, 2010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant