From 0bf380ff110897d2b5db2e22ef6efe1e9ba9888d Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 22 Nov 2016 16:16:58 +0100 Subject: fixed local Q-Register management on certain broken platforms * on MSVCRT/MinGW, space allocated with alloca()/g_newa() was apparently freed once the first exception was caught. This prevented the proper destruction of local Q-Reg tables and broke the Windows port. * Since all alternatives to alloca() like VLAs are not practical, the default Q-Register initialization has been moved out of the QRegisterTable constructor into QRegisterTable::insert_defaults(). * The remaining QRegisterTable initialization and destruction is very cheap, so we simply reserve an empty QRegisterTable for local registers on every Execute::macro() call. The default registers are only initialized when required, though. * All of this has to change anyway once we replace the C++ call-stack approach to macro calls with our own macro call frame memory management. --- src/qregisters.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/qregisters.h') diff --git a/src/qregisters.h b/src/qregisters.h index 4648149..fc7a624 100644 --- a/src/qregisters.h +++ b/src/qregisters.h @@ -286,6 +286,12 @@ public: class QRegisterTable : private RBTreeString, public Object { class UndoTokenRemove : public UndoToken { + /* + * NOTE: Storing the table here is only necessary since + * we may have to remove from a global or local Q-Reg + * table. This could be avoided using a separate + * subclass for local registers. + */ QRegisterTable *table; QRegister *reg; @@ -303,7 +309,8 @@ class QRegisterTable : private RBTreeString, public Object { bool must_undo; public: - QRegisterTable(bool _undo = true); + QRegisterTable(bool _must_undo = true) + : must_undo(_must_undo) {} ~QRegisterTable() { @@ -339,6 +346,8 @@ public: return insert(buf); } + void insert_defaults(void); + inline QRegister * find(const gchar *name) { -- cgit v1.2.3