I am trying to write a C library for python that will return some data about a value that is passed to it in string from. The returned data is in a c structure format and I need to get this information back to python to use it.
So far my research has found a few ways this can be done one is in the form of a list and another is in the form of a python dictionary. The problem I have with either of these is memory management. I don't want to have to deal with allocation and management of memory if I can avoid it. The structure is a fixed size so I do not see this as something that is needed. Another Idea I had was to pass in a structure object of some sorts and populate it.
Code examples can be found below, any help would be appreciated.
C Code:
static PyObject* GetValue(PyObject* self, PyObject* args)
{
const char* name;
const tSomeObject* pointer = NULL;
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
pointer = FindIO(inOutName);
if(!LibSwitch(inOutPointer))
{
/// @todo Do something if this call fails.
printf("IO Not Found!\r\n");
}
/// @todo Return the result some how????
Py_RETURN_NONE;
}
Python Code:
import SomeModule
SomeStruct = SomeModule.GetValue("Some Value")
Print(SomeStruct)