[Python-Dev] getcode() function in pyexpat.c

Jeremy Hylton jeremy@alum.mit.edu
Mon, 22 Jan 2001 10:26:27 -0500 (EST)

The pyexpat module uses functions named getcode() and
call_with_frame() for handlers of some sort.  I can make this much out
from the code, but the rest is a bit of a mystery.  I was trying to
read this code because of the errors Tim is seeing with test_sax on
Windows.  A few comments to explain this highly stylized and
macro-laden code would be appreciated.

The module appears to be creating empty code objects and calling
them.  I say they appear to be empty, because when they are created 
they don't appear to have anything initialized except name, filename,
and firstlineno.

    getcode(EndNamespaceDecl, 419)
    <code at 0x81b73c0
        co_name = 'EndNamespaceDecl'
        co_filename = 'pyexpat.c'
        co_firstlineno = 419
        co_argcount = 0
        co_nlocals = 0
        co_stacksize = 0
        co_flags = 0
        co_consts = ()
        co_names = ()
        co_varnames = ()
        co_freevars = ()
        co_cellvars = ()
        co_code = ''

(The freevars and cellvars entries are part of the support for nested
scopes.  They can be safely ignored for the moment.) 

I simply don't understand what's going on -- and I'm deeply suspicious
that it is the source of whatever problems Tim is seeing with