summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pp_ctl.c4
-rw-r--r--t/op/incfilter.t22
2 files changed, 24 insertions, 2 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index 28e258b7ed..d6b59ad833 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -5240,6 +5240,7 @@ S_run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen)
I'm going to use a mortal in case the upstream filter croaks. */
upstream = ((SvOK(buf_sv) && sv_len(buf_sv)) || SvGMAGICAL(buf_sv))
? sv_newmortal() : buf_sv;
+ SvTEMP_off(upstream);
SvUPGRADE(upstream, SVt_PV);
if (filter_has_file) {
@@ -5251,11 +5252,12 @@ S_run_user_filter(pTHX_ int idx, SV *buf_sv, int maxlen)
int count;
ENTER_with_name("call_filter_sub");
- SAVE_DEFSV;
+ SAVEGENERICSV(GvSV(PL_defgv));
SAVETMPS;
EXTEND(SP, 2);
DEFSV_set(upstream);
+ SvREFCNT_inc_simple_void_NN(upstream);
PUSHMARK(SP);
mPUSHi(0);
if (filter_state) {
diff --git a/t/op/incfilter.t b/t/op/incfilter.t
index 74675a2c12..9db4f7d21b 100644
--- a/t/op/incfilter.t
+++ b/t/op/incfilter.t
@@ -13,7 +13,7 @@ use strict;
use Config;
use Filter::Util::Call;
-plan(tests => 143);
+plan(tests => 145);
unshift @INC, sub {
no warnings 'uninitialized';
@@ -227,3 +227,23 @@ for (0 .. 1) {
\'like(__FILE__, qr/(?:GLOB|CODE)\(0x[0-9a-f]+\)/, "__FILE__ is valid");';
do $fh or die;
}
+
+# [perl #91880] $_ marked TEMP or having the wrong refcount inside a
+{ # filter sub
+ local @INC; local $|;
+ unshift @INC, sub { sub { undef *_; --$| }};
+ do "dah";
+ pass '$_ has the right refcount inside a filter sub';
+
+ my $temps = 0;
+ @INC = sub { sub {
+ my $temp = \sub{$_}->();
+ $temps++ if $temp == \$_;
+ $_ = "a" unless $|;
+ return --$|
+ }};
+ local $^W;
+ do "dah";
+
+ is $temps, 0, '$_ is not marked TEMP';
+}