From 63a4fe8d7744a9aed1a064d6e245e0d18170e406 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 7 Apr 2023 10:59:30 +0200 Subject: [PATCH] Issue #1327 fixed (segfault in pymod finalization code) --- src/db/db/dbLayout.h | 12 ++++++------ src/pymod/unit_tests/pymod_tests.cc | 6 ++++++ testdata/pymod/issue1327.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100755 testdata/pymod/issue1327.py diff --git a/src/db/db/dbLayout.h b/src/db/db/dbLayout.h index 87f76b965..232f52465 100644 --- a/src/db/db/dbLayout.h +++ b/src/db/db/dbLayout.h @@ -1952,7 +1952,7 @@ public: explicit LayoutLocker (db::Layout *layout = 0, bool no_update = false) : mp_layout (layout), m_no_update (no_update) { - if (mp_layout) { + if (mp_layout.get ()) { mp_layout->start_changes (); } } @@ -1965,7 +1965,7 @@ public: LayoutLocker (const LayoutLocker &other) : mp_layout (other.mp_layout), m_no_update (other.m_no_update) { - if (mp_layout) { + if (mp_layout.get ()) { mp_layout->start_changes (); } } @@ -1976,17 +1976,17 @@ public: return *this; } - set (other.mp_layout, other.m_no_update); + set (const_cast (other.mp_layout.get ()), other.m_no_update); return *this; } private: - db::Layout *mp_layout; + tl::weak_ptr mp_layout; bool m_no_update; void set (db::Layout *layout, bool no_update) { - if (mp_layout) { + if (mp_layout.get ()) { if (m_no_update) { mp_layout->end_changes_no_update (); } else { @@ -1995,7 +1995,7 @@ private: } mp_layout = layout; m_no_update = no_update; - if (mp_layout) { + if (mp_layout.get ()) { mp_layout->start_changes (); } } diff --git a/src/pymod/unit_tests/pymod_tests.cc b/src/pymod/unit_tests/pymod_tests.cc index 733143794..d523dd344 100644 --- a/src/pymod/unit_tests/pymod_tests.cc +++ b/src/pymod/unit_tests/pymod_tests.cc @@ -71,6 +71,9 @@ int run_pymodtest (tl::TestBase *_this, const std::string &fn) tl::InputPipe pipe (cmd); tl::InputStream is (pipe); text = is.read_all (); + + // subprocess exits without error + EXPECT_EQ (pipe.wait(), 0); } tl::info << text; @@ -89,6 +92,9 @@ PYMODTEST (import_db, "import_db.py") PYMODTEST (import_rdb, "import_rdb.py") PYMODTEST (import_lay, "import_lay.py") +// others +PYMODTEST (issue1327, "issue1327.py") + #if defined(HAVE_QT) && defined(HAVE_QTBINDINGS) PYMODTEST (import_QtCore, "import_QtCore.py") diff --git a/testdata/pymod/issue1327.py b/testdata/pymod/issue1327.py new file mode 100755 index 000000000..b6a4fbed5 --- /dev/null +++ b/testdata/pymod/issue1327.py @@ -0,0 +1,28 @@ +# KLayout Layout Viewer +# Copyright (C) 2006-2023 Matthias Koefferlein +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import klayout.db as kdb + +ly = kdb.Layout() +cell = ly.create_cell("TOP") +parents = cell.each_parent_cell() + +# makes the unit test happy +print("OK") + +# was crashing now in finalization code .. +