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

Commit 250e4b0

Browse files
committed
Fix _PyMethodDef_RawFastCallDict() argument parsing
Issue python#29259: * Move also the !PyErr_Occurred() assertion to the top, similar to other functions. * Fix also comment/error messages: the function was renamed to _PyMethodDef_RawFastCallDict()
1 parent 7612f1e commit 250e4b0

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

Objects/methodobject.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,30 +159,31 @@ _PyMethodDef_RawFastCallDict(PyMethodDef *method, PyObject *self, PyObject **arg
159159
PyObject *result;
160160
int flags;
161161

162+
/* _PyMethodDef_RawFastCallDict() must not be called with an exception set,
163+
because it may clear it (directly or indirectly) and so the
164+
caller loses its exception */
165+
assert(!PyErr_Occurred());
166+
162167
assert(method != NULL);
163168
assert(nargs >= 0);
164169
assert(nargs == 0 || args != NULL);
165170
assert(kwargs == NULL || PyDict_Check(kwargs));
166171

167-
/* _PyCFunction_FastCallDict() must not be called with an exception set,
168-
because it may clear it (directly or indirectly) and so the
169-
caller loses its exception */
170-
assert(!PyErr_Occurred());
171-
172172
meth = method->ml_meth;
173173
flags = method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
174174

175175
switch (flags)
176176
{
177177
case METH_NOARGS:
178-
if (nargs != 0) {
179-
goto no_keyword_error;
180-
}
178+
if (nargs != 0) {
179+
PyErr_Format(PyExc_TypeError,
180+
"%.200s() takes no arguments (%zd given)",
181+
method->ml_name, nargs);
182+
return NULL;
183+
}
181184

182185
if (kwargs != NULL && PyDict_GET_SIZE(kwargs) != 0) {
183-
PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
184-
method->ml_name);
185-
return NULL;
186+
goto no_keyword_error;
186187
}
187188

188189
result = (*meth) (self, NULL);
@@ -249,7 +250,7 @@ _PyMethodDef_RawFastCallDict(PyMethodDef *method, PyObject *self, PyObject **arg
249250

250251
default:
251252
PyErr_SetString(PyExc_SystemError,
252-
"Bad call flags in PyCFunction_Call. "
253+
"Bad call flags in _PyMethodDef_RawFastCallDict. "
253254
"METH_OLDARGS is no longer supported!");
254255
return NULL;
255256
}
@@ -258,8 +259,9 @@ _PyMethodDef_RawFastCallDict(PyMethodDef *method, PyObject *self, PyObject **arg
258259

259260
no_keyword_error:
260261
PyErr_Format(PyExc_TypeError,
261-
"%.200s() takes no arguments (%zd given)",
262-
method->ml_name, nargs);
262+
"%.200s() takes no keyword arguments",
263+
method->ml_name, nargs);
264+
263265
return NULL;
264266
}
265267

0 commit comments

Comments
 (0)