mirror of
https://github.com/python/cpython.git
synced 2025-11-17 01:25:57 +00:00
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:
parent
72dacb8026
commit
9bfd2bf5ed
15 changed files with 31 additions and 67 deletions
|
|
@ -3242,9 +3242,6 @@ inital(void)
|
||||||
(void) ALseterrorhandler(ErrorHandler);
|
(void) ALseterrorhandler(ErrorHandler);
|
||||||
#endif /* OLD_INTERFACE */
|
#endif /* OLD_INTERFACE */
|
||||||
|
|
||||||
/* Check for errors */
|
|
||||||
if (PyErr_Occurred()) {
|
|
||||||
error:
|
error:
|
||||||
Py_FatalError("can't initialize module al");
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -802,7 +802,4 @@ initcd(void)
|
||||||
#ifdef CD_CDROM /* only newer versions of the library */
|
#ifdef CD_CDROM /* only newer versions of the library */
|
||||||
PyDict_SetItemString(d, "CDROM", PyInt_FromLong((long) CD_CDROM));
|
PyDict_SetItemString(d, "CDROM", PyInt_FromLong((long) CD_CDROM));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (PyErr_Occurred())
|
|
||||||
Py_FatalError("can't initialize module cd");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,17 +35,14 @@ static PyMethodDef errno_methods[] = {
|
||||||
static void
|
static void
|
||||||
_inscode(PyObject *d, PyObject *de, char *name, int code)
|
_inscode(PyObject *d, PyObject *de, char *name, int code)
|
||||||
{
|
{
|
||||||
PyObject *u;
|
PyObject *u = PyString_FromString(name);
|
||||||
PyObject *v;
|
PyObject *v = PyInt_FromLong((long) code);
|
||||||
|
|
||||||
u = PyString_FromString(name);
|
/* Don't bother checking for errors; they'll be caught at the end
|
||||||
v = PyInt_FromLong((long) code);
|
* of the module initialization function by the caller of
|
||||||
|
* initerrno().
|
||||||
if (!u || !v) {
|
*/
|
||||||
/* Don't bother reporting this error */
|
if (u && v) {
|
||||||
PyErr_Clear();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* insert in modules dict */
|
/* insert in modules dict */
|
||||||
PyDict_SetItem(d, u, v);
|
PyDict_SetItem(d, u, v);
|
||||||
/* insert in errorcode dict */
|
/* insert in errorcode dict */
|
||||||
|
|
@ -76,8 +73,8 @@ initerrno(void)
|
||||||
m = Py_InitModule3("errno", errno_methods, errno__doc__);
|
m = Py_InitModule3("errno", errno_methods, errno__doc__);
|
||||||
d = PyModule_GetDict(m);
|
d = PyModule_GetDict(m);
|
||||||
de = PyDict_New();
|
de = PyDict_New();
|
||||||
if (de == NULL || PyDict_SetItemString(d, "errorcode", de))
|
if (!d || !de || PyDict_SetItemString(d, "errorcode", de) < 0)
|
||||||
Py_FatalError("can't initialize errno module");
|
return;
|
||||||
|
|
||||||
/* Macro so I don't have to edit each and every line below... */
|
/* 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)
|
#define inscode(d, ds, de, name, code, comment) _inscode(d, de, name, code)
|
||||||
|
|
|
||||||
|
|
@ -328,8 +328,4 @@ initfcntl(void)
|
||||||
/* Add some symbolic constants to the module */
|
/* Add some symbolic constants to the module */
|
||||||
d = PyModule_GetDict(m);
|
d = PyModule_GetDict(m);
|
||||||
all_ins(d);
|
all_ins(d);
|
||||||
|
|
||||||
/* Check for errors */
|
|
||||||
if (PyErr_Occurred())
|
|
||||||
Py_FatalError("can't initialize module fcntl");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -442,9 +442,6 @@ initlinuxaudiodev(void)
|
||||||
goto error;
|
goto error;
|
||||||
Py_DECREF(x);
|
Py_DECREF(x);
|
||||||
|
|
||||||
/* Check for errors */
|
|
||||||
if (PyErr_Occurred()) {
|
|
||||||
error:
|
error:
|
||||||
Py_FatalError("can't initialize module linuxaudiodev");
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -268,8 +268,7 @@ initmath(void)
|
||||||
if (PyDict_SetItemString(d, "e", v) < 0)
|
if (PyDict_SetItemString(d, "e", v) < 0)
|
||||||
goto finally;
|
goto finally;
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
return;
|
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
Py_FatalError("can't initialize math module");
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1729,23 +1729,25 @@ initmpz(void)
|
||||||
|
|
||||||
/* create some frequently used constants */
|
/* create some frequently used constants */
|
||||||
if ((mpz_value_zero = newmpzobject()) == NULL)
|
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);
|
mpz_set_ui(&mpz_value_zero->mpz, (unsigned long int)0);
|
||||||
|
|
||||||
if ((mpz_value_one = newmpzobject()) == NULL)
|
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);
|
mpz_set_ui(&mpz_value_one->mpz, (unsigned long int)1);
|
||||||
|
|
||||||
if ((mpz_value_mone = newmpzobject()) == NULL)
|
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);
|
mpz_set_si(&mpz_value_mone->mpz, (long)-1);
|
||||||
|
|
||||||
dict = PyModule_GetDict(module);
|
dict = PyModule_GetDict(module);
|
||||||
if (dict != NULL) {
|
if (dict != NULL) {
|
||||||
PyDict_SetItemString(dict, "MPZType", (PyObject*)&MPZtype);
|
PyDict_SetItemString(dict, "MPZType", (PyObject*)&MPZtype);
|
||||||
}
|
}
|
||||||
|
finally:
|
||||||
|
return;
|
||||||
} /* initmpz() */
|
} /* initmpz() */
|
||||||
|
|
||||||
#ifdef MAKEDUMMYINT
|
#ifdef MAKEDUMMYINT
|
||||||
int _mpz_dummy_int; /* XXX otherwise, we're .bss-less (DYNLOAD->Jack?) */
|
int _mpz_dummy_int; /* XXX otherwise, we're .bss-less (DYNLOAD->Jack?) */
|
||||||
#endif /* def MAKEDUMMYINT */
|
#endif /* def MAKEDUMMYINT */
|
||||||
|
|
|
||||||
|
|
@ -2862,11 +2862,10 @@ initparser(void)
|
||||||
parser_error = PyErr_NewException("parser.ParserError", NULL, NULL);
|
parser_error = PyErr_NewException("parser.ParserError", NULL, NULL);
|
||||||
|
|
||||||
if ((parser_error == 0)
|
if ((parser_error == 0)
|
||||||
|| (PyDict_SetItemString(dict, "ParserError", parser_error) != 0)) {
|
|| (PyDict_SetItemString(dict, "ParserError", parser_error) != 0))
|
||||||
/*
|
{
|
||||||
* This is serious.
|
/* caller will check PyErr_Occurred() */
|
||||||
*/
|
return;
|
||||||
Py_FatalError("can't define parser.ParserError");
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Nice to have, but don't cry if we fail.
|
* Nice to have, but don't cry if we fail.
|
||||||
|
|
|
||||||
|
|
@ -650,9 +650,5 @@ initpcre(void)
|
||||||
insint(d, "DOTALL", PCRE_DOTALL);
|
insint(d, "DOTALL", PCRE_DOTALL);
|
||||||
insint(d, "VERBOSE", PCRE_EXTENDED);
|
insint(d, "VERBOSE", PCRE_EXTENDED);
|
||||||
insint(d, "LOCALE", PCRE_LOCALE);
|
insint(d, "LOCALE", PCRE_LOCALE);
|
||||||
|
|
||||||
/* Check for errors */
|
|
||||||
if (PyErr_Occurred())
|
|
||||||
Py_FatalError("can't initialize module pcre");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -983,6 +983,4 @@ initpure()
|
||||||
#else
|
#else
|
||||||
PyDict_SetItemString(d, "QUANTIFY_VERSION", Py_None);
|
PyDict_SetItemString(d, "QUANTIFY_VERSION", Py_None);
|
||||||
#endif
|
#endif
|
||||||
if (PyErr_Occurred())
|
|
||||||
Py_FatalError("couldn't initialize the pure module");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -559,8 +559,4 @@ initsha(void)
|
||||||
functions require an integral number of
|
functions require an integral number of
|
||||||
blocks */
|
blocks */
|
||||||
insint("digestsize", 20);
|
insint("digestsize", 20);
|
||||||
|
|
||||||
/* Check for errors */
|
|
||||||
if (PyErr_Occurred())
|
|
||||||
Py_FatalError("can't initialize module SHA");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1244,7 +1244,4 @@ initstrop(void)
|
||||||
PyDict_SetItemString(d, "uppercase", s);
|
PyDict_SetItemString(d, "uppercase", s);
|
||||||
Py_DECREF(s);
|
Py_DECREF(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PyErr_Occurred())
|
|
||||||
Py_FatalError("can't initialize module strop");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -232,8 +232,4 @@ initsyslog(void)
|
||||||
ins(d, "LOG_CRON", LOG_CRON);
|
ins(d, "LOG_CRON", LOG_CRON);
|
||||||
ins(d, "LOG_UUCP", LOG_UUCP);
|
ins(d, "LOG_UUCP", LOG_UUCP);
|
||||||
ins(d, "LOG_NEWS", LOG_NEWS);
|
ins(d, "LOG_NEWS", LOG_NEWS);
|
||||||
|
|
||||||
/* Check for errors */
|
|
||||||
if (PyErr_Occurred())
|
|
||||||
Py_FatalError("can't initialize module syslog");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -512,14 +512,15 @@ static PyMethodDef time_methods[] = {
|
||||||
static void
|
static void
|
||||||
ins(PyObject *d, char *name, PyObject *v)
|
ins(PyObject *d, char *name, PyObject *v)
|
||||||
{
|
{
|
||||||
if (v == NULL)
|
/* Don't worry too much about errors, they'll be caught by the
|
||||||
Py_FatalError("Can't initialize time module -- NULL value");
|
* caller of inittime().
|
||||||
if (PyDict_SetItemString(d, name, v) != 0)
|
*/
|
||||||
Py_FatalError(
|
if (v)
|
||||||
"Can't initialize time module -- PyDict_SetItemString failed");
|
PyDict_SetItemString(d, name, v);
|
||||||
Py_DECREF(v);
|
Py_XDECREF(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char module_doc[] =
|
static char module_doc[] =
|
||||||
"This module provides various functions to manipulate time values.\n\
|
"This module provides various functions to manipulate time values.\n\
|
||||||
\n\
|
\n\
|
||||||
|
|
@ -647,8 +648,6 @@ inittime(void)
|
||||||
#endif /* macintosh */
|
#endif /* macintosh */
|
||||||
#endif /* HAVE_TM_ZONE */
|
#endif /* HAVE_TM_ZONE */
|
||||||
#endif /* !HAVE_TZNAME || __GLIBC__ */
|
#endif /* !HAVE_TZNAME || __GLIBC__ */
|
||||||
if (PyErr_Occurred())
|
|
||||||
Py_FatalError("Can't initialize time module");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,4 @@ static PyMethodDef timing_methods[] = {
|
||||||
DL_EXPORT(void) inittiming(void)
|
DL_EXPORT(void) inittiming(void)
|
||||||
{
|
{
|
||||||
(void)Py_InitModule("timing", timing_methods);
|
(void)Py_InitModule("timing", timing_methods);
|
||||||
if (PyErr_Occurred())
|
|
||||||
Py_FatalError("can't initialize module timing");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue