as() no longer memsets and always throws.
This commit is contained in:
parent
a2e3cc0709
commit
b27a58b5b8
2 changed files with 10 additions and 15 deletions
|
|
@ -202,8 +202,8 @@ namespace swig
|
||||||
// swig::SwigVar_PyObject item = OctSequence_GetItem(_seq, _index);
|
// swig::SwigVar_PyObject item = OctSequence_GetItem(_seq, _index);
|
||||||
octave_value item; // * todo
|
octave_value item; // * todo
|
||||||
try {
|
try {
|
||||||
return swig::as<T>(item, true);
|
return swig::as<T>(item);
|
||||||
} catch (std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
char msg[1024];
|
char msg[1024];
|
||||||
sprintf(msg, "in sequence element %d ", _index);
|
sprintf(msg, "in sequence element %d ", _index);
|
||||||
if (!Octave_Error_Occurred()) {
|
if (!Octave_Error_Occurred()) {
|
||||||
|
|
|
||||||
|
|
@ -103,14 +103,14 @@ namespace swig {
|
||||||
|
|
||||||
template <class Type>
|
template <class Type>
|
||||||
struct traits_as<Type, value_category> {
|
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;
|
Type v;
|
||||||
int res = asval(obj, &v);
|
int res = asval(obj, &v);
|
||||||
if (!obj.is_defined() || !SWIG_IsOK(res)) {
|
if (!obj.is_defined() || !SWIG_IsOK(res)) {
|
||||||
if (!Octave_Error_Occurred()) {
|
if (!Octave_Error_Occurred()) {
|
||||||
%type_error(swig::type_name<Type>());
|
%type_error(swig::type_name<Type>());
|
||||||
}
|
}
|
||||||
if (throw_error) throw std::invalid_argument("bad type");
|
throw std::invalid_argument("bad type");
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +118,7 @@ namespace swig {
|
||||||
|
|
||||||
template <class Type>
|
template <class Type>
|
||||||
struct traits_as<Type, pointer_category> {
|
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;
|
Type *v = 0;
|
||||||
int res = traits_asptr<Type>::asptr(obj, &v);
|
int res = traits_asptr<Type>::asptr(obj, &v);
|
||||||
if (SWIG_IsOK(res) && v) {
|
if (SWIG_IsOK(res) && v) {
|
||||||
|
|
@ -130,21 +130,17 @@ namespace swig {
|
||||||
return *v;
|
return *v;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Uninitialized return value, no Type() constructor required.
|
|
||||||
static Type *v_def = (Type*) malloc(sizeof(Type));
|
|
||||||
if (!Octave_Error_Occurred()) {
|
if (!Octave_Error_Occurred()) {
|
||||||
%type_error(swig::type_name<Type>());
|
%type_error(swig::type_name<Type>());
|
||||||
}
|
}
|
||||||
if (throw_error) throw std::invalid_argument("bad type");
|
throw std::invalid_argument("bad type");
|
||||||
memset(v_def,0,sizeof(Type));
|
|
||||||
return *v_def;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Type>
|
template <class Type>
|
||||||
struct traits_as<Type*, pointer_category> {
|
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;
|
Type *v = 0;
|
||||||
int res = traits_asptr<Type>::asptr(obj, &v);
|
int res = traits_asptr<Type>::asptr(obj, &v);
|
||||||
if (SWIG_IsOK(res)) {
|
if (SWIG_IsOK(res)) {
|
||||||
|
|
@ -153,15 +149,14 @@ namespace swig {
|
||||||
if (!Octave_Error_Occurred()) {
|
if (!Octave_Error_Occurred()) {
|
||||||
%type_error(swig::type_name<Type>());
|
%type_error(swig::type_name<Type>());
|
||||||
}
|
}
|
||||||
if (throw_error) throw std::invalid_argument("bad type");
|
throw std::invalid_argument("bad type");
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Type>
|
template <class Type>
|
||||||
inline Type as(const octave_value& obj, bool te = false) {
|
inline Type as(const octave_value& obj) {
|
||||||
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
|
return traits_as<Type, typename traits<Type>::category>::as(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Type>
|
template <class Type>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue