On 2019-04-27, Eric Snow wrote:
Alternative
For every context-sensitive function we could add a new first parameter, "context", that provides the runtime context to use. That would be something like this:
struct { PyThreadState *tstate; ... } PyRuntimeContext;
The interpreter state and global runtime state would still be accessible via the same indirection we have now.
This should be an opaque structure, IMHO. Users of the API should not know what's inside of it. We could have inline functions to get various things out of it, e.g.
PyThreadState *PyRuntime_GetThreadState(PyRuntimeContext *ctx) _PyRuntimeState *PyRuntime_GetRuntimeState(PyRuntimeContext *ctx)
Can we just add a _PyRuntimeState pointer to PyThreadState and then PyThreadState is basically the same as PyRuntimeContext? I don't see why _PyRuntimeState needs to be heap allocated at this point. Set the pointer to _PyRuntimeState when we create a new PyThreadState.
Regards,
Neil