Index: _testcapimodule.c =================================================================== --- _testcapimodule.c (revision 78171) +++ _testcapimodule.c (working copy) @@ -1730,39 +1730,42 @@ } \ PyObject *module = PyImport_ImportModule(known->module); - if (module) { - pointer = PyCapsule_Import(known->name, 0); - if (!pointer) { - Py_DECREF(module); - FAIL("PyCapsule_GetPointer returned NULL unexpectedly!"); - } - object = PyObject_GetAttrString(module, known->attribute); - if (!object) { - Py_DECREF(module); - return NULL; - } - pointer2 = PyCapsule_GetPointer(object, - "weebles wobble but they don't fall down"); - if (!PyErr_Occurred()) { - Py_DECREF(object); - Py_DECREF(module); - FAIL("PyCapsule_GetPointer should have failed but did not!"); - } - PyErr_Clear(); - if (pointer2) { - Py_DECREF(module); - Py_DECREF(object); - if (pointer2 == pointer) { - FAIL("PyCapsule_GetPointer should not have" - " returned its internal pointer!"); - } else { - FAIL("PyCapsule_GetPointer should have" - " returned NULL pointer but did not!"); - } - } - Py_DECREF(object); - Py_DECREF(module); - } + if (!module) { + PyErr_Clear(); + continue; + } + + pointer = PyCapsule_Import(known->name, 0); + if (!pointer) { + Py_DECREF(module); + FAIL("PyCapsule_GetPointer returned NULL unexpectedly!"); + } + object = PyObject_GetAttrString(module, known->attribute); + if (!object) { + Py_DECREF(module); + return NULL; + } + pointer2 = PyCapsule_GetPointer(object, + "weebles wobble but they don't fall down"); + if (!PyErr_Occurred()) { + Py_DECREF(object); + Py_DECREF(module); + FAIL("PyCapsule_GetPointer should have failed but did not!"); + } + PyErr_Clear(); + if (pointer2) { + Py_DECREF(module); + Py_DECREF(object); + if (pointer2 == pointer) { + FAIL("PyCapsule_GetPointer should not have" + " returned its internal pointer!"); + } else { + FAIL("PyCapsule_GetPointer should have" + " returned NULL pointer but did not!"); + } + } + Py_DECREF(object); + Py_DECREF(module); } exit: