Revert r4301 - utils_free_pointers() taking 4 arguments.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4321 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2009-10-15 16:15:28 +00:00
parent 6befde884b
commit cf35a8a495
10 changed files with 63 additions and 23 deletions

View File

@ -8,6 +8,10 @@
Add foreach_str() API macro.
Temporarily modify scintilla to say if tab was used for
autocompletion.
* src/templates.c, src/build.c, src/utils.c, src/utils.h,
src/project.c, src/search.c, src/editor.c, src/ui_utils.c,
plugins/classbuilder.c:
Revert r4301 - utils_free_pointers() taking 4 arguments.
2009-10-14 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>

View File

@ -188,6 +188,27 @@ static void cc_dlg_on_base_name_entry_changed(GtkWidget *entry, CreateClassDialo
static void cc_dlg_on_create_class(CreateClassDialog *cc_dlg);
/* The list must be ended with NULL as an extra check that arg_count is correct. */
static void
free_pointers(gsize arg_count, ...)
{
va_list a;
gsize i;
gpointer ptr;
va_start(a, arg_count);
for (i = 0; i < arg_count; i++)
{
ptr = va_arg(a, gpointer);
g_free(ptr);
}
ptr = va_arg(a, gpointer);
if (ptr)
g_warning("Wrong arg_count!");
va_end(a);
}
static gchar*
get_template_class_header(ClassInfo *class_info)
{
@ -688,12 +709,12 @@ static void cc_dlg_on_create_class(CreateClassDialog *cc_dlg)
g_free(text);
}
utils_free_pointers(tmp, class_info->class_name, class_info->class_name_up, NULL);
utils_free_pointers(class_info->base_name, class_info->class_name_low, class_info->base_include, NULL);
utils_free_pointers(class_info->header, class_info->header_guard, class_info->source, NULL);
utils_free_pointers(class_info->base_decl, class_info->constructor_decl, class_info->constructor_impl, NULL);
utils_free_pointers(class_info->gtk_destructor_registration, class_info->destructor_decl, NULL, NULL);
utils_free_pointers(class_info->destructor_impl, class_info->base_gtype, class_info, NULL);
free_pointers(17, tmp, class_info->class_name, class_info->class_name_up,
class_info->base_name, class_info->class_name_low, class_info->base_include,
class_info->header, class_info->header_guard, class_info->source, class_info->base_decl,
class_info->constructor_decl, class_info->constructor_impl,
class_info->gtk_destructor_registration, class_info->destructor_decl,
class_info->destructor_impl, class_info->base_gtype, class_info, NULL);
}

View File

@ -735,7 +735,7 @@ static gchar *prepare_run_script(GeanyDocument *doc, gchar **vte_cmd_nonscript,
{
ui_set_statusbar(TRUE, _("Failed to change the working directory to \"%s\""),
NZV(working_dir) ? working_dir : "<NULL>" );
utils_free_pointers(cmd_string, working_dir, NULL, NULL);
utils_free_pointers(2, cmd_string, working_dir, NULL);
return NULL;
}
@ -747,7 +747,7 @@ static gchar *prepare_run_script(GeanyDocument *doc, gchar **vte_cmd_nonscript,
if (vte_cmd_nonscript != NULL)
*vte_cmd_nonscript = cmd_string;
utils_free_pointers(executable, locale_filename, NULL, NULL);
utils_free_pointers(2, executable, locale_filename, NULL);
return working_dir;
}
else
@ -766,7 +766,7 @@ static gchar *prepare_run_script(GeanyDocument *doc, gchar **vte_cmd_nonscript,
NZV(cmd_string) ? cmd_string : NULL);
}
utils_free_pointers(cmd_string, tmp, executable, locale_filename);
utils_free_pointers(4, cmd_string, tmp, executable, locale_filename, NULL);
if (result)
return working_dir;

View File

@ -2086,7 +2086,7 @@ static void snippets_replace_wildcards(GeanyEditor *editor, GString *text)
templates_replace_all(text, year, date, datetime);
utils_string_replace_all(text, "{filename}", basename);
utils_free_pointers(year, date, datetime, basename);
utils_free_pointers(4, year, date, datetime, basename, NULL);
}

