python - PyList_GetItem not idempotent -


i'm trying out swig , have following c code , interface respectively:

// example.c #include <python/python.h> pyobject *test ( pyobject *self, int i) {     pyobject **x;     x = malloc(sizeof(pyobject *));     *x = pylist_getitem(self, i);     return *x; }  // example.i %module example %{ /* put header files here or function declarations below */ extern pyobject* test(pyobject *self, int i); %}  extern pyobject* test(pyobject *self, int i); 

it compiles , can import extension module fine. in fact, when define variable [{1:1},{2:2}] , example.test(a, 0) first time, returns {1,1}. when enter python shell, [{1:1},{2:2}] expected. when try example.test(a,0) again, segmentation fault. ideas why happening?

pyobject* pylist_getitem(pyobject *list, py_ssize_t index)
return value: borrowed reference.

incref object before returning it.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -