Skip Menu |
Report information

Subject: Filter::Simple with immediately following "no"
Date: Sun, 08 Jan 2012 10:32:35 +1100
To: perlbug [...] perl.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 1.1k
With recent debian perl 5.14.2, if a Filter::Simple module is turned off with a "no" immediately after being turned on, like use MyFilter; no MyFilter; then the remaining script after the "no" is ignored. The attached foo.el script and MyFilter.pm module show the problem. Running perl foo.el I expected it to print "this part is not filtered", but it doesn't. If you put a blank line after "use MyFilter" it does. I struck this with Smart::Comments when I'd deleted everything between use and no, but left those lines intending perhaps to add back some code there shortly ... Nosing around Filter::Simple it looks like when the terminator is found on the very first call of the filter_add() handler, the handler returns 0, which the perl parser perhaps takes to mean EOF, and therefore stops reading. I expect it ought to return with "no MyFilter" or suitably mangled terminator, to have that run as code. Dunno if an empty "use/no" block ought to be shown to the FILTER{} etc code of the subclass. I suppose currently a "use MyFilter" immediately followed by EOF has not called with an empty, so maybe no empties should be shown to it, by default at least.
Download foo.pl
text/x-perl 77b
use lib '.'; use MyFilter; no MyFilter; print "this part is not filtered\n";
Download MyFilter.pm
text/x-perl 79b
package MyFilter; use Filter::Simple; FILTER { print "FILTER code runs\n"; }
Download (untitled) / with headers
text/plain 2.6k
----------------------------------------------------------------- --- Flags: category=library severity=medium module=Filter::Simple --- Site configuration information for perl 5.14.2: Configured by Debian Project at Mon Nov 28 21:49:25 UTC 2011. Summary of my perl5 (revision 5 version 14 subversion 2) configuration: Platform: osname=linux, osvers=2.6.32-5-686, archname=i486-linux-gnu-thread-multi-64int uname='linux callisto 2.6.32-5-686 #1 smp mon oct 3 04:15:24 utc 2011 i686 gnulinux ' config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.14 -Darchlib=/usr/lib/perl/5.14 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.14.2 -Dsitearch=/usr/local/lib/perl/5.14.2 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Duse64bitint -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Ui_libutil -DDEBUGGING=-g -Doptimize=-O2 -Duseshrplib -Dlibperl=libperl.so.5.14.2 -des' hint=recommended, useposix=true, d_sigaction=define useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=define, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2 -g', cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion='', gccversion='4.6.2', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /lib/i386-linux-gnu /lib/../lib /usr/lib/i386-linux-gnu /usr/lib/../lib /lib /usr/lib /usr/lib64 libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt perllibs=-ldl -lm -lpthread -lc -lcrypt libc=, so=so, useshrplib=true, libperl=libperl.so.5.14.2 gnulibc_version='2.13' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib -fstack-protector' Locally applied patches:
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 856b
I have attempted to reproduce your problem in blead with the script you provided, but was unable to. ~/tmp/FS$ cat foo.pl use lib '.'; use MyFilter; no MyFilter; print "this part is not filtered\n"; ~/tmp/FS$ cat MyFilter.pm package MyFilter; use Filter::Simple; FILTER { print "FILTER code runs\n"; } 1; ~/tmp/FS$ perl foo.pl FILTER code runs this part is not filtered I thought maybe the problem had been fixed since your report, but with 5.14.2, I still get the same result. ~/tmp/FS$ perlbrew use 14.2 ~/tmp/FS$ perl -v |head -2 This is perl 5, version 14, subversion 2 (v5.14.2) built for darwin-2level ~/tmp/FS$ perl foo.pl FILTER code runs this part is not filtered I am tentatively rejecting this bug. If you can provide further steps to reproduce it, please reply and we can re-open it. -- rjbs
Subject: Re: [perl #107726] Filter::Simple with immediately following "no"
Date: Sat, 07 Sep 2013 10:12:23 +1000
To: perlbug-followup [...] perl.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 688b
"Ricardo SIGNES via RT" <perlbug-followup@perl.org> writes: Show quoted text
> > ~/tmp/FS$ cat MyFilter.pm > package MyFilter; > use Filter::Simple; > FILTER { > print "FILTER code runs\n"; > } > 1;
The MyFilter.pm must end as I posted without "1;". In that case it still fails for me, with recent debian i386 5.14.2 and current filter 1.49 and Filter::Simple 0.88. Such an end without "1;" is per the examples in demo/*.pm. -- If a grizzly bear is coming at you past advice has been "stand still". Recently this has been revised to "run if you want to". Running is the reason you have legs and during your last few seconds of life you may as well put them to their intended use.
RT-Send-CC: perl5-porters [...] perl.org
Whoops! Yes, verified. So, the question I had was, then, "what is the magic true value?" It had the be the result of calling FILTER. I hadn't included a semicolon after the subroutine passed to FILTER, so 1 became its argument, making "1" the terminator for the filter, rather than the "no MyFilter" it expected. I think the little state machine that gathers lines has an off-by-one, although I've really only given it a cursory glance. I suggest this patch: diff --git a/dist/Filter-Simple/lib/Filter/Simple.pm b/dist/Filter-Simple/lib/Filter/Simple.pm index d1da0b2..f0ad0f3 100644 --- a/dist/Filter-Simple/lib/Filter/Simple.pm +++ b/dist/Filter-Simple/lib/Filter/Simple.pm @@ -198,6 +198,7 @@ sub gen_filter_import { if ($terminator{terminator} && m/$terminator{terminator}/) { $lastline = $_; + $count++; last; } $data .= $_; Other eyes are encouraged. -- rjbs
Subject: Re: [perl #107726] Filter::Simple with immediately following "no"
Date: Fri, 13 Sep 2013 07:57:07 +1000
To: perlbug-followup [...] perl.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 442b
"Ricardo SIGNES via RT" <perlbug-followup@perl.org> writes: Show quoted text
> > making "1" the terminator for the filter,
Ah, something subtle there. Show quoted text
> I think the little state machine
It's actually a slurp through to the terminator, no? The docs could make that clearer, since the bare filter stuff is normally line by line. Show quoted text
> + $count++;
Yes, looks likely. It actually only needs a flag rather than a count anyway I suppose.
CC: perlbug-followup [...] perl.org
Subject: Re: [perl #107726] Filter::Simple with immediately following "no"
Date: Thu, 12 Sep 2013 22:17:25 -0400
To: Kevin Ryde <user42 [...] zip.com.au>
From: Ricardo Signes <perl.p5p [...] rjbs.manxome.org>
Download (untitled) / with headers
text/plain 261b
* Kevin Ryde <user42@zip.com.au> [2013-09-12T17:57:07] Show quoted text
> > Yes, looks likely. It actually only needs a flag rather than a count > anyway I suppose.
Could you write a test for the bug? Then I'll apply your test and my patch and we'll high five. :) -- rjbs
Download signature.asc
application/pgp-signature 490b

Message body not shown because it is not plain text.

Subject: Re: [perl #107726] Filter::Simple with immediately following "no"
Date: Mon, 16 Sep 2013 19:01:50 +1000
To: perlbug-followup [...] perl.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 255b
"Ricardo Signes via RT" <perlbug-followup@perl.org> writes: Show quoted text
> > Could you write a test for the bug?
Yes. I wouldn't mind also if the docs began by summarizing the good things of Filter::Simple rather than describing how hard is Filter::Util::Call :-).
CC: perlbug-followup [...] perl.org
Subject: Re: [perl #107726] Filter::Simple with immediately following "no"
Date: Mon, 16 Sep 2013 19:20:55 -0400
To: Kevin Ryde <user42 [...] zip.com.au>
From: Ricardo Signes <perl.p5p [...] rjbs.manxome.org>
Download (untitled) / with headers
text/plain 498b
* Kevin Ryde <user42@zip.com.au> [2013-09-16T05:01:50] Show quoted text
> "Ricardo Signes via RT" <perlbug-followup@perl.org> writes:
> > > > Could you write a test for the bug?
> > Yes. > > I wouldn't mind also if the docs began by summarizing the good things of > Filter::Simple rather than describing how hard is Filter::Util::Call > :-).
Such a patch would also be welcome! The days are clearly long gone when anybody needs to be convinved to use Filter::Simple rather than filter::Util::Call. :) -- rjbs
Download signature.asc
application/pgp-signature 490b

Message body not shown because it is not plain text.

RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 438b
On Thu Sep 12 19:18:12 2013, perl.p5p@rjbs.manxome.org wrote: Show quoted text
> * Kevin Ryde <user42@zip.com.au> [2013-09-12T17:57:07]
> > > > Yes, looks likely. It actually only needs a flag rather than a count > > anyway I suppose.
> > Could you write a test for the bug? Then I'll apply your test and my > patch and > we'll high five. :)
I have just added a test in 7e9e80a7 and applied Ricardo’s patch as 8bc40f3a4eb. -- Father Chrysostomos
Download (untitled) / with headers
text/plain 313b
Thank you for filing this report. You have helped make Perl better. With the release today of Perl 5.26.0, this and 210 other issues have been resolved. Perl 5.26.0 may be downloaded via: https://metacpan.org/release/XSAWYERX/perl-5.26.0 If you find that the problem persists, feel free to reopen this ticket.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org