Issue 36767: Segmentation fault when running c extension on macOS (original) (raw)

I was trying to build a c extension with cpython while it keeps crashing when I get it running, the code is quite simple:

#include "Python.h"

int main ()
{
    PyObject *p;
    p = PySet_New(NULL);
}

I build with command clang -I/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/include/python3.7m -L/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin -lpython3.7m test.c -o run when I ran it ./run, segmentation fault: 11 kicks in However, if I go with python2, it worked fine: clang -I /usr/local/Cellar/python\@2/2.7.16/Frameworks/Python.framework/Versions/2.7/include/python2.7 -L /usr/local/opt/python\@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/ -lpython2.7 test.c -o run

I was wondering if it is the problem with macOS? I tried build python from source, but didn't work, keeps crashing