0
내 확장 기능에서 c 함수를 호출하려고하는데이 테스트 케이스로 문제를 좁혔습니다.PyArg_ParseTuple이 세그먼트 화 오류를 일으킴
#import "Python.h"
...
// Called from python with test_method(0, 0, 'TEST')
static PyObject*
test_method(PyObject *args)
{
int ok, x, y, size;
const char *s;
// this causes Segmentation fault
//ok = PyArg_ParseTuple(args, "iis#", &x, &y, &s, &size);
// also segfaults
//if(ok) PyErr_SetString(PyExc_SystemError, 'Exception');
// this does not cause segfault but fills the variables with garbage
ok = PyArg_ParseTuple(&args, "iis#", &x, &y, &s, &size);
// Example: >test_method 0, 37567920, (garbage)
printf(">test_method %d, %d, %s\n", x, y, s);
/* Success */
Py_RETURN_NONE;
}
static PyMethodDef testMethods[] =
{
{"test_method", test_method, METH_VARARGS,
"test_method"},
...
{NULL, NULL, 0, NULL}
};
내가 잘못하고있는 아이디어. (Python 버전 2.6.4).
그것은 호기심에서 나온 것입니다. * 스스로 언급 한 것은 무엇입니까? 모듈? – jtm
답변에 대한 답변을 연장했습니다. –