Skip to content

Commit

Permalink
Use smaller structs
Browse files Browse the repository at this point in the history
  • Loading branch information
pablogsal committed Jul 10, 2023
1 parent b84bb00 commit ff5d47e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 56 deletions.
62 changes: 36 additions & 26 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,40 +55,50 @@ typedef struct _Py_AuditHookEntry {

typedef struct _Py_DebugOffsets {
// Runtime state offset;
off_t rs_finalizing;
off_t rs_interpreters_head;
struct _runtime_state {
off_t finalizing;
off_t interpreters_head;
} runtime_state;

// Interpreter state offset;
off_t is_next;
off_t is_threads_head;
off_t is_gc;
off_t is_imports_modules;
off_t is_sysdict;
off_t is_builtins;
off_t is_ceval_gil;
struct _interpreter_state {
off_t next;
off_t threads_head;
off_t gc;
off_t imports_modules;
off_t sysdict;
off_t builtins;
off_t ceval_gil;
} interpreter_state;

// Thread state offset;
off_t ts_prev;
off_t ts_next;
off_t ts_interp;
off_t ts_cframe;
off_t ts_thread_id;
struct _thread_state{
off_t prev;
off_t next;
off_t interp;
off_t cframe;
off_t thread_id;
} thread_state;

// Frame object offset;
off_t fo_previous;
off_t fo_executable;
off_t fo_prev_instr;
off_t fo_localsplus;
off_t fo_owner;
struct _frame_object {
off_t previous;
off_t executable;
off_t prev_instr;
off_t localsplus;
off_t owner;
} frame_object;

// Code object offset;
off_t co_filename;
off_t co_name;
off_t co_linetable;
off_t co_firstlineno;
off_t co_argcount;
off_t co_localsplusnames;
off_t co_co_code_adaptive;
struct _code_object {
off_t filename;
off_t name;
off_t linetable;
off_t firstlineno;
off_t argcount;
off_t localsplusnames;
off_t co_code_adaptive;
} code_object;
} _Py_DebugOffsets;

/* Full Python runtime state */
Expand Down
66 changes: 36 additions & 30 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,42 @@ extern PyTypeObject _PyExc_MemoryError;
#define _PyRuntimeState_INIT(runtime) \
{ \
.debug_offsets = { \
.rs_finalizing = offsetof(_PyRuntimeState, _finalizing), \
.rs_interpreters_head = offsetof(_PyRuntimeState, interpreters.head), \
\
.is_next = offsetof(PyInterpreterState, next), \
.is_threads_head = offsetof(PyInterpreterState, threads.head), \
.is_gc = offsetof(PyInterpreterState, gc), \
.is_imports_modules = offsetof(PyInterpreterState, imports.modules), \
.is_sysdict = offsetof(PyInterpreterState, sysdict), \
.is_builtins = offsetof(PyInterpreterState, builtins), \
.is_ceval_gil = offsetof(PyInterpreterState, ceval.gil), \
\
.ts_prev = offsetof(PyThreadState, prev), \
.ts_next = offsetof(PyThreadState, next), \
.ts_interp = offsetof(PyThreadState, interp), \
.ts_cframe = offsetof(PyThreadState, cframe), \
.ts_thread_id = offsetof(PyThreadState, thread_id), \
\
.fo_previous = offsetof(_PyInterpreterFrame, previous), \
.fo_executable = offsetof(_PyInterpreterFrame, f_executable), \
.fo_prev_instr = offsetof(_PyInterpreterFrame, prev_instr), \
.fo_localsplus = offsetof(_PyInterpreterFrame, localsplus), \
.fo_owner = offsetof(_PyInterpreterFrame, owner), \
\
.co_filename = offsetof(PyCodeObject, co_filename), \
.co_name = offsetof(PyCodeObject, co_name), \
.co_linetable = offsetof(PyCodeObject, co_linetable), \
.co_firstlineno = offsetof(PyCodeObject, co_firstlineno), \
.co_argcount = offsetof(PyCodeObject, co_argcount), \
.co_localsplusnames = offsetof(PyCodeObject, co_localsplusnames), \
.co_co_code_adaptive = offsetof(PyCodeObject, co_code_adaptive), \
.runtime_state = { \
.finalizing = offsetof(_PyRuntimeState, _finalizing), \
.interpreters_head = offsetof(_PyRuntimeState, interpreters.head), \
}, \
.interpreter_state = { \
.next = offsetof(PyInterpreterState, next), \
.threads_head = offsetof(PyInterpreterState, threads.head), \
.gc = offsetof(PyInterpreterState, gc), \
.imports_modules = offsetof(PyInterpreterState, imports.modules), \
.sysdict = offsetof(PyInterpreterState, sysdict), \
.builtins = offsetof(PyInterpreterState, builtins), \
.ceval_gil = offsetof(PyInterpreterState, ceval.gil), \
}, \
.thread_state = { \
.prev = offsetof(PyThreadState, prev), \
.next = offsetof(PyThreadState, next), \
.interp = offsetof(PyThreadState, interp), \
.cframe = offsetof(PyThreadState, cframe), \
.thread_id = offsetof(PyThreadState, thread_id), \
}, \
.frame_object = { \
.previous = offsetof(_PyInterpreterFrame, previous), \
.executable = offsetof(_PyInterpreterFrame, f_executable), \
.prev_instr = offsetof(_PyInterpreterFrame, prev_instr), \
.localsplus = offsetof(_PyInterpreterFrame, localsplus), \
.owner = offsetof(_PyInterpreterFrame, owner), \
}, \
.code_object = { \
.filename = offsetof(PyCodeObject, co_filename), \
.name = offsetof(PyCodeObject, co_name), \
.linetable = offsetof(PyCodeObject, co_linetable), \
.firstlineno = offsetof(PyCodeObject, co_firstlineno), \
.argcount = offsetof(PyCodeObject, co_argcount), \
.localsplusnames = offsetof(PyCodeObject, co_localsplusnames), \
.co_code_adaptive = offsetof(PyCodeObject, co_code_adaptive), \
}, \
}, \
.allocators = { \
.standard = _pymem_allocators_standard_INIT(runtime), \
Expand Down

0 comments on commit ff5d47e

Please sign in to comment.