summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Pit <vince@profvince.com>2011-11-20 11:56:11 +0100
committerVincent Pit <vince@profvince.com>2011-11-20 11:56:41 +0100
commit7c864bb3ffceec4b5c696507d5fc0d4e9e2f13b3 (patch)
treed5efd902c10f6968c168595552f785075de62097
parentcbd87d8d73269d0f60e1d5c404627169d56ed661 (diff)
downloadperl-7c864bb3ffceec4b5c696507d5fc0d4e9e2f13b3.tar.gz
Handle require() on implicit $_ properly w/r global overrides
Those require() calls are compiled as BASEOPs, so it is invalid to look for their op_first member when they are translated to a call to the global override subroutine. The new entersub call should get $_ in its argument list instead. This fixes [perl #78260].
-rw-r--r--op.c12
-rw-r--r--pod/perldelta.pod6
-rw-r--r--t/op/override.t14
3 files changed, 27 insertions, 5 deletions
diff --git a/op.c b/op.c
index 6a6fa87fa7..8727db4c91 100644
--- a/op.c
+++ b/op.c
@@ -8588,10 +8588,14 @@ Perl_ck_require(pTHX_ OP *o)
}
if (gv && GvCVu(gv) && GvIMPORTED_CV(gv)) {
- OP * const kid = cUNOPo->op_first;
- OP * newop;
-
- cUNOPo->op_first = 0;
+ OP *kid, *newop;
+ if (o->op_flags & OPf_KIDS) {
+ kid = cUNOPo->op_first;
+ cUNOPo->op_first = NULL;
+ }
+ else {
+ kid = newDEFSVOP();
+ }
#ifndef PERL_MAD
op_free(o);
#endif
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index b9e3631495..1e6c7eac17 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -580,6 +580,12 @@ the warnings would occur if enabled in the comparison routine's scope.
C<Internals::SvREFCNT> now behaves consistently in 'get' and 'set' scenarios
[perl #103222] and also treats the reference count as unsigned.
+=item *
+
+Calling C<require> on an implicit C<$_> when C<*CORE::GLOBAL::require> has
+been overridden does not segfault anymore, and C<$_> is now passed to the
+overriding subroutine [perl #78260].
+
=back
=head1 Acknowledgements
diff --git a/t/op/override.t b/t/op/override.t
index 413ba77e84..ab2cbf1515 100644
--- a/t/op/override.t
+++ b/t/op/override.t
@@ -6,7 +6,7 @@ BEGIN {
require './test.pl';
}
-plan tests => 26;
+plan tests => 28;
#
# This file tries to test builtin override using CORE::GLOBAL
@@ -52,6 +52,18 @@ is( $r, join($dirsep, "Foo", "Bar.pm") );
eval "use 5.006";
is( $r, "5.006" );
+{
+ local $_ = 'foo.pm';
+ require;
+ is( $r, 'foo.pm' );
+}
+
+{
+ my $_ = 'bar.pm';
+ require;
+ is( $r, 'bar.pm' );
+}
+
# localizing *CORE::GLOBAL::foo should revert to finding CORE::foo
{
local(*CORE::GLOBAL::require);