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
Post a Comment