# HG changeset patch # User Stephen Thorne # Parent d9c98730e2e87b09096bc98e535e5683cb969ea4 Issue #14988: When pyexpat.so is missing or will otherwise cause an ImportError, importing _elementtree will propagate the ImportError instead of raising RuntimeError. diff -r d9c98730e2e8 Misc/NEWS --- a/Misc/NEWS Sat Jul 07 13:34:50 2012 +1000 +++ b/Misc/NEWS Sat Jul 07 23:03:02 2012 +0200 @@ -54,6 +54,10 @@ - Issue #15194: Update libffi to the 3.0.11 release. +- Issue #14988: When pyexpat.so is missing or will otherwise cause an + ImportError, importing _elementtree will propagate the ImportError instead of + raising RuntimeError. + Tools/Demos ----------- diff -r d9c98730e2e8 Modules/_elementtree.c --- a/Modules/_elementtree.c Sat Jul 07 13:34:50 2012 +1000 +++ b/Modules/_elementtree.c Sat Jul 07 23:03:02 2012 +0200 @@ -3504,21 +3504,19 @@ /* link against pyexpat */ expat_capi = PyCapsule_Import(PyExpat_CAPSULE_NAME, 0); - if (expat_capi) { - /* check that it's usable */ - if (strcmp(expat_capi->magic, PyExpat_CAPI_MAGIC) != 0 || - expat_capi->size < sizeof(struct PyExpat_CAPI) || - expat_capi->MAJOR_VERSION != XML_MAJOR_VERSION || - expat_capi->MINOR_VERSION != XML_MINOR_VERSION || - expat_capi->MICRO_VERSION != XML_MICRO_VERSION) { - expat_capi = NULL; - } - } - if (!expat_capi) { - PyErr_SetString( - PyExc_RuntimeError, "cannot load dispatch table from pyexpat" - ); + if (expat_capi == NULL) return NULL; + + /* check that it's usable */ + if (strcmp(expat_capi->magic, PyExpat_CAPI_MAGIC) != 0 || + expat_capi->size < sizeof(struct PyExpat_CAPI) || + expat_capi->MAJOR_VERSION != XML_MAJOR_VERSION || + expat_capi->MINOR_VERSION != XML_MINOR_VERSION || + expat_capi->MICRO_VERSION != XML_MICRO_VERSION) { + PyErr_SetString( + PyExc_RuntimeError, "cannot load dispatch table from pyexpat" + ); + return NULL; } elementtree_parseerror_obj = PyErr_NewException(