Skip to content

Commit 4ee84ab

Browse files
committed
Use explicit stacksize in _Py_MakeTrampoline. Allow interpreter to clear previous frame pointer.
1 parent 9f710e6 commit 4ee84ab

File tree

5 files changed

+7
-10
lines changed

5 files changed

+7
-10
lines changed

Include/internal/pycore_code.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ _PyCode_LineNumberFromArray(PyCodeObject *co, int index)
511511
}
512512

513513
extern PyCodeObject *
514-
_Py_MakeTrampoline(const char *code, int codelen, const char *cname);
514+
_Py_MakeTrampoline(const char *code, int codelen, int stacksize, const char *cname);
515515

516516

517517
#ifdef __cplusplus

Objects/codeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,7 +2223,7 @@ _PyStaticCode_InternStrings(PyCodeObject *co)
22232223
}
22242224

22252225
PyCodeObject *
2226-
_Py_MakeTrampoline(const char *code, int codelen, const char *cname)
2226+
_Py_MakeTrampoline(const char *code, int codelen, int stacksize, const char *cname)
22272227
{
22282228
PyObject *name = NULL;
22292229
PyObject *co_code = NULL;
@@ -2263,7 +2263,7 @@ _Py_MakeTrampoline(const char *code, int codelen, const char *cname)
22632263
.posonlyargcount = 0,
22642264
.kwonlyargcount = 0,
22652265

2266-
.stacksize = 2,
2266+
.stacksize = stacksize,
22672267

22682268
.exceptiontable = (PyObject *)&_Py_SINGLETON(bytes_empty),
22692269
};

Objects/genobject.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult,
208208
Py_INCREF(result);
209209
_PyFrame_StackPush(frame, result);
210210

211-
_PyInterpreterFrame *prev = tstate->cframe->current_frame;
212-
frame->previous = tstate->cframe->current_frame;
213-
214211
gen->gi_exc_state.previous_item = tstate->exc_info;
215212
tstate->exc_info = &gen->gi_exc_state;
216213

@@ -228,11 +225,10 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult,
228225
tstate->exc_info = gen->gi_exc_state.previous_item;
229226
gen->gi_exc_state.previous_item = NULL;
230227

231-
assert(tstate->cframe->current_frame == prev);
232228
/* Don't keep the reference to previous any longer than necessary. It
233229
* may keep a chain of frames alive or it could create a reference
234230
* cycle. */
235-
frame->previous = NULL;
231+
assert(frame->previous == NULL);
236232

237233
/* If the generator just returned (as opposed to yielding), signal
238234
* that the generator is exhausted. */

Python/ceval.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10381038
py_frame.frame_obj = NULL;
10391039
py_frame.f_code = tstate->interp->interpreter_trampoline;
10401040
assert(tstate->interp->interpreter_trampoline != NULL);
1041-
py_frame.prev_instr = _PyCode_CODE(tstate->interp->interpreter_trampoline);
1041+
_Py_CODEUNIT *code = _PyCode_CODE(tstate->interp->interpreter_trampoline);
1042+
py_frame.prev_instr = code;
10421043
py_frame.stacktop = 0;
10431044
py_frame.owner = FRAME_OWNED_BY_CSTACK;
10441045
py_frame.yield_offset = 0;

Python/pylifecycle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ pycore_init_builtins(PyThreadState *tstate)
797797
assert(object__getattribute__);
798798
interp->callable_cache.object__getattribute__ = object__getattribute__;
799799
interp->interpreter_trampoline = _Py_MakeTrampoline(
800-
INTERPRETER_TRAMPOLINE_CODE, sizeof(INTERPRETER_TRAMPOLINE_CODE), "<interpreter trampoline>");
800+
INTERPRETER_TRAMPOLINE_CODE, sizeof(INTERPRETER_TRAMPOLINE_CODE), 1, "<interpreter trampoline>");
801801
if (interp->interpreter_trampoline == NULL) {
802802
return _PyStatus_ERR("failed to create interpreter trampoline.");
803803
}

0 commit comments

Comments
 (0)