GeezerVison is showing github.com — bpo-29548: Recommend PyObject_Call APIs over PyEval_Call APIs. by methane · Pull Request #75 · python/cpython
bpo-29548: Recommend PyObject_Call APIs over PyEval_Call APIs.
#75
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
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.c
(1)
.h
(1)
All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -7,6 +7,12 @@ extern "C" {
/* Interface to random parts in ceval.c */
/* PyEval_CallObjectWithKeywords(), PyEval_CallObject(), PyEval_CallFunction
* and PyEval_CallMethod are kept for backward compatibility: PyObject_Call(),
* PyObject_CallFunction() and PyObject_CallMethod() are recommended to call
* a callable object.
*/
PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
PyObject *callable,
PyObject *args,
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -939,25 +939,20 @@ PyObject_CallFunction(PyObject *callable, const char *format, ...)
}
/* PyEval_CallFunction is exact copy of PyObject_CallFunction.
* This function is kept for backward compatibility.
*/
PyObject *
PyEval_CallFunction(PyObject *callable, const char *format, ...)
Comment thread
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
commit message: this change also optimizes PyEval_CallFunction() and PyEval_CallMethod() to avoid temporary tuple when possible.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
Main purpose is reducing maintenance cost rather than optimization.
There are very few callers in the world.
I hope compiler can remove duplicated code too, but I'm not sure.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
{
va_list vargs;
PyObject *args;
PyObject *res;
va_start(vargs, format);
args = Py_VaBuildValue(format, vargs);
va_end(vargs);
if (args == NULL)
return NULL;
va_list va;
PyObject *result;
res = PyEval_CallObject(callable, args);
Py_DECREF(args);
va_start(va, format);
result = _PyObject_CallFunctionVa(callable, format, va, 0);
va_end(va);
return res ;
return result ;
}
Expand Down
Expand Up
@@ -1014,33 +1009,29 @@ PyObject_CallMethod(PyObject *obj, const char *name, const char *format, ...)
}
/* PyEval_CallMethod is exact copy of PyObject_CallMethod.
* This function is kept for backward compatibility.
*/
PyObject *
PyEval_CallMethod(PyObject *obj, const char *name, const char *format, ...)
{
va_list vargs;
PyObject *meth;
PyObject *args;
PyObject *res;
meth = PyObject_GetAttrString(obj, name);
if (meth == NULL)
return NULL;
va_start(vargs, format);
va_list va;
PyObject *callable, *retval;
args = Py_VaBuildValue(format, vargs);
va_end(vargs);
if (obj == NULL || name == NULL) {
return null_error();
}
if (args == NULL) {
Py_DECREF(meth);
callable = PyObject_GetAttrString(obj, name);
if (callable == NULL)
return NULL;
}
res = PyEval_CallObject(meth, args );
Py_DECREF(meth );
Py_DECREF(args );
va_start(va, format );
retval = callmethod(callable, format, va, 0 );
va_end(va );
return res;
Py_DECREF(callable);
return retval;
}
Expand Down
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.