I've read a mail from a Chinese user which sent to guile-user. And I
realized that this locale string reading error is a real problem to a
Chinese user.
And I talked with Wingo & ijp about this topic. Finally I found what's the
problem.
All the string seems to be handled all by libunistring now, and
"u32_conv_from_encoding" should return a valid string under "zh_CN.UTF-8",
but it didn't.
We need to call setlocale(LC_ALL, ""), or the user must do it in their code
every time.
The better solution maybe set locale each time scm_*_locale_string is
called,  because the locale could be changed during the runtime.

Here is the patch. It solved the problem like these:
------------------cut begin--------------
...
(write (command-line))
...
-------------------cut end---------------

# ./test.scm 我靠
==>("./ad.scm" "我靠")

Now it works.



---------------------------------------------patch
cut---------------------------------------------------------

>From a424c2f7022cc81d163971cf961581d560f0d4ed Mon Sep 17 00:00:00 2001
From: NalaGinrut <nalagin...@gmail.com>
Date: Tue, 8 Nov 2011 02:56:03 +0800
Subject: [PATCH] fix locale string reading

---
 libguile/strings.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/libguile/strings.c b/libguile/strings.c
index 666a951..391c983 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -29,6 +29,7 @@
 #include <uninorm.h>
 #include <unistr.h>
 #include <uniconv.h>
+#include <locale.h>

 #include "striconveh.h"

@@ -1532,6 +1533,7 @@ scm_from_locale_string (const char *str)
 SCM
 scm_from_locale_stringn (const char *str, size_t len)
 {
+  setlocale (LC_ALL, "");
   return scm_from_stringn (str, len, locale_charset (),
                            scm_i_get_conversion_strategy (SCM_BOOL_F));
 }
@@ -1758,6 +1760,7 @@ scm_to_locale_string (SCM str)
 char *
 scm_to_locale_stringn (SCM str, size_t *lenp)
 {
+  setlocale (LC_ALL, "");
   return scm_to_stringn (str, lenp,
                          locale_charset (),
                          scm_i_get_conversion_strategy (SCM_BOOL_F));
-- 
1.7.0.4

Reply via email to