r22684 - gnucash/trunk/src - Readd gnc_scm_to_locale_string function and use it where appropriate

Geert Janssens gjanssens at code.gnucash.org
Sat Dec 22 13:20:30 EST 2012


Author: gjanssens
Date: 2012-12-22 13:20:29 -0500 (Sat, 22 Dec 2012)
New Revision: 22684
Trac: http://svn.gnucash.org/trac/changeset/22684

Modified:
   gnucash/trunk/src/app-utils/gfec.c
   gnucash/trunk/src/app-utils/guile-util.c
   gnucash/trunk/src/app-utils/option-util.c
   gnucash/trunk/src/app-utils/test/test-scm-query-string.c
   gnucash/trunk/src/core-utils/gnc-guile-utils.c
   gnucash/trunk/src/core-utils/gnc-guile-utils.h
   gnucash/trunk/src/engine/engine-helpers.c
   gnucash/trunk/src/engine/glib-helpers.c
   gnucash/trunk/src/engine/kvp-scm.c
   gnucash/trunk/src/gnome-utils/dialog-options.c
   gnucash/trunk/src/gnome-utils/gnc-menu-extensions.c
   gnucash/trunk/src/gnome/dialog-tax-info.c
   gnucash/trunk/src/import-export/qif-import/dialog-account-picker.c
   gnucash/trunk/src/report/report-gnome/dialog-custom-report.c
   gnucash/trunk/src/report/report-gnome/dialog-report-column-view.c
   gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c
   gnucash/trunk/src/report/report-gnome/window-report.c
   gnucash/trunk/src/report/report-system/Makefile.am
   gnucash/trunk/src/report/report-system/gnc-report.c
Log:
Readd gnc_scm_to_locale_string function and use it where appropriate

This function is a wrapper around scm_to_locale_string which returns
a gchar * to be freed with g_free. The return value of the original
function has to be freed with free. This is confusing since most of
the gnucash code relies on g_malloc/g_free.

While at it, clean up a lot of memory handling issues around (gnc_)scm_to_locale_string

Modified: gnucash/trunk/src/app-utils/gfec.c
===================================================================
--- gnucash/trunk/src/app-utils/gfec.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/app-utils/gfec.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -11,6 +11,7 @@
 
 #include "config.h"
 #include "gfec.h"
+#include "gnc-guile-utils.h"
 #include "platform.h"
 #if COMPILER(MSVC)
 # define strdup _strdup
@@ -36,15 +37,7 @@
     {
         result = scm_call_2(func, tag, throw_args);
         if (scm_is_string(result))
-        {
-            char * str;
-
-            scm_dynwind_begin (0);
-            str = scm_to_locale_string (result);
-            msg = g_strdup (str);
-            scm_dynwind_free (str);
-            scm_dynwind_end ();
-        }
+            msg = gnc_scm_to_locale_string (result);
     }
 
     if (msg == NULL)

Modified: gnucash/trunk/src/app-utils/guile-util.c
===================================================================
--- gnucash/trunk/src/app-utils/guile-util.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/app-utils/guile-util.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -444,7 +444,7 @@
  *   return the newly allocated memo of a scheme split, or NULL.    *
  *                                                                  *
  * Args: split_scm - the scheme split                               *
- * Returns: newly allocated memo string                             *
+ * Returns: newly allocated memo string, must be freed with g_free  *
 \********************************************************************/
 char *
 gnc_split_scm_get_memo(SCM split_scm)
@@ -460,17 +460,17 @@
     if (!scm_is_string(result))
         return NULL;
 
-    return scm_to_locale_string(result);
+    return gnc_scm_to_locale_string(result);
 }
 
 
-/********************************************************************\
- * gnc_split_scm_get_action                                         *
- *   return the newly allocated action of a scheme split, or NULL.  *
- *                                                                  *
- * Args: split_scm - the scheme split                               *
- * Returns: newly allocated action string                           *
-\********************************************************************/
+/**********************************************************************\
+ * gnc_split_scm_get_action                                           *
+ *   return the newly allocated action of a scheme split, or NULL.    *
+ *                                                                    *
+ * Args: split_scm - the scheme split                                 *
+ * Returns: newly allocated action string, must be freed with g_free  *
+\**********************************************************************/
 char *
 gnc_split_scm_get_action(SCM split_scm)
 {
@@ -485,7 +485,7 @@
     if (!scm_is_string(result))
         return NULL;
 
-    return scm_to_locale_string(result);
+    return gnc_scm_to_locale_string(result);
 }
 
 
@@ -918,13 +918,13 @@
 }
 
 
