Python STL container method overloading fix

Fix method overloading of methods that take STL containers of different types.
Due to some error handling that was not cleared during typehecking.
This commit is contained in:
William S Fulton 2019-08-06 19:36:14 +01:00
commit 86cb3a9532
9 changed files with 200 additions and 24 deletions

View file

@ -7,6 +7,56 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.0.1 (in progress)
===========================
2019-08-07: wsfulton
[Python] Fix method overloading of methods that take STL containers of different
types. The following usage (using std::vector) would fail when using -builtin:
%include <std_string.i>
%include <std_vector.i>
%inline %{
struct X {};
%}
%template(VectorX) std::vector<X>;
%template(VectorInt) std::vector<int>;
%inline %{
using namespace std;
string VectorOverload(vector<X> v);
string VectorOverload(vector<int> v);
%}
The following would incorrectly fail:
s = VectorOverload([1, 2, 3])
With:
Traceback (most recent call last):
File "runme3.py", line 20, in <module>
ret = VectorOverload([1, 2, 3])
TypeError: Wrong number or type of arguments for overloaded function 'VectorOverload'.
Possible C/C++ prototypes are:
VectorOverload(std::vector< Number,std::allocator< Number > >)
VectorOverload(std::vector< int,std::allocator< int > >)
The problem was due to some error handling that was not cleared during typehecking.
In this case an error was not cleared when the elements in the list failed the
typecheck for converting to X. Only occurs in Python 3+.
In some combinations of overloaded methods, the following type of error message would
occur:
RuntimeError: in sequence element 0
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "runme3.py", line 23, in <module>
check(VectorOverload(v), "vector<X>")
SystemError: <built-in function VectorOverload> returned a result with an error set
2019-08-01: wsfulton
#1602 Fix regression in 4.0.0 where a template function containing a parameter
with the same name as the function name led to the parameter name used in the