<div dir="ltr"><div><div>Hello,<br><br>I'm extending an application that supports customization using the C language.<br>I am able to write standalone python applications that use the C API's using cffi.<br>This is good, but only a first step.<br>
<br>This application allows me to register code that will run on various events but it has to be C code.<br>I'd like to write Python code instead.<br>So
 basically, my C code will use the Python C API to get a handle to the 
module and function (like how they do it here 
<a href="http://docs.python.org/2/extending/embedding.html#pure-embedding">http://docs.python.org/2/extending/embedding.html#pure-embedding</a>)<br>What
 would be the proper way to pass a pointer to a C structure from C to 
Python so that I can use ffi.cast and be able to use it from within 
Python?<br><br>I have got this to work but I'm not certain that it is correct, fool-proof, or portable.<br><br>This is how I got it to work from the C side....<br><br>PyObject* pArgs = Py_BuildValue("(k)", &some_structure);<br>
PyObject_CallObject(pFunc, pArgs)<br><br>... and from the Python side...<br><br>def my_function(struct_ptr):<br>    struct = ffi.cast("mystruct_t *", struct_ptr)<br><br><br>Like I said, this works fine.  I am able to manipulate the structure from within Python.<br>
I just want to know the correct way to to this.<br><br></div>Thanks,<br></div>~Eric<br></div>