Discussion:
[Swig-devel] [MATLAB] swig test-suite contains member functions with names that are not allowed for MATLAB
Kris Thielemans
2015-06-28 17:14:35 UTC
Permalink
Hi all

Some of the test-suite files contains functions like __str__. When wrapping these to MATLAB, we get errors like this:

Warning: invalid MATLAB symbol '__str__' (function)
Symbols may not start with '_'. Maybe try something like this: %rename(u__str__) __str__;

I guess we could edit all the offending test files (e.g. cpp_basic.i) and put some conditionals in there with this type of rename. How is this handled in other languages?

Kris
William S Fulton
2015-08-04 05:54:08 UTC
Permalink
Post by Kris Thielemans
Hi all
Some of the test-suite files contains functions like __str__. When
Warning: invalid MATLAB symbol '__str__' (function)
%rename(u__str__) __str__;
I guess we could edit all the offending test files (e.g. cpp_basic.i) and
put some conditionals in there with this type of rename. How is this
handled in other languages?
As far as I can tell these are valid symbols in all other languages. I
guess you'll have to put in a conditional %rename in te testcases for
Matlab.

As symbols beginning with _ are possible in C and C++, perhaps Matlab
should use the regex feature of %rename to automatically rename these
symbols. Or at a minimum document the regex required for the warning. BTW,
it looks like the warning has not been properly implemented as there is no
warning number displayed.

William
Kris Thielemans
2015-08-30 21:07:15 UTC
Permalink
From: William S Fulton, Sent: 04 August 2015 06:54





On 28 June 2015 at 18:14, Kris Thielemans wrote:

Hi all

Some of the test-suite files contains functions like __str__. When wrapping these to MATLAB, we get errors like this:

Warning: invalid MATLAB symbol '__str__' (function)
Symbols may not start with '_'. Maybe try something like this: %rename(u__str__) __str__;

I guess we could edit all the offending test files (e.g. cpp_basic.i) and put some conditionals in there with this type of rename. How is this handled in other languages?



As far as I can tell these are valid symbols in all other languages. I guess you'll have to put in a conditional %rename in te testcases for Matlab.

As symbols beginning with _ are possible in C and C++, perhaps Matlab should use the regex feature of %rename to automatically rename these symbols. Or at a minimum document the regex required for the warning. BTW, it looks like the warning has not been properly implemented as there is no warning number displayed.



Hi William

I had another look at this. This seems to be falling into a few different categories:

director_frob, evil_diamond_prop, using1, using2, wallkw: some public variable/method start with _ (which seems a non-standard way of doing things, but ok). I guess we %rename these for Matlab (or adapt corresponding test cases in other languages, but I guess that won’t be appreciated).

cpp_basic: defines __str__ which presumably is a special function name for Lua (like in Python) as its test-case uses tostring. I guess we’d have to rename it to an equivalent Matlab function if it exists.

operator_overload, operator_overload_break: more complicated. __rsub__,, __getitem__, __setitem__, __str__, not sure what to do here

preproc: __GMP_HAVE_CONST etc. not sure here either

A few cases about __deref__ which are because of a rename of *::operator-> in swig.swg. We can handle that in matlabopers.swg





Kris
William S Fulton
2015-08-31 15:07:04 UTC
Permalink
*From: *William S Fulton, *Sent:* 04 August 2015 06:54
Hi all
Some of the test-suite files contains functions like __str__. When
Warning: invalid MATLAB symbol '__str__' (function)
%rename(u__str__) __str__;
I guess we could edit all the offending test files (e.g. cpp_basic.i) and
put some conditionals in there with this type of rename. How is this
handled in other languages?
As far as I can tell these are valid symbols in all other languages. I
guess you'll have to put in a conditional %rename in te testcases for
Matlab.
As symbols beginning with _ are possible in C and C++, perhaps Matlab
should use the regex feature of %rename to automatically rename these
symbols. Or at a minimum document the regex required for the warning. BTW,
it looks like the warning has not been properly implemented as there is no
warning number displayed.
Hi William
director_frob, evil_diamond_prop, using1, using2, wallkw: some public
variable/method start with _ (which seems a non-standard way of doing
things, but ok). I guess we %rename these for Matlab (or adapt
corresponding test cases in other languages, but I guess that won’t be
appreciated).
cpp_basic: defines __str__ which presumably is a special function name for
Lua (like in Python) as its test-case uses tostring. I guess we’d have to
rename it to an equivalent Matlab function if it exists.
operator_overload, operator_overload_break: more complicated. __rsub__,,
__getitem__, __setitem__, __str__, not sure what to do here
preproc: __GMP_HAVE_CONST etc. not sure here either
A few cases about __deref__ which are because of a rename of *::operator->
in swig.swg. We can handle that in matlabopers.swg
__str__ is a special function for some languages (it is a toString method).
As it doesn't have this special meaning in Matlab, don't add this part of
the runtime test. LIkewise for __getitem__, setitem__ etc, these tests are
just for languages that have special meaning to them.

