Stefan Behnel added the comment:

Marcel proposed to disallow main-execution if the extension *might* return 
anything but a real object (not only if it actually does), but that seems 
excessive to me. The actual problem is that we consider it unsafe if the module 
is executed more than once, because it might overwrite module state. But that's 
entirely up to the extension implementation and independent of what it uses as 
module type.

Given how easy it is so create and/or depend on global state in C, I would 
assume that extensions have to be explicitly designed in order to be 
re-executable. Can't we just have another slot that explicitly marks the module 
as such?

What do you think of this protocol:

Before running the exec or main-exec function, the runner checks for a slot 
entry "Py_mod_allow_reexec" (can have value NULL). If not found, it sets the 
function pointers in the exec *and* main-exec slots to NULL to prevent any 
further (or concurrent) re-execution. If the slot function is not NULL on the 
next execution request, it can be called (again).

That effectively prevents any re-execution by default and provides an opt-in 
way for the module to allow it.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30403>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to