Permalink
Browse files

Add stash_group_free_settings() function to API

Frees the memory allocated for setting values in a group.
  • Loading branch information...
1 parent c7b3a09 commit f2d33bc16ea8c8c6ef5f8f5cd6aee77ec63f2129 @zhekov zhekov committed with ntrel Apr 5, 2012
Showing with 32 additions and 3 deletions.
  1. +2 −0 plugins/geanyfunctions.h
  2. +3 −2 src/plugindata.h
  3. +2 −1 src/plugins.c
  4. +23 −0 src/stash.c
  5. +2 −0 src/stash.h
View
@@ -418,6 +418,8 @@
geany_functions->p_stash->stash_group_display
#define stash_group_update \
geany_functions->p_stash->stash_group_update
+#define stash_group_free_settings \
+ geany_functions->p_stash->stash_group_free_settings
#define symbols_get_context_separator \
geany_functions->p_symbols->symbols_get_context_separator
#define build_activate_menu_item \
View
@@ -55,7 +55,7 @@ G_BEGIN_DECLS
* @warning You should not test for values below 200 as previously
* @c GEANY_API_VERSION was defined as an enum value, not a macro.
*/
-#define GEANY_API_VERSION 214
+#define GEANY_API_VERSION 215
/** The Application Binary Interface (ABI) version, incremented whenever
* existing fields in the plugin data types have to be changed or reordered.
@@ -701,6 +701,7 @@ typedef struct StashFuncs
const gchar *property_name, GType type);
void (*stash_group_display)(struct StashGroup *group, GtkWidget *owner);
void (*stash_group_update)(struct StashGroup *group, GtkWidget *owner);
+ void (*stash_group_free_settings)(struct StashGroup *group);
}
StashFuncs;
@@ -716,7 +717,7 @@ SymbolsFuncs;
typedef struct BuildFuncs
{
void (*build_activate_menu_item)(const GeanyBuildGroup grp, const guint cmd);
- const gchar *(*build_get_current_menu_item)(const GeanyBuildGroup grp, const guint cmd,
+ const gchar *(*build_get_current_menu_item)(const GeanyBuildGroup grp, const guint cmd,
const GeanyBuildCmdEntries field);
void (*build_remove_menu_item)(const GeanyBuildSource src, const GeanyBuildGroup grp,
const gint cmd);
View
@@ -346,7 +346,8 @@ static StashFuncs stash_funcs = {
&stash_group_add_entry,
&stash_group_add_widget_property,
&stash_group_display,
- &stash_group_update
+ &stash_group_update,
+ &stash_group_free_settings
};
static SymbolsFuncs symbols_funcs = {
View
@@ -335,6 +335,29 @@ StashGroup *stash_group_new(const gchar *name)
}
+/** Frees the memory allocated for setting values in a group.
+ * Useful e.g. to avoid freeing strings individually.
+ * @note This is *not* called by stash_group_free().
+ * @param group . */
+void stash_group_free_settings(StashGroup *group)
+{
+ StashPref *entry;
+ guint i;
+
+ foreach_ptr_array(entry, i, group->entries)
+ {
+ if (entry->setting_type == G_TYPE_STRING)
+ g_free(*(gchararray *) entry->setting);
+ else if (entry->setting_type == G_TYPE_STRV)
+ g_strfreev(*(gchararray **) entry->setting);
+ else
+ continue;
+
+ *(gpointer**) entry->setting = NULL;
+ }
+}
+
+
/** Frees a group.
* @param group . */
void stash_group_free(StashGroup *group)
View
@@ -60,6 +60,8 @@ gboolean stash_group_load_from_file(StashGroup *group, const gchar *filename);
gint stash_group_save_to_file(StashGroup *group, const gchar *filename,
GKeyFileFlags flags);
+void stash_group_free_settings(StashGroup *group);
+
void stash_group_free(StashGroup *group);

0 comments on commit f2d33bc

Please sign in to comment.