mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
Apply two changes, systematically:
(1) Use PyErr_NewException("module.class", NULL, NULL) to create the
exception object.
(2) Remove all calls to Py_FatalError(); instead, return or
ignore the errors -- the import code now checks PyErr_Occurred()
after calling a module's init function, so it's no longer a
fatal error for the initialization to fail.
Also did some small cleanups, e.g. removed unnecessary test for
"already initialized" from initfpectl(), and unified
initposix()/initnt().
I haven't checked this very thoroughly, so while the changes are
pretty trivial -- beware of untested code!
This commit is contained in:
parent
ccf0a44d2d
commit
0cb96de269
27 changed files with 79 additions and 167 deletions
|
|
@ -2254,73 +2254,37 @@ all_ins(d)
|
|||
}
|
||||
|
||||
|
||||
/* XXX The following should be more unified -- only difference left is
|
||||
function name and module name. */
|
||||
|
||||
#if defined(_MSC_VER) || defined(__WATCOMC__)
|
||||
#define INITFUNC initnt
|
||||
#define MODNAME "nt"
|
||||
#else
|
||||
#define INITFUNC initposix
|
||||
#define MODNAME "posix"
|
||||
#endif
|
||||
|
||||
void
|
||||
initnt()
|
||||
INITFUNC()
|
||||
{
|
||||
PyObject *m, *d, *v;
|
||||
|
||||
m = Py_InitModule4("nt",
|
||||
m = Py_InitModule4(MODNAME,
|
||||
posix_methods,
|
||||
posix__doc__,
|
||||
(PyObject *)NULL,
|
||||
PYTHON_API_VERSION);
|
||||
(PyObject *)NULL,
|
||||
PYTHON_API_VERSION);
|
||||
d = PyModule_GetDict(m);
|
||||
|
||||
/* Initialize nt.environ dictionary */
|
||||
/* Initialize environ dictionary */
|
||||
v = convertenviron();
|
||||
if (v == NULL || PyDict_SetItemString(d, "environ", v) != 0)
|
||||
goto finally;
|
||||
return;
|
||||
Py_DECREF(v);
|
||||
|
||||
if (all_ins(d))
|
||||
goto finally;
|
||||
|
||||
/* Initialize nt.error exception */
|
||||
PosixError = PyString_FromString("os.error");
|
||||
PyDict_SetItemString(d, "error", PosixError);
|
||||
|
||||
if (!PyErr_Occurred())
|
||||
return;
|
||||
|
||||
finally:
|
||||
/* XXX Shouldn't */
|
||||
Py_FatalError("can't initialize NT posixmodule");
|
||||
/* Initialize exception */
|
||||
PosixError = PyErr_NewException("os.error", NULL, NULL);
|
||||
if (PosixError != NULL)
|
||||
PyDict_SetItemString(d, "error", PosixError);
|
||||
}
|
||||
#else /* not a PC port */
|
||||
void
|
||||
initposix()
|
||||
{
|
||||
PyObject *m, *d, *v;
|
||||
|
||||
m = Py_InitModule4("posix",
|
||||
posix_methods,
|
||||
posix__doc__,
|
||||
(PyObject *)NULL,
|
||||
PYTHON_API_VERSION);
|
||||
d = PyModule_GetDict(m);
|
||||
|
||||
/* Initialize posix.environ dictionary */
|
||||
v = convertenviron();
|
||||
if (v == NULL || PyDict_SetItemString(d, "environ", v) != 0)
|
||||
goto finally;
|
||||
Py_DECREF(v);
|
||||
|
||||
if (all_ins(d))
|
||||
goto finally;
|
||||
|
||||
/* Initialize posix.error exception */
|
||||
PosixError = PyString_FromString("os.error");
|
||||
PyDict_SetItemString(d, "error", PosixError);
|
||||
|
||||
if (!PyErr_Occurred())
|
||||
return;
|
||||
|
||||
finally:
|
||||
/* XXX Shouldn't */
|
||||
Py_FatalError("can't initialize posix module");
|
||||
}
|
||||
#endif /* !_MSC_VER */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue