Branch: refs/heads/master Author: Thomas Martitz kugel@rockbox.org Committer: Thomas Martitz kugel@rockbox.org Date: Tue, 19 Jan 2016 16:08:59 UTC Commit: 43737733acc46eee7dff88eb922622694faba29b https://github.com/geany/geany/commit/43737733acc46eee7dff88eb922622694faba2...
Log Message: ----------- plugin api: convert StashGroup to GBoxed internally
Because the stash_group_new() is an exported API, it has to be at least a boxed type to be usable for gobject introspection. The boxed type uses reference counting as opposed to memory duplication.
The obligatory stash_group_dup() is not exported (doesn't have to).
Modified Paths: -------------- src/stash.c src/stash.h
Modified: src/stash.c 46 lines changed, 33 insertions(+), 13 deletions(-) =================================================================== @@ -123,6 +123,7 @@ typedef struct StashPref StashPref;
struct StashGroup { + guint refcount; /* ref count for GBoxed implementation */ const gchar *name; /* group name to use in the keyfile */ GPtrArray *entries; /* array of (StashPref*) */ gboolean various; /* mark group for display/edit in stash treeview */ @@ -347,17 +348,27 @@ gint stash_group_save_to_file(StashGroup *group, const gchar *filename, }
+static void free_stash_pref(StashPref *pref) +{ + if (pref->widget_type == GTK_TYPE_RADIO_BUTTON) + g_free(pref->extra.radio_buttons); + + g_slice_free(StashPref, pref); +} + + /** Creates a new group. * @param name Name used for @c GKeyFile group. * @return Group. */ GEANY_API_SYMBOL StashGroup *stash_group_new(const gchar *name) { - StashGroup *group = g_new0(StashGroup, 1); + StashGroup *group = g_slice_new0(StashGroup);
group->name = name; - group->entries = g_ptr_array_new(); + group->entries = g_ptr_array_new_with_free_func((GDestroyNotify) free_stash_pref); group->use_defaults = TRUE; + group->refcount = 1; return group; }
@@ -386,27 +397,36 @@ void stash_group_free_settings(StashGroup *group) }
+static StashGroup *stash_group_dup(StashGroup *src) +{ + g_atomic_int_inc(&src->refcount); + + return src; +} + + /** Frees a group. * @param group . */ GEANY_API_SYMBOL void stash_group_free(StashGroup *group) { - StashPref *entry; - guint i; - - foreach_ptr_array(entry, i, group->entries) + if (g_atomic_int_dec_and_test(&group->refcount)) { - if (entry->widget_type == GTK_TYPE_RADIO_BUTTON) - { - g_free(entry->extra.radio_buttons); - } - g_slice_free(StashPref, entry); + g_ptr_array_free(group->entries, TRUE); + g_slice_free(StashGroup, group); } - g_ptr_array_free(group->entries, TRUE); - g_free(group); }
+/** Gets the GBoxed-derived GType for StashGroup + * + * @return StashGroup type . */ +GEANY_API_SYMBOL +GType stash_group_get_type(void); + +G_DEFINE_BOXED_TYPE(StashGroup, stash_group, stash_group_dup, stash_group_free); + + /* Used for selecting groups passed to stash_tree_setup(). * @c FALSE by default. */ void stash_group_set_various(StashGroup *group, gboolean various)
Modified: src/stash.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -33,6 +33,7 @@ typedef struct StashGroup StashGroup; * stash_group_display() and stash_group_update(). */ typedef gconstpointer StashWidgetID;
+GType stash_group_get_type(void);
StashGroup *stash_group_new(const gchar *name);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).