summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lib/swigerrors.swg25
-rw-r--r--Lib/swigrun.swg6
-rw-r--r--Lib/typemaps/cstrings.swg4
-rw-r--r--Lib/typemaps/enumint.swg4
-rw-r--r--Lib/typemaps/fragments.swg3
-rw-r--r--Lib/typemaps/implicit.swg2
-rw-r--r--Lib/typemaps/inoutlist.swg11
-rw-r--r--Lib/typemaps/primtypes.swg9
-rw-r--r--Lib/typemaps/strings.swg4
-rw-r--r--Lib/typemaps/traits.swg2
-rw-r--r--Lib/typemaps/valtypes.swg15
-rw-r--r--Source/Modules/overload.cxx17
-rw-r--r--Source/Modules/swigmod.h3
13 files changed, 63 insertions, 42 deletions
diff --git a/Lib/swigerrors.swg b/Lib/swigerrors.swg
index 8b4636a23..0e37686cb 100644
--- a/Lib/swigerrors.swg
+++ b/Lib/swigerrors.swg
@@ -1,13 +1,14 @@
/* Errors in SWIG */
-#define SWIG_MemoryError 1
-#define SWIG_IOError 2
-#define SWIG_RuntimeError 3
-#define SWIG_IndexError 4
-#define SWIG_TypeError 5
-#define SWIG_DivisionByZero 6
-#define SWIG_OverflowError 7
-#define SWIG_SyntaxError 8
-#define SWIG_ValueError 9
-#define SWIG_SystemError 10
-#define SWIG_AttributeError 11
-#define SWIG_UnknownError 99
+#define SWIG_UnknownError -1
+#define SWIG_IOError -2
+#define SWIG_RuntimeError -3
+#define SWIG_IndexError -4
+#define SWIG_TypeError -5
+#define SWIG_DivisionByZero -6
+#define SWIG_OverflowError -7
+#define SWIG_SyntaxError -8
+#define SWIG_ValueError -9
+#define SWIG_SystemError -10
+#define SWIG_AttributeError -11
+#define SWIG_MemoryError -12
+
diff --git a/Lib/swigrun.swg b/Lib/swigrun.swg
index bd79d552b..af2999a73 100644
--- a/Lib/swigrun.swg
+++ b/Lib/swigrun.swg
@@ -57,6 +57,12 @@
#define SWIG_OK 0
#define SWIG_ERROR -1
+/* Flags to manage cast and return states */
+#define SWIG_MAX_CAST_RANK 4
+#define SWIG_IsOK(r) (r >= 0)
+#define SWIG_AddCast(r) (SWIG_IsOK(r) ? (r + 1) : r)
+#define SWIG_GetCastRank(r) (SWIG_IsOK(r) ? ((r < SWIG_MAX_CAST_RANK) ? (r + 1) : 0) : 0)
+
#include <string.h>
diff --git a/Lib/typemaps/cstrings.swg b/Lib/typemaps/cstrings.swg
index 14483ed47..bef1659e5 100644
--- a/Lib/typemaps/cstrings.swg
+++ b/Lib/typemaps/cstrings.swg
@@ -182,7 +182,7 @@
%define Name ## _output_maxsize(TYPEMAP, SIZE)
%typemap(in,noblock=1,fragment=SWIG_AsVal_frag(size_t)) (TYPEMAP, SIZE) (size_t size, Char *buff = 0) {
- if (SWIG_AsVal(size_t)($input, &size) != SWIG_OK) {
+ if (!SWIG_IsOK(SWIG_AsVal(size_t)($input, &size))) {
%argument_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
}
buff= %new_array(size+1, Char);
@@ -212,7 +212,7 @@
%define Name ## _output_withsize(TYPEMAP, SIZE)
%typemap(in,noblock=1,fragment=SWIG_AsVal_frag(size_t)) (TYPEMAP, SIZE) (size_t n, Char *buff = 0, $*2_ltype size) {
- if (SWIG_AsVal(size_t)($input, &n) != SWIG_OK) {
+ if (!SWIG_IsOK(SWIG_AsVal(size_t)($input, &n))) {
%argument_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
}
buff= %new_array(n+1, Char);
diff --git a/Lib/typemaps/enumint.swg b/Lib/typemaps/enumint.swg
index 8d80919d1..e9ad5cb62 100644
--- a/Lib/typemaps/enumint.swg
+++ b/Lib/typemaps/enumint.swg
@@ -7,7 +7,7 @@
%typemap(in,fragment=SWIG_AsVal_frag(int),noblock=1) const enum SWIGTYPE& (int val, int ecode, $basetype temp) {
ecode = SWIG_AsVal(int)($input, &val);
- if (ecode != SWIG_OK) {
+ if (!SWIG_IsOK(ecode)) {
%argument_fail(ecode, "$type", $argnum);
} else {
temp = %static_cast(val,$basetype);
@@ -21,7 +21,7 @@
%variable_fail(SWIG_AttributeError,"$type", "arch, read-only $name");
} else {
int ecode = SWIG_AsVal(int)($input, %reinterpret_cast(&$1,int*));
- if (ecode != SWIG_OK) {
+ if (!SWIG_IsOK(ecode)) {
%variable_fail(ecode, "$type", "$name");
}
}
diff --git a/Lib/typemaps/fragments.swg b/Lib/typemaps/fragments.swg
index 6211cd012..14e3cbc6c 100644
--- a/Lib/typemaps/fragments.swg
+++ b/Lib/typemaps/fragments.swg
@@ -357,12 +357,11 @@ SWIG_AsVal_dec(Type)(SWIG_Object obj, Type *val)
{
Base v;
int res = SWIG_AsVal(Base)(obj, &v);
- if (res == SWIG_OK) {
+ if (SWIG_IsOK(res)) {
if (OverflowCond) {
return SWIG_OverflowError;
} else {
if (val) *val = %numeric_cast(v, Type);
- return SWIG_OK;
}
}
return res;
diff --git a/Lib/typemaps/implicit.swg b/Lib/typemaps/implicit.swg
index 5997c5b44..6269658f4 100644
--- a/Lib/typemaps/implicit.swg
+++ b/Lib/typemaps/implicit.swg
@@ -44,7 +44,7 @@
%define %implicit_frag(Type...) ,fragment=SWIG_Traits_frag(Type) %enddef
%define %implicit_code(Type...)
- if (swig::asval<Type >(obj, 0) == SWIG_OK) {
+ if (SWIG_IsOK(swig::asval<Type >(obj, 0))) {
Type _v;
swig::asval<Type >(obj, &_v);
if (val) *val = %new_copy(_v, value_type);
diff --git a/Lib/typemaps/inoutlist.swg b/Lib/typemaps/inoutlist.swg
index dc0062d0a..cbb937e25 100644
--- a/Lib/typemaps/inoutlist.swg
+++ b/Lib/typemaps/inoutlist.swg
@@ -81,7 +81,7 @@ or you can use the %apply directive :
if (!%check_input_ptr($input,&$1,$descriptor,$disown)) {
Type val;
int ecode = asval_meth($input, &val);
- if (ecode != SWIG_OK) {
+ if (!SWIG_IsOK(ecode)) {
%argument_fail(ecode, "$*ltype",$argnum);
}
temp = %static_cast(val, $*ltype);
@@ -93,7 +93,7 @@ or you can use the %apply directive :
if (!%check_input_ptr($input,&$1,$descriptor,$disown)) {
Type val;
int ecode = asval_meth($input, &val);
- if (ecode != SWIG_OK) {
+ if (!SWIG_IsOK(ecode)) {
%argument_fail(ecode, "$*ltype",$argnum);
}
temp = %static_cast(val, $*ltype);
@@ -103,7 +103,12 @@ or you can use the %apply directive :
}
%typemap(typecheck,noblock=1,precedence=code,fragment=asval_frag) Type *INPUT, Type &INPUT {
void *ptr;
- $1 = ((asval_meth($input, 0) == SWIG_OK) || (%check_input_ptr($input,&ptr,$1_descriptor,0)));
+ int res = asval_meth($input, 0);
+ if (SWIG_IsOK(res)) {
+ $1 = SWIG_GetCastRank(res);
+ } else {
+ $1 = %check_input_ptr($input,&ptr,$1_descriptor,0);
+ }
}
%enddef
diff --git a/Lib/typemaps/primtypes.swg b/Lib/typemaps/primtypes.swg
index 16db06769..c245f4b4a 100644
--- a/Lib/typemaps/primtypes.swg
+++ b/Lib/typemaps/primtypes.swg
@@ -106,9 +106,10 @@ SWIGINTERN int
SWIG_AsVal_dec(bool)(SWIG_Object obj, bool *val)
{
long v;
- if (SWIG_AsVal(long)(obj, val ? &v : 0) == SWIG_OK) {
+ int res = SWIG_IsOK(SWIG_AsVal(long)(obj, val ? &v : 0));
+ if (SWIG_IsOK(res)) {
if (val) *val = v ? true : false;
- return SWIG_OK;
+ return res;
}
return SWIG_TypeError;
}
@@ -170,7 +171,7 @@ SWIG_AsVal_dec(size_t)(SWIG_Object obj, size_t *val)
{
unsigned long v;
int res = SWIG_AsVal(unsigned long)(obj, val ? &v : 0);
- if ((res == SWIG_OK) && val) *val = %numeric_cast(v, size_t);
+ if (SWIG_IsOK(res) && val) *val = %numeric_cast(v, size_t);
return res;
}
}
@@ -191,7 +192,7 @@ SWIG_AsVal_dec(ptrdiff_t)(SWIG_Object obj, ptrdiff_t *val)
{
long v;
int res = SWIG_AsVal(long)(obj, val ? &v : 0);
- if ((res == SWIG_OK) && val) *val = %numeric_cast(v, ptrdiff_t);
+ if (SWIG_IsOK(res) && val) *val = %numeric_cast(v, ptrdiff_t);
return res;
}
}
diff --git a/Lib/typemaps/strings.swg b/Lib/typemaps/strings.swg
index 1fb5b2fb5..1ea88f20e 100644
--- a/Lib/typemaps/strings.swg
+++ b/Lib/typemaps/strings.swg
@@ -540,10 +540,10 @@ SWIGINTERN int
SWIG_AsVal_dec(Char)(SWIG_Object obj, Char *val)
{
int res = SWIG_As##CharName##Array(obj, val, 1);
- if (res != SWIG_OK) {
+ if (!SWIG_IsOK(res)) {
long v;
res = SWIG_AsVal(long)(obj, &v);
- if (res == SWIG_OK) {
+ if (SWIG_IsOK(res)) {
if ((CHAR_MIN <= v) && (v <= CHAR_MAX)) {
if (val) *val = %numeric_cast(v, Char);
} else {
diff --git a/Lib/typemaps/traits.swg b/Lib/typemaps/traits.swg
index 6d332a271..840093073 100644
--- a/Lib/typemaps/traits.swg
+++ b/Lib/typemaps/traits.swg
@@ -169,7 +169,7 @@ namespace swig {
template <class Type>
struct traits_checkval {
static bool check SWIG_CHECK_DECL_ARGS(SWIG_Object obj) {
- return obj && (asval SWIG_AS_CALL_ARGS(obj, (Type *)(0)) == SWIG_OK);
+ return obj && SWIG_IsOK(asval SWIG_AS_CALL_ARGS(obj, (Type *)(0)));
}
};
diff --git a/Lib/typemaps/valtypes.swg b/Lib/typemaps/valtypes.swg
index 778c69c5a..c5b286791 100644
--- a/Lib/typemaps/valtypes.swg
+++ b/Lib/typemaps/valtypes.swg
@@ -33,7 +33,7 @@
%define %value_in_typemap(asval_meth,frag,Type...)
%typemap(in,noblock=1,fragment=frag) Type (Type val, int ecode = 0) {
ecode = asval_meth($input, &val);
- if (ecode != SWIG_OK) {
+ if (!SWIG_IsOK(ecode)) {
%argument_fail(ecode, "$ltype", $argnum);
}
$1 = %static_cast(val,$ltype);
@@ -41,7 +41,7 @@
%typemap(freearg) Type "";
%typemap(in,noblock=1,fragment=frag) const Type & ($*ltype temp, Type val, int ecode = 0) {
ecode = asval_meth($input, &val);
- if (ecode != SWIG_OK) {
+ if (!SWIG_IsOK(ecode)) {
%argument_fail(ecode, "$*ltype", $argnum);
}
temp = %static_cast(val, $*ltype);
@@ -67,7 +67,7 @@
%typemap(varin,noblock=1,fragment=frag) Type {
Type val;
int res = asval_meth($input, &val);
- if (res != SWIG_OK) {
+ if (!SWIG_IsOK(res)) {
%variable_fail(res, "$type", "$name");
}
$1 = %static_cast(val,$ltype);
@@ -110,7 +110,7 @@
%typemap(directorargout,noblock=1,fragment=frag) Type *DIRECTOROUT {
Type val;
int res = asval_meth($input, &val);
- if (res != SWIG_OK) {
+ if (!SWIG_IsOK(res)) {
%dirout_fail(res, "$type");
}
*$result = %static_cast(val, $type);
@@ -118,7 +118,7 @@
%typemap(directorout,noblock=1,fragment=frag) Type {
Type val;
int res = asval_meth($input, &val);
- if (res != SWIG_OK) {
+ if (!SWIG_IsOK(res)) {
%dirout_fail(res, "$type");
}
$result = %static_cast(val,$type);
@@ -126,7 +126,7 @@
%typemap(directorout,noblock=1,fragment=frag,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const Type& {
Type val;
int res = asval_meth($input, &val);
- if (res != SWIG_OK) {
+ if (!SWIG_IsOK(res)) {
%dirout_fail(res, "$type");
}
$basetype *temp = new $basetype(($basetype)val);
@@ -161,7 +161,8 @@
%define %value_typecheck_typemap(check,asval_meth,frag,Type...)
%typemap(typecheck,noblock=1,precedence=check,fragment=frag) Type, const Type& {
- $1 = (asval_meth($input, 0) == SWIG_OK);
+ int res = asval_meth($input, NULL);
+ $1 = SWIG_GetCastRank(res);
}
%enddef
diff --git a/Source/Modules/overload.cxx b/Source/Modules/overload.cxx
index 30621f331..86fc7cba3 100644
--- a/Source/Modules/overload.cxx
+++ b/Source/Modules/overload.cxx
@@ -29,12 +29,17 @@ struct Overloaded {
};
static int fast_dispatch_mode = 0;
+static int cast_dispatch_mode = 0;
/* Set fast_dispatch_mode */
void Wrapper_fast_dispatch_mode_set(int flag) {
fast_dispatch_mode = flag;
}
+void Wrapper_cast_dispatch_mode_set(int flag) {
+ cast_dispatch_mode = flag;
+}
+
/* -----------------------------------------------------------------------------
* Swig_overload_rank()
*
@@ -367,7 +372,7 @@ Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *maxargs) {
String *sw = NewString("");
Printf(f,"{\n");
Printf(f,"unsigned long _index = 0;\n");
- Printf(f,"double _rank = 0;\n");
+ Printf(f,"double _rank = 0; \n");
/* Get a list of methods ranked by precedence values and argument count */
List *dispatch = Swig_overload_rank(n, true);
@@ -397,7 +402,7 @@ Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *maxargs) {
Printf(f,"if (%s >= %d) {\n", argc_template_string, num_required);
}
Printf(f,"double _ranki = 0;\n");
- Printf(f,"double _pi = pow(4,%d);\n",num_arguments);
+ Printf(f,"double _pi = 1;\n",num_arguments);
/* create a list with the wrappers that collide with the
current one based on argument number */
@@ -466,7 +471,7 @@ Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *maxargs) {
if (emitcheck) {
if (need_v) {
- Printf(f,"int _v = 1;\n");
+ Printf(f,"int _v;\n");
need_v = 0;
}
if (j >= num_required) {
@@ -478,8 +483,8 @@ Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *maxargs) {
Printv(f,"{\n",tm,"}\n",NIL);
fn = i + 1;
Printf(f, "if (!_v) goto check_%d;\n", fn);
- Printf(f, "_ranki += _0.25*v*_pi;\n", fn);
- Printf(f, "_pi *= 0.25;\n", fn);
+ Printf(f, "_ranki += _v*_pi;\n", fn);
+ Printf(f, "_pi *= SWIG_MAX_CAST_RANK;\n", fn);
}
}
if (!Getattr(pj,"tmap:in:SWIGTYPE") && Getattr(pj,"tmap:typecheck:SWIGTYPE")) {
@@ -499,7 +504,7 @@ Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *maxargs) {
/* close braces */
for (/* empty */; num_braces > 0; num_braces--) Printf(f, "}\n");
- Printf(f,"if (_ranki > _rank) { _rank = _ranki; _index = %d;}\n",i+1);
+ Printf(f,"if (!_index || (_ranki < _rank)) { _rank = _ranki; _index = %d;}\n",i+1);
String *lfmt = ReplaceFormat (fmt, num_arguments);
Printf(sw, "case %d:\n", i+1);
Printf(sw, Char(lfmt),Getattr(ni,"wrap:name"));
diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h
index 13e38ce44..5300040a8 100644
--- a/Source/Modules/swigmod.h
+++ b/Source/Modules/swigmod.h
@@ -321,6 +321,8 @@ void emit_mark_varargs(ParmList *l);
void emit_action(Node *n, Wrapper *f);
void Swig_overload_check(Node *n);
String *Swig_overload_dispatch(Node *n, const String_or_char *fmt, int *);
+String *Swig_overload_dispatch_cast(Node *n, const String_or_char *fmt, int *);
+String *Swig_overload_dispatch_fast(Node *n, const String_or_char *fmt, int *);
SwigType *cplus_value_type(SwigType *t);
/* directors.cxx start */
@@ -351,6 +353,7 @@ void Wrapper_virtual_elimination_mode_set(int);
void Wrapper_director_mode_set(int);
void Wrapper_director_protected_mode_set(int);
void Wrapper_fast_dispatch_mode_set(int);
+void Wrapper_cast_dispatch_mode_set(int);
void clean_overloaded(Node *n);