develooper Front page | perl.perl5.porters | Postings from March 2003

Re: Parse::RecDescent triggers infinete loop in perl5.9.0 and 5.8.1 [perl #17757]

Thread Previous | Thread Next
From:
hv
Date:
March 9, 2003 21:54
Subject:
Re: Parse::RecDescent triggers infinete loop in perl5.9.0 and 5.8.1 [perl #17757]
Message ID:
200303100556.h2A5uHS24899@crypt.compulink.co.uk
David Dyck <david.dyck@fluke.com> wrote:
:The following code using Parse::RecDescent does
:an infinite loop with perl5.9.0  (presuming with 5.8.1)
:but finishes fine with perl5.8.0.  I haven't simplified
:this as much as I could yet, the grammar comes
:from derived from Inline::C::ParseRecDescent, where
:I first saw the problem in its make test.

Here's another step of simplification:

#!/usr/bin/perl -w
use strict;

sub get_parser {
    require Parse::RecDescent;
    $main::RD_HINT++;
    Parse::RecDescent->new(grammar())
}


sub grammar {
    <<'END';
code:   'x' { '...' }
END
}

BEGIN { $::RD_TRACE = 1; }

get_parser()->code('x');
get_parser()->code('x');
__END__

If I copy the Parse::RecDescent module into a new file and require
that instead, the problem goes away, so I'm not sure how best to
track this down further. But the -Dr output before hitting the loop
is down to under 6K lines now, so I think it's starting to come
within reach. Just to recapitulate, the tail of that output looks
like:
  Matching REx `^["'`]' against `''
    Setting an EVAL scope, savestack=165
     0 <> <'>               |  1:  BOL
     0 <> <'>               |  2:  ANYOF["'`]
     1 <'> <>               | 13:  END
  Match successful!
  Guessing start of match, REx ` \' [^\\']* (\\.[^\\']*)* \' ' against `'...']; }
  '...
  Found floating substr `'' at offset -243388...
  Contradicts anchored substr `'', trying floating at offset -243387...
  Found floating substr `'' at offset -243431...
  Contradicts anchored substr `'', trying floating at offset -243430...
  Found floating substr `'' at offset -243431...
  Contradicts anchored substr `'', trying floating at offset -243430...
[loop]

The construction of the string also seems important: if I replace the
grammar with the (theoretically identical):
sub grammar {
    q[code:   'x' { '...' }
]
}
.. it no longer fails. I suspect this is down to malloc perturbation,
since various small changes can cause it to stop failing either with
or without -Dr, or both.

Hugo

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About