SWIG Python—包装一个需要指向结构的双指针的函数
我正在包装一个包含结构的C库:SWIG Python—包装一个需要指向结构的双指针的函数,python,pointers,swig,Python,Pointers,Swig,我正在包装一个包含结构的C库: struct SCIP { //... } void SCIPcreate(SCIP** s) 以及创建这样一个结构的函数: struct SCIP { //... } void SCIPcreate(SCIP** s) SWIG生成一个python类SCIP和一个函数SCIPcreate(*args) 当我现在尝试在python中调用SCIPcreate()时,它显然需要一个类型为SCIP**的参数,我该如何创建这样的东西呢 或者我应该尝试使用自动调用S
struct SCIP
{
//...
}
void SCIPcreate(SCIP** s)
以及创建这样一个结构的函数:
struct SCIP
{
//...
}
void SCIPcreate(SCIP** s)
SWIG生成一个python类SCIP
和一个函数SCIPcreate(*args)
当我现在尝试在python中调用SCIPcreate()
时,它显然需要一个类型为SCIP**
的参数,我该如何创建这样的东西呢
或者我应该尝试使用自动调用SCIPcreate()
的构造函数扩展SCIP
类吗?如果是这样的话,我该怎么做呢?给定头文件:
struct SCIP {};
void SCIPcreate(struct SCIP **s) {
*s = malloc(sizeof **s);
}
我们可以使用以下方法包装此函数:
%module test
%{
#include "test.h"
%}
%typemap(in,numinputs=0) struct SCIP **s (struct SCIP *temp) {
$1 = &temp;
}
%typemap(argout) struct SCIP **s {
%set_output(SWIG_NewPointerObj(SWIG_as_voidptr(*$1), $*1_descriptor, SWIG_POINTER_OWN));
}
%include "test.h"
这是两个类型映射,一个用于创建本地临时指针,用作函数的输入,另一个用于在调用后将指针的值复制到返回中
除此之外,您还可以使用%inline
设置重载:
%newobject SCIPcreate;
%inline %{
struct SCIP *SCIPcreate() {
struct SICP *temp;
SCIPcreate(&temp);
return temp;
}
%}