-/********************************************************************\
- * gnc_get_credit_string                                            *
- *   return a credit string for a given account type                *
- *                                                                  *
- * Args: account_type - type of account to get credit string for    *
- * Return: g_malloc'd credit string or NULL                         *
-\********************************************************************/
+/************************************************************************\
+ * gnc_get_credit_string                                                *
+ *   return a credit string for a given account type                    *
+ *                                                                      *
+ * Args: account_type - type of account to get credit string for        *
+ * Return: g_malloc'd credit string or NULL, must be freed with g_free  *
+\************************************************************************/
 char *
 gnc_get_credit_string(GNCAccountType account_type)
 {
@@ -945,7 +945,7 @@
     if (!scm_is_string(result))
         return NULL;
 
-    return scm_to_locale_string(result);
+    return gnc_scm_to_locale_string(result);
 }
 
 

Modified: gnucash/trunk/src/app-utils/option-util.c
===================================================================
--- gnucash/trunk/src/app-utils/option-util.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/app-utils/option-util.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -32,7 +32,7 @@
 #include "option-util.h"
 #include "engine-helpers.h"
 #include "glib-helpers.h"
-#include "guile-util.h"
+#include "gnc-guile-utils.h"
 #include "qof.h"
 #include "guile-mappings.h"
 
@@ -900,8 +900,6 @@
 gnc_option_permissible_value_name(GNCOption *option, int index)
 {
     SCM name;
-    char * str;
-    char * string;
 
     if (index < 0)
         return NULL;
@@ -915,13 +913,7 @@
     if (!scm_is_string(name))
         return NULL;
 
-    scm_dynwind_begin (0);
-    str = scm_to_locale_string (name);
-    string = g_strdup (str);
-    scm_dynwind_free (str);
-    scm_dynwind_end ();
-
-    return string;
+    return gnc_scm_to_locale_string (name);
 }
 
 
@@ -939,8 +931,6 @@
 gnc_option_permissible_value_description(GNCOption *option, int index)
 {
     SCM help;
-    char * str;
-    char * string;
 
     if (index < 0)
         return NULL;
@@ -954,13 +944,7 @@
     if (!scm_is_string(help))
         return NULL;
 
-    scm_dynwind_begin (0);
-    str = scm_to_locale_string (help);
-    string = g_strdup (str);
-    scm_dynwind_free (str);
-    scm_dynwind_end ();
-
-    return string;
+    return gnc_scm_to_locale_string (help);
 }
 
 
@@ -1708,11 +1692,7 @@
             return;
         }
 
-        scm_dynwind_begin (0);
-        str = scm_to_locale_string (oops);
-        message = g_strdup (str);
-        scm_dynwind_free (str);
-        scm_dynwind_end ();
+        message = gnc_scm_to_locale_string (oops);
         name = gnc_option_name(option);
         section = gnc_option_section(option);
 
@@ -1903,8 +1883,6 @@
 {
     SCM getter;
     SCM value;
-    char * str;
-    char * string;
 
     if (odb == NULL)
         return NULL;
@@ -1917,12 +1895,7 @@
     if (!scm_is_string(value))
         return NULL;
 
-    scm_dynwind_begin (0);
-    str = scm_to_locale_string (value);
-    string = g_strdup (str);
-    scm_dynwind_free (str);
-    scm_dynwind_end ();
-    return string;
+    return gnc_scm_to_locale_string (value);
 }
 
 
@@ -2028,16 +2001,7 @@
         {
             value = scm_call_0(getter);
             if (scm_is_string(value))
-            {
-                char * str;
-                char * string;
-                scm_dynwind_begin (0);
-                str = scm_to_locale_string (value);
-                string = g_strdup (str);
-                scm_dynwind_free (str);
-                scm_dynwind_end ();
-                return string;
-            }
+                return gnc_scm_to_locale_string (value);
         }
     }
 
@@ -2772,14 +2736,7 @@
             break;
 
         if (custom)
-        {
-            char * tmp_str;
-            char * string;
-            tmp_str = scm_to_locale_string (val);
-            string = g_strdup (tmp_str);
-            free (tmp_str);
-            *custom = string;
-        }
+            *custom = gnc_scm_to_locale_string (val);
 
         return FALSE;
 

Modified: gnucash/trunk/src/app-utils/test/test-scm-query-string.c
===================================================================
--- gnucash/trunk/src/app-utils/test/test-scm-query-string.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/app-utils/test/test-scm-query-string.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -6,6 +6,7 @@
 
 #include "engine-helpers.h"
 #include "gnc-module.h"
+#include "gnc-guile-utils.h"
 #include "test-engine-stuff.h"
 #include "test-stuff.h"
 #include "Query.h"
@@ -20,7 +21,6 @@
     SCM res_q;
     SCM args = SCM_EOL;
     Query *q2;
-    char * str;
     gchar *str2 = NULL;
 
     scm_q = gnc_query2scm (q);
@@ -30,11 +30,7 @@
     args = scm_cons (scm_from_locale_string ("'"), scm_cons (str_q, SCM_EOL));
     str_q = scm_string_append (args);
 
-    scm_dynwind_begin (0);
-    str = scm_to_locale_string (str_q);
-    if (str) str2 = g_strdup(str);
-    scm_dynwind_free (str);
-    scm_dynwind_end ();
+    str2 = gnc_scm_to_locale_string (str_q);
     if (str2)
     {
         res_q = scm_c_eval_string (str2);
@@ -53,14 +49,14 @@
         scm_q = gnc_query2scm (q2);
         scm_display (scm_q, SCM_UNDEFINED);
         scm_newline (SCM_UNDEFINED);
-        if (str2) g_free(str2);
+        g_free(str2);
         exit (1);
     }
     else
     {
         success ("queries match");
     }
-    if (str2) g_free(str2);
+    g_free(str2);
     if (q2) qof_query_destroy (q2);
 }
 

Modified: gnucash/trunk/src/core-utils/gnc-guile-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-guile-utils.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/core-utils/gnc-guile-utils.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -32,7 +32,35 @@
 
 
 /********************************************************************\
- * gnc_guile_symbol_to_locale_string                                *
+ * gnc_scm_to_locale_string                                         *
+ *   returns the string representation of the scm string in         *
+ *   a newly allocated gchar * or NULL if it can't be retrieved.    *
+ *                                                                  *
+ * Args: symbol_value - the scm symbol                              *
+ * Returns: newly allocated gchar * or NULL, should be freed with   *
+ *          g_free by the caller                                    *
+\********************************************************************/
+gchar *gnc_scm_to_locale_string(SCM scm_string)
+{
+    if (scm_is_string (scm_string))
+    {
+        gchar* s;
+        char * str;
+
+        str = scm_to_locale_string(scm_string);
+        s = g_strdup(str);
+        free (str);
+        return s;
+    }
+
+    /* Unable to extract string from the symbol...*/
+    PERR("bad value\n");
+    return NULL;
+}
+
+
+/********************************************************************\
+ * gnc_scm_symbol_to_locale_string                                  *
  *   returns the string representation of the scm symbol in         *
  *   a newly allocated gchar * or NULL if it can't be retrieved.    *
  *                                                                  *

Modified: gnucash/trunk/src/core-utils/gnc-guile-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-guile-utils.h	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/core-utils/gnc-guile-utils.h	2012-12-22 18:20:29 UTC (rev 22684)
@@ -28,7 +28,15 @@
 #include <libguile.h>
 
 /** Helper function to get the string representation of
- *  a guile symbol. */
+ *  a guile string.
+ *
+ *  Returns a newly allocated string that must be freed with g_free*/
+gchar * gnc_scm_to_locale_string(SCM scm_string);
+
+/** Helper function to get the string representation of
+ *  a guile symbol.
+ *
+ *  Returns a newly allocated string that must be freed with g_free*/
 gchar * gnc_scm_symbol_to_locale_string(SCM scm_string);
 
 /* Helpful functions for calling functions that return

Modified: gnucash/trunk/src/engine/engine-helpers.c
===================================================================
--- gnucash/trunk/src/engine/engine-helpers.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/engine/engine-helpers.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -326,11 +326,9 @@
     {
         return *guid_null();
     }
-    scm_dynwind_begin (0);
-    str = scm_to_locale_string (guid_scm);
+    str = gnc_scm_to_locale_string (guid_scm);
     string_to_guid(str, &guid);
-    scm_dynwind_free (str);
-    scm_dynwind_end ();
+    g_free (str);
     return guid;
 }
 
@@ -348,11 +346,9 @@
     {
         return FALSE;
     }
-    scm_dynwind_begin (0);
-    str = scm_to_locale_string (guid_scm);
+    str = gnc_scm_to_locale_string (guid_scm);
     return_int = string_to_guid(str, &guid);
-    scm_dynwind_free (str);
-    scm_dynwind_end ();
+    g_free (str);
     return return_int;
 }
 
@@ -702,14 +698,8 @@
         if (!scm_is_string (key_scm))
             break;
 
-        scm_dynwind_begin (0);
-        str = scm_to_locale_string(key_scm);
-        key = g_strdup (str);
-        scm_dynwind_free (str);
-        scm_dynwind_end ();
-
+        key = gnc_scm_to_locale_string(key_scm);
         path = g_slist_prepend (path, key);
-
         path_scm = SCM_CDR (path_scm);
     }
 
@@ -877,11 +867,9 @@
     case KVP_TYPE_STRING:
     {
         gchar * str;
-        scm_dynwind_begin (0);
-        str = scm_to_locale_string (val_scm);
+        str = gnc_scm_to_locale_string (val_scm);
         value = kvp_value_new_string (str);
-        scm_dynwind_free (str);
-        scm_dynwind_end ();
+        g_free (str);
         break;
     }
 
@@ -1175,13 +1163,11 @@
             qt_scm = SCM_CDR (qt_scm);
             if (!scm_is_string (scm)) break;
 
-            scm_dynwind_begin (0);
-            matchstring = scm_to_locale_string (scm);
+            matchstring = gnc_scm_to_locale_string (scm);
 
             pd = qof_query_string_predicate (compare_how, matchstring,
                                              options, is_regex);
-            scm_dynwind_free (matchstring);
-            scm_dynwind_end ();
+            g_free (matchstring);
         }
         else if (!g_strcmp0 (type, QOF_TYPE_DATE))
         {
@@ -1299,12 +1285,10 @@
             qt_scm = SCM_CDR (qt_scm);
             if (!scm_is_string (scm))
                 break;
-            scm_dynwind_begin (0);
-            char_list = scm_to_locale_string (scm);
+            char_list = gnc_scm_to_locale_string (scm);
 
             pd = qof_query_char_predicate (options, char_list);
-            scm_dynwind_free (char_list);
-            scm_dynwind_end ();
+            g_free (char_list);
         }
         else if (!g_strcmp0 (type, QOF_TYPE_KVP))
         {
@@ -1572,8 +1556,7 @@
 
             scm = SCM_CAR (query_term_scm);
             query_term_scm = SCM_CDR (query_term_scm);
-            scm_dynwind_begin (0);
-            matchstring = scm_to_locale_string (scm);
+            matchstring = gnc_scm_to_locale_string (scm);
 
             if (!g_strcmp0 (pr_type, "pr-action"))
             {
@@ -1607,8 +1590,7 @@
             {
                 PINFO ("Unknown string predicate: %s", pr_type);
             }
-            scm_dynwind_free (matchstring);
-            scm_dynwind_end ();
+            g_free (matchstring);
 
         }
         else if (!g_strcmp0 (pd_type, "pd-cleared"))
@@ -1648,7 +1630,6 @@
         {
             GncGUID guid;
             QofIdType id_type;
-            gchar *str;
 
             /* guid */
             if (scm_is_null (query_term_scm))
@@ -1661,11 +1642,7 @@
             /* id type */
             scm = SCM_CAR (query_term_scm);
             query_term_scm = SCM_CDR (query_term_scm);
-            scm_dynwind_begin (0);
-            str = scm_to_locale_string (scm);
-            id_type = g_strdup (str);
-            scm_dynwind_free (str);
-            scm_dynwind_end ();
+            id_type = (QofIdType) gnc_scm_to_locale_string (scm);
 
             xaccQueryAddGUIDMatch (q, &guid, id_type, QOF_QUERY_OR);
             g_free ((void *) id_type);

Modified: gnucash/trunk/src/engine/glib-helpers.c
===================================================================
--- gnucash/trunk/src/engine/glib-helpers.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/engine/glib-helpers.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -28,6 +28,7 @@
 #include <glib.h>
 #include <libguile.h>
 #include "guile-mappings.h"
+#include "gnc-guile-utils.h"
 #include "swig-runtime.h"
 #include "glib-helpers.h"
 
@@ -128,14 +129,12 @@
     {
         if (scm_is_string(SCM_CAR(list)))
         {
-            char * str;
+            gchar * str;
 
-            scm_dynwind_begin (0);
-            str = scm_to_locale_string (SCM_CAR(list));
+            str = gnc_scm_to_locale_string (SCM_CAR(list));
             if (str)
                 glist = g_list_prepend (glist, g_strdup (str));
-            scm_dynwind_free (str);
-            scm_dynwind_end ();
+            g_free (str);
         }
         list = SCM_CDR (list);
     }
@@ -152,14 +151,12 @@
     {
         if (scm_is_string(SCM_CAR(list)))
         {
-            char * str;
+            gchar * str;
 
-            scm_dynwind_begin (0);
-            str = scm_to_locale_string (SCM_CAR(list));
+            str = gnc_scm_to_locale_string (SCM_CAR(list));
             if (str)
                 gslist = g_slist_prepend (gslist, g_strdup (str));
-            scm_dynwind_free (str);
-            scm_dynwind_end ();
+            g_free (str);
         }
         list = SCM_CDR (list);
     }

Modified: gnucash/trunk/src/engine/kvp-scm.c
===================================================================
--- gnucash/trunk/src/engine/kvp-scm.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/engine/kvp-scm.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -6,6 +6,7 @@
 
 #include "kvp-scm.h"
 #include "guile-mappings.h"
