aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2013-03-18 20:47:29 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2013-03-18 20:47:29 +0100
commitefdea080a27d51b522f2414873e5c112201b71e6 (patch)
tree1f1d9a12230dd356fd7e2bde17200e8abdf1d3b3
parent79112159f8f87efb5aa6fc98def89f4cd50545e8 (diff)
downloadsciteco-efdea080a27d51b522f2414873e5c112201b71e6.tar.gz
declare all global inter-dependant objects in main.cpp and get rid of init_priority attribute
* we cannot use weak symbols in MinGW, so we avoid init_priority for symbol initialization by compiling the empty definitions into sciteco-minimal but the real ones into sciteco (had to add new file symbols-minimal.cpp) * this fixes compilation/linking on LLVM Clang AND Dragonegg since their init_priority attribute is broken! this will likely be fixed in the near future but broken versions will be around for some time
-rw-r--r--.gitignore3
-rw-r--r--src/Makefile.am5
-rw-r--r--src/interface-gtk.cpp2
-rw-r--r--src/interface-gtk.h1
-rw-r--r--src/interface-ncurses.cpp2
-rw-r--r--src/interface-ncurses.h1
-rw-r--r--src/main.cpp20
-rw-r--r--src/qregisters.cpp7
-rw-r--r--src/qregisters.h1
-rw-r--r--src/ring.cpp3
-rw-r--r--src/ring.h1
-rw-r--r--src/sciteco.h4
-rwxr-xr-xsrc/symbols-extract.tes20
-rw-r--r--src/symbols-minimal.cpp28
-rw-r--r--src/symbols.cpp8
-rw-r--r--src/symbols.h7
16 files changed, 62 insertions, 51 deletions
diff --git a/.gitignore b/.gitignore
index 570636c..a5c3616 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,7 +30,8 @@ stamp-*
/doc/doxygen
/src/gtk-info-popup*.[ch]
-/src/symbols-*.cpp
+/src/symbols-scintilla.cpp
+/src/symbols-scilexer.cpp
# Backups
*~
diff --git a/src/Makefile.am b/src/Makefile.am
index edd09d1..50ef424 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -13,7 +13,7 @@ EXTRA_DIST = gtk-info-popup.gob \
symbols-extract.tes
noinst_LIBRARIES = libsciteco-base.a
-libsciteco_base_a_SOURCES = sciteco.h \
+libsciteco_base_a_SOURCES = main.cpp sciteco.h \
cmdline.cpp cmdline.h \
undo.cpp undo.h \
expressions.cpp expressions.h \
@@ -47,12 +47,11 @@ if BOOTSTRAP
noinst_PROGRAMS = sciteco-minimal
symbols-scintilla.cpp symbols-scilexer.cpp : sciteco-minimal$(EXEEXT)
endif
-sciteco_minimal_SOURCES = main.cpp
+sciteco_minimal_SOURCES = symbols-minimal.cpp
sciteco_minimal_LDADD = libsciteco-base.a \
@SCINTILLA_PATH@/bin/scintilla.a
bin_PROGRAMS = sciteco
-sciteco_SOURCES = $(sciteco_minimal_SOURCES)
nodist_sciteco_SOURCES = $(nodist_sciteco_minimal_SOURCES) \
symbols-scintilla.cpp symbols-scilexer.cpp
sciteco_LDADD = $(sciteco_minimal_LDADD)
diff --git a/src/interface-gtk.cpp b/src/interface-gtk.cpp
index e27e5f4..f48dc37 100644
--- a/src/interface-gtk.cpp
+++ b/src/interface-gtk.cpp
@@ -41,8 +41,6 @@
#include "interface.h"
#include "interface-gtk.h"
-InterfaceGtk interface INIT_PRIO(PRIO_INTERFACE);
-
extern "C" {
static void scintilla_notify(ScintillaObject *sci, uptr_t idFrom,
SCNotification *notify, gpointer user_data);
diff --git a/src/interface-gtk.h b/src/interface-gtk.h
index baa499c..ed2cabe 100644
--- a/src/interface-gtk.h
+++ b/src/interface-gtk.h
@@ -28,6 +28,7 @@
#include "interface.h"
+/* object declared in main.cpp */
extern class InterfaceGtk : public Interface {
GtkWidget *window;
GtkWidget *editor_widget;
diff --git a/src/interface-ncurses.cpp b/src/interface-ncurses.cpp
index 639c594..bbde5de 100644
--- a/src/interface-ncurses.cpp
+++ b/src/interface-ncurses.cpp
@@ -40,8 +40,6 @@
#include "interface.h"
#include "interface-ncurses.h"
-InterfaceNCurses interface INIT_PRIO(PRIO_INTERFACE);
-
extern "C" {
static void scintilla_notify(Scintilla *sci, int idFrom,
void *notify, void *user_data);
diff --git a/src/interface-ncurses.h b/src/interface-ncurses.h
index 86c193b..da4bbc1 100644
--- a/src/interface-ncurses.h
+++ b/src/interface-ncurses.h
@@ -29,6 +29,7 @@
#include "interface.h"
+/* object declared in main.cpp */
extern class InterfaceNCurses : public Interface {
SCREEN *screen;
FILE *screen_tty;
diff --git a/src/main.cpp b/src/main.cpp
index 968b816..86c6da5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -47,6 +47,26 @@
#define INI_FILE "teco.ini"
#endif
+/*
+ * defining the global objects here ensures
+ * a ctor/dtor order without depending on the
+ * GCC init_priority() attribute
+ */
+#ifdef INTERFACE_GTK
+InterfaceGtk interface;
+#elif defined(INTERFACE_NCURSES)
+InterfaceNCurses interface;
+#endif
+
+/*
+ * Scintilla will be initialized after these
+ * ctors (in main()), but dtors are guaranteed
+ * to be executed before Scintilla's
+ * destruction
+ */
+QRegisterTable QRegisters::globals;
+Ring ring;
+
namespace Flags {
tecoInt ed = 0;
}
diff --git a/src/qregisters.cpp b/src/qregisters.cpp
index a35a6d6..5d8091b 100644
--- a/src/qregisters.cpp
+++ b/src/qregisters.cpp
@@ -54,13 +54,6 @@ namespace States {
}
namespace QRegisters {
- /*
- * NOTE: the ctor will still be called before
- * Scintilla is initialized.
- * But the dtor is called before Scintilla
- * destruction.
- */
- QRegisterTable globals INIT_PRIO(PRIO_INTERFACE+1);
QRegisterTable *locals = NULL;
QRegister *current = NULL;
diff --git a/src/qregisters.h b/src/qregisters.h
index 73ceada..b8b4912 100644
--- a/src/qregisters.h
+++ b/src/qregisters.h
@@ -410,6 +410,7 @@ namespace States {
}
namespace QRegisters {
+ /* object declared in main.cpp */
extern QRegisterTable globals;
extern QRegisterTable *locals;
extern QRegister *current;
diff --git a/src/ring.cpp b/src/ring.cpp
index c082381..3168c88 100644
--- a/src/ring.cpp
+++ b/src/ring.cpp
@@ -54,9 +54,6 @@ namespace States {
StateSaveFile savefile;
}
-/* dtor must be executed before Interface dtor */
-Ring ring INIT_PRIO(PRIO_INTERFACE+1);
-
#ifdef G_OS_WIN32
typedef DWORD FileAttributes;
diff --git a/src/ring.h b/src/ring.h
index 3f13d6a..b695cb6 100644
--- a/src/ring.h
+++ b/src/ring.h
@@ -123,6 +123,7 @@ public:
}
};
+/* object declared in main.cpp */
extern class Ring {
/*
* Emitted after a buffer close
diff --git a/src/sciteco.h b/src/sciteco.h
index b7f92fd..84c9775 100644
--- a/src/sciteco.h
+++ b/src/sciteco.h
@@ -52,10 +52,6 @@ extern sig_atomic_t sigint_occurred;
*/
#define NIL ((void *)0)
-#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 8a47ede..2fe270c 100755
--- a/src/symbols-extract.tes
+++ b/src/symbols-extract.tes
@@ -27,29 +27,15 @@ I/*
#include "sciteco.h"
#include "symbols.h"
-static class SymbolListInitializer_Q#na {
- static const SymbolList::Entry entries[];
-
-public:
- SymbolListInitializer_Q#na();
-} initializer INIT_PRIO(PRIO_SYMBOLS);
-
-const SymbolList::Entry SymbolListInitializer_Q#na::entries[] = {
+static const SymbolList::Entry entries[] = {

<
.,W.Xa 0KK
- I#ifdef Qa
- {"Qa", Qa},
-#endif
-
+ I#ifdef Qa^J^I{"Qa", Qa},^J#endif^J
.-Z;>
I};
-SymbolListInitializer_Q#na::SymbolListInitializer_Q#na()
-{
- Symbols::Q#na.entries = entries;
- Symbols::Q#na.size = G_N_ELEMENTS(entries);
-}
+SymbolList Symbols::Q#na(entries, G_N_ELEMENTS(entries));

! write output file !
diff --git a/src/symbols-minimal.cpp b/src/symbols-minimal.cpp
new file mode 100644
index 0000000..5b1a8ec
--- /dev/null
+++ b/src/symbols-minimal.cpp
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2012-2013 Robin Haberkorn
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sciteco.h"
+#include "symbols.h"
+
+namespace Symbols {
+ SymbolList scintilla;
+ SymbolList scilexer;
+}
diff --git a/src/symbols.cpp b/src/symbols.cpp
index 60abf57..eaa5f80 100644
--- a/src/symbols.cpp
+++ b/src/symbols.cpp
@@ -27,14 +27,6 @@
#include "symbols.h"
/*
- * Constructors executed before the ones defined in generated code.
- */
-namespace Symbols {
- SymbolList scintilla INIT_PRIO(PRIO_SYMBOLS-1);
- SymbolList scilexer INIT_PRIO(PRIO_SYMBOLS-1);
-}
-
-/*
* Since symbol lists are presorted constant arrays we can do a simple
* binary search.
*/
diff --git a/src/symbols.h b/src/symbols.h
index 1e94e98..f2cbc16 100644
--- a/src/symbols.h
+++ b/src/symbols.h
@@ -22,11 +22,13 @@
#include <glib.h>
class SymbolList {
+public:
struct Entry {
const gchar *name;
gint value;
};
+private:
const Entry *entries;
gint size;
int (*cmp_fnc)(const char *, const char *, size_t);
@@ -50,12 +52,9 @@ public:
gint lookup(const gchar *name, const gchar *prefix = "");
GList *get_glist(void);
-
- /* generated per Scintilla SymbolList */
- friend class SymbolListInitializer_scintilla;
- friend class SymbolListInitializer_scilexer;
};
+/* objects declared in symbols-minimal.cpp or auto-generated code */
namespace Symbols {
extern SymbolList scintilla;
extern SymbolList scilexer;