summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-10-01 04:29:29 (GMT)
committerGuido van Rossum <guido@python.org>1997-10-01 04:29:29 (GMT)
commit0cb96de2699fa032ef1379ebb62a4dfb66ee5fde (patch)
tree7c8fed41fb1b4ad5da7bb2fe8d0200e27c125561 /Modules/socketmodule.c
parentccf0a44d2dd9b754fd98c15dbef1c2e8c1b41797 (diff)
downloadcpython-0cb96de2699fa032ef1379ebb62a4dfb66ee5fde.zip
cpython-0cb96de2699fa032ef1379ebb62a4dfb66ee5fde.tar.gz
cpython-0cb96de2699fa032ef1379ebb62a4dfb66ee5fde.tar.bz2
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!
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r--Modules/socketmodule.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 48ce55a..77cf5d1 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1314,17 +1314,16 @@ static PyMethodDef PySocket_methods[] = {
/* 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 @@ initsocket()
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);