aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2013-02-01 19:34:23 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2013-02-01 19:34:23 +0100
commit9dd2447d42fd6c822139f3cd1fd2cd284346e5e8 (patch)
tree96f00124bc521f631567a619686da012bb199127 /src
parent850206158f6e77a4798f79fe293a7d7b7a7687f0 (diff)
downloadsciteco-9dd2447d42fd6c822139f3cd1fd2cd284346e5e8.tar.gz
fixed buffer Ring initialization
* there was a dependency on interface initialization. it did not cause issues because destruction order was by chance. * introduced INIT_PRIO and PRIO_* macros to easy initialization order declaration (using a PRIO_* formula makes code self-documenting) * also used this to clean up QRegisterTable initialization (we do not need the explicit initialize() method) * also used to clean up symbols initialization
Diffstat (limited to 'src')
-rw-r--r--src/interface-gtk.cpp2
-rw-r--r--src/interface-ncurses.cpp2
-rw-r--r--src/main.cpp2
-rw-r--r--src/parser.cpp17
-rw-r--r--src/qregisters.cpp5
-rw-r--r--src/qregisters.h5
-rw-r--r--src/ring.cpp3
-rw-r--r--src/sciteco.h4
-rwxr-xr-xsrc/symbols-extract.tes10
-rw-r--r--src/symbols.cpp5
10 files changed, 34 insertions, 21 deletions
diff --git a/src/interface-gtk.cpp b/src/interface-gtk.cpp
index c1a557a..d1d20cd 100644
--- a/src/interface-gtk.cpp
+++ b/src/interface-gtk.cpp
@@ -41,7 +41,7 @@
#include "interface.h"
#include "interface-gtk.h"
-InterfaceGtk interface;
+InterfaceGtk interface INIT_PRIO(PRIO_INTERFACE);
extern "C" {
static void scintilla_notify(ScintillaObject *sci, uptr_t idFrom,
diff --git a/src/interface-ncurses.cpp b/src/interface-ncurses.cpp
index 899043c..b850ad4 100644
--- a/src/interface-ncurses.cpp
+++ b/src/interface-ncurses.cpp
@@ -40,7 +40,7 @@
#include "interface.h"
#include "interface-ncurses.h"
-InterfaceNCurses interface;
+InterfaceNCurses interface INIT_PRIO(PRIO_INTERFACE);
extern "C" {
static void scintilla_notify(Scintilla *sci, int idFrom,
diff --git a/src/main.cpp b/src/main.cpp
index d1a3c84..42ebc71 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -187,7 +187,6 @@ main(int argc, char **argv)
interface.ssm(SCI_STYLESETFONT, STYLE_DEFAULT, (sptr_t)"Courier");
interface.ssm(SCI_STYLECLEARALL);
- QRegisters::globals.initialize();
/* search string and status register */
QRegisters::globals.initialize("_");
/* replacement string register */
@@ -195,7 +194,6 @@ main(int argc, char **argv)
/* current buffer name and number ("*") */
QRegisters::globals.insert(new QRegisterBufferInfo());
- local_qregs.initialize();
QRegisters::locals = &local_qregs;
ring.edit((const gchar *)NULL);
diff --git a/src/parser.cpp b/src/parser.cpp
index 4765f29..37dd055 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -94,8 +94,7 @@ Execute::macro(const gchar *macro, bool locals) throw (State::Error)
GotoTable *parent_goto_table = Goto::table;
GotoTable macro_goto_table(false);
- QRegisterTable *parent_locals = QRegisters::locals;
- QRegisterTable macro_locals(false);
+ QRegisterTable *parent_locals;
State *parent_state = States::current;
gint parent_pc = macro_pc;
@@ -110,8 +109,8 @@ Execute::macro(const gchar *macro, bool locals) throw (State::Error)
Goto::table = &macro_goto_table;
if (locals) {
- macro_locals.initialize();
- QRegisters::locals = &macro_locals;
+ parent_locals = QRegisters::locals;
+ QRegisters::locals = new QRegisterTable(false);
}
try {
@@ -123,7 +122,10 @@ Execute::macro(const gchar *macro, bool locals) throw (State::Error)
g_free(Goto::skip_label);
Goto::skip_label = NULL;
- QRegisters::locals = parent_locals;
+ if (locals) {
+ delete QRegisters::locals;
+ QRegisters::locals = parent_locals;
+ }
Goto::table = parent_goto_table;
macro_pc = parent_pc;
@@ -132,7 +134,10 @@ Execute::macro(const gchar *macro, bool locals) throw (State::Error)
throw; /* forward */
}
- QRegisters::locals = parent_locals;
+ if (locals) {
+ delete QRegisters::locals;
+ QRegisters::locals = parent_locals;
+ }
Goto::table = parent_goto_table;
macro_pc = parent_pc;
diff --git a/src/qregisters.cpp b/src/qregisters.cpp
index eda915b..a13fba1 100644
--- a/src/qregisters.cpp
+++ b/src/qregisters.cpp
@@ -52,7 +52,7 @@ namespace States {
}
namespace QRegisters {
- QRegisterTable globals;
+ QRegisterTable globals INIT_PRIO(PRIO_INTERFACE+1);
QRegisterTable *locals = NULL;
QRegister *current = NULL;
@@ -248,8 +248,7 @@ QRegisterBufferInfo::edit(void)
undo.push_msg(SCI_UNDO);
}
-void
-QRegisterTable::initialize(void)
+QRegisterTable::QRegisterTable(bool _undo) : RBTree(), must_undo(_undo)
{
/* general purpose registers */
for (gchar q = 'A'; q <= 'Z'; q++)
diff --git a/src/qregisters.h b/src/qregisters.h
index 34f20e8..19fd3cd 100644
--- a/src/qregisters.h
+++ b/src/qregisters.h
@@ -156,7 +156,7 @@ class QRegisterTable : public RBTree {
bool must_undo;
public:
- QRegisterTable(bool _undo = true) : RBTree(), must_undo(_undo) {}
+ QRegisterTable(bool _undo = true);
inline QRegister *
insert(QRegister *reg)
@@ -177,9 +177,8 @@ public:
inline void
initialize(gchar name)
{
- initialize((gchar []){name, '\0'});
+ initialize(CHR2STR(name));
}
- void initialize(void);
inline QRegister *
operator [](const gchar *name)
diff --git a/src/ring.cpp b/src/ring.cpp
index 2656ae9..8654686 100644
--- a/src/ring.cpp
+++ b/src/ring.cpp
@@ -54,7 +54,8 @@ namespace States {
StateSaveFile savefile;
}
-Ring ring;
+/* dtor must be executed before Interface dtor */
+Ring ring INIT_PRIO(PRIO_INTERFACE+1);
#ifdef G_OS_WIN32
diff --git a/src/sciteco.h b/src/sciteco.h
index 441b262..e129a4c 100644
--- a/src/sciteco.h
+++ b/src/sciteco.h
@@ -34,6 +34,10 @@ namespace Flags {
extern sig_atomic_t sigint_occurred;
+#define INIT_PRIO(X) __attribute__((init_priority(X)))
+#define PRIO_INTERFACE 1000
+#define PRIO_SYMBOLS 1000
+
#define IS_CTL(C) ((C) < ' ')
#define CTL_ECHO(C) ((C) | 0x40)
#define CTL_KEY(C) ((C) & ~0x40)
diff --git a/src/symbols-extract.tes b/src/symbols-extract.tes
index 841530c..ec3a76a 100755
--- a/src/symbols-extract.tes
+++ b/src/symbols-extract.tes
@@ -51,11 +51,17 @@ Ga ZJB 0,.Mq J
! format as C/C++ array !
I/*
- * AUTOGENERATED - DO NOT EDIT
+ * AUTOGENERATED FROM Qi
+ * DO NOT EDIT
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <glib.h>
#include "Qi"
+#include "sciteco.h"
#include "symbols.h"
static const SymbolList::Entry entries[] = {
@@ -69,7 +75,7 @@ static const SymbolList::Entry entries[] = {
.-Z;>
I};
-__attribute__((constructor(2000)))
+__attribute__((constructor(PRIO_SYMBOLS)))
static void
initialize(void)
{
diff --git a/src/symbols.cpp b/src/symbols.cpp
index 6943b7c..5b0de92 100644
--- a/src/symbols.cpp
+++ b/src/symbols.cpp
@@ -23,14 +23,15 @@
#include <glib.h>
+#include "sciteco.h"
#include "symbols.h"
/*
* Constructors executed before the ones defined in generated code.
*/
namespace Symbols {
- SymbolList __attribute__((init_priority(1000))) scintilla;
- SymbolList __attribute__((init_priority(1000))) scilexer;
+ SymbolList scintilla INIT_PRIO(PRIO_SYMBOLS-1);
+ SymbolList scilexer INIT_PRIO(PRIO_SYMBOLS-1);
}
/*