From: Han, K. <Kim...@am...> - 2008-09-12 13:59:04
|
Hi, all I am using SWIG to generate the Perl extension module. I have a problem when I tried to add a overload method for existing function. The followings are function declaration. // original method int read_register_by_id(int64_t* pRegisterId, int64_t* pValueToRead, int sizeInBits); // overload method int read_register_by_id(long idHi, long idLow, long* pValueHi, long* pValueLow, int sizeInBits); After I compiled the file, SWIG generated the code code shown below. Problem I had was that I always got an error, "No matching function for overloaded 'read_register_by_id'" although I passed all the parameters correctly. Therefore, I investigated the code generated by SWIG and found that SWIG_ConvertPtr is returning a false negative (wrong error). To prove my theory, I deleted two "if (!_v) goto check_2;" after SWIG_ConvertPtr statement in "XS(_wrap_read_register_by_id)". Everything was fine and I got the value that I expected. I believe SWIG_ConvertPtr is returning a wrong error. Can you look into that problem? XS(_wrap_read_register_by_id) { dXSARGS; { unsigned long _index = 0; SWIG_TypeRank _rank = 0; if (items == 3) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(0), &vptr, SWIGTYPE_p_int64_t, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(1), &vptr, SWIGTYPE_p_int64_t, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { { int res = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(2), NULL); _v = SWIG_CheckState(res); } } if (!_v) goto check_1; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 1; if (_rank == _rankm) goto dispatch; } } check_1: if (items == 5) { SWIG_TypeRank _ranki = 0; SWIG_TypeRank _rankm = 0; SWIG_TypeRank _pi = 1; int _v = 0; { { int res = SWIG_AsVal_long SWIG_PERL_CALL_ARGS_2(ST(0), NULL); _v = SWIG_CheckState(res); } } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { { int res = SWIG_AsVal_long SWIG_PERL_CALL_ARGS_2(ST(1), NULL); _v = SWIG_CheckState(res); } } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(2), &vptr, SWIGTYPE_p_long, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_2; à If this line is gone, everything works just fine! _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { void *vptr = 0; int res = SWIG_ConvertPtr(ST(3), &vptr, SWIGTYPE_p_long, 0); _v = SWIG_CheckState(res); } if (!_v) goto check_2; à If this line is gone, everything works just fine! _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; { { int res = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(4), NULL); _v = SWIG_CheckState(res); } } if (!_v) goto check_2; _ranki += _v*_pi; _rankm += _pi; _pi *= SWIG_MAXCASTRANK; if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = 2; if (_rank == _rankm) goto dispatch; } } check_2: dispatch: switch(_index) { case 1: ++PL_markstack_ptr; SWIG_CALLXS(_wrap_read_register_by_id__SWIG_0); return; case 2: ++PL_markstack_ptr; SWIG_CALLXS(_wrap_read_register_by_id__SWIG_1); return; } } croak("No matching function for overloaded 'read_register_by_id'"); XSRETURN(0); } |