◐ Shell
clean mode source ↗

Message 112926 - Python tracker

Attempting to compile Python 3 extension modules on GCC with "-Wmissing-field-initializers" enabled leads to warnings from the PyModuleDef_HEAD_INIT macro

Seen attempting to build SELinux python bindings against python 3.1 with "-W -Werror", the "-W" implies "-Wmissing-field-initializers":
> cc -Werror -Wall -W -Wundef -Wshadow -Wmissing-noreturn
> > -Wmissing-format-attribute -I../include -I/usr/include -D_GNU_SOURCE
> > -D_FILE_OFFSET_BITS=64  -I/usr/include/python3.1 -fPIC -DSHARED -c -o
> > audit2why.lo audit2why.c
> > cc1: warnings being treated as errors
> > audit2why.c:439: error: missing initializer
> > audit2why.c:439: error: (near initialization for ?moduledef.m_base.m_init¹)
> > make: *** [audit2why.lo] Error 1

The PyModuleDef_HEAD_INIT is intended to initialize m_base within a PyModuleDef, but only explicitly initializes the PyObject_HEAD fields:

#define PyModuleDef_HEAD_INIT {PyObject_HEAD_INIT(NULL)}

typedef struct PyModuleDef_Base {
  PyObject_HEAD
  PyObject* (*m_init)(void);
  Py_ssize_t m_index;
  PyObject* m_copy;
} PyModuleDef_Base;

typedef struct PyModuleDef{
  PyModuleDef_Base m_base;
  const char* m_name;
  const char* m_doc;
  Py_ssize_t m_size;
  PyMethodDef *m_methods;
  inquiry m_reload;
  traverseproc m_traverse;
  inquiry m_clear;
  freefunc m_free;
} PyModuleDef;

The attached patch extends it to also explicitly zero the other m_base fields.