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 2010-06-30 09:36:57
我已經擴展了我的回答來回答這個問題。 – 2010-06-30 10:45:14