Mercurial > cpython-lru_cache-weakref
diff Modules/cStringIO.c @ 27044:23280a64288e legacy-trunk
SF patch 660559: Use METH_O and METH_NOARGS where possible
Simplify code and speed access by using PyArg_UnpackTuple, METH_O and
METH_NOARGS in three modules that can benefit from it.
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 03 Jan 2003 08:24:58 +0000 |
| parents | 9a178adb4e2d |
| children | 0ea5991f6edb |
line wrap: on
line diff
--- a/Modules/cStringIO.c Fri Jan 03 03:30:21 2003 +0000 +++ b/Modules/cStringIO.c Fri Jan 03 08:24:58 2003 +0000 @@ -87,10 +87,9 @@ } static PyObject * -IO_flush(IOobject *self, PyObject *args) { +IO_flush(IOobject *self, PyObject *unused) { UNLESS (IO__opencheck(self)) return NULL; - UNLESS (PyArg_ParseTuple(args, ":flush")) return NULL; Py_INCREF(Py_None); return Py_None; @@ -115,7 +114,7 @@ int s; UNLESS (IO__opencheck(self)) return NULL; - UNLESS (PyArg_ParseTuple(args,"|O:getval",&use_pos)) return NULL; + UNLESS (PyArg_UnpackTuple(args,"getval", 0, 1,&use_pos)) return NULL; if (PyObject_IsTrue(use_pos)) { s=self->pos; @@ -129,10 +128,7 @@ PyDoc_STRVAR(IO_isatty__doc__, "isatty(): always returns 0"); static PyObject * -IO_isatty(IOobject *self, PyObject *args) { - - UNLESS (PyArg_ParseTuple(args, ":isatty")) return NULL; - +IO_isatty(IOobject *self, PyObject *unused) { Py_INCREF(Py_False); return Py_False; } @@ -243,10 +239,9 @@ "reset() -- Reset the file position to the beginning"); static PyObject * -IO_reset(IOobject *self, PyObject *args) { +IO_reset(IOobject *self, PyObject *unused) { UNLESS (IO__opencheck(self)) return NULL; - UNLESS (PyArg_ParseTuple(args, ":reset")) return NULL; self->pos = 0; @@ -257,10 +252,9 @@ PyDoc_STRVAR(IO_tell__doc__, "tell() -- get the current position."); static PyObject * -IO_tell(IOobject *self, PyObject *args) { +IO_tell(IOobject *self, PyObject *unused) { UNLESS (IO__opencheck(self)) return NULL; - UNLESS (PyArg_ParseTuple(args, ":tell")) return NULL; return PyInt_FromLong(self->pos); } @@ -379,10 +373,7 @@ PyDoc_STRVAR(O_close__doc__, "close(): explicitly release resources held."); static PyObject * -O_close(Oobject *self, PyObject *args) { - - UNLESS (PyArg_ParseTuple(args, ":close")) return NULL; - +O_close(Oobject *self, PyObject *unused) { if (self->buf != NULL) free(self->buf); self->buf = NULL; @@ -400,8 +391,6 @@ PyObject *tmp = 0; static PyObject *joiner = NULL; - UNLESS (PyArg_ParseTuple(args, "O:writelines", &args)) return NULL; - if (!joiner) { PyObject *empty_string = PyString_FromString(""); if (empty_string == NULL) @@ -428,21 +417,21 @@ static struct PyMethodDef O_methods[] = { /* Common methods: */ - {"flush", (PyCFunction)IO_flush, METH_VARARGS, IO_flush__doc__}, + {"flush", (PyCFunction)IO_flush, METH_NOARGS, IO_flush__doc__}, {"getvalue", (PyCFunction)IO_getval, METH_VARARGS, IO_getval__doc__}, - {"isatty", (PyCFunction)IO_isatty, METH_VARARGS, IO_isatty__doc__}, + {"isatty", (PyCFunction)IO_isatty, METH_NOARGS, IO_isatty__doc__}, {"read", (PyCFunction)IO_read, METH_VARARGS, IO_read__doc__}, {"readline", (PyCFunction)IO_readline, METH_VARARGS, IO_readline__doc__}, {"readlines", (PyCFunction)IO_readlines,METH_VARARGS, IO_readlines__doc__}, - {"reset", (PyCFunction)IO_reset, METH_VARARGS, IO_reset__doc__}, - {"tell", (PyCFunction)IO_tell, METH_VARARGS, IO_tell__doc__}, + {"reset", (PyCFunction)IO_reset, METH_NOARGS, IO_reset__doc__}, + {"tell", (PyCFunction)IO_tell, METH_NOARGS, IO_tell__doc__}, {"truncate", (PyCFunction)IO_truncate, METH_VARARGS, IO_truncate__doc__}, /* Read-write StringIO specific methods: */ - {"close", (PyCFunction)O_close, METH_VARARGS, O_close__doc__}, + {"close", (PyCFunction)O_close, METH_NOARGS, O_close__doc__}, {"seek", (PyCFunction)O_seek, METH_VARARGS, O_seek__doc__}, {"write", (PyCFunction)O_write, METH_VARARGS, O_write__doc__}, - {"writelines", (PyCFunction)O_writelines, METH_VARARGS, O_writelines__doc__}, + {"writelines", (PyCFunction)O_writelines, METH_O, O_writelines__doc__}, {NULL, NULL} /* sentinel */ }; @@ -527,10 +516,7 @@ /* -------------------------------------------------------- */ static PyObject * -I_close(Iobject *self, PyObject *args) { - - UNLESS (PyArg_ParseTuple(args, ":close")) return NULL; - +I_close(Iobject *self, PyObject *unused) { Py_XDECREF(self->pbuf); self->pbuf = NULL; self->buf = NULL; @@ -562,18 +548,18 @@ static struct PyMethodDef I_methods[] = { /* Common methods: */ - {"flush", (PyCFunction)IO_flush, METH_VARARGS, IO_flush__doc__}, + {"flush", (PyCFunction)IO_flush, METH_NOARGS, IO_flush__doc__}, {"getvalue", (PyCFunction)IO_getval, METH_VARARGS, IO_getval__doc__}, - {"isatty", (PyCFunction)IO_isatty, METH_VARARGS, IO_isatty__doc__}, + {"isatty", (PyCFunction)IO_isatty, METH_NOARGS, IO_isatty__doc__}, {"read", (PyCFunction)IO_read, METH_VARARGS, IO_read__doc__}, {"readline", (PyCFunction)IO_readline, METH_VARARGS, IO_readline__doc__}, {"readlines", (PyCFunction)IO_readlines,METH_VARARGS, IO_readlines__doc__}, - {"reset", (PyCFunction)IO_reset, METH_VARARGS, IO_reset__doc__}, - {"tell", (PyCFunction)IO_tell, METH_VARARGS, IO_tell__doc__}, + {"reset", (PyCFunction)IO_reset, METH_NOARGS, IO_reset__doc__}, + {"tell", (PyCFunction)IO_tell, METH_NOARGS, IO_tell__doc__}, {"truncate", (PyCFunction)IO_truncate, METH_VARARGS, IO_truncate__doc__}, /* Read-only StringIO specific methods: */ - {"close", (PyCFunction)I_close, METH_VARARGS, O_close__doc__}, + {"close", (PyCFunction)I_close, METH_NOARGS, O_close__doc__}, {"seek", (PyCFunction)I_seek, METH_VARARGS, O_seek__doc__}, {NULL, NULL} }; @@ -674,7 +660,7 @@ IO_StringIO(PyObject *self, PyObject *args) { PyObject *s=0; - if (!PyArg_ParseTuple(args, "|O:StringIO", &s)) return NULL; + if (!PyArg_UnpackTuple(args, "StringIO", 0, 1, &s)) return NULL; if (s) return newIobject(s); return newOobject(128);
