GH-105678: Split MAKE_FUNCTION into MAKE_FUNCTION and SET_FUNCTION_ATTRIBUTE (GH-105680)

This commit is contained in:
Mark Shannon 2023-06-13 09:51:05 +01:00 committed by GitHub
parent 217589d4f3
commit 09ffa69e2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 480 additions and 430 deletions

View file

@ -83,15 +83,14 @@ dummy_func(
// Dummy labels.
pop_1_error:
// Dummy locals.
PyObject *annotations;
PyObject *dummy;
PyObject *attr;
PyObject *attrs;
PyObject *bottom;
PyObject *callable;
PyObject *callargs;
PyObject *closure;
PyObject *codeobj;
PyObject *cond;
PyObject *defaults;
PyObject *descr;
_PyInterpreterFrame entry_frame;
PyObject *exc;
@ -3297,11 +3296,7 @@ dummy_func(
CHECK_EVAL_BREAKER();
}
inst(MAKE_FUNCTION, (defaults if (oparg & MAKE_FUNCTION_DEFAULTS),
kwdefaults if (oparg & MAKE_FUNCTION_KWDEFAULTS),
annotations if (oparg & MAKE_FUNCTION_ANNOTATIONS),
closure if (oparg & MAKE_FUNCTION_CLOSURE),
codeobj -- func)) {
inst(MAKE_FUNCTION, (codeobj -- func)) {
PyFunctionObject *func_obj = (PyFunctionObject *)
PyFunction_New(codeobj, GLOBALS());
@ -3311,27 +3306,37 @@ dummy_func(
goto error;
}
if (oparg & MAKE_FUNCTION_CLOSURE) {
assert(PyTuple_CheckExact(closure));
func_obj->func_closure = closure;
}
if (oparg & MAKE_FUNCTION_ANNOTATIONS) {
assert(PyTuple_CheckExact(annotations));
func_obj->func_annotations = annotations;
}
if (oparg & MAKE_FUNCTION_KWDEFAULTS) {
assert(PyDict_CheckExact(kwdefaults));
func_obj->func_kwdefaults = kwdefaults;
}
if (oparg & MAKE_FUNCTION_DEFAULTS) {
assert(PyTuple_CheckExact(defaults));
func_obj->func_defaults = defaults;
}
func_obj->func_version = ((PyCodeObject *)codeobj)->co_version;
func = (PyObject *)func_obj;
}
inst(SET_FUNCTION_ATTRIBUTE, (attr, func -- func)) {
assert(PyFunction_Check(func));
PyFunctionObject *func_obj = (PyFunctionObject *)func;
switch(oparg) {
case MAKE_FUNCTION_CLOSURE:
assert(func_obj->func_closure == NULL);
func_obj->func_closure = attr;
break;
case MAKE_FUNCTION_ANNOTATIONS:
assert(func_obj->func_annotations == NULL);
func_obj->func_annotations = attr;
break;
case MAKE_FUNCTION_KWDEFAULTS:
assert(PyDict_CheckExact(attr));
assert(func_obj->func_kwdefaults == NULL);
func_obj->func_kwdefaults = attr;
break;
case MAKE_FUNCTION_DEFAULTS:
assert(PyTuple_CheckExact(attr));
assert(func_obj->func_defaults == NULL);
func_obj->func_defaults = attr;
break;
default:
Py_UNREACHABLE();
}
}
inst(RETURN_GENERATOR, (--)) {
assert(PyFunction_Check(frame->f_funcobj));
PyFunctionObject *func = (PyFunctionObject *)frame->f_funcobj;