changeset: 105553:434e76e0ee17 user: Victor Stinner date: Fri Dec 09 15:39:28 2016 +0100 files: Modules/_io/bufferedio.c Modules/_io/fileio.c Modules/_io/iobase.c Modules/_io/textio.c Modules/_io/winconsoleio.c description: Use _PyObject_CallMethodIdObjArgs() in _io Issue #28915: Replace _PyObject_CallMethodId() with _PyObject_CallMethodIdObjArgs() when the format string was only made of "O" formats, PyObject* arguments. _PyObject_CallMethodIdObjArgs() avoids the creation of a temporary tuple and doesn't have to parse a format string. diff -r 5b41b92a7ccf -r 434e76e0ee17 Modules/_io/bufferedio.c --- a/Modules/_io/bufferedio.c Fri Dec 09 15:24:31 2016 +0100 +++ b/Modules/_io/bufferedio.c Fri Dec 09 15:39:28 2016 +0100 @@ -454,7 +454,8 @@ { if (self->ok && self->raw) { PyObject *r; - r = _PyObject_CallMethodId(self->raw, &PyId__dealloc_warn, "O", source); + r = _PyObject_CallMethodIdObjArgs(self->raw, &PyId__dealloc_warn, + source, NULL); if (r) Py_DECREF(r); else diff -r 5b41b92a7ccf -r 434e76e0ee17 Modules/_io/fileio.c --- a/Modules/_io/fileio.c Fri Dec 09 15:24:31 2016 +0100 +++ b/Modules/_io/fileio.c Fri Dec 09 15:39:28 2016 +0100 @@ -150,8 +150,8 @@ PyObject *exc, *val, *tb; int rc; _Py_IDENTIFIER(close); - res = _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type, - &PyId_close, "O", self); + res = _PyObject_CallMethodIdObjArgs((PyObject*)&PyRawIOBase_Type, + &PyId_close, self, NULL); if (!self->closefd) { self->fd = -1; return res; diff -r 5b41b92a7ccf -r 434e76e0ee17 Modules/_io/iobase.c --- a/Modules/_io/iobase.c Fri Dec 09 15:24:31 2016 +0100 +++ b/Modules/_io/iobase.c Fri Dec 09 15:39:28 2016 +0100 @@ -661,7 +661,8 @@ to remove the bytecode interpretation overhead, but it could probably be removed here. */ _Py_IDENTIFIER(extend); - PyObject *ret = _PyObject_CallMethodId(result, &PyId_extend, "O", self); + PyObject *ret = _PyObject_CallMethodIdObjArgs(result, &PyId_extend, + self, NULL); if (ret == NULL) { Py_DECREF(result); diff -r 5b41b92a7ccf -r 434e76e0ee17 Modules/_io/textio.c --- a/Modules/_io/textio.c Fri Dec 09 15:24:31 2016 +0100 +++ b/Modules/_io/textio.c Fri Dec 09 15:39:28 2016 +0100 @@ -899,8 +899,8 @@ PyObject *locale_module = _PyIO_get_locale_module(state); if (locale_module == NULL) goto catch_ImportError; - self->encoding = _PyObject_CallMethodId( - locale_module, &PyId_getpreferredencoding, "O", Py_False); + self->encoding = _PyObject_CallMethodIdObjArgs( + locale_module, &PyId_getpreferredencoding, Py_False, NULL); Py_DECREF(locale_module); if (self->encoding == NULL) { catch_ImportError: @@ -2644,7 +2644,9 @@ else { PyObject *exc = NULL, *val, *tb; if (self->finalizing) { - res = _PyObject_CallMethodId(self->buffer, &PyId__dealloc_warn, "O", self); + res = _PyObject_CallMethodIdObjArgs(self->buffer, + &PyId__dealloc_warn, + self, NULL); if (res) Py_DECREF(res); else diff -r 5b41b92a7ccf -r 434e76e0ee17 Modules/_io/winconsoleio.c --- a/Modules/_io/winconsoleio.c Fri Dec 09 15:24:31 2016 +0100 +++ b/Modules/_io/winconsoleio.c Fri Dec 09 15:39:28 2016 +0100 @@ -85,7 +85,7 @@ Py_CLEAR(decoded); return '\0'; } - decoded_upper = PyObject_CallMethod(decoded, "upper", ""); + decoded_upper = PyObject_CallMethod(decoded, "upper", NULL); Py_CLEAR(decoded); if (!decoded_upper) { PyErr_Clear(); @@ -181,8 +181,8 @@ PyObject *exc, *val, *tb; int rc; _Py_IDENTIFIER(close); - res = _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type, - &PyId_close, "O", self); + res = _PyObject_CallMethodIdObjArgs((PyObject*)&PyRawIOBase_Type, + &PyId_close, self, NULL); if (!self->closehandle) { self->handle = INVALID_HANDLE_VALUE; return res;