我正在使用扩展的python概念编写包装程序,我不知道如何处理枚举。基本上我有一个c函数,其中一个输入是枚举。我应该使用什么格式选项?
typedef enum
{
ISOUTPUT = 'W',
ISINPUT = 'R'
} myenum;
int func1( i int, b myenum)
我的包装程序:
static PyObject *Wrapper_func1(PyObject *self, PyObject *args)
{
int x, result;
myenum y;
PyArg_ParseTuple(args,"iC",x,y);
result= func1(x, y);
return Py_BuildValue("i",result);
}
在python脚本中
import mymodule
x= mymodule.func1(1,'R') --- giving attribute error, when I debugged I found it is giving segment violation,
BT:
#0 convertsimple (arg=0x73e960, p_format=0x7fffffffd348,
p_va=<value optimized out>, flags=0,
msgbuf=0x7fffffffd1b0 "\310V\266\252\252*", bufsize=256,
freelist=0x7fffffffd330) at Python/getargs.c:684
#1 0x000000000048e30f in convertitem (freelist=<value optimized out>,
bufsize=<value optimized out>, msgbuf=<value optimized out>,
levels=<value optimized out>, flags=<value optimized out>,
p_va=<value optimized out>, p_format=<value optimized out>, arg=0x73e960)
at Python/getargs.c:499
#2 vgetargs1 (freelist=<value optimized out>, bufsize=<value optimized out>,
msgbuf=<value optimized out>, levels=<value optimized out>,
flags=<value optimized out>, p_va=<value optimized out>,
p_format=<value optimized out>, arg=0x73e960) at Python/getargs.c:330
#3 0x000000000048ea68 in PyArg_ParseTuple (args=0x73e960, format=0x0)
at Python/getargs.c:102