mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-132775: Unrevert "Add _PyCode_VerifyStateless()" (gh-133528)
This reverts commit3c73cf5
(gh-133497), which itself reverted the original commitd270bb5
(gh-133221). We reverted the original change due to failing android tests. The checks in _PyCode_CheckNoInternalState() were too strict, so we've relaxed them.
This commit is contained in:
parent
61ac88c06e
commit
27128e4fa8
8 changed files with 359 additions and 38 deletions
|
@ -1165,6 +1165,47 @@ error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
verify_stateless_code(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
PyObject *codearg;
|
||||
PyObject *globalnames = NULL;
|
||||
PyObject *globalsns = NULL;
|
||||
PyObject *builtinsns = NULL;
|
||||
static char *kwlist[] = {"code", "globalnames",
|
||||
"globalsns", "builtinsns", NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
|
||||
"O|O!O!O!:get_code_var_counts", kwlist,
|
||||
&codearg, &PySet_Type, &globalnames,
|
||||
&PyDict_Type, &globalsns, &PyDict_Type, &builtinsns))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (PyFunction_Check(codearg)) {
|
||||
if (globalsns == NULL) {
|
||||
globalsns = PyFunction_GET_GLOBALS(codearg);
|
||||
}
|
||||
if (builtinsns == NULL) {
|
||||
builtinsns = PyFunction_GET_BUILTINS(codearg);
|
||||
}
|
||||
codearg = PyFunction_GET_CODE(codearg);
|
||||
}
|
||||
else if (!PyCode_Check(codearg)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"argument must be a code object or a function");
|
||||
return NULL;
|
||||
}
|
||||
PyCodeObject *code = (PyCodeObject *)codearg;
|
||||
|
||||
if (_PyCode_VerifyStateless(
|
||||
tstate, code, globalnames, globalsns, builtinsns) < 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
#ifdef _Py_TIER2
|
||||
|
||||
static PyObject *
|
||||
|
@ -2292,6 +2333,8 @@ static PyMethodDef module_functions[] = {
|
|||
{"get_co_localskinds", get_co_localskinds, METH_O, NULL},
|
||||
{"get_code_var_counts", _PyCFunction_CAST(get_code_var_counts),
|
||||
METH_VARARGS | METH_KEYWORDS, NULL},
|
||||
{"verify_stateless_code", _PyCFunction_CAST(verify_stateless_code),
|
||||
METH_VARARGS | METH_KEYWORDS, NULL},
|
||||
#ifdef _Py_TIER2
|
||||
{"add_executor_dependency", add_executor_dependency, METH_VARARGS, NULL},
|
||||
{"invalidate_executors", invalidate_executors, METH_O, NULL},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue