8000 gh-132775: Use _PyFunction_VerifyStateless() and _PyCode_VerifyStateless() by ericsnowcurrently · Pull Request #134439 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-132775: Use _PyFunction_VerifyStateless() and _PyCode_VerifyStateless() #134439

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
Show file tree
Hide file tree
Changes from 1 commit
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
Diff view
Prev Previous commit
Fix the tests.
  • Loading branch information
ericsnowcurrently committed May 21, 2025
commit 51afd9b973df09e017d3f34a0227b73182bbce9b
3 changes: 2 additions & 1 deletion Lib/test/test__interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ def test_closure(self):
def script():
assert spam

with self.assertRaises(ValueError):
with self.assertRaises(TypeError):
_interpreters.run_func(self.id, script)

# XXX This hasn't been fixed yet.
Expand All @@ -1065,6 +1065,7 @@ def script():
with self.assertRaises(ValueError):
_interpreters.run_func(self.id, script)

@unittest.skip("we're not quite there yet")
def test_args(self):
with self.subTest('args'):
def script(a, b=0):
Expand Down
9 changes: 6 additions & 3 deletions Modules/_interpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,11 +972,14 @@ convert_code_arg(PyThreadState *tstate,
PyObject *cause;
PyCodeObject *code = NULL;
if (PyFunction_Check(arg)) {
if (_PyFunction_VerifyStateless(tstate, arg) < 0) {
// For now we allow globals, so we can't use
// _PyFunction_VerifyStateless().
PyObject *codeobj = PyFunction_GetCode(arg);
if (_PyCode_VerifyStateless(
tstate, (PyCodeObject *)codeobj, NULL, NULL, NULL) < 0) {
goto chained;
}
code = (PyCodeObject *)PyFunction_GetCode(arg);
Py_INCREF(code);
code = (PyCodeObject *)Py_NewRef(codeobj);
}
else if (PyCode_Check(arg)) {
if (_PyCode_VerifyStateless(
Expand Down
Loading
0