#967 Type system broken for pointers and the STL

None
closed
python (259)
5
2016-08-01
2008-11-29
No

The type system is broken when using the STL and pointers. Testcase below (li_std_vector_ptr.i - checked into svn):

%module li_std_vector_ptr

%include "std_vector.i"

%template(IntPtrVector) std::vector<int *>;

%inline %{
#include <iostream>
using namespace std;
int* makeIntPtr(int v) {
return new int(v);
}
double* makeDoublePtr(double v) {
return new double(v);
}

#if 1
int** makeIntPtrPtr(int* v) {
return new int*(v);
}
#endif

void displayVector(std::vector<int *> vpi) {
cout << "displayVector..." << endl;
for (int i=0; i<vpi.size(); ++i)
cout << *vpi[i] << endl;
}
%}

The following Python code fails:

from li_std_vector_ptr import *

ip1 = makeIntPtr(11)
ip2 = makeIntPtr(22)

vi = IntPtrVector((ip1, ip2))
displayVector(vi)

Traceback (most recent call last):
File "./li_std_vector_ptr_runme.py", line 6, in <module>
vi = IntPtrVector((ip1, ip2))
File "/home/william/swig/trunk/Examples/test-suite/python/li_std_vector_ptr.py", line 122, in __init__
this = _li_std_vector_ptr.new_IntPtrVector(*args)
NotImplementedError: Wrong number of arguments for overloaded function 'new_IntPtrVector'.
Possible C/C++ prototypes are:
std::vector< int * >()
std::vector< int * >(std::vector< int * > const &)
std::vector< int * >(std::vector< int * >::size_type)
std::vector< int * >(std::vector< int * >::size_type,std::vector< int * >::value_type)

Something to do with int ** in the type system causes it to fail, because if the makeIntIntPtr() method is removed, then it works. But I think it works by chance more than anything else as in SWIG_Python_ConvertPtrAndOwn(), swig_type_info *ty is zero, when it should contain type information for "int *".

The problem was previously masked but since fixing invalid STL conversions, the problem is more visible, see svn changeset 10958.

Discussion

  • William Fulton

    William Fulton - 2016-08-01
    • status: open --> closed
    • assigned_to: William Fulton
    • Group: -->
     
  • William Fulton

    William Fulton - 2016-08-01

    Fixed in swig-3.0.11.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks