diff options
41 files changed, 477 insertions, 122 deletions
diff --git a/CHANGES.current b/CHANGES.current index 883963f27..0be45290b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,76 @@ Version 2.0.0 (in progress) ============================ +2010-04-01: wsfulton + Numerous subtle typemap matching rule fixes when using the default type. The typemap + matching rules are to take a type and find the best default typemap (SWIGTYPE, SWIGTYPE* etc), + then look for the next best match by reducing the chosen default type. The type reduction + now follows C++ template partial specialization matching rules. + + Below are the set of changes made showing the default type reduction + along with the old reduced type and the new version of the reduced type: + + SWIGTYPE const &[ANY] + new: SWIGTYPE const &[] + old: SWIGTYPE (&)[ANY] + + SWIGTYPE *const [ANY] + new: SWIGTYPE const [ANY] + old: SWIGTYPE *[ANY] + + SWIGTYPE const *const [ANY] + new: SWIGTYPE *const [ANY] + old: SWIGTYPE const *[ANY] + + SWIGTYPE const *const & + new: SWIGTYPE *const & + old: SWIGTYPE const *& + + SWIGTYPE *const * + new: SWIGTYPE const * + old: SWIGTYPE ** + + SWIGTYPE *const & + new: SWIGTYPE const & + old: SWIGTYPE *& + + Additionally, a const SWIGTYPE lookup is used now for any constant type. Some examples, where + T is some reduced type, eg int, struct Foo: + + T const + new: SWIGTYPE const + old: SWIGTYPE + + T *const + new: SWIGTYPE *const + old: SWIGTYPE * + + T const[] + new: SWIGTYPE const[] + old: SWIGTYPE[] + + enum T const + new: enum SWIGTYPE const + old: enum SWIGTYPE + + T (*const )[] + new: SWIGTYPE (*const )[] + old: SWIGTYPE (*)[] + + Reminder: the typemap matching rules can now be seen for any types being wrapped by using + either the -debug-tmsearch or -debug-tmused options. + + In practice this leads to some subtle matching rule changes and the majority of users + won't notice any changes, except in the prime area of motivation for this change: Improve + STL containers of const pointers and passing const pointers by reference. This is fixed + because many of the STL containers use a type 'T const&' as parameters and when T is + a const pointer, for example, 'K const*', then the full type is 'K const*const&'. This + means that the 'SWIGTYPE *const&' typemaps now match when T is either a non-const or + const pointer. Furthermore, some target languages incorrectly had 'SWIGTYPE *&' typemaps + when these should have been 'SWIGTYPE *const&'. These have been corrected (Java, C#, Lua, PHP). + + *** POTENTIAL INCOMPATIBILITY *** + 2010-03-13: wsfulton [Java] Some very old deprecated pragma warnings are now errors. diff --git a/Examples/test-suite/constant_pointers.i b/Examples/test-suite/constant_pointers.i index c2344fb6a..277d3cc75 100644 --- a/Examples/test-suite/constant_pointers.i +++ b/Examples/test-suite/constant_pointers.i @@ -70,6 +70,8 @@ public: void ret6(int*& a) {} int*& ret7() {return GlobalIntPtr;} + void ret8(int*const& a) {} + int*const& ret9() {return GlobalIntPtr;} ReturnValuesTest() : int3(NULL) {} private: ReturnValuesTest& operator=(const ReturnValuesTest&); @@ -112,7 +114,7 @@ int* const globalRet2() {return &GlobalInt;} return b; } - B const*& cbar(B const*& b) { + B *const& cbar(B *const& b) { return b; } } diff --git a/Examples/test-suite/global_namespace.i b/Examples/test-suite/global_namespace.i index 31dbb9e59..7b575614f 100644 --- a/Examples/test-suite/global_namespace.i +++ b/Examples/test-suite/global_namespace.i @@ -11,8 +11,8 @@ class Klass6 {}; class Klass7 {}; struct KlassMethods { - static void methodA(::Klass1 v, const ::Klass2 cv, const ::Klass3 *cp, ::Klass4 *p, const ::Klass5 &cr, ::Klass6 &r, ::Klass7*& pr) {} - static void methodB( Klass1 v, const Klass2 cv, const Klass3 *cp, Klass4 *p, const Klass5 &cr, Klass6 &r, Klass7*& pr) {} + static void methodA(::Klass1 v, const ::Klass2 cv, const ::Klass3 *cp, ::Klass4 *p, const ::Klass5 &cr, ::Klass6 &r, ::Klass7*const& pr) {} + static void methodB( Klass1 v, const Klass2 cv, const Klass3 *cp, Klass4 *p, const Klass5 &cr, Klass6 &r, Klass7*const& pr) {} }; %} @@ -28,8 +28,8 @@ class XYZ7 {}; } struct XYZMethods { - static void methodA(::Space::XYZ1 v, const ::Space::XYZ2 cv, const ::Space::XYZ3 *cp, ::Space::XYZ4 *p, const ::Space::XYZ5 &cr, ::Space::XYZ6 &r, ::Space::XYZ7*& pr) {} - static void methodB( Space::XYZ1 v, const Space::XYZ2 cv, const Space::XYZ3 *cp, Space::XYZ4 *p, const Space::XYZ5 &cr, Space::XYZ6 &r, Space::XYZ7*& pr) {} + static void methodA(::Space::XYZ1 v, const ::Space::XYZ2 cv, const ::Space::XYZ3 *cp, ::Space::XYZ4 *p, const ::Space::XYZ5 &cr, ::Space::XYZ6 &r, ::Space::XYZ7*const& pr) {} + static void methodB( Space::XYZ1 v, const Space::XYZ2 cv, const Space::XYZ3 *cp, Space::XYZ4 *p, const Space::XYZ5 &cr, Space::XYZ6 &r, Space::XYZ7*const& pr) {} }; %} diff --git a/Examples/test-suite/java_pgcpp.i b/Examples/test-suite/java_pgcpp.i index 6a50ffe72..6bfef9316 100644 --- a/Examples/test-suite/java_pgcpp.i +++ b/Examples/test-suite/java_pgcpp.i @@ -16,21 +16,21 @@ %typemap(jstype) Space::Classic ** " Classic " %typemap(javain) Space::Classic ** "Classic.getCPtr($javainput)" -// Default typemaps for pass by value, ref, pointer and pointer reference should use pgcpp +// Default typemaps for pass by value, ref, pointer and pointer const reference should use pgcpp %inline %{ namespace Space { struct Classic { Classic() {} - Classic(Classic c1, Classic& c2, Classic* c3, Classic*& c4, Classic** c5) {} - Classic(const Classic c1, const Classic& c2, const Classic* c3, const Classic*& c4, const Classic** c5, bool b) {} + Classic(Classic c1, Classic& c2, Classic* c3, Classic*const& c4, Classic** c5) {} + Classic(const Classic c1, const Classic& c2, const Classic* c3, const Classic*const& c4, const Classic** c5, bool b) {} - void method(Classic c1, Classic& c2, Classic* c3, Classic*& c4, Classic** c5) {} - void methodconst(const Classic c1, const Classic& c2, const Classic* c3, const Classic*& c4, const Classic** c5) {} + void method(Classic c1, Classic& c2, Classic* c3, Classic*const& c4, Classic** c5) {} + void methodconst(const Classic c1, const Classic& c2, const Classic* c3, const Classic*const& c4, const Classic** c5) {} }; - void function(Classic c1, Classic& c2, Classic* c3, Classic*& c4, Classic** c5) {} - void functionconst(const Classic c1, const Classic& c2, const Classic* c3, const Classic*& c4, const Classic** c5) {} + void function(Classic c1, Classic& c2, Classic* c3, Classic*const& c4, Classic** c5) {} + void functionconst(const Classic c1, const Classic& c2, const Classic* c3, const Classic*const& c4, const Classic** c5) {} } %} diff --git a/Examples/test-suite/li_boost_intrusive_ptr.i b/Examples/test-suite/li_boost_intrusive_ptr.i index 7c37e6843..47b64682a 100644 --- a/Examples/test-suite/li_boost_intrusive_ptr.i +++ b/Examples/test-suite/li_boost_intrusive_ptr.i @@ -295,7 +295,7 @@ Klass& reftest(Klass& k) { k.append(" reftest");
return k;
}
-Klass*& pointerreftest(Klass*& k) {
+Klass *const& pointerreftest(Klass *const& k) {
k->append(" pointerreftest");
return k;
}
@@ -334,7 +334,7 @@ std::string overload_rawbyptr(int i) { return "int"; } std::string overload_rawbyptr(Klass *k) { return "rawbyptr"; }
std::string overload_rawbyptrref(int i) { return "int"; }
-std::string overload_rawbyptrref(Klass *&k) { return "rawbyptrref"; }
+std::string overload_rawbyptrref(Klass *const&k) { return "rawbyptrref"; }
diff --git a/Examples/test-suite/li_boost_shared_ptr.i b/Examples/test-suite/li_boost_shared_ptr.i index f992a3c08..7a9468e4f 100644 --- a/Examples/test-suite/li_boost_shared_ptr.i +++ b/Examples/test-suite/li_boost_shared_ptr.i @@ -222,7 +222,7 @@ Klass& reftest(Klass& k) { k.append(" reftest"); return k; } -Klass*& pointerreftest(Klass*& k) { +Klass *const& pointerreftest(Klass *const& k) { k->append(" pointerreftest"); return k; } @@ -275,7 +275,7 @@ std::string overload_rawbyptr(int i) { return "int"; } std::string overload_rawbyptr(Klass *k) { return "rawbyptr"; } std::string overload_rawbyptrref(int i) { return "int"; } -std::string overload_rawbyptrref(Klass *&k) { return "rawbyptrref"; } +std::string overload_rawbyptrref(Klass *const&k) { return "rawbyptrref"; } diff --git a/Examples/test-suite/pointer_reference.i b/Examples/test-suite/pointer_reference.i index b7c605429..c57a32374 100644 --- a/Examples/test-suite/pointer_reference.i +++ b/Examples/test-suite/pointer_reference.i @@ -29,10 +29,10 @@ struct Struct { static Struct *pInstance; }; -void set(Struct *& s) { +void set(Struct *const& s) { Struct::instance = *s; } -Struct *& get() { +Struct *const& get() { return Struct::pInstance; } %} diff --git a/Lib/allegrocl/allegrocl.swg b/Lib/allegrocl/allegrocl.swg index 266303113..cc23a1f90 100644 --- a/Lib/allegrocl/allegrocl.swg +++ b/Lib/allegrocl/allegrocl.swg @@ -219,6 +219,12 @@ $body)" %typemap(lispclass) wchar_t* "cl:string"; ////////////////////////////////////////////////////////////// +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + /* name conversion for overloaded operators. */ #ifdef __cplusplus %rename(__add__) *::operator+; diff --git a/Lib/cffi/cffi.swg b/Lib/cffi/cffi.swg index c832e00d2..6ac82f45e 100644 --- a/Lib/cffi/cffi.swg +++ b/Lib/cffi/cffi.swg @@ -130,6 +130,11 @@ %typemap(lispclass) double "cl:number"; %typemap(lispclass) char * "cl:string"; +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } %{ diff --git a/Lib/chicken/chicken.swg b/Lib/chicken/chicken.swg index 68f022570..112780499 100644 --- a/Lib/chicken/chicken.swg +++ b/Lib/chicken/chicken.swg @@ -680,6 +680,16 @@ $result = C_SCHEME_UNDEFINED; %apply unsigned long { size_t }; /* ------------------------------------------------------------ + * Various + * ------------------------------------------------------------ */ + +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + +/* ------------------------------------------------------------ * Overloaded operator support * ------------------------------------------------------------ */ diff --git a/Lib/csharp/boost_shared_ptr.i b/Lib/csharp/boost_shared_ptr.i index 52ac510ce..86a62c33c 100644 --- a/Lib/csharp/boost_shared_ptr.i +++ b/Lib/csharp/boost_shared_ptr.i @@ -44,10 +44,10 @@ %{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %} // plain pointer by reference -%typemap(in) CONST TYPE *& ($*1_ltype temp = 0) -%{ temp = (((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0); +%typemap(in) TYPE *CONST& ($*1_ltype temp = 0) +%{ temp = (TYPE *)(((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0); $1 = &temp; %} -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE *& +%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& %{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %} // shared_ptr by value @@ -138,7 +138,7 @@ PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode return ret; } -%typemap(csout, excode=SWIGEXCODE) CONST TYPE *& { +%typemap(csout, excode=SWIGEXCODE) TYPE *CONST& { IntPtr cPtr = $imcall; PROXYCLASS ret = (cPtr == IntPtr.Zero) ? null : new PROXYCLASS(cPtr, true);$excode return ret; diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index 1f58db48d..57998b9db 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -522,6 +522,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { SWIGTYPE, SWIGTYPE *, SWIGTYPE &, + SWIGTYPE *const&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" @@ -782,24 +783,21 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) { } %} /* Pointer reference typemaps */ -%typemap(ctype) SWIGTYPE *& "void *" -%typemap(imtype, out="IntPtr") SWIGTYPE *& "HandleRef" -%typemap(cstype) SWIGTYPE *& "$*csclassname" -%typemap(csin) SWIGTYPE *& "$*csclassname.getCPtr($csinput)" -%typemap(csout, excode=SWIGEXCODE) SWIGTYPE *& { +%typemap(ctype) SWIGTYPE *const& "void *" +%typemap(imtype, out="IntPtr") SWIGTYPE *const& "HandleRef" +%typemap(cstype) SWIGTYPE *const& "$*csclassname" +%typemap(csin) SWIGTYPE *const& "$*csclassname.getCPtr($csinput)" +%typemap(csout, excode=SWIGEXCODE) SWIGTYPE *const& { IntPtr cPtr = $imcall; $*csclassname ret = (cPtr == IntPtr.Zero) ? null : new $*csclassname(cPtr, $owner);$excode return ret; } -%typemap(in) SWIGTYPE *& ($*1_ltype temp = 0) +%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0) %{ temp = ($*1_ltype)$input; - $1 = &temp; %} -%typemap(out) SWIGTYPE *& + $1 = ($1_ltype)&temp; %} +%typemap(out) SWIGTYPE *const& %{ $result = (void *)*$1; %} -/* Array reference typemaps */ -%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } - /* Marshal C/C++ pointer to IntPtr */ %typemap(ctype) void *VOID_INT_PTR "void *" %typemap(imtype) void *VOID_INT_PTR "IntPtr" @@ -953,6 +951,12 @@ using System.Runtime.InteropServices; %apply unsigned long { size_t }; %apply const unsigned long & { const size_t & }; +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + /* csharp keywords */ %include <csharpkw.swg> diff --git a/Lib/guile/std_map.i b/Lib/guile/std_map.i index 19c863096..600075ebe 100644 --- a/Lib/guile/std_map.i +++ b/Lib/guile/std_map.i @@ -224,7 +224,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& __getitem__(const K& key) throw (std::out_of_range) { + const T& __getitem__(const K& key) throw (std::out_of_range) { std::map<K,T >::iterator i = self->find(key); if (i != self->end()) return i->second; diff --git a/Lib/guile/std_vector.i b/Lib/guile/std_vector.i index 6801daee8..6a5e8ae36 100644 --- a/Lib/guile/std_vector.i +++ b/Lib/guile/std_vector.i @@ -208,7 +208,7 @@ namespace std { self->pop_back(); return x; } - T& ref(int i) throw (std::out_of_range) { + const T& ref(int i) throw (std::out_of_range) { int size = int(self->size()); if (i>=0 && i<size) return (*self)[i]; diff --git a/Lib/guile/typemaps.i b/Lib/guile/typemaps.i index 4f306f7f8..c194d4bc9 100644 --- a/Lib/guile/typemaps.i +++ b/Lib/guile/typemaps.i @@ -448,4 +448,10 @@ typedef unsigned long SCM; $1 = SWIG_CheckState(res); } +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + /* typemaps.i ends here */ diff --git a/Lib/java/boost_intrusive_ptr.i b/Lib/java/boost_intrusive_ptr.i index 9b9e1755f..f7b7da32f 100644 --- a/Lib/java/boost_intrusive_ptr.i +++ b/Lib/java/boost_intrusive_ptr.i @@ -69,12 +69,12 @@ #endif
%}
-%typemap(in) CONST TYPE *& ($*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
+%typemap(in) TYPE *CONST& ($*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
// plain pointer by reference
- temp = ((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
+ temp = ($*1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
$1 = &temp;
%}
-%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") CONST TYPE *& %{
+%typemap(out, fragment="SWIG_intrusive_deleter,SWIG_null_deleter") TYPE *CONST& %{
// plain pointer by reference(out)
#if ($owner)
if (*$1) {
@@ -246,7 +246,7 @@ long cPtr = $jnicall;
return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
}
-%typemap(javaout) CONST TYPE *& {
+%typemap(javaout) TYPE *CONST& {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
}
@@ -353,10 +353,10 @@ %{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %}
// plain pointer by reference
-%typemap(in) CONST TYPE *& ($*1_ltype temp = 0)
-%{ temp = ((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
+%typemap(in) TYPE *CONST& ($*1_ltype temp = 0)
+%{ temp = ($*1_ltype)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0);
$1 = &temp; %}
-%typemap(out, fragment="SWIG_null_deleter") CONST TYPE *&
+%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST&
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %}
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > swigSharedPtrUpcast ($&1_type smartarg) %{
@@ -396,7 +396,7 @@ long cPtr = $jnicall;
return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
}
-%typemap(javaout) CONST TYPE *& {
+%typemap(javaout) TYPE *CONST& {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true);
}
diff --git a/Lib/java/boost_shared_ptr.i b/Lib/java/boost_shared_ptr.i index 38262f20c..1c74a2453 100644 --- a/Lib/java/boost_shared_ptr.i +++ b/Lib/java/boost_shared_ptr.i @@ -44,10 +44,10 @@ %{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %} // plain pointer by reference -%typemap(in) CONST TYPE *& ($*1_ltype temp = 0) -%{ temp = ((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); +%typemap(in) TYPE *CONST& ($*1_ltype temp = 0) +%{ temp = (TYPE *)((*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) ? (*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input)->get() : 0); $1 = &temp; %} -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE *& +%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& %{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %} // shared_ptr by value @@ -132,7 +132,7 @@ long cPtr = $jnicall; return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true); } -%typemap(javaout) CONST TYPE *& { +%typemap(javaout) TYPE *CONST& { long cPtr = $jnicall; return (cPtr == 0) ? null : new PROXYCLASS(cPtr, true); } diff --git a/Lib/java/java.swg b/Lib/java/java.swg index 2dfbe59f2..0fadf1604 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -897,6 +897,7 @@ SWIGTYPE, SWIGTYPE *, SWIGTYPE &, + SWIGTYPE *const&, SWIGTYPE [], SWIGTYPE (CLASS::*) "" @@ -1025,23 +1026,20 @@ } /* Pointer reference typemaps */ -%typemap(jni) SWIGTYPE *& "jlong" -%typemap(jtype) SWIGTYPE *& "long" -%typemap(jstype) SWIGTYPE *& "$*javaclassname" -%typemap(javain) SWIGTYPE *& "$*javaclassname.getCPtr($javainput)" -%typemap(javaout) SWIGTYPE *& { +%typemap(jni) SWIGTYPE *const& "jlong" +%typemap(jtype) SWIGTYPE *const& "long" +%typemap(jstype) SWIGTYPE *const& "$*javaclassname" +%typemap(javain) SWIGTYPE *const& "$*javaclassname.getCPtr($javainput)" +%typemap(javaout) SWIGTYPE *const& { long cPtr = $jnicall; return (cPtr == 0) ? null : new $*javaclassname(cPtr, $owner); } -%typemap(in) SWIGTYPE *& ($*1_ltype temp = 0) +%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0) %{ temp = *($1_ltype)&$input; - $1 = &temp; %} -%typemap(out) SWIGTYPE *& + $1 = ($1_ltype)&temp; %} +%typemap(out) SWIGTYPE *const& %{ *($1_ltype)&$result = *$1; %} -/* Array reference typemaps */ -%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } - /* Typemaps used for the generation of proxy and type wrapper class code */ %typemap(javabase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "" %typemap(javaclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class" @@ -1203,6 +1201,12 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE) %apply unsigned long { size_t }; %apply const unsigned long & { const size_t & }; +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + /* java keywords */ %include <javakw.swg> diff --git a/Lib/lua/lua.swg b/Lib/lua/lua.swg index c3f5cecc5..5218bf0a8 100644 --- a/Lib/lua/lua.swg +++ b/Lib/lua/lua.swg @@ -40,7 +40,7 @@ %typemap(consttab) long long, unsigned long long { SWIG_LUA_STRING, (char *) "$symname", 0, 0, (void *)"$value", 0} -%typemap(consttab) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] +%typemap(consttab) SWIGTYPE *, SWIGTYPE *const, SWIGTYPE &, SWIGTYPE [] { SWIG_LUA_POINTER, (char *)"$symname", 0, 0, (void *)$value, &$1_descriptor} // member function pointers diff --git a/Lib/lua/luatypemaps.swg b/Lib/lua/luatypemaps.swg index 401541267..58f42eea1 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -167,11 +167,11 @@ temp=($basetype)lua_tonumber(L,$input); $1=&temp;%} // Also needed for object ptrs by const ref // eg A* const& ref_pointer(A* const& a); // found in mixed_types.i -%typemap(in,checkfn="lua_isuserdata") SWIGTYPE *&($*ltype temp) +%typemap(in,checkfn="lua_isuserdata") SWIGTYPE *const&($*ltype temp) %{temp=($*ltype)SWIG_MustGetPtr(L,$input,$*descriptor,0,$argnum,"$symname"); -$1=&temp;%} +$1=($1_ltype)&temp;%} -%typemap(out) SWIGTYPE *& +%typemap(out) SWIGTYPE *const& %{SWIG_NewPointerObj(L,*$1,$*descriptor,$owner); SWIG_arg++; %} @@ -335,7 +335,7 @@ parmeters match which function // Also needed for object ptrs by const ref // eg const A* ref_pointer(A* const& a); // found in mixed_types.i -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE* const & +%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const& { void *ptr; if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr(L,$input, (void **) &ptr, $*descriptor, 0)) { @@ -352,6 +352,9 @@ parmeters match which function // Array reference typemaps %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + // size_t (which is just a unsigned long) %apply unsigned long { size_t }; %apply const unsigned long & { const size_t & }; diff --git a/Lib/modula3/modula3.swg b/Lib/modula3/modula3.swg index 599a12e5a..3affdd0de 100644 --- a/Lib/modula3/modula3.swg +++ b/Lib/modula3/modula3.swg @@ -745,3 +745,10 @@ FROM BlaBla IMPORT Bla; /* Some ANSI C typemaps */ %apply unsigned long { size_t }; + +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + diff --git a/Lib/mzscheme/typemaps.i b/Lib/mzscheme/typemaps.i index b9f22440c..f12513df8 100644 --- a/Lib/mzscheme/typemaps.i +++ b/Lib/mzscheme/typemaps.i @@ -349,3 +349,10 @@ REF_MAP(double, SCHEME_REALP, scheme_real_to_double, } +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + + diff --git a/Lib/ocaml/std_map.i b/Lib/ocaml/std_map.i index f202e74ed..d7bf1e0f7 100644 --- a/Lib/ocaml/std_map.i +++ b/Lib/ocaml/std_map.i @@ -29,7 +29,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& get(const K& key) throw (std::out_of_range) { + const T& get(const K& key) throw (std::out_of_range) { std::map<K,T >::iterator i = self->find(key); if (i != self->end()) return i->second; diff --git a/Lib/ocaml/typemaps.i b/Lib/ocaml/typemaps.i index 39544de94..e5458a3e2 100644 --- a/Lib/ocaml/typemaps.i +++ b/Lib/ocaml/typemaps.i @@ -314,3 +314,11 @@ SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val); %swig_enum_out(out) %swig_enum_out(varout) %swig_enum_out(directorin) + + +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + diff --git a/Lib/octave/boost_shared_ptr.i b/Lib/octave/boost_shared_ptr.i index 2a3c1532f..d702108a6 100644 --- a/Lib/octave/boost_shared_ptr.i +++ b/Lib/octave/boost_shared_ptr.i @@ -143,7 +143,7 @@ // plain pointer by reference // Note: $disown not implemented as it will lead to a memory leak of the shared_ptr instance -%typemap(in) CONST TYPE *& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { +%typemap(in) TYPE *CONST& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { int newmem = 0; res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { @@ -158,15 +158,15 @@ } $1 = &temp; } -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE *& { +%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } -%typemap(varin) CONST TYPE *& %{ +%typemap(varin) TYPE *CONST& %{ #error "varin typemap not implemented" %} -%typemap(varout) CONST TYPE *& %{ +%typemap(varout) TYPE *CONST& %{ #error "varout typemap not implemented" %} @@ -283,10 +283,10 @@ // Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting // function is not called thereby avoiding a possible smart pointer copy constructor call when casting up the inheritance chain. %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) - CONST TYPE, - CONST TYPE &, - CONST TYPE *, - CONST TYPE *&, + TYPE CONST, + TYPE CONST &, + TYPE CONST *, + TYPE *CONST&, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, diff --git a/Lib/perl5/perltypemaps.swg b/Lib/perl5/perltypemaps.swg index a59f84689..540974476 100644 --- a/Lib/perl5/perltypemaps.swg +++ b/Lib/perl5/perltypemaps.swg @@ -75,7 +75,7 @@ %include <typemaps/swigtypemaps.swg> /* ------------------------------------------------------------ - * Perl extra typemaps + * Perl extra typemaps / typemap overrides * ------------------------------------------------------------ */ %typemap(varout,type="$1_descriptor") SWIGTYPE *, SWIGTYPE [] @@ -90,3 +90,6 @@ %typemap(varout,type="$1_descriptor") SWIGTYPE (CLASS::*) { SWIG_MakePackedObj($result, (void *) &$1, sizeof($1_type), $1_descriptor); } + +%typemap(varout) SWIGTYPE *const = SWIGTYPE *; + diff --git a/Lib/perl5/std_map.i b/Lib/perl5/std_map.i index b19414597..ab0d3816d 100644 --- a/Lib/perl5/std_map.i +++ b/Lib/perl5/std_map.i @@ -30,7 +30,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& get(const K& key) throw (std::out_of_range) { + const T& get(const K& key) throw (std::out_of_range) { std::map<K,T >::iterator i = self->find(key); if (i != self->end()) return i->second; diff --git a/Lib/php/php.swg b/Lib/php/php.swg index feeb9c5df..ff4001d7e 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -115,12 +115,12 @@ } } -%typemap(in) SWIGTYPE *& ($*ltype temp) +%typemap(in) SWIGTYPE *const& ($*ltype temp) { if(SWIG_ConvertPtr(*$input, (void **) &temp, $*1_descriptor, 0) < 0) { SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor"); } - $1 = &temp; + $1 = ($1_ltype)&temp; } %typemap(in) SWIGTYPE *DISOWN @@ -339,7 +339,7 @@ SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner); %} -%typemap(out) SWIGTYPE *& +%typemap(out) SWIGTYPE *const& %{ SWIG_SetPointerZval(return_value, (void *)*$1, $*1_descriptor, $owner); %} @@ -394,10 +394,6 @@ SWIG_SetPointerZval($input, SWIG_as_voidptr(&$1_name), $&1_descriptor, 2); } -/* Array reference typemaps */ -%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } - - %typemap(out) void ""; %typemap(out) char [ANY] @@ -441,10 +437,11 @@ _v = (SWIG_ConvertPtr(*$input, (void **)&tmp, $&1_descriptor, 0) >= 0); } -%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, +%typecheck(SWIG_TYPECHECK_POINTER) + SWIGTYPE *, SWIGTYPE [], SWIGTYPE &, - SWIGTYPE *& + SWIGTYPE *const& { void *tmp; _v = (SWIG_ConvertPtr(*$input, (void**)&tmp, $1_descriptor, 0) >= 0); @@ -478,6 +475,12 @@ SWIG_PHP_Error(E_ERROR, (char *)$1); %} +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + /* php keywords */ %include <phpkw.swg> diff --git a/Lib/php/std_map.i b/Lib/php/std_map.i index cfb82f44c..b6b417da7 100644 --- a/Lib/php/std_map.i +++ b/Lib/php/std_map.i @@ -29,7 +29,7 @@ namespace std { unsigned int size() const; void clear(); %extend { - T& get(const K& key) throw (std::out_of_range) { + const T& get(const K& key) throw (std::out_of_range) { std::map<K,T >::iterator i = self->find(key); if (i != self->end()) return i->second; diff --git a/Lib/pike/pike.swg b/Lib/pike/pike.swg index 2ba27671e..0cfec52b0 100644 --- a/Lib/pike/pike.swg +++ b/Lib/pike/pike.swg @@ -264,6 +264,12 @@ extern "C" { } } +/* Array reference typemaps */ +%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } + +/* const pointers */ +%apply SWIGTYPE * { SWIGTYPE *const } + /* ------------------------------------------------------------ * Overloaded operator support * ------------------------------------------------------------ */ diff --git a/Lib/python/boost_shared_ptr.i b/Lib/python/boost_shared_ptr.i index d5dffcda9..59a3a9298 100644 --- a/Lib/python/boost_shared_ptr.i +++ b/Lib/python/boost_shared_ptr.i @@ -151,7 +151,7 @@ // plain pointer by reference // Note: $disown not implemented by default as it will lead to a memory leak of the shared_ptr instance -%typemap(in) CONST TYPE *& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { +%typemap(in) TYPE *CONST& (void *argp = 0, int res = 0, $*1_ltype temp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempshared) { int newmem = 0; res = SWIG_ConvertPtrAndOwn($input, &argp, $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SHARED_PTR_DISOWN | %convertptr_flags, &newmem); if (!SWIG_IsOK(res)) { @@ -166,15 +166,15 @@ } $1 = &temp; } -%typemap(out, fragment="SWIG_null_deleter") CONST TYPE *& { +%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST& { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); } -%typemap(varin) CONST TYPE *& %{ +%typemap(varin) TYPE *CONST& %{ #error "varin typemap not implemented" %} -%typemap(varout) CONST TYPE *& %{ +%typemap(varout) TYPE *CONST& %{ #error "varout typemap not implemented" %} @@ -291,10 +291,10 @@ // Note: SWIG_ConvertPtr with void ** parameter set to 0 instead of using SWIG_ConvertPtrAndOwn, so that the casting // function is not called thereby avoiding a possible smart pointer copy constructor call when casting up the inheritance chain. %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) - CONST TYPE, - CONST TYPE &, - CONST TYPE *, - CONST TYPE *&, + TYPE CONST, + TYPE CONST &, + TYPE CONST *, + TYPE *CONST&, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *, diff --git a/Lib/python/pytypemaps.swg b/Lib/python/pytypemaps.swg index e8df069ef..817ed1d90 100644 --- a/Lib/python/pytypemaps.swg +++ b/Lib/python/pytypemaps.swg @@ -61,7 +61,7 @@ /* ------------------------------------------------------------ - * Python extra typemaps + * Python extra typemaps / typemap overrides * ------------------------------------------------------------ */ /* Get the address of the 'python self' object */ diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index ee01d07d7..5103e43db 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -29,8 +29,10 @@ %typemap("rtype") bool, bool * "logical"; %typemap("rtype") enum SWIGTYPE "character"; %typemap("rtype") enum SWIGTYPE * "character"; +%typemap("rtype") enum SWIGTYPE *const "character"; %typemap("rtype") enum SWIGTYPE & "character"; %typemap("rtype") SWIGTYPE * "$R_class"; +%typemap("rtype") SWIGTYPE *const "$R_class"; %typemap("rtype") SWIGTYPE & "$R_class"; %typemap("rtype") SWIGTYPE "$&R_class"; @@ -65,13 +67,15 @@ %{ $input = enumToInteger($input, "$R_class"); %} %typemap(scoercein) enum SWIGTYPE * %{ $input = enumToInteger($input, "$R_class"); %} +%typemap(scoercein) enum SWIGTYPE *const + %{ $input = enumToInteger($input, "$R_class"); %} -%typemap(scoercein) SWIGTYPE, SWIGTYPE *, SWIGTYPE & +%typemap(scoercein) SWIGTYPE, SWIGTYPE *, SWIGTYPE *const, SWIGTYPE & %{ %} /* -%typemap(scoercein) SWIGTYPE * +%typemap(scoercein) SWIGTYPE *, SWIGTYPE *const %{ $input = coerceIfNotSubclass($input, "$R_class") %} %typemap(scoercein) SWIGTYPE & @@ -115,6 +119,9 @@ string &, std::string & %typemap(scoerceout) enum SWIGTYPE * %{ $result = enumToInteger($result, "$R_class"); %} +%typemap(scoerceout) enum SWIGTYPE *const + %{ $result = enumToInteger($result, "$R_class"); %} + %typemap(scoerceout) SWIGTYPE %{ class($result) <- "$&R_class"; %} @@ -125,6 +132,9 @@ string &, std::string & %typemap(scoerceout) SWIGTYPE * %{ class($result) <- "$R_class"; %} +%typemap(scoerceout) SWIGTYPE *const + %{ class($result) <- "$R_class"; %} + /* Override the SWIGTYPE * above. */ %typemap(scoerceout) char, char *, diff --git a/Lib/tcl/std_map.i b/Lib/tcl/std_map.i index 006a62efd..9d27e0f39 100644 --- a/Lib/tcl/std_map.i +++ b/Lib/tcl/std_map.i @@ -31,7 +31,7 @@ namespace std { bool empty() const; void clear(); %extend { - T& get(const K& key) throw (std::out_of_range) { + const T& get(const K& key) throw (std::out_of_range) { std::map<K,T >::iterator i = self->find(key); if (i != self->end()) return i->second; diff --git a/Lib/tcl/tcltypemaps.swg b/Lib/tcl/tcltypemaps.swg index 7199e674c..d93c8869b 100644 --- a/Lib/tcl/tcltypemaps.swg +++ b/Lib/tcl/tcltypemaps.swg @@ -61,7 +61,7 @@ /* ------------------------------------------------------------ - * Tcl extra typemaps + * Tcl extra typemaps / typemap overrides * ------------------------------------------------------------ */ #if 1 @@ -84,6 +84,7 @@ %typemap(out) SWIGTYPE = SWIGTYPE INSTANCE; %typemap(out) SWIGTYPE * = SWIGTYPE *INSTANCE; +%typemap(out) SWIGTYPE *const = SWIGTYPE *; %typemap(out) SWIGTYPE & = SWIGTYPE &INSTANCE; %typemap(out) SWIGTYPE [] = SWIGTYPE INSTANCE[]; %typemap(varout) SWIGTYPE = SWIGTYPE INSTANCE; diff --git a/Lib/typemaps/swigtype.swg b/Lib/typemaps/swigtype.swg index 15f2f9b41..f57766962 100644 --- a/Lib/typemaps/swigtype.swg +++ b/Lib/typemaps/swigtype.swg @@ -21,15 +21,15 @@ %typemap(freearg) SWIGTYPE [] ""; -%typemap(in, noblock=1) SWIGTYPE* const& (void *argp = 0, int res = 0, $*ltype temp) { +%typemap(in, noblock=1) SWIGTYPE *const& (void *argp = 0, int res = 0, $*1_ltype temp) { res = SWIG_ConvertPtr($input, &argp, $*descriptor, $disown | %convertptr_flags); if (!SWIG_IsOK(res)) { %argument_fail(res, "$*ltype", $symname, $argnum); } temp = %reinterpret_cast(argp, $*ltype); - $1 = &temp; + $1 = %reinterpret_cast(&temp, $1_ltype); } -%typemap(freearg) SWIGTYPE* const& ""; +%typemap(freearg) SWIGTYPE *const& ""; /* Reference */ @@ -106,7 +106,7 @@ %set_output(SWIG_NewPointerObj(%as_voidptr($1), $descriptor, $owner | %newpointer_flags)); } -%typemap(out, noblock=1) SWIGTYPE* const& { +%typemap(out, noblock=1) SWIGTYPE *const& { %set_output(SWIG_NewPointerObj(%as_voidptr(*$1), $*descriptor, $owner | %newpointer_flags)); } @@ -299,6 +299,12 @@ $1 = SWIG_CheckState(res); } +%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) SWIGTYPE *const& { + void *vptr = 0; + int res = SWIG_ConvertPtr($input, &vptr, $descriptor, 0); + $1 = SWIG_CheckState(res); +} + %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) SWIGTYPE & { void *vptr = 0; int res = SWIG_ConvertPtr($input, &vptr, $descriptor, 0); @@ -337,7 +343,7 @@ /* directorin */ -%typemap(directorin,noblock=1) SWIGTYPE*, SWIGTYPE* const& { +%typemap(directorin,noblock=1) SWIGTYPE *, SWIGTYPE *const& { $input = SWIG_NewPointerObj(%as_voidptr($1_name), $descriptor, %newpointer_flags); } @@ -345,7 +351,7 @@ $input = SWIG_NewPointerObj(%as_voidptr(&$1_name), $&descriptor, %newpointer_flags); } -%typemap(directorin,noblock=1) SWIGTYPE& { +%typemap(directorin,noblock=1) SWIGTYPE & { $input = SWIG_NewPointerObj(%as_voidptr(&$1_name), $descriptor, %newpointer_flags); } @@ -407,7 +413,7 @@ * --- Constants --- * ------------------------------------------------------------ */ -%typemap(constcode,noblock=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []{ +%typemap(constcode,noblock=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { %set_constant("$symname", SWIG_NewPointerObj(%as_voidptr($value),$descriptor,%newpointer_flags)); } @@ -547,6 +553,7 @@ } #endif +%apply SWIGTYPE * { SWIGTYPE *const } /* ------------------------------------------------------------ * --- Special typemaps --- @@ -602,3 +609,4 @@ %typemap(varout,noblock=1) SWIGTYPE INSTANCE { %set_varoutput(SWIG_NewInstanceObj(%as_voidptr(&$1), $&1_descriptor, %newinstance_flags)); } + diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 778c8e5ba..2bfddc764 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3014,8 +3014,6 @@ Node *Language::classLookup(SwigType *s) { Symtab *stab = 0; SwigType *ty1 = SwigType_typedef_resolve_all(s); SwigType *ty2 = SwigType_strip_qualifiers(ty1); - Delete(ty1); - ty1 = 0; String *base = SwigType_base(ty2); @@ -3052,11 +3050,18 @@ Node *Language::classLookup(SwigType *s) { if (n) { /* Found a match. Look at the prefix. We only allow the cases where where we want a proxy class for the particular type */ - if ((Len(prefix) == 0) || // simple type (pass by value) - (Strcmp(prefix, "p.") == 0) || // pointer - (Strcmp(prefix, "r.") == 0) || // reference - (Strcmp(prefix, "r.p.") == 0) || // pointer by reference - SwigType_prefix_is_simple_1D_array(prefix)) { // Simple 1D array (not arrays of pointers/references) + bool acceptable_prefix = + (Len(prefix) == 0) || // simple type (pass by value) + (Strcmp(prefix, "p.") == 0) || // pointer + (Strcmp(prefix, "r.") == 0) || // reference + SwigType_prefix_is_simple_1D_array(prefix); // Simple 1D array (not arrays of pointers/references) + // Also accept pointer by const reference, not non-const pointer reference + if (!acceptable_prefix && (Strcmp(prefix, "r.p.") == 0)) { + Delete(prefix); + prefix = SwigType_prefix(ty1); + acceptable_prefix = (Strncmp(prefix, "r.q(const", 9) == 0); + } + if (acceptable_prefix) { SwigType *cs = Copy(s); Setattr(classtypes, cs, n); Delete(cs); @@ -3064,9 +3069,10 @@ Node *Language::classLookup(SwigType *s) { n = 0; } } - Delete(ty2); - Delete(base); Delete(prefix); + Delete(base); + Delete(ty2); + Delete(ty1); } if (n && (GetFlag(n, "feature:ignore") || Getattr(n, "feature:onlychildren"))) { n = 0; @@ -3092,10 +3098,6 @@ Node *Language::enumLookup(SwigType *s) { SwigType *lt = SwigType_ltype(s); SwigType *ty1 = SwigType_typedef_resolve_all(lt); SwigType *ty2 = SwigType_strip_qualifiers(ty1); - Delete(lt); - Delete(ty1); - lt = 0; - ty1 = 0; String *base = SwigType_base(ty2); @@ -3134,9 +3136,11 @@ Node *Language::enumLookup(SwigType *s) { n = 0; } } - Delete(ty2); - Delete(base); Delete(prefix); + Delete(base); + Delete(ty2); + Delete(ty1); + Delete(lt); } if (n && (GetFlag(n, "feature:ignore"))) { n = 0; diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c index fd6a06ca0..079fa07fe 100644 --- a/Source/Swig/stype.c +++ b/Source/Swig/stype.c @@ -493,6 +493,186 @@ SwigType *SwigType_default(SwigType *t) { } /* ----------------------------------------------------------------------------- + * SwigType_default_create() + * + * Create the default type for this datatype. This takes a type and strips it + * down to a generic form first by resolving all typedefs. + * + * Rules: + * Pointers: p.SWIGTYPE + * References: r.SWIGTYPE + * Arrays no dimension: a().SWIGTYPE + * Arrays with dimension: a(ANY).SWIGTYPE + * Member pointer: m(CLASS).SWIGTYPE + * Function pointer: f(ANY).SWIGTYPE + * Enums: enum SWIGTYPE + * Types: SWIGTYPE + * + * Examples (also see SwigType_default_reduce): + * + * int [2][4] + * a(2).a(4).int + * a(ANY).a(ANY).SWIGTYPE + * + * struct A {}; + * typedef A *Aptr; + * Aptr const & + * r.q(const).Aptr + * r.q(const).p.SWIGTYPE + * + * enum E {e1, e2}; + * enum E const & + * r.q(const).enum E + * r.q(const).enum SWIGTYPE + * ----------------------------------------------------------------------------- */ + +SwigType *SwigType_default_create(SwigType *ty) { + SwigType *r = 0; + List *l; + Iterator it; + int numitems; + + if (!SwigType_isvarargs(ty)) { + SwigType *t = SwigType_typedef_resolve_all(ty); + r = NewStringEmpty(); + l = SwigType_split(t); + numitems = Len(l); + + if (numitems >= 1) { + String *last_subtype = Getitem(l, numitems-1); + if (SwigType_isenum(last_subtype)) + Setitem(l, numitems-1, NewString("enum SWIGTYPE")); + else + Setitem(l, numitems-1, NewString("SWIGTYPE")); + } + + for (it = First(l); it.item; it = Next(it)) { + String *subtype = it.item; + if (SwigType_isarray(subtype)) { + if (Equal(subtype, "a().")) + Append(r, NewString("a().")); + else + Append(r, NewString("a(ANY).")); + } else if (SwigType_isfunction(subtype)) { + Append(r, NewString("f(ANY).SWIGTYPE")); + break; + } else if (SwigType_ismemberpointer(subtype)) { + Append(r, NewString("m(CLASS).SWIGTYPE")); + break; + } else { + Append(r, subtype); + } + } + + Delete(l); + Delete(t); + } + + return r; +} + +/* ----------------------------------------------------------------------------- + * SwigType_default_reduce() + * + * This function implements type reduction used in the typemap matching rules + * and is very close to the type reduction used in partial template specialization. + * SWIGTYPE is used as the generic type. The basic idea is to repeatedly call + * this function to reduce the type until it is reduced to nothing. + * + * The type t must have already been converted to the default type via a call to + * SwigType_default_create() before calling this function. + * + * Example reductions (matching the examples described in SwigType_default_create): + * + * a(ANY).a(ANY).SWIGTYPE + * a(ANY).a().SWIGTYPE + * a(ANY).p.SWIGTYPE + * a(ANY).SWIGTYPE + * a().SWIGTYPE + * p.SWIGTYPE + * SWIGTYPE + * + * r.q(const).p.SWIGTYPE + * r.q(const).SWIGTYPE + * r.SWIGTYPE + * SWIGTYPE + * + * r.q(const).enum SWIGTYPE + * r.enum SWIGTYPE + * r.SWIGTYPE + * SWIGTYPE + * ----------------------------------------------------------------------------- */ + +SwigType *SwigType_default_reduce(SwigType *t) { + SwigType *r = NewStringEmpty(); + List *l; + Iterator it; + int numitems; + + l = SwigType_split(t); + + numitems = Len(l); + if (numitems >= 1) { + String *last_subtype = Getitem(l, numitems-1); + int is_enum = SwigType_isenum(last_subtype); + + if (numitems >=2 ) { + String *subtype = Getitem(l, numitems-2); /* last but one */ + if (SwigType_isarray(subtype)) { + if (is_enum) { + /* enum reduction, enum SWIGTYPE => SWIGTYPE */ + Setitem(l, numitems-1, NewString("SWIGTYPE")); + } else { + /* array reduction, a(ANY). => a(). => p. */ + String *reduced_subtype = 0; + if (Strcmp(subtype, "a().") == 0) { + reduced_subtype = NewString("p."); + } else if (Strcmp(subtype, "a(ANY).") == 0) { + reduced_subtype = NewString("a()."); + } else { + assert(0); + } + Setitem(l, numitems-2, reduced_subtype); + } + } else if (SwigType_ismemberpointer(subtype)) { + /* member pointer reduction, m(CLASS). => p. */ + Setitem(l, numitems-2, NewString("p.")); + } else if (is_enum && !SwigType_isqualifier(subtype)) { + /* enum reduction, enum SWIGTYPE => SWIGTYPE */ + Setitem(l, numitems-1, NewString("SWIGTYPE")); + } else { + /* simple type reduction, eg, r.p.p. => r.p. */ + /* also function pointers eg, p.f(ANY). => p. */ + Delitem(l, numitems-2); + } + } else { + if (is_enum) { + /* enum reduction, enum SWIGTYPE => SWIGTYPE */ + Setitem(l, numitems-1, NewString("SWIGTYPE")); + } else { + /* delete the only item, we are done with reduction */ + Delitem(l, 0); + } + } + } else { + assert(0); + } + + for (it = First(l); it.item; it = Next(it)) { + Append(r, it.item); + } + + if (Len(r) == 0) { + Delete(r); + r = 0; + } + + Delete(l); + return r; +} + + +/* ----------------------------------------------------------------------------- * SwigType_namestr() * * Returns a string of the base type. Takes care of template expansions diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index b3cb0f158..6228b2f43 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -172,6 +172,8 @@ extern "C" { extern void SwigType_array_setdim(SwigType *t, int n, const_String_or_char_ptr rep); extern SwigType *SwigType_array_type(SwigType *t); extern String *SwigType_default(SwigType *t); + extern SwigType *SwigType_default_create(SwigType *ty); + extern SwigType *SwigType_default_reduce(SwigType *t); extern void SwigType_typename_replace(SwigType *t, String *pat, String *rep); extern SwigType *SwigType_remove_global_scope_prefix(const SwigType *t); extern SwigType *SwigType_alttype(SwigType *t, int ltmap); diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index aaf156d8e..cc32780c5 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -674,7 +674,7 @@ static Hash *typemap_search_helper(int debug_display, Hash *tm, const String *tm if (debug_display) Printf(stdout, " Looking for: %s\n", SwigType_str(ctype, 0)); if (tm) { - result = Getattr(tm, tm_method); /* See if there is simply a type match */ + result = Getattr(tm, tm_method); /* See if there is simply a type without name match */ if (result && Getattr(result, "code")) goto ret_result; if (result) @@ -779,7 +779,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type /* Hmmm. Well, no match seems to be found at all. See if there is some kind of default (SWIGTYPE) mapping */ - primitive = SwigType_default(type); + primitive = SwigType_default_create(type); while (primitive) { tm = get_typemap(ts, primitive); result = typemap_search_helper(debug_display, tm, tm_method, primitive, cqualifiedname, cname, &backup); @@ -787,7 +787,7 @@ static Hash *typemap_search(const_String_or_char_ptr tmap_method, SwigType *type goto ret_result; { - SwigType *nprim = SwigType_default(primitive); + SwigType *nprim = SwigType_default_reduce(primitive); Delete(primitive); primitive = nprim; } diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c index 9ccdfbf7b..a2e23e52d 100644 --- a/Source/Swig/typeobj.c +++ b/Source/Swig/typeobj.c @@ -50,6 +50,9 @@ char cvsroot_typeobj_c[] = "$Id$"; * 'q(str).' = Qualifier (such as const or volatile) (const, volatile) * 'm(qual).' = Pointer to member (qual::*) * + * The complete type representation for varargs is: + * 'v(...)' + * * The encoding follows the order that you might describe a type in words. * For example "p.a(200).int" is "A pointer to array of int's" and * "p.q(const).char" is "a pointer to a const char". @@ -177,6 +180,9 @@ SwigType *SwigType_del_element(SwigType *t) { * SwigType_pop() * * Pop one type element off the type. + * Example: t in: q(const).p.Integer + * t out: p.Integer + * result: q(const). * ----------------------------------------------------------------------------- */ SwigType *SwigType_pop(SwigType *t) { |