diff --git a/CHANGES.current b/CHANGES.current index a1e7ed6e2..c52179d45 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,33 @@ Version 2.0.0 (in progress) ============================ +2010-05-27: wsfulton + Add the ability for $typemap special variable macros to call other $typemap + special variable macros, for example: + + %typemap(cstype) CC "CC" + %typemap(cstype) BB "$typemap(cstype, CC)" + %typemap(cstype) AA "$typemap(cstype, BB)" + void hah(AA aa); + + This also fixes C# std::vector containers of shared_ptr and %shared_ptr. + + Also added diagnostics for $typemap with -debug-tmsearch, for example, the + above displays additional diagnostic lines starting "Containing: ": + + example.i:34: Searching for a suitable 'cstype' typemap for: AA aa + Looking for: AA aa + Looking for: AA + Using: %typemap(cstype) AA + Containing: $typemap(cstype, BB) + example.i:31: Searching for a suitable 'cstype' typemap for: BB + Looking for: BB + Using: %typemap(cstype) BB + Containing: $typemap(cstype, CC) + example.i:29: Searching for a suitable 'cstype' typemap for: CC + Looking for: CC + Using: %typemap(cstype) CC + 2010-05-26: olly Fix %attribute2ref not to produce a syntax error if the last argument (AccessorMethod) is omitted. Patch from David Piepgras diff --git a/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs b/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs new file mode 100644 index 000000000..2b8c84e1b --- /dev/null +++ b/Examples/test-suite/csharp/li_boost_shared_ptr_bits_runme.cs @@ -0,0 +1,17 @@ +using System; +using li_boost_shared_ptr_bitsNamespace; + +public class runme +{ + static void Main() + { + VectorIntHolder v = new VectorIntHolder(); + v.Add(new IntHolder(11)); + v.Add(new IntHolder(22)); + v.Add(new IntHolder(33)); + + int sum = li_boost_shared_ptr_bits.sum(v); + if (sum != 66) + throw new ApplicationException("sum is wrong"); + } +} diff --git a/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java b/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java new file mode 100644 index 000000000..ffa0c5e64 --- /dev/null +++ b/Examples/test-suite/java/li_boost_shared_ptr_bits_runme.java @@ -0,0 +1,24 @@ +import li_boost_shared_ptr_bits.*; + +public class li_boost_shared_ptr_bits_runme { + static { + try { + System.loadLibrary("li_boost_shared_ptr_bits"); + } 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[]) + { + VectorIntHolder v = new VectorIntHolder(); + v.add(new IntHolder(11)); + v.add(new IntHolder(22)); + v.add(new IntHolder(33)); + + int sum = li_boost_shared_ptr_bits.sum(v); + if (sum != 66) + throw new RuntimeException("sum is wrong"); + } +} diff --git a/Examples/test-suite/li_boost_shared_ptr_bits.i b/Examples/test-suite/li_boost_shared_ptr_bits.i index 4e144093e..b43e1b137 100644 --- a/Examples/test-suite/li_boost_shared_ptr_bits.i +++ b/Examples/test-suite/li_boost_shared_ptr_bits.i @@ -23,3 +23,28 @@ struct NonDynamic { boost::shared_ptr boing(boost::shared_ptr b) { return b; } %} +// vector of shared_ptr +%include "std_vector.i" + +#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED) + +%shared_ptr(IntHolder); + +#endif + +%inline %{ +#include "boost/shared_ptr.hpp" +struct IntHolder { + int val; + IntHolder(int a) : val(a) {} +}; +int sum(std::vector< boost::shared_ptr > v) { + int sum = 0; + for (size_t i=0; ival; + return sum; +} +%} + +%template(VectorIntHolder) std::vector< boost::shared_ptr >; + diff --git a/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py index c6bd2f97a..9e5668e57 100644 --- a/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py +++ b/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py @@ -18,3 +18,14 @@ check(nd) b = boing(nd) check(b) +################################ + +v = VectorIntHolder() +v.push_back(IntHolder(11)) +v.push_back(IntHolder(22)) +v.push_back(IntHolder(33)) + +sum = sum(v) +if sum != 66: + raise "sum is wrong" + diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c index 2bf806e66..607ab6d10 100644 --- a/Source/Swig/typemap.c +++ b/Source/Swig/typemap.c @@ -1940,10 +1940,16 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper #ifdef SWIG_DEBUG Printf(stdout, "Swig_typemap_attach_parms: embedded\n"); #endif - if (!already_substituting) { - already_substituting = 1; + if (already_substituting < 10) { + already_substituting++; + if ((in_typemap_search_multi == 0) && typemap_search_debug) { + String *dtypemap = NewString(dollar_typemap); + Replaceall(dtypemap, "$TYPEMAP", "$typemap"); + Printf(stdout, " Containing: %s\n", dtypemap); + Delete(dtypemap); + } Swig_typemap_attach_parms(tmap_method, to_match_parms, f); - already_substituting = 0; + already_substituting--; /* Look for the typemap code */ attr = NewStringf("tmap:%s", tmap_method); @@ -1974,10 +1980,11 @@ static void replace_embedded_typemap(String *s, ParmList *parm_sublist, Wrapper } Delete(attr); } else { - /* simple recursive call check, but prevents using an embedded typemap that contains another embedded typemap */ + /* Simple recursive call check to prevent infinite recursion - this strategy only allows a limited + * number of calls by a embedded typemaps to other embedded typemaps though */ String *dtypemap = NewString(dollar_typemap); Replaceall(dtypemap, "$TYPEMAP", "$typemap"); - Swig_error(Getfile(s), Getline(s), "Recursive $typemap calls not supported - %s\n", dtypemap); + Swig_error(Getfile(s), Getline(s), "Likely recursive $typemap calls containing %s. Use -debug-tmsearch to debug.\n", dtypemap); Delete(dtypemap); } syntax_error = 0;