SWIG (C & Python) cstring.i 问题
SWIG (C & Python) cstring.i problems
我已阅读 http://www.swig.org/Doc1.3/Library.html#Library_nn12 但在 Python 使用以下形式的函数时遇到问题:
/* foo.h */
//fills *filename with useful stuff in the usual way
int foo(char *filename);
我有一个大致如下所示的接口文件:
%module foo
{% #include "foo.h" %}
%include "foo.h"
%cstring_bounded_output(char *filename, 1024);
extern int foo(char *filename);
swig 文档让我相信我可以从 python 调用 foo() 而不带任何参数,并且 return 值将是 python 字符串文件名。然而:
In [4]: foo.foo()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-db4ddc3a33ec> in <module>()
----> 1 foo.foo()
TypeError: foo() takes exactly 1 argument (0 given)
foo() 仍然需要一个 char *。我的接口文件是否正确?这是从此类 C 函数中获取 python 值的首选方法吗?
http://web.mit.edu/svn/src/swig-1.3.25/Lib/python/cstring.i 很难解析。如果有人知道这个宏在做什么,最好能对它有所了解。
注意:如果相关的话,我被困在使用 Swig 1 的生产环境中。3.z。此外,我必须在这里使用 Swig。
%cstring_bounded_output
必须在 foo
的声明之前,即使是在头文件中的声明。这个版本适合我:
%module foo
%include cstring.i
%{
#include "foo.h"
%}
%cstring_bounded_output(char* filename, 1024);
%include "foo.h"
extern int foo(char *filename);
我已阅读 http://www.swig.org/Doc1.3/Library.html#Library_nn12 但在 Python 使用以下形式的函数时遇到问题:
/* foo.h */
//fills *filename with useful stuff in the usual way
int foo(char *filename);
我有一个大致如下所示的接口文件:
%module foo
{% #include "foo.h" %}
%include "foo.h"
%cstring_bounded_output(char *filename, 1024);
extern int foo(char *filename);
swig 文档让我相信我可以从 python 调用 foo() 而不带任何参数,并且 return 值将是 python 字符串文件名。然而:
In [4]: foo.foo()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-db4ddc3a33ec> in <module>()
----> 1 foo.foo()
TypeError: foo() takes exactly 1 argument (0 given)
foo() 仍然需要一个 char *。我的接口文件是否正确?这是从此类 C 函数中获取 python 值的首选方法吗?
http://web.mit.edu/svn/src/swig-1.3.25/Lib/python/cstring.i 很难解析。如果有人知道这个宏在做什么,最好能对它有所了解。
注意:如果相关的话,我被困在使用 Swig 1 的生产环境中。3.z。此外,我必须在这里使用 Swig。
%cstring_bounded_output
必须在 foo
的声明之前,即使是在头文件中的声明。这个版本适合我:
%module foo
%include cstring.i
%{
#include "foo.h"
%}
%cstring_bounded_output(char* filename, 1024);
%include "foo.h"
extern int foo(char *filename);