在python中调用涉及指针的C函数 [英] Call a C function involving pointers in python

查看:236
本文介绍了在python中调用涉及指针的C函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要从python调用一个C函数,如下所示:

Hi,
I need to call a C function from python which looks like this:

void func(void **buffer, int *szBuffer)
{
    //allocate memory to buffer
    *szBuffer = req_size;
    *buffer = malloc(req_size);

    //buffer filled
}



然后,我必须在python中使用缓冲区.我怎么能做到这一点.请帮忙!



Then i must use the buffer in python. How can i achieve this. Please help!

推荐答案

做到这一点的自然方法"是以Python可能理解的方式包装函数,即编写适当的C 扩展名的扩展名.请参阅:使用C或C ++扩展Python" [
The ''natural way'' to do that would be wrapping your function in way Python may understand, i.e. writing a proper C extension for Python. See: "Extending Python with C or C++"[^].


我不知道python函数的工作原理,但是我建议您获取Python的开发套件.请按照此处提供的说明进行操作.
I dont know how python function works, But I will suggest you to get development kit for Python. Follow the instruction provided there


如果您熟悉Boost,可以尝试使用它.
1.
增强Python. [另一个包装器生成器.这对很多语言都有约束力. [ ^ ]
3. Python在线文档中的一些羊肚菌链接. [ ^ ]
You can try using boost if you are familiar with it.
1. Boost Python.[^]
2. Another wrapper generator. This has binding for a lot of languages.[^]
3. A few morel links from the python online documentation.[^]


这篇关于在python中调用涉及指针的C函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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