~ chicken-core (master) 3cff0992e24da18058b91a81606e24393ad1732a
commit 3cff0992e24da18058b91a81606e24393ad1732a
Author: felix <felix@call-with-current-continuation.org>
AuthorDate: Mon Oct 5 17:08:10 2026 +0200
Commit: felix <felix@call-with-current-continuation.org>
CommitDate: Mon Oct 5 17:08:10 2026 +0200
throw error when encoding stirng into latin1 and character is not in range
diff --git a/chicken.h b/chicken.h
index 61102149..624f151a 100644
--- a/chicken.h
+++ b/chicken.h
@@ -653,7 +653,8 @@ void *alloca ();
#define C_BAD_ARGUMENT_TYPE_COMPLEX_ABS 55
#define C_REST_ARG_OUT_OF_BOUNDS_ERROR 56
#define C_DECODING_ERROR 57
-#define C_BAD_ARGUMENT_TYPE_NUMERIC_RANGE_ERROR 58
+#define C_ENCODING_ERROR 58
+#define C_BAD_ARGUMENT_TYPE_NUMERIC_RANGE_ERROR 59
/* Platform information */
#if defined(C_BIG_ENDIAN)
@@ -1866,6 +1867,7 @@ C_fctexport void C_save_and_reclaim_args(void *trampoline, int n, ...) C_noret;
C_fctexport void C_rereclaim2(C_uword size, int relative_resize) C_regparm;
C_fctexport void C_unbound_variable(C_word sym);
C_fctexport void C_decoding_error(C_word str, C_word index);
+C_fctexport void C_encoding_error(C_word bv, C_word index);
C_fctexport C_word C_retrieve2(C_word val, char *name) C_regparm;
C_fctexport void *C_retrieve2_symbol_proc(C_word val, char *name) C_regparm;
C_fctexport int C_in_stackp(C_word x) C_regparm;
diff --git a/library.scm b/library.scm
index 3588715c..8400fda5 100644
--- a/library.scm
+++ b/library.scm
@@ -6771,7 +6771,8 @@ EOF
" but rest list length is " (##sys#number->string c) )
(if fn (list fn) '()))))
((57) (apply ##sys#signal-hook #:type-error loc "string contains invalid UTF-8 sequence" args))
- ((58) (apply ##sys#signal-hook #:type-error loc "bad argument type - numeric value exceeds range" args))
+ ((58) (apply ##sys#signal-hook #:type-error loc "string contains un-encodable character" args))
+ ((59) (apply ##sys#signal-hook #:type-error loc "bad argument type - numeric value exceeds range" args))
(else (apply ##sys#signal-hook #:runtime-error loc "unknown internal error" args)) ) ) ) )
) ; chicken.condition
diff --git a/runtime.c b/runtime.c
index efa5772d..a62f2297 100644
--- a/runtime.c
+++ b/runtime.c
@@ -1982,6 +1982,11 @@ void barf(int code, char *loc, ...)
c = 2;
break;
+ case C_ENCODING_ERROR:
+ msg = C_text("string contains unencodable character");
+ c = 2;
+ break;
+
case C_BAD_ARGUMENT_TYPE_NUMERIC_RANGE_ERROR:
msg = C_text("bad argument type - value exceeds numeric range");
c = 1;
@@ -4223,6 +4228,13 @@ C_decoding_error(C_word str, C_word index)
}
+void
+C_encoding_error(C_word bv, C_word index)
+{
+ barf(C_ENCODING_ERROR, NULL, bv, index);
+}
+
+
/* XXX: This needs to be given a better name.
C_retrieve used to exist but it just called C_fast_retrieve */
C_regparm C_word C_retrieve2(C_word val, char *name)
diff --git a/utf.c b/utf.c
index 02526940..b52c7227 100644
--- a/utf.c
+++ b/utf.c
@@ -659,6 +659,7 @@ C_regparm C_word C_utf_to_latin(C_word from, C_word to, C_word start, C_word ble
int e;
while(n > 0) {
pf2 = utf8_decode(pf, &c, &e);
+ if(c > 255) C_encoding_error(from, C_fix(C_unfix(start) + C_unfix(blen) - n));
n -= pf2 - pf;
pf = pf2;
*(pt++) = c & 0xff;
Trap