Merge pull request #1027 from mromberg/memset2

stdcommon as() memset() removal for octave, R and scilab
This commit is contained in:
Olly Betts 2017-07-21 13:51:10 +12:00 • committed by GitHub
commit 7ac21f3799
4 changed files with 26 additions and 46 deletions

View file

@ -202,8 +202,8 @@ namespace swig
// swig::SwigVar_PyObject item = OctSequence_GetItem(_seq, _index);
octave_value item; // * todo
try {
return swig::as<T>(item, true);
} catch (std::exception& e) {
return swig::as<T>(item);
} catch (const std::exception& e) {
char msg[1024];
sprintf(msg, "in sequence element %d ", _index);
if (!Octave_Error_Occurred()) {

View file

@ -103,14 +103,14 @@ namespace swig {
template <class Type>
struct traits_as<Type, value_category> {
static Type as(const octave_value& obj, bool throw_error) {
static Type as(const octave_value& obj) {
Type v;
int res = asval(obj, &v);
if (!obj.is_defined() || !SWIG_IsOK(res)) {
if (!Octave_Error_Occurred()) {
%type_error(swig::type_name<Type>());
}
if (throw_error) throw std::invalid_argument("bad type");
throw std::invalid_argument("bad type");
}
return v;
}
@ -118,7 +118,7 @@ namespace swig {
template <class Type>
struct traits_as<Type, pointer_category> {
static Type as(const octave_value& obj, bool throw_error) {
static Type as(const octave_value& obj) {
Type *v = 0;
int res = traits_asptr<Type>::asptr(obj, &v);
if (SWIG_IsOK(res) && v) {
@ -130,21 +130,17 @@ namespace swig {
return *v;
}
} else {
// Uninitialized return value, no Type() constructor required.
static Type *v_def = (Type*) malloc(sizeof(Type));
if (!Octave_Error_Occurred()) {
%type_error(swig::type_name<Type>());
}
if (throw_error) throw std::invalid_argument("bad type");
memset(v_def,0,sizeof(Type));
return *v_def;
throw std::invalid_argument("bad type");
}
}
};
template <class Type>
struct traits_as<Type*, pointer_category> {
static Type* as(const octave_value& obj, bool throw_error) {
static Type* as(const octave_value& obj) {
Type *v = 0;
int res = traits_asptr<Type>::asptr(obj, &v);
if (SWIG_IsOK(res)) {
@ -153,15 +149,14 @@ namespace swig {
if (!Octave_Error_Occurred()) {
%type_error(swig::type_name<Type>());
}
if (throw_error) throw std::invalid_argument("bad type");
return 0;
throw std::invalid_argument("bad type");
}
}
};
template <class Type>
inline Type as(const octave_value& obj, bool te = false) {
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
inline Type as(const octave_value& obj) {
return traits_as<Type, typename traits<Type>::category>::as(obj);
}
template <class Type>

View file

@ -101,12 +101,11 @@ namespace swig {
template <class Type>
struct traits_as<Type, value_category> {
static Type as(SWIG_Object obj, bool throw_error) {
static Type as(SWIG_Object obj) {
Type v;
int res = asval(obj, &v);
if (!obj || !SWIG_IsOK(res)) {
if (throw_error)
throw std::invalid_argument("bad type");
throw std::invalid_argument("bad type");
}
return v;
}
@ -114,7 +113,7 @@ namespace swig {
template <class Type>
struct traits_as<Type, pointer_category> {
static Type as(SWIG_Object obj, bool throw_error) {
static Type as(SWIG_Object obj) {
Type *v = 0;
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
if (SWIG_IsOK(res) && v) {
@ -126,12 +125,7 @@ namespace swig {
return *v;
}
} else {
// Uninitialized return value, no Type() constructor required.
static Type *v_def = (Type*) malloc(sizeof(Type));
if (throw_error)
throw std::invalid_argument("bad type");
memset(v_def,0,sizeof(Type));
return *v_def;
}
}
};
@ -152,8 +146,8 @@ namespace swig {
};
template <class Type>
inline Type as(SWIG_Object obj, bool te = false) {
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
inline Type as(SWIG_Object obj) {
return traits_as<Type, typename traits<Type>::category>::as(obj);
}
template <class Type>

View file

@ -104,23 +104,21 @@ namespace swig {
template <class Type>
struct traits_as<Type, value_category> {
static Type as(const SwigSciObject& obj, bool throw_error) {
static Type as(const SwigSciObject& obj) {
Type v;
int res = asval(obj, &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;
%type_error(swig::type_name<Type>());
throw std::invalid_argument("bad type");
}
}
};
template <class Type>
struct traits_as<Type, pointer_category> {
static Type as(const SwigSciObject& obj, bool throw_error) {
static Type as(const SwigSciObject& obj) {
Type *v = 0;
int res = traits_asptr<Type>::asptr(obj, &v);
if (SWIG_IsOK(res) && v) {
@ -132,36 +130,29 @@ namespace swig {
return *v;
}
} else {
// Uninitialized return value, no Type() constructor required.
static Type *v_def = (Type*) malloc(sizeof(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;
%type_error(swig::type_name<Type>());
throw std::invalid_argument("bad type");
}
}
};
template <class Type>
struct traits_as<Type*, pointer_category> {
static Type* as(const SwigSciObject& obj, bool throw_error) {
static Type* as(const SwigSciObject& obj) {
Type *v = 0;
int res = traits_asptr<Type>::asptr(obj, &v);
if (SWIG_IsOK(res)) {
return v;
} else {
%type_error(swig::type_name<Type>());
if (throw_error)
throw std::invalid_argument("bad type");
return SWIG_OK;
%type_error(swig::type_name<Type>());
throw std::invalid_argument("bad type");
}
}
};
template <class Type>
inline Type as(const SwigSciObject& obj, bool te = false) {
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
inline Type as(const SwigSciObject& obj) {
return traits_as<Type, typename traits<Type>::category>::as(obj);
}
template <class Type>