Commit f8d577c6 authored by Joris Vankerschaver's avatar Joris Vankerschaver

DOC: Add calls to Py_Initialize/Py_Finalize in code sample.

parent 9eb978cc
...@@ -418,10 +418,12 @@ made available when you include :file:`modulename_api.h`.:: ...@@ -418,10 +418,12 @@ made available when you include :file:`modulename_api.h`.::
Vehicle car; Vehicle car;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
Py_Initialize();
import_delorean(); import_delorean();
car.speed = atoi(argv[1]); car.speed = atoi(argv[1]);
car.power = atof(argv[2]); car.power = atof(argv[2]);
activate(&car); activate(&car);
Py_Finalize();
} }
.. note:: .. note::
...@@ -434,7 +436,10 @@ made available when you include :file:`modulename_api.h`.:: ...@@ -434,7 +436,10 @@ made available when you include :file:`modulename_api.h`.::
Using the :keyword:`api` method does not require the C code using the Using the :keyword:`api` method does not require the C code using the
declarations to be linked with the extension module in any way, as the Python declarations to be linked with the extension module in any way, as the Python
import machinery is used to make the connection dynamically. However, only import machinery is used to make the connection dynamically. However, only
functions can be accessed this way, not variables. functions can be accessed this way, not variables. Note also that for the
module import mechanism to be set up correctly, the user must call
Py_Initialize() and Py_Finalize(); if you experience a segmentation fault in
the call to :func:`import_modulename`, it is likely that this wasn't done.
You can use both :keyword:`public` and :keyword:`api` on the same function to You can use both :keyword:`public` and :keyword:`api` on the same function to
make it available by both methods, e.g.:: make it available by both methods, e.g.::
......
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