Search code examples
pythoncmallocipythonpython-c-api

IPython behaves differently than CPython when interacting with c extension


I have developed a small python c-extension, with a flex scanner, that works perfectly fine in CPython. All my tests pass. But in IPython the output differs or IPython dies with a malloc error, whenever I try to interact with my c-extension. When I run my c-extension with valgrind lots of potential memory issues are detacted in Py_Initialize(), but none of them seem to be related to my code. I also double checked the reference count on my objects. I'm using anaconda on OS X with Python 3.6.5 Anybody got an idea what may cause this problem or how to debug this issue?

The memory error I get is:

python(92795,0x7fff9ba8f380) malloc: *** error for object 0x7f9222845a40: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

Solution

  • Ok it was my own stupid fault. I Python didn't used the c extension from the conda env, but an older not properly working version of my c extension.