[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] GNU Guile branch, string_abstraction2, updated. 4d9dfb46
From: |
Michael Gran |
Subject: |
[Guile-commits] GNU Guile branch, string_abstraction2, updated. 4d9dfb466ad6fdc9bd42ae7ed5a47dcedec5981a |
Date: |
Tue, 26 May 2009 16:00:39 +0000 |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".
http://git.savannah.gnu.org/cgit/guile.git/commit/?id=4d9dfb466ad6fdc9bd42ae7ed5a47dcedec5981a
The branch, string_abstraction2 has been updated
via 4d9dfb466ad6fdc9bd42ae7ed5a47dcedec5981a (commit)
from cd130d9b5fbb6345a57dfde0800be8a9a9257203 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 4d9dfb466ad6fdc9bd42ae7ed5a47dcedec5981a
Author: Michael Gran <address@hidden>
Date: Tue May 26 08:56:06 2009 -0700
move reader encoding parameters to fluids
* libguile/ports.c: only use accessors functions for
reader encoding parameters
* libguile/strings.c: move scm_i_port_encoding and
scm_i_conversion_strategy into fluids, and make
accessor functions for the new fluid variables.
* libguile/strings.h: remove macro SCM_PORT_ENCODING
* libguile/posix.c: only use accessor functions for
reader encoding parameters
-----------------------------------------------------------------------
Summary of changes:
libguile/ports.c | 6 +-
libguile/posix.c | 14 +----
libguile/strings.c | 135 ++++++++++++++++++++++++++++++++++++++++------------
libguile/strings.h | 8 ++--
4 files changed, 115 insertions(+), 48 deletions(-)
diff --git a/libguile/ports.c b/libguile/ports.c
index 4ed30c2..0b9ecd0 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -963,7 +963,7 @@ scm_getc (SCM port)
bufcount++;
/* Handle most ASCII characters quickly. */
- if ((scm_i_port_encoding == NULL)
+ if ((scm_i_get_port_encoding () == NULL)
|| ('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <=
'Z'))
{
/* In all (?) encodings except UTF-16 and UTF-32, alnum characters
@@ -974,7 +974,7 @@ scm_getc (SCM port)
for (;;)
{
- u32 = u32_conv_from_encoding (SCM_PORT_ENCODING,
scm_conversion_strategy,
+ u32 = u32_conv_from_encoding (SCM_PORT_ENCODING,
scm_i_get_conversion_strategy (),
buf, bufcount, NULL, NULL, &u32len);
if (u32 == NULL || u32len == 0)
{
@@ -1053,7 +1053,7 @@ scm_getc (SCM port)
characters won't help. Try hard to make a string for the
error message. */
- if (scm_conversion_strategy != iconveh_escape_sequence)
+ if (scm_i_get_conversion_strategy ()!= iconveh_escape_sequence)
{
u32 = u32_conv_from_encoding (SCM_PORT_ENCODING,
iconveh_escape_sequence,
buf, bufcount, NULL, NULL, &u32len);
diff --git a/libguile/posix.c b/libguile/posix.c
index 8cfec5c..30a224b 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1665,9 +1665,7 @@ SCM_DEFINE (scm_setlocale, "setlocale", 1, 1, 0,
SCM_SYSERROR;
}
- if (scm_i_port_encoding != NULL)
- free (scm_i_port_encoding);
- scm_i_port_encoding = strdup (locale_charset ());
+ scm_i_set_port_encoding (locale_charset ());
/* Recompute the standard SRFI-14 character sets in a locale-dependent
(actually charset-dependent) way. */
scm_srfi_14_compute_char_sets ();
@@ -1705,11 +1703,7 @@ SCM_DEFINE (scm_setencoding, "setencoding", 1, 0, 0,
scm_misc_error (FUNC_NAME, "invalid or unknown character encoding ~s",
scm_list_1 (enc));
free (u32);
- if (scm_i_port_encoding != NULL)
- free (scm_i_port_encoding);
-
- scm_i_port_encoding = new_enc;
-
+ scm_i_set_port_encoding (new_enc);
return SCM_UNSPECIFIED;
}
@@ -1732,9 +1726,7 @@ SCM_DEFINE (scm_setbinary, "setbinary", 0, 0, 0,
"@code{setlocale} will, again, modify the character encoding.\n")
#define FUNC_NAME s_scm_setbinary
{
- if (scm_i_port_encoding != NULL)
- free (scm_i_port_encoding);
- scm_i_port_encoding = NULL;
+ scm_i_set_port_encoding (NULL);
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME
diff --git a/libguile/strings.c b/libguile/strings.c
index 3ca2902..99e9257 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -35,6 +35,7 @@
#include "libguile/validate.h"
#include "libguile/dynwind.h"
#include "libguile/eq.h"
+#include "libguile/fluids.h"
#include "striconveh.h"
@@ -256,11 +257,70 @@ scm_i_pthread_mutex_t stringbuf_write_mutex =
SCM_I_PTHREAD_MUTEX_INITIALIZER;
#define IS_SH_STRING(str) (SCM_CELL_TYPE(str)==SH_STRING_TAG)
+/* This is the current locale encoding. */
+SCM_GLOBAL_VARIABLE (scm_port_encoding, "%port-encoding");
+static int scm_port_encoding_init = 0;
+
+const char *
+scm_i_get_port_encoding ()
+{
+ SCM encoding;
+ if (!scm_port_encoding_init)
+ return NULL;
+ else if (!scm_is_fluid (SCM_VARIABLE_REF (scm_port_encoding)))
+ return NULL;
+ else
+ {
+ encoding = scm_fluid_ref (SCM_VARIABLE_REF (scm_port_encoding));
+ if (!scm_is_string (encoding))
+ return NULL;
+ else
+ return scm_i_string_chars (encoding);
+ }
+}
+
+void
+scm_i_set_port_encoding (const char *enc)
+{
+ char *buf;
+ SCM encoding;
+
+ if (enc == NULL)
+ encoding = SCM_BOOL_F;
+ else
+ {
+ encoding = scm_i_make_string (strlen (enc), &buf);
+ memcpy (buf, enc, strlen(enc));
+ }
+ if (!scm_port_encoding_init
+ || !scm_is_fluid (SCM_VARIABLE_REF (scm_port_encoding)))
+ scm_misc_error (NULL, "tried to set port encoding fluid before it is
initialized",
+ SCM_EOL);
+ scm_fluid_set_x (SCM_VARIABLE_REF (scm_port_encoding), encoding);
+}
+
/* This determines how conversions handle unconvertible characters. */
-enum iconv_ilseq_handler scm_conversion_strategy;
+SCM_GLOBAL_VARIABLE (scm_conversion_strategy, "%conversion-strategy");
+static int scm_conversion_strategy_init = 0;
+
+enum iconv_ilseq_handler
+scm_i_get_conversion_strategy ()
+{
+ SCM encoding;
+
+ if (!scm_conversion_strategy_init
+ || !scm_is_fluid (SCM_VARIABLE_REF (scm_conversion_strategy)))
+ return iconveh_question_mark;
+ else
+ {
+ encoding = scm_fluid_ref (SCM_VARIABLE_REF (scm_conversion_strategy));
+ if (scm_is_false (encoding))
+ return iconveh_question_mark;
+ else
+ return (enum iconv_ilseq_handler) scm_to_int (encoding);
+ }
+}
-/* This is the current locale encoding. */
-char *scm_i_port_encoding;
SCM
scm_i_make_string (size_t len, char **charsp)
@@ -1016,6 +1076,10 @@ SCM_DEFINE (scm_set_conversion_error_behavior_x,
"set-conversion-error-behavior!
static SCM esc;
static int first = 1;
+ if (!scm_conversion_strategy_init)
+ scm_misc_error (NULL,
+ "tried to set a conversion strategy before string module
initialization.",
+ SCM_EOL);
if (first)
{
err = scm_from_locale_symbol ("error");
@@ -1025,11 +1089,14 @@ SCM_DEFINE (scm_set_conversion_error_behavior_x,
"set-conversion-error-behavior!
}
if (scm_is_true (scm_eq_p (sym, err)))
- scm_conversion_strategy = iconveh_error;
+ scm_fluid_set_x (SCM_VARIABLE_REF (scm_conversion_strategy),
+ scm_from_int ((int) iconveh_error));
else if (scm_is_true (scm_eq_p (sym, qm)))
- scm_conversion_strategy = iconveh_question_mark;
+ scm_fluid_set_x (SCM_VARIABLE_REF (scm_conversion_strategy),
+ scm_from_int ((int) iconveh_question_mark));
else if (scm_is_true (scm_eq_p (sym, esc)))
- scm_conversion_strategy = iconveh_escape_sequence;
+ scm_fluid_set_x (SCM_VARIABLE_REF (scm_conversion_strategy),
+ scm_from_int ((int) iconveh_escape_sequence));
else
SCM_MISC_ERROR ("unknown conversion behavior ~s", scm_list_1 (sym));
@@ -1374,7 +1441,8 @@ scm_from_locale_stringn (const char *str, size_t len)
if (len == 0)
return scm_nullstr;
- if (strcmp (SCM_PORT_ENCODING, "ISO-8859-1") == 0)
+ if (scm_i_get_port_encoding () == NULL
+ || strcmp (SCM_PORT_ENCODING, "ISO-8859-1") == 0)
{
res = scm_i_make_string (len, &dst);
memcpy (dst, str, len);
@@ -1383,7 +1451,7 @@ scm_from_locale_stringn (const char *str, size_t len)
u32len = 0;
u32 = (scm_t_wchar *) u32_conv_from_encoding (SCM_PORT_ENCODING,
- scm_conversion_strategy,
+ scm_i_get_conversion_strategy
(),
str, len,
NULL,
NULL, &u32len);
@@ -1535,6 +1603,7 @@ scm_to_locale_stringn (SCM str, size_t *lenp)
char *buf;
size_t strlen, len, i;
int ret;
+ const char *enc;
if (!scm_is_string (str))
scm_wrong_type_arg_msg (NULL, 0, str, "string");
@@ -1548,7 +1617,7 @@ scm_to_locale_stringn (SCM str, size_t *lenp)
"string contains #\\nul character: ~S",
scm_list_1 (str));
- if (scm_i_is_narrow_string (str) && scm_i_port_encoding == NULL)
+ if (scm_i_is_narrow_string (str) && (scm_i_get_port_encoding() == NULL))
{
if (lenp)
{
@@ -1567,14 +1636,17 @@ scm_to_locale_stringn (SCM str, size_t *lenp)
buf = NULL;
len = 0;
+ enc = scm_i_get_port_encoding ();
+ if (enc == NULL)
+ enc = "ISO-8859-1";
if (scm_i_is_narrow_string (str))
{
ret = mem_iconveh (scm_i_string_chars (str), strlen,
- "ISO-8859-1", SCM_PORT_ENCODING,
- scm_conversion_strategy, NULL,
+ "ISO-8859-1", enc,
+ scm_i_get_conversion_strategy (), NULL,
&buf, &len);
- if (ret == 0 && scm_conversion_strategy == iconveh_escape_sequence)
+ if (ret == 0 && scm_i_get_conversion_strategy () ==
iconveh_escape_sequence)
unistring_escapes_to_guile_escapes (&buf, &len);
if (ret != 0)
@@ -1582,10 +1654,10 @@ scm_to_locale_stringn (SCM str, size_t *lenp)
/* If there is a conversion error, try to generate an escaped
version of the string for the error message. */
SCM escape_str;
- if (scm_conversion_strategy != iconveh_escape_sequence)
+ if (scm_i_get_conversion_strategy () != iconveh_escape_sequence)
ret = mem_iconveh (scm_i_string_chars (str),
strlen,
- "ISO-8859-1", SCM_PORT_ENCODING,
+ "ISO-8859-1", enc,
iconveh_escape_sequence, NULL,
&buf, &len);
if (ret == 0)
@@ -1593,19 +1665,19 @@ scm_to_locale_stringn (SCM str, size_t *lenp)
unistring_escapes_to_guile_escapes (&buf, &len);
escape_str = scm_from_locale_stringn (buf, len);
free (buf);
- scm_misc_error (NULL, "cannot convert to output locale ~s: ~a",
- scm_list_2 (scm_from_locale_string
(SCM_PORT_ENCODING),
+ scm_misc_error (NULL, "cannot convert to output locale ~s:
\"~a\"",
+ scm_list_2 (scm_from_locale_string (enc),
escape_str));
}
else
scm_misc_error (NULL, "cannot convert to output locale ~s",
- scm_list_1 (scm_from_locale_string
(SCM_PORT_ENCODING)));
+ scm_list_1 (scm_from_locale_string (enc)));
}
}
else
{
- buf = u32_conv_to_encoding (SCM_PORT_ENCODING,
- scm_conversion_strategy,
+ buf = u32_conv_to_encoding (enc,
+ scm_i_get_conversion_strategy (),
(scm_t_uint32 *) scm_i_string_wide_chars
(str),
strlen,
NULL,
@@ -1615,8 +1687,8 @@ scm_to_locale_stringn (SCM str, size_t *lenp)
/* If there is a conversion error, try to generate an escaped
version of the string for the error message. */
SCM escape_str;
- if (scm_conversion_strategy != iconveh_escape_sequence)
- buf = u32_conv_to_encoding (SCM_PORT_ENCODING,
+ if (scm_i_get_conversion_strategy () != iconveh_escape_sequence)
+ buf = u32_conv_to_encoding (enc,
iconveh_escape_sequence,
(scm_t_uint32 *)
scm_i_string_wide_chars (str),
strlen,
@@ -1627,13 +1699,13 @@ scm_to_locale_stringn (SCM str, size_t *lenp)
/* scm_unistring_escapes_to_guile_escapes (&buf, &len) */
escape_str = scm_from_locale_stringn (buf, len);
free (buf);
- scm_misc_error (NULL, "cannot convert to output locale ~s: ~s",
- scm_list_2 (scm_from_locale_string
(SCM_PORT_ENCODING),
+ scm_misc_error (NULL, "cannot convert to output locale ~s:
\"~a\"",
+ scm_list_2 (scm_from_locale_string (enc),
escape_str));
}
else
scm_misc_error (NULL, "cannot convert to output locale ~s",
- scm_list_1 (scm_from_locale_string
(SCM_PORT_ENCODING)));
+ scm_list_1 (scm_from_locale_string (enc)));
}
}
@@ -1814,14 +1886,17 @@ scm_i_deprecated_string_length (SCM str)
void
scm_init_strings ()
{
+#include "libguile/strings.x"
scm_nullstr = scm_i_make_string (0, NULL);
- scm_conversion_strategy = iconveh_question_mark;
- /* Since, ISO-8859-1 is an 8-bit charset with the Unicode codepoints
- 0 to 255, it is effectively the same as doing no conversion on
- input or output. */
- scm_i_port_encoding = NULL;
-#include "libguile/strings.x"
+ SCM_VARIABLE_SET (scm_port_encoding, scm_make_fluid ());
+ scm_fluid_set_x (SCM_VARIABLE_REF (scm_port_encoding), SCM_BOOL_F);
+ scm_port_encoding_init = 1;
+
+ SCM_VARIABLE_SET (scm_conversion_strategy, scm_make_fluid ());
+ scm_fluid_set_x (SCM_VARIABLE_REF (scm_conversion_strategy),
+ scm_from_int ((int) iconveh_question_mark));
+ scm_conversion_strategy_init = 1;
}
diff --git a/libguile/strings.h b/libguile/strings.h
index a2ed19d..9361a8d 100644
--- a/libguile/strings.h
+++ b/libguile/strings.h
@@ -76,12 +76,12 @@
an error for for strings that are not null-terminated.
*/
-extern char *scm_i_port_encoding;
-#define SCM_PORT_ENCODING ((scm_i_port_encoding==NULL) ? "ISO-8859-1" :
scm_i_port_encoding)
-extern enum iconv_ilseq_handler scm_conversion_strategy;
-
+#define SCM_PORT_ENCODING (scm_i_get_port_encoding())
SCM_API SCM scm_set_conversion_error_behavior_x (SCM behavior);
+SCM_INTERNAL const char *scm_i_get_port_encoding (void);
+SCM_INTERNAL void scm_i_set_port_encoding (const char *enc);
+SCM_INTERNAL enum iconv_ilseq_handler scm_i_get_conversion_strategy (void);
SCM_API SCM scm_string_p (SCM x);
SCM_API SCM scm_string (SCM chrs);
SCM_API SCM scm_make_string (SCM k, SCM chr);
hooks/post-receive
--
GNU Guile
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Guile-commits] GNU Guile branch, string_abstraction2, updated. 4d9dfb466ad6fdc9bd42ae7ed5a47dcedec5981a,
Michael Gran <=