+#include "gnc-guile-utils.h"
 #include "swig-runtime.h"
 
 /* NOTE: There are some problems with this approach. Currently,
@@ -48,11 +49,9 @@
     {
         gchar *newstr;
         KvpValue *ret;
-        scm_dynwind_begin (0);
-        newstr = scm_to_locale_string (val);
+        newstr = gnc_scm_to_locale_string (val);
         ret = kvp_value_new_string(newstr);
-        scm_dynwind_free (newstr);
-        scm_dynwind_end ();
+        g_free (newstr);
         return ret;
     }
     else if (SWIG_IsPointerOfType(val, SWIG_TypeQuery("_p_KvpFrame")))

Modified: gnucash/trunk/src/gnome/dialog-tax-info.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-tax-info.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/gnome/dialog-tax-info.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -31,6 +31,7 @@
 #include <libguile.h>
 #include "guile-mappings.h"
 #include "guile-util.h"
+#include "gnc-guile-utils.h"
 
 #include "Account.h"
 #include "gnc-ui-util.h"
@@ -337,37 +338,19 @@
 
         scm = scm_call_3 (getters.form, category, code_scm, tax_entity_type);
         if (scm_is_string(scm))
-        {
-            scm_dynwind_begin (0);
-            str = scm_to_locale_string(scm);
-            txf_info->form = g_strdup (str);
-            scm_dynwind_free (str);
-            scm_dynwind_end ();
-        }
+            txf_info->form = gnc_scm_to_locale_string(scm);
         else
             txf_info->form = g_strdup ("");
 
         scm = scm_call_3 (getters.description, category, code_scm, tax_entity_type);
         if (scm_is_string(scm))
-        {
-            scm_dynwind_begin (0);
-            str = scm_to_locale_string(scm);
-            txf_info->description = g_strdup (str);
-            scm_dynwind_free (str);
-            scm_dynwind_end ();
-        }
+            txf_info->description = gnc_scm_to_locale_string(scm);
         else
             txf_info->description = g_strdup ("");
 
         scm = scm_call_2 (getters.help, category, code_scm);
         if (scm_is_string(scm))
-        {
-            scm_dynwind_begin (0);
-            str = scm_to_locale_string(scm);
-            help_text = g_strdup (str);
-            scm_dynwind_free (str);
-            scm_dynwind_end ();
-        }
+            help_text = gnc_scm_to_locale_string(scm);
         else
             help_text = g_strdup ("");
 
@@ -395,15 +378,8 @@
                 line_year = scm_is_bool (SCM_CAR (year_scm)) ? 0 :
                             scm_to_int (SCM_CAR (year_scm));
                 if (scm_is_string((SCM_CAR (SCM_CDR (year_scm)))))
-                {
-                    gchar *temp_line;
-                    scm_dynwind_begin (0);
-                    temp_line = scm_to_locale_string((SCM_CAR (SCM_CDR
-                                                      (year_scm))));
-                    line = g_strdup (temp_line);
-                    scm_dynwind_free (temp_line);
-                    scm_dynwind_end ();
-                }
+                    line = gnc_scm_to_locale_string((SCM_CAR (SCM_CDR
+                                                     (year_scm))));
                 else
                     line = g_strdup ("");
                 temp2 = g_strdup_printf ("%d", line_year);
@@ -505,33 +481,19 @@
         tax_type_info = g_new0 (TaxTypeInfo, 1);
 
         if (scm_is_symbol(type_scm))
-            str = gnc_scm_symbol_to_locale_string (type_scm);
+            tax_type_info->type_code = gnc_scm_symbol_to_locale_string (type_scm);
         else
-            str = g_strdup ("");
-        tax_type_info->type_code = g_strdup (str);
-        g_free (str);
+            tax_type_info->type_code = g_strdup ("");
 
         scm = scm_call_1 (getters.tax_entity_type, type_scm);
         if (scm_is_string(scm))
-        {
-            scm_dynwind_begin (0);
-            str = scm_to_locale_string(scm);
-            tax_type_info->type = g_strdup (str);
-            scm_dynwind_free (str);
-            scm_dynwind_end ();
-        }
+            tax_type_info->type = gnc_scm_to_locale_string(scm);
         else
             tax_type_info->type = g_strdup ("");
 
         scm = scm_call_1 (getters.tax_entity_desc, type_scm);
         if (scm_is_string(scm))
-        {
-            scm_dynwind_begin (0);
-            str = scm_to_locale_string(scm);
-            tax_type_info->description = g_strdup (str);
-            scm_dynwind_free (str);
-            scm_dynwind_end ();
-        }
+            tax_type_info->description = gnc_scm_to_locale_string(scm);
         else
             tax_type_info->description = g_strdup ("");
 

Modified: gnucash/trunk/src/gnome-utils/dialog-options.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-options.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/gnome-utils/dialog-options.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -50,6 +50,7 @@
 #include "gnc-session.h"
 #include "gnc-ui.h"
 #include "guile-util.h"
+#include "gnc-guile-utils.h"
 #include "option-util.h"
 #include "guile-mappings.h"
 #include "gnc-date-format.h"
@@ -2171,14 +2172,8 @@
     if (scm_is_string(value))
     {
         const gchar *string;
-        char * str;
 
-        scm_dynwind_begin (0);
-        str = scm_to_locale_string (value);
-        string = g_strdup (str);
-        scm_dynwind_free (str);
-        scm_dynwind_end ();
-
+        string = gnc_scm_to_locale_string (value);
         gtk_entry_set_text(GTK_ENTRY(widget), string);
         g_free ((gpointer *) string);
         return FALSE;
@@ -2201,14 +2196,8 @@
     if (scm_is_string(value))
     {
         const gchar *string;
-        char * str;
 
-        scm_dynwind_begin (0);
-        str = scm_to_locale_string (value);
-        string = g_strdup (str);
-        scm_dynwind_free (str);
-        scm_dynwind_end ();
-
+        string = gnc_scm_to_locale_string (value);
         gtk_text_buffer_set_text (buffer, string, scm_c_string_length(value));
         g_free ((gpointer *) string);
         return FALSE;
@@ -2481,14 +2470,8 @@
     if (scm_is_string(value))
     {
         const gchar *string;
-        char * str;
 
-        scm_dynwind_begin (0);
-        str = scm_to_locale_string (value);
-        string = g_strdup (str);
-        scm_dynwind_free (str);
-        scm_dynwind_end ();
-
+        string = gnc_scm_to_locale_string (value);
         if ((string != NULL) && (*string != '\0'))
         {
             GtkFontButton *font_button = GTK_FONT_BUTTON(widget);
@@ -2509,14 +2492,8 @@
     if (scm_is_string(value))
     {
         const gchar *string;
-        char * str;
 
-        scm_dynwind_begin (0);
-        str = scm_to_locale_string (value);
-        string = g_strdup (str);
-        scm_dynwind_free (str);
-        scm_dynwind_end ();
-
+        string = gnc_scm_to_locale_string (value);
         if (string && *string)
         {
             gchar *test;

Modified: gnucash/trunk/src/gnome-utils/gnc-menu-extensions.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-menu-extensions.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/gnome-utils/gnc-menu-extensions.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -171,22 +171,15 @@
 
         if (scm_is_string(item))
         {
-            char* s;
+            gchar* s;
+            s = gnc_scm_to_locale_string(item);
 
-            scm_dynwind_begin (0);
-            s = scm_to_locale_string(item);
-
             if (i == 1)
-            {
-
                 strings[i] = g_strdup(s);
-            }
             else
-            {
                 strings[i] = g_strdup(gettext(s));
-            }
-            scm_dynwind_free (s);
-            scm_dynwind_end ();
+
+            g_free (s);
         }
         else
         {

Modified: gnucash/trunk/src/import-export/qif-import/dialog-account-picker.c
===================================================================
--- gnucash/trunk/src/import-export/qif-import/dialog-account-picker.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/import-export/qif-import/dialog-account-picker.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -35,6 +35,7 @@
 #include "gnc-gui-query.h"
 #include "gnc-ui-util.h"
 #include "guile-mappings.h"
+#include "gnc-guile-utils.h"
 #include "gnc-ui.h" /* for GNC_RESPONSE_NEW */
 
 enum account_cols
