Mercurial > cpython-lru_cache-weakref
diff Modules/socketmodule.c @ 6367:2c29b8982643 legacy-trunk
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!
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 01 Oct 1997 04:29:29 +0000 |
| parents | 88b0b2a3aab5 |
| children | f67a6339ede7 |
line wrap: on
line diff
--- a/Modules/socketmodule.c Tue Sep 30 22:14:39 1997 +0000 +++ b/Modules/socketmodule.c Wed Oct 01 04:29:29 1997 +0000 @@ -1314,17 +1314,16 @@ /* Convenience routine to export an integer value. * - * Since this function is called only from initsocket/init_socket(), any - * errors trigger a fatal exception. + * Errors are silently ignored, for better or for worse... */ static void BUILD_FUNC_DEF_3(insint,PyObject *,d, char *,name, int,value) { PyObject *v = PyInt_FromLong((long) value); if (!v || PyDict_SetItemString(d, name, v)) - Py_FatalError("can't initialize socket module"); + PyErr_Clear(); - Py_DECREF(v); + Py_XDECREF(v); } @@ -1398,15 +1397,15 @@ m = Py_InitModule("socket", PySocket_methods); #endif d = PyModule_GetDict(m); - PySocket_Error = PyString_FromString("socket.error"); - if (PySocket_Error == NULL || - PyDict_SetItemString(d, "error", PySocket_Error) != 0) - Py_FatalError("can't define socket.error"); + PySocket_Error = PyErr_NewException("socket.error", NULL, NULL); + if (PySocket_Error == NULL) + return; + PyDict_SetItemString(d, "error", PySocket_Error); PySocketSock_Type.ob_type = &PyType_Type; Py_INCREF(&PySocketSock_Type); if (PyDict_SetItemString(d, "SocketType", (PyObject *)&PySocketSock_Type) != 0) - Py_FatalError("can't define socket.SocketType"); + return; insint(d, "AF_INET", AF_INET); #ifdef AF_UNIX insint(d, "AF_UNIX", AF_UNIX);
