Reputation: 233
I'm using SWIT to convert a vc project to python. I found when a struct has a member which type is like "typedef char TEXT[16]" cannot be converted correctly. for example:
typedef char TEXT[16];
struct MYSTRUCT
{
TEXT TradingDay;
};
The wrapper cpp cannot compile all right. "error C2075: 'Target of operator new()' : array initialization needs curly braces" BUT,if typedef is not an array , like this:
typedef int NUMBER;
struct MYSTRUCT2
{
NUMBER Money;
};
there will be all right. what should I do? thx!
P.S: i file:
%module MyDataAPI
%include "typemaps.i"
%header %{
#include "../References/MyDataAPI.h"
%}
namespace MyDataAPI
{
struct MYSTRUCT
{
TEXT TradingDay;
};
struct MYSTRUCT2
{
NUMBER Money;
};
}
Upvotes: 0
Views: 1878
Reputation: 178409
Make sure your typedef
statements are processed by SWIG. %header
only adds code to the generated file, that data is not processed by SWIG. %inline
both adds the code directly to the generated file and processes it with SWIG. Here's my .i
file:
%module x
%inline %{
typedef char TEXT[16];
typedef int NUMBER;
namespace MyDataAPI
{
struct MYSTRUCT
{
TEXT TradingDay;
};
struct MYSTRUCT2
{
NUMBER Money;
};
}
%}
And use:
T:\>py
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import x
>>> a=x.MYSTRUCT()
>>> a.TradingDay
''
>>> a.TradingDay='ABCDEFGHIJKLMNOPQ' # Note this is too long, 17 chars...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: in method 'MYSTRUCT_TradingDay_set', argument 2 of type 'char [16]'
>>> a.TradingDay='ABCDEFGHIJKLMNOP'
>>> a.TradingDay
'ABCDEFGHIJKLMNOP'
>>> b=x.MYSTRUCT2()
>>> b.Money
0
>>> b.Money=100
>>> b.Money
100
Upvotes: 1