Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61bdb0d

Browse files
committed
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.
1 parent 20401de commit 61bdb0d

5 files changed

Lines changed: 14 additions & 10 deletions

File tree

Modules/_io/bufferedio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ buffered_dealloc_warn(buffered *self, PyObject *source)
454454
{
455455
if (self->ok && self->raw) {
456456
PyObject *r;
457-
r = _PyObject_CallMethodId(self->raw, &PyId__dealloc_warn, "O", source);
457+
r = _PyObject_CallMethodIdObjArgs(self->raw, &PyId__dealloc_warn,
458+
source, NULL);
458459
if (r)
459460
Py_DECREF(r);
460461
else

Modules/_io/fileio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ _io_FileIO_close_impl(fileio *self)
150150
PyObject *exc, *val, *tb;
151151
int rc;
152152
_Py_IDENTIFIER(close);
153-
res = _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type,
154-
&PyId_close, "O", self);
153+
res = _PyObject_CallMethodIdObjArgs((PyObject*)&PyRawIOBase_Type,
154+
&PyId_close, self, NULL);
155155
if (!self->closefd) {
156156
self->fd = -1;
157157
return res;

Modules/_io/iobase.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,8 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint)
661661
to remove the bytecode interpretation overhead, but it could
662662
probably be removed here. */
663663
_Py_IDENTIFIER(extend);
664-
PyObject *ret = _PyObject_CallMethodId(result, &PyId_extend, "O", self);
664+
PyObject *ret = _PyObject_CallMethodIdObjArgs(result, &PyId_extend,
665+
self, NULL);
665666

666667
if (ret == NULL) {
667668
Py_DECREF(result);

Modules/_io/textio.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,8 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
899899
PyObject *locale_module = _PyIO_get_locale_module(state);
900900
if (locale_module == NULL)
901901
goto catch_ImportError;
902-
self->encoding = _PyObject_CallMethodId(
903-
locale_module, &PyId_getpreferredencoding, "O", Py_False);
902+
self->encoding = _PyObject_CallMethodIdObjArgs(
903+
locale_module, &PyId_getpreferredencoding, Py_False, NULL);
904904
Py_DECREF(locale_module);
905905
if (self->encoding == NULL) {
906906
catch_ImportError:
@@ -2644,7 +2644,9 @@ _io_TextIOWrapper_close_impl(textio *self)
26442644
else {
26452645
PyObject *exc = NULL, *val, *tb;
26462646
if (self->finalizing) {
2647-
res = _PyObject_CallMethodId(self->buffer, &PyId__dealloc_warn, "O", self);
2647+
res = _PyObject_CallMethodIdObjArgs(self->buffer,
2648+
&PyId__dealloc_warn,
2649+
self, NULL);
26482650
if (res)
26492651
Py_DECREF(res);
26502652
else

Modules/_io/winconsoleio.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ char _PyIO_get_console_type(PyObject *path_or_fd) {
8585
Py_CLEAR(decoded);
8686
return '\0';
8787
}
88-
decoded_upper = PyObject_CallMethod(decoded, "upper", "");
88+
decoded_upper = PyObject_CallMethod(decoded, "upper", NULL);
8989
Py_CLEAR(decoded);
9090
if (!decoded_upper) {
9191
PyErr_Clear();
@@ -181,8 +181,8 @@ _io__WindowsConsoleIO_close_impl(winconsoleio *self)
181181
PyObject *exc, *val, *tb;
182182
int rc;
183183
_Py_IDENTIFIER(close);
184-
res = _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type,
185-
&PyId_close, "O", self);
184+
res = _PyObject_CallMethodIdObjArgs((PyObject*)&PyRawIOBase_Type,
185+
&PyId_close, self, NULL);
186186
if (!self->closehandle) {
187187
self->handle = INVALID_HANDLE_VALUE;
188188
return res;

0 commit comments

Comments
 (0)