fix overloading between unsigned long long and strings, as reported by Tim Lee.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9036 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
f854385d57
commit
54eb801392
4 changed files with 75 additions and 5 deletions
|
|
@ -107,3 +107,23 @@ struct Structure {
|
|||
const std::string Structure::ConstStaticMemberString = "const static member string";
|
||||
%}
|
||||
|
||||
|
||||
%inline %{
|
||||
class Foo {
|
||||
public:
|
||||
unsigned long long test(unsigned long long l)
|
||||
{
|
||||
return l + 1;
|
||||
}
|
||||
std::string test(std::string l)
|
||||
{
|
||||
return l + "1";
|
||||
}
|
||||
|
||||
unsigned long long testl(unsigned long long l)
|
||||
{
|
||||
return l + 1;
|
||||
}
|
||||
|
||||
};
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -105,3 +105,16 @@ if (li_std_string::test_reference_input("hello") ne "hello") {
|
|||
if (li_std_string::test_reference_inout("hello") ne "hellohello") {
|
||||
die ("reference_inout");
|
||||
}
|
||||
|
||||
|
||||
$gen1 = new li_std_string::Foo();
|
||||
if ($gen1->test(1) ne 2) {
|
||||
die ("ulonglong");
|
||||
}
|
||||
if ($gen1->test("1") ne "11") {
|
||||
die ("ulonglong");
|
||||
}
|
||||
if ($gen1->testl(9234567890121111113) ne 9234567890121111114) {
|
||||
die ("ulonglong");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ SWIG_AsVal_dec(long)(SV *obj, long* val)
|
|||
} else {
|
||||
if (*endptr == '\0') {
|
||||
if (val) *val = v;
|
||||
return SWIG_AddCast(SWIG_OK);
|
||||
return SWIG_Str2NumCast(SWIG_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -128,7 +128,7 @@ SWIG_AsVal_dec(unsigned long)(SV *obj, unsigned long *val)
|
|||
} else {
|
||||
if (*endptr == '\0') {
|
||||
if (val) *val = v;
|
||||
return SWIG_AddCast(SWIG_OK);
|
||||
return SWIG_Str2NumCast(SWIG_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -189,7 +189,7 @@ SWIG_AsVal_dec(long long)(SV *obj, long long *val)
|
|||
} else {
|
||||
if (*endptr == '\0') {
|
||||
if (val) *val = v;
|
||||
return SWIG_AddCast(SWIG_OK);
|
||||
return SWIG_Str2NumCast(SWIG_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -239,6 +239,14 @@ SWIG_AsVal_dec(unsigned long long)(SV *obj, unsigned long long *val)
|
|||
if (SvUOK(obj)) {
|
||||
if (val) *val = SvUV(obj);
|
||||
return SWIG_OK;
|
||||
} else if (SvIOK(obj)) {
|
||||
long v = SvIV(obj);
|
||||
if (v >= 0) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
} else {
|
||||
int dispatch = 0;
|
||||
const char *nptr = SvPV(obj, PL_na);
|
||||
|
|
@ -251,7 +259,7 @@ SWIG_AsVal_dec(unsigned long long)(SV *obj, unsigned long long *val)
|
|||
} else {
|
||||
if (*endptr == '\0') {
|
||||
if (val) *val = v;
|
||||
return SWIG_AddCast(SWIG_OK);
|
||||
return SWIG_Str2NumCast(SWIG_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -302,7 +310,7 @@ SWIG_AsVal_dec(double)(SV *obj, double *val)
|
|||
} else {
|
||||
if (*endptr == '\0') {
|
||||
if (val) *val = v;
|
||||
return SWIG_AddCast(SWIG_OK);
|
||||
return SWIG_Str2NumCast(SWIG_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,6 +158,35 @@ static void SWIG_croak_null()
|
|||
#endif
|
||||
|
||||
|
||||
/*
|
||||
Define how strict is the cast between strings an integers/doubles
|
||||
when overloading between these types occurs.
|
||||
|
||||
The default is making it as strict as possible by using SWIG_AddCast
|
||||
when needed.
|
||||
|
||||
You can use -DSWIG_PERL_NO_STRICT_STR2NUM at compilation time to
|
||||
disable the SWIG_AddCast, making the casting between string and
|
||||
numbers less strict.
|
||||
|
||||
In the end, we try to solve the overloading between strings and
|
||||
numerical types in the more natural way, but if you can avoid it,
|
||||
well, avoid it using %rename, for example.
|
||||
*/
|
||||
#ifndef SWIG_PERL_NO_STRICT_STR2NUM
|
||||
# ifndef SWIG_PERL_STRICT_STR2NUM
|
||||
# define SWIG_PERL_STRICT_STR2NUM
|
||||
# endif
|
||||
#endif
|
||||
#ifdef SWIG_PERL_STRICT_STR2NUM
|
||||
/* string takes precedence */
|
||||
#define SWIG_Str2NumCast(x) SWIG_AddCast(x)
|
||||
#else
|
||||
/* number takes precedence */
|
||||
#define SWIG_Str2NumCast(x) x
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue