How can I get swig to wrap a linked list-type structure?
Posted
by bk
on Stack Overflow
See other posts from Stack Overflow
or by bk
Published on 2010-05-28T02:44:49Z
Indexed on
2010/05/28
2:51 UTC
Read the original article
Hit count: 231
Here's what I take to be a pretty standard header for a list. Because the struct
points to itself, we need this two-part declaration. Call it listicle.h
:
typedef struct _listicle listicle;
struct _listicle{
int i;
listicle *next;
};
I'm trying to get swig to wrap this, so that the Python user can make use of the listicle
struct. Here's what I have in listicle.i
right now:
%module listicle
%{
#include "listicle.h"
%}
%include listicle.h
%rename(listicle) _listicle;
%extend listicle {
listicle() {return malloc (sizeof(listicle));}
}
As you can tell by my being here asking, it doesn't work. All the various combinations
I've tried each fail in their own special way. [This one: %extend defined for an undeclared class listicle
. Change it to %extend _listicle
(and fix the constructor) and loading in Python gives type object '_listicle' has no attribute '_listicle_swigregister'
. And so on.]
Suggestions?
© Stack Overflow or respective owner