From: Nitro <ni...@dr...> - 2006-05-30 21:10:41
|
Hello, I seem to have run into a bug, but I am not really sure. Here it goes: I have wrapped something liket this: class X { void SetParameter( const std::string& name, const std::vector<SomeClass>& value ); void SetParameter( const std::string& name, const std::vector<SomeOtherClass>& value ); void SetParameter( const std::string& name, const std::vector<YetAnotherClass>& value ); }; There's a dispatch function in the swig wrapper for this which actually determines which of the overloaded methods to call. It includes lots code like this: int res = swig::asptr(argv[2], (std::vector<DCSDK::DCMath::DCVector2f,std::allocator<DCSDK::DCMath::DCVector2f > >**)(0)); _v = SWIG_CheckState(res); if (!_v) goto check_8; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 8; if (_rank == _rankm) goto dispatch; } When I call something like this (in Python): x = X() x.SetParameter( 'something', DC.Math.MatrixVec() ) where MatrixVec is an std::vector<DCSDK::DCMath::DCMatrix> then the above snippet of wrapper code claims that the asptr method succeeded (return code is 0), despite the fact that the passed in type is a vector<Matrix> and it should check if it's a vector<Vector2f>. It should return something negative instead to indicate that a Matrix can't be converted to a Vector2f. If you debug into this more, then you see that this piece of code is finally called: template <class Type> struct traits_asptr { static int asptr(PyObject *obj, Type **val) { Type *p; int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0) == SWIG_OK) ? SWIG_OLDOBJ : 0; if (SWIG_IsOK(res)) { if (val) *val = p; } return res; } }; When it is called with Type == Matrix and type of obj == Vector2f, the SWIG_ConvertPtr function indeed returns a negatve error code indicating that it can't convert the object. But still, res = 0 due to the ?: operator. However, res == 0 is equivalent to SWIG_OK meaning that the object could be converted, which is wrong. So the result is not returned properly. This problem then propagates back to the piece of wrapper code I quoted at the beginning where it thinks that a Matrix is a Vector2f and leads to a program crash. Note that this problem does not occur if the SetParameter functions take "simple" types (no std::vector, but something like float, int, class perhaps). Then the generated wrapper looks like int res = SWIG_ConvertPtr(argv[2], 0, SWIGTYPE_p_DCSDK__DCMath__DCMatrix, 0); _v = SWIG_CheckState(res); where res is correctly returned and not set to 0. Can you confirm this bug? -Matthias |