[consider merging] Avoids an assertion when using tuples for out vector parameters

This commit is contained in:
Matthias Koefferlein 2023-11-25 21:41:36 +01:00
parent 38d7d34642
commit b2b950041d
2 changed files with 13 additions and 3 deletions

View File

@ -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;

View File

@ -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")));
}
}