Sounds like you have a problem with symbols beginning with an underscore.
You'll need to solve this problem as this is common enough in C and C++.
It'll also solve the problem with two leading underscores. If Matlab fails
with functions beginning with an underscore what is the current handling?
The answer will dictate what changes should be made in the test-suite. Can
you provide a link to the test-suite errors to look at?

William
Joel Andersson
2015-08-31 15:31:36 UTC
Permalink
Hi,

Concerning __str__, that can simply be renamed to "disp" in MATLAB, which
would correspond to standard MATLAB usage. __getitem__ and __setitem__
"almost" correspond to "paren" and "setparen" in the MATLAB module:

* If you do A = B(i,j), it will call B.paren(i, j)
* If you do A(i,j) = B, it will call A.setparen(B, i, j)

I think this is slightly different from at least Python syntax, where I
think "(i,j)" is treated as a tuple and value argument comes last when
setting. Since "paren" and "setparen" are defined in the MATLAB module, we
could simply change our definition, though I'm not sure if that's a good
idea since it feels like better C++ to treat a "tuple" as multiple
arguments.

Best regards,
Joel
Post by William S Fulton
*From: *William S Fulton, *Sent:* 04 August 2015 06:54
Hi all
Some of the test-suite files contains functions like __str__. When
Warning: invalid MATLAB symbol '__str__' (function)
%rename(u__str__) __str__;
I guess we could edit all the offending test files (e.g. cpp_basic.i) and
put some conditionals in there with this type of rename. How is this
handled in other languages?
As far as I can tell these are valid symbols in all other languages. I
guess you'll have to put in a conditional %rename in te testcases for
Matlab.
As symbols beginning with _ are possible in C and C++, perhaps Matlab
should use the regex feature of %rename to automatically rename these
symbols. Or at a minimum document the regex required for the warning. BTW,
it looks like the warning has not been properly implemented as there is no
warning number displayed.
Hi William
director_frob, evil_diamond_prop, using1, using2, wallkw: some public
variable/method start with _ (which seems a non-standard way of doing
things, but ok). I guess we %rename these for Matlab (or adapt
corresponding test cases in other languages, but I guess that won’t be
appreciated).
cpp_basic: defines __str__ which presumably is a special function name
for Lua (like in Python) as its test-case uses tostring. I guess we’d have
to rename it to an equivalent Matlab function if it exists.
operator_overload, operator_overload_break: more complicated. __rsub__,,
__getitem__, __setitem__, __str__, not sure what to do here
preproc: __GMP_HAVE_CONST etc. not sure here either
A few cases about __deref__ which are because of a rename of
*::operator-> in swig.swg. We can handle that in matlabopers.swg
__str__ is a special function for some languages (it is a toString
method). As it doesn't have this special meaning in Matlab, don't add this
part of the runtime test. LIkewise for __getitem__, setitem__ etc, these
tests are just for languages that have special meaning to them.
Sounds like you have a problem with symbols beginning with an underscore.
You'll need to solve this problem as this is common enough in C and C++.
It'll also solve the problem with two leading underscores. If Matlab fails
with functions beginning with an underscore what is the current handling?
The answer will dictate what changes should be made in the test-suite. Can
you provide a link to the test-suite errors to look at?
William
------------------------------------------------------------------------------
_______________________________________________
Swig-devel mailing list
https://lists.sourceforge.net/lists/listinfo/swig-devel
--
--
Joel Andersson, PhD
Ptge. Busquets 11-13, atico 3
E-08940 Cornella de Llobregat (Barcelona), Spain
Home: +34-93-6034011
Mobile: +34-63-4408800 (in Sweden also +46-707-360512)
Loading...