summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-08-24 21:57:43 (GMT)
committerFred Drake <fdrake@acm.org>2000-08-24 21:57:43 (GMT)
commitc23b5239ae0681624511e8bf98003f4c5bb9e0ff (patch)
tree9caf0ae3343c0c1b4e0b0154099aff678b1cf3a5
parentfa12e13ae7e5a95f83e4880f518f32f083bdd010 (diff)
downloadcpython-c23b5239ae0681624511e8bf98003f4c5bb9e0ff.zip
cpython-c23b5239ae0681624511e8bf98003f4c5bb9e0ff.tar.gz
cpython-c23b5239ae0681624511e8bf98003f4c5bb9e0ff.tar.bz2
Remove the Py_FatalError() from initpyexpat(); the Guido has decreed
that this is not appropriate. Made somewhat more robust in the face of reload() (exception is not rebuilt, etc.). Made the exception a class exception.
-rw-r--r--Modules/pyexpat.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 6e04b2e..6572037 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -863,24 +863,40 @@ initpyexpat(void)
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
- ErrorObject = PyString_FromString("pyexpat.error");
+ if (ErrorObject == NULL)
+ ErrorObject = PyErr_NewException("pyexpat.error", NULL, NULL);
PyDict_SetItemString(d, "error", ErrorObject);
PyDict_SetItemString(d, "__version__",
PyString_FromStringAndSize(rev+11,
strlen(rev+11)-2));
- sys_modules = PySys_GetObject("modules");
- errors_module = PyModule_New("pyexpat.errors");
- PyDict_SetItemString(d, "errors", errors_module);
- PyDict_SetItemString(sys_modules, "pyexpat.errors", errors_module);
-
/* XXX When Expat supports some way of figuring out how it was
compiled, this should check and set native_encoding
appropriately.
*/
PyDict_SetItemString(d, "native_encoding",
PyString_FromString("UTF-8"));
+
+ sys_modules = PySys_GetObject("modules");
+ {
+ PyObject *errmod_name = PyString_FromString("pyexpat.errors");
+
+ if (errmod_name != NULL) {
+ errors_module = PyDict_GetItem(errmod_name);
+ if (errors_module == NULL) {
+ errors_module = PyModule_New("pyexpat.errors");
+ if (errors_module != NULL) {
+ PyDict_SetItemString(d, "errors", errors_module);
+ PyDict_SetItem(sys_modules, errmod_name, errors_module);
+ }
+ }
+ PyDECREF(errmod_name);
+ if (errors_module == NULL)
+ /* Don't code dump later! */
+ return;
+ }
+ }
errors_dict = PyModule_GetDict(errors_module);
#define MYCONST(name) \
@@ -906,10 +922,6 @@ initpyexpat(void)
MYCONST(XML_ERROR_MISPLACED_XML_PI);
MYCONST(XML_ERROR_UNKNOWN_ENCODING);
MYCONST(XML_ERROR_INCORRECT_ENCODING);
-
- /* Check for errors */
- if (PyErr_Occurred())
- Py_FatalError("can't initialize module pyexpat");
}
void clear_handlers(xmlparseobject *self)