From 94f683868adc0a2e25b1315b3a6bffe7a488bd25 Mon Sep 17 00:00:00 2001 From: Lindley French Date: Mon, 15 Jun 2015 14:28:19 -0700 Subject: [PATCH 1/3] Enable variable and typemap substitution in typemap kwargs, and a test that verifies this works for directorin:descriptor. --- Examples/test-suite/java/Makefile.in | 1 + .../java/java_director_ptrclass_runme.java | 47 ++++++++ Examples/test-suite/java_director_ptrclass.i | 107 ++++++++++++++++++ Source/Swig/typemap.c | 28 +++++ 4 files changed, 183 insertions(+) create mode 100644 Examples/test-suite/java/java_director_ptrclass_runme.java create mode 100644 Examples/test-suite/java_director_ptrclass.i diff --git a/Examples/test-suite/java/Makefile.in b/Examples/test-suite/java/Makefile.in index 310f1a773..3dc6555ef 100644 --- a/Examples/test-suite/java/Makefile.in +++ b/Examples/test-suite/java/Makefile.in @@ -27,6 +27,7 @@ CPP_TEST_CASES = \ java_director_assumeoverride \ java_director_exception_feature \ java_director_exception_feature_nspace \ + java_director_ptrclass \ java_enums \ java_jnitypes \ java_lib_arrays_dimensionless \ diff --git a/Examples/test-suite/java/java_director_ptrclass_runme.java b/Examples/test-suite/java/java_director_ptrclass_runme.java new file mode 100644 index 000000000..2d78a8f2e --- /dev/null +++ b/Examples/test-suite/java/java_director_ptrclass_runme.java @@ -0,0 +1,47 @@ + +import java_director_ptrclass.*; + +public class java_director_ptrclass_runme { + + static { + try { + System.loadLibrary("java_director_ptrclass"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + Foo f = new Foo(); + Foo ft = new TouchingFoo(); + Baz b = new Baz(); + if (b.GetTouched()) { + throw new RuntimeException ( "Baz should not have been touched yet." ); + } + + Baz b2 = f.FinalMaybeTouch(b); + + if (b2.GetTouched() || b.GetTouched()) { + throw new RuntimeException ( "Baz should not have been touched by Foo." ); + } + + Baz b3 = ft.FinalMaybeTouch(b); + + if (!b.GetTouched() || !b3.GetTouched() || !b2.GetTouched()) { + throw new RuntimeException ( "Baz was not touched by TouchingFoo. This" + + " might mean the directorin typemap is not" + + " parsing the typemap(jstype, Bar) in its" + + " 'descriptor' kwarg correctly." ); + } + } +} + +class TouchingFoo extends Foo { + @Override + public Baz MaybeTouch(Baz baz_ptr) { + baz_ptr.SetTouched(); + return baz_ptr; + } +} + diff --git a/Examples/test-suite/java_director_ptrclass.i b/Examples/test-suite/java_director_ptrclass.i new file mode 100644 index 000000000..6b4fc1f08 --- /dev/null +++ b/Examples/test-suite/java_director_ptrclass.i @@ -0,0 +1,107 @@ +%module(directors="1") java_director_ptrclass + +// Tests that custom director typemaps can be used with C++ types that +// represent a pointer, in such a way that Java perceives this class as +// equivalent to the underlying type. In particular, this verifies that +// a typemap lookup within a typemap kwarg, in this case +// directorin:descriptor, works as expected. + +%{ +namespace bar { +class Baz { +public: + Baz() : touched(false) {} + void SetTouched() { touched = true; } + bool GetTouched() { return touched; } +private: + bool touched; +}; + +template +class Ptr { +public: + Ptr(T* b) : b_(b) {} + T* Get() const { return b_; } +private: + T* b_; +}; + +class Foo { +public: + // Calling FinalMaybeTouch from Java unambiguously goes through C++ to + // reach MaybeTouch. + Ptr< bar::Baz > FinalMaybeTouch(Baz* b) { + return MaybeTouch(Ptr< bar::Baz >(b)); + } + virtual Ptr< bar::Baz > MaybeTouch(Ptr< bar::Baz > f) { + return f; /* Don't touch */ + } + virtual ~Foo() {} +}; +} +%} + +%feature("director") Foo; + +%typemap(jni) bar::Ptr< bar::Baz > "jlong" +%typemap(jtype) bar::Ptr< bar::Baz > "long" +%typemap(jstype) bar::Ptr< bar::Baz > "Baz" +%typemap(in) bar::Ptr< bar::Baz > { + $1 = bar::Ptr< bar::Baz >(*( bar::Baz**)&$input); +} +%typemap(out) bar::Ptr< bar::Baz > { + const bar::Ptr< bar::Baz >& ptr = $1; + if (ptr.Get()) { + $result = ($typemap(jni, bar::Baz))ptr.Get(); + } else { + $result = 0; + } +} +%typemap(javain) bar::Ptr< bar::Baz > "$typemap(jstype, bar::Baz).getCPtr($javainput)" +%typemap(javaout) bar::Ptr< bar::Baz > { + long cPtr = $jnicall; + return (cPtr == 0) ? null : new $typemap(jstype, bar::Baz)(cPtr, false); +} +%typemap(directorin, descriptor="L$packagepath/$typemap(jstype, bar::Baz);") bar::Ptr< bar::Baz > +%{ *((bar::Baz**)&$input) = ((bar::Ptr< bar::Baz >&)$1).Get(); %} +%typemap(directorout) bar::Ptr< bar::Baz > { + $result = bar::Ptr< bar::Baz >(*( bar::Baz**)&$input); +} +%typemap(javadirectorin) bar::Ptr< bar::Baz > %{ + ((long)$jniinput == 0) ? null : new $typemap(jstype, bar::Baz)($jniinput, false) +%} +%typemap(javadirectorout) bar::Ptr< bar::Baz > "$typemap(jstype, bar::Baz).getCPtr($javacall)" + +namespace bar { +class Baz { +public: + Baz() : touched(false) {} + void SetTouched() { touched = true; } + bool GetTouched() { return touched; } +private: + bool touched; +}; + +template +class Ptr { +public: + Ptr(T* b) : b_(b) {} + T* Get() { return b_; } +private: + T* b_; +}; + +class Foo { +public: + // Calling FinalMaybeTouch from Java unambiguously goes through C++ to + // reach MaybeTouch. + Ptr< bar::Baz > FinalMaybeTouch(Baz* b) { + return MaybeTouch(Ptr< bar::Baz >(b)); + } + virtual Ptr< bar::Baz > MaybeTouch(Ptr< bar::Baz > f) { + return f; /* Don't touch */ + } + virtual ~Foo() {} +}; +} + diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index 23b1e80e9..cee323fb9 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -1397,6 +1397,20 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No String *value = Copy(Getattr(kw, "value")); String *kwtype = Getattr(kw, "type"); char *ckwname = Char(Getattr(kw, "name")); + { + /* Expand variables and typemaps in kwargs. */ + SwigType *ptype = Getattr(node, "type"); + String *pname = Getattr(node, "name"); + String *lname = Getattr(node, "lname"); + SwigType *mtype = Getattr(node, "tmap:match"); + SwigType *matchtype = mtype ? mtype : ptype; + ParmList *parm_sublist; + typemap_replace_vars(value, NULL, matchtype, ptype, pname, lname, 0); + parm_sublist = NewParmWithoutFileLineInfo(ptype, pname); + Setattr(parm_sublist, "lname", lname); + replace_embedded_typemap(value, parm_sublist, NULL, tm); + Delete(parm_sublist); + } if (kwtype) { String *mangle = Swig_string_mangle(kwtype); Append(value, mangle); @@ -1569,6 +1583,20 @@ static void typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr tmap_method while (kw) { String *value = Copy(Getattr(kw, "value")); String *type = Getattr(kw, "type"); + { + /* Expand variables and typemaps in kwargs. */ + SwigType *ptype = Getattr(p, "type"); + String *pname = Getattr(p, "name"); + String *lname = Getattr(p, "lname"); + SwigType *mtype = Getattr(p, "tmap:match"); + SwigType *matchtype = mtype ? mtype : ptype; + ParmList *parm_sublist; + typemap_replace_vars(value, NULL, matchtype, ptype, pname, lname, 0); + parm_sublist = NewParmWithoutFileLineInfo(ptype, pname); + Setattr(parm_sublist, "lname", lname); + replace_embedded_typemap(value, parm_sublist, NULL, tm); + Delete(parm_sublist); + } if (type) { Hash *v = NewHash(); Setattr(v, "type", type); From 2f00f6c8cc6377210312290913662ddacf9e8b69 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 22 Jul 2015 13:02:15 +0100 Subject: [PATCH 2/3] Support special variable expansion in special variable macros in typemap attributes. Add test cases for special variable expansions and special variable macros (aka embedded typemaps) expansion. --- Examples/test-suite/common.mk | 1 + .../special_variable_attributes_runme.cs | 32 ++++ .../test-suite/special_variable_attributes.i | 170 ++++++++++++++++++ Source/Swig/typemap.c | 47 +++-- 4 files changed, 234 insertions(+), 16 deletions(-) create mode 100644 Examples/test-suite/csharp/special_variable_attributes_runme.cs create mode 100644 Examples/test-suite/special_variable_attributes.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 3f3b2216f..cc1ec7464 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -374,6 +374,7 @@ CPP_TEST_CASES += \ smart_pointer_templatevariables \ smart_pointer_typedef \ special_variables \ + special_variable_attributes \ special_variable_macros \ static_array_member \ static_const_member \ diff --git a/Examples/test-suite/csharp/special_variable_attributes_runme.cs b/Examples/test-suite/csharp/special_variable_attributes_runme.cs new file mode 100644 index 000000000..0365ba47c --- /dev/null +++ b/Examples/test-suite/csharp/special_variable_attributes_runme.cs @@ -0,0 +1,32 @@ + +// This is the bool runtime testcase. It checks that the C++ bool type works. + +using System; +using special_variable_attributesNamespace; + +public class special_variable_attributes_runme { + + public static void Main() { + if (special_variable_attributes.getNumber1() != 111) + throw new ApplicationException("getNumber1 failed"); + if (special_variable_attributes.getNumber2() != 222) + throw new ApplicationException("getNumber2 failed"); + if (special_variable_attributes.getNumber3() != 333) + throw new ApplicationException("getNumber3 failed"); + + if (special_variable_attributes.bounceNumber1(10) != 110) + throw new ApplicationException("bounceNumber1 failed"); + if (special_variable_attributes.bounceNumber2(10) != 220) + throw new ApplicationException("bounceNumber2 failed"); + if (special_variable_attributes.bounceNumber3(10) != 330) + throw new ApplicationException("bounceNumber3 failed"); + + if (special_variable_attributes.multi1(12.34) != 12+34) + throw new ApplicationException("multi1 failed"); + if (special_variable_attributes.multi2(12.34) != 12+34+55) + throw new ApplicationException("multi2 failed"); + if (special_variable_attributes.multi3(12.34) != 12+34+77) + throw new ApplicationException("multi3 failed"); + } + +} diff --git a/Examples/test-suite/special_variable_attributes.i b/Examples/test-suite/special_variable_attributes.i new file mode 100644 index 000000000..02dd5f36c --- /dev/null +++ b/Examples/test-suite/special_variable_attributes.i @@ -0,0 +1,170 @@ +%module special_variable_attributes + +// Special variable expansion and special variable macros, aka embedded typemaps - expansion tests +// Tests these are expanded within typemap attributes. +// Also tests that these are expanded when used together, so that the special variables +// can be used as the type passed to the special variable macro. +// C# is used for testing as it is one of the few languages that uses a lot of typemap attributes. +// Attributes in both 'in' and 'out' typemaps are needed, that is, +// typemaps targeting both parameters and return values respectively). + +#ifdef SWIGCSHARP +// Check special variable expansion in typemap attributes. +// This changes return by reference into return by value. +// Takes advantage of the fact that 'int' is a valid type in both C and C#. +// This is not a realistic use, just a way to test the variable expansion in the 'out' attribute. +%typemap(ctype, out="$*1_ltype") int& getNumber1 "_not_used_" +%typemap(imtype, out="$*1_ltype") int& getNumber1 "_not_used_" +%typemap(cstype, out="$*1_ltype") int& getNumber1 "_not_used_" +%typemap(out) int& getNumber1 "$result = *$1;" +%typemap(csout, excode=SWIGEXCODE) int & getNumber1 { + int ret = $imcall;$excode + return ret; + } +#endif + +%inline %{ +int& getNumber1() { + static int num = 111; + return num; +} +%} + +#ifdef SWIGCSHARP +// Check special variable macro expansion in typemap attributes. +// This changes return by reference into return by value. +%typemap(ctype, out="$typemap(ctype, int)") int& getNumber2 "_not_used_" +%typemap(imtype, out="$typemap(imtype, int)") int& getNumber2 "_not_used_" +%typemap(cstype, out="$typemap(cstype, int)") int& getNumber2 "_not_used_" +%typemap(out) int& getNumber2 "$result = *$1;" +%typemap(csout, excode=SWIGEXCODE) int & getNumber2 { + int ret = $imcall;$excode + return ret; + } +#endif + +%inline %{ +int& getNumber2() { + static int num = 222; + return num; +} +%} + + +#ifdef SWIGCSHARP +// Check special variable macro expansion and special variable expansion in typemap attributes. +// This changes return by reference into return by value. +%typemap(ctype, out="$typemap(ctype, $*1_ltype)") int& getNumber3 "_not_used_" +%typemap(imtype, out="$typemap(imtype, $*1_ltype)") int& getNumber3 "_not_used_" +%typemap(cstype, out="$typemap(cstype, $*1_ltype)") int& getNumber3 "_not_used_" +%typemap(out) int& getNumber3 "$result = *$1;" +%typemap(csout, excode=SWIGEXCODE) int & getNumber3 { + int ret = $imcall;$excode + return ret; + } +#endif + +%inline %{ +int& getNumber3() { + static int num = 333; + return num; +} +%} + +#ifdef SWIGCSHARP +// Check special variable macro expansion in typemap attributes. +%typemap(csin, + pre=" $typemap(cstype, int) $csinput_scaled = 11;" + ) int num1 +%{$csinput * $csinput_scaled %} +#endif + +%inline %{ +int bounceNumber1(int num1) { + return num1; +} +%} + +#ifdef SWIGCSHARP +// Check special variable expansion in typemap attributes. +%typemap(csin, + pre=" $1_type $csinput_scaled = 22;" + ) int num2 +%{$csinput * $csinput_scaled %} +#endif + +%inline %{ +int bounceNumber2(int num2) { + return num2; +} +%} + +#ifdef SWIGCSHARP +// Check special variable and special variable macro expansion in typemap attributes. +%typemap(csin, + pre=" $typemap(cstype, $1_type) $csinput_scaled = 33;" + ) int num3 +%{$csinput * $csinput_scaled %} +#endif + +%inline %{ +int bounceNumber3(int num3) { + return num3; +} +%} + +///////////////////////////////// +//// Multi-argument typemaps //// +///////////////////////////////// + +// Test expansion of special variables +#ifdef SWIGCSHARP +%typemap(ctype) (int intvar, char charvar) "double" +%typemap(imtype) (int intvar, char charvar) "double" +%typemap(cstype) (int intvar, char charvar) "double" +%typemap(in) (int intvar, char charvar) +%{ + // split double value a.b into two numbers, a and b*100 + $1 = (int)$input; + $2 = ($input - $1 + 0.005) * 100; +%} +%typemap(csin, + pre=" $1_type $csinput_$1_type = 50;\n" // $1_type should expand to int + " $2_type $csinput_$2_type = 'A';" // $2_type should expand to char + ) (int intvar, char charvar) +%{$csinput + ($csinput_int - 50 + $csinput_char - 'A') + ($csinput_$1_type - 50 + $csinput_$2_type - 'A')%} +#endif + +%inline %{ +int multi1(int intvar, char charvar) { + return intvar + charvar; +} +%} + +#ifdef SWIGCSHARP +%typemap(csin, + pre=" $typemap(cstype, int) $csinput_$typemap(cstype, int) = 50;\n" // also should expand to int + " $typemap(cstype, char) $csinput_$typemap(cstype, char) = 'A';" // also should expand to char + ) (int intvar, char charvar) +%{55 + $csinput + ($csinput_int - 50 + $csinput_char - 'A') + ($csinput_$typemap(cstype, int) - 50 + $csinput_$typemap(cstype, char) - 'A')%} +#endif + +%inline %{ +int multi2(int intvar, char charvar) { + return intvar + charvar; +} +%} + +#ifdef SWIGCSHARP +%typemap(csin, + pre=" $typemap(cstype, $1_type) $csinput_$typemap(cstype, $1_type) = 50;\n" // also should expand to int + " $typemap(cstype, $2_type) $csinput_$typemap(cstype, $2_type) = 'A';" // also should expand to char + ) (int intvar, char charvar) +%{77 + $csinput + ($csinput_int - 50 + $csinput_char - 'A') + ($csinput_$typemap(cstype, $1_type) - 50 + $csinput_$typemap(cstype, $2_type) - 'A')%} +#endif + +%inline %{ +int multi3(int intvar, char charvar) { + return intvar + charvar; +} +%} diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index cee323fb9..7f8ff60cd 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -1398,14 +1398,16 @@ static String *Swig_typemap_lookup_impl(const_String_or_char_ptr tmap_method, No String *kwtype = Getattr(kw, "type"); char *ckwname = Char(Getattr(kw, "name")); { - /* Expand variables and typemaps in kwargs. */ + /* Expand special variables in typemap attributes. */ SwigType *ptype = Getattr(node, "type"); String *pname = Getattr(node, "name"); String *lname = Getattr(node, "lname"); SwigType *mtype = Getattr(node, "tmap:match"); SwigType *matchtype = mtype ? mtype : ptype; ParmList *parm_sublist; - typemap_replace_vars(value, NULL, matchtype, ptype, pname, lname, 0); + typemap_replace_vars(value, NULL, matchtype, ptype, pname, lname, 1); + + /* Expand special variable macros (embedded typemaps) in typemap attributes. */ parm_sublist = NewParmWithoutFileLineInfo(ptype, pname); Setattr(parm_sublist, "lname", lname); replace_embedded_typemap(value, parm_sublist, NULL, tm); @@ -1572,30 +1574,43 @@ String *Swig_typemap_lookup(const_String_or_char_ptr tmap_method, Node *node, co * If this hash (tm) contains a linked list of parameters under its "kwargs" * attribute, add keys for each of those named keyword arguments to this * parameter for later use. - * For example, attach the typemap attributes to p: + * For example, attach the typemap attributes to firstp (first parameter in parameter list): * %typemap(in, foo="xyz") ... - * A new attribute called "tmap:in:foo" with value "xyz" is attached to p. + * A new attribute called "tmap:in:foo" with value "xyz" is attached to firstp. + * Also expands special variables and special variable macros in the typemap attributes. * ----------------------------------------------------------------------------- */ -static void typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr tmap_method, Parm *p) { +static void typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr tmap_method, Parm *firstp, int nmatch) { String *temp = NewStringEmpty(); Parm *kw = Getattr(tm, "kwargs"); while (kw) { String *value = Copy(Getattr(kw, "value")); String *type = Getattr(kw, "type"); - { - /* Expand variables and typemaps in kwargs. */ - SwigType *ptype = Getattr(p, "type"); + int i; + Parm *p = firstp; + /* Expand special variables */ + for (i = 0; i < nmatch; i++) { + SwigType *type = Getattr(p, "type"); String *pname = Getattr(p, "name"); String *lname = Getattr(p, "lname"); SwigType *mtype = Getattr(p, "tmap:match"); - SwigType *matchtype = mtype ? mtype : ptype; - ParmList *parm_sublist; - typemap_replace_vars(value, NULL, matchtype, ptype, pname, lname, 0); - parm_sublist = NewParmWithoutFileLineInfo(ptype, pname); + SwigType *matchtype = mtype ? mtype : type; + typemap_replace_vars(value, NULL, matchtype, type, pname, lname, i + 1); + p = nextSibling(p); + } + + /* Expand special variable macros (embedded typemaps). + * Special variable are expanded first above as they might be used in the special variable macros. + * For example: $typemap(imtype, $2_type). */ + p = firstp; + for (i = 0; i < nmatch; i++) { + SwigType *type = Getattr(p, "type"); + String *pname = Getattr(p, "name"); + String *lname = Getattr(p, "lname"); + ParmList *parm_sublist = NewParmWithoutFileLineInfo(type, pname); Setattr(parm_sublist, "lname", lname); replace_embedded_typemap(value, parm_sublist, NULL, tm); - Delete(parm_sublist); + p = nextSibling(p); } if (type) { Hash *v = NewHash(); @@ -1606,13 +1621,13 @@ static void typemap_attach_kwargs(Hash *tm, const_String_or_char_ptr tmap_method } Clear(temp); Printf(temp, "%s:%s", tmap_method, Getattr(kw, "name")); - Setattr(p, typemap_method_name(temp), value); + Setattr(firstp, typemap_method_name(temp), value); Delete(value); kw = nextSibling(kw); } Clear(temp); Printf(temp, "%s:match_type", tmap_method); - Setattr(p, typemap_method_name(temp), Getattr(tm, "type")); + Setattr(firstp, typemap_method_name(temp), Getattr(tm, "type")); Delete(temp); } @@ -1807,7 +1822,7 @@ void Swig_typemap_attach_parms(const_String_or_char_ptr tmap_method, ParmList *p Setattr(firstp, typemap_method_name(temp), p); /* Attach kwargs */ - typemap_attach_kwargs(tm, tmap_method, firstp); + typemap_attach_kwargs(tm, tmap_method, firstp, nmatch); /* Replace the argument number */ sprintf(temp, "%d", argnum); From f482adc6d1a4b1cc27b4ecbb6b461d1f747906b6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 22 Jul 2015 23:23:55 +0100 Subject: [PATCH 3/3] Add documentation and CHANGES for special variables and typemap attributes. Also add info about special variable expansions in special variable macros. --- CHANGES.current | 35 +++++++++++++++++++ Doc/Manual/Contents.html | 2 ++ Doc/Manual/Typemaps.html | 72 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 0c56946f8..cd5ae106a 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,41 @@ See the RELEASENOTES file for a summary of changes in each release. Version 3.0.7 (in progress) =========================== +2015-07-22: wsfulton + Support for special variable expansion in typemap attributes. Example usage expansion + in the 'out' attribute (C# specific): + + %typemap(ctype, out="$*1_ltype") unsigned int& "$*1_ltype" + + is equivalent to the following as $*1_ltype expands to 'unsigned int': + + %typemap(ctype, out="unsigned int") unsigned int& "unsigned int" + + Special variables can be used within special variable macros too. Example usage expansion: + + %typemap(cstype) unsigned int "uint" + %typemap(cstype, out="$typemap(cstype, $*1_ltype)") unsigned int& "$typemap(cstype, $*1_ltype)" + + Special variables are expanded first and hence the above is equivalent to: + + %typemap(cstype, out="$typemap(cstype, unsigned int)") unsigned int& "$typemap(cstype, unsigned int)" + + which then expands to: + + %typemap(cstype, out="uint") unsigned int& "uint" + +2015-07-22: lindleyf + Apply patch #439 - support for $typemap() (aka embedded typemaps or special variable + macros) in typemap attributes. A simple example where $typemap() is expanded in the + 'out' attribute (C# specific): + + %typemap(cstype) unsigned int "uint" + %typemap(cstype, out="$typemap(cstype, unsigned int)") unsigned int& "$typemap(cstype, unsigned int)" + + is equivalent to: + + %typemap(cstype, out="uint") unsigned int& "uint" + 2015-07-18: m7thon [Python] Docstrings provided via %feature("docstring") are now quoted and added to the tp_doc slot when using python builtin classes (-builtin). When no docstring is diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 793f2ed21..06c858b29 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -441,6 +441,8 @@
  • $descriptor(type)
  • $typemap(method, typepattern) +
  • Special variables and typemap attributes +
  • Special variables combined with special variable macros
  • Common typemap methods +
  • Special variables and typemap attributes +
  • Special variables combined with special variable macros
  • Common typemap methods
      @@ -2425,6 +2427,76 @@ The result is the following expansion + +

      11.4.5 Special variables and typemap attributes

      + + +

      +As of SWIG-3.0.7 typemap attributes will also expand special variables and special variable macros. +

      + +

      +Example usage showing the expansion in the 'out' attribute (C# specific) as well as the main typemap body: +

      + +
      +
      +%typemap(ctype, out="$*1_ltype") unsigned int& "$*1_ltype"
      +
      +
      + +

      +is equivalent to the following as $*1_ltype expands to unsigned int: +

      + +
      +
      +%typemap(ctype, out="unsigned int") unsigned int& "unsigned int"
      +
      +
      + +

      11.4.6 Special variables combined with special variable macros

      + + +

      +Special variables can also be used within special variable macros. +The special variables are expanded before they are used in the special variable macros. +

      + +

      +Consider the following C# typemaps: +

      + +
      +
      +%typemap(cstype) unsigned int "uint"
      +%typemap(cstype, out="$typemap(cstype, $*1_ltype)") unsigned int& "$typemap(cstype, $*1_ltype)"
      +
      +
      + +

      +Special variables are expanded first and hence the above is equivalent to: +

      + +
      +
      +%typemap(cstype) unsigned int "uint"
      +%typemap(cstype, out="$typemap(cstype, unsigned int)") unsigned int& "$typemap(cstype, unsigned int)"
      +
      +
      + +

      +which then expands to: +

      + +
      +
      +%typemap(cstype) unsigned int "uint"
      +%typemap(cstype, out="uint") unsigned int& "uint"
      +
      +
      + +

      11.5 Common typemap methods