痛饮,Python和输出字符串 [英] Swig, python and output strings

查看:113
本文介绍了痛饮,Python和输出字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用痛饮包装一个C接口,看起来像这样:

I am using Swig to wrap a C interface that looks like this:

int dosomething(char **str);

其中str为输出字符串。例如,从C与其叫这样的:

where str is an output string. For example, from C its called like this:

char *str= NULL;
int val= dosomething(&str);
   ...
free(str);

在Python中,我希望能够调用它是这样的:

In Python, I'd like to be able to call it like this:

val,str = dosomething()

但是,Python会报告

However, python keeps reporting

TypeError: dosomething() takes exactly 1 arguments (0 given)

我在一个类型映射使用OUTPUT试过,但无济于事。任何想法?

I've tried using OUTPUT in a typemap, but to no avail. Any ideas?

推荐答案

试试这个类型映射(我使用痛饮2.0.0):

Try this typemap (I'm using SWIG 2.0.0):

%include <cstring.i>
%cstring_output_allocate(char **str, free(*$1));

文档: cstring.i

这篇关于痛饮,Python和输出字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