[Python-checkins] r68352 - in sandbox/trunk/io-c: _iobase.c _iomodule.h io.c
antoine.pitrou
python-checkins at python.org
Tue Jan 6 00:45:23 CET 2009
Author: antoine.pitrou
Date: Tue Jan 6 00:45:23 2009
New Revision: 68352
Log:
fix destructor on raw file IO
This might not be the best way to do it but somehow I fail to make it so
that tp_del gets called, including in subclasses.
Modified:
sandbox/trunk/io-c/_iobase.c
sandbox/trunk/io-c/_iomodule.h
sandbox/trunk/io-c/io.c
Modified: sandbox/trunk/io-c/_iobase.c
==============================================================================
--- sandbox/trunk/io-c/_iobase.c (original)
+++ sandbox/trunk/io-c/_iobase.c Tue Jan 6 00:45:23 2009
@@ -149,18 +149,24 @@
Py_RETURN_NONE;
}
-static void
-IOBase_del(PyObject *self)
+static PyObject *
+IOBase_del(PyObject *self, PyObject *args)
{
- PyObject *res = PyObject_CallMethod(self, "flush", NULL);
+ PyObject *res = NULL;
+ res = PyObject_CallMethodObjArgs(self, _PyIO_str_close, NULL);
if (res == NULL) {
/* At program exit time, it's possible that globals have already been
* deleted, and then the close() call might fail. Since there's
* nothing we can do about such failures and they annoy the end
* users, we suppress the traceback.
+ *
+ * XXX: this function can be called at other times and what if the
+ * error is genuine?
*/
PyErr_Clear();
}
+ Py_XDECREF(res);
+ Py_RETURN_NONE;
}
/* Inquiry methods */
@@ -522,6 +528,7 @@
{"fileno", IOBase_fileno, METH_NOARGS, IOBase_fileno_doc},
{"isatty", IOBase_isatty, METH_NOARGS, IOBase_isatty_doc},
+ {"__del__", IOBase_del, METH_NOARGS},
{"__enter__", IOBase_enter, METH_NOARGS},
{"__exit__", IOBase_exit, METH_VARARGS},
@@ -584,7 +591,7 @@
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
- IOBase_del, /* tp_del */
+ 0, /* tp_del */
};
Modified: sandbox/trunk/io-c/_iomodule.h
==============================================================================
--- sandbox/trunk/io-c/_iomodule.h (original)
+++ sandbox/trunk/io-c/_iomodule.h Tue Jan 6 00:45:23 2009
@@ -50,6 +50,7 @@
/* Implementation details */
+extern PyObject *_PyIO_str_close;
extern PyObject *_PyIO_str_closed;
extern PyObject *_PyIO_str_fileno;
extern PyObject *_PyIO_str_flush;
Modified: sandbox/trunk/io-c/io.c
==============================================================================
--- sandbox/trunk/io-c/io.c (original)
+++ sandbox/trunk/io-c/io.c Tue Jan 6 00:45:23 2009
@@ -14,6 +14,7 @@
/* Various interned strings */
+PyObject *_PyIO_str_close;
PyObject *_PyIO_str_closed;
PyObject *_PyIO_str_fileno;
PyObject *_PyIO_str_flush;
@@ -622,6 +623,8 @@
PyModule_AddObject(m, "IncrementalNewlineDecoder", (PyObject *) &PyIncrementalNewlineDecoder_Type);
/* Interned strings */
+ if (!(_PyIO_str_close = PyUnicode_InternFromString("close")))
+ goto fail;
if (!(_PyIO_str_closed = PyUnicode_InternFromString("closed")))
goto fail;
if (!(_PyIO_str_fileno = PyUnicode_InternFromString("fileno")))
More information about the Python-checkins
mailing list