From e51946920e2f2a99b44b8aa2b58ed2c0a51d2ddb Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Fri, 17 Jan 2025 20:25:55 +0000 Subject: [PATCH 1/2] gh-128954: Reorder _PyInterpreterFrame fields for reduced memory usage This reduces the size of _PyInterpreterFrame by 8 bytes on 64-bit platforms using the free threading build due to alignment requirements. This allows for slightly more recursive calls into the interpreter (from C), but `test_call.test_super_deep` still crashes. --- Include/internal/pycore_frame.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index 96ae4dd22ecb43..8e870995c4b70e 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -68,11 +68,11 @@ typedef struct _PyInterpreterFrame { PyObject *f_locals; /* Strong reference, may be NULL. Only valid if not on C stack */ PyFrameObject *frame_obj; /* Strong reference, may be NULL. Only valid if not on C stack */ _Py_CODEUNIT *instr_ptr; /* Instruction currently executing (or about to begin) */ + _PyStackRef *stackpointer; #ifdef Py_GIL_DISABLED /* Index of thread-local bytecode containing instr_ptr. */ int32_t tlbc_index; #endif - _PyStackRef *stackpointer; uint16_t return_offset; /* Only relevant during a function call */ char owner; char visited; From c04efb5cc0ee72c0c428dd119afd678714975b97 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Fri, 17 Jan 2025 20:48:21 +0000 Subject: [PATCH 2/2] Fix size test in test_sys --- Lib/test/test_sys.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index d839893d2c657e..39857445a02255 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1621,7 +1621,7 @@ def func(): return sys._getframe() x = func() if support.Py_GIL_DISABLED: - INTERPRETER_FRAME = '10PhcP' + INTERPRETER_FRAME = '9PihcP' else: INTERPRETER_FRAME = '9PhcP' check(x, size('3PiccPP' + INTERPRETER_FRAME + 'P'))