This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2013-07-18.21:04:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1374181487.7.0.883080946196.issue18501@psf.upfronthosting.co.za>
In-reply-to
Content
For the issue #18408, I added assertions in PyEval_EvalFrameEx() and similar functions to exit with an assertion error in debug mode if these functions are called with an exception set:

New changeset 48a869a39e2d by Victor Stinner in branch 'default':
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
http://hg.python.org/cpython/rev/48a869a39e2d

New changeset 5bd9db528aed by Victor Stinner in branch 'default':
Issue #18408: PyObject_Str(), PyObject_Repr() and type_call() now fail with an
http://hg.python.org/cpython/rev/5bd9db528aed

lxml test suite failed with an C assertion error because of these changes. I fixed the issue with the following change:

New changeset 6ec0e9347dd4 by Victor Stinner in branch 'default':
Issue #18408: Fix _elementtree.c, don't call Python function from an expat
http://hg.python.org/cpython/rev/6ec0e9347dd4

Instead of having to check if an exception is set in each Python callback, it would be better to "stop" the XML parser. Modules/pyexpat.c calls "flag_error(self); XML_SetCharacterDataHandler(self->itself, noop_character_data_handler);" on error:

/* This handler is used when an error has been detected, in the hope
   that actual parsing can be terminated early.  This will only help
   if an external entity reference is encountered. */
static int
error_external_entity_ref_handler(XML_Parser parser,
                                  const XML_Char *context,
                                  const XML_Char *base,
                                  const XML_Char *systemId,
                                  const XML_Char *publicId)
{
    return 0;
}

/* Dummy character data handler used when an error (exception) has
   been detected, and the actual parsing can be terminated early.
   This is needed since character data handler can't be safely removed
   from within the character data handler, but can be replaced.  It is
   used only from the character data handler trampoline, and must be
   used right after `flag_error()` is called. */
static void
noop_character_data_handler(void *userData, const XML_Char *data, int len)
{
    /* Do nothing. */
}

static void
flag_error(xmlparseobject *self)
{
    clear_handlers(self, 0);
    XML_SetExternalEntityRefHandler(self->itself,
                                    error_external_entity_ref_handler);
}
History
Date User Action Args
2013-07-18 21:04:47vstinnersetrecipients: + vstinner
2013-07-18 21:04:47vstinnersetmessageid: <1374181487.7.0.883080946196.issue18501@psf.upfronthosting.co.za>
2013-07-18 21:04:47vstinnerlinkissue18501 messages
2013-07-18 21:04:47vstinnercreate