diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2013-02-21 21:49:19 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2013-02-22 01:18:06 +0100 |
commit | 5611d53c8c5ecf586233636d6090ce7e47644e04 (patch) | |
tree | 3e14daa1cb71778d5f54a3714eaba32fdc226eae | |
parent | 8f0e72f0fedbfc8e4f26bff93472d0c1d59247df (diff) | |
download | sciteco-5611d53c8c5ecf586233636d6090ce7e47644e04.tar.gz |
fixed global object initialization order issue
* Scintilla is now initialized from main() using Interface::main()
* Scintilla initialization depends on initialization of objects in the
global namespace (otherwise the Lexer catalogue may not be filled
properly and lexing may not work). Lexer modules were initialized
after SciTECO interface initialization
* merged Scintilla initialization (Interface::main()) with interface
option parsing
-rw-r--r-- | src/interface-gtk.cpp | 11 | ||||
-rw-r--r-- | src/interface-gtk.h | 12 | ||||
-rw-r--r-- | src/interface-ncurses.cpp | 19 | ||||
-rw-r--r-- | src/interface-ncurses.h | 21 | ||||
-rw-r--r-- | src/interface.h | 3 | ||||
-rw-r--r-- | src/main.cpp | 6 | ||||
-rw-r--r-- | src/qregisters.cpp | 6 |
7 files changed, 53 insertions, 25 deletions
diff --git a/src/interface-gtk.cpp b/src/interface-gtk.cpp index d1d20cd..cc39699 100644 --- a/src/interface-gtk.cpp +++ b/src/interface-gtk.cpp @@ -53,12 +53,13 @@ static gboolean exit_app(GtkWidget *w, GdkEventAny *e, gpointer p); #define UNNAMED_FILE "(Unnamed)" -InterfaceGtk::InterfaceGtk() +void +InterfaceGtk::main(int &argc, char **&argv) { GtkWidget *vbox; GtkWidget *info_content; - gtk_init(NULL, NULL); + gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), PACKAGE_NAME); @@ -203,8 +204,10 @@ InterfaceGtk::widget_set_font(GtkWidget *widget, const gchar *font_name) InterfaceGtk::~InterfaceGtk() { - gtk_widget_destroy(popup_widget); - gtk_widget_destroy(window); + if (popup_widget) + gtk_widget_destroy(popup_widget); + if (window) + gtk_widget_destroy(window); scintilla_release_resources(); } diff --git a/src/interface-gtk.h b/src/interface-gtk.h index 43e9e89..baa499c 100644 --- a/src/interface-gtk.h +++ b/src/interface-gtk.h @@ -37,7 +37,11 @@ extern class InterfaceGtk : public Interface { GtkWidget *popup_widget; public: - InterfaceGtk(); + InterfaceGtk() : window(NULL), + editor_widget(NULL), + cmdline_widget(NULL), + info_widget(NULL), message_widget(NULL), + popup_widget(NULL) {} ~InterfaceGtk(); inline GOptionGroup * @@ -45,11 +49,7 @@ public: { return gtk_get_option_group(TRUE); } - inline void - parse_args(int &argc, char **&argv) - { - gtk_parse_args(&argc, &argv); - } + void main(int &argc, char **&argv); void vmsg(MessageType type, const gchar *fmt, va_list ap); void msg_clear(void); diff --git a/src/interface-ncurses.cpp b/src/interface-ncurses.cpp index a0e1e9a..3458813 100644 --- a/src/interface-ncurses.cpp +++ b/src/interface-ncurses.cpp @@ -52,7 +52,9 @@ static void scintilla_notify(Scintilla *sci, int idFrom, #define SCI_COLOR_ATTR(f, b) \ COLOR_PAIR(SCI_COLOR_PAIR(f, b)) -InterfaceNCurses::InterfaceNCurses() +void +InterfaceNCurses::main(int &argc __attribute__((unused)), + char **&argv __attribute__((unused))) { init_screen(); cbreak(); @@ -442,18 +444,23 @@ InterfaceNCurses::Popup::~Popup() InterfaceNCurses::~InterfaceNCurses() { - delwin(info_window); + if (info_window) + delwin(info_window); g_free(info_current); /* also deletes curses window */ - scintilla_delete(sci); - delwin(cmdline_window); + if (sci) + scintilla_delete(sci); + if (cmdline_window) + delwin(cmdline_window); g_free(cmdline_current); - delwin(msg_window); + if (msg_window) + delwin(msg_window); if (!isendwin()) endwin(); - delscreen(screen); + if (screen) + delscreen(screen); if (screen_tty) fclose(screen_tty); } diff --git a/src/interface-ncurses.h b/src/interface-ncurses.h index dffa892..86c193b 100644 --- a/src/interface-ncurses.h +++ b/src/interface-ncurses.h @@ -52,14 +52,20 @@ extern class InterfaceNCurses : public Interface { ~Popup(); } popup; - void init_screen(void); - void resize_all_windows(void); - void draw_info(void); - public: - InterfaceNCurses(); + InterfaceNCurses() : screen(NULL), + screen_tty(NULL), + sci(NULL), + info_window(NULL), + info_current(NULL), + sci_window(NULL), + msg_window(NULL), + cmdline_window(NULL), + cmdline_current(NULL) {} ~InterfaceNCurses(); + void main(int &argc, char **&argv); + void vmsg(MessageType type, const gchar *fmt, va_list ap); void msg_clear(void); @@ -81,6 +87,11 @@ public: /* main entry point */ void event_loop(void); + +private: + void init_screen(void); + void resize_all_windows(void); + void draw_info(void); } interface; #endif diff --git a/src/interface.h b/src/interface.h index 24c5b89..6f7bc84 100644 --- a/src/interface.h +++ b/src/interface.h @@ -63,7 +63,8 @@ public: { return NULL; } - virtual void parse_args(int &argc, char **&argv) {} + /* expected to initialize Scintilla */ + virtual void main(int &argc, char **&argv) = 0; enum MessageType { MSG_USER, diff --git a/src/main.cpp b/src/main.cpp index 78e4daa..9979ee8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -160,9 +160,7 @@ process_options(int &argc, char **&argv) mung_file = get_teco_ini(argv[0]); } - interface.parse_args(argc, argv); - - /* remaining arguments, are arguments to the munged file */ + /* remaining arguments, are arguments to the interface */ } static inline void @@ -197,6 +195,8 @@ main(int argc, char **argv) signal(SIGINT, sigint_handler); process_options(argc, argv); + interface.main(argc, argv); + /* remaining arguments are arguments to the munged file */ interface.ssm(SCI_SETCARETSTYLE, CARETSTYLE_BLOCK); interface.ssm(SCI_SETCARETFORE, 0xFFFFFF); diff --git a/src/qregisters.cpp b/src/qregisters.cpp index 41e1a16..69b3ea9 100644 --- a/src/qregisters.cpp +++ b/src/qregisters.cpp @@ -53,6 +53,12 @@ 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; |