View File

@ -691,7 +691,7 @@ static gboolean update_config(const PropertyDialogElements *e)
SHOW_ERR1(_("Project base directory could not be created (%s)."),
g_strerror(err_code));
gtk_widget_grab_focus(e->base_path);
utils_free_pointers(locale_path, locale_filename, NULL, NULL);
utils_free_pointers(2, locale_path, locale_filename, NULL);
return FALSE;
}
}

View File

@ -1433,7 +1433,7 @@ search_find_in_files(const gchar *utf8_search_text, const gchar *dir, const gcha
tool_prefs.grep_cmd, opts, utf8_search_text, dir);
utf8_str = utils_get_utf8_from_locale(str);
msgwin_msg_add_string(COLOR_BLUE, -1, NULL, utf8_str);
utils_free_pointers(str, utf8_str, NULL, NULL);
utils_free_pointers(2, str, utf8_str, NULL);
ret = TRUE;
}
g_strfreev(argv);

View File

@ -299,8 +299,7 @@ static gchar *get_template_from_file(const gchar *locale_fname, const gchar *doc
utils_string_replace_all(template, "{filename}", doc_filename);
utils_string_replace_all(template, "{fileheader}", file_header);
utils_free_pointers(year, date, datetime, file_header);
g_free(content);
utils_free_pointers(5, year, date, datetime, file_header, content, NULL);
return g_string_free(template, FALSE);
}
return NULL;
@ -552,7 +551,7 @@ static gchar *make_comment_block(const gchar *comment_text, gint filetype_idx, g
else
result = g_strconcat(tmp, frame_end, NULL);
utils_free_pointers(prefix, tmp, frame_start, frame_end);
utils_free_pointers(4, prefix, tmp, frame_start, frame_end, NULL);
g_strfreev(lines);
return result;
}

View File

@ -1721,7 +1721,7 @@ static void on_config_file_clicked(GtkWidget *widget, gpointer user_data)
g_file_get_contents(global_file, &global_content, NULL, NULL);
document_new_file(utf8, ft, global_content);
utils_free_pointers(utf8, base_name, global_file, global_content);
utils_free_pointers(4, utf8, base_name, global_file, global_content, NULL);
}
}

View File

@ -1259,6 +1259,27 @@ gchar *utils_get_utf8_from_locale(const gchar *locale_text)
}
/* Pass pointers to free after arg_count.
* The last argument must be NULL as an extra check that arg_count is correct. */
void utils_free_pointers(gsize arg_count, ...)
{
va_list a;
gsize i;
gpointer ptr;
va_start(a, arg_count);
for (i = 0; i < arg_count; i++)
{
ptr = va_arg(a, gpointer);
g_free(ptr);
}
ptr = va_arg(a, gpointer);
if (ptr)
g_warning("Wrong arg_count!");
va_end(a);
}
/* Creates a string array deep copy of a series of non-NULL strings.
* The first argument is nothing special.
* The list must be ended with NULL.

View File

@ -57,13 +57,6 @@
#define utils_strdupa(str) \
strcpy(g_alloca(strlen(str) + 1), str)
/** Free up to four pointers. */
#define utils_free_pointers(one, two, three, four)\
g_free(one);\
g_free(two);\
g_free(three);\
g_free(four);
/** Iterates all the items in @a array using pointers.
* @param item pointer to an item in @a array.
* @param array C array to traverse.
@ -195,6 +188,8 @@ gchar *utils_get_locale_from_utf8(const gchar *utf8_text);
gchar *utils_get_utf8_from_locale(const gchar *locale_text);
void utils_free_pointers(gsize arg_count, ...) G_GNUC_NULL_TERMINATED;
gchar **utils_strv_new(const gchar *first, ...) G_GNUC_NULL_TERMINATED;
gint utils_mkdir(const gchar *path, gboolean create_parent_dirs);