if (SvROK(arg) && (SvTYPE(SvRV(arg)) <= SVt_PVLV)
&& !isGV_with_GP(SvRV(arg))) {
filter_cache = SvRV(arg);
- SvREFCNT_inc_simple_void_NN(filter_cache);
if (i < count) {
arg = SP[i++];
}
filter_has_file = 0;
- if (filter_cache) {
- SvREFCNT_dec(filter_cache);
- filter_cache = NULL;
- }
+ filter_cache = NULL;
if (filter_state) {
SvREFCNT_dec(filter_state);
filter_state = NULL;
than hanging another SV from it. In turn, filter_add() optionally
takes the SV to use as the filter (or creates a new SV if passed
NULL), so simply pass in whatever value filter_cache has. */
- SV * const datasv = filter_add(S_run_user_filter, filter_cache);
+ SV * const fc = filter_cache ? newSV(0) : NULL;
+ SV *datasv;
+ if (fc) sv_copypv(fc, filter_cache);
+ datasv = filter_add(S_run_user_filter, fc);
IoLINES(datasv) = filter_has_file;
IoTOP_GV(datasv) = MUTABLE_GV(filter_state);
IoBOTTOM_GV(datasv) = MUTABLE_GV(filter_sub);
use Config;
use Filter::Util::Call;
-plan(tests => 145);
+plan(tests => 148);
unshift @INC, sub {
no warnings 'uninitialized';
do \"pass\n(\n'Scalar references are treated as initial file contents'\n)\n"
or die;
+use constant scalarreffee =>
+ "pass\n(\n'Scalar references are treated as initial file contents'\n)\n";
+do \scalarreffee or die;
+is scalarreffee,
+ "pass\n(\n'Scalar references are treated as initial file contents'\n)\n",
+ 'and are not gobbled up when read-only';
+
+{
+ local $SIG{__WARN__} = sub {}; # ignore deprecation warning from ?...?
+ do qr/a?, 1/;
+ pass "No crash (perhaps) when regexp ref is returned from inc filter";
+ # Even if that outputs "ok", it may not have passed, as the crash
+ # occurs during globular destruction. But the crash will result in
+ # this script failing.
+}
+
open $fh, "<", \"ss('The file is concatenated');";
do [\'pa', $fh] or die;