Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 0a2e468

Browse files
committed
Cleanup _PyMethodDef_RawFastCallDict()
Issue python#29259: use a different case for METH_VARARGS and METH_VARARGS|METH_KEYWORDS to avoid testing again flags to decide if keywords should be checked or not.
1 parent a8cb515 commit 0a2e468

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

Objects/methodobject.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ _PyMethodDef_RawFastCallDict(PyMethodDef *method, PyObject *self, PyObject **arg
9393
PyCFunction meth;
9494
PyObject *result;
9595
int flags;
96+
PyObject *argstuple;
9697

9798
/* _PyMethodDef_RawFastCallDict() must not be called with an exception set,
9899
because it can clear it (directly or indirectly) and so the
@@ -140,30 +141,27 @@ _PyMethodDef_RawFastCallDict(PyMethodDef *method, PyObject *self, PyObject **arg
140141
break;
141142

142143
case METH_VARARGS:
143-
case METH_VARARGS | METH_KEYWORDS:
144-
{
145-
/* Slow-path: create a temporary tuple for positional arguments */
146-
PyObject *tuple;
147-
148144
if (!(flags & METH_KEYWORDS)
149145
&& kwargs != NULL && PyDict_GET_SIZE(kwargs) != 0) {
150146
goto no_keyword_error;
151147
}
148+
/* fall through next case */
152149

153-
tuple = _PyStack_AsTuple(args, nargs);
154-
if (tuple == NULL) {
150+
case METH_VARARGS | METH_KEYWORDS:
151+
/* Slow-path: create a temporary tuple for positional arguments */
152+
argstuple = _PyStack_AsTuple(args, nargs);
153+
if (argstuple == NULL) {
155154
return NULL;
156155
}
157156

158157
if (flags & METH_KEYWORDS) {
159-
result = (*(PyCFunctionWithKeywords)meth) (self, tuple, kwargs);
158+
result = (*(PyCFunctionWithKeywords)meth) (self, argstuple, kwargs);
160159
}
161160
else {
162-
result = (*meth) (self, tuple);
161+
result = (*meth) (self, argstuple);
163162
}
164-
Py_DECREF(tuple);
163+
Py_DECREF(argstuple);
165164
break;
166-
}
167165

168166
case METH_FASTCALL:
169167
{

0 commit comments

Comments
 (0)