Kaydet (Commit) 2990fa11 authored tarafından Victor Stinner's avatar Victor Stinner

Issue #27809: Use _PyObject_FastCallDict()

Modify:

* builtin_sorted()
* classmethoddescr_call()
* methoddescr_call()
* wrapperdescr_call()
üst 6fea7f7f
...@@ -213,7 +213,7 @@ static PyObject * ...@@ -213,7 +213,7 @@ static PyObject *
methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds) methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds)
{ {
Py_ssize_t argc; Py_ssize_t argc;
PyObject *self, *func, *result; PyObject *self, *func, *result, **stack;
/* Make sure that the first argument is acceptable as 'self' */ /* Make sure that the first argument is acceptable as 'self' */
assert(PyTuple_Check(args)); assert(PyTuple_Check(args));
...@@ -242,13 +242,8 @@ methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds) ...@@ -242,13 +242,8 @@ methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds)
func = PyCFunction_NewEx(descr->d_method, self, NULL); func = PyCFunction_NewEx(descr->d_method, self, NULL);
if (func == NULL) if (func == NULL)
return NULL; return NULL;
args = PyTuple_GetSlice(args, 1, argc); stack = &PyTuple_GET_ITEM(args, 1);
if (args == NULL) { result = _PyObject_FastCallDict(func, stack, argc - 1, kwds);
Py_DECREF(func);
return NULL;
}
result = PyEval_CallObjectWithKeywords(func, args, kwds);
Py_DECREF(args);
Py_DECREF(func); Py_DECREF(func);
return result; return result;
} }
...@@ -258,7 +253,7 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args, ...@@ -258,7 +253,7 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
PyObject *kwds) PyObject *kwds)
{ {
Py_ssize_t argc; Py_ssize_t argc;
PyObject *self, *func, *result; PyObject *self, *func, *result, **stack;
/* Make sure that the first argument is acceptable as 'self' */ /* Make sure that the first argument is acceptable as 'self' */
assert(PyTuple_Check(args)); assert(PyTuple_Check(args));
...@@ -295,14 +290,9 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args, ...@@ -295,14 +290,9 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
func = PyCFunction_NewEx(descr->d_method, self, NULL); func = PyCFunction_NewEx(descr->d_method, self, NULL);
if (func == NULL) if (func == NULL)
return NULL; return NULL;
args = PyTuple_GetSlice(args, 1, argc); stack = &PyTuple_GET_ITEM(args, 1);
if (args == NULL) { result = _PyObject_FastCallDict(func, stack, argc - 1, kwds);
Py_DECREF(func);
return NULL;
}
result = PyEval_CallObjectWithKeywords(func, args, kwds);
Py_DECREF(func); Py_DECREF(func);
Py_DECREF(args);
return result; return result;
} }
...@@ -310,7 +300,7 @@ static PyObject * ...@@ -310,7 +300,7 @@ static PyObject *
wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds) wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds)
{ {
Py_ssize_t argc; Py_ssize_t argc;
PyObject *self, *func, *result; PyObject *self, *func, *result, **stack;
/* Make sure that the first argument is acceptable as 'self' */ /* Make sure that the first argument is acceptable as 'self' */
assert(PyTuple_Check(args)); assert(PyTuple_Check(args));
...@@ -339,13 +329,9 @@ wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds) ...@@ -339,13 +329,9 @@ wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds)
func = PyWrapper_New((PyObject *)descr, self); func = PyWrapper_New((PyObject *)descr, self);
if (func == NULL) if (func == NULL)
return NULL; return NULL;
args = PyTuple_GetSlice(args, 1, argc);
if (args == NULL) { stack = &PyTuple_GET_ITEM(args, 1);
Py_DECREF(func); result = _PyObject_FastCallDict(func, stack, argc - 1, kwds);
return NULL;
}
result = PyEval_CallObjectWithKeywords(func, args, kwds);
Py_DECREF(args);
Py_DECREF(func); Py_DECREF(func);
return result; return result;
} }
......
...@@ -2087,10 +2087,11 @@ PyDoc_STRVAR(builtin_sorted__doc__, ...@@ -2087,10 +2087,11 @@ PyDoc_STRVAR(builtin_sorted__doc__,
static PyObject * static PyObject *
builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds) builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)
{ {
PyObject *newlist, *v, *seq, *keyfunc=NULL, *newargs; PyObject *newlist, *v, *seq, *keyfunc=NULL, **newargs;
PyObject *callable; PyObject *callable;
static char *kwlist[] = {"iterable", "key", "reverse", 0}; static char *kwlist[] = {"iterable", "key", "reverse", 0};
int reverse; int reverse;
int nargs;
/* args 1-3 should match listsort in Objects/listobject.c */ /* args 1-3 should match listsort in Objects/listobject.c */
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi:sorted", if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi:sorted",
...@@ -2107,15 +2108,9 @@ builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds) ...@@ -2107,15 +2108,9 @@ builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)
return NULL; return NULL;
} }
newargs = PyTuple_GetSlice(args, 1, 4); newargs = &PyTuple_GET_ITEM(args, 1);
if (newargs == NULL) { nargs = PyTuple_GET_SIZE(args) - 1;
Py_DECREF(newlist); v = _PyObject_FastCallDict(callable, newargs, nargs, kwds);
Py_DECREF(callable);
return NULL;
}
v = PyObject_Call(callable, newargs, kwds);
Py_DECREF(newargs);
Py_DECREF(callable); Py_DECREF(callable);
if (v == NULL) { if (v == NULL) {
Py_DECREF(newlist); Py_DECREF(newlist);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment