diff options
author | R David Murray <rdmurray@bitdance.com> | 2012-04-13 21:27:19 -0400 |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2012-04-13 21:27:19 -0400 |
commit | ea7bc055b08fb442986e0735b1b5b325b0b51ecc (patch) | |
tree | 20c2b837c787daf7e95ece075e6544627b17625a /Modules/_io/iobase.c | |
parent | c32365d2ce552d1d17279e30a564509235ffb1db (diff) | |
parent | c2c9c905706160bf34aea12f2348210aac3e0da2 (diff) | |
download | cpython-ea7bc055b08fb442986e0735b1b5b325b0b51ecc.tar.gz |
Merge #14399: corrected news item
Diffstat (limited to 'Modules/_io/iobase.c')
-rw-r--r-- | Modules/_io/iobase.c | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 35c7cdd480..b30bbb69a3 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -59,8 +59,9 @@ PyDoc_STRVAR(iobase_doc, of the IOBase object rather than the virtual `closed` attribute as returned by whatever subclass. */ +_Py_IDENTIFIER(__IOBase_closed); #define IS_CLOSED(self) \ - PyObject_HasAttrString(self, "__IOBase_closed") + _PyObject_HasAttrId(self, &PyId___IOBase_closed) /* Internal methods */ static PyObject * @@ -97,7 +98,9 @@ PyDoc_STRVAR(iobase_tell_doc, static PyObject * iobase_tell(PyObject *self, PyObject *args) { - return PyObject_CallMethod(self, "seek", "ii", 0, 1); + _Py_IDENTIFIER(seek); + + return _PyObject_CallMethodId(self, &PyId_seek, "ii", 0, 1); } PyDoc_STRVAR(iobase_truncate_doc, @@ -156,19 +159,6 @@ iobase_closed_get(PyObject *self, void *context) return PyBool_FromLong(IS_CLOSED(self)); } -static PyObject * -iobase_get_dict(PyObject *self) -{ - PyObject **dictptr = _PyObject_GetDictPtr(self); - PyObject *dict; - assert(dictptr); - dict = *dictptr; - if (dict == NULL) - dict = *dictptr = PyDict_New(); - Py_XINCREF(dict); - return dict; -} - PyObject * _PyIOBase_check_closed(PyObject *self, PyObject *args) { @@ -190,12 +180,13 @@ static PyObject * iobase_close(PyObject *self, PyObject *args) { PyObject *res; + _Py_IDENTIFIER(__IOBase_closed); if (IS_CLOSED(self)) Py_RETURN_NONE; res = PyObject_CallMethodObjArgs(self, _PyIO_str_flush, NULL); - PyObject_SetAttrString(self, "__IOBase_closed", Py_True); + _PyObject_SetAttrId(self, &PyId___IOBase_closed, Py_True); if (res == NULL) { return NULL; } @@ -464,12 +455,14 @@ iobase_readline(PyObject *self, PyObject *args) int has_peek = 0; PyObject *buffer, *result; Py_ssize_t old_size = -1; + _Py_IDENTIFIER(read); + _Py_IDENTIFIER(peek); if (!PyArg_ParseTuple(args, "|O&:readline", &_PyIO_ConvertSsize_t, &limit)) { return NULL; } - if (PyObject_HasAttrString(self, "peek")) + if (_PyObject_HasAttrId(self, &PyId_peek)) has_peek = 1; buffer = PyByteArray_FromStringAndSize(NULL, 0); @@ -481,7 +474,9 @@ iobase_readline(PyObject *self, PyObject *args) PyObject *b; if (has_peek) { - PyObject *readahead = PyObject_CallMethod(self, "peek", "i", 1); + _Py_IDENTIFIER(peek); + PyObject *readahead = _PyObject_CallMethodId(self, &PyId_peek, "i", 1); + if (readahead == NULL) goto fail; if (!PyBytes_Check(readahead)) { @@ -515,7 +510,7 @@ iobase_readline(PyObject *self, PyObject *args) Py_DECREF(readahead); } - b = PyObject_CallMethod(self, "read", "n", nreadahead); + b = _PyObject_CallMethodId(self, &PyId_read, "n", nreadahead); if (b == NULL) goto fail; if (!PyBytes_Check(b)) { @@ -601,7 +596,9 @@ iobase_readlines(PyObject *self, PyObject *args) /* XXX special-casing this made sense in the Python version in order to remove the bytecode interpretation overhead, but it could probably be removed here. */ - PyObject *ret = PyObject_CallMethod(result, "extend", "O", self); + _Py_IDENTIFIER(extend); + PyObject *ret = _PyObject_CallMethodId(result, &PyId_extend, "O", self); + if (ret == NULL) { Py_DECREF(result); return NULL; @@ -704,7 +701,7 @@ static PyMethodDef iobase_methods[] = { }; static PyGetSetDef iobase_getset[] = { - {"__dict__", (getter)iobase_get_dict, NULL, NULL}, + {"__dict__", PyObject_GenericGetDict, NULL, NULL}, {"closed", (getter)iobase_closed_get, NULL, NULL}, {NULL} }; @@ -781,8 +778,11 @@ rawiobase_read(PyObject *self, PyObject *args) return NULL; } - if (n < 0) - return PyObject_CallMethod(self, "readall", NULL); + if (n < 0) { + _Py_IDENTIFIER(readall); + + return _PyObject_CallMethodId(self, &PyId_readall, NULL); + } /* TODO: allocate a bytes object directly instead and manually construct a writable memoryview pointing to it. */ @@ -823,8 +823,9 @@ rawiobase_readall(PyObject *self, PyObject *args) return NULL; while (1) { - PyObject *data = PyObject_CallMethod(self, "read", - "i", DEFAULT_BUFFER_SIZE); + _Py_IDENTIFIER(read); + PyObject *data = _PyObject_CallMethodId(self, &PyId_read, + "i", DEFAULT_BUFFER_SIZE); if (!data) { Py_DECREF(chunks); return NULL; |