There seems to be a bug in SWIG's (v2.0.7) typemap search for SWIGTYPE const [ANY] typemaps. Given the following interface:
===== test.i =====
%module test;
%typemap(in) SWIGTYPE [ANY], SWIGTYPE const [ANY] {
/* mytypemap $1_dim0 */
}
typedef double myarray[7];
//%apply SWIGTYPE[ANY] { double[7] };
void myfunction(myarray a, myarray const b);
----- test.i -----
if I compile with
swig -python -debug-tmsearch test.i
(although this does not seem to be Python-specific), I get the following output:
test.i:11: Searching for a suitable 'in' typemap for: myarray a
Looking for: myarray a
Looking for: myarray
Looking for: double a[7]
Looking for: double [7]
Looking for: double a[ANY]
Looking for: double [ANY]
Looking for: SWIGTYPE a[ANY]
Looking for: SWIGTYPE [ANY]
Using: %typemap(in) SWIGTYPE [ANY]
test.i:11: Searching for a suitable 'in' typemap for: myarray const b
Looking for: myarray const b
Looking for: myarray const
Looking for: myarray b
Looking for: myarray
Looking for: double const b[7]
Looking for: double const [7]
Looking for: double b[7]
Looking for: double [7]
Looking for: double b[ANY]
Looking for: double [ANY]
Looking for: SWIGTYPE const b[ANY]
Looking for: SWIGTYPE const [ANY]
Looking for: SWIGTYPE const b[]
Looking for: SWIGTYPE const []
Looking for: SWIGTYPE *const b
Looking for: SWIGTYPE *const
Using: %apply SWIGTYPE * { SWIGTYPE *const }
i.e. the typemap is correctly found for type myarray, but not for myarray const. For some reason SWIGTYPE const [ANY] is being rejected.
If I manually apply the typemap by uncommenting the %apply line in test.i, however, it works:
test.i:11: Searching for a suitable 'in' typemap for: myarray a
Looking for: myarray a
Looking for: myarray
Looking for: double a[7]
Looking for: double [7]
Using: %apply SWIGTYPE [ANY] { double [7] }
test.i:11: Searching for a suitable 'in' typemap for: myarray const b
Looking for: myarray const b
Looking for: myarray const
Looking for: myarray b
Looking for: myarray
Looking for: double const b[7]
Looking for: double const [7]
Looking for: double b[7]
Looking for: double [7]
Using: %apply SWIGTYPE [ANY] { double [7] }
and $1_dim0 is given the correct value (7) in the wrapping code.
Moved to github: https://github.com/swig/swig/pull/28