[Python-Dev] sre.c and sre_match()
Jack Diederich
jack@performancedrivers.com
Wed, 16 Apr 2003 09:55:00 -0400
On Tue, Apr 15, 2003 at 11:22:42PM -0400, Tim Peters wrote:
> [Jack Diederich]
> > I can't find sre_match() anywhere in the source
>
> It's in _sre.c, here:
>
> LOCAL(int)
> SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level)
>
> SRE_MATCH is a macro, and expands to either sre_match or sre_umatch,
> depending on whether Unicode support is enabled. Note that _sre.c arranges
> to compile itself *twice*, via its
>
> #define SRE_RECURSIVE
> #include "_sre.c"
> #undef SRE_RECURSIVE
>
> This is to get both 8-bit and Unicode versions of the basic routines when
> Unicode support is enabled.
>
My god, its full of stars.
Ah, that explains how both sre_umatch() and sre_umatch() get defined and make
the if (state.charsize == 1) switches possible.
the SRE_RECURSIVE isn't hard to understand once you know it is there, but
might it be tidier to breakout the stuff parsed twice into another file?
The current layout of the _sre.c is
<stuff done once, setup stuff>
<stuff done twice, via #include "_sre.c">
<stuff done once, object stuff>
mv <stuff done twice> to _sre_twice.c
#define SRE_MATCH sre_match
#include "_sre_twice.c" /* defines the symbols sre_match, sre_search .. */
#define SRE_MATCH sre_umatch
#include "_sre_twice.c" /* defines the symbols sre_umatch, sre_usearch .. */
<stuff done once>
You probably don't get random people walking around _sre.c much, but it would
have gotten me where I need to go (or at least a better chance).
thanks,
-jack