mirror of https://github.com/swig/swig
Avoid -Wempty-body warnings from SWIG_contract_assert
This commit is contained in:
parent
b624d17f3f
commit
31af3ce9bf
|
@ -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");
|
||||
|
|
|
@ -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\"
|
||||
|
|
|
@ -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)
|
||||
%}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
/* 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)
|
||||
%}
|
||||
|
||||
|
||||
|
|
|
@ -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) \
|
||||
|
|
|
@ -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)
|
||||
%}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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&
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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))
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue