Dear Chris -

> I am trying to create a C extension module to provide a python-callable
> function that can operate on a graph created using python-graph. Everything
> is working except extracting the pointer to the underlying C graph inside of
> the PyObject graph.

This hasn't been tested too much so let me know if you run into any issues, but
the idea is roughly as follows:

- There is a header named igraphmodule_api.h in the source code of the Python
  interface. This header is installed into
  ${PREFIX}/include/pythonX.Y/python-igraph/igraphmodule_api.h where ${PREFIX}
  is your Python prefix (typically /usr if you are using a system Python on
  Linux or Mac) and X.Y is your Python version number.

- Including igraphmodule_api.h in your C code would give you a function named
  import_igraph() - this must be called before using any igraph-related call
  from your C code. The function will return 0 if everything is okay.

- After having called import_igraph, you can start calling PyIGraph_ToCGraph()
  from your C code.

I have followed the instructions on the page below to implement this in igraph:

https://docs.python.org/2.7/extending/extending.html#using-capsules

Alternatively, you can use PyObject_CallMethod(py_graph, "_raw_pointer", "()")
to call the _raw_pointer method from C code -- this would return the raw memory
address as a Python integer (PyObject). You can then extract the memory address
using PyInt_AsLong and cast it into an (igraph_t*). (Don't forget to Py_DECREF
the Python integer if you don't need it any more).

T.

_______________________________________________
igraph-help mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/igraph-help

Reply via email to