This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Segmentation fault when running c extension on macOS
Type: crash Stage: resolved
Components: macOS Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Senhui Guo, ned.deily, ronaldoussoren, taleinat
Priority: normal Keywords:

Created on 2019-05-01 13:49 by Senhui Guo, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg341196 - (view) Author: Senhui Guo (Senhui Guo) Date: 2019-05-01 13:49
I was trying to build a c extension with cpython while it keeps crashing when I get it running, the code is quite simple:
```cpp
#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
msg341200 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2019-05-01 14:35
The program you include in your report will crash because the interpreter is never initialised.

See the embedding documentation for more information: https://docs.python.org/3/extending/embedding.html
msg349043 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2019-08-05 10:06
I'm closing this: It has had no followup in over 3 months, and seems to be a simple misuse of the C API rather than a bug.
History
Date User Action Args
2022-04-11 14:59:14adminsetgithub: 80948
2019-08-05 10:06:02taleinatsetstatus: pending -> closed

nosy: + taleinat
messages: + msg349043

stage: resolved
2019-05-01 14:35:34ronaldoussorensetstatus: open -> pending
resolution: not a bug
messages: + msg341200
2019-05-01 13:49:57Senhui Guocreate