Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9bfd2bf

Browse files
committed
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
1 parent 72dacb8 commit 9bfd2bf

15 files changed

Lines changed: 31 additions & 67 deletions

Modules/almodule.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,9 +3242,6 @@ inital(void)
32423242
(void) ALseterrorhandler(ErrorHandler);
32433243
#endif /* OLD_INTERFACE */
32443244

3245-
/* Check for errors */
3246-
if (PyErr_Occurred()) {
3247-
error:
3248-
Py_FatalError("can't initialize module al");
3249-
}
3245+
error:
3246+
return;
32503247
}

Modules/cdmodule.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,4 @@ initcd(void)
802802
#ifdef CD_CDROM /* only newer versions of the library */
803803
PyDict_SetItemString(d, "CDROM", PyInt_FromLong((long) CD_CDROM));
804804
#endif
805-
806-
if (PyErr_Occurred())
807-
Py_FatalError("can't initialize module cd");
808805
}

Modules/errnomodule.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,14 @@ static PyMethodDef errno_methods[] = {
3535
static void
3636
_inscode(PyObject *d, PyObject *de, char *name, int code)
3737
{
38-
PyObject *u;
39-
PyObject *v;
38+
PyObject *u = PyString_FromString(name);
39+
PyObject *v = PyInt_FromLong((long) code);
4040

41-
u = PyString_FromString(name);
42-
v = PyInt_FromLong((long) code);
43-
44-
if (!u || !v) {
45-
/* Don't bother reporting this error */
46-
PyErr_Clear();
47-
}
48-
else {
41+
/* Don't bother checking for errors; they'll be caught at the end
42+
* of the module initialization function by the caller of
43+
* initerrno().
44+
*/
45+
if (u && v) {
4946
/* insert in modules dict */
5047
PyDict_SetItem(d, u, v);
5148
/* insert in errorcode dict */
@@ -76,8 +73,8 @@ initerrno(void)
7673
m = Py_InitModule3("errno", errno_methods, errno__doc__);
7774
d = PyModule_GetDict(m);
7875
de = PyDict_New();
79-
if (de == NULL || PyDict_SetItemString(d, "errorcode", de))
80-
Py_FatalError("can't initialize errno module");
76+
if (!d || !de || PyDict_SetItemString(d, "errorcode", de) < 0)
77+
return;
8178

8279
/* Macro so I don't have to edit each and every line below... */
8380
#define inscode(d, ds, de, name, code, comment) _inscode(d, de, name, code)

Modules/fcntlmodule.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,4 @@ initfcntl(void)
328328
/* Add some symbolic constants to the module */
329329
d = PyModule_GetDict(m);
330330
all_ins(d);
331-
332-
/* Check for errors */
333-
if (PyErr_Occurred())
334-
Py_FatalError("can't initialize module fcntl");
335331
}

Modules/linuxaudiodev.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,6 @@ initlinuxaudiodev(void)
442442
goto error;
443443
Py_DECREF(x);
444444

445-
/* Check for errors */
446-
if (PyErr_Occurred()) {
447-
error:
448-
Py_FatalError("can't initialize module linuxaudiodev");
449-
}
445+
error:
446+
return;
450447
}

Modules/mathmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ initmath(void)
268268
if (PyDict_SetItemString(d, "e", v) < 0)
269269
goto finally;
270270
Py_DECREF(v);
271-
return;
272271

273272
finally:
274-
Py_FatalError("can't initialize math module");
273+
return;
275274
}

Modules/mpzmodule.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,23 +1729,25 @@ initmpz(void)
17291729

17301730
/* create some frequently used constants */
17311731
if ((mpz_value_zero = newmpzobject()) == NULL)
1732-
Py_FatalError("initmpz: can't initialize mpz constants");
1732+
goto finally;
17331733
mpz_set_ui(&mpz_value_zero->mpz, (unsigned long int)0);
17341734

17351735
if ((mpz_value_one = newmpzobject()) == NULL)
1736-
Py_FatalError("initmpz: can't initialize mpz constants");
1736+
goto finally;
17371737
mpz_set_ui(&mpz_value_one->mpz, (unsigned long int)1);
17381738

17391739
if ((mpz_value_mone = newmpzobject()) == NULL)
1740-
Py_FatalError("initmpz: can't initialize mpz constants");
1740+
goto finally;
17411741
mpz_set_si(&mpz_value_mone->mpz, (long)-1);
17421742

17431743
dict = PyModule_GetDict(module);
17441744
if (dict != NULL) {
17451745
PyDict_SetItemString(dict, "MPZType", (PyObject*)&MPZtype);
17461746
}
1747-
1747+
finally:
1748+
return;
17481749
} /* initmpz() */
1750+
17491751
#ifdef MAKEDUMMYINT
17501752
int _mpz_dummy_int; /* XXX otherwise, we're .bss-less (DYNLOAD->Jack?) */
17511753
#endif /* def MAKEDUMMYINT */

Modules/parsermodule.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,11 +2862,10 @@ initparser(void)
28622862
parser_error = PyErr_NewException("parser.ParserError", NULL, NULL);
28632863

28642864
if ((parser_error == 0)
2865-
|| (PyDict_SetItemString(dict, "ParserError", parser_error) != 0)) {
2866-
/*
2867-
* This is serious.
2868-
*/
2869-
Py_FatalError("can't define parser.ParserError");
2865+
|| (PyDict_SetItemString(dict, "ParserError", parser_error) != 0))
2866+
{
2867+
/* caller will check PyErr_Occurred() */
2868+
return;
28702869
}
28712870
/*
28722871
* Nice to have, but don't cry if we fail.

Modules/pcremodule.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,5 @@ initpcre(void)
650650
insint(d, "DOTALL", PCRE_DOTALL);
651651
insint(d, "VERBOSE", PCRE_EXTENDED);
652652
insint(d, "LOCALE", PCRE_LOCALE);
653-
654-
/* Check for errors */
655-
if (PyErr_Occurred())
656-
Py_FatalError("can't initialize module pcre");
657653
}
658654

Modules/puremodule.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,4 @@ initpure()
983983
#else
984984
PyDict_SetItemString(d, "QUANTIFY_VERSION", Py_None);
985985
#endif
986-
if (PyErr_Occurred())
987-
Py_FatalError("couldn't initialize the pure module");
988986
}

0 commit comments

Comments
 (0)