Permalink
Browse files

Allocate the mainwin on the heap

This lets us return NULL from owl_global_get_mainwin before the mainwin
has been initilized.

Since g has static duration, g.mw is automatically initialized to NULL.
  • Loading branch information...
JasonGross committed Jul 24, 2011
1 parent 8135737 commit ab88b053a39621697d2c5b89fcd5dfd9fbf65b04
Showing with 9 additions and 5 deletions.
  1. +4 −3 global.c
  2. +4 −1 mainwin.c
  3. +1 −1 owl.h
View
@@ -108,7 +108,7 @@ static void _owl_global_init_windows(owl_global *g)
owl_mainpanel_init(&(g->mainpanel));
/* Create the widgets */
- owl_mainwin_init(&(g->mw), g->mainpanel.recwin);
+ g->mw = owl_mainwin_new(g->mainpanel.recwin);
owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin);
owl_sepbar_init(g->mainpanel.sepwin);
@@ -240,8 +240,9 @@ void owl_global_set_markedmsgid(owl_global *g, int i) {
/* windows */
-owl_mainwin *owl_global_get_mainwin(owl_global *g) {
- return(&(g->mw));
+owl_mainwin *owl_global_get_mainwin(owl_global *g)
+{
+ return g->mw;
}
owl_popwin *owl_global_get_popwin(owl_global *g) {
View
@@ -3,8 +3,9 @@
static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data);
static void owl_mainwin_resized(owl_window *w, void *user_data);
-void owl_mainwin_init(owl_mainwin *mw, owl_window *window)
+CALLER_OWN owl_mainwin *owl_mainwin_new(owl_window *window)
{
+ owl_mainwin *mw = g_new(owl_mainwin, 1);
mw->curtruncated=0;
mw->lastdisplayed=-1;
mw->window = g_object_ref(window);
@@ -15,6 +16,8 @@ void owl_mainwin_init(owl_mainwin *mw, owl_window *window)
/* For now, we do not bother with connecting up dependencies; that'll be a
* future refactor of the mainwin */
+
+ return mw;
}
static void owl_mainwin_resized(owl_window *w, void *user_data)
View
2 owl.h
@@ -532,7 +532,7 @@ typedef struct _owl_popexec {
} owl_popexec;
typedef struct _owl_global {
- owl_mainwin mw;
+ owl_mainwin *mw;
owl_popwin *pw;
owl_msgwin msgwin;
owl_history cmdhist; /* command history */

0 comments on commit ab88b05

Please sign in to comment.