aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/qregisters.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-20 05:08:19 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-20 05:08:19 +0100
commite909fb2179724b5619213520ca46cc31b4e6713b (patch)
treeb80edd2db67783d9a44a0dc45ffbe7e0baef20fb /src/qregisters.cpp
parentf843a090cdda120d58f968b7936bdcc53b61e323 (diff)
downloadsciteco-e909fb2179724b5619213520ca46cc31b4e6713b.tar.gz
Throw error when a macro terminates while a local q-reg is edited.
This is only a problem if the macro created the local Q-Register table (i.e. not when called with ":M") but resulted in segfaults. Since we do not want to save in a Q-Reg whether it is local (and that wouldn't suffice anyway), we do it in the Q-Register table cleanup. The corresponding QRegisterTable::clear() must be called explicitly, since the RBTree::clear() called on destruction does not and cannot throw errors. If QRegisterTable::clear() has been called successfully, the default object destructor will not do much. If it has thrown an error, the destructor will clean up the remaining Q-Registers.
Diffstat (limited to 'src/qregisters.cpp')
-rw-r--r--src/qregisters.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/qregisters.cpp b/src/qregisters.cpp
index fdb804b..223a707 100644
--- a/src/qregisters.cpp
+++ b/src/qregisters.cpp
@@ -275,6 +275,30 @@ QRegisterTable::edit(QRegister *reg)
QRegisters::current = reg;
}
+/*
+ * This is similar to RBTree::clear() but
+ * has the advantage that we can check whether some
+ * register is currently edited.
+ * Since this is not a destructor, we can throw
+ * errors.
+ * Therefore this method should be called before
+ * a (local) QRegisterTable is deleted.
+ */
+void
+QRegisterTable::clear(void)
+{
+ QRegister *cur;
+
+ while ((cur = (QRegister *)min())) {
+ if (cur == QRegisters::current)
+ throw Error("Currently edited Q-Register \"%s\" "
+ "cannot be discarded", cur->name);
+
+ remove(cur);
+ delete cur;
+ }
+}
+
void
QRegisterStack::UndoTokenPush::run(void)
{