Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-29548: Fix some inefficient call API usage #97

Merged
merged 4 commits into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3070,7 +3070,7 @@ slot_tp_del(PyObject *self)
/* Execute __del__ method, if any. */
del = _PyObject_LookupSpecial(self, &PyId___tp_del__);
if (del != NULL) {
res = PyEval_CallObject(del, NULL);
res = _PyObject_CallNoArg(del);
if (res == NULL)
PyErr_WriteUnraisable(del);
else
Expand Down
3 changes: 1 addition & 2 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,7 @@ t_bootstrap(void *boot_raw)
_PyThreadState_Init(tstate);
PyEval_AcquireThread(tstate);
nb_threads++;
res = PyEval_CallObjectWithKeywords(
boot->func, boot->args, boot->keyw);
res = PyObject_Call(boot->func, boot->args, boot->keyw);
if (res == NULL) {
if (PyErr_ExceptionMatches(PyExc_SystemExit))
PyErr_Clear();
Expand Down
11 changes: 4 additions & 7 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,7 @@ PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[
}
PyTuple_SET_ITEM(arg, i, s);
}
res = PyEval_CallObject(func, arg);
res = PyObject_Call(func, arg, NULL);
Py_DECREF(arg);

if (res == NULL)
Expand Down Expand Up @@ -2661,16 +2661,13 @@ static void
FileHandler(ClientData clientData, int mask)
{
FileHandler_ClientData *data = (FileHandler_ClientData *)clientData;
PyObject *func, *file, *arg, *res;
PyObject *func, *file, *res;

ENTER_PYTHON
func = data->func;
file = data->file;

arg = Py_BuildValue("(Oi)", file, (long) mask);
res = PyEval_CallObject(func, arg);
Py_DECREF(arg);

res = PyObject_CallFunction(func, "Oi", file, mask);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arg variable is no more used and can be removed, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I missed it.
Additionally, argument for "i" format should be int, not (long).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, argument for "i" format should be int, not (long).

Right, I spotted it as well, but then I forgot to report it, sorry :-) Hopefully you fixed it!

if (res == NULL) {
errorInCmd = 1;
PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd);
Expand Down Expand Up @@ -2840,7 +2837,7 @@ TimerHandler(ClientData clientData)

ENTER_PYTHON

res = PyEval_CallObject(func, NULL);
res = _PyObject_CallNoArg(func);
Py_DECREF(func);
Py_DECREF(v); /* See Tktt_New() */

Expand Down
2 changes: 1 addition & 1 deletion Objects/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
41 changes: 14 additions & 27 deletions Objects/fileobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,39 +49,26 @@ 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) {
PyErr_BadInternalCall();
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)) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Objects/weakrefobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down