marco gaddoni | 15 Jun 2012 12:20
Picon

"regression" with typedef struct and %typemap(cscode)

Hello !

i think i have found a regression from 2.0.2 to 2.0.5 (and 2.0.7).

Using SWIG 2.0.5-7, I got a problem extending proxy classes with additional C# code.
In this example:

---------
%module test

%typemap(cscode) MyStruct %{ int field_b; %}

%include <typemaps.i>

typedef struct _myStruct
{
        int field_a;
} MyStruct;
----------

invoke swig -csharp -c++ .

The code generated by SWIG for MyStruc.cs, doesn't have the member field_b
But if I compile with SWIG 2.0.2-4 got it.

With SWIG 2.0.5-7, the only way to extending MyStruct with field_b, is to substitute the line:

%typemap(cscode) MyStruct %{ int field_b; %}

with

%typemap(cscode) _myStruct %{ int field_b; %}

we are using some typemap to add to
the opencv IplImage some methods to save and load from disk
and dont want to change the library.

I think this is an unwanted change in behavour.

Ciao,

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
William S Fulton | 8 Jul 2012 16:56
Picon
Favicon
Gravatar

Re: "regression" with typedef struct and %typemap(cscode)

On 15/06/12 11:20, marco gaddoni wrote:
> Hello !
>
> i think i have found a regression from 2.0.2 to 2.0.5 (and 2.0.7).
>
> Using SWIG 2.0.5-7, I got a problem extending proxy classes with
> additional C# code.
> In this example:
>
> ---------
> %module test
>
> %typemap(cscode) MyStruct %{ int field_b; %}
>
> %include <typemaps.i>
>
> typedef struct _myStruct
> {
>          int field_a;
> } MyStruct;
> ----------
>
> invoke swig -csharp -c++ .
>
> The code generated by SWIG for MyStruc.cs, doesn't have the member field_b
> But if I compile with SWIG 2.0.2-4 got it.
>
> With SWIG 2.0.5-7, the only way to extending MyStruct with field_b, is
> to substitute the line:
>
> %typemap(cscode) MyStruct %{ int field_b; %}
>
> with
>
> %typemap(cscode) _myStruct %{ int field_b; %}
>
> we are using some typemap to add to
> the opencv IplImage some methods to save and load from disk
> and dont want to change the library.
>
> I think this is an unwanted change in behavour.
This change in behaviour is due to a bug fix in swig-2.0.5 where a 
struct declared as you showed incorrectly set the type for the proxy as 
MyStruct. This is incorrect as this is a typedef to the real type - 
'struct _myStruct'. The following will work for both older and newer 
versions:

%typemap(cscode) _myStruct %{ int field_b; %}

William

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

Gmane