@@ -92,15 +93,7 @@
         }
 
         if (scm_is_string(SCM_CAR(current)))
-        {
-            char * str;
-
-            scm_dynwind_begin (0);
-            str = scm_to_locale_string (SCM_CAR(current));
-            compname = g_strdup(str);
-            scm_dynwind_free (str);
-            scm_dynwind_end ();
-        }
+            compname = gnc_scm_to_locale_string (SCM_CAR(current));
         else
             compname = g_strdup("");
 
@@ -349,16 +342,8 @@
 
     /* Set the initial account to be selected. */
     if (scm_is_string(orig_acct))
-    {
-        char * str;
+        wind->selected_name = gnc_scm_to_locale_string (orig_acct);
 
-        scm_dynwind_begin (0);
-        str = scm_to_locale_string (orig_acct);
-        wind->selected_name = g_strdup(str);
-        scm_dynwind_free (str);
-        scm_dynwind_end ();
-    }
-
     builder = gtk_builder_new();
     gnc_builder_add_from_file (builder, "dialog-account-picker.glade", "QIF Import Account Picker");
 

Modified: gnucash/trunk/src/report/report-gnome/dialog-custom-report.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/dialog-custom-report.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/report/report-gnome/dialog-custom-report.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -35,6 +35,7 @@
 #include "option-util.h"
 #include "window-report.h"
 #include "guile-mappings.h"
+#include "gnc-guile-utils.h"
 #include "gnc-gui-query.h"
 #include "gnc-ui.h"
 #include "gnc-report.h"
@@ -99,7 +100,6 @@
     SCM get_names = scm_c_eval_string("gnc:custom-report-template-names");
     SCM template_menu_name = scm_c_eval_string("gnc:report-template-menu-name/report-guid");
     SCM names;
-    const gchar *name;
     int i;
     GtkTreeIter iter;
 
