Merge pull request #1716 from ZackerySpytz/Python-utf8-cache

Use PyUnicode_AsUTF8() for Python >= 3.3
diff --git a/.travis.yml b/.travis.yml
index 32c6656..cedce51 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -428,7 +428,7 @@
       env: SWIGLANG=go
     - compiler: clang
       os: osx
-      env: SWIGLANG=guile
+      env: SWIGLANG=guile CSTD=c11
     - compiler: clang
       os: osx
       env: SWIGLANG=java
diff --git a/CHANGES.current b/CHANGES.current
index 75043b3..b45fee2 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -7,8 +7,32 @@
 Version 4.0.2 (in progress)
 ===========================
 
+2020-05-28: ZackerySpytz
+            #1776 Quite dramatically decrease run times when generating very large interface files by changing some internal memory pool sizes.
+
+2020-05-28: mcfarljm
+            #1788 Fix handling of Doxygen \endlink command.
+
+2020-05-24: vapier
+            [JS] #1796 Fix pkg-config invocation in configure.
+
+2020-02-18: ryannevell
+            [Lua] #1728 Add support for LUA lightuserdata to SWIG_Lua_ConvertPtr.
+
+2020-02-18: dmach
+            [Ruby] #1725 Fix gcc -Wcatch-value warnings.
+
+2020-02-14: treitmayr
+            #1724 Fix wrapping of abstract user-defined conversion operators.
+
+2020-02-13: ddurham2
+            [Python] #1512 Fix memleak when using STL containers of shared_ptr objects.
+
+2020-02-06: wsfulton
+            [Python] #1673 #1674 Fix setting 'this' when extending a proxy class with __slots__.
+
 2020-01-31: vadz
-            [Ruby] Add std::auto_ptr<> typemaps.
+            [Ruby] #1651 Add std::auto_ptr<> typemaps.
 
 2020-01-31: ZackerySpytz
             [Python] #1700 More robust error checking for failures in calls to Python C API:
diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html
index ca56887..ef4c010 100644
--- a/Doc/Manual/CSharp.html
+++ b/Doc/Manual/CSharp.html
@@ -76,9 +76,6 @@
 </p>
 
 <p>
-</p>
-
-<p>
 To get the most out of this chapter an understanding of interop is required.
 The <a href="https://msdn.microsoft.com">Microsoft Developer Network (MSDN)</a> has a good reference guide in a section titled "Interop Marshaling".
 Monodoc, available from the Mono project, has a very useful section titled <a href="https://www.mono-project.com/docs/advanced/pinvoke/">Interop with native libraries</a>.
diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html
index 0d0c977..79ffdd5 100644
--- a/Doc/Manual/Contents.html
+++ b/Doc/Manual/Contents.html
@@ -1499,6 +1499,9 @@
 <li><a href="R.html#R_nn5">General policy</a>
 <li><a href="R.html#R_language_conventions">Language conventions</a>
 <li><a href="R.html#R_nn6">C++ classes</a>
+<ul>
+<li><a href="R.html#R_class_examples">Examples</a>
+</ul>
 <li><a href="R.html#R_nn7">Enumerations</a>
 </ul>
 </div>
diff --git a/Doc/Manual/Doxygen.html b/Doc/Manual/Doxygen.html
index 40faa20..53238c2 100644
--- a/Doc/Manual/Doxygen.html
+++ b/Doc/Manual/Doxygen.html
@@ -1204,6 +1204,7 @@
 <td>\b</td>
 <td>wrapped with '**'</td>
 </tr>
+<tr>
 <td>\c</td>
 <td>wrapped with '``'</td>
 </tr>
@@ -1299,7 +1300,7 @@
 <td>\overload</td>
 <td>prints 'This is an overloaded ...' according to Doxygen docs</td>
 </tr>
-</tr>
+<tr>
 <td>\p</td>
 <td>wrapped with '``'</td>
 </tr>
diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html
index 60f7e17..80807ba 100644
--- a/Doc/Manual/Lua.html
+++ b/Doc/Manual/Lua.html
@@ -145,7 +145,7 @@
 The following table list the additional commandline options available for the Lua module. They can also be seen by using: 
 </p>
 
-<div class="code"><pre>
+<div class="shell"><pre>
 swig -lua -help 
 </pre></div>
 
@@ -747,7 +747,8 @@
 <p>
 Class data members are accessed in the same manner as C structures. Static class members present a special problem for Lua, as Lua doesn't have support for such features. Therefore, SWIG generates wrappers that try to work around some of these issues. To illustrate, suppose you have a class like this:
 </p>
