mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Two more patches by Tony Lownds (SF# 1607548).
(1) Combines the code paths for MAKE_FUNCTION and MAKE_CLOSURE. Fixes a crash where functions with closures and either annotations or keyword-only arguments result in MAKE_CLOSURE, but only MAKE_FUNCTION has the code to handle annotations or keyword-only arguments. Includes enough tests to trigger the bug. (2) Change peepholer to not bail in the presence of EXTENDED_ARG + MAKE_FUNCTION. Enforce the natural 16-bit limit of annotations in compile.c. Also update Misc/NEWS with the "input = raw_input" change.
This commit is contained in:
parent
f74225d63b
commit
0240b92a6c
7 changed files with 68 additions and 38 deletions
|
@ -2236,6 +2236,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
|||
break;
|
||||
}
|
||||
|
||||
case MAKE_CLOSURE:
|
||||
case MAKE_FUNCTION:
|
||||
{
|
||||
int posdefaults = oparg & 0xff;
|
||||
|
@ -2245,6 +2246,12 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
|||
v = POP(); /* code object */
|
||||
x = PyFunction_New(v, f->f_globals);
|
||||
Py_DECREF(v);
|
||||
|
||||
if (x != NULL && opcode == MAKE_CLOSURE) {
|
||||
v = POP();
|
||||
err = PyFunction_SetClosure(x, v);
|
||||
Py_DECREF(v);
|
||||
}
|
||||
|
||||
if (x != NULL && num_annotations > 0) {
|
||||
Py_ssize_t name_ix;
|
||||
|
@ -2308,34 +2315,6 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
|||
break;
|
||||
}
|
||||
|
||||
case MAKE_CLOSURE:
|
||||
{
|
||||
v = POP(); /* code object */
|
||||
x = PyFunction_New(v, f->f_globals);
|
||||
Py_DECREF(v);
|
||||
if (x != NULL) {
|
||||
v = POP();
|
||||
err = PyFunction_SetClosure(x, v);
|
||||
Py_DECREF(v);
|
||||
}
|
||||
if (x != NULL && oparg > 0) {
|
||||
v = PyTuple_New(oparg);
|
||||
if (v == NULL) {
|
||||
Py_DECREF(x);
|
||||
x = NULL;
|
||||
break;
|
||||
}
|
||||
while (--oparg >= 0) {
|
||||
w = POP();
|
||||
PyTuple_SET_ITEM(v, oparg, w);
|
||||
}
|
||||
err = PyFunction_SetDefaults(x, v);
|
||||
Py_DECREF(v);
|
||||
}
|
||||
PUSH(x);
|
||||
break;
|
||||
}
|
||||
|
||||
case BUILD_SLICE:
|
||||
if (oparg == 3)
|
||||
w = POP();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue