[Python-checkins] r68413 - in sandbox/trunk/io-c: _bufferedio.c _iobase.c _iomodule.h _textio.c
amaury.forgeotdarc
python-checkins at python.org
Thu Jan 8 22:45:04 CET 2009
Author: amaury.forgeotdarc
Date: Thu Jan 8 22:45:03 2009
New Revision: 68413
Log:
Probably a hack: when calling _PyIOBase_checkClosed &co from C code,
return a borrowed reference,
since all that matters is the comparition to NULL.
Modified:
sandbox/trunk/io-c/_bufferedio.c
sandbox/trunk/io-c/_iobase.c
sandbox/trunk/io-c/_iomodule.h
sandbox/trunk/io-c/_textio.c
Modified: sandbox/trunk/io-c/_bufferedio.c
==============================================================================
--- sandbox/trunk/io-c/_bufferedio.c (original)
+++ sandbox/trunk/io-c/_bufferedio.c Thu Jan 8 22:45:03 2009
@@ -813,7 +813,7 @@
return -1;
}
- if (_PyIOBase_checkReadable(raw, NULL) == NULL)
+ if (_PyIOBase_checkReadable(raw, Py_True) == NULL)
return -1;
Py_CLEAR(self->raw);
@@ -1183,7 +1183,7 @@
return -1;
}
- if (_PyIOBase_checkWritable(raw, NULL) == NULL)
+ if (_PyIOBase_checkWritable(raw, Py_True) == NULL)
return -1;
Py_CLEAR(self->raw);
@@ -1520,9 +1520,9 @@
return -1;
}
- if (_PyIOBase_checkReadable(reader, NULL) == NULL)
+ if (_PyIOBase_checkReadable(reader, Py_True) == NULL)
return -1;
- if (_PyIOBase_checkWritable(writer, NULL) == NULL)
+ if (_PyIOBase_checkWritable(writer, Py_True) == NULL)
return -1;
args = Py_BuildValue("(n)", buffer_size);
@@ -1730,11 +1730,11 @@
return -1;
}
- if (_PyIOBase_checkSeekable(raw, NULL) == NULL)
+ if (_PyIOBase_checkSeekable(raw, Py_True) == NULL)
return -1;
- if (_PyIOBase_checkReadable(raw, NULL) == NULL)
+ if (_PyIOBase_checkReadable(raw, Py_True) == NULL)
return -1;
- if (_PyIOBase_checkWritable(raw, NULL) == NULL)
+ if (_PyIOBase_checkWritable(raw, Py_True) == NULL)
return -1;
Py_CLEAR(self->raw);
Modified: sandbox/trunk/io-c/_iobase.c
==============================================================================
--- sandbox/trunk/io-c/_iobase.c (original)
+++ sandbox/trunk/io-c/_iobase.c Thu Jan 8 22:45:03 2009
@@ -133,13 +133,16 @@
PyObject *
-_PyIOBase_checkClosed(PyObject *self, PyObject *unused)
+_PyIOBase_checkClosed(PyObject *self, PyObject *args)
{
if (IOBase_closed(self)) {
PyErr_SetString(PyExc_ValueError, "I/O operation on closed file.");
return NULL;
}
- Py_RETURN_NONE;
+ if (args == Py_True)
+ return Py_None;
+ else
+ Py_RETURN_NONE;
}
/* XXX: IOBase thinks it has to maintain its own internal state in
@@ -201,7 +204,7 @@
}
PyObject *
-_PyIOBase_checkSeekable(PyObject *self, PyObject *unused)
+_PyIOBase_checkSeekable(PyObject *self, PyObject *args)
{
PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_seekable, NULL);
if (res == NULL)
@@ -210,6 +213,8 @@
Py_CLEAR(res);
PyErr_SetString(PyExc_IOError, "File or stream is not seekable.");
}
+ if (args == Py_True)
+ Py_DECREF(res);
return res;
}
@@ -226,7 +231,7 @@
/* May be called with any object */
PyObject *
-_PyIOBase_checkReadable(PyObject *self, PyObject *unused)
+_PyIOBase_checkReadable(PyObject *self, PyObject *args)
{
PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_readable, NULL);
if (res == NULL)
@@ -235,6 +240,8 @@
Py_CLEAR(res);
PyErr_SetString(PyExc_IOError, "File or stream is not readable.");
}
+ if (args == Py_True)
+ Py_DECREF(res);
return res;
}
@@ -251,7 +258,7 @@
/* May be called with any object */
PyObject *
-_PyIOBase_checkWritable(PyObject *self, PyObject *unused)
+_PyIOBase_checkWritable(PyObject *self, PyObject *args)
{
PyObject *res = PyObject_CallMethodObjArgs(self, _PyIO_str_writable, NULL);
if (res == NULL)
@@ -260,6 +267,8 @@
Py_CLEAR(res);
PyErr_SetString(PyExc_IOError, "File or stream is not writable.");
}
+ if (args == Py_True)
+ Py_DECREF(res);
return res;
}
@@ -268,7 +277,7 @@
static PyObject *
IOBase_enter(PyObject *self, PyObject *args)
{
- if (_PyIOBase_checkClosed(self, NULL) == NULL)
+ if (_PyIOBase_checkClosed(self, Py_True) == NULL)
return NULL;
Py_INCREF(self);
@@ -304,7 +313,7 @@
static PyObject *
IOBase_isatty(PyObject *self, PyObject *args)
{
- if (_PyIOBase_checkClosed(self, NULL) == NULL)
+ if (_PyIOBase_checkClosed(self, Py_True) == NULL)
return NULL;
Py_RETURN_FALSE;
}
@@ -334,7 +343,7 @@
return NULL;
}
- if (_PyIOBase_checkClosed(self, NULL) == NULL)
+ if (_PyIOBase_checkClosed(self, Py_True) == NULL)
return NULL;
if (PyObject_HasAttrString(self, "peek"))
@@ -406,7 +415,7 @@
static PyObject *
IOBase_iter(PyObject *self)
{
- if (_PyIOBase_checkClosed(self, NULL) == NULL)
+ if (_PyIOBase_checkClosed(self, Py_True) == NULL)
return NULL;
Py_INCREF(self);
@@ -502,7 +511,7 @@
return NULL;
}
- if (_PyIOBase_checkClosed(self, NULL) == NULL)
+ if (_PyIOBase_checkClosed(self, Py_True) == NULL)
return NULL;
iter = PyObject_GetIter(lines);
Modified: sandbox/trunk/io-c/_iomodule.h
==============================================================================
--- sandbox/trunk/io-c/_iomodule.h (original)
+++ sandbox/trunk/io-c/_iomodule.h Thu Jan 8 22:45:03 2009
@@ -30,10 +30,14 @@
extern PyTypeObject PyTextIOWrapper_Type;
extern PyTypeObject PyIncrementalNewlineDecoder_Type;
-extern PyObject* _PyIOBase_checkReadable(PyObject *self, PyObject *unused);
-extern PyObject* _PyIOBase_checkWritable(PyObject *self, PyObject *unused);
-extern PyObject* _PyIOBase_checkSeekable(PyObject *self, PyObject *unused);
-extern PyObject* _PyIOBase_checkClosed(PyObject *self, PyObject *unused);
+/* These functions are used as METH_NOARGS methods, are normally called
+ * with args=NULL, and return a new reference.
+ * BUT when args=Py_True is passed, they return a borrowed reference.
+ */
+extern PyObject* _PyIOBase_checkReadable(PyObject *self, PyObject *args);
+extern PyObject* _PyIOBase_checkWritable(PyObject *self, PyObject *args);
+extern PyObject* _PyIOBase_checkSeekable(PyObject *self, PyObject *args);
+extern PyObject* _PyIOBase_checkClosed(PyObject *self, PyObject *args);
extern PyObject* PyIOExc_UnsupportedOperation;
Modified: sandbox/trunk/io-c/_textio.c
==============================================================================
--- sandbox/trunk/io-c/_textio.c (original)
+++ sandbox/trunk/io-c/_textio.c Thu Jan 8 22:45:03 2009
@@ -655,7 +655,7 @@
return NULL;
}
- if (_PyIOBase_checkClosed((PyObject *)self, NULL) == NULL)
+ if (_PyIOBase_checkClosed((PyObject *)self, Py_True) == NULL)
return NULL;
Py_INCREF(text);
@@ -928,7 +928,7 @@
return NULL;
}
- if (_PyIOBase_checkClosed((PyObject *)self, NULL) == NULL)
+ if (_PyIOBase_checkClosed((PyObject *)self, Py_True) == NULL)
return NULL;
/* Grab all the decoded text (we will rewind any extra bits later). */
@@ -1192,7 +1192,7 @@
return NULL;
Py_INCREF(cookieObj);
- if (_PyIOBase_checkClosed((PyObject *)self, NULL) == NULL)
+ if (_PyIOBase_checkClosed((PyObject *)self, Py_True) == NULL)
goto fail;
if (!self->seekable) {
More information about the Python-checkins
mailing list