This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #68712] caller() filenames broken by "use"
authorFather Chrysostomos <sprout@cpan.org>
Sat, 11 Dec 2010 05:46:13 +0000 (21:46 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 11 Dec 2010 05:47:21 +0000 (21:47 -0800)
require() sets the file name for PL_compiling but localises it to the
calling scope, not the scope that it creates. As a result, caller()
during or after require (in the same scope that require was called
from) will return the wrong file name for whichever code is being com-
piled at the time and any scope sharing the same CopFILE (or something
like that):

$ ./miniperl -Ilib -e 'BEGIN{require strict; warn join ", ", caller(0)}'
main, lib/strict.pm, 1, main::BEGIN, 1, , , , 0, ,  at -e line 1.
      ^^^^^^^^^^^^^ should be -e

This commit moves the SAVECOPFILE_FREE and CopFILE_set down below the
ENTER_with_name to put it in the right scope. It was in its existing
location presumably because namesv needed to be freed before any code
that could die (and the CopFILE_set call reads a PV allocated for
namesv). So now namesv is mortalised instead.

The if(tryrsfp) is no longer necessary, as that code is never reached
when tryrsfp is false.

The block in between that sets %INC was reading CopFILE. It can simply
use the same tryname variable that is passed to CopFILE_set.


No differences found