r20000 - gnucash/trunk/src/app-utils - Follow-up to r19999: Refactor guile version-safe scm_to_locale_string into gnc function.

Christian Stimming cstim at code.gnucash.org
Thu Dec 30 06:41:33 EST 2010


Author: cstim
Date: 2010-12-30 06:41:33 -0500 (Thu, 30 Dec 2010)
New Revision: 20000
Trac: http://svn.gnucash.org/trac/changeset/20000

Modified:
   gnucash/trunk/src/app-utils/guile-util.c
   gnucash/trunk/src/app-utils/guile-util.h
Log:
Follow-up to r19999: Refactor guile version-safe scm_to_locale_string into gnc function.

(Yay, I made r20000 :-)

Modified: gnucash/trunk/src/app-utils/guile-util.c
===================================================================
--- gnucash/trunk/src/app-utils/guile-util.c	2010-12-30 11:33:31 UTC (rev 19999)
+++ gnucash/trunk/src/app-utils/guile-util.c	2010-12-30 11:41:33 UTC (rev 20000)
@@ -163,17 +163,7 @@
 
         if (scm_is_string(value))
         {
-            char* x;
-            gchar* s;
-
-            x = scm_to_locale_string(value);
-
-            /* scm_to_locale_string() returns a malloc'ed string in
-               guile-1.8 (but not in guile-1.6).  Copy to a
-               g_malloc'ed one. */
-            s = g_strdup(x);
-            gnc_free_scm_locale_string(x);
-            return s;
+            return gnc_scm_to_locale_string(value);
         }
         else
         {
@@ -662,8 +652,6 @@
 gnc_split_scm_get_memo(SCM split_scm)
 {
     SCM result;
-    char* x;
-    gchar* s;
 
     initialize_scm_functions();
 
@@ -674,14 +662,7 @@
     if (!scm_is_string(result))
         return NULL;
 
-    x = scm_to_locale_string(result);
-
-    /* scm_to_locale_string() returns a malloc'ed string in
-       guile-1.8 (but not in guile-1.6).
-       Copy to a g_malloc'ed one. */
-    s = g_strdup(x);
-    gnc_free_scm_locale_string(x);
-    return s;
+    return gnc_scm_to_locale_string(result);
 }
 
 
@@ -696,8 +677,6 @@
 gnc_split_scm_get_action(SCM split_scm)
 {
     SCM result;
-    char* x;
-    gchar* s;
 
     initialize_scm_functions();
 
@@ -708,14 +687,7 @@
     if (!scm_is_string(result))
         return NULL;
 
-    x = scm_to_locale_string(result);
-
-    /* scm_to_locale_string() returns a malloc'ed string in
-       guile-1.8 (but not in guile-1.6).
-       Copy to a g_malloc'ed one. */
-    s = g_strdup(x);
-    gnc_free_scm_locale_string(x);
-    return s;
+    return gnc_scm_to_locale_string(result);
 }
 
 
@@ -1130,8 +1102,6 @@
     const gchar *string;
     SCM result;
     SCM arg;
-    char* x;
-    gchar* s;
 
     initialize_scm_functions();
 
@@ -1147,14 +1117,7 @@
     if (!scm_is_string(result))
         return NULL;
 
-    x = scm_to_locale_string(result);
-
-    /* scm_to_locale_string() returns a malloc'ed string in
-       guile-1.8 (but not in guile-1.6).
-       Copy to a g_malloc'ed one. */
-    s = g_strdup(x);
-    gnc_free_scm_locale_string(x);
-    return s;
+    return gnc_scm_to_locale_string(result);
 }
 
 
@@ -1171,8 +1134,6 @@
     const gchar *string;
     SCM result;
     SCM arg;
-    char* x;
-    gchar* s;
 
     initialize_scm_functions();
 
@@ -1188,14 +1149,7 @@
     if (!scm_is_string(result))
         return NULL;
 
-    x = scm_to_locale_string(result);
-
-    /* scm_to_locale_string() returns a malloc'ed string in
-       guile-1.8 (but not in guile-1.6).
-       Copy to a g_malloc'ed one. */
-    s = g_strdup(x);
-    gnc_free_scm_locale_string(x);
-    return s;
+    return gnc_scm_to_locale_string(result);
 }
 
 
@@ -1364,3 +1318,15 @@
 
     return mktime(&tm);
 }
+
+gchar *gnc_scm_to_locale_string(SCM scm_string)
+{
+    gchar* s;
+    char* x = scm_to_locale_string(scm_string);
+
+    /* scm_to_locale_string() returns a malloc'ed string in guile-1.8
+       (but not in guile-1.6).  Copy to a g_malloc'ed one. */
+    s = g_strdup(x);
+    gnc_free_scm_locale_string(x);
+    return s;
+}

Modified: gnucash/trunk/src/app-utils/guile-util.h
===================================================================
--- gnucash/trunk/src/app-utils/guile-util.h	2010-12-30 11:33:31 UTC (rev 19999)
+++ gnucash/trunk/src/app-utils/guile-util.h	2010-12-30 11:41:33 UTC (rev 20000)
@@ -41,6 +41,11 @@
 SCM    gnc_guile_list_ref(SCM list, int index);
 SCM    gnc_guile_call1_to_vector(SCM func, SCM arg);
 
+/** Wrapper around scm_to_locale_string() that returns a newly
+ * allocated string (even for guile-1.6 version). The caller must
+ * g_free() the returned string later. */
+gchar * gnc_scm_to_locale_string(SCM scm_string);
+
 /* Don't use this to get hold of symbols that are considered private
  * to a given module unless the C code you're writing is considered
  * part of that module.  */



More information about the gnucash-changes mailing list