私は Python の初心者で、C で記述されたモジュールを使用して Python スクリプトを起動しようとしています。Python スクリプトを起動しようとすると、セグメンテーション違反 (コア ダンプ) エラーが発生します。ここにCコードがあります:
// 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);
}
そしてpythonスクリプト:
from input_device import device_open
device_open(1)
誰かが私を見て、私が間違っていることを正しい方向に向けることができますか. 前もって感謝します。