diff options
author | INADA Naoki <methane@users.noreply.github.com> | 2017-02-16 00:26:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-16 00:26:01 (GMT) |
commit | 72dccde884d89586b0cafd990675b7e21720a81f (patch) | |
tree | b0a57ee76f067c30869089792f385d950dcf22d5 /Objects | |
parent | 72e81d00eee685cfe33aaddf2aa9feef2d07591f (diff) | |
download | cpython-72dccde884d89586b0cafd990675b7e21720a81f.zip cpython-72dccde884d89586b0cafd990675b7e21720a81f.tar.gz cpython-72dccde884d89586b0cafd990675b7e21720a81f.tar.bz2 |
bpo-29548: Fix some inefficient call API usage (GH-97)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/abstract.c | 2 | ||||
-rw-r--r-- | Objects/fileobject.c | 41 | ||||
-rw-r--r-- | Objects/typeobject.c | 2 | ||||
-rw-r--r-- | Objects/weakrefobject.c | 2 |
4 files changed, 17 insertions, 30 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index 589d9e8..4a75b92 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1329,7 +1329,7 @@ PyNumber_Long(PyObject *o) } trunc_func = _PyObject_LookupSpecial(o, &PyId___trunc__); if (trunc_func) { - result = PyEval_CallObject(trunc_func, NULL); + result = _PyObject_CallNoArg(trunc_func); Py_DECREF(trunc_func); if (result == NULL || PyLong_CheckExact(result)) { return result; diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 3c3d46d..0f71944 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -49,6 +49,7 @@ PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const c PyObject * PyFile_GetLine(PyObject *f, int n) { + _Py_IDENTIFIER(readline); PyObject *result; if (f == NULL) { @@ -56,32 +57,18 @@ PyFile_GetLine(PyObject *f, int n) return NULL; } - { - PyObject *reader; - PyObject *args; - _Py_IDENTIFIER(readline); - - reader = _PyObject_GetAttrId(f, &PyId_readline); - if (reader == NULL) - return NULL; - if (n <= 0) - args = PyTuple_New(0); - else - args = Py_BuildValue("(i)", n); - if (args == NULL) { - Py_DECREF(reader); - return NULL; - } - result = PyEval_CallObject(reader, args); - Py_DECREF(reader); - Py_DECREF(args); - if (result != NULL && !PyBytes_Check(result) && - !PyUnicode_Check(result)) { - Py_DECREF(result); - result = NULL; - PyErr_SetString(PyExc_TypeError, - "object.readline() returned non-string"); - } + if (n <= 0) { + result = _PyObject_CallMethodIdObjArgs(f, &PyId_readline, NULL); + } + else { + result = _PyObject_CallMethodId(f, &PyId_readline, "i", n); + } + if (result != NULL && !PyBytes_Check(result) && + !PyUnicode_Check(result)) { + Py_DECREF(result); + result = NULL; + PyErr_SetString(PyExc_TypeError, + "object.readline() returned non-string"); } if (n < 0 && result != NULL && PyBytes_Check(result)) { @@ -197,7 +184,7 @@ PyObject_AsFileDescriptor(PyObject *o) } else if ((meth = _PyObject_GetAttrId(o, &PyId_fileno)) != NULL) { - PyObject *fno = PyEval_CallObject(meth, NULL); + PyObject *fno = _PyObject_CallNoArg(meth); Py_DECREF(meth); if (fno == NULL) return -1; diff --git a/Objects/typeobject.c b/Objects/typeobject.c index f18a795..18b67c8 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4348,7 +4348,7 @@ _common_reduce(PyObject *self, int proto) if (!copyreg) return NULL; - res = PyEval_CallMethod(copyreg, "_reduce_ex", "(Oi)", self, proto); + res = PyObject_CallMethod(copyreg, "_reduce_ex", "Oi", self, proto); Py_DECREF(copyreg); return res; diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index ab6b235..d12db91 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -461,7 +461,7 @@ proxy_checkref(PyWeakReference *proxy) WRAP_BINARY(proxy_getattr, PyObject_GetAttr) WRAP_UNARY(proxy_str, PyObject_Str) -WRAP_TERNARY(proxy_call, PyEval_CallObjectWithKeywords) +WRAP_TERNARY(proxy_call, PyObject_Call) static PyObject * proxy_repr(PyWeakReference *proxy) |