Quantcast

SWIG python wrapper compile error with std:vector<int>

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

SWIG python wrapper compile error with std:vector<int>

dcofer
This post has NOT been accepted by the mailing list yet.
I am attempting to setup a SWIG interface for my C++ code for python. I wanted to start simple and build up, so I I started with just including the templates for std::vector int and string. I was able to use this same code to get a C# wrapper to work, so I am pretty sure the syntax is correct. SWIG generates the C++ wrapper, but when I try and compile it I get compile errors. The generated SWIG code is trying to use a variable that was never instantiated (bold in the code below). Anyone have any ideas on what I am doing wrong here, or if there is a bug in SWIG? I am using SWIG 3.0 on a windows 64 bit machine running the following command >swig -c++ -python StdUtils_python.i.

Here is the SWIG interface file I am using

/* File : StdUtils_python.i */
%module(directors="1") StdUtils_VC10D
%{
#include "StdAfx.h"
using namespace StdUtils;

%}

#define SWIG_SHARED_PTR_SUBNAMESPACE tr1
#define STD_UTILS_PORT
%include "std_vector.i"
%include "std_string.i"
%include "std_shared_ptr.i"

%include "typemaps.i"

%define %standard_byref_params(TYPE)
        %apply TYPE& INOUT { TYPE& };
        %apply TYPE& OUTPUT { TYPE& result };
%enddef

%standard_byref_params(bool)
%standard_byref_params(signed char)
%standard_byref_params(unsigned char)
%standard_byref_params(short)
%standard_byref_params(unsigned short)
%standard_byref_params(int)
%standard_byref_params(unsigned int)
%standard_byref_params(long)
%standard_byref_params(unsigned long)
%standard_byref_params(long long)
%standard_byref_params(unsigned long long)
%standard_byref_params(float)
%standard_byref_params(double)

%template(vector_String) std::vector<std::string>;
%template(vector_int) std::vector<int>;




Here is one of the errors I am getting:

stdutils_python_wrap.cxx(8979): error C2065: 'res3' : undeclared identifier

It has a lot of errors of this same type. The code related to this one is shown below with the problem line in bold:


SWIGINTERN PyObject *_wrap_vector_int___setitem____SWIG_2(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
  PyObject *resultobj = 0;
  std::vector< int > *arg1 = (std::vector< int > *) 0 ;
  std::vector< int >::difference_type arg2 ;
  std::vector< int >::value_type *arg3 = 0 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  ptrdiff_t val2 ;
  int ecode2 = 0 ;
  std::vector< int >::value_type temp3 ;
  int val3 ;
  int ecode3 = 0 ;
  PyObject * obj0 = 0 ;
  PyObject * obj1 = 0 ;
  PyObject * obj2 = 0 ;
 
  if (!PyArg_ParseTuple(args,(char *)"OOO:vector_int___setitem__",&obj0,&obj1,&obj2)) SWIG_fail;
  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_std__vectorT_int_std__allocatorT_int_t_t, 0 |  0 );
  if (!SWIG_IsOK(res1)) {
    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "vector_int___setitem__" "', argument " "1"" of type '" "std::vector< int > *""'");
  }
  arg1 = reinterpret_cast< std::vector< int > * >(argp1);
  ecode2 = SWIG_AsVal_ptrdiff_t(obj1, &val2);
  if (!SWIG_IsOK(ecode2)) {
    SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "vector_int___setitem__" "', argument " "2"" of type '" "std::vector< int >::difference_type""'");
  }
  arg2 = static_cast< std::vector< int >::difference_type >(val2);
  ecode3 = SWIG_AsVal_int(obj2, &val3);
  if (!SWIG_IsOK(ecode3)) {
    SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "vector_int___setitem__" "', argument " "3"" of type '" "std::vector< int >::value_type""'");
  }
  temp3 = static_cast< std::vector< int >::value_type >(val3);
  arg3 = &temp3;
  try {
    std_vector_Sl_int_Sg____setitem____SWIG_2(arg1,arg2,(int const &)*arg3);
  }
  catch(std::out_of_range &_e) {
    SWIG_exception_fail(SWIG_IndexError, (&_e)->what());
  }
 
  resultobj = SWIG_Py_Void();
  if (SWIG_IsTmpObj(res3)) {
    resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_From_int((*arg3)));
  } else {
    int new_flags = SWIG_IsNewObj(res3) ? (SWIG_POINTER_OWN |  0 ) :  0 ;
    resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_NewPointerObj((void*)(arg3), SWIGTYPE_p_int, new_flags));
  }
  return resultobj;
fail:
  return NULL;
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: SWIG python wrapper compile error with std:vector<int>

dcofer
This was not sent to the post the first time, so I replying to it to get it out there.
Loading...