From 787e9dc05c7e73485e0b8adce8d8e05444f2adaa Mon Sep 17 00:00:00 2001 From: bytemarx <100504683+bytemarx@users.noreply.github.com> Date: Sun, 10 Dec 2023 03:36:30 -0500 Subject: [PATCH] [3.12] orbital: Added custom entry in `PyInterpreterState` Hijacked the interpreter state to get my boys on the inside. Currently, there doesn't seem to be an officially supported way to get a piece of pre-initialized per-interpreter memory over to an embedded module (more specifically, the embedded module's functions). For example: [init'd mem #1] ----> [subinterp #1] ----> {module fn call} [init'd mem #2] ----> [subinterp #2] ----> {module fn call} {module fn call} has a single implementation with access to its module state via `PyModule_GetState`. The initialization of a subinterpreter populates a custom entry for the pre-initialized memory in its interpreter state. On initialization of the embedded module (`Py_mod_exec`), the module state is populated with the custom entry (`PyThreadState_Get()->interp`). The module function now has access to the pre-initialized memory via its module state. --- Include/internal/pycore_interp.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h index 37cc88ed081b727..f78e3e7178e527b 100644 --- a/Include/internal/pycore_interp.h +++ b/Include/internal/pycore_interp.h @@ -103,6 +103,11 @@ struct _is { size_t stacksize; } threads; + + // ORBITAL MODIFICATIONS (hey guys, don't mind me) + const void* orb_passthough; + + /* Reference to the _PyRuntime global variable. This field exists to not have to pass runtime in addition to tstate to a function. Get runtime from tstate: tstate->interp->runtime. */