Skip Menu |

This queue is for tickets about the ParseLex CPAN distribution.

Report information
The Basics
Id: 1861
Status: resolved
Priority: 0/
Queue: ParseLex

People
Owner: Nobody in particular
Requestors: shane [...] icserv.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.15
Fixed in: (no value)



Subject: Persistent filehandle problems?
Distribution: ParseLex-2.15 Perl Version: 5.005_03 5.6.1 OS: Red Hat 6.2 (Linux 2.2.14-5.0 i686) Gentoo 1.3 (Linux 2.4.19-gentoo-r7 i686) It appears that ParseLex is holding onto old file handles or something like that. A patch for the problem is attached. The code below produces the problem. #!/usr/bin/perl use strict; use Symbol; my $file = "/tmp/showbugtest.dat"; open F, ">$file" || die "Can't open test data file '$file' $!"; while ( <DATA> ) { print F; } close F; my $fh = gensym; my_parser::parse($file); # Prints: 'GOT: 3 lines' my_parser::parse($fh); # No output because of bad file handle my_parser::parse($file); # Prints: 'GOT: 0 lines', but should be the # same as the first call to parse package my_parser; use strict; use Parse::Lex; use Symbol; sub parse { my $file = shift; my $fh; my $should_close = 0; if ( ref $file eq "GLOB" ) { $fh = $file; fileno( $fh ) or return undef; } else { $fh = gensym; open $fh, $file or die "Can't open file '$file' for import. Error: $!"; $should_close = 1; } my $token; my $line_cnt = 0; my $lexer = Parse::Lex->new( EOR => '\n', LINE => '.*' ); $lexer->from($fh); while ( $lexer->nextis(\$token) ) { ++ $line_cnt if $token->name eq "EOR"; } close $fh if $should_close; # take this out and it MAY work print "GOT: $line_cnt lines\n"; } __END__ 1,one 2,two 3,three
Index: CPAN/ParseLex/lib/Parse/ALex.pm diff -c CPAN/ParseLex/lib/Parse/ALex.pm:1.1 CPAN/ParseLex/lib/Parse/ALex.pm:1.2 *** CPAN/ParseLex/lib/Parse/ALex.pm:1.1 Thu Dec 5 15:52:11 2002 --- CPAN/ParseLex/lib/Parse/ALex.pm Thu Dec 5 16:01:59 2002 *************** *** 252,260 **** my $self = shift; my $debug = 0; # From STREAM ! local *X = $_[0]; ! print STDERR "arg: $_[0] ", fileno(X) , "\n" if $debug; ! if (defined(fileno(X))) { $self->[$STREAM] = $_[0]; print STDERR "From stream\n" if $debug; --- 252,259 ---- my $self = shift; my $debug = 0; # From STREAM ! print STDERR "arg: $_[0] ", fileno($_[0]) , "\n" if $debug; ! if (defined(fileno($_[0]))) { $self->[$STREAM] = $_[0]; print STDERR "From stream\n" if $debug;
Subject: Patch doesn't work under Perl 5.005
From: shane [...] icserv.net
[guest - Fri Dec 6 14:07:21 2002]: The patch I submitted earlier doesn't work under Perl 5.005. I didn't check this before I submitted it. Sorry. Attached is a new patch that works (and passes the test suite) under 5.005 and 5.6.1. Show quoted text
> Distribution: ParseLex-2.15 > Perl Version: 5.005_03 > 5.6.1 > OS: Red Hat 6.2 (Linux 2.2.14-5.0 i686) > Gentoo 1.3 (Linux 2.4.19-gentoo-r7 i686) > > It appears that ParseLex is holding onto old file handles or
something Show quoted text
> like that. A patch for the problem is attached.
Index: CPAN/ParseLex/lib/Parse/ALex.pm diff -c CPAN/ParseLex/lib/Parse/ALex.pm:1.1 CPAN/ParseLex/lib/Parse/ALex.pm:1.2.2.2 *** CPAN/ParseLex/lib/Parse/ALex.pm:1.1 Thu Dec 5 15:52:11 2002 --- CPAN/ParseLex/lib/Parse/ALex.pm Thu Jan 16 17:03:29 2003 *************** *** 252,260 **** my $self = shift; my $debug = 0; # From STREAM ! local *X = $_[0]; ! print STDERR "arg: $_[0] ", fileno(X) , "\n" if $debug; ! if (defined(fileno(X))) { $self->[$STREAM] = $_[0]; print STDERR "From stream\n" if $debug; --- 252,260 ---- my $self = shift; my $debug = 0; # From STREAM ! my $fd = eval { fileno( $_[0] ) }; ! print STDERR "arg: $_[0] ", $fd, "\n" if $debug; ! if (defined( $fd )) { $self->[$STREAM] = $_[0]; print STDERR "From stream\n" if $debug;
 VERSION 2.16 - 5/01/2010
 
o New maintainer pscust@cpan.org
o Parse::Template 0.33 : Fix syntax errors
  Solves RT #7880, #12845, #14785, #11807, #48964, #53112
o Parse::Token    2.16 : Fix syntax errors
  Solves RT #12845, #36285, #48964, #53112
o test4.t : adapt to current Perl (line vs chunk)
  Solves RT #158, #11808, #11809, #12846, #14785, #48964, #53112
o tests : add blib/lib to Perl path
  Solves RT #48964, #53112
o Added test8.t with code from RT #1861, but error is not reproduced in Perl 5.10, and 
  patch does not work in Perl 5.10; patch not added.
 
test8.t fails in perl 5.8.8
Resolved in 2.18, in a way compatible with both perl 5.8 and 5.10 In ALex::from(): check for stream : check only ref($fh) insteaf of fileno() Filehandles connected to memory objects via new features of "open" may return undefined even though they are open.)