This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
avoid identical stack traces
authorDavid Mitchell <davem@iabyn.com>
Fri, 13 Dec 2019 13:48:25 +0000 (13:48 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 13 Dec 2019 21:38:45 +0000 (21:38 +0000)
commitf2f32cd638746f538da6db804dab6dd54e654f30
treef5e152c50a4190af6b22798921e90e0fbd5faeb0
parent2f580e4a5aae92e985b4bc612e7324f9c85713d7
avoid identical stack traces

GH #15109

The output of caller() (e.g. as produced by carp::Confess) produces
multiple identical outputs when within a nested use/require. This is
because at the time of calling the 'BEGIN { require ... }', PL_curcop is
set to &PL_compiling, which is a fixed buffer within the interpreter,
whose individual file and line fields are saved and restored when doing
a new require/eval. This means that within the innermost require,
PL_compiling has file:lineno of the innermost source file, and multiple
saved PL_curcop values in the context stack frames all point to the same
&PL_copmpiling.  So all levels of the stack trace appear to come from the
innermost file.

This commit fixes this (after a fashion) by, at the start of calling a
BEGIN, making PL_curcop point to a temporary copy of PL_compiling
instead.

This is all a bit of a hack.
MANIFEST
op.c
t/lib/GH_15109/Apack.pm [new file with mode: 0644]
t/lib/GH_15109/Bpack.pm [new file with mode: 0644]
t/lib/GH_15109/Cpack.pm [new file with mode: 0644]
t/op/caller.t