« Return to Thread: typedef / %rename problem in struct

Re: typedef / %rename problem in struct

by David Piepgrass :: Rate this Message:

Reply to Author | View in Thread

> Hi,
> I'm having trouble wrapping a more complicated version of the code
> below.
> Specifically, SWIG is defining an outer__inner struct, but using _inner
> as
> the type for inner in the set / get methods it generates.  I've tried
> to
> explicitly %rename _inner to outer__inner but SWIG is ignore the
> directive
> for some reason.
>
> Does anybody know a way around this problem, short of redefining the
> struct
> (that's not an option as the struct is autogenerated as part of a much,
> much
> larger project that I have little control over)?

Sounds like a bug to me. However, %rename is behaving correctly: it renames the symbol in the target language, it does not change references to the symbol on the C/C++ side.

Try this workaround:

%{
#include "pytest.h"
typedef outer::_inner _inner;
%}

> pytest.i
> -------------------------------
> %module pytest
> %{
> #include "pytest.h"
> %}
>
> %include "pytest.h"
> -------------------------------
>
> pytest.h
> -------------------------------
> typedef unsigned char UINT8;
>
> struct outer {
>
>     typedef struct __inner {
>         UINT8 Mode: 2;
>         UINT8 State: 2;
>         UINT8 Fire: 1;
>         UINT8 Spare: 3;
>     } _inner;
>
>     _inner inner;
> };
> -------------------------------
>
> ||=== pytest, Debug ===|
> pytest_wrap.cxx||In function `PyObject*
> _wrap_outer_inner_set(PyObject*,
> PyObject*)':|
> pytest_wrap.cxx|2973|error: `_inner' was not declared in this scope|
> pytest_wrap.cxx|2973|error: expected `;' before "arg2"|
> pytest_wrap.cxx|2995|error: `temp' was not declared in this scope|
> pytest_wrap.cxx|2995|error: `_inner' is not a type|
> pytest_wrap.cxx|2995|error: expected `>' before '*' token|
> pytest_wrap.cxx|2995|error: expected `(' before '*' token|
> pytest_wrap.cxx|2995|error: expected primary-expression before '>'
> token|
> pytest_wrap.cxx|2995|error: expected `)' before ';' token|
> pytest_wrap.cxx|2996|error: `arg2' was not declared in this scope|
> pytest_wrap.cxx|2997|error: type `<type error>' argument given to
> `delete',
> expected pointer|
> pytest_wrap.cxx|2996|warning: unused variable 'arg2'|
> pytest_wrap.cxx|3000|error: `arg2' was not declared in this scope|
> pytest_wrap.cxx|3000|warning: unused variable 'arg2'|
> pytest_wrap.cxx||In function `PyObject*
> _wrap_outer_inner_get(PyObject*,
> PyObject*)':|
> pytest_wrap.cxx|3014|error: `_inner' was not declared in this scope|
> pytest_wrap.cxx|3014|error: expected `;' before "result"|
> pytest_wrap.cxx|3022|error: `result' was not declared in this scope|
> pytest_wrap.cxx|3023|error: `_inner' is not a type|
> pytest_wrap.cxx|3023|error: ISO C++ forbids declaration of `type name'
> with
> no type|
> pytest_wrap.cxx|3023|error: expected `>' before "_inner"|
> pytest_wrap.cxx|3023|error: expected `(' before "_inner"|
> pytest_wrap.cxx|3023|error: expected primary-expression before '>'
> token|
> pytest_wrap.cxx||In function `PyObject*
> _wrap_outer__inner_get(PyObject*,
> PyObject*)':|
> pytest_wrap.cxx|3044|error: invalid use of `outer::_inner'|
> ||=== Build finished: 20 errors, 2 warnings ===|
> --
> View this message in context: http://www.nabble.com/typedef----rename-
> problem-in-struct-tp25931898p25931898.html
> Sent from the swig-user mailing list archive at Nabble.com.
>
>
> -----------------------------------------------------------------------
> -------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart
> your
> developing skills, take BlackBerry mobile applications to market and
> stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> Swig-user mailing list
> Swig-user@...
> https://lists.sourceforge.net/lists/listinfo/swig-user

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

 « Return to Thread: typedef / %rename problem in struct