Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   SWIG, Python and C structures (http://www.velocityreviews.com/forums/t361083-swig-python-and-c-structures.html)

RocketIII 07-28-2006 01:32 PM

SWIG, Python and C structures
 
Hi,

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'
statement.

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)
sxa.sa = sxl # <-triggers the
following error

Traceback (most recent call last):
File "pymod_test.py", line 34, in ?
test()
File "pymod_test.py", line 31, in test
test2()
File "pymod_test.py", line 25, in test2
sxa.sa = sxl
File "/home/user/utv/misc/pymods/pymod.py", line 70, in <lambda>
__setattr__ = lambda self, name, value: _swig_setattr(self, SXA,
name, value)
File "/home/user/utv/misc/pymods/pymod.py", line 22, in _swig_setattr
return _swig_setattr_nondynamic(self,class_type,name,valu e,0)
File "/home/user/utv/misc/pymods/pymod.py", line 15, in
_swig_setattr_nondynamic
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.
sxa.sa = sx1

Can anyone please advise

Regards
- 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.