Avoid errors due to generating identical overloads

Add typecheck typemaps for primitive types and string and call
Swig_overload_check() to ensure that we don't generate two wrappers
functions taking the same "const char*" type if we have overloads taking
it and "std::string" (or a reference) in the original code.
This commit is contained in:
Vadim Zeitlin 2021-12-05 20:49:20 +01:00
commit a335fff2ec
3 changed files with 96 additions and 0 deletions

View file

@ -239,6 +239,90 @@ same_action_all_primitive_types(out, "$result = $1;", "$result = *$1;")
$result = ($1_ltype) 0;
}
/* Typecheck typemaps - The purpose of these is merely to issue a warning for overloaded C++ functions
* that cannot be overloaded in the wrappers as more than one C++ type maps to a single C type */
%typecheck(SWIG_TYPECHECK_BOOL)
bool,
const bool &
""
%typecheck(SWIG_TYPECHECK_CHAR)
char,
const char &
""
%typecheck(SWIG_TYPECHECK_INT8)
signed char,
const signed char &
""
%typecheck(SWIG_TYPECHECK_UINT8)
unsigned char,
const unsigned char &
""
%typecheck(SWIG_TYPECHECK_INT16)
short,
const short &
""
%typecheck(SWIG_TYPECHECK_UINT16)
unsigned short,
const unsigned short &
""
%typecheck(SWIG_TYPECHECK_INT32)
int,
long,
const int &,
const long &
""
%typecheck(SWIG_TYPECHECK_UINT32)
unsigned int,
unsigned long,
const unsigned int &,
const unsigned long &
""
%typecheck(SWIG_TYPECHECK_INT64)
long long,
const long long &
""
%typecheck(SWIG_TYPECHECK_UINT64)
unsigned long long,
const unsigned long long &
""
%typecheck(SWIG_TYPECHECK_FLOAT)
float,
const float &
""
%typecheck(SWIG_TYPECHECK_DOUBLE)
double,
const double &
""
%typecheck(SWIG_TYPECHECK_STRING)
char *,
char *&,
char[ANY],
char[]
""
%typecheck(SWIG_TYPECHECK_POINTER)
SWIGTYPE,
SWIGTYPE *,
SWIGTYPE &,
SWIGTYPE &&,
SWIGTYPE *const&,
SWIGTYPE [],
SWIGTYPE (CLASS::*)
""
#ifdef SWIG_CPPMODE
%insert("runtime") %{

View file

@ -64,4 +64,8 @@ class string;
$result = strdup(cppresult->c_str());
%}
// This is required to warn about clashes between the overloaded functions
// taking strings and raw pointers in the generated wrappers.
%typemap(typecheck) string, const string &, string *, string & = char *;
}

View file

@ -402,6 +402,14 @@ public:
if (Checkattr(n, "storage", "friend"))
return;
// Usually generating wrappers for overloaded methods is fine, but sometimes their types can clash after applying typemaps and in this case we have no
// choice but to avoid generating them, as otherwise we'd just generate uncompilable code.
if (Getattr(n, "sym:overloaded")) {
Swig_overload_check(n);
if (Getattr(n, "overload:ignore"))
return;
}
temp_ptr_setter<Node*> set(&node_func_, n);
// As mentioned elsewhere, we can't use Swig_storage_isstatic() here because the "storage" attribute is temporarily saved in another view when this