summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeert Janssens <janssens-geert@telenet.be>2013-12-13 17:48:26 +0100
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2014-02-08 15:58:58 +0000
commit36f5117b25fd6689e76bb0e2854e9df696631a2c (patch)
tree8ede29226864eca1764ca09ddaaaa2c1bc08b0f5
parentc569210dd59e252be5176cb3224cc7e354bb97c1 (diff)
downloadswig-36f5117b25fd6689e76bb0e2854e9df696631a2c.tar.gz
Guile: make scm to string conversion work with non-ascii strings
-rw-r--r--Examples/test-suite/guile/li_std_string_runme.scm4
-rw-r--r--Lib/guile/guile_scm_run.swg22
2 files changed, 13 insertions, 13 deletions
diff --git a/Examples/test-suite/guile/li_std_string_runme.scm b/Examples/test-suite/guile/li_std_string_runme.scm
index 5dde68f8d..5b5563281 100644
--- a/Examples/test-suite/guile/li_std_string_runme.scm
+++ b/Examples/test-suite/guile/li_std_string_runme.scm
@@ -2,4 +2,8 @@
;; Guile modules (namespaces) but simply put all the bindings into the
;; current module. That's enough for such a simple test.
(dynamic-call "scm_init_li_std_string_module" (dynamic-link "./libli_std_string"))
+; Note: when working with non-ascii strings in guile 2
+; locale must be set explicitly
+; The setlocale call below takes care of that
+(setlocale LC_ALL "")
(load "../schemerunme/li_std_string.scm")
diff --git a/Lib/guile/guile_scm_run.swg b/Lib/guile/guile_scm_run.swg
index 0ac51f919..4978ab114 100644
--- a/Lib/guile/guile_scm_run.swg
+++ b/Lib/guile/guile_scm_run.swg
@@ -41,10 +41,14 @@ typedef struct swig_guile_clientdata {
SCM goops_class;
} swig_guile_clientdata;
+#if SCM_MAJOR_VERSION <= 2
+#define scm_to_utf8_string scm_to_locale_string
+#define scm_from_utf8_string scm_from_locale_string
+#endif
#define SWIG_scm2str(s) \
SWIG_Guile_scm2newstr(s, NULL)
#define SWIG_str02scm(str) \
- str ? scm_from_locale_string(str) : SCM_BOOL_F
+ str ? scm_from_utf8_string(str) : SCM_BOOL_F
# define SWIG_malloc(size) \
scm_malloc(size)
# define SWIG_free(mem) \
@@ -84,21 +88,13 @@ SWIGINTERN char *
SWIG_Guile_scm2newstr(SCM str, size_t *len) {
#define FUNC_NAME "SWIG_Guile_scm2newstr"
char *ret;
- char *tmp;
- size_t l;
SCM_ASSERT (scm_is_string(str), str, 1, FUNC_NAME);
- l = scm_c_string_length(str);
- ret = (char *) SWIG_malloc( (l + 1) * sizeof(char));
+ ret = scm_to_utf8_string(str);
if (!ret) return NULL;
- tmp = scm_to_locale_string(str);
- memcpy(ret, tmp, l);
- free(tmp);
-
- ret[l] = '\0';
- if (len) *len = l;
+ if (len) *len = strlen(ret) - 1;
return ret;
#undef FUNC_NAME
}
@@ -482,7 +478,7 @@ SWIG_Guile_GetArgs (SCM *dest, SCM rest,
int num_args_passed = 0;
for (i = 0; i<reqargs; i++) {
if (!SCM_CONSP(rest))
- scm_wrong_num_args(scm_from_locale_string(procname ? (char *) procname : "unknown procedure"));
+ scm_wrong_num_args(scm_from_utf8_string(procname ? (char *) procname : "unknown procedure"));
*dest++ = SCM_CAR(rest);
rest = SCM_CDR(rest);
num_args_passed++;
@@ -495,7 +491,7 @@ SWIG_Guile_GetArgs (SCM *dest, SCM rest,
for (; i<optargs; i++)
*dest++ = SCM_UNDEFINED;
if (!SCM_NULLP(rest))
- scm_wrong_num_args(scm_from_locale_string(procname ? (char *) procname : "unknown procedure"));
+ scm_wrong_num_args(scm_from_utf8_string(procname ? (char *) procname : "unknown procedure"));
return num_args_passed;
}