mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-132775: Cleanup Related to crossinterp.c Before Further Changes (gh-132974)
This change consists of adding tests and moving code around, with some renaming thrown in.
This commit is contained in:
parent
b739ec5ab7
commit
6f04325992
10 changed files with 838 additions and 348 deletions
|
@ -1115,67 +1115,6 @@ The code/function must not take any arguments or be a closure\n\
|
|||
If a function is provided, its code object is used and all its state\n\
|
||||
is ignored, including its __globals__ dict.");
|
||||
|
||||
static PyObject *
|
||||
interp_call(PyObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
static char *kwlist[] = {"id", "callable", "args", "kwargs",
|
||||
"restrict", NULL};
|
||||
PyObject *id, *callable;
|
||||
PyObject *args_obj = NULL;
|
||||
PyObject *kwargs_obj = NULL;
|
||||
int restricted = 0;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds,
|
||||
"OO|OO$p:" MODULE_NAME_STR ".call", kwlist,
|
||||
&id, &callable, &args_obj, &kwargs_obj,
|
||||
&restricted))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int reqready = 1;
|
||||
PyInterpreterState *interp = \
|
||||
resolve_interp(id, restricted, reqready, "make a call in");
|
||||
if (interp == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (args_obj != NULL) {
|
||||
PyErr_SetString(PyExc_ValueError, "got unexpected args");
|
||||
return NULL;
|
||||
}
|
||||
if (kwargs_obj != NULL) {
|
||||
PyErr_SetString(PyExc_ValueError, "got unexpected kwargs");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *code = (PyObject *)convert_code_arg(callable, MODULE_NAME_STR ".call",
|
||||
"argument 2", "a function");
|
||||
if (code == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *excinfo = NULL;
|
||||
int res = _interp_exec(self, interp, code, NULL, &excinfo);
|
||||
Py_DECREF(code);
|
||||
if (res < 0) {
|
||||
assert((excinfo == NULL) != (PyErr_Occurred() == NULL));
|
||||
return excinfo;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(call_doc,
|
||||
"call(id, callable, args=None, kwargs=None, *, restrict=False)\n\
|
||||
\n\
|
||||
Call the provided object in the identified interpreter.\n\
|
||||
Pass the given args and kwargs, if possible.\n\
|
||||
\n\
|
||||
\"callable\" may be a plain function with no free vars that takes\n\
|
||||
no arguments.\n\
|
||||
\n\
|
||||
The function's code object is used and all its state\n\
|
||||
is ignored, including its __globals__ dict.");
|
||||
|
||||
static PyObject *
|
||||
interp_run_string(PyObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
|
@ -1267,6 +1206,67 @@ are not supported. Methods and other callables are not supported either.\n\
|
|||
\n\
|
||||
(See " MODULE_NAME_STR ".exec().");
|
||||
|
||||
static PyObject *
|
||||
interp_call(PyObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
static char *kwlist[] = {"id", "callable", "args", "kwargs",
|
||||
"restrict", NULL};
|
||||
PyObject *id, *callable;
|
||||
PyObject *args_obj = NULL;
|
||||
PyObject *kwargs_obj = NULL;
|
||||
int restricted = 0;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds,
|
||||
"OO|OO$p:" MODULE_NAME_STR ".call", kwlist,
|
||||
&id, &callable, &args_obj, &kwargs_obj,
|
||||
&restricted))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int reqready = 1;
|
||||
PyInterpreterState *interp = \
|
||||
resolve_interp(id, restricted, reqready, "make a call in");
|
||||
if (interp == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (args_obj != NULL) {
|
||||
PyErr_SetString(PyExc_ValueError, "got unexpected args");
|
||||
return NULL;
|
||||
}
|
||||
if (kwargs_obj != NULL) {
|
||||
PyErr_SetString(PyExc_ValueError, "got unexpected kwargs");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *code = (PyObject *)convert_code_arg(callable, MODULE_NAME_STR ".call",
|
||||
"argument 2", "a function");
|
||||
if (code == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *excinfo = NULL;
|
||||
int res = _interp_exec(self, interp, code, NULL, &excinfo);
|
||||
Py_DECREF(code);
|
||||
if (res < 0) {
|
||||
assert((excinfo == NULL) != (PyErr_Occurred() == NULL));
|
||||
return excinfo;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(call_doc,
|
||||
"call(id, callable, args=None, kwargs=None, *, restrict=False)\n\
|
||||
\n\
|
||||
Call the provided object in the identified interpreter.\n\
|
||||
Pass the given args and kwargs, if possible.\n\
|
||||
\n\
|
||||
\"callable\" may be a plain function with no free vars that takes\n\
|
||||
no arguments.\n\
|
||||
\n\
|
||||
The function's code object is used and all its state\n\
|
||||
is ignored, including its __globals__ dict.");
|
||||
|
||||
|
||||
static PyObject *
|
||||
object_is_shareable(PyObject *self, PyObject *args, PyObject *kwds)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue