Segmentation fault (core dumped). Using C module in python -
i newbie in python , trying launch python script module writen on c. getting segmentation fault (core dumped) error when trying launch python script. here c code:
// input_device.c #include "python.h" #include "input.h" static pyobject* input_device_open(pyobject* self, pyobject* id) { int fd, nr; pyobject* pyfd; if (!pyint_check(id)) return null; nr = (int)pyint_aslong(id); fd = device_open(nr, 0); if (fd == -1) return null; pyfd = pyint_fromlong(fd); py_incref(pyfd); return pyfd; } static pymethoddef module_methods[] = { { "device_open", (pycfunction)input_device_open, meth_varargs, "..." }, { null, null, 0, null } }; pymodinit_func initinput_device(void) { py_initmodule4("input_device", module_methods, "wrapper methods", 0, python_api_version); }
and python script:
from input_device import device_open device_open(1)
could take , point me in right direction, doing wrong. in advance.
is legitimate return null
without setting exception, or making sure 1 has been set function have called? thought null
signal python go exception raise user.
i not sure py_incref(pyfd);
necessary; doesn't object have refcount of 1 upon creation?
Comments
Post a Comment