Velocity Reviews

Velocity Reviews (
-   Python (
-   -   SWIG, Python and C structures (

RocketIII 07-28-2006 01:32 PM

SWIG, Python and C structures

I have structures like the following:

typedef struct _SX
int i;
char str[10];
} SX;

typedef struct _SXA
int num_elements;
SX sa[10];
} SXA;

void myfunc1( SX *sx_p );
void myfunc2( SXA *sxa_p );

The swig interface file simply includes the .h-file with the '%include'

I'm having problems when sending elements of SX within the SXA as an
argument to myfunc2!

The Python codes is like following:
sx1 = pymod.SX()
sx1.i = 1
sx1.str = "string1"
sx2 = pymod.SX()
sx2.i = 2
sx2.str = "string2"

sxl = []
sxl.append( sx1 )
sxl.append( sx2 )

sxa = pymod.SXA()
sxa.num_elements = len(sxl) = sxl # <-triggers the
following error

Traceback (most recent call last):
File "", line 34, in ?
File "", line 31, in test
File "", line 25, in test2 = sxl
File "/home/user/utv/misc/pymods/", line 70, in <lambda>
__setattr__ = lambda self, name, value: _swig_setattr(self, SXA,
name, value)
File "/home/user/utv/misc/pymods/", line 22, in _swig_setattr
return _swig_setattr_nondynamic(self,class_type,name,valu e,0)
File "/home/user/utv/misc/pymods/", line 15, in
if method: return method(self,value)
TypeError: argument number 2: a 'SX *' is expected, 'list([<pymod.SX;
proxy of C SX instance at _a0211708_p__SX>, <pymod.SX; proxy of C SX
instance at _70b21408_p__SX>])' is received

I've tried to add a %typemap (in) SX { ... } without any success.

The following assignment with call to myfunc2 works though. = sx1

Can anyone please advise

- Ingi

All times are GMT. The time now is 09:28 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.