r22683 - gnucash/trunk/src - Use gnc_guile_call1_to_string convenience function where appropriate
Geert Janssens
gjanssens at code.gnucash.org
Sat Dec 22 13:20:18 EST 2012
Author: gjanssens
Date: 2012-12-22 13:20:17 -0500 (Sat, 22 Dec 2012)
New Revision: 22683
Trac: http://svn.gnucash.org/trac/changeset/22683
Modified:
gnucash/trunk/src/import-export/qif-import/assistant-qif-import.c
gnucash/trunk/src/report/report-gnome/dialog-report-style-sheet.c
gnucash/trunk/src/report/report-system/gnc-report.c
Log:
Use gnc_guile_call1_to_string convenience function where appropriate
And improve memory handling surrounding it where needed.
Modified: gnucash/trunk/src/import-export/qif-import/assistant-qif-import.c
===================================================================
--- gnucash/trunk/src/import-export/qif-import/assistant-qif-import.c 2012-12-22 18:20:05 UTC (rev 22682)
+++ gnucash/trunk/src/import-export/qif-import/assistant-qif-import.c 2012-12-22 18:20:17 UTC (rev 22683)
@@ -45,6 +45,7 @@
#include "qof.h"
#include "gnc-file.h"
#include "gnc-gui-query.h"
+#include "gnc-guile-utils.h"
#include "gnc-currency-edit.h"
#include "gnc-ui-util.h"
#include "gnc-gconf-utils.h"
@@ -53,7 +54,6 @@
#include "gnc-plugin-page-account-tree.h"
#include "gnc-ui.h"
#include "guile-mappings.h"
-#include "guile-util.h"
#include "swig-runtime.h"
@@ -276,8 +276,8 @@
SCM get_gnc_name = scm_c_eval_string("qif-map-entry:gnc-name");
SCM get_new = scm_c_eval_string("qif-map-entry:new-acct?");
SCM accts_left;
- const gchar *qif_name = NULL;
- const gchar *gnc_name = NULL;
+ gchar *qif_name = NULL;
+ gchar *gnc_name = NULL;
gboolean checked;
gint row = 0;
gint prev_row;
@@ -303,26 +303,8 @@
while (!scm_is_null(accts_left))
{
- if (scm_is_string(scm_call_1(get_qif_name, SCM_CAR(accts_left))))
- {
- char * str;
-
- scm_dynwind_begin (0);
- str = scm_to_locale_string (scm_call_1(get_qif_name, SCM_CAR(accts_left)));
- qif_name = g_strdup (str);
- scm_dynwind_free (str);
- scm_dynwind_end ();
- }
- if (scm_is_string(scm_call_1(get_gnc_name, SCM_CAR(accts_left))))
- {
- char * str;
-
- scm_dynwind_begin (0);
- str = scm_to_locale_string (scm_call_1(get_gnc_name, SCM_CAR(accts_left)));
- gnc_name = g_strdup (str);
- scm_dynwind_free (str);
- scm_dynwind_end ();
- }
+ qif_name = gnc_guile_call1_to_string(get_qif_name, SCM_CAR(accts_left));
+ gnc_name = gnc_guile_call1_to_string(get_gnc_name, SCM_CAR(accts_left));
checked = (scm_call_1(get_new, SCM_CAR(accts_left)) == SCM_BOOL_T);
gtk_list_store_append(store, &iter);
@@ -334,6 +316,8 @@
ACCOUNT_COL_ELLIPSIZE, PANGO_ELLIPSIZE_START,
-1);
accts_left = SCM_CDR(accts_left);
+ g_free (qif_name);
+ g_free (gnc_name);
}
/* move to the old selected row */
@@ -1797,19 +1781,6 @@
}
else if (!scm_is_null(load_return))
{
- /* since the result of scm_to_locale_string doesn't appear to be used */
- /* can we just delete the whole if statement? */
- if (scm_is_string(SCM_CADR(load_return)))
- {
- char * str;
-
- scm_dynwind_begin (0);
- str = scm_to_locale_string (SCM_CADR(load_return));
- /* str doesn't seem to be used anywhere, so go ahead and free it */
- scm_dynwind_free (str);
- scm_dynwind_end ();
- }
-
if (SCM_CAR(load_return) == SCM_BOOL_F)
{
imported_files = scm_call_2(unload_qif_file, scm_qiffile, imported_files);
@@ -2082,20 +2053,11 @@
{
/* There is an account name missing. Ask the user to provide one. */
SCM default_acct = scm_c_eval_string("qif-file:path-to-accountname");
- const gchar * default_acctname = NULL;
+ gchar * default_acctname = NULL;
- if (scm_is_string(scm_call_1(default_acct, wind->selected_file)))
- {
- char * str;
-
- scm_dynwind_begin (0);
- str = scm_to_locale_string (scm_call_1(default_acct,
- wind->selected_file));
- default_acctname = g_strdup (str);
- scm_dynwind_free (str);
- scm_dynwind_end ();
- }
+ default_acctname = gnc_guile_call1_to_string(default_acct, wind->selected_file);
gtk_entry_set_text(GTK_ENTRY(wind->acct_entry), default_acctname);
+ g_free (default_acctname);
}
else
{
@@ -2224,10 +2186,8 @@
update_file_page(QIFImportWindow * wind)
{
SCM loaded_file_list = wind->imported_files;
- SCM scm_qiffile = SCM_BOOL_F;
SCM qif_file_path;
int row = 0;
- const char * row_text = NULL;
GtkTreeView *view;
GtkListStore *store;
GtkTreeIter iter;
@@ -2242,23 +2202,19 @@
while (!scm_is_null(loaded_file_list))
{
+ gchar *row_text = NULL;
+ SCM scm_qiffile = SCM_BOOL_F;
+
scm_qiffile = SCM_CAR(loaded_file_list);
- if (scm_is_string(scm_call_1(qif_file_path, scm_qiffile)))
- {
- char * str;
+ row_text = gnc_guile_call1_to_string(qif_file_path, scm_qiffile);
- scm_dynwind_begin (0);
- str = scm_to_locale_string (scm_call_1(qif_file_path, scm_qiffile));
- row_text = g_strdup (str);
- scm_dynwind_free (str);
- scm_dynwind_end ();
- }
-
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
FILENAME_COL_INDEX, row++,
FILENAME_COL_NAME, row_text,
-1);
+ g_free (row_text);
+
if (scm_qiffile == wind->selected_file)
{
path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
Modified: gnucash/trunk/src/report/report-gnome/dialog-report-style-sheet.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/dialog-report-style-sheet.c 2012-12-22 18:20:05 UTC (rev 22682)
+++ gnucash/trunk/src/report/report-gnome/dialog-report-style-sheet.c 2012-12-22 18:20:17 UTC (rev 22683)
@@ -31,6 +31,7 @@
#include "dialog-options.h"
#include "dialog-utils.h"
#include "gnc-gtk-utils.h"
+#include "gnc-guile-utils.h"
#include "gnc-report.h"
#include "gnc-ui.h"
@@ -205,15 +206,10 @@
/* put in the list of style sheet type names */
for (; !scm_is_null(templates); templates = SCM_CDR(templates))
{
- char * str;
- const char* orig_name;
+ gchar* orig_name;
SCM t = SCM_CAR(templates);
- scm_dynwind_begin (0);
- str = scm_to_locale_string (scm_call_1(t_name, t));
- orig_name = g_strdup (str);
- scm_dynwind_free (str);
- scm_dynwind_end ();
+ orig_name = gnc_guile_call1_to_string(t_name, t);
/* Store the untranslated names for lookup later */
template_names = g_list_prepend (template_names, (gpointer)orig_name);
@@ -221,6 +217,8 @@
/* The displayed name should be translated */
gtk_list_store_append(GTK_LIST_STORE(template_model), &iter);
gtk_list_store_set (GTK_LIST_STORE(template_model), &iter, 0, _(orig_name), -1);
+
+ /* Note: don't g_free orig_name here - template_names still refers to it*/
}
gtk_combo_box_set_active(GTK_COMBO_BOX(template_combo), 0);
@@ -248,7 +246,7 @@
}
}
- g_list_free (template_names);
+ g_list_free_full (template_names, g_free);
g_object_unref(G_OBJECT(builder));
@@ -265,30 +263,25 @@
SCM sheet_info,
gboolean select)
{
- SCM get_name, scm_name;
- const gchar *c_name;
- char * str;
+ SCM get_name;
+ gchar *c_name;
GtkTreeSelection *selection;
GtkTreeIter iter;
- get_name = scm_c_eval_string("gnc:html-style-sheet-name");
- scm_name = scm_call_1(get_name, sheet_info);
- scm_dynwind_begin (0);
- str = scm_to_locale_string (scm_name);
- c_name = g_strdup (str);
- scm_dynwind_free (str);
- scm_dynwind_end ();
+ get_name = scm_c_eval_string ("gnc:html-style-sheet-name");
+ c_name = gnc_guile_call1_to_string (get_name, sheet_info);
if (!c_name)
return;
/* add the column name */
- scm_gc_protect_object(sheet_info);
+ scm_gc_protect_object (sheet_info);
gtk_list_store_append (ss->list_store, &iter);
gtk_list_store_set (ss->list_store, &iter,
/* Translate the displayed name */
COLUMN_NAME, _(c_name),
COLUMN_STYLESHEET, sheet_info,
-1);
+ g_free (c_name);
/* The translation of the name fortunately doesn't affect the
* lookup because that is done through the sheet_info argument. */
Modified: gnucash/trunk/src/report/report-system/gnc-report.c
===================================================================
--- gnucash/trunk/src/report/report-system/gnc-report.c 2012-12-22 18:20:05 UTC (rev 22682)
+++ gnucash/trunk/src/report/report-system/gnc-report.c 2012-12-22 18:20:17 UTC (rev 22683)
@@ -31,6 +31,7 @@
#include <string.h>
#include "gfec.h"
+#include "gnc-guile-utils.h"
#include "gnc-report.h"
/* Fow now, this is global, like it was in guile. It _should_ be per-book. */
@@ -187,24 +188,11 @@
gnc_report_name( SCM report )
{
SCM get_name = scm_c_eval_string("gnc:report-name");
- SCM value;
- gchar *str = NULL;
- gchar *report_name = NULL;
if (report == SCM_BOOL_F)
return NULL;
- value = scm_call_1(get_name, report);
- if (!scm_is_string(value))
- return NULL;
-
- scm_dynwind_begin (0);
- str = scm_to_locale_string (value);
- report_name = g_strdup (str);
- scm_dynwind_free (str);
- scm_dynwind_end ();
-
- return report_name;
+ return gnc_guile_call1_to_string(get_name, report);
}
gchar*
More information about the gnucash-changes
mailing list