as() no longer memsets and always throws.

This commit is contained in:
Mike Romberg 2017-07-20 14:28:02 -06:00
commit b27a58b5b8
2 changed files with 10 additions and 15 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>