8000 MAKE_FUNCTION · python/cpython@6a05302 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a05302

Browse files
committed
MAKE_FUNCTION
1 parent 04e06e2 commit 6a05302

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
@@ -2972,36 +2972,39 @@ dummy_func(
29722972
CHECK_EVAL_BREAKER();
29732973
}
29742974

2975-
// error: MAKE_FUNCTION has irregular stack effect
2976-
inst(MAKE_FUNCTION) {
2977-
PyObject *codeobj = POP();
2978-
PyFunctionObject *func = (PyFunctionObject *)
2975+
inst(MAKE_FUNCTION, (defaults if (oparg & 0x01),
2976+
kwdefaults if (oparg & 0x02),
2977+
annotations if (oparg & 0x04),
2978+
closure if (oparg & 0x08),
2979+
codeobj -- func)) {
2980+
2981+
PyFunctionObject *func_obj = (PyFunctionObject *)
29792982
PyFunction_New(codeobj, GLOBALS());
29802983

29812984
Py_DECREF(codeobj);
2982-
if (func == NULL) {
2985+
if (func_obj == NULL) {
29832986
goto error;
29842987
}
29852988

29862989
if (oparg & 0x08) {
2987-
assert(PyTuple_CheckExact(TOP()));
2988-
func->func_closure = POP();
2990+
assert(PyTuple_CheckExact(closure));
2991+
func_obj->func_closure = closure;
29892992
}
29902993
if (oparg & 0x04) {
2991-
assert(PyTuple_CheckExact(TOP()));
2992-
func->func_annotations = POP();
2994+
assert(PyTuple_CheckExact(annotations));
2995+
func_obj->func_annotations = annotations;
29932996
}
29942997
if (oparg & 0x02) {
2995-
assert(PyDict_CheckExact(TOP()));
2996-
func->func_kwdefaults = POP();
2998+
assert(PyDict_CheckExact(kwdefaults));
2999+
func_obj->func_kwdefaults = kwdefaults;
29973000
}
29983001
if (oparg & 0x01) {
2999-
assert(PyTuple_CheckExact(TOP()));
3000-
func->func_defaults = POP();
3002+
assert(PyTuple_CheckExact(defaults));
3003+
func_obj->func_defaults = defaults;
30013004
}
30023005

3003-
func->func_version = ((PyCodeObject *)codeobj)->co_version;
3004-
PUSH((PyObject *)func);
3006+
func_obj->func_version = ((PyCodeObject *)codeobj)->co_version;
3007+
func = (PyObject *)func_obj;
30053008
}
30063009

30073010
inst(RETURN_GENERATOR, (--)) {

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 0;
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 0;
677677
case BUILD_SLICE:

0 commit comments

Comments
 (0)
0