@@ -116,19 +116,17 @@
         	 in the gtkliststore */
         for (i = 0; !scm_is_null(names); i++)
         {
-            char * str;
+            gchar *name;
 
-            scm_dynwind_begin (0);
-            str = scm_to_locale_string (scm_call_2(template_menu_name, SCM_CAR(names), SCM_BOOL_F));
-            name = g_strdup (str);
-            scm_dynwind_free (str);
-            scm_dynwind_end ();
+            name = gnc_scm_to_locale_string (scm_call_2(template_menu_name, SCM_CAR(names), SCM_BOOL_F));
 
             gtk_list_store_append(store, &iter);
             gtk_list_store_set(store, &iter,
                                COL_NAME, name,
                                COL_NUM, i,
                                -1);
+            g_free (name);
+
             names = SCM_CDR(names);
         }
     }
@@ -277,18 +275,13 @@
 
     SCM template_menu_name = scm_c_eval_string("gnc:report-template-menu-name/report-guid");
     SCM guid;
-    gchar* report_name;
 
     guid = get_custom_report_selection(crd, _("You must select a report to delete."));
     if (!scm_is_null(guid))
     {
-        char * str;
+        gchar *report_name;
 
-        scm_dynwind_begin (0);
-        str = scm_to_locale_string(scm_call_2(template_menu_name, guid, SCM_BOOL_F));
-        report_name = g_strdup (str);
-        scm_dynwind_free (str);
-        scm_dynwind_end ();
+        report_name = gnc_scm_to_locale_string(scm_call_2(template_menu_name, guid, SCM_BOOL_F));
 
         /* we must confirm the user wants to delete their precious custom report! */
         if (gnc_verify_dialog(crd->dialog, FALSE, "Are you sure you want to delete %s?", report_name))

Modified: gnucash/trunk/src/report/report-gnome/dialog-report-column-view.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/dialog-report-column-view.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/report/report-gnome/dialog-report-column-view.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -34,6 +34,7 @@
 #include "option-util.h"
 #include "window-report.h"
 #include "guile-mappings.h"
+#include "gnc-guile-utils.h"
 #include "gnc-report.h"
 
 enum available_cols
@@ -113,7 +114,7 @@
                                     SCM_BOOL_F);
     SCM   this_report;
     SCM   selection;
-    const gchar *name;
+    gchar *name;
     int   row, i, id;
     GtkListStore *store;
     GtkTreeIter iter;
@@ -145,21 +146,17 @@
     {
         for (i = 0; !scm_is_null(names); names = SCM_CDR(names), i++)
         {
-            char * str;
-
             if (scm_is_equal (SCM_CAR(names), selection))
                 row = i;
-            scm_dynwind_begin (0);
-            str = scm_to_locale_string (scm_call_2(template_menu_name, SCM_CAR(names),
+            name = gnc_scm_to_locale_string (scm_call_2(template_menu_name, SCM_CAR(names),
                                                    SCM_BOOL_F));
-            name = _(g_strdup (str));
-            scm_dynwind_free (str);
-            scm_dynwind_end ();
+
             gtk_list_store_append(store, &iter);
             gtk_list_store_set(store, &iter,
-                               AVAILABLE_COL_NAME, name,
+                               AVAILABLE_COL_NAME, _(name),
                                AVAILABLE_COL_ROW, i,
                                -1);
+            g_free (name);
         }
 
     }
@@ -193,27 +190,22 @@
     {
         for (i = 0; !scm_is_null(contents); contents = SCM_CDR(contents), i++)
         {
-            char * str;
-
             if (scm_is_equal (SCM_CAR(contents), selection))
                 row = i;
 
             id = scm_to_int(SCM_CAAR(contents));
             this_report = gnc_report_find(id);
-            scm_dynwind_begin (0);
-            str = scm_to_locale_string (scm_call_1(report_menu_name, this_report));
-            name = _(g_strdup (str));
-            scm_dynwind_free (str);
-            scm_dynwind_end ();
+            name = gnc_scm_to_locale_string (scm_call_1(report_menu_name, this_report));
 
             gtk_list_store_append(store, &iter);
             gtk_list_store_set
             (store, &iter,
-             CONTENTS_COL_NAME, name,
+             CONTENTS_COL_NAME, _(name),
              CONTENTS_COL_ROW, i,
              CONTENTS_COL_REPORT_COLS, scm_to_int(SCM_CADR(SCM_CAR(contents))),
              CONTENTS_COL_REPORT_ROWS, scm_to_int(SCM_CADDR(SCM_CAR(contents))),
              -1);
+            g_free (name);
         }
     }
 

Modified: gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -51,6 +51,7 @@
 #include "gnc-engine.h"
 #include "gnc-gconf-utils.h"
 #include "gnc-gnome-utils.h"
+#include "gnc-guile-utils.h"
 #include "gnc-html-history.h"
 #include "gnc-html.h"
 #include "gnc-html-factory.h"
@@ -770,13 +771,11 @@
         }
 
         key_name = g_strdup_printf(SCHEME_OPTIONS_N, id);
-        scm_dynwind_begin (0);
-        str = scm_to_locale_string (scm_text);
+        str = gnc_scm_to_locale_string (scm_text);
         text = gnc_guile_strip_comments(str);
         g_key_file_set_string(key_file, group_name, key_name, text);
         g_free(text);
-        scm_dynwind_free (str);
-        scm_dynwind_end ();
+        g_free (str);
         g_free(key_name);
     }
 
