From 9bfd2bf5ede8e5d58775180d6867d81ddcdd3594 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Fri, 1 Sep 2000 09:01:32 +0000 Subject: Do the absolute minimal amount of modifications to eradicate Py_FatalError() from module initialization functions. The importing mechanism already checks for PyErr_Occurred() after module importation and it Does The Right Thing. Unfortunately, the following either were not compiled or tested by the regression suite, due to issues with my development platform: almodule.c cdmodule.c mpzmodule.c puremodule.c timingmodule.c --- Modules/almodule.c | 7 ++----- Modules/cdmodule.c | 3 --- Modules/errnomodule.c | 21 +++++++++------------ Modules/fcntlmodule.c | 4 ---- Modules/linuxaudiodev.c | 7 ++----- Modules/mathmodule.c | 3 +-- Modules/mpzmodule.c | 10 ++++++---- Modules/parsermodule.c | 9 ++++----- Modules/pcremodule.c | 4 ---- Modules/puremodule.c | 2 -- Modules/shamodule.c | 4 ---- Modules/stropmodule.c | 3 --- Modules/syslogmodule.c | 4 ---- Modules/timemodule.c | 15 +++++++-------- Modules/timingmodule.c | 2 -- 15 files changed, 31 insertions(+), 67 deletions(-) diff --git a/Modules/almodule.c b/Modules/almodule.c index f162cf5..23fd96f 100644 --- a/Modules/almodule.c +++ b/Modules/almodule.c @@ -3242,9 +3242,6 @@ inital(void) (void) ALseterrorhandler(ErrorHandler); #endif /* OLD_INTERFACE */ - /* Check for errors */ - if (PyErr_Occurred()) { - error: - Py_FatalError("can't initialize module al"); - } + error: + return; } diff --git a/Modules/cdmodule.c b/Modules/cdmodule.c index 8042075..5f88a0f 100644 --- a/Modules/cdmodule.c +++ b/Modules/cdmodule.c @@ -802,7 +802,4 @@ initcd(void) #ifdef CD_CDROM /* only newer versions of the library */ PyDict_SetItemString(d, "CDROM", PyInt_FromLong((long) CD_CDROM)); #endif - - if (PyErr_Occurred()) - Py_FatalError("can't initialize module cd"); } diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c index 8607ea2..b47feb6 100644 --- a/Modules/errnomodule.c +++ b/Modules/errnomodule.c @@ -35,17 +35,14 @@ static PyMethodDef errno_methods[] = { static void _inscode(PyObject *d, PyObject *de, char *name, int code) { - PyObject *u; - PyObject *v; + PyObject *u = PyString_FromString(name); + PyObject *v = PyInt_FromLong((long) code); - u = PyString_FromString(name); - v = PyInt_FromLong((long) code); - - if (!u || !v) { - /* Don't bother reporting this error */ - PyErr_Clear(); - } - else { + /* Don't bother checking for errors; they'll be caught at the end + * of the module initialization function by the caller of + * initerrno(). + */ + if (u && v) { /* insert in modules dict */ PyDict_SetItem(d, u, v); /* insert in errorcode dict */ @@ -76,8 +73,8 @@ initerrno(void) m = Py_InitModule3("errno", errno_methods, errno__doc__); d = PyModule_GetDict(m); de = PyDict_New(); - if (de == NULL || PyDict_SetItemString(d, "errorcode", de)) - Py_FatalError("can't initialize errno module"); + if (!d || !de || PyDict_SetItemString(d, "errorcode", de) < 0) + return; /* Macro so I don't have to edit each and every line below... */ #define inscode(d, ds, de, name, code, comment) _inscode(d, de, name, code) diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c index 174a904..fd4c3e3 100644 --- a/Modules/fcntlmodule.c +++ b/Modules/fcntlmodule.c @@ -328,8 +328,4 @@ initfcntl(void) /* Add some symbolic constants to the module */ d = PyModule_GetDict(m); all_ins(d); - - /* Check for errors */ - if (PyErr_Occurred()) - Py_FatalError("can't initialize module fcntl"); } diff --git a/Modules/linuxaudiodev.c b/Modules/linuxaudiodev.c index 72ba567..509823e 100644 --- a/Modules/linuxaudiodev.c +++ b/Modules/linuxaudiodev.c @@ -442,9 +442,6 @@ initlinuxaudiodev(void) goto error; Py_DECREF(x); - /* Check for errors */ - if (PyErr_Occurred()) { - error: - Py_FatalError("can't initialize module linuxaudiodev"); - } + error: + return; } diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 626e606..569e8c9 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -268,8 +268,7 @@ initmath(void) if (PyDict_SetItemString(d, "e", v) < 0) goto finally; Py_DECREF(v); - return; finally: - Py_FatalError("can't initialize math module"); + return; } diff --git a/Modules/mpzmodule.c b/Modules/mpzmodule.c index ad52736..8be9f08 100644 --- a/Modules/mpzmodule.c +++ b/Modules/mpzmodule.c @@ -1729,23 +1729,25 @@ initmpz(void) /* create some frequently used constants */ if ((mpz_value_zero = newmpzobject()) == NULL) - Py_FatalError("initmpz: can't initialize mpz constants"); + goto finally; mpz_set_ui(&mpz_value_zero->mpz, (unsigned long int)0); if ((mpz_value_one = newmpzobject()) == NULL) - Py_FatalError("initmpz: can't initialize mpz constants"); + goto finally; mpz_set_ui(&mpz_value_one->mpz, (unsigned long int)1); if ((mpz_value_mone = newmpzobject()) == NULL) - Py_FatalError("initmpz: can't initialize mpz constants"); + goto finally; mpz_set_si(&mpz_value_mone->mpz, (long)-1); dict = PyModule_GetDict(module); if (dict != NULL) { PyDict_SetItemString(dict, "MPZType", (PyObject*)&MPZtype); } - + finally: + return; } /* initmpz() */ + #ifdef MAKEDUMMYINT int _mpz_dummy_int; /* XXX otherwise, we're .bss-less (DYNLOAD->Jack?) */ #endif /* def MAKEDUMMYINT */ diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index d946608..056d2bb 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -2862,11 +2862,10 @@ initparser(void) parser_error = PyErr_NewException("parser.ParserError", NULL, NULL); if ((parser_error == 0) - || (PyDict_SetItemString(dict, "ParserError", parser_error) != 0)) { - /* - * This is serious. - */ - Py_FatalError("can't define parser.ParserError"); + || (PyDict_SetItemString(dict, "ParserError", parser_error) != 0)) + { + /* caller will check PyErr_Occurred() */ + return; } /* * Nice to have, but don't cry if we fail. diff --git a/Modules/pcremodule.c b/Modules/pcremodule.c index 3043405..21629b8 100644 --- a/Modules/pcremodule.c +++ b/Modules/pcremodule.c @@ -650,9 +650,5 @@ initpcre(void) insint(d, "DOTALL", PCRE_DOTALL); insint(d, "VERBOSE", PCRE_EXTENDED); insint(d, "LOCALE", PCRE_LOCALE); - - /* Check for errors */ - if (PyErr_Occurred()) - Py_FatalError("can't initialize module pcre"); } diff --git a/Modules/puremodule.c b/Modules/puremodule.c index 869aec5..d901580 100644 --- a/Modules/puremodule.c +++ b/Modules/puremodule.c @@ -983,6 +983,4 @@ initpure() #else PyDict_SetItemString(d, "QUANTIFY_VERSION", Py_None); #endif - if (PyErr_Occurred()) - Py_FatalError("couldn't initialize the pure module"); } diff --git a/Modules/shamodule.c b/Modules/shamodule.c index 3761cf5..cc11f12 100644 --- a/Modules/shamodule.c +++ b/Modules/shamodule.c @@ -559,8 +559,4 @@ initsha(void) functions require an integral number of blocks */ insint("digestsize", 20); - - /* Check for errors */ - if (PyErr_Occurred()) - Py_FatalError("can't initialize module SHA"); } diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c index 1980032..617eb26 100644 --- a/Modules/stropmodule.c +++ b/Modules/stropmodule.c @@ -1244,7 +1244,4 @@ initstrop(void) PyDict_SetItemString(d, "uppercase", s); Py_DECREF(s); } - - if (PyErr_Occurred()) - Py_FatalError("can't initialize module strop"); } diff --git a/Modules/syslogmodule.c b/Modules/syslogmodule.c index 6452620..eda5490 100644 --- a/Modules/syslogmodule.c +++ b/Modules/syslogmodule.c @@ -232,8 +232,4 @@ initsyslog(void) ins(d, "LOG_CRON", LOG_CRON); ins(d, "LOG_UUCP", LOG_UUCP); ins(d, "LOG_NEWS", LOG_NEWS); - - /* Check for errors */ - if (PyErr_Occurred()) - Py_FatalError("can't initialize module syslog"); } diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 8cb7484..edf09d1 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -512,14 +512,15 @@ static PyMethodDef time_methods[] = { static void ins(PyObject *d, char *name, PyObject *v) { - if (v == NULL) - Py_FatalError("Can't initialize time module -- NULL value"); - if (PyDict_SetItemString(d, name, v) != 0) - Py_FatalError( - "Can't initialize time module -- PyDict_SetItemString failed"); - Py_DECREF(v); + /* Don't worry too much about errors, they'll be caught by the + * caller of inittime(). + */ + if (v) + PyDict_SetItemString(d, name, v); + Py_XDECREF(v); } + static char module_doc[] = "This module provides various functions to manipulate time values.\n\ \n\ @@ -647,8 +648,6 @@ inittime(void) #endif /* macintosh */ #endif /* HAVE_TM_ZONE */ #endif /* !HAVE_TZNAME || __GLIBC__ */ - if (PyErr_Occurred()) - Py_FatalError("Can't initialize time module"); } diff --git a/Modules/timingmodule.c b/Modules/timingmodule.c index 0742005..1844696 100644 --- a/Modules/timingmodule.c +++ b/Modules/timingmodule.c @@ -72,6 +72,4 @@ static PyMethodDef timing_methods[] = { DL_EXPORT(void) inittiming(void) { (void)Py_InitModule("timing", timing_methods); - if (PyErr_Occurred()) - Py_FatalError("can't initialize module timing"); } -- cgit v0.12