Skip to content

Commit ff5d47e

Browse files
committed
Use smaller structs
1 parent b84bb00 commit ff5d47e

File tree

2 files changed

+72
-56
lines changed

2 files changed

+72
-56
lines changed

Include/internal/pycore_runtime.h

+36-26
Original file line numberDiff line numberDiff line change
@@ -55,40 +55,50 @@ typedef struct _Py_AuditHookEntry {
5555

5656
typedef struct _Py_DebugOffsets {
5757
// Runtime state offset;
58-
off_t rs_finalizing;
59-
off_t rs_interpreters_head;
58+
struct _runtime_state {
59+
off_t finalizing;
60+
off_t interpreters_head;
61+
} runtime_state;
6062

6163
// Interpreter state offset;
62-
off_t is_next;
63-
off_t is_threads_head;
64-
off_t is_gc;
65-
off_t is_imports_modules;
66-
off_t is_sysdict;
67-
off_t is_builtins;
68-
off_t is_ceval_gil;
64+
struct _interpreter_state {
65+
off_t next;
66+
off_t threads_head;
67+
off_t gc;
68+
off_t imports_modules;
69+
off_t sysdict;
70+
off_t builtins;
71+
off_t ceval_gil;
72+
} interpreter_state;
6973

7074
// Thread state offset;
71-
off_t ts_prev;
72-
off_t ts_next;
73-
off_t ts_interp;
74-
off_t ts_cframe;
75-
off_t ts_thread_id;
75+
struct _thread_state{
76+
off_t prev;
77+
off_t next;
78+
off_t interp;
79+
off_t cframe;
80+
off_t thread_id;
81+
} thread_state;
7682

7783
// Frame object offset;
78-
off_t fo_previous;
79-
off_t fo_executable;
80-
off_t fo_prev_instr;
81-
off_t fo_localsplus;
82-
off_t fo_owner;
84+
struct _frame_object {
85+
off_t previous;
86+
off_t executable;
87+
off_t prev_instr;
88+
off_t localsplus;
89+
off_t owner;
90+
} frame_object;
8391

8492
// Code object offset;
85-
off_t co_filename;
86-
off_t co_name;
87-
off_t co_linetable;
88-
off_t co_firstlineno;
89-
off_t co_argcount;
90-
off_t co_localsplusnames;
91-
off_t co_co_code_adaptive;
93+
struct _code_object {
94+
off_t filename;
95+
off_t name;
96+
off_t linetable;
97+
off_t firstlineno;
98+
off_t argcount;
99+
off_t localsplusnames;
100+
off_t co_code_adaptive;
101+
} code_object;
92102
} _Py_DebugOffsets;
93103

94104
/* Full Python runtime state */

Include/internal/pycore_runtime_init.h

+36-30
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,42 @@ extern PyTypeObject _PyExc_MemoryError;
2424
#define _PyRuntimeState_INIT(runtime) \
2525
{ \
2626
.debug_offsets = { \
27-
.rs_finalizing = offsetof(_PyRuntimeState, _finalizing), \
28-
.rs_interpreters_head = offsetof(_PyRuntimeState, interpreters.head), \
29-
\
30-
.is_next = offsetof(PyInterpreterState, next), \
31-
.is_threads_head = offsetof(PyInterpreterState, threads.head), \
32-
.is_gc = offsetof(PyInterpreterState, gc), \
33-
.is_imports_modules = offsetof(PyInterpreterState, imports.modules), \
34-
.is_sysdict = offsetof(PyInterpreterState, sysdict), \
35-
.is_builtins = offsetof(PyInterpreterState, builtins), \
36-
.is_ceval_gil = offsetof(PyInterpreterState, ceval.gil), \
37-
\
38-
.ts_prev = offsetof(PyThreadState, prev), \
39-
.ts_next = offsetof(PyThreadState, next), \
40-
.ts_interp = offsetof(PyThreadState, interp), \
41-
.ts_cframe = offsetof(PyThreadState, cframe), \
42-
.ts_thread_id = offsetof(PyThreadState, thread_id), \
43-
\
44-
.fo_previous = offsetof(_PyInterpreterFrame, previous), \
45-
.fo_executable = offsetof(_PyInterpreterFrame, f_executable), \
46-
.fo_prev_instr = offsetof(_PyInterpreterFrame, prev_instr), \
47-
.fo_localsplus = offsetof(_PyInterpreterFrame, localsplus), \
48-
.fo_owner = offsetof(_PyInterpreterFrame, owner), \
49-
\
50-
.co_filename = offsetof(PyCodeObject, co_filename), \
51-
.co_name = offsetof(PyCodeObject, co_name), \
52-
.co_linetable = offsetof(PyCodeObject, co_linetable), \
53-
.co_firstlineno = offsetof(PyCodeObject, co_firstlineno), \
54-
.co_argcount = offsetof(PyCodeObject, co_argcount), \
55-
.co_localsplusnames = offsetof(PyCodeObject, co_localsplusnames), \
56-
.co_co_code_adaptive = offsetof(PyCodeObject, co_code_adaptive), \
27+
.runtime_state = { \
28+
.finalizing = offsetof(_PyRuntimeState, _finalizing), \
29+
.interpreters_head = offsetof(_PyRuntimeState, interpreters.head), \
30+
}, \
31+
.interpreter_state = { \
32+
.next = offsetof(PyInterpreterState, next), \
33+
.threads_head = offsetof(PyInterpreterState, threads.head), \
34+
.gc = offsetof(PyInterpreterState, gc), \
35+
.imports_modules = offsetof(PyInterpreterState, imports.modules), \
36+
.sysdict = offsetof(PyInterpreterState, sysdict), \
37+
.builtins = offsetof(PyInterpreterState, builtins), \
38+
.ceval_gil = offsetof(PyInterpreterState, ceval.gil), \
39+
}, \
40+
.thread_state = { \
41+
.prev = offsetof(PyThreadState, prev), \
42+
.next = offsetof(PyThreadState, next), \
43+
.interp = offsetof(PyThreadState, interp), \
44+
.cframe = offsetof(PyThreadState, cframe), \
45+
.thread_id = offsetof(PyThreadState, thread_id), \
46+
}, \
47+
.frame_object = { \
48+
.previous = offsetof(_PyInterpreterFrame, previous), \
49+
.executable = offsetof(_PyInterpreterFrame, f_executable), \
50+
.prev_instr = offsetof(_PyInterpreterFrame, prev_instr), \
51+
.localsplus = offsetof(_PyInterpreterFrame, localsplus), \
52+
.owner = offsetof(_PyInterpreterFrame, owner), \
53+
}, \
54+
.code_object = { \
55+
.filename = offsetof(PyCodeObject, co_filename), \
56+
.name = offsetof(PyCodeObject, co_name), \
57+
.linetable = offsetof(PyCodeObject, co_linetable), \
58+
.firstlineno = offsetof(PyCodeObject, co_firstlineno), \
59+
.argcount = offsetof(PyCodeObject, co_argcount), \
60+
.localsplusnames = offsetof(PyCodeObject, co_localsplusnames), \
61+
.co_code_adaptive = offsetof(PyCodeObject, co_code_adaptive), \
62+
}, \
5763
}, \
5864
.allocators = { \
5965
.standard = _pymem_allocators_standard_INIT(runtime), \

0 commit comments

Comments
 (0)