summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-01-06 14:55:56 (GMT)
committerGitHub <noreply@github.com>2023-01-06 14:55:56 (GMT)
commit15c44789bb125b93e96815a336ec73423c47508e (patch)
treed8962fa33de6dc997e397a8856eb70d72a542ba7 /Python
parent78068126a1f2172ff61a0871ba43d8530bc73905 (diff)
downloadcpython-15c44789bb125b93e96815a336ec73423c47508e.zip
cpython-15c44789bb125b93e96815a336ec73423c47508e.tar.gz
cpython-15c44789bb125b93e96815a336ec73423c47508e.tar.bz2
gh-100758: Refactor initialisation of frame headers into a single function (_PyFrame_Initialize) (GH-100759)
Diffstat (limited to 'Python')
-rw-r--r--Python/bytecodes.c25
-rw-r--r--Python/ceval.c5
-rw-r--r--Python/generated_cases.c.h25
3 files changed, 11 insertions, 44 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 6e20ba6..251ee56 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -448,13 +448,10 @@ dummy_func(
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), BINARY_SUBSCR);
STAT_INC(BINARY_SUBSCR, hit);
Py_INCREF(getitem);
- _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, getitem);
+ _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, getitem, 2);
STACK_SHRINK(2);
new_frame->localsplus[0] = container;
new_frame->localsplus[1] = sub;
- for (int i = 2; i < code->co_nlocalsplus; i++) {
- new_frame->localsplus[i] = NULL;
- }
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
DISPATCH_INLINED(new_frame);
}
@@ -1714,14 +1711,11 @@ dummy_func(
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), LOAD_ATTR);
STAT_INC(LOAD_ATTR, hit);
Py_INCREF(fget);
- _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f);
+ _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 1);
SET_TOP(NULL);
int shrink_stack = !(oparg & 1);
STACK_SHRINK(shrink_stack);
new_frame->localsplus[0] = owner;
- for (int i = 1; i < code->co_nlocalsplus; i++) {
- new_frame->localsplus[i] = NULL;
- }
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
DISPATCH_INLINED(new_frame);
}
@@ -1749,15 +1743,12 @@ dummy_func(
PyObject *name = GETITEM(names, oparg >> 1);
Py_INCREF(f);
- _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f);
+ _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 2);
SET_TOP(NULL);
int shrink_stack = !(oparg & 1);
STACK_SHRINK(shrink_stack);
new_frame->localsplus[0] = owner;
new_frame->localsplus[1] = Py_NewRef(name);
- for (int i = 2; i < code->co_nlocalsplus; i++) {
- new_frame->localsplus[i] = NULL;
- }
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
DISPATCH_INLINED(new_frame);
}
@@ -2672,14 +2663,11 @@ dummy_func(
DEOPT_IF(code->co_argcount != argcount, CALL);
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
STAT_INC(CALL, hit);
- _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
+ _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func, argcount);
STACK_SHRINK(argcount);
for (int i = 0; i < argcount; i++) {
new_frame->localsplus[i] = stack_pointer[i];
}
- for (int i = argcount; i < code->co_nlocalsplus; i++) {
- new_frame->localsplus[i] = NULL;
- }
STACK_SHRINK(2-is_meth);
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
DISPATCH_INLINED(new_frame);
@@ -2702,7 +2690,7 @@ dummy_func(
DEOPT_IF(argcount < minargs, CALL);
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
STAT_INC(CALL, hit);
- _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
+ _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func, code->co_argcount);
STACK_SHRINK(argcount);
for (int i = 0; i < argcount; i++) {
new_frame->localsplus[i] = stack_pointer[i];
@@ -2712,9 +2700,6 @@ dummy_func(
i - minargs);
new_frame->localsplus[i] = Py_NewRef(def);
}
- for (int i = code->co_argcount; i < code->co_nlocalsplus; i++) {
- new_frame->localsplus[i] = NULL;
- }
STACK_SHRINK(2-is_meth);
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
DISPATCH_INLINED(new_frame);
diff --git a/Python/ceval.c b/Python/ceval.c
index 149b88e..56cd9ad 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1974,11 +1974,8 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func,
if (frame == NULL) {
goto fail;
}
- _PyFrame_InitializeSpecials(frame, func, locals, code);
+ _PyFrame_Initialize(frame, func, locals, code, 0);
PyObject **localsarray = &frame->localsplus[0];
- for (int i = 0; i < code->co_nlocalsplus; i++) {
- localsarray[i] = NULL;
- }
if (initialize_locals(tstate, func, localsarray, args, argcount, kwnames)) {
assert(frame->owner != FRAME_OWNED_BY_GENERATOR);
_PyEvalFrameClearAndPop(tstate, frame);
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index beb5bec..218bc62 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -564,13 +564,10 @@
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), BINARY_SUBSCR);
STAT_INC(BINARY_SUBSCR, hit);
Py_INCREF(getitem);
- _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, getitem);
+ _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, getitem, 2);
STACK_SHRINK(2);
new_frame->localsplus[0] = container;
new_frame->localsplus[1] = sub;
- for (int i = 2; i < code->co_nlocalsplus; i++) {
- new_frame->localsplus[i] = NULL;
- }
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
DISPATCH_INLINED(new_frame);
}
@@ -1941,14 +1938,11 @@
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), LOAD_ATTR);
STAT_INC(LOAD_ATTR, hit);
Py_INCREF(fget);
- _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f);
+ _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 1);
SET_TOP(NULL);
int shrink_stack = !(oparg & 1);
STACK_SHRINK(shrink_stack);
new_frame->localsplus[0] = owner;
- for (int i = 1; i < code->co_nlocalsplus; i++) {
- new_frame->localsplus[i] = NULL;
- }
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
DISPATCH_INLINED(new_frame);
}
@@ -1975,15 +1969,12 @@
PyObject *name = GETITEM(names, oparg >> 1);
Py_INCREF(f);
- _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f);
+ _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, f, 2);
SET_TOP(NULL);
int shrink_stack = !(oparg & 1);
STACK_SHRINK(shrink_stack);
new_frame->localsplus[0] = owner;
new_frame->localsplus[1] = Py_NewRef(name);
- for (int i = 2; i < code->co_nlocalsplus; i++) {
- new_frame->localsplus[i] = NULL;
- }
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
DISPATCH_INLINED(new_frame);
}
@@ -3011,14 +3002,11 @@
DEOPT_IF(code->co_argcount != argcount, CALL);
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
STAT_INC(CALL, hit);
- _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
+ _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func, argcount);
STACK_SHRINK(argcount);
for (int i = 0; i < argcount; i++) {
new_frame->localsplus[i] = stack_pointer[i];
}
- for (int i = argcount; i < code->co_nlocalsplus; i++) {
- new_frame->localsplus[i] = NULL;
- }
STACK_SHRINK(2-is_meth);
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
DISPATCH_INLINED(new_frame);
@@ -3040,7 +3028,7 @@
DEOPT_IF(argcount < minargs, CALL);
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
STAT_INC(CALL, hit);
- _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func);
+ _PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func, code->co_argcount);
STACK_SHRINK(argcount);
for (int i = 0; i < argcount; i++) {
new_frame->localsplus[i] = stack_pointer[i];
@@ -3050,9 +3038,6 @@
i - minargs);
new_frame->localsplus[i] = Py_NewRef(def);
}
- for (int i = code->co_argcount; i < code->co_nlocalsplus; i++) {
- new_frame->localsplus[i] = NULL;
- }
STACK_SHRINK(2-is_meth);
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
DISPATCH_INLINED(new_frame);