Skip to content

Commit 963896a

Browse files
committed
Fix tier2 optimizer
1 parent db12634 commit 963896a

5 files changed

Lines changed: 10 additions & 4 deletions

File tree

Include/internal/pycore_frame.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ static inline PyCodeObject *_PyFrame_GetCode(_PyInterpreterFrame *f) {
8484
return (PyCodeObject *)executable;
8585
}
8686

87+
static inline PyFunctionObject *_PyFrame_GetFunction(_PyInterpreterFrame *f) {
88+
PyObject *func = PyStackRef_AsPyObjectBorrow(f->f_funcobj);
89+
assert(PyFunction_Check(func));
90+
return (PyFunctionObject *)func;
91+
}
92+
8793
static inline _PyStackRef *_PyFrame_Stackbase(_PyInterpreterFrame *f) {
8894
return (f->localsplus + _PyFrame_GetCode(f)->co_nlocalsplus);
8995
}

Modules/_testinternalcapi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ static PyObject *
682682
record_eval(PyThreadState *tstate, struct _PyInterpreterFrame *f, int exc)
683683
{
684684
if (PyStackRef_FunctionCheck(f->f_funcobj)) {
685-
PyFunctionObject *func = (PyFunctionObject *)PyStackRef_AsPyObjectBorrow(f->f_funcobj);
685+
PyFunctionObject *func = _PyFrame_GetFunction(f);
686686
PyObject *module = _get_current_module();
687687
assert(module != NULL);
688688
module_state *state = get_module_state(module);

Objects/frameobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,7 @@ frame_init_get_vars(_PyInterpreterFrame *frame)
18681868
}
18691869

18701870
/* Free vars have not been initialized -- Do that */
1871-
PyFunctionObject *func = (PyFunctionObject *)PyStackRef_AsPyObjectBorrow(frame->f_funcobj);
1871+
PyFunctionObject *func = _PyFrame_GetFunction(frame);
18721872
PyObject *closure = func->func_closure;
18731873
int offset = PyUnstable_Code_GetFirstFree(co);
18741874
for (int i = 0; i < co->co_nfreevars; ++i) {

Python/optimizer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ translate_bytecode_to_trace(
533533
{
534534
bool first = true;
535535
PyCodeObject *code = _PyFrame_GetCode(frame);
536-
PyFunctionObject *func = (PyFunctionObject *)frame->f_funcobj;
536+
PyFunctionObject *func = _PyFrame_GetFunction(frame);
537537
assert(PyFunction_Check(func));
538538
PyCodeObject *initial_code = code;
539539
_Py_BloomFilter_Add(dependencies, initial_code);

Python/optimizer_analysis.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
145145
return 1;
146146
}
147147
PyObject *globals = frame->f_globals;
148-
PyFunctionObject *function = (PyFunctionObject *)frame->f_funcobj;
148+
PyFunctionObject *function = _PyFrame_GetFunction(frame);
149149
assert(PyFunction_Check(function));
150150
assert(function->func_builtins == builtins);
151151
assert(function->func_globals == globals);

0 commit comments

Comments
 (0)