mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
bpo-32455: Add jump parameter to dis.stack_effect(). (GH-6610)
Add C API function PyCompile_OpcodeStackEffectWithJump().
This commit is contained in:
parent
b042cf10c6
commit
7bdf28265a
8 changed files with 99 additions and 26 deletions
|
|
@ -15,16 +15,20 @@ _opcode.stack_effect -> int
|
|||
opcode: int
|
||||
oparg: object = None
|
||||
/
|
||||
*
|
||||
jump: object = None
|
||||
|
||||
Compute the stack effect of the opcode.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static int
|
||||
_opcode_stack_effect_impl(PyObject *module, int opcode, PyObject *oparg)
|
||||
/*[clinic end generated code: output=ad39467fa3ad22ce input=2d0a9ee53c0418f5]*/
|
||||
_opcode_stack_effect_impl(PyObject *module, int opcode, PyObject *oparg,
|
||||
PyObject *jump)
|
||||
/*[clinic end generated code: output=64a18f2ead954dbb input=461c9d4a44851898]*/
|
||||
{
|
||||
int effect;
|
||||
int oparg_int = 0;
|
||||
int jump_int;
|
||||
if (HAS_ARG(opcode)) {
|
||||
if (oparg == Py_None) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
|
|
@ -40,7 +44,21 @@ _opcode_stack_effect_impl(PyObject *module, int opcode, PyObject *oparg)
|
|||
"stack_effect: opcode does not permit oparg but oparg was specified");
|
||||
return -1;
|
||||
}
|
||||
effect = PyCompile_OpcodeStackEffect(opcode, oparg_int);
|
||||
if (jump == Py_None) {
|
||||
jump_int = -1;
|
||||
}
|
||||
else if (jump == Py_True) {
|
||||
jump_int = 1;
|
||||
}
|
||||
else if (jump == Py_False) {
|
||||
jump_int = 0;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"stack_effect: jump must be False, True or None");
|
||||
return -1;
|
||||
}
|
||||
effect = PyCompile_OpcodeStackEffectWithJump(opcode, oparg_int, jump_int);
|
||||
if (effect == PY_INVALID_STACK_EFFECT) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"invalid opcode or oparg");
|
||||
|
|
|
|||
20
Modules/clinic/_opcode.c.h
generated
20
Modules/clinic/_opcode.c.h
generated
|
|
@ -3,30 +3,34 @@ preserve
|
|||
[clinic start generated code]*/
|
||||
|
||||
PyDoc_STRVAR(_opcode_stack_effect__doc__,
|
||||
"stack_effect($module, opcode, oparg=None, /)\n"
|
||||
"stack_effect($module, opcode, oparg=None, /, *, jump=None)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Compute the stack effect of the opcode.");
|
||||
|
||||
#define _OPCODE_STACK_EFFECT_METHODDEF \
|
||||
{"stack_effect", (PyCFunction)_opcode_stack_effect, METH_FASTCALL, _opcode_stack_effect__doc__},
|
||||
{"stack_effect", (PyCFunction)_opcode_stack_effect, METH_FASTCALL|METH_KEYWORDS, _opcode_stack_effect__doc__},
|
||||
|
||||
static int
|
||||
_opcode_stack_effect_impl(PyObject *module, int opcode, PyObject *oparg);
|
||||
_opcode_stack_effect_impl(PyObject *module, int opcode, PyObject *oparg,
|
||||
PyObject *jump);
|
||||
|
||||
static PyObject *
|
||||
_opcode_stack_effect(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||
_opcode_stack_effect(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
static const char * const _keywords[] = {"", "", "jump", NULL};
|
||||
static _PyArg_Parser _parser = {"i|O$O:stack_effect", _keywords, 0};
|
||||
int opcode;
|
||||
PyObject *oparg = Py_None;
|
||||
PyObject *jump = Py_None;
|
||||
int _return_value;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, "i|O:stack_effect",
|
||||
&opcode, &oparg)) {
|
||||
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
|
||||
&opcode, &oparg, &jump)) {
|
||||
goto exit;
|
||||
}
|
||||
_return_value = _opcode_stack_effect_impl(module, opcode, oparg);
|
||||
_return_value = _opcode_stack_effect_impl(module, opcode, oparg, jump);
|
||||
if ((_return_value == -1) && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
|
|
@ -35,4 +39,4 @@ _opcode_stack_effect(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=577a91c9aa5559a9 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=bbf6c4cfc91edc29 input=a9049054013a1b77]*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue