From b27a58b5b85698db763452bd7cb14f07338e13f6 Mon Sep 17 00:00:00 2001 From: Mike Romberg Date: Thu, 20 Jul 2017 14:28:02 -0600 Subject: [PATCH] as() no longer memsets and always throws. --- Lib/octave/octcontainer.swg | 4 ++-- Lib/octave/octstdcommon.swg | 21 ++++++++------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Lib/octave/octcontainer.swg b/Lib/octave/octcontainer.swg index 771edbde0..9b6520739 100644 --- a/Lib/octave/octcontainer.swg +++ b/Lib/octave/octcontainer.swg @@ -202,8 +202,8 @@ namespace swig // swig::SwigVar_PyObject item = OctSequence_GetItem(_seq, _index); octave_value item; // * todo try { - return swig::as(item, true); - } catch (std::exception& e) { + return swig::as(item); + } catch (const std::exception& e) { char msg[1024]; sprintf(msg, "in sequence element %d ", _index); if (!Octave_Error_Occurred()) { diff --git a/Lib/octave/octstdcommon.swg b/Lib/octave/octstdcommon.swg index b3b3d0048..80b2154d9 100644 --- a/Lib/octave/octstdcommon.swg +++ b/Lib/octave/octstdcommon.swg @@ -103,14 +103,14 @@ namespace swig { template struct traits_as { - 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()); } - if (throw_error) throw std::invalid_argument("bad type"); + throw std::invalid_argument("bad type"); } return v; } @@ -118,7 +118,7 @@ namespace swig { template struct traits_as { - static Type as(const octave_value& obj, bool throw_error) { + static Type as(const octave_value& obj) { Type *v = 0; int res = traits_asptr::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()); } - 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 struct traits_as { - static Type* as(const octave_value& obj, bool throw_error) { + static Type* as(const octave_value& obj) { Type *v = 0; int res = traits_asptr::asptr(obj, &v); if (SWIG_IsOK(res)) { @@ -153,15 +149,14 @@ namespace swig { if (!Octave_Error_Occurred()) { %type_error(swig::type_name()); } - if (throw_error) throw std::invalid_argument("bad type"); - return 0; + throw std::invalid_argument("bad type"); } } }; template - inline Type as(const octave_value& obj, bool te = false) { - return traits_as::category>::as(obj, te); + inline Type as(const octave_value& obj) { + return traits_as::category>::as(obj); } template