This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Use longjmp to abandon first pass quickly
authorKarl Williamson <public@khwilliamson.com>
Wed, 1 Sep 2010 17:40:32 +0000 (11:40 -0600)
committerRafael Garcia-Suarez <rgs@consttype.org>
Mon, 13 Sep 2010 12:06:09 +0000 (14:06 +0200)
commitbbd61b5ffb7621c2fcb7c3dd1beba837f27a9b40
treefa2e7d5d30f7a9eebc0c58fb628fea84306cbd77
parent62fed28b592e017778cf07b732b66755ea7b0b61
regcomp.c: Use longjmp to abandon first pass quickly

regcomp.c currently does a first pass to determine the size needed for
the regex.  If the regex needs to be in utf8, but this wasn't known at
the beginning of the pass the size computation needs to be completely
redone with that in mind.  The input is converted to utf8 and the first
pass is redone.  Prior to this patch, the discovery of needing to redo
the first pass merely set a flag and continued the now useless rest of
the first pass.  This patch causes this first pass to be aborted
immediately upon discovering that it will have to be redone.

This uses the Perl macros that wrap setjmp and longjmp.  When the first
pass is abandoned, it longjmps back to the corresponding setjmp to
convert to utf8 and redo.  I was advised that I could use setjmp and
longjump directly, but it seemed safer to use the wrappers, as they
should know about any platform-dependent issues.

If this code intercepts a longjmp that wasn't meant for it, it simply
reissues the longjmp so that the correct handler will get it.

This patch should have no effect on externally visible behavior, except
for a speedup of some regex compiles.
regcomp.c