diff --git a/src/app-utils/guile-util.c b/src/app-utils/guile-util.c index 6c6e4d448d..d21afc30ac 100644 --- a/src/app-utils/guile-util.c +++ b/src/app-utils/guile-util.c @@ -163,17 +163,7 @@ gnc_guile_call1_to_string(SCM func, SCM arg) 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 @@ char * gnc_split_scm_get_memo(SCM split_scm) { SCM result; - char* x; - gchar* s; initialize_scm_functions(); @@ -674,14 +662,7 @@ gnc_split_scm_get_memo(SCM split_scm) 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 @@ char * gnc_split_scm_get_action(SCM split_scm) { SCM result; - char* x; - gchar* s; initialize_scm_functions(); @@ -708,14 +687,7 @@ gnc_split_scm_get_action(SCM split_scm) 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 @@ gnc_get_debit_string(GNCAccountType account_type) const gchar *string; SCM result; SCM arg; - char* x; - gchar* s; initialize_scm_functions(); @@ -1147,14 +1117,7 @@ gnc_get_debit_string(GNCAccountType account_type) 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 @@ gnc_get_credit_string(GNCAccountType account_type) const gchar *string; SCM result; SCM arg; - char* x; - gchar* s; initialize_scm_functions(); @@ -1188,14 +1149,7 @@ gnc_get_credit_string(GNCAccountType account_type) 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 @@ gnc_parse_time_to_timet(const gchar *s, const gchar *format) 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; +} diff --git a/src/app-utils/guile-util.h b/src/app-utils/guile-util.h index ac6994a0a3..45bbdc7cd0 100644 --- a/src/app-utils/guile-util.h +++ b/src/app-utils/guile-util.h @@ -41,6 +41,11 @@ SCM gnc_guile_call1_to_list(SCM func, SCM arg); 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. */