summaryrefslogtreecommitdiff
path: root/libguile/strings.c
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2011-02-02 15:52:56 +0100
committerLudovic Courtès <ludo@gnu.org>2011-02-02 18:06:28 +0100
commitc62da8f891569aa717f4f8557c7e87650ec92fb1 (patch)
treeb176c4ccfc858a9e55915da0131901c3fa3e0907 /libguile/strings.c
parentd6cf96974ea21b2f0deb1908baefb3dd2b704331 (diff)
downloadguile-c62da8f891569aa717f4f8557c7e87650ec92fb1.tar.gz
Have `read-char' & co. throw to `decoding-error'.
* libguile/ports.c (scm_read_char): Mention `decoding-error' in the docstring. (get_codepoint): Change to return an error code; add `codepoint' output parameter. Don't raise an error from here. (scm_getc): Raise an error with `scm_decoding_error' if `get_codepoint' returns an error. (scm_peek_char): Likewise. Update docstring. * libguile/strings.c (scm_decoding_error_key): New variable. (scm_decoding_error): New function. (scm_from_stringn): Use `scm_decoding_error' instead of `scm_encoding_error'. * libguile/strings.h (scm_decoding_error): New declaration. * test-suite/tests/ports.test ("string ports")["read-char, wrong encoding, error"]: Change to expect `decoding-error'. Make sure PORT points past the error. ["read-char, wrong encoding, escape"]: Likewise. ["peek-char, wrong encoding, error"]: New test. * test-suite/tests/r6rs-ports.test ("7.2.11 Binary Output")["put-bytevector with wrong-encoding string port"]: Change to expect `decoding-error'. ("8.2.6 Input and output ports")["transcoded-port [error handling mode = raise]"]: Likewise. * test-suite/tests/rdelim.test ("read-line")["decoding error", "decoding error, substitute"]: New tests. * doc/ref/api-io.texi (Reading): Update documentation of `read-char' and `peek-char'. (Line/Delimited): Update documentation of `read-line'.
Diffstat (limited to 'libguile/strings.c')
-rw-r--r--libguile/strings.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/libguile/strings.c b/libguile/strings.c
index 41998a92b..7a580609e 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -1407,9 +1407,11 @@ SCM_DEFINE (scm_string_append, "string-append", 0, 0, 1,
-/* Conversion to/from other encodings. */
+/* Charset conversion error handling. */
SCM_SYMBOL (scm_encoding_error_key, "encoding-error");
+SCM_SYMBOL (scm_decoding_error_key, "decoding-error");
+
void
scm_encoding_error (const char *subr, int err, const char *message,
const char *from, const char *to, SCM string_or_bv)
@@ -1428,6 +1430,22 @@ scm_encoding_error (const char *subr, int err, const char *message,
SCM_UNDEFINED));
}
+/* Raise an exception informing of an encoding error on PORT. This
+ means that a character could not be written in PORT's encoding. */
+void
+scm_decoding_error (const char *subr, int err, const char *message, SCM port)
+{
+ scm_throw (scm_decoding_error_key,
+ scm_list_n (scm_from_locale_string (subr),
+ scm_from_locale_string (message),
+ scm_from_int (err),
+ port,
+ SCM_UNDEFINED));
+}
+
+
+/* String conversion to/from C. */
+
SCM
scm_from_stringn (const char *str, size_t len, const char *encoding,
scm_t_string_failed_conversion_handler handler)
@@ -1473,9 +1491,8 @@ scm_from_stringn (const char *str, size_t len, const char *encoding,
memcpy (buf, str, len);
bv = scm_c_take_bytevector (buf, len);
- scm_encoding_error (__func__, errno,
- "input locale conversion error",
- encoding, "UTF-32", bv);
+ scm_decoding_error (__func__, errno,
+ "input locale conversion error", bv);
}
i = 0;