]> granicus.if.org Git - python/commitdiff
Do the absolute minimal amount of modifications to eradicate
authorBarry Warsaw <barry@python.org>
Fri, 1 Sep 2000 09:01:32 +0000 (09:01 +0000)
committerBarry Warsaw <barry@python.org>
Fri, 1 Sep 2000 09:01:32 +0000 (09:01 +0000)
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

15 files changed:
Modules/almodule.c
Modules/cdmodule.c
Modules/errnomodule.c
Modules/fcntlmodule.c
Modules/linuxaudiodev.c
Modules/mathmodule.c
Modules/mpzmodule.c
Modules/parsermodule.c
Modules/pcremodule.c
Modules/puremodule.c
Modules/shamodule.c
Modules/stropmodule.c
Modules/syslogmodule.c
Modules/timemodule.c
Modules/timingmodule.c

index f162cf5b4514253fd030f59ab7020ce971700ffd..23fd96f02c6f12f0bec0ab9438436bfaa3e94ae8 100644 (file)
@@ -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;
 }
index 804207572481545de34d6f31578151bd3dfd2171..5f88a0f8cd0aa6dafbf53a4eb75f214df783b44a 100644 (file)
@@ -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");
 }
index 8607ea25657fea9e0e1642f49398fb4608678271..b47feb62817fc74fa5735150b1733975955bfcc5 100644 (file)
@@ -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)
index 174a904ced531d842b8e23f5b3b5ab6b283194b2..fd4c3e304a5df2b0e4cfec4672eaafe1dff081f3 100644 (file)
@@ -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");
 }
index 72ba5670617e28872e5e1bf7f36ad0e32495b658..509823ed32d4fb3614d07333c2f5785fc208b3ad 100644 (file)
@@ -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;
 }
index 626e606534bee44511e0e0fc1679573f08e8207c..569e8c9cdda526f3e3d49490d81ee74b50208cd1 100644 (file)
@@ -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;
 }
index ad5273677f0f03a012bf9a71a6e3b8f5eefa8d8c..8be9f08df45d92158e74cc53753b2d88e17aff21 100644 (file)
@@ -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 */
index d946608dac9692b9b27e53bcc84918686c2eeaa0..056d2bbf27227bd37fc8ee24a033d8b07ba4ee02 100644 (file)
@@ -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.
index 3043405b0846128a7347660e1b901b5a77995853..21629b806b435f37a4daf30a951ed00a3d45e89d 100644 (file)
@@ -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");
 }
 
index 869aec51b3e08de88a95bce0bc49369e6d709195..d901580708c003d622e1c1c88b8a6e996505bbae 100644 (file)
@@ -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");
 }
index 3761cf58ceb77a0b97ae8817e0ed483fb9ce58cd..cc11f128852e966e51906f4f9c3fd71353254ec9 100644 (file)
@@ -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");
 }
index 1980032e2eb5e370118159c8563e960b1a71e0ee..617eb26ec4d558370330a7397e5d7926bd443dcc 100644 (file)
@@ -1244,7 +1244,4 @@ initstrop(void)
                PyDict_SetItemString(d, "uppercase", s);
                Py_DECREF(s);
        }
-
-       if (PyErr_Occurred())
-               Py_FatalError("can't initialize module strop");
 }
index 6452620d366e9a2ada721b825540228dfef5b81b..eda5490c16f1314da39b153919273aa48a909c21 100644 (file)
@@ -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");
 }
index 8cb7484984055b16e9b419de8d46c0adde3779ea..edf09d11312a497738b900e8853d666bcbc4bb5c 100644 (file)
@@ -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");
 }
 
 
index 07420053d63577e2424cd7fcbe2d5e2c0a23b5ba..184469679b8f743b90f794214be8ff49640d13ee 100644 (file)
@@ -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");
 }