From b2b950041d9df15c318cebf1490f16194d8f86ab Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 25 Nov 2023 21:41:36 +0100 Subject: [PATCH] [consider merging] Avoids an assertion when using tuples for out vector parameters --- src/gsi/gsi/gsiSerialisation.cc | 10 +++++++++- src/pya/pya/pyaMarshal.cc | 6 ++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/gsi/gsi/gsiSerialisation.cc b/src/gsi/gsi/gsiSerialisation.cc index 97aa8713e..1744e567c 100644 --- a/src/gsi/gsi/gsiSerialisation.cc +++ b/src/gsi/gsi/gsiSerialisation.cc @@ -23,6 +23,7 @@ #include "gsi.h" #include "gsiSerialisation.h" +#include "tlLog.h" namespace gsi { @@ -38,7 +39,14 @@ public: ~AdaptorSynchronizer () { - mp_src->copy_to (mp_target, *mp_heap); + try { + // NOTE: exceptions must not escape destructors as a basic C++ design requirement + mp_src->copy_to (mp_target, *mp_heap); + } catch (tl::Exception &ex) { + tl::error << ex.msg (); + } catch (...) { + } + delete mp_src; delete mp_target; mp_src = 0; diff --git a/src/pya/pya/pyaMarshal.cc b/src/pya/pya/pyaMarshal.cc index d6aae3e01..a476c4d32 100644 --- a/src/pya/pya/pyaMarshal.cc +++ b/src/pya/pya/pyaMarshal.cc @@ -928,8 +928,10 @@ void PythonBasedVectorAdaptor::push (gsi::SerialArgs &r, tl::Heap &heap) void PythonBasedVectorAdaptor::clear () { - if (PySequence_Check (m_array.get ())) { - PySequence_DelSlice (m_array.get (), 0, PySequence_Length (m_array.get ())); + if (PyList_Check (m_array.get ())) { + PyList_SetSlice (m_array.get (), 0, PyList_Size (m_array.get ()), NULL); + } else if (PyTuple_Check (m_array.get ())) { + throw tl::Exception (tl::to_string (tr ("Tuples cannot be modified and cannot be used as out parameters"))); } }