give actions a ref count
Dana Jansens danakj@orodu.net
5 files changed,
19 insertions(+),
10 deletions(-)
M
openbox/action.c
→
openbox/action.c
@@ -65,18 +65,25 @@ void (*func)(union ActionData *);
void (*setup)(ObAction **, ObUserAction uact); } ActionString; -static ObAction *action_new(void (*func)(union ActionData *data), - ObUserAction uact) +static ObAction *action_new(void (*func)(union ActionData *data)) { ObAction *a = g_new0(ObAction, 1); + a->ref = 1; a->func = func; return a; } -void action_free(ObAction *a) +void action_ref(ObAction *a) +{ + ++a->ref; +} + +void action_unref(ObAction *a) { if (a == NULL) return; + + if (--a->ref > 0) return; /* deal with pointers */ if (a->func == action_execute || a->func == action_restart)@@ -359,7 +366,7 @@ /* you cannot call ShowMenu from inside a menu, cuz the menu code makes
assumptions that there is only one menu (and submenus) open at a time! */ if (uact == OB_USER_ACTION_MENU_SELECTION) { - action_free(*a); + action_unref(*a); a = NULL; } }@@ -772,7 +779,7 @@
for (i = 0; actionstrings[i].name; i++) if (!g_ascii_strcasecmp(name, actionstrings[i].name)) { exist = TRUE; - a = action_new(actionstrings[i].func, uact); + a = action_new(actionstrings[i].func); if (actionstrings[i].setup) actionstrings[i].setup(&a, uact); /* only key bindings can be interactive. thus saith the xor.
M
openbox/action.h
→
openbox/action.h
@@ -152,7 +152,8 @@ struct Layer layer;
}; struct _ObAction { - ObUserAction act; + guint ref; + /* The func member acts like an enum to tell which one of the structs in the data union are valid. */@@ -176,7 +177,8 @@
ObAction *action_from_string(const gchar *name, ObUserAction uact); ObAction *action_parse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, ObUserAction uact); -void action_free(ObAction *a); +void action_ref(ObAction *a); +void action_unref(ObAction *a); /*! Executes a list of actions. @param c The client associated with the action. Can be NULL.
M
openbox/keytree.c
→
openbox/keytree.c
@@ -34,7 +34,7 @@ for (it = tree->keylist; it != NULL; it = it->next)
g_free(it->data); g_list_free(tree->keylist); for (sit = tree->actions; sit != NULL; sit = sit->next) - action_free(sit->data); + action_unref(sit->data); g_slist_free(tree->actions); } g_free(tree);
M
openbox/mouse.c
→
openbox/mouse.c
@@ -142,7 +142,7 @@ for (j = 0; j < OB_NUM_MOUSE_ACTIONS; ++j) {
GSList *it; for (it = b->actions[j]; it; it = it->next) - action_free(it->data); + action_unref(it->data); g_slist_free(b->actions[j]); } g_free(b);