scilab: clean error management code, remove useless macros

This commit is contained in:
Simon Marchetto 2014-04-04 11:29:46 +02:00
commit 7af4bc72c6
3 changed files with 39 additions and 41 deletions

View file

@ -65,7 +65,7 @@ namespace swig
}
catch (std::exception& e)
{
SWIG_Scilab_AddErrorMsg(e.what());
SWIG_Scilab_ErrorMsg(SWIG_RuntimeError, e.what());
}
}
@ -395,7 +395,7 @@ namespace swig {
}
catch (std::exception& e)
{
SWIG_Scilab_AddErrorMsg(e.what());
SWIG_Scilab_ErrorMsg(SWIG_RuntimeError, e.what());
}
}
}
@ -436,7 +436,7 @@ namespace swig {
}
catch (std::exception& e)
{
SWIG_Scilab_AddErrorMsg(e.what());
SWIG_Scilab_ErrorMsg(SWIG_RuntimeError, e.what());
}
}
};

View file

@ -222,6 +222,7 @@ SWIG_Scilab_ErrorType(int code) {
return "RuntimeError";
}
}
#define SWIG_ErrorType(code) SWIG_Scilab_ErrorType(code)
SWIGINTERN void
SWIG_Scilab_ErrorMsg(int code, const char *msg)
@ -229,11 +230,10 @@ SWIG_Scilab_ErrorMsg(int code, const char *msg)
Scierror(999, _("SWIG/Scilab %s: %s.\n"), SWIG_Scilab_ErrorType(code), msg);
}
#define SWIG_fail return SWIG_ERROR;
#define SWIG_ErrorType(code) SWIG_Scilab_ErrorType(code)
#define SWIG_Error(code, msg) SWIG_Scilab_ErrorMsg(code, msg)
#define SWIG_Error(code, msg) SWIG_Scilab_ErrorMsg(code, msg)
#define SWIG_fail return SWIG_ERROR;
#define SWIG_Scilab_Raise(obj, type, desc) SwigScilabRaise(type)
SWIGRUNTIME int
SwigScilabRaise(const char *type) {
@ -243,9 +243,7 @@ SwigScilabRaise(const char *type) {
#endif
}
#define Scilab_Error_Occurred() 0
#define SWIG_Scilab_AddErrorMsg(msg) {;}
#define SWIG_Scilab_Raise(obj, type, desc) SwigScilabRaise(type)
/*
* Pointer utility functions

View file

@ -61,7 +61,8 @@ namespace swig {
if (val) {
Type *p = 0;
int res = traits_asptr<Type>::asptr(obj, &p);
if (!SWIG_IsOK(res)) return res;
if (!SWIG_IsOK(res))
return res;
if (p) {
typedef typename noconst_traits<Type>::noconst_type noconst_type;
*(const_cast<noconst_type*>(val)) = *p;
@ -105,13 +106,14 @@ namespace swig {
static Type as(const SwigSciObject& obj, bool throw_error) {
Type v;
int res = asval(obj, &v);
//if (!obj.is_defined() || !SWIG_IsOK(res)) {
if (!Scilab_Error_Occurred()) {
%type_error(swig::type_name<Type>());
}
if (throw_error) throw std::invalid_argument("bad type");
//}
return v;
if (SWIG_IsOK(res)) {
return v;
} else {
%type_error(swig::type_name<Type>());
if (throw_error)
throw std::invalid_argument("bad type");
return res;
}
}
};
@ -131,10 +133,9 @@ namespace swig {
} else {
// Uninitialized return value, no Type() constructor required.
static Type *v_def = (Type*) malloc(sizeof(Type));
if (!Scilab_Error_Occurred()) {
%type_error(swig::type_name<Type>());
}
if (throw_error) throw std::invalid_argument("bad type");
%type_error(swig::type_name<Type>());
if (throw_error)
throw std::invalid_argument("bad type");
memset(v_def,0,sizeof(Type));
return *v_def;
}
@ -149,10 +150,9 @@ namespace swig {
if (SWIG_IsOK(res)) {
return v;
} else {
if (!Scilab_Error_Occurred()) {
%type_error(swig::type_name<Type>());
}
if (throw_error) throw std::invalid_argument("bad type");
%type_error(swig::type_name<Type>());
if (throw_error)
throw std::invalid_argument("bad type");
return SWIG_OK;
}
}