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
This commit is contained in:
Barry Warsaw 2000-09-01 09:01:32 +00:00
parent 72dacb8026
commit 9bfd2bf5ed
15 changed files with 31 additions and 67 deletions

View 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;
}

View 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");
}

View 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)

View 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");
}

View 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;
}

View 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;
}

View 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 */

View 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.

View 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");
}

View 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");
}

View 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");
}

View 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");
}

View 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");
}

View 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");
}

View 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");
}