mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-112383: teach dis how to interpret ENTER_EXECUTOR (#117171)
This commit is contained in:
parent
6c83352bfe
commit
d610d821fd
7 changed files with 120 additions and 50 deletions
|
|
@ -347,6 +347,28 @@ _opcode_get_intrinsic2_descs_impl(PyObject *module)
|
|||
return list;
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
|
||||
_opcode.get_executor
|
||||
|
||||
code: object
|
||||
offset: int
|
||||
|
||||
Return the executor object at offset in code if exists, None otherwise.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_opcode_get_executor_impl(PyObject *module, PyObject *code, int offset)
|
||||
/*[clinic end generated code: output=c035c7a47b16648f input=85eff93ea7aac282]*/
|
||||
{
|
||||
if (!PyCode_Check(code)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"expected a code object, not '%.100s'",
|
||||
Py_TYPE(code)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
return (PyObject *)PyUnstable_GetExecutor((PyCodeObject *)code, offset);
|
||||
}
|
||||
|
||||
static PyMethodDef
|
||||
opcode_functions[] = {
|
||||
|
|
@ -363,6 +385,7 @@ opcode_functions[] = {
|
|||
_OPCODE_GET_NB_OPS_METHODDEF
|
||||
_OPCODE_GET_INTRINSIC1_DESCS_METHODDEF
|
||||
_OPCODE_GET_INTRINSIC2_DESCS_METHODDEF
|
||||
_OPCODE_GET_EXECUTOR_METHODDEF
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -991,26 +991,6 @@ get_optimizer(PyObject *self, PyObject *Py_UNUSED(ignored))
|
|||
return opt;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
get_executor(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
|
||||
{
|
||||
|
||||
if (!_PyArg_CheckPositional("get_executor", nargs, 2, 2)) {
|
||||
return NULL;
|
||||
}
|
||||
PyObject *code = args[0];
|
||||
PyObject *offset = args[1];
|
||||
long ioffset = PyLong_AsLong(offset);
|
||||
if (ioffset == -1 && PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
if (!PyCode_Check(code)) {
|
||||
PyErr_SetString(PyExc_TypeError, "first argument must be a code object");
|
||||
return NULL;
|
||||
}
|
||||
return (PyObject *)PyUnstable_GetExecutor((PyCodeObject *)code, ioffset);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
add_executor_dependency(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
|
@ -1836,7 +1816,6 @@ static PyMethodDef module_functions[] = {
|
|||
{"iframe_getlasti", iframe_getlasti, METH_O, NULL},
|
||||
{"get_optimizer", get_optimizer, METH_NOARGS, NULL},
|
||||
{"set_optimizer", set_optimizer, METH_O, NULL},
|
||||
{"get_executor", _PyCFunction_CAST(get_executor), METH_FASTCALL, NULL},
|
||||
{"new_counter_optimizer", new_counter_optimizer, METH_NOARGS, NULL},
|
||||
{"new_uop_optimizer", new_uop_optimizer, METH_NOARGS, NULL},
|
||||
{"add_executor_dependency", add_executor_dependency, METH_VARARGS, NULL},
|
||||
|
|
|
|||
62
Modules/clinic/_opcode.c.h
generated
62
Modules/clinic/_opcode.c.h
generated
|
|
@ -668,4 +668,64 @@ _opcode_get_intrinsic2_descs(PyObject *module, PyObject *Py_UNUSED(ignored))
|
|||
{
|
||||
return _opcode_get_intrinsic2_descs_impl(module);
|
||||
}
|
||||
/*[clinic end generated code: output=a1052bb1deffb7f2 input=a9049054013a1b77]*/
|
||||
|
||||
PyDoc_STRVAR(_opcode_get_executor__doc__,
|
||||
"get_executor($module, /, code, offset)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return the executor object at offset in code if exists, None otherwise.");
|
||||
|
||||
#define _OPCODE_GET_EXECUTOR_METHODDEF \
|
||||
{"get_executor", _PyCFunction_CAST(_opcode_get_executor), METH_FASTCALL|METH_KEYWORDS, _opcode_get_executor__doc__},
|
||||
|
||||
static PyObject *
|
||||
_opcode_get_executor_impl(PyObject *module, PyObject *code, int offset);
|
||||
|
||||
static PyObject *
|
||||
_opcode_get_executor(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
|
||||
#define NUM_KEYWORDS 2
|
||||
static struct {
|
||||
PyGC_Head _this_is_not_used;
|
||||
PyObject_VAR_HEAD
|
||||
PyObject *ob_item[NUM_KEYWORDS];
|
||||
} _kwtuple = {
|
||||
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
||||
.ob_item = { &_Py_ID(code), &_Py_ID(offset), },
|
||||
};
|
||||
#undef NUM_KEYWORDS
|
||||
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
||||
|
||||
#else // !Py_BUILD_CORE
|
||||
# define KWTUPLE NULL
|
||||
#endif // !Py_BUILD_CORE
|
||||
|
||||
static const char * const _keywords[] = {"code", "offset", NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "get_executor",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[2];
|
||||
PyObject *code;
|
||||
int offset;
|
||||
|
||||
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
|
||||
if (!args) {
|
||||
goto exit;
|
||||
}
|
||||
code = args[0];
|
||||
offset = PyLong_AsInt(args[1]);
|
||||
if (offset == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
return_value = _opcode_get_executor_impl(module, code, offset);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=2dbb31b041b49c8f input=a9049054013a1b77]*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue