So, I have this C code:
#include "Python.h"
void check(PyObject* pdict)
{
printf("About to instantiate PyString!\n");
PyObject* mdstr = PyObject_Str(pdict);
printf("Python dict: %s\n", PyString_AsString(mdstr));
}
Which I am able to compile and link into a shared library named 'libTmp.so'
Then I use this ctypes code fragment to invoke the 'check' function:
from ctypes import cdll, py_object, CFUNCTYPE, POINTER
SO = cdll.LoadLibrary("libTmp.so")
prototype = CFUNCTYPE(py_object, py_object)
check = prototype(('check',SO))
But when I try to invoke the 'check' function I get a segfault from the line:
PyObject* mdstr = PyObject_Str(pdict);
check({'one':1}) for example will segfault...
I suspect it is either a misunderstanding of the proper use case on my part or perhaps a unicode issue?
Any ideas would be appreciated.
Thanks