Skip to content

Commit 15b0931

Browse files
committed
MAKE_FUNCTION
1 parent 0675b8f commit 15b0931

File tree

3 files changed

+41
-30
lines changed

3 files changed

+41
-30
lines changed

Python/bytecodes.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2978,36 +2978,39 @@ dummy_func(
29782978
CHECK_EVAL_BREAKER();
29792979
}
29802980

2981-
// error: MAKE_FUNCTION has irregular stack effect
2982-
inst(MAKE_FUNCTION) {
2983-
PyObject *codeobj = POP();
2984-
PyFunctionObject *func = (PyFunctionObject *)
2981+
inst(MAKE_FUNCTION, (defaults if (oparg & 0x01),
2982+
kwdefaults if (oparg & 0x02),
2983+
annotations if (oparg & 0x04),
2984+
closure if (oparg & 0x08),
2985+
codeobj -- func)) {
2986+
2987+
PyFunctionObject *func_obj = (PyFunctionObject *)
29852988
PyFunction_New(codeobj, GLOBALS());
29862989

29872990
Py_DECREF(codeobj);
2988-
if (func == NULL) {
2991+
if (func_obj == NULL) {
29892992
goto error;
29902993
}
29912994

29922995
if (oparg & 0x08) {
2993-
assert(PyTuple_CheckExact(TOP()));
2994-
func->func_closure = POP();
2996+
assert(PyTuple_CheckExact(closure));
2997+
func_obj->func_closure = closure;
29952998
}
29962999
if (oparg & 0x04) {
2997-
assert(PyTuple_CheckExact(TOP()));
2998-
func->func_annotations = POP();
3000+
assert(PyTuple_CheckExact(annotations));
3001+
func_obj->func_annotations = annotations;
29993002
}
30003003
if (oparg & 0x02) {
3001-
assert(PyDict_CheckExact(TOP()));
3002-
func->func_kwdefaults = POP();
3004+
assert(PyDict_CheckExact(kwdefaults));
3005+
func_obj->func_kwdefaults = kwdefaults;
30033006
}
30043007
if (oparg & 0x01) {
3005-
assert(PyTuple_CheckExact(TOP()));
3006-
func->func_defaults = POP();
3008+
assert(PyTuple_CheckExact(defaults));
3009+
func_obj->func_defaults = defaults;
30073010
}
30083011

3009-
func->func_version = ((PyCodeObject *)codeobj)->co_version;
3010-
PUSH((PyObject *)func);
3012+
func_obj->func_version = ((PyCodeObject *)codeobj)->co_version;
3013+
func = (PyObject *)func_obj;
30113014
}
30123015

30133016
// stack effect: ( -- )

Python/generated_cases.c.h

Lines changed: 21 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/opcode_metadata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
325325
case CALL_FUNCTION_EX:
326326
return -1;
327327
case MAKE_FUNCTION:
328-
return -1;
328+
return ((oparg & 0x01) ? 1 : 0) + ((oparg & 0x02) ? 1 : 0) + ((oparg & 0x04) ? 1 : 0) + ((oparg & 0x08) ? 1 : 0) + 1;
329329
case RETURN_GENERATOR:
330330
return -1;
331331
case BUILD_SLICE:
@@ -671,7 +671,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
671671
case CALL_FUNCTION_EX:
672672
return -1;
673673
case MAKE_FUNCTION:
674-
return -1;
674+
return 1;
675675
case RETURN_GENERATOR:
676676
return -1;
677677
case BUILD_SLICE:

0 commit comments

Comments
 (0)