remove bool from as() (it now always throws).

catch std::invalid_argument (what is expected) instread of std::exception.
This commit is contained in:
Mike Romberg 2017-07-03 12:49:30 -06:00
commit b229d92f9b
2 changed files with 9 additions and 10 deletions

View file

@ -434,8 +434,8 @@ namespace swig
{
swig::SwigVar_PyObject item = PySequence_GetItem(_seq, _index);
try {
return swig::as<T>(item, true);
} catch (std::exception& e) {
return swig::as<T>(item);
} catch (const std::invalid_argument& e) {
char msg[1024];
sprintf(msg, "in sequence element %d ", (int)_index);
if (!PyErr_Occurred()) {

View file

@ -107,14 +107,14 @@ namespace swig {
template <class Type>
struct traits_as<Type, value_category> {
static Type as(PyObject *obj, bool throw_error) {
static Type as(PyObject *obj) {
Type v;
int res = asval(obj, &v);
if (!obj || !SWIG_IsOK(res)) {
if (!PyErr_Occurred()) {
::%type_error(swig::type_name<Type>());
}
if (throw_error) throw std::invalid_argument("bad type");
throw std::invalid_argument("bad type");
}
return v;
}
@ -122,7 +122,7 @@ namespace swig {
template <class Type>
struct traits_as<Type, pointer_category> {
static Type as(PyObject *obj, bool /* throw_error */) {
static Type as(PyObject *obj) {
Type *v = 0;
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
if (SWIG_IsOK(res) && v) {
@ -144,7 +144,7 @@ namespace swig {
template <class Type>
struct traits_as<Type*, pointer_category> {
static Type* as(PyObject *obj, bool throw_error) {
static Type* as(PyObject *obj) {
Type *v = 0;
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : SWIG_ERROR);
if (SWIG_IsOK(res)) {
@ -153,15 +153,14 @@ namespace swig {
if (!PyErr_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(PyObject *obj, bool te = false) {
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
inline Type as(PyObject *obj) {
return traits_as<Type, typename traits<Type>::category>::as(obj);
}
template <class Type>