How do I pass a populated c structure to python (without ctypes)

189 Views Asked by At

How can I pass a c structure to python without using ctypes ?

I have a pointer to a stats_res_t structure that I'm trying to return to python.

I'm trying something along the lines of

PyObject* pyobject_get_system_stats(PyObject *self, PyObject *args)
{
    PyObject *temp;

    PyObject *resultlist;
    PyObject *res;
    stats_res_t *response;

    if(PyArg_ParseTuple(args,"O",&temp))
    {

        resultlist=PyDict_Values(temp);
        res=PyList_AsTuple(resultlist);

        // populate response

    }
    return Py_BuildValue("O",response);
}

but it causes segfault in python.

Is it possible to pass a populated structure to python using PyObject ?

0

There are 0 best solutions below