8000 [3.14] gh-132775: Fix _PyFunctIon_VerifyStateless() (GH-134900) by miss-islington · Pull Request #134901 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.14] gh-132775: Fix _PyFunctIon_VerifyStateless() (GH-134900) #134901

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

Merged
merged 1 commit into from
May 29, 2025
Merged
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
8000
Diff view
34 changes: 20 additions & 14 deletions Objects/funcobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1264,26 +1264,32 @@ _PyFunction_VerifyStateless(PyThreadState *tstate, PyObject *func)
}
// Disallow __defaults__.
PyObject *defaults = PyFunction_GET_DEFAULTS(func);
if (defaults != NULL && defaults != Py_None && PyDict_Size(defaults) > 0)
{
_PyErr_SetString(tstate, PyExc_ValueError, "defaults not supported");
return -1;
if (defaults != NULL) {
assert(PyTuple_Check(defaults)); // per PyFunction_New()
if (PyTuple_GET_SIZE(defaults) > 0) {
_PyErr_SetString(tstate, PyExc_ValueError,
"defaults not supported");
return -1;
}
}
// Disallow __kwdefaults__.
PyObject *kwdefaults = PyFunction_GET_KW_DEFAULTS(func);
if (kwdefaults != NULL && kwdefaults != Py_None
&& PyDict_Size(kwdefaults) > 0)
{
_PyErr_SetString(tstate, PyExc_ValueError,
"keyword defaults not supported");
return -1;
if (kwdefaults != NULL) {
assert(PyDict_Check(kwdefaults)); // per PyFunction_New()
if (PyDict_Size(kwdefaults) > 0) {
_PyErr_SetString(tstate, PyExc_ValueError,
"keyword defaults not supported");
return -1;
}
}
// Disallow __closure__.
PyObject *closure = PyFunction_GET_CLOSURE(func);
if (closure != NULL && closure != Py_None && PyTuple_GET_SIZE(closure) > 0)
{
_PyErr_SetString(tstate, PyExc_ValueError, "closures not supported");
return -1;
if (closure != NULL) {
assert(PyTuple_Check(closure)); // per PyFunction_New()
if (PyTuple_GET_SIZE(closure) > 0) {
_PyErr_SetString(tstate, PyExc_ValueError, "closures not supported");
return -1;
}
}
// Check the code.
PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
Expand Down
Loading
0