logo       

Dispatch function (for function overloading) does not use typemap s: msg#00161

programming.swig

Subject: Dispatch function (for function overloading) does not use typemap s

Hi,

I use swig 1.3.19 to create a Tcl wrapper for my C++ libaries.

However When I combine overloaded functions and typemaps the wrapper does
not work properly. I am not sure whether this is bug or not.

I have a C++ class to represent an ID (sample code snippet follows below).
Typemaps convert references to this class to plain strings in Tcl. The
typemaps I use are pretty straight forward.

%typemap(in) ID {
$1 = ID(Tcl_GetStringFromObj($input,NULL));
}

%typemap(in) const ID & (ID temp) {
temp = ID(Tcl_GetStringFromObj($input,NULL));
$1 = &temp;
}

%typemap(out) ID {

Tcl_SetStringObj($result,(char*)($1.getString().c_str()),$1.getString().leng
th());
}

%typemap(out) const ID & {

Tcl_SetStringObj($result,(char*)($1->getString().c_str()),$1->getString().le
ngth());
}

#ifndef SWIG
class ID
{
public:
ID()
ID( const char* pValue ) { _id = pValue }
ID( const std::string& value ) { _id = value }
ID( const ID& id ) { _id = id._id }
std::string getString() { return _id; }
...

private:
std::String _id;
}
#endif

Everyting works fine like this except in one situation where I have two
overloaded functions both accepting ID references. The following class is an
example of this situation:

class myclass
{
doSomething( const ID& );
doSomething( const ID&, const ID& );
}

The two functions are wrapped properly (typemaps are used to convert de
parameters). However SWIG generates a third sort of dispatch functioin. This
dispatch function makes no use of typemaps. To determine which overloaded
function should be called the dispatch function looks at the parameters. In
my case it checks whether the given string is a pointer an ID. Which is not
the case since I use typemaps. The dispatch function looks like this.

static int
_wrap_InzetSoortVoertuig_dekSpecifiek(ClientData clientData, Tcl_Interp
*interp, int objc, Tcl_Obj *CONST objv[]) {
Tcl_Obj *CONST *argv = objv+1;
int argc = objc-1;
if (argc == 2) {
int _v;
{
void *ptr;
if (SWIG_ConvertPtr(interp, argv[0], (void **) &ptr,
SWIGTYPE_p_IBApi__InzetSoortVoertuig, 0) == TCL_ERROR) {
_v = 0;
}else {
_v = 1;
}
}
if (_v) {
{
void *ptr;
if (SWIG_ConvertPtr(interp, argv[1], (void **) &ptr,
SWIGTYPE_p_ID, 0) == TCL_ERROR) {
//
----------------------------------------------------------------------------
// Fails because a string was supplied and not a
reference to and ID.
//
----------------------------------------------------------------------------
_v = 0;
}else {
_v = 1;
}
}
if (_v) {
return
_wrap_InzetSoortVoertuig_dekSpecifiek__SWIG_1(clientData, interp, objc,
objv);
}
}
}
if (argc == 3) {
int _v;
{
void *ptr;
if (SWIG_ConvertPtr(interp, argv[0], (void **) &ptr,
SWIGTYPE_p_IBApi__InzetSoortVoertuig, 0) == TCL_ERROR) {
_v = 0;
}else {
_v = 1;
}
}
if (_v) {
{
void *ptr;
if (SWIG_ConvertPtr(interp, argv[1], (void **) &ptr,
SWIGTYPE_p_ID, 0) == TCL_ERROR) {
//
----------------------------------------------------------------------------
// Fails because a string was supplied and not a
reference to and ID.
//
----------------------------------------------------------------------------
_v = 0;
}else {
_v = 1;
}
}
if (_v) {
{
void *ptr;
if (SWIG_ConvertPtr(interp, argv[2], (void **) &ptr,
SWIGTYPE_p_ID, 0) == TCL_ERROR) {
//
----------------------------------------------------------------------------
// Fails because a string was supplied and not a
reference to and ID.
//
----------------------------------------------------------------------------
_v = 0;
}else {
_v = 1;
}
}
if (_v) {
return
_wrap_InzetSoortVoertuig_dekSpecifiek__SWIG_0(clientData, interp, objc,
objv);
}
}
}
}

Tcl_SetResult(interp,(char *) "No matching function for overloaded
'InzetSoortVoertuig_dekSpecifiek'", TCL_STATIC);
return TCL_ERROR;
}

Unless I overlooked something, it seems that SWIG does not take typemaps
into account when generating the dispatch function.

I am not sure whether or not to report this as a bug. Can someone give me
some feedback on this.

Kind regards,

Minto
----------------------------- ITO ------------------------------------------

ITO (Informatie en Communicatie Technologie Organisatie) is een agentschap
van het ministerie van Binnenlandse Zaken en Koninkrijksrelaties en levert
besloten en bedrijfszekere ICT aan OOV-diensten (Politie, Brandweer,
Ambulancezorg en Koninklijke Marechaussee) en Justitie.
Vanaf 1 januari 2004 gaat ITO op in ISC, de ICT Service Coöperatie voor
Politie, Justitie en Veiligheid.
ITO (Information and Communications Technology Organisation), an official
agency of the Ministry of the Interior and Kingdom Relations, provides
closed and reliable ICT for Public Order and Safety and Justice services
(Police, Fire Brigade, Ambulance services and Military Police) and the
Director of Public Prosecutions.
----------------------------- Disclaimer ---------------------------------
Aan dit bericht en/of deze bijlage(n) kunnen geen rechten worden ontleend.
Belangrijke afspraken dienen dan ook altijd door de daartoe bevoegde persoon
te worden ondertekend. Deze mail is uitsluitend bestemd voor de
geadresseerde(n). Verstrekking aan en gebruik door anderen is niet
toegestaan. ITO sluit iedere aansprakelijkheid uit die voortvloeit uit
elektronische verzending.
No rights may be derived from this message and/or this attachment (these
attachments). Important agreements must therefore always be signed by an
appropriately authorized individual. This mail is intended for the
addressee's (addressees') eyes only. It may not be distributed to, nor used
by, third parties. ITO disclaims any liability arising from electronic
mailing.
On January 1st 2004, ITO will become part of ISC, the ICT-service
organisation for Public Order and Safety and Justice services and the
Director of Public Prosecutions.
_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise