Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add owl_ptr_array_free convenience function

Unfortunately, most uses of GPtrArray here require a two-step chant
which is really annoying. Until we require glib 2.22 and get
g_ptr_array_new_with_free_func, use this helper function.
  • Loading branch information...
commit 3cdd6d22718b22f0f669d34777233912c1688ed6 1 parent e4524da
@davidben davidben authored
Showing with 16 additions and 16 deletions.
  1. +1 −2  buddylist.c
  2. +3 −6 functions.c
  3. +1 −2  keymap.c
  4. +10 −4 util.c
  5. +1 −2  zwrite.c
View
3  buddylist.c
@@ -133,6 +133,5 @@ void owl_buddylist_clear(owl_buddylist *bl)
void owl_buddylist_cleanup(owl_buddylist *bl)
{
- g_ptr_array_foreach(bl->buddies, (GFunc)owl_buddy_delete, NULL);
- g_ptr_array_free(bl->buddies, true);
+ owl_ptr_array_free(bl->buddies, (GDestroyNotify)owl_buddy_delete);
}
View
9 functions.c
@@ -2778,8 +2778,7 @@ void owl_function_zpunt(const char *class, const char *inst, const char *recip,
}
owl_function_punt(argv->len, (const char *const*) argv->pdata, direction);
- g_ptr_array_foreach(argv, (GFunc)g_free, NULL);
- g_ptr_array_free(argv, true);
+ owl_ptr_array_free(argv, g_free);
}
void owl_function_punt(int argc, const char *const *argv, int direction)
@@ -3072,8 +3071,7 @@ void owl_function_buddylist(int aim, int zephyr, const char *filename)
}
}
}
- g_ptr_array_foreach(anyone, (GFunc)g_free, NULL);
- g_ptr_array_free(anyone, true);
+ owl_ptr_array_free(anyone, g_free);
}
}
#endif
@@ -3417,8 +3415,7 @@ void owl_function_zephyr_buddy_check(int notify)
}
}
- g_ptr_array_foreach(anyone, (GFunc)g_free, NULL);
- g_ptr_array_free(anyone, true);
+ owl_ptr_array_free(anyone, g_free);
#endif
}
View
3  keymap.c
@@ -23,8 +23,7 @@ void owl_keymap_cleanup(owl_keymap *km)
{
g_free(km->name);
g_free(km->desc);
- g_ptr_array_foreach(km->bindings, (GFunc)owl_keybinding_delete, NULL);
- g_ptr_array_free(km->bindings, true);
+ owl_ptr_array_free(km->bindings, (GDestroyNotify)owl_keybinding_delete);
}
void owl_keymap_set_parent(owl_keymap *km, const owl_keymap *parent)
View
14 util.c
@@ -97,6 +97,15 @@ CALLER_OWN char *owl_util_makepath(const char *in)
return(out);
}
+void owl_ptr_array_free(GPtrArray *array, GDestroyNotify element_free_func)
+{
+ /* TODO: when we move to requiring glib 2.22+, use
+ * g_ptr_array_new_with_free_func instead. */
+ if (element_free_func)
+ g_ptr_array_foreach(array, (GFunc)element_free_func, NULL);
+ g_ptr_array_free(array, true);
+}
+
/* Break a command line up into argv, argc. The caller must free
the returned values with g_strfreev. If there is an error argc will be set
to -1, argv will be NULL and the caller does not need to free anything. The
@@ -169,10 +178,7 @@ CALLER_OWN char **owl_parseline(const char *line, int *argc)
/* check for unbalanced quotes */
if (quote!='\0') {
- /* TODO: when we move to requiring glib 2.22+, use
- * g_ptr_array_new_with_free_func. */
- g_ptr_array_foreach(argv, (GFunc)g_free, NULL);
- g_ptr_array_free(argv, true);
+ owl_ptr_array_free(argv, g_free);
if (argc) *argc = -1;
return(NULL);
}
View
3  zwrite.c
@@ -347,8 +347,7 @@ void owl_zwrite_delete(owl_zwrite *z)
void owl_zwrite_cleanup(owl_zwrite *z)
{
- g_ptr_array_foreach(z->recips, (GFunc)g_free, NULL);
- g_ptr_array_free(z->recips, true);
+ owl_ptr_array_free(z->recips, g_free);
g_free(z->cmd);
g_free(z->zwriteline);
g_free(z->class);
Please sign in to comment.
Something went wrong with that request. Please try again.