Invalid charset at EOF does not cause decoding error
authorAndy Wingo <wingo@pobox.com>
Wed, 3 Mar 2021 15:05:07 +0000 (16:05 +0100)
committerAndy Wingo <wingo@pobox.com>
Wed, 3 Mar 2021 15:22:56 +0000 (16:22 +0100)
* libguile/ports.c (peek_iconv_codepoint): If the input has no bytes,
there's little point in raising a decoding error here.  Therefore remove
the needless iconv acquisition, harmonising with suspendable-ports.
* test-suite/tests/ports.test ("port-encoding"): Update test to include
some input so that the exception gets raised.

libguile/ports.c
test-suite/tests/ports.test

index 65823f9d7be8baa59aa84ccf07448cd62c270b08..c25c2070928ecca387dda5a3b28b85026f56cd0a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright 1995-2001,2003-2004,2006-2019
+/* Copyright 1995-2001,2003-2004,2006-2019,2021
      Free Software Foundation, Inc.
 
    This file is part of Guile.
@@ -1948,14 +1948,7 @@ peek_iconv_codepoint (SCM port, SCM *buf, size_t *cur, size_t *len)
           *len = input_size;
           if (input_size == 0)
             /* Normal EOF.  */
-            {
-              /* Make sure iconv descriptors have been opened even if
-                 there were no bytes, to be sure that a decoding error
-                 is signalled if the encoding itself was invalid.  */
-              scm_port_acquire_iconv_descriptors (port, NULL, NULL);
-              scm_port_release_iconv_descriptors (port);
-              return EOF;
-            }
+            return EOF;
 
           /* EOF found in the middle of a multibyte character. */
           if (scm_is_eq (SCM_PORT (port)->conversion_strategy,
index 9aa486e98c7804790b2a89c154ff1adf1023f84a..cd87640abc51b066c347a4540a8cbc7954072395 100644 (file)
 
   (pass-if-exception "set-port-encoding!, wrong encoding"
     exception:miscellaneous-error
-    (let ((p (open-input-string "")))
+    (let ((p (open-input-string "q")))
       (set-port-encoding! p "does-not-exist")
       (read p)))