STINNER Victor added the comment: 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); } ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue18501> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com