Skip to content Skip to sidebar Skip to footer

Python Sentinel In C++ Extension

I'm working on a Python extension module written in C++. According to the Python documentation the module method table should be written like this: static PyMethodDef SpamMethods[]

Solution 1:

A pod class initialized with {} has fields not explicitly set zeroed.

If PyMethodDef is pod (plain old data), as I suspect, {NULL, NULL, 0, NULL} will generate the same data as {}.

This is true in both C and C++.

If the class PyMethodDef was a non-pod class in C++11, {NULL, NULL, 0, NULL} could do something different than {}, but I strongly doubt that is the case here.

The only concern I would have is if the library changed on me to make PyMethodDef a non-pod, and chose to make {} not zero the data at the same time. I would find that unlikely.

Post a Comment for "Python Sentinel In C++ Extension"