[XML-SIG] pyexpat interface issue

Fred L. Drake, Jr. fdrake@acm.org
Tue, 15 May 2001 13:06:36 -0400 (EDT)

  The pyexpat module defines two wrappers for handlers which are
expected to return integers (NotStandaloneHandler and
ExternalEntityRefHandler).  What stands out about these handlers is
that Expat is expecting a return value (the others have void
returns).  The wrappers will propogate an exception if one is raised
by the Python handler implementation, but then assumes that the return
value is actually an integer.  They use PyInt_AsLong() to convert the
return value to an integer, but don't check the return value:  if
PyInt_AsLong() returns -1 and PyErr_Occurred() is non-NULL, a
TypeError was raised by PyInt_AsLong() because the value passed to it
was not an integer object.  The -1 will be passed to Expat, which will
happily continue parsing since it expects a false value to tell it to
stop parsing.  This has been this way for a while.
  Should the documentation for these interfaces be modifed to reflect
this (strange) behavior, with some code cleanup to avoid having unused
exception state laying around (which *can* show up later in unrelated
code), or should the implementation be fixed to propogate the
exception, or something else?  I'm concerned that changing the actual
behavior will adversely effect existing code that uses pyexpat.


Fred L. Drake, Jr.  <fdrake at acm.org>
PythonLabs at Digital Creations