develooper Front page | perl.perl5.porters | Postings from December 2015

[perl #127083] Caller inside BEGIN block return wrong info

Thread Next
From:
KES
Date:
December 30, 2015 12:31
Subject:
[perl #127083] Caller inside BEGIN block return wrong info
Message ID:
rt-4.0.18-1239-1451478660-343.127083-75-0@perl.org
# New Ticket Created by  KES 
# Please include the string:  [perl #127083]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=127083 >


To: perlbug@perl.org
Reply-To: kes-kes@yandex.ru
Message-Id: <5.22.0_15075_1451477435@keswork>
Subject: Caller inside BEGIN block return wrong info
Cc: kes-kes@yandex.ru
From: kes-kes@yandex.ru


This is a bug report for perl from kes-kes@yandex.ru,
generated with the help of perlbug 1.40 running under perl 5.22.0.


-----------------------------------------------------------------
[Please describe your issue here]
$cat t.pl
#!/usr/bin/env perl

BEGIN {
    local $" = ' - ';
    my $level =  0;
    while( my @frame =  caller( $level++ ) ) {
        print "@frame[0..3]\n";
    }
    print "\n";
}

use Mod2;

$cat Mod2.pm
package Mod2;
#2
#3
#4
BEGIN {
    local $" = ' - ';
    my $level =  0;
    while( my @frame =  caller( $level++ ) ) {
        print "@frame[0..3]\n";
    }
    print "\n";
}

use Mod1;

1;

$cat Mod1.pm
package Mod1;
#2
#3
#4
#5
#6
BEGIN {
    local $" = ' - ';
    my $level =  0;
    while( my @frame =  caller( $level++ ) ) {
        print "@frame[0..3]\n";
    }
    print "\n";
}

1;

The output is:
main - ./t.pl - 10 - main::BEGIN
main - ./t.pl - 10 - (eval)

main - Mod2.pm - 12 - Mod2::BEGIN
main - Mod2.pm - 12 - (eval)
main - ./t.pl - 12 - (eval)
main - Mod2.pm - 12 - main::BEGIN
main - Mod2.pm - 12 - (eval)

main - Mod1.pm - 14 - Mod1::BEGIN
main - Mod1.pm - 14 - (eval)
Mod2 - Mod2.pm - 14 - (eval)
main - Mod1.pm - 14 - Mod2::BEGIN
main - Mod1.pm - 14 - (eval)
main - ./t.pl - 12 - (eval)
main - Mod1.pm - 14 - main::BEGIN
main - Mod1.pm - 14 - (eval)


It is not expected that the information about last frames is changed.
I think that the call to 'caller' from Mod1 should look like:
main - Mod1.pm - 14 - Mod1::BEGIN
main - Mod1.pm - 14 - (eval)
Mod2 - Mod2.pm - 14 - (eval)
main - Mod2.pm - 12 - Mod2::BEGIN
main - Mod2.pm - 12 - (eval)
main - ./t.pl - 12 - (eval)
main - ./t.pl - 10 - main::BEGIN
main - ./t.pl - 10 - (eval)





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

Configured by kes at Tue Sep 29 16:12:55 EEST 2015.

Summary of my perl5 (revision 5 version 22 subversion 0) configuration:
   
  Platform:
    osname=linux, osvers=3.13.0-37-generic, archname=x86_64-linux
    uname='linux keswork 3.13.0-37-generic #64-ubuntu smp mon sep 22 21:28:38 utc 2014 x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Dprefix=/home/kes/perl'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.8.4', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.19.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.19'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'


---
@INC for perl 5.22.0:
    /home/kes/work/projects/perl_libs/lib
    /home/kes/perl5/lib/perl5/x86_64-linux
    /home/kes/perl5/lib/perl5
    /home/kes/perl/lib/site_perl/5.22.0/x86_64-linux
    /home/kes/perl/lib/site_perl/5.22.0
    /home/kes/perl/lib/5.22.0/x86_64-linux
    /home/kes/perl/lib/5.22.0
    .

---
Environment for perl 5.22.0:
    HOME=/home/kes
    LANG=ru_UA.UTF-8
    LANGUAGE=en
    LC_MESSAGES=en_US.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/kes/perl/bin:/home/kes/perl/bin:/home/kes/perl5/bin:/home/kes/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
    PERL5DB=BEGIN { require "Devel/KillPrint.pm" }
    PERL5LIB=/home/kes/work/projects/perl_libs/lib:/home/kes/perl5/lib/perl5
    PERLDB_OPTS=RemotePort=keswork:9001
    PERL_BADLANG (unset)
    PERL_MB_OPT=--install_base "/home/kes/perl5"
    PERL_MM_OPT=INSTALL_BASE=/home/kes/perl5
    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