Permalink
Browse files

Allocate owl_messagelist on the heap

This lets us return NULL from owl_global_get_messagelist before the
messagelist has been initilized.

Since g has static duration, g.ml is automatically initialized to NULL.
  • Loading branch information...
1 parent ab88b05 commit 219f52ca5fddec776365b3e66f4e5415d11a1d40 @JasonGross JasonGross committed Jul 24, 2011
Showing with 19 additions and 18 deletions.
  1. +2 −2 global.c
  2. +5 −2 messagelist.c
  3. +2 −2 owl.h
  4. +10 −12 view.c
View
@@ -74,7 +74,7 @@ void owl_global_init(owl_global *g) {
owl_global_set_confdir(g, cd);
g_free(cd);
- owl_messagelist_create(&(g->msglist));
+ g->msglist = owl_messagelist_new();
_owl_global_init_windows(g);
@@ -256,7 +256,7 @@ void owl_global_set_popwin(owl_global *g, owl_popwin *pw) {
/* msglist */
owl_messagelist *owl_global_get_msglist(owl_global *g) {
- return(&(g->msglist));
+ return g->msglist;
}
/* keyhandler */
View
@@ -1,15 +1,18 @@
#include "owl.h"
-void owl_messagelist_create(owl_messagelist *ml)
+CALLER_OWN owl_messagelist *owl_messagelist_new(void)
{
+ owl_messagelist *ml = g_new(owl_messagelist, 1);
ml->list = g_ptr_array_new();
+ return ml;
}
-void owl_messagelist_cleanup(owl_messagelist *ml, bool free_messages)
+void owl_messagelist_delete(owl_messagelist *ml, bool free_messages)
{
if (free_messages)
g_ptr_array_foreach(ml->list, (GFunc)owl_message_delete, NULL);
g_ptr_array_free(ml->list, true);
+ g_free(ml);
}
int owl_messagelist_get_size(const owl_messagelist *ml)
View
@@ -451,7 +451,7 @@ typedef struct _owl_filter {
typedef struct _owl_view {
char *name;
owl_filter *filter;
- owl_messagelist ml;
+ owl_messagelist *ml;
const owl_style *style;
int cachedmsgid;
} owl_view;
@@ -550,7 +550,7 @@ typedef struct _owl_global {
int markedmsgid; /* for finding the marked message when it has moved. */
int curmsg_vert_offset;
owl_view current_view;
- owl_messagelist msglist;
+ owl_messagelist *msglist;
WINDOW *input_pad;
owl_mainpanel mainpanel;
gulong typwin_erase_id;
View
@@ -5,7 +5,7 @@ void owl_view_create(owl_view *v, const char *name, owl_filter *f, const owl_sty
v->name=g_strdup(name);
v->filter=f;
v->style=s;
- owl_messagelist_create(&(v->ml));
+ v->ml = owl_messagelist_new();
owl_view_recalculate(v);
}
@@ -18,7 +18,7 @@ const char *owl_view_get_name(const owl_view *v)
void owl_view_consider_message(owl_view *v, owl_message *m)
{
if (owl_filter_message_match(v->filter, m)) {
- owl_messagelist_append_element(&(v->ml), m);
+ owl_messagelist_append_element(v->ml, m);
}
}
@@ -29,22 +29,20 @@ void owl_view_recalculate(owl_view *v)
{
int i, j;
const owl_messagelist *gml;
- owl_messagelist *ml;
owl_message *m;
gml=owl_global_get_msglist(&g);
- ml=&(v->ml);
/* nuke the old list, don't free the messages */
- owl_messagelist_cleanup(ml, false);
- owl_messagelist_create(&(v->ml));
+ owl_messagelist_delete(v->ml, false);
+ v->ml = owl_messagelist_new();
/* find all the messages we want */
j=owl_messagelist_get_size(gml);
for (i=0; i<j; i++) {
m=owl_messagelist_get_element(gml, i);
if (owl_filter_message_match(v->filter, m)) {
- owl_messagelist_append_element(ml, m);
+ owl_messagelist_append_element(v->ml, m);
}
}
}
@@ -71,22 +69,22 @@ const char *owl_view_get_style_name(const owl_view *v) {
owl_message *owl_view_get_element(const owl_view *v, int index)
{
- return(owl_messagelist_get_element(&(v->ml), index));
+ return owl_messagelist_get_element(v->ml, index);
}
void owl_view_delete_element(owl_view *v, int index)
{
- owl_messagelist_delete_element(&(v->ml), index);
+ owl_messagelist_delete_element(v->ml, index);
}
void owl_view_undelete_element(owl_view *v, int index)
{
- owl_messagelist_undelete_element(&(v->ml), index);
+ owl_messagelist_undelete_element(v->ml, index);
}
int owl_view_get_size(const owl_view *v)
{
- return(owl_messagelist_get_size(&(v->ml)));
+ return owl_messagelist_get_size(v->ml);
}
/* Returns the position in the view with a message closest
@@ -157,6 +155,6 @@ const char *owl_view_get_filtname(const owl_view *v)
void owl_view_cleanup(owl_view *v)
{
- owl_messagelist_cleanup(&v->ml, false);
+ owl_messagelist_delete(v->ml, false);
g_free(v->name);
}

0 comments on commit 219f52c

Please sign in to comment.