hpy icon indicating copy to clipboard operation
hpy copied to clipboard

HPyGlobal: should we fail loading module multiple times in one interpreter if the module uses HPyGlobal

Open steve-s opened this issue 1 year ago • 2 comments

HPyGlobal does not provide isolation for multiple instances of the same module loaded in one interpreter. However, experienced user could use HPyGlobal in such scenario, for example:

HPy type = HPyGlobal_Load(ctx, &MyType_Global);
if (HPy_IsNull(type)) {
    type = HPyType_FromSpec(...);
    HPyGlobal_Store(ctx, type);
}
HPy_Close(ctx, type);

I am slightly in favor of disallowing this and failing if HPyGlobals are registered in the module and the module is loaded twice in the same interpreter. It would be a compatible change to allow this when some flag is explicitly set, so we are not shutting the door - we can add this when we see a use case. (I think that people that want to support loading module multiple times in one interpreter should ideally use module state & it wasn't a thing some time ago, so I'd only expect a green-field new projects to do this).

steve-s avatar May 04 '23 09:05 steve-s