2024-04-30 23:37:27 发布
网友
我试图为一个函数(libFunc)编写一个pythoncwrapper,它的原型是
libFunc(char**, int*, char*, int)
如何使用PyArg_ParseTuple设置函数调用的参数。这是我目前所拥有的
我可以使用byref对ctypes执行相同的操作。在
最后我就这样做了
#include <Python.h> PyObject* libFunc_py(PyObject* self, PyObject* args) { char* input; char* output; int inputlen; int outputlen; PyArg_ParseTuple(args, "s#" , &input, &inputlen); int ret = libFunc(&output, &outlen, input, inputlen); if (ret !=0) { Py_ErrSetString(PyExc_RunTimeError, "ErrorMessage"); return NULL; } PyObject* retStr = Py_BuildValue("s#", output,outputlen); if(output) free(output) return retStr; }
最后我就这样做了
相关问题 更多 >
编程相关推荐