The test below seems to cause swig some namespace confusion. I am using the 2.0.9 release built from source on cygwin.
// swig -Wall -python -includeall -c++ -outdir python -o python/m_wrap.cpp m.i %module m %{ #include <utility> %} %include "std_pair.i" namespace ns{ %template(int_pair) std::pair<int,int>; };
Here is the offending procedure:
SWIGINTERN PyObject *_wrap_new_int_pair__SWIG_2(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; pair< int,int > *arg1 = 0 ; void *argp1 = 0 ; int res1 = 0 ; PyObject * obj0 = 0 ; std::pair< int,int > *result = 0 ; if (!PyArg_ParseTuple(args,(char *)"O:new_int_pair",&obj0)) SWIG_fail; res1 = SWIG_ConvertPtr(obj0, &argp1, SWIGTYPE_p_pairT_int_int_t, 0 | 0); if (!SWIG_IsOK(res1)) { SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_int_pair" "', argument " "1"" of type '" "pair< int,int > const &""'"); } if (!argp1) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "new_int_pair" "', argument " "1"" of type '" "pair< int,int > const &""'"); } arg1 = reinterpret_cast< pair< int,int > * >(argp1); result = (std::pair< int,int > *)new std::pair< int,int >((pair< int,int > const &)*arg1); resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_std__pairT_int_int_t, SWIG_POINTER_NEW | 0 ); return resultobj; fail: return NULL; }
The problem is that it keeps referencing pair instead of std::pair. Furthermore, on a larger input that reuses pair more later, it ends up creating a number of references like ns::std::pair.
Duplicate of [#1238]
Related
Bugs:
#1238This example now gives an error:
If changed to explicitly reference
std
from the root by prefixing::
like sothen the file processing and the generated code doesn't reference
pair
unqualified.git log -S"and was incorrectly instantiated in scope"
points to 959e6272082e416303d80d7326430d1fd0b4c432 which has commit message:The example above is essentially the same as yours, so the error is deliberate, There's a working alternative above, so closing.