Daniel Liu, 28.06.2012 01:52:
> I've been trying to run the delorean.pyx and marty.c example for C API
> Declaration (
http://docs.cython.org/src/userguide/external_C_code.html) and
> I've been getting segmentation faults:
>
> delorean.pyx:
> # delorean.pyx
>
> ctypedef public struct Vehicle:
> int speed
> float power
>
> cdef public api void activate(Vehicle *v):
> if v.speed >= 88 and v.power >= 1.21:
> print "Time travel achieved"
>
> marty.c:
> #include "delorean_api.h"
>
> Vehicle car;
>
> int main(int argc, char *argv[]) {
> import_delorean();
> car.speed = atoi(argv[1]);
> car.power = atof(argv[2]);
> activate(&car);
> }
>
> compiling:
> cython delorean.pyx
> gcc delorean.c marty.c -I/usr/include/python2.7/ -lpython2.7
>
> running:
> ./a.out 100 2
> Segmentation fault (core dumped)
>
> Does anyone know what might be happening?
You didn't initialise the Python runtime.
http://docs.python.org/c-api/init.html
Take a look at the embedding example in Demos/embed/
Stefan