【问题标题】:How can I get swig to wrap a linked list-type structure?如何让 swig 包装一个链表类型的结构?
【发布时间】:2010-05-28 02:44:49
【问题描述】:

我认为这是一个非常标准的列表标题。因为结构 指向它自己,我们需要这个由两部分组成的声明。叫它listicle.h

typedef struct _listicle listicle;

struct _listicle{
    int i;
    listicle *next;
};    

我正在尝试用 swig 来包装它,以便 Python 用户可以使用 listicle 结构。这是我现在在listicle.i 中的内容:

%module listicle

%{
#include "listicle.h"
%}

%include listicle.h
%rename(listicle) _listicle;

%extend listicle {
    listicle() {return malloc (sizeof(listicle));}
}

正如我在这里询问的那样,它不起作用。所有各种组合 我以自己特殊的方式尝试了每一次失败。 [这个:%extend defined for an undeclared class listicle。将其更改为%extend _listicle(并修复构造函数)并在 Python 中加载得到type object '_listicle' has no attribute '_listicle_swigregister'。以此类推。]

建议?

【问题讨论】:

    标签: c swig struct


    【解决方案1】:

    也许你可以忽略 python 代码中的 next 指针,只使用你在 python 中调用的 next() 函数?或者也许我不明白问题是什么......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 2020-04-10
      • 1970-01-01
      • 2015-06-24
      • 1970-01-01
      相关资源
      最近更新 更多