I'm writing a Python class in C and I want to put assertions in my debug code. assert.h
suits me fine. This only gets put in debug compiles so there's no chance of an assert failure impacting a user of the Python code*.
I'm trying to divide my 'library' code (which should be separate to the code linked against Python) so I can use it from other C code. My Python methods are therefore thinnish wrappers around my pure-C code.
So I can't do this in my 'library' code:
if (black == white)
{
PyErr_SetString(PyExc_RuntimeError, "Remap failed");
}
because this pollutes my pure-C code with Python. It's also far uglier than a simple
assert(black != white);
I believe that the Distutils compiler always sets NDEBUG
, which means I can't use assert.h
even in debug builds.
Mac OS and Linux.
Help!
*one argument I've heard against asserting in C code called from Python.
python setup.py build
orpython setup.py build --debug
I get something like:gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -g -UDEBUG -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c thing.c -o build/temp.macosx-10.6-intel-2.7/thing.o
. How would I remove the NDEBUG? – Ribaldry