<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Dec 16, 2017 at 11:14 AM, Antoine Pitrou <span dir="ltr"><<a href="mailto:solipsis@pitrou.net" target="_blank">solipsis@pitrou.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Sat, 16 Dec 2017 19:37:54 +0100<br>
Antoine Pitrou <<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>> wrote:<br>
><br>
> Currently, you can pass a `module_api_version` to PyModule_Create2(),<br>
> but that function is for specialists only :-)<br>
><br>
> ("""Most uses of this function should be using PyModule_Create()<br>
> instead; only use this if you are sure you need it.""")<br>
<br>
</span>Ah, it turns out I misunderstood that piece of documentation and also<br>
what PEP 3121 really did w.r.t the module API check.<br>
<br>
PyModule_Create() is actually a *macro* calling PyModule_Create2() with<br>
the version number is was compiled against!<br>
<br>
#ifdef Py_LIMITED_API<br>
#define PyModule_Create(module) \<br>
        PyModule_Create2(module, PYTHON_ABI_VERSION)<br>
#else<br>
#define PyModule_Create(module) \<br>
        PyModule_Create2(module, PYTHON_API_VERSION)<br>
#endif<br>
<br>
And there's already a check for that version number in moduleobject.c:<br>
<a href="https://github.com/python/cpython/blob/master/Objects/moduleobject.c#L114" rel="noreferrer" target="_blank">https://github.com/python/<wbr>cpython/blob/master/Objects/<wbr>moduleobject.c#L114</a><br>
<br>
That check is always invoked when calling PyModule_Create() and<br>
PyModule_Create2().  Currently it merely invokes a warning, but we can<br>
easily turn that into an error.<br>
<br>
(with apologies to Martin von Löwis for not fully understanding what he<br>
did at the time :-))<br>
</blockquote></div><br>If it's only a warning, I worry that if we stop checking the flag bits 
it can cause wild pointer following. This sounds like it would be a 
potential security issue (load a module, ignore the warning, try to use a
 certain API on a class it defines, boom). Also, could there still be 
3rd party modules out there that haven't been recompiled in a really 
long time and use some older backwards compatible module initialization 
API? (I guess we could stop supporting that and let them fail hard.)<br clear="all"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>