-<div class="targetlang"><pre>class Spam {
+<div class="code"><pre>
+class Spam {
 public:
   static void foo();
   static int bar;
@@ -756,7 +757,7 @@
 <p>
 In Lua, C++ static members can be accessed as follows:
 </p>
-<div class="code"><pre>
+<div class="targetlang"><pre>
 &gt; example.Spam.foo()            -- calling Spam::foo()
 &gt; a=example.Spam.bar            -- reading Spam::bar 
 &gt; example.Spam.bar=b            -- writing to Spam::bar
@@ -774,7 +775,7 @@
 <b>Compatibility Note:</b> In versions prior to SWIG-3.0.0 only the following names would work:
 </p>
 
-<div class="code"><pre>
+<div class="targetlang"><pre>
 &gt; example.Spam_foo()            -- calling Spam::foo()
 &gt; a=example.Spam_bar            -- reading Spam::bar 
 &gt; example.Spam_bar=b            -- writing to Spam::bar
@@ -964,7 +965,8 @@
 <p>
 One restriction with operator overloading support is that SWIG is not able to fully handle operators that aren't defined as part of the class. For example, if you had code like this
 </p>
-<div class="targetlang"><pre>class Complex {
+<div class="code"><pre>
+class Complex {
 ...
 friend Complex operator+(double, const Complex &amp;c);
 ...
@@ -973,7 +975,8 @@
 <p>
 then SWIG doesn't know what to do with the friend function--in fact, it simply ignores it and issues a warning. You can still wrap the operator, but you may have to encapsulate it in a special function. For example:
 </p>
-<div class="targetlang"><pre>%rename(Complex_add_dc) operator+(double, const Complex &amp;);
+<div class="code"><pre>
+%rename(Complex_add_dc) operator+(double, const Complex &amp;);
 ...
 Complex operator+(double, const Complex &amp;c);
 </pre></div>
@@ -1446,6 +1449,7 @@
 If %nspace is enabled, then class namespace is taken as scope. If there is no namespace, or %nspace is disabled,
 then module is considered a class namespace.</p>
 <p> Consider the following C++ code </p>
+
 <div class="code"><pre>%module example
 %nspace MyWorld::Test;
 namespace MyWorld {
@@ -1486,6 +1490,7 @@
 
 <p> The internal organization of inheritance has changed. 
 Consider the following C++ code:</p>
+
 <div class="code"><pre>%module example
 class Base {
   public:
@@ -1502,6 +1507,7 @@
 was copied to <tt>.fn</tt> table of class Derived and so on. This was a recursive procedure, so in the end the whole
 inheritance tree of derived class was squashed into derived class. </p>
 <p> That means that any changes done to class Base after module initialization wouldn't affect class Derived:</p>
+
 <div class="targetlang"><pre>
 base = example.Base()
 der = example.Derived()
@@ -1516,6 +1522,8 @@
 </pre></div>
 <p> This behaviour was changed. Now unless -squash-bases option is provided, Derived store a list of it's bases and if some symbol is not found in it's own service tables
 then its bases are searched for it. Option -squash-bases will effectively return old behaviour.
+</p>
+
 <div class="targetlang"><pre>
 &gt; print(der.new_func) -- Now it works
 function
diff --git a/Doc/Manual/Preprocessor.html b/Doc/Manual/Preprocessor.html
index 63ee2c2..51cc063 100644
--- a/Doc/Manual/Preprocessor.html
+++ b/Doc/Manual/Preprocessor.html
@@ -110,11 +110,13 @@
                                 such as 0x010311 (corresponding to SWIG-1.3.11).
 
 SWIGCSHARP                      Defined when using C#
+SWIGD                           Defined when using D
+SWIGGO                          Defined when using Go
 SWIGGUILE                       Defined when using Guile
 SWIGJAVA                        Defined when using Java
 SWIGJAVASCRIPT                  Defined when using Javascript
-SWIG_JAVASCRIPT_JSC             Defined when using Javascript for JavascriptCore
-SWIG_JAVASCRIPT_V8              Defined when using Javascript for v8 or node.js 
+SWIG_JAVASCRIPT_JSC             Defined when using Javascript with -jsc
+SWIG_JAVASCRIPT_V8              Defined when using Javascript with -v8 or -node
 SWIGLUA                         Defined when using Lua
 SWIGMZSCHEME                    Defined when using Mzscheme
 SWIGOCAML                       Defined when using OCaml
@@ -144,11 +146,23 @@
 </div>
 
 <p>
+The following are language specific symbols that might be defined:
+</p>
+
+<div class="code"><pre>
+SWIG_D_VERSION                  Unsigned integer target version when using D
+SWIGGO_CGO                      Defined when using Go for cgo
+SWIGGO_GCCGO                    Defined when using Go for gccgo
+SWIGGO_INTGO_SIZE               Size of the Go type int when using Go (32 or 64)
+SWIGPYTHON_PY3                  Defined when using Python with -py3
+SWIGPYTHON_BUILTIN              Defined when using Python with -builtin
+SWIG_RUBY_AUTORENAME            Defined when using Ruby with -autorename
+</pre></div>
+
+<p>
 Interface files can look at these symbols as necessary to change the
 way in which an interface is generated or to mix SWIG directives with
-C code. These symbols are also defined within the C code generated by
-SWIG (except for the symbol `<tt>SWIG</tt>' which is only defined
-within the SWIG compiler).
+C code.
 </p>
 
 <H2><a name="Preprocessor_nn5">11.4 Macro Expansion</a></H2>
diff --git a/Doc/Manual/R.html b/Doc/Manual/R.html
index 6547ab1..e44fe43 100644
--- a/Doc/Manual/R.html
+++ b/Doc/Manual/R.html
@@ -17,6 +17,9 @@
 <li><a href="#R_nn5">General policy</a>
 <li><a href="#R_language_conventions">Language conventions</a>
 <li><a href="#R_nn6">C++ classes</a>
+<ul>
+<li><a href="#R_class_examples">Examples</a>
+</ul>
 <li><a href="#R_nn7">Enumerations</a>
 </ul>
 </div>
@@ -33,7 +36,11 @@
 <p>
 The R bindings are under active development.  They have been used to
 compile and run an R interface to QuantLib running on Mandriva Linux
-with gcc. The R bindings also work on Microsoft Windows using Visual C++.
+with gcc. They are also used to create the SimpleITK R package, which
+runs on Linux and MacOS. SWIG is used to create all wrapper
+interfaces
+to <a href="http://http://www.simpleitk.org/">SimpleITK</a>.  The R
+bindings also work on Microsoft Windows using Visual C++.
 </p>
 
 <H2><a name="R_nn2">34.1 Bugs</a></H2>
@@ -44,7 +51,9 @@
 </p>
 
 <ul>
-<li>Garbage collection of created objects
+<li>Garbage collection of some created objects. Finalizers are
+  available for wrapped C++ classes and are called by the
+  garbage collection system.
 <li>C Array wrappings
 </ul>
 
@@ -158,7 +167,10 @@
 will save a large amount of loading time.
 </p>
 
-
+<p>
+There is no need to precompile large R files if the SWIG-generated code is being included
+in an R package. The package infrastructure provides this service during package installation.
+</p>
 
 <H2><a name="R_nn5">34.4 General policy</a></H2>
 
@@ -173,7 +185,7 @@
 
 
 <p>
-getitem and setitem use C++ conventions (i.e. zero based indices). [<-
+getitem and setitem use C++ conventions (i.e. zero based indices). [&lt;-
 and [ are overloaded to allow for R syntax (one based indices and
 slices)
 </p>
@@ -182,14 +194,122 @@
 
 
 <p>
-C++ objects are implemented as external pointer objects with the class
-being the mangled name of the class. The C++ classes are encapsulated
-as an SEXP with an external pointer type. The class is the mangled
-name of the class. The nice thing about R is that is allows you to
-keep track of the pointer object which removes the necessity for a lot
-of the proxy class baggage you see in other languages.
+Wrapping of C++ classes for R works quite well. R has a special
+type, known as an external reference, that can be used as a pointer
+to arbitary things, including C++ classes. The proxy layers generated
+for other classes are not required.
 </p>
 
+<p>
+  SWIG currently creates a custom hierarchy of R classes derived from the
+  external reference type and implements
+type checking and function overloading in the R code it generates. In
+the future we hope to utilise the built in R6 class structures.
+</p>
+
+<p>
+The R interface has the following capabilities:
+</p>
+<ul>
+  <li> Destructor methods are registered and called automatically by the R garbage collector.
+<li> A range of std::vector types are converted automatically to R equivalents via the std_vector.i library.
+<li> The $ operator is used for method access.
+<li> Variable accessors are automatically generated and called via the $, [, [[, $&lt;-,  [&lt;-, [[&lt;- operators.
+</ul>
+
+<H3><a name="R_class_examples">34.6.1 Examples</a></H3>
+
+
+<p>
+Consider the following simple example:
+</p>
+
+<div class="code">
+  <pre>
+class Vehicle {
+private:
+  int m_axles;
+
+public:
+  int Axles() {
+    return(m_axles);
+  }
+
+  bool Available;
+
+  Vehicle() {
+    Available=false;
+    m_axles=2;
+  }
+
+  Vehicle(int ax) {
+    Available=false;
+    m_axles=ax;
+  }
+};
+</pre>
+</div>
+
+<p>
+The following options are available in R:
+</p>
+
+<div class="code">
+<pre>
+v1 &lt;- Vehicle()
+v2 &lt;- Vehicle(4)
+# access members
+v1$Axles()
+[1] 2
+v2$Axles
+[1] 4
+v1$Available
+[1] FALSE
+# Set availabilty
+v1$Available &lt;- TRUE
+v1$Available
+[1] TRUE
+</pre>
+</div>
+  
+<p>
+A useful trick to determine the methods that are available is to
+query the R method definition as follows:
+</p>
+
+<div class="code">
+  <pre>
+# display the methods for the class
+getMethod("$", class(v1))
+    
+Method Definition:
+
+function (x, name) 
+{
+    accessorFuns = list(Axles = Vehicle_Axles, Available = Vehicle_Available_get)
+    vaccessors = c("Available")
+    idx = pmatch(name, names(accessorFuns))
+    if (is.na(idx)) 
+        return(callNextMethod(x, name))
+    f = accessorFuns[[idx]]
+    if (is.na(match(name, vaccessors))) 
+        function(...) {
+            f(x, ...)
+        }
+    else f(x)
+}
+
+Signatures:
+        x           
+target  "_p_Vehicle"
+defined "_p_Vehicle"
+
+</pre>
+</div>
+<p>
+The names in the <tt>accessorFuns</tt> list correspond to class methods while names in the <tt>vaccessors</tt> section
+correspond to variables that may be modified.
+</p>
 <H2><a name="R_nn7">34.7 Enumerations</a></H2>
 
 
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index 115747e..e77f09c 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -184,6 +184,7 @@
 	director_classes \
 	director_classic \
 	director_constructor \
+	director_conversion_operators \
 	director_default \
 	director_detect \
 	director_enum \
diff --git a/Examples/test-suite/director_conversion_operators.i b/Examples/test-suite/director_conversion_operators.i
new file mode 100644
index 0000000..afcd49d
--- /dev/null
+++ b/Examples/test-suite/director_conversion_operators.i
@@ -0,0 +1,35 @@
+%module(directors="1") director_conversion_operators
+
+%feature("director");
+
+%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Bar;
+
+%rename(toFoo) Bar::operator Foo();
+%rename(toFooPtr) Bar::operator Foo *();
+%rename(toFooRef) Bar::operator Foo &();
+%rename(toFooPtrRef) Bar::operator Foo *&();
+
+%rename(toOtherFoo) Bar::operator OtherFoo();
+%rename(toOtherFooPtr) Bar::operator OtherFoo *();
+%rename(toOtherFooRef) Bar::operator OtherFoo &();
+%rename(toOtherFooPtrRef) Bar::operator OtherFoo *&();
+
+%inline %{
+   struct Foo {
+   };
+   struct OtherFoo {
+   };
+   struct Bar {
+      Foo myFoo;
+      Foo *myFooPtr;
+      virtual ~Bar() { }
+      virtual operator Foo () { return Foo(); }
+      virtual operator Foo *() { return &myFoo; }
+      virtual operator Foo &() { return myFoo; }
+      virtual operator Foo *&() { return myFooPtr; }
+      virtual operator OtherFoo () = 0;
+      virtual operator OtherFoo *() = 0;
+      virtual operator OtherFoo &() = 0;
+      virtual operator OtherFoo *&() = 0;
+   };
+%}
diff --git a/Examples/test-suite/doxygen_misc_constructs.i b/Examples/test-suite/doxygen_misc_constructs.i
index c1b3eea..9cf95de 100644
--- a/Examples/test-suite/doxygen_misc_constructs.i
+++ b/Examples/test-suite/doxygen_misc_constructs.i
@@ -36,7 +36,7 @@
      * @param line line number
      * @param isGetSize if set, for every object location both address and size are returned
      *
-     * @link Connection::getId() @endlink <br>
+     * @link Connection::getId() @endlink<br>
      */
     void getAddress(int &fileName,
                     int line,
@@ -62,7 +62,7 @@
      * used for unspecified parameters.
      * <p>
      *
-     * @link advancedWinIDEALaunching.py Python example.@endlink <br>
+     * @link advancedWinIDEALaunching.py Python example.@endlink<br>
      */
     class CConnectionConfig
     {
diff --git a/Examples/test-suite/doxygen_translate_all_tags.i b/Examples/test-suite/doxygen_translate_all_tags.i
index 6cefd8d..b54203d 100644
--- a/Examples/test-suite/doxygen_translate_all_tags.i
+++ b/Examples/test-suite/doxygen_translate_all_tags.i
@@ -210,7 +210,7 @@
  * 
  * \line example
  *
- * \link someMember Some description follows \endlink
+ * \link someMember Some description follows\endlink with text after
  * 
  * \mainpage Some title
  *
diff --git a/Examples/test-suite/java/doxygen_translate_all_tags_runme.java b/Examples/test-suite/java/doxygen_translate_all_tags_runme.java
index fda1fc3..56272bf 100644
--- a/Examples/test-suite/java/doxygen_translate_all_tags_runme.java
+++ b/Examples/test-suite/java/doxygen_translate_all_tags_runme.java
@@ -93,7 +93,7 @@
     		" </li><li>With lots of items \n" +
     		" </li><li>lots of lots of items \n" +
     		" </li></ul> \n" +
-    		" {@link someMember Some description follows }\n" +
+    		" {@link someMember Some description follows} with text after\n" +
     		" This will only appear in man\n");
     
     wantedComments.put("doxygen_translate_all_tags.doxygen_translate_all_tags.func07(int, int, int, int)",
diff --git a/Examples/test-suite/lua/Makefile.in b/Examples/test-suite/lua/Makefile.in
index 63b8692..92559bb 100644
--- a/Examples/test-suite/lua/Makefile.in
+++ b/Examples/test-suite/lua/Makefile.in
@@ -15,6 +15,7 @@
 CPP_TEST_CASES += \
 	lua_no_module_global \
 	lua_inherit_getitem  \
+	lua_lightuserdata  \
 
 
 C_TEST_CASES += \
diff --git a/Examples/test-suite/lua/lua_lightuserdata_runme.lua b/Examples/test-suite/lua/lua_lightuserdata_runme.lua
new file mode 100644
index 0000000..c1c3c1d
--- /dev/null
+++ b/Examples/test-suite/lua/lua_lightuserdata_runme.lua
@@ -0,0 +1,7 @@
+require("import") -- the import fn
+import("lua_lightuserdata") -- import lib
+
+local t = lua_lightuserdata
+local d = t.get_lightuserdata()
+local r = t.check_lighuserdata(d)
+assert(r)
diff --git a/Examples/test-suite/lua_lightuserdata.i b/Examples/test-suite/lua_lightuserdata.i
new file mode 100644
index 0000000..9069b6a
--- /dev/null
+++ b/Examples/test-suite/lua_lightuserdata.i
@@ -0,0 +1,17 @@
+%module lua_lightuserdata
+
+%native(get_lightuserdata) int get_lightuserdata(lua_State* L);
+%{
+static int foo;
+int get_lightuserdata(lua_State* L)
+{
+  lua_pushlightuserdata(L, &foo);
+  return 1;
+}
+%}
+
+%inline %{
+bool check_lighuserdata(const void* d) {
+  return d == &foo;
+}
+%}
diff --git a/Examples/test-suite/python/Makefile.in b/Examples/test-suite/python/Makefile.in
index be06f7e..4c0507c 100644
--- a/Examples/test-suite/python/Makefile.in
+++ b/Examples/test-suite/python/Makefile.in
@@ -11,7 +11,7 @@
 LANGUAGE     = python
 PYTHON       = $(PYBIN)
 PYCODESTYLE       = @PYCODESTYLE@
-PYCODESTYLE_FLAGS = --ignore=E252,E30,E402,E501,E731,W291,W391
+PYCODESTYLE_FLAGS = --ignore=E252,E30,E402,E501,E731,E741,W291,W391
 
 #*_runme.py for Python 2.x, *_runme3.py for Python 3.x
 PY2SCRIPTSUFFIX = _runme.py
diff --git a/Examples/test-suite/python/cpp11_shared_ptr_upcast_runme.py b/Examples/test-suite/python/cpp11_shared_ptr_upcast_runme.py
new file mode 100644
index 0000000..08546a4
--- /dev/null
+++ b/Examples/test-suite/python/cpp11_shared_ptr_upcast_runme.py
@@ -0,0 +1,63 @@
+from cpp11_shared_ptr_upcast import *
+
+# This is a port from the Ruby equivalent test and some tests ported from
+# Examples/test-suite/ruby/cpp11_shared_ptr_upcast_runme.rb are not working and commented out with:
+# not working:
+
+def swig_assert_equal_simple(expected, got):
+    if expected != got:
+        raise RuntimeError("Expected: {}. Got: {}")
+
+# non-overloaded
+swig_assert_equal_simple(7, derived_num1(Derived(7)))
+swig_assert_equal_simple(7, derived_num2([Derived(7)]))
+swig_assert_equal_simple(7, derived_num3({0: Derived(7)}))
+
+swig_assert_equal_simple(-1, base_num1(Derived(7)))
+swig_assert_equal_simple(-1, base_num2([Derived(7)]))
+swig_assert_equal_simple(-1, base_num3({0: Derived(7)}))
+
+swig_assert_equal_simple(999, derived_num1(None))
+# not working: swig_assert_equal_simple(999, derived_num2([None]))
+# not working: swig_assert_equal_simple(999, derived_num3({0: None}))
+
+swig_assert_equal_simple(999, base_num1(None))
+# not working: swig_assert_equal_simple(999, base_num2([None]))
+# not working: swig_assert_equal_simple(999, base_num3({0: None}))
+
+# overloaded
+swig_assert_equal_simple(7, derived_num(Derived(7)))
+swig_assert_equal_simple(7, derived_num([Derived(7)]))
+swig_assert_equal_simple(7, derived_num({0: Derived(7)}))
+
+swig_assert_equal_simple(-1, base_num(Derived(7)))
+swig_assert_equal_simple(-1, base_num([Derived(7)]))
+swig_assert_equal_simple(-1, base_num({0: Derived(7)}))
+
+# ptr to shared_ptr
+swig_assert_equal_simple(7, derived2_num1(Derived2(7)))
+swig_assert_equal_simple(7, derived2_num2([Derived2(7)]))
+swig_assert_equal_simple(7, derived2_num3({0: Derived2(7)}))
+
+swig_assert_equal_simple(-1, base2_num1(Derived2(7)))
+
+# not working: try:
+# not working:     # Upcast for pointers to shared_ptr in this generic framework has not been implemented
+# not working:     swig_assert_equal_simple(-1, base2_num2([Derived2(7)]))
+# not working:     raise RuntimeError, "Failed to catch TypeError"
+# not working: except TypeError:
+# not working:     pass
+# not working: try:
+# not working:     # Upcast for pointers to shared_ptr in this generic framework has not been implemented
+# not working:     swig_assert_equal_simple(-1, base2_num3({0: Derived2(7)}))
+# not working:     raise RuntimeError, "Failed to catch TypeError"
+# not working: except TypeError:
+# not working:     pass
+
+swig_assert_equal_simple(888, derived2_num1(None))
+swig_assert_equal_simple(999, derived2_num2([None])) # although 888 would be more consistent
+swig_assert_equal_simple(999, derived2_num3({0: None})) # although 888 would be more consistent
+
+swig_assert_equal_simple(888, base2_num1(None))
+swig_assert_equal_simple(999, base2_num2([None])) # although 888 would be more consistent
+swig_assert_equal_simple(999, base2_num3({0: None})) # although 888 would be more consistent
diff --git a/Examples/test-suite/python/doxygen_translate_all_tags_runme.py b/Examples/test-suite/python/doxygen_translate_all_tags_runme.py
index 2b5b3b8..e884cf9 100644
--- a/Examples/test-suite/python/doxygen_translate_all_tags_runme.py
+++ b/Examples/test-suite/python/doxygen_translate_all_tags_runme.py
@@ -175,7 +175,7 @@
 
 
 
-someMember Some description follows
+someMember Some description follows with text after
 
 
 
diff --git a/Examples/test-suite/python/python_append_runme.py b/Examples/test-suite/python/python_append_runme.py
index eddda53..e5f6b07 100644
--- a/Examples/test-suite/python/python_append_runme.py
+++ b/Examples/test-suite/python/python_append_runme.py
@@ -21,3 +21,16 @@
 Test.static_func()
 if grabstaticpath() != os.path.basename(mypath):
     raise RuntimeError("grabstaticpath failed")
+
+# slots test
+fs = ForSlots()
+if fs.ValidVariable != 99:
+    raise RuntimeError("ValidVariable failed")
+fs.ValidVariable = 11
+if fs.ValidVariable != 11:
+    raise RuntimeError("ValidVariable failed")
+try:
+    fs.Invalid = 22
+    raise RuntimeError("It should not be possible to set a random variable name")
+except AttributeError:
+    pass
diff --git a/Examples/test-suite/python_append.i b/Examples/test-suite/python_append.i
index 0494943..883097e 100644
--- a/Examples/test-suite/python_append.i
+++ b/Examples/test-suite/python_append.i
@@ -42,13 +42,31 @@
 %}
 
 %inline %{
-
 class Test {
 public:
   static void static_func() {};
   void funk() {};
 };
+%}
 
+// Github issue #1674
+%extend ForSlots {
+  %pythoncode %{
+        __slots__ = ["this"]
+    %}
+}
+// While __slots__ does not contain 'ValidVariable' in the list, it is still possible
+// to set 'ValidVariable'. A little odd, but the whole attribute setting is bypassed
+// for setting C/C++ member variables.
+// Not sure how to test the equivalent for -builtin.
+%inline %{
+struct ForSlots {
+  int ValidVariable;
+  ForSlots() : ValidVariable(99) {}
+};
+%}
+
+%inline %{
 #ifdef SWIGPYTHON_BUILTIN
 bool is_python_builtin() { return true; }
 #else
diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg
index bd764d6..b8ddf00 100644
--- a/Lib/lua/luarun.swg
+++ b/Lib/lua/luarun.swg
@@ -1765,6 +1765,11 @@
     *ptr=0;
     return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
   }
+  if (lua_islightuserdata(L,index))
+  {
+    *ptr=lua_touserdata(L,index);
+    return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
+  }
   usr=(swig_lua_userdata*)lua_touserdata(L,index);  /* get data */
   if (usr)
   {
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg
index d6eeda9..63ff82f 100644
--- a/Lib/python/pyrun.swg
+++ b/Lib/python/pyrun.swg
@@ -1245,25 +1245,21 @@
   return inst;
 }
 
-SWIGRUNTIME void
+SWIGRUNTIME int
 SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this)
 {
- PyObject *dict;
 #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS)
- PyObject **dictptr = _PyObject_GetDictPtr(inst);
- if (dictptr != NULL) {
-   dict = *dictptr;
-   if (dict == NULL) {
-     dict = PyDict_New();
-     *dictptr = dict;
-   }
-   PyDict_SetItem(dict, SWIG_This(), swig_this);
-   return;
- }
+  PyObject **dictptr = _PyObject_GetDictPtr(inst);
+  if (dictptr != NULL) {
+    PyObject *dict = *dictptr;
+    if (dict == NULL) {
+      dict = PyDict_New();
+      *dictptr = dict;
+    }
+    return PyDict_SetItem(dict, SWIG_This(), swig_this);
+  }
 #endif
- dict = PyObject_GetAttrString(inst, "__dict__");
- PyDict_SetItem(dict, SWIG_This(), swig_this);
- Py_DECREF(dict);
+  return PyObject_SetAttr(inst, SWIG_This(), swig_this);
 } 
 
 
@@ -1277,7 +1273,8 @@
     if (sthis) {
       SwigPyObject_append((PyObject*) sthis, obj[1]);
     } else {
-      SWIG_Python_SetSwigThis(obj[0], obj[1]);
+      if (SWIG_Python_SetSwigThis(obj[0], obj[1]) != 0)
+        return NULL;
     }
     return SWIG_Py_Void();
   }
diff --git a/Lib/python/pystdcommon.swg b/Lib/python/pystdcommon.swg
index 0242e4d..afa7135 100644
--- a/Lib/python/pystdcommon.swg
+++ b/Lib/python/pystdcommon.swg
@@ -45,11 +45,20 @@
   template <class Type>
   struct traits_asptr {   
     static int asptr(PyObject *obj, Type **val) {
-      Type *p = 0;
+      int res = SWIG_ERROR;
       swig_type_info *descriptor = type_info<Type>();
-      int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
-      if (SWIG_IsOK(res)) {
-	if (val) *val = p;
+      if (val) {
+        Type *p = 0;
+        int newmem = 0;
+        res = descriptor ? SWIG_ConvertPtrAndOwn(obj, (void **)&p, descriptor, 0, &newmem) : SWIG_ERROR;
+        if (SWIG_IsOK(res)) {
+          if (newmem & SWIG_CAST_NEW_MEMORY) {
+            res |= SWIG_NEWOBJMASK;
+          }
+          *val = p;
+        }
+      } else {
+        res = descriptor ? SWIG_ConvertPtr(obj, 0, descriptor, 0) : SWIG_ERROR;
       }
       return res;
     }
diff --git a/Lib/ruby/rubycontainer.swg b/Lib/ruby/rubycontainer.swg
index 9fa205b..e723308 100644
--- a/Lib/ruby/rubycontainer.swg
+++ b/Lib/ruby/rubycontainer.swg
@@ -628,7 +628,7 @@
       try {
 	r = swig::from< const Sequence* >( swig::getslice(self, i, j) );
       }
-      catch( std::out_of_range ) {
+      catch( const std::out_of_range& ) {
       }
       return r;
     }
@@ -687,9 +687,8 @@
 	r = swig::from< Sequence::value_type >( *(at) );
 	$self->erase(at); 
       }
-      catch (std::out_of_range)
-	{
-	}
+      catch (const std::out_of_range&) {
+      }
       return r;
     }
   }
@@ -757,7 +756,7 @@
       try {
 	r = swig::from< Sequence::value_type >( *(swig::cgetpos(self, i)) );
       }
-      catch( std::out_of_range ) {
+      catch( const std::out_of_range& ) {
       }
       return r;
     }
@@ -780,7 +779,7 @@
       try {
 	r = swig::from< const Sequence* >( swig::getslice(self, i, j) );
       }
-      catch( std::out_of_range ) {
+      catch( const std::out_of_range& ) {
       }
       return r;
     }
@@ -790,7 +789,7 @@
       try {
 	r = swig::from< Sequence::value_type >( *(swig::cgetpos(self, i)) );
       }
-      catch( std::out_of_range ) {
+      catch( const std::out_of_range& ) {
       }
       return r;
     }
@@ -1017,7 +1016,7 @@
 	  } else {
 	    return rubyseq.check() ? SWIG_OK : SWIG_ERROR;
 	  }
-	} catch (std::exception& e) {
+	} catch (const std::exception& e) {
 	  if (seq) {
 	    VALUE lastErr = rb_gv_get("$!");
 	    if (lastErr == Qnil) {
@@ -1057,7 +1056,7 @@
 	  } else {
 	    return true;
 	  }
-	} catch (std::exception& e) {
+	} catch (const std::exception& e) {
 	  if (seq) {
 	    VALUE lastErr = rb_gv_get("$!");
 	    if (lastErr == Qnil) {
diff --git a/Lib/ruby/std_shared_ptr.i b/Lib/ruby/std_shared_ptr.i
index dee35ec..086e308 100644
--- a/Lib/ruby/std_shared_ptr.i
+++ b/Lib/ruby/std_shared_ptr.i
@@ -13,24 +13,27 @@
   template <class Type>
   struct traits_asptr<std::shared_ptr<Type> > {
     static int asptr(VALUE obj, std::shared_ptr<Type> **val) {
-      std::shared_ptr<Type> *p = 0;
+      int res = SWIG_ERROR;
       swig_type_info *descriptor = type_info<std::shared_ptr<Type> >();
-      swig_ruby_owntype newmem = {0, 0};
-      int res = descriptor ? SWIG_ConvertPtrAndOwn(obj, (void **)&p, descriptor, 0, &newmem) : SWIG_ERROR;
-      if (SWIG_IsOK(res)) {
-	if (val) {
-	  if (*val) {
-	    **val = p ? *p : std::shared_ptr<Type>();
-	  } else {
-	    *val = p;
-	    if (newmem.own & SWIG_CAST_NEW_MEMORY) {
-	      // Upcast for pointers to shared_ptr in this generic framework has not been implemented
-	      res = SWIG_ERROR;
-	    }
-	  }
-	}
-	if (newmem.own & SWIG_CAST_NEW_MEMORY)
-	  delete p;
+      if (val) {
+        std::shared_ptr<Type> *p = 0;
+        swig_ruby_owntype newmem = {0, 0};
+        res = descriptor ? SWIG_ConvertPtrAndOwn(obj, (void **)&p, descriptor, 0, &newmem) : SWIG_ERROR;
+        if (SWIG_IsOK(res)) {
+          if (*val) {
+            **val = p ? *p : std::shared_ptr<Type>();
+          } else {
+            *val = p;
+            if (newmem.own & SWIG_CAST_NEW_MEMORY) {
+              // Upcast for pointers to shared_ptr in this generic framework has not been implemented
+              res = SWIG_ERROR;
+            }
+          }
+          if (newmem.own & SWIG_CAST_NEW_MEMORY)
+            delete p;
+        }
+      } else {
+        res = descriptor ? SWIG_ConvertPtr(obj, 0, descriptor, 0) : SWIG_ERROR;
       }
       return res;
     }
diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
index 470b7d0..8029dee 100644
--- a/Source/CParse/parser.y
+++ b/Source/CParse/parser.y
@@ -4800,6 +4800,9 @@
 		 if ($8.qualifier) {
 		   SwigType_push($4,$8.qualifier);
 		 }
+		 if ($8.val) {
+		   Setattr($$,"value",$8.val);
+		 }
 		 Setattr($$,"refqualifier",$8.refqualifier);
 		 Setattr($$,"decl",$4);
 		 Setattr($$,"parms",$6);
@@ -4818,6 +4821,9 @@
 		 if ($8.qualifier) {
 		   SwigType_push(decl,$8.qualifier);
 		 }
+		 if ($8.val) {
+		   Setattr($$,"value",$8.val);
+		 }
 		 Setattr($$,"refqualifier",$8.refqualifier);
 		 Setattr($$,"decl",decl);
 		 Setattr($$,"parms",$6);
@@ -4836,6 +4842,9 @@
 		 if ($8.qualifier) {
 		   SwigType_push(decl,$8.qualifier);
 		 }
+		 if ($8.val) {
+		   Setattr($$,"value",$8.val);
+		 }
 		 Setattr($$,"refqualifier",$8.refqualifier);
 		 Setattr($$,"decl",decl);
 		 Setattr($$,"parms",$6);
@@ -4856,6 +4865,9 @@
 		 if ($9.qualifier) {
 		   SwigType_push(decl,$9.qualifier);
 		 }
+		 if ($9.val) {
+		   Setattr($$,"value",$9.val);
+		 }
 		 Setattr($$,"refqualifier",$9.refqualifier);
 		 Setattr($$,"decl",decl);
 		 Setattr($$,"parms",$7);
@@ -4873,7 +4885,10 @@
 		if ($7.qualifier) {
 		  SwigType_push(t,$7.qualifier);
 		}
-		 Setattr($$,"refqualifier",$7.refqualifier);
+		if ($7.val) {
+		  Setattr($$,"value",$7.val);
+		}
+		Setattr($$,"refqualifier",$7.refqualifier);
 		Setattr($$,"decl",t);
 		Setattr($$,"parms",$5);
 		Setattr($$,"conversion_operator","1");
diff --git a/Source/DOH/memory.c b/Source/DOH/memory.c
index e0e4c68..4a9494e 100644
--- a/Source/DOH/memory.c
+++ b/Source/DOH/memory.c
@@ -15,7 +15,7 @@
 #include "dohint.h"
 
 #ifndef DOH_POOL_SIZE
-#define DOH_POOL_SIZE         16384
+#define DOH_POOL_SIZE         4194304
 #endif
 
 /* Checks stale DOH object use - will use a lot more memory as pool memory is not re-used. */
diff --git a/Source/Doxygen/doxyparser.cxx b/Source/Doxygen/doxyparser.cxx
index 6bda9d2..35d1836 100644
--- a/Source/Doxygen/doxyparser.cxx
+++ b/Source/Doxygen/doxyparser.cxx
@@ -1196,6 +1196,10 @@
     // do it every time.)
     if (getBaseCommand(cmd) == CMD_CODE) skipLeadingSpace = true;
     else skipLeadingSpace = false;
+  } else if (cmd.substr(0,3) == "end") {
+    // If processing an "end" command such as "endlink", don't skip
+    // the space before the next string
+    skipLeadingSpace = false;
   }
 
   if (skipLeadingSpace) {
diff --git a/configure.ac b/configure.ac
index b4cadef..fce5b9e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1597,7 +1597,7 @@
 
   if test -z "$JSCORELIB" -a -n "$PKGCONFIG"; then
     AC_MSG_CHECKING(for JavaScriptCore/Webkit library)
-    if pkg-config javascriptcoregtk-1.0; then
+    if $PKGCONFIG javascriptcoregtk-1.0; then
       JSCORELIB=`$PKGCONFIG --libs javascriptcoregtk-1.0`
       JSCOREVERSION=`$PKGCONFIG --modversion javascriptcoregtk-1.0`
     fi