diff --git a/Examples/test-suite/aggregate.i b/Examples/test-suite/aggregate.i index dc00f0605..8ac31ece7 100644 --- a/Examples/test-suite/aggregate.i +++ b/Examples/test-suite/aggregate.i @@ -6,7 +6,7 @@ To support contracts, you need to add a macro to the runtime. For Python, it looks like this: -#define SWIG_contract_assert(expr, msg) if (!(expr)) { PyErr_SetString(PyExc_RuntimeError, (char *) msg #expr ); goto fail; } else +#define SWIG_contract_assert(expr, msg) do { if (!(expr)) { PyErr_SetString(PyExc_RuntimeError, (char *) msg #expr ); goto fail; } } while (0) Note: It is used like this: SWIG_contract_assert(x == 1, "Some kind of error message"); diff --git a/Examples/test-suite/javascript/Makefile.in b/Examples/test-suite/javascript/Makefile.in index 0e11f3d9d..c0c73e242 100644 --- a/Examples/test-suite/javascript/Makefile.in +++ b/Examples/test-suite/javascript/Makefile.in @@ -47,9 +47,6 @@ ifeq (node,$(JSENGINE)) SWIGOPT += -v8 -DBUILDING_NODE_EXTENSION=1 # shut up some warnings - # contract macro has an empty 'else' at the end... - aggregate.cpptest: GYP_CFLAGS = \"-Wno-empty-body\" - contract.cpptest: GYP_CFLAGS = \"-Wno-empty-body\" # dunno... ignoring generously apply_signed_char.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\" diff --git a/Lib/csharp/csharphead.swg b/Lib/csharp/csharphead.swg index 7db4c0e3c..56a019bd5 100644 --- a/Lib/csharp/csharphead.swg +++ b/Lib/csharp/csharphead.swg @@ -335,5 +335,5 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterStringCallback_$module(SWIG_CSharpString %insert(runtime) %{ /* Contract support */ -#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, msg, ""); return nullreturn; } else +#define SWIG_contract_assert(nullreturn, expr, msg) do { if (!(expr)) {SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, msg, ""); return nullreturn; } } while (0) %} diff --git a/Lib/d/dhead.swg b/Lib/d/dhead.swg index 50e9c2e87..1ef1e4164 100644 --- a/Lib/d/dhead.swg +++ b/Lib/d/dhead.swg @@ -12,7 +12,7 @@ #include /* Contract support. */ -#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_DSetPendingException(SWIG_DException, msg); return nullreturn; } else +#define SWIG_contract_assert(nullreturn, expr, msg) do { if (!(expr)) {SWIG_DSetPendingException(SWIG_DException, msg); return nullreturn; } } while (0) %} diff --git a/Lib/guile/guile_scm_run.swg b/Lib/guile/guile_scm_run.swg index 86e5c3be0..2e96184b1 100644 --- a/Lib/guile/guile_scm_run.swg +++ b/Lib/guile/guile_scm_run.swg @@ -65,10 +65,12 @@ typedef struct swig_guile_clientdata { #define SWIG_IsPointer(object) \ SWIG_Guile_IsPointer(object) #define SWIG_contract_assert(expr, msg) \ - if (!(expr)) \ - scm_error(scm_from_locale_symbol("swig-contract-assertion-failed"), \ - (char *) FUNC_NAME, (char *) msg, \ - SCM_EOL, SCM_BOOL_F); else + do { \ + if (!(expr)) \ + scm_error(scm_from_locale_symbol("swig-contract-assertion-failed"), \ + (char *) FUNC_NAME, (char *) msg, \ + SCM_EOL, SCM_BOOL_F); \ + } while (0) /* for C++ member pointers, ie, member methods */ #define SWIG_ConvertMember(obj, ptr, sz, ty) \ diff --git a/Lib/java/javahead.swg b/Lib/java/javahead.swg index 1fc327909..758a037d1 100644 --- a/Lib/java/javahead.swg +++ b/Lib/java/javahead.swg @@ -87,5 +87,5 @@ static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionC %insert(runtime) %{ /* Contract support */ -#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else +#define SWIG_contract_assert(nullreturn, expr, msg) do { if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } } while (0) %} diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg index 1de9cc829..0bf233cd1 100644 --- a/Lib/lua/luarun.swg +++ b/Lib/lua/luarun.swg @@ -307,7 +307,7 @@ typedef struct { /* Contract support */ #define SWIG_contract_assert(expr, msg) \ - if (!(expr)) { SWIG_Lua_pusherrstring(L, (char *) msg); goto fail; } else + do { if (!(expr)) { SWIG_Lua_pusherrstring(L, (char *) msg); goto fail; } } while (0) /* helper #defines */ diff --git a/Lib/lua/luatypemaps.swg b/Lib/lua/luatypemaps.swg index 3f531bd05..3a75753c1 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -24,7 +24,7 @@ // additional check for unsigned numbers, to not permit negative input %typemap(in,checkfn="lua_isnumber") unsigned int, unsigned short, unsigned long, unsigned char -%{SWIG_contract_assert((lua_tonumber(L,$input)>=0),"number must not be negative") +%{SWIG_contract_assert((lua_tonumber(L,$input)>=0),"number must not be negative"); $1 = ($type)lua_tonumber(L, $input);%} %typemap(out) int,short,long, @@ -43,7 +43,7 @@ $1 = ($type)lua_tonumber(L, $input);%} %{ temp=($*1_ltype)lua_tonumber(L,$input); $1=&temp;%} %typemap(in,checkfn="lua_isnumber") const unsigned int&($*1_ltype temp) -%{SWIG_contract_assert((lua_tonumber(L,$input)>=0),"number must not be negative") +%{SWIG_contract_assert((lua_tonumber(L,$input)>=0),"number must not be negative"); temp=($*1_ltype)lua_tonumber(L,$input); $1=&temp;%} %typemap(out) const int&, const unsigned int& diff --git a/Lib/mzscheme/mzrun.swg b/Lib/mzscheme/mzrun.swg index c438c9ce8..279073113 100644 --- a/Lib/mzscheme/mzrun.swg +++ b/Lib/mzscheme/mzrun.swg @@ -23,12 +23,14 @@ extern "C" { SWIG_MzScheme_MustGetPtr(s, type, argnum, flags, FUNC_NAME, argc, argv) #define SWIG_contract_assert(expr,msg) \ - if (!(expr)) { \ - char *m=(char *) scheme_malloc(strlen(msg)+1000); \ - sprintf(m,"SWIG contract, assertion failed: function=%s, message=%s", \ - (char *) FUNC_NAME,(char *) msg); \ - scheme_signal_error(m); \ - } + do { \ + if (!(expr)) { \ + char *m=(char *) scheme_malloc(strlen(msg)+1000); \ + sprintf(m,"SWIG contract, assertion failed: function=%s, message=%s", \ + (char *) FUNC_NAME,(char *) msg); \ + scheme_signal_error(m); \ + } \ + } while (0) /* Runtime API */ #define SWIG_GetModule(clientdata) SWIG_MzScheme_GetModule((Scheme_Env *)(clientdata)) diff --git a/Lib/ocaml/ocamlrundec.swg b/Lib/ocaml/ocamlrundec.swg index 555f9a44f..dde0b8e5c 100644 --- a/Lib/ocaml/ocamlrundec.swg +++ b/Lib/ocaml/ocamlrundec.swg @@ -164,7 +164,7 @@ SWIGINTERN void SWIG_OCamlThrowException(SWIG_OCamlExceptionCodes code, const ch CAMLreturn0; } -#define SWIG_contract_assert(expr, msg) if(!(expr)) {SWIG_OCamlThrowException(SWIG_OCamlRuntimeException, msg);} +#define SWIG_contract_assert(expr, msg) do { if(!(expr)) {SWIG_OCamlThrowException(SWIG_OCamlRuntimeException, msg);} } while (0) SWIGINTERN int SWIG_GetPtr(void *source, void **result, swig_type_info *type, swig_type_info *result_type); diff --git a/Lib/typemaps/exception.swg b/Lib/typemaps/exception.swg index b60a32996..e48294c3f 100644 --- a/Lib/typemaps/exception.swg +++ b/Lib/typemaps/exception.swg @@ -30,7 +30,7 @@ %define_as(SWIG_exception_fail(code, msg), %block(%error(code, msg); SWIG_fail)) -%define_as(SWIG_contract_assert(expr, msg), if (!(expr)) { %error(SWIG_RuntimeError, msg); SWIG_fail; } else) +%define_as(SWIG_contract_assert(expr, msg), do { if (!(expr)) { %error(SWIG_RuntimeError, msg); SWIG_fail; } } while (0)) }