@@ -787,13 +786,11 @@
         return;
     }
 
-    scm_dynwind_begin (0);
-    str = scm_to_locale_string (scm_text);
+    str = gnc_scm_to_locale_string (scm_text);
     text = gnc_guile_strip_comments(str);
     g_key_file_set_string(key_file, group_name, SCHEME_OPTIONS, text);
     g_free(text);
-    scm_dynwind_free (str);
-    scm_dynwind_end ();
+    g_free (str);
     LEAVE(" ");
 }
 
@@ -1371,11 +1368,8 @@
             break;
         }
 
-        scm_dynwind_begin (0);
-        name = scm_to_locale_string (scm);
-        choices = g_list_prepend (choices, g_strdup (name));
-        scm_dynwind_free (name);
-        scm_dynwind_end ();
+        name = gnc_scm_to_locale_string (scm);
+        choices = g_list_prepend (choices, name);
     }
 
     if (!bad)
@@ -1423,14 +1417,7 @@
     if (choice == SCM_BOOL_T)
         type = g_strdup (html_type);
     else
-    {
-        char * str;
-        scm_dynwind_begin (0);
-        str = scm_to_locale_string(SCM_CAR (choice));
-        type = g_strdup (str);
-        scm_dynwind_free (str);
-        scm_dynwind_end ();
-    }
+        type = gnc_scm_to_locale_string(SCM_CAR (choice));
 
     /* %s is the type of what is about to be saved, e.g. "HTML". */
     title = g_strdup_printf (_("Save %s To File"), type);

Modified: gnucash/trunk/src/report/report-gnome/window-report.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/window-report.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/report/report-gnome/window-report.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -36,6 +36,7 @@
 #include "dialog-options.h"
 #include "file-utils.h"
 #include "gnc-gkeyfile-utils.h"
+#include "gnc-guile-utils.h"
 #include "gnc-report.h"
 #include "gnc-ui.h"
 #include "option-util.h"
@@ -158,15 +159,7 @@
             {
                 ptr = scm_call_1(get_template_name, ptr);
                 if (scm_is_string(ptr))
-                {
-                    char * str;
-
-                    scm_dynwind_begin (0);
-                    str = scm_to_locale_string (ptr);
-                    title = g_strdup (str);
-                    scm_dynwind_free (str);
-                    scm_dynwind_end ();
-                }
+                    title = gnc_scm_to_locale_string (ptr);
             }
         }
 

Modified: gnucash/trunk/src/report/report-system/Makefile.am
===================================================================
--- gnucash/trunk/src/report/report-system/Makefile.am	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/report/report-system/Makefile.am	2012-12-22 18:20:29 UTC (rev 22684)
@@ -14,6 +14,7 @@
 libgncmod_report_system_la_LDFLAGS = -avoid-version
 
 libgncmod_report_system_la_LIBADD = \
+  ${top_builddir}/src/core-utils/libgnc-core-utils.la \
   ${top_builddir}/src/gnc-module/libgnc-module.la \
   ${top_builddir}/src/app-utils/libgncmod-app-utils.la \
   ${GUILE_LIBS} \
@@ -28,6 +29,7 @@
 
 AM_CPPFLAGS = \
   -I${top_srcdir}/src \
+  -I${top_srcdir}/src/core-utils \
   -I${top_srcdir}/src/gnc-module \
   -I${top_srcdir}/src/app-utils \
   ${GLIB_CFLAGS} \

Modified: gnucash/trunk/src/report/report-system/gnc-report.c
===================================================================
--- gnucash/trunk/src/report/report-system/gnc-report.c	2012-12-22 18:20:17 UTC (rev 22683)
+++ gnucash/trunk/src/report/report-system/gnc-report.c	2012-12-22 18:20:29 UTC (rev 22684)
@@ -157,11 +157,7 @@
     if (scm_text == SCM_UNDEFINED || !scm_is_string (scm_text))
         return FALSE;
 
-    scm_dynwind_begin (0);
-    free_data = scm_to_locale_string (scm_text);
-    *data = g_strdup (free_data);
-    scm_dynwind_free (free_data);
-    scm_dynwind_end ();
+    *data = gnc_scm_to_locale_string (scm_text);
 
     return TRUE;
 }



More information about the gnucash-changes mailing list