Commit 373cc5de authored by scoder's avatar scoder Committed by GitHub

Merge pull request #2409 from gabrieldemarmiesse/test__external_c_code

Added tests to "Interfacing with external C code" part 2
parents b4f0e29b 714143f4
# delorean.pyx
cdef public struct Vehicle:
int speed
float power
cdef api void activate(Vehicle *v):
if v.speed >= 88 and v.power >= 1.21:
print("Time travel achieved")
\ No newline at end of file
# marty.c
#include "delorean_api.h"
Vehicle car;
int main(int argc, char *argv[]) {
Py_Initialize();
import_delorean();
car.speed = atoi(argv[1]);
car.power = atof(argv[2]);
activate(&car);
Py_Finalize();
}
......@@ -458,32 +458,12 @@ contains the api call which is generating the segmentation fault does not call
the :func:`import_modulename` function before the api call which crashes.
Any public C type or extension type declarations in the Cython module are also
made available when you include :file:`modulename_api.h`.::
made available when you include :file:`modulename_api.h`.:
# delorean.pyx
cdef public struct Vehicle:
int speed
float power
.. literalinclude:: ../../examples/userguide/external_C_code/delorean.pyx
cdef api void activate(Vehicle *v):
if v.speed >= 88 and v.power >= 1.21:
print("Time travel achieved")
.. sourcecode:: c
# marty.c
#include "delorean_api.h"
Vehicle car;
int main(int argc, char *argv[]) {
Py_Initialize();
import_delorean();
car.speed = atoi(argv[1]);
car.power = atof(argv[2]);
activate(&car);
Py_Finalize();
}
.. literalinclude:: ../../examples/userguide/external_C_code/marty.c
:language: C
.. note::
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment