[Python-checkins] r67104 - sandbox/trunk/io-c/io.c
amaury.forgeotdarc
python-checkins at python.org
Tue Nov 4 23:42:23 CET 2008
Author: amaury.forgeotdarc
Date: Tue Nov 4 23:42:23 2008
New Revision: 67104
Log:
Expose methods _checkClosed & co: socket.SocketIO needs them.
Modified:
sandbox/trunk/io-c/io.c
Modified: sandbox/trunk/io-c/io.c
==============================================================================
--- sandbox/trunk/io-c/io.c (original)
+++ sandbox/trunk/io-c/io.c Tue Nov 4 23:42:23 2008
@@ -641,14 +641,14 @@
}
-static int
-IOBase_checkClosed(PyObject *self)
+static PyObject *
+IOBase_checkClosed(PyObject *self, PyObject *unused)
{
if (IOBase_closed(self)) {
PyErr_SetString(PyExc_ValueError, "I/O operation on closed file.");
- return -1;
+ return NULL;
}
- return 0;
+ Py_RETURN_NONE;
}
static PyObject*
@@ -700,19 +700,17 @@
Py_RETURN_FALSE;
}
-static int
-IOBase_checkSeekable(PyObject *self)
+static PyObject*
+IOBase_checkSeekable(PyObject *self, PyObject *unused)
{
- int ret = 0;
PyObject *res = PyObject_CallMethod(self, "seekable", NULL);
if (res == NULL)
- return -1;
+ return NULL;
if (res != Py_True) {
+ Py_CLEAR(res);
PyErr_SetString(PyExc_IOError, "File or stream is not seekable.");
- ret = -1;
}
- Py_DECREF(res);
- return ret;
+ return res;
}
PyDoc_STRVAR(IOBase_readable_doc,
@@ -727,19 +725,17 @@
}
/* May be called with any object */
-static int
-IOBase_checkReadable(PyObject *self)
+static PyObject*
+IOBase_checkReadable(PyObject *self, PyObject *unused)
{
- int ret = 0;
PyObject *res = PyObject_CallMethod(self, "readable", NULL);
if (res == NULL)
- return -1;
+ return NULL;
if (res != Py_True) {
+ Py_CLEAR(res);
PyErr_SetString(PyExc_IOError, "File or stream is not readable.");
- ret = -1;
}
- Py_DECREF(res);
- return ret;
+ return res;
}
PyDoc_STRVAR(IOBase_writable_doc,
@@ -754,19 +750,17 @@
}
/* May be called with any object */
-static int
-IOBase_checkWritable(PyObject *self)
+static PyObject*
+IOBase_checkWritable(PyObject *self, PyObject *unused)
{
- int ret = 0;
PyObject *res = PyObject_CallMethod(self, "writable", NULL);
if (res == NULL)
- return -1;
+ return NULL;
if (res != Py_True) {
+ Py_CLEAR(res);
PyErr_SetString(PyExc_IOError, "File or stream is not writable.");
- ret = -1;
}
- Py_DECREF(res);
- return ret;
+ return res;
}
/* Context manager */
@@ -774,7 +768,7 @@
static PyObject *
IOBase_enter(PyObject *self, PyObject *args)
{
- if (IOBase_checkClosed(self) < 0)
+ if (IOBase_checkClosed(self, NULL) == NULL)
return NULL;
Py_INCREF(self);
@@ -810,7 +804,7 @@
static PyObject *
IOBase_isatty(PyObject *self, PyObject *args)
{
- if (IOBase_checkClosed(self) < 0)
+ if (IOBase_checkClosed(self, NULL) == NULL)
return NULL;
Py_RETURN_FALSE;
}
@@ -840,7 +834,7 @@
return NULL;
}
- if (IOBase_checkClosed(self) < 0)
+ if (IOBase_checkClosed(self, NULL) == NULL)
return NULL;
if (PyObject_HasAttrString(self, "peek"))
@@ -924,7 +918,7 @@
static PyObject *
IOBase_iter(PyObject *self, PyObject *args)
{
- if (IOBase_checkClosed(self) < 0)
+ if (IOBase_checkClosed(self, NULL) == NULL)
return NULL;
Py_INCREF(self);
@@ -1015,7 +1009,7 @@
return NULL;
}
- if (IOBase_checkClosed(self) < 0)
+ if (IOBase_checkClosed(self, NULL) == NULL)
return NULL;
iter = PyObject_GetIter(lines);
@@ -1054,6 +1048,12 @@
{"seekable", IOBase_seekable, METH_NOARGS},
{"readable", IOBase_readable, METH_NOARGS},
{"writable", IOBase_writable, METH_NOARGS},
+
+ {"_checkClosed", IOBase_checkClosed, METH_NOARGS},
+ {"_checkSeekable", IOBase_checkSeekable, METH_NOARGS},
+ {"_checkReadable", IOBase_checkReadable, METH_NOARGS},
+ {"_checkWritable", IOBase_checkWritable, METH_NOARGS},
+
{"fileno", IOBase_fileno, METH_NOARGS},
{"isatty", IOBase_isatty, METH_NOARGS},
@@ -1191,9 +1191,10 @@
PyObject *b;
Py_ssize_t cursize = 0;
- b = PyBytes_FromStringAndSize(NULL, 0);
+ b = PyBytes_FromStringAndSize(NULL, 1); /* Avoid shared buffer */
if (b == NULL)
return NULL;
+ assert (Py_REFCNT(b) == 1);
while (1) {
Py_ssize_t length;
@@ -1556,7 +1557,7 @@
return -1;
}
- if (IOBase_checkReadable(raw) < 0)
+ if (IOBase_checkReadable(raw, NULL) == NULL)
return -1;
Py_INCREF(raw);
@@ -2039,7 +2040,7 @@
return -1;
}
- if (IOBase_checkWritable(raw) < 0)
+ if (IOBase_checkWritable(raw, NULL) == NULL)
return -1;
Py_INCREF(raw);
@@ -2422,9 +2423,9 @@
return -1;
}
- if (IOBase_checkReadable(reader) < 0)
+ if (IOBase_checkReadable(reader, NULL) == NULL)
return -1;
- if (IOBase_checkWritable(writer) < 0)
+ if (IOBase_checkWritable(writer, NULL) == NULL)
return -1;
args = Py_BuildValue("(n)", buffer_size);
@@ -2628,11 +2629,11 @@
return -1;
}
- if (IOBase_checkSeekable(raw) < 0)
+ if (IOBase_checkSeekable(raw, NULL) == NULL)
return -1;
- if (IOBase_checkReadable(raw) < 0)
+ if (IOBase_checkReadable(raw, NULL) == NULL)
return -1;
- if (IOBase_checkWritable(raw) < 0)
+ if (IOBase_checkWritable(raw, NULL) == NULL)
return -1;
Py_INCREF(raw);
More information about the Python-checkins
mailing list