SWIG cannot convert typedef type

I am using SWIT to convert a vc project to python. I found that the structure has a member whose type is similar to "typedef char TEXT [16]", which cannot be converted correctly. eg:

typedef char TEXT[16];
struct MYSTRUCT
{       
    TEXT    TradingDay;     
};

The cpp wrapper cannot compile everything correctly. "error C2075:" The purpose of the new () operator: curly braces are needed to initialize the array "BUT, if typedef is not an array, for example:

    typedef int NUMBER;
    struct MYSTRUCT2
{       
    NUMBER Money;       
};

everything will be fine. what should I do? THX!

PS: i file:

%module MyDataAPI
%include "typemaps.i"

%header %{
#include "../References/MyDataAPI.h"

%}

namespace MyDataAPI
{
     struct MYSTRUCT
    {       
        TEXT    TradingDay;     
    };
    struct MYSTRUCT2
    {       
        NUMBER Money;       
    };
}
0
source share
1 answer

, typedef SWIG. %header , SWIG. %inline SWIG. .i:

%module x

%inline %{
    typedef char TEXT[16];
    typedef int NUMBER;
    namespace MyDataAPI
    {
        struct MYSTRUCT
        {
            TEXT TradingDay;
        };
        struct MYSTRUCT2
        {
            NUMBER Money;
        };
    }
%}

:

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
+1

Source: https://habr.com/ru/post/1545205/


All Articles