[issue9518] PyModuleDef_HEAD_INIT does not explicitly initialize all fields of m_base

Dave Malcolm report at bugs.python.org
Wed Sep 29 00:46:44 CEST 2010

Dave Malcolm <dmalcolm at redhat.com> added the comment:

Thanks.  The code in question is a wrapper to a security-sensitive library (user-space SELinux code), hence the compilation warnings have been turned up as much as possible.

The .c code in question is generated by SWIG, and that does indeed appear to be writing out full initializers for PyTypeObject instances (and the other associated structs).

It appears to be just Python 3's PyModuleDef_HEAD_INIT macro that leaves fields uninitialized (hence this patch).

The gory details of the SWIG-generated code can be seen at:
(and the .i files in that directory)

Although it's not on by default gcc will issue a "missing initializer" warning when fields aren't initialized when "-Wmissing-field-initializers" is enabled (in this case, due to the use of "-W").  This becomes an error with -Werror.

Whether or not this is a useful warning isn't clear to me, but it seems to be reasonable to suppress the warning given that as-is, people who use gcc's "-W" catch-all will run into this on all Python 3 modules, and that the patch is trivial, and that this case gives no warnings when building such code against Python 2.*

Hope this makes sense.


Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list