Skip to content

Commit

Permalink
Added custom entry in PyInterpreterState
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bytemarx committed Jun 16, 2024
1 parent 547e882 commit 90f462b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ struct _is {
size_t stacksize;
} threads;


// CUSTOM MODIFICATIONS (hey guys, don't mind me)
void* passthrough;


/* 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. */
Expand Down

0 comments on commit 90f462b

Please sign in to comment.