1

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

Travis
  • 552
  • 1
  • 8
  • 14

1 Answers1

-1

Turns out this has been asked and answered elsewhere on StackOverflow by Mr. Mark Tolonen

https://stackoverflow.com/a/11218281/267157

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Travis
  • 552
  • 1
  • 8
  • 14