guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] GNU Guile branch, master, updated. release_1-9-15-40-gc2


From: Ludovic Courtès
Subject: [Guile-commits] GNU Guile branch, master, updated. release_1-9-15-40-gc2c550c
Date: Thu, 10 Feb 2011 22:05:06 +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=c2c550ca9d2442d070f79ed8bacb8db173c72df3

The branch, master has been updated
       via  c2c550ca9d2442d070f79ed8bacb8db173c72df3 (commit)
       via  9d9c66ba82217a3c96febda51cc9ddbb5f8ce3e3 (commit)
       via  064c27c4ef8987218e01a2a7dd9c51c9c88ef50b (commit)
       via  fe949e7bc69bb72610b8eeafcfbb0754b2c0db32 (commit)
      from  0bc86fcedcd19a1a388faa6505f822d57a30584c (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 c2c550ca9d2442d070f79ed8bacb8db173c72df3
Author: Ludovic Courtès <address@hidden>
Date:   Thu Feb 10 22:56:37 2011 +0100

    "latin1" -> "Latin-1".
    
    Reported by Ralf Wildenhues.
    
    * doc/ref/vm.texi (Loading Instructions): Use "Latin-1", not "latin1".

commit 9d9c66ba82217a3c96febda51cc9ddbb5f8ce3e3
Author: Ludovic Courtès <address@hidden>
Date:   Thu Feb 10 22:50:51 2011 +0100

    Add `scm_i_set_default_port_encoding' and `scm_i_default_port_encoding'.
    
    * libguile/ports.c (scm_i_set_default_port_encoding,
      scm_i_default_port_encoding): New function.  Replace
      `scm_i_set_port_encoding_x' and `scm_i_get_port_encoding' with
      PORT == SCM_BOOL_F.
      (scm_i_set_port_encoding_x): Assume PORT is a port.
      (scm_i_get_port_encoding): Remove.
      (scm_port_encoding): Adjust accordingly.
      (scm_new_port_table_entry): Use `scm_i_default_port_encoding'.
    
    * libguile/ports.h (scm_i_get_port_encoding): Remove declarations.
      (scm_i_default_port_encoding, scm_i_set_default_port_encoding): New
      declarations.
    
    * libguile/posix.c (setlocale): Use `scm_i_set_default_port_encoding'.

commit 064c27c4ef8987218e01a2a7dd9c51c9c88ef50b
Author: Ludovic Courtès <address@hidden>
Date:   Thu Feb 10 22:27:37 2011 +0100

    Simplify `scm_i_set_port_encoding_x'.
    
    * libguile/ports.c (find_valid_encoding): Remove.
      (scm_i_set_port_encoding_x): Remove call to `find_valid_encoding'.
      Remove `valid_enc'.  Rename `enc' to `encoding'.
    
    * test-suite/tests/ports.test ("port-encoding"): New test prefix.

commit fe949e7bc69bb72610b8eeafcfbb0754b2c0db32
Author: Ludovic Courtès <address@hidden>
Date:   Thu Feb 10 23:01:34 2011 +0100

    Add `read-delimited' tests.
    
    * test-suite/tests/rdelim.test ("read-delimited", "read-delimited!"):
      New test prefixes.

-----------------------------------------------------------------------

Summary of changes:
 doc/ref/vm.texi              |    6 +-
 libguile/ports.c             |  189 ++++++++++++++++--------------------------
 libguile/ports.h             |    3 +-
 libguile/posix.c             |    4 +-
 test-suite/tests/ports.test  |   11 +++
 test-suite/tests/rdelim.test |  100 ++++++++++++++++++++++-
 6 files changed, 189 insertions(+), 124 deletions(-)

diff --git a/doc/ref/vm.texi b/doc/ref/vm.texi
index 1f82704..0bb9f80 100644
--- a/doc/ref/vm.texi
+++ b/doc/ref/vm.texi
@@ -1,6 +1,6 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Guile Reference Manual.
address@hidden Copyright (C)  2008,2009,2010
address@hidden Copyright (C)  2008, 2009, 2010, 2011
 @c   Free Software Foundation, Inc.
 @c See the file guile.texi for copying conditions.
 
@@ -1063,7 +1063,7 @@ embedded in the stream as a string.
 @end deffn
 @deffn Instruction load-string length
 Load a string from the instruction stream. The string is assumed to be
-encoded in the ``latin1'' locale.
+Latin-1-encoded.
 @end deffn
 @deffn Instruction load-wide-string length
 Load a UTF-32 string from the instruction stream. @var{length} is the
@@ -1071,7 +1071,7 @@ length in bytes, not in codepoints.
 @end deffn
 @deffn Instruction load-symbol length
 Load a symbol from the instruction stream. The symbol is assumed to be
-encoded in the ``latin1'' locale. Symbols backed by wide strings may
+Latin-1-encoded. Symbols backed by wide strings may
 be loaded via @code{load-wide-string} then @code{make-symbol}.
 @end deffn
 @deffn Instruction load-array length
diff --git a/libguile/ports.c b/libguile/ports.c
index 270071c..1da6a83 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -598,12 +598,11 @@ scm_new_port_table_entry (scm_t_bits tag)
   entry->file_name = SCM_BOOL_F;
   entry->rw_active = SCM_PORT_NEITHER;
   entry->port = z;
+
   /* Initialize this port with the thread's current default
      encoding.  */
-  if ((enc = scm_i_get_port_encoding (SCM_BOOL_F)) == NULL)
-    entry->encoding = NULL;
-  else
-    entry->encoding = scm_gc_strdup (enc, "port");
+  enc = scm_i_default_port_encoding ();
+  entry->encoding = enc ? scm_gc_strdup (enc, "port") : NULL;
 
   /* The conversion descriptors will be opened lazily.  */
   entry->input_cd = (iconv_t) -1;
@@ -1970,148 +1969,102 @@ SCM_VARIABLE (default_port_encoding_var, 
"%default-port-encoding");
 
 static int scm_port_encoding_init = 0;
 
-/* Return a C string representation of the current encoding.  */
+/* Use ENCODING as the default encoding for future ports.  */
+void
+scm_i_set_default_port_encoding (const char *encoding)
+{
+  if (!scm_port_encoding_init
+      || !scm_is_fluid (SCM_VARIABLE_REF (default_port_encoding_var)))
+    scm_misc_error (NULL, "tried to set port encoding fluid before it is 
initialized",
+                   SCM_EOL);
+
+  if (encoding == NULL
+      || !strcmp (encoding, "ASCII")
+      || !strcmp (encoding, "ANSI_X3.4-1968")
+      || !strcmp (encoding, "ISO-8859-1"))
+    scm_fluid_set_x (SCM_VARIABLE_REF (default_port_encoding_var), SCM_BOOL_F);
+  else
+    scm_fluid_set_x (SCM_VARIABLE_REF (default_port_encoding_var),
+                    scm_from_locale_string (encoding));
+}
+
+/* Return the name of the default encoding for newly created ports; a
+   return value of NULL means "ISO-8859-1".  */
 const char *
-scm_i_get_port_encoding (SCM port)
+scm_i_default_port_encoding (void)
 {
-  SCM encoding;
-  
-  if (scm_is_false (port))
+  if (!scm_port_encoding_init)
+    return NULL;
+  else if (!scm_is_fluid (SCM_VARIABLE_REF (default_port_encoding_var)))
+    return NULL;
+  else
     {
-      if (!scm_port_encoding_init)
-       return NULL;
-      else if (!scm_is_fluid (SCM_VARIABLE_REF (default_port_encoding_var)))
+      SCM encoding;
+
+      encoding = scm_fluid_ref (SCM_VARIABLE_REF (default_port_encoding_var));
+      if (!scm_is_string (encoding))
        return NULL;
       else
-       {
-         encoding = scm_fluid_ref (SCM_VARIABLE_REF 
(default_port_encoding_var));
-         if (!scm_is_string (encoding))
-           return NULL;
-         else
-           return scm_i_string_chars (encoding);
-       }
-    }
-  else
-    {
-      scm_t_port *pt;
-      pt = SCM_PTAB_ENTRY (port);
-      return pt->encoding;
+       return scm_i_string_chars (encoding);
     }
 }
 
-/* Returns ENC if it is a recognized encoding.  If it isn't, it tries
-   to find an alias of ENC that is valid.  Otherwise, it returns
-   NULL.  */
-static const char *
-find_valid_encoding (const char *enc)
+void
+scm_i_set_port_encoding_x (SCM port, const char *encoding)
 {
-  int isvalid = 0;
-  const char str[] = " ";
-  scm_t_uint32 result_buf;
-  scm_t_uint32 *u32;
-  size_t u32len;
-
-  u32len = sizeof (result_buf) / sizeof (scm_t_uint32);
-  u32 = u32_conv_from_encoding (enc, iconveh_error, str, 1,
-                                NULL, &result_buf, &u32len);
-  isvalid = (u32 != NULL);
+  scm_t_port *pt;
+  iconv_t new_input_cd, new_output_cd;
 
-  if (SCM_UNLIKELY (u32 != &result_buf))
-    free (u32);
+  new_input_cd = (iconv_t) -1;
+  new_output_cd = (iconv_t) -1;
 
-  if (isvalid)
-    return enc;
+  /* Set the character encoding for this port.  */
+  pt = SCM_PTAB_ENTRY (port);
 
-  return NULL;
-}
+  if (encoding == NULL)
+    encoding = "ISO-8859-1";
 
-void
-scm_i_set_port_encoding_x (SCM port, const char *enc)
-{
-  const char *valid_enc;
-  scm_t_port *pt;
+  pt->encoding = scm_gc_strdup (encoding, "port");
 
-  /* Null is shorthand for the native, Latin-1 encoding.  */
-  if (enc == NULL)
-    valid_enc = NULL;
-  else
+  if (SCM_CELL_WORD_0 (port) & SCM_RDNG)
     {
-      valid_enc = find_valid_encoding (enc);
-      if (valid_enc == NULL)
+      /* Open an input iconv conversion descriptor, from ENCODING
+        to UTF-8.  We choose UTF-8, not UTF-32, because iconv
+        implementations can typically convert from anything to
+        UTF-8, but not to UTF-32 (see
+        
<http://lists.gnu.org/archive/html/bug-libunistring/2010-09/msg00007.html>).  */
+      new_input_cd = iconv_open ("UTF-8", encoding);
+      if (new_input_cd == (iconv_t) -1)
        goto invalid_encoding;
     }
 
-  if (scm_is_false (port))
+  if (SCM_CELL_WORD_0 (port) & SCM_WRTNG)
     {
-      /* Set the default encoding for future ports.  */
-      if (!scm_port_encoding_init
-         || !scm_is_fluid (SCM_VARIABLE_REF (default_port_encoding_var)))
-       scm_misc_error (NULL, "tried to set port encoding fluid before it is 
initialized",
-                       SCM_EOL);
-
-      if (valid_enc == NULL 
-          || !strcmp (valid_enc, "ASCII")
-          || !strcmp (valid_enc, "ANSI_X3.4-1968")
-          || !strcmp (valid_enc, "ISO-8859-1"))
-        scm_fluid_set_x (SCM_VARIABLE_REF (default_port_encoding_var), 
SCM_BOOL_F);
-      else
-        scm_fluid_set_x (SCM_VARIABLE_REF (default_port_encoding_var), 
-                         scm_from_locale_string (valid_enc));
-    }
-  else
-    {
-      iconv_t new_input_cd, new_output_cd;
-
-      new_input_cd = (iconv_t) -1;
-      new_output_cd = (iconv_t) -1;
-
-      /* Set the character encoding for this port.  */
-      pt = SCM_PTAB_ENTRY (port);
-
-      if (valid_enc == NULL)
-       valid_enc = "ISO-8859-1";
-
-      pt->encoding = scm_gc_strdup (valid_enc, "port");
-
-      if (SCM_CELL_WORD_0 (port) & SCM_RDNG)
+      new_output_cd = iconv_open (encoding, "UTF-8");
+      if (new_output_cd == (iconv_t) -1)
        {
-         /* Open an input iconv conversion descriptor, from VALID_ENC
-            to UTF-8.  We choose UTF-8, not UTF-32, because iconv
-            implementations can typically convert from anything to
-            UTF-8, but not to UTF-32 (see
-            
<http://lists.gnu.org/archive/html/bug-libunistring/2010-09/msg00007.html>).  */
-         new_input_cd = iconv_open ("UTF-8", valid_enc);
-         if (new_input_cd == (iconv_t) -1)
-           goto invalid_encoding;
-       }
-
-      if (SCM_CELL_WORD_0 (port) & SCM_WRTNG)
-       {
-         new_output_cd = iconv_open (valid_enc, "UTF-8");
-         if (new_output_cd == (iconv_t) -1)
-           {
-             if (new_input_cd != (iconv_t) -1)
-               iconv_close (new_input_cd);
-             goto invalid_encoding;
-           }
+         if (new_input_cd != (iconv_t) -1)
+           iconv_close (new_input_cd);
+         goto invalid_encoding;
        }
+    }
 
-      if (pt->input_cd != (iconv_t) -1)
-       iconv_close (pt->input_cd);
-      if (pt->output_cd != (iconv_t) -1)
-       iconv_close (pt->output_cd);
+  if (pt->input_cd != (iconv_t) -1)
+    iconv_close (pt->input_cd);
+  if (pt->output_cd != (iconv_t) -1)
+    iconv_close (pt->output_cd);
 
-      pt->input_cd = new_input_cd;
-      pt->output_cd = new_output_cd;
-    }
+  pt->input_cd = new_input_cd;
+  pt->output_cd = new_output_cd;
 
   return;
 
  invalid_encoding:
   {
     SCM err;
-    err = scm_from_locale_string (enc);
-    scm_misc_error (NULL, "invalid or unknown character encoding ~s",
+    err = scm_from_locale_string (encoding);
+    scm_misc_error ("scm_i_set_port_encoding_x",
+                   "invalid or unknown character encoding ~s",
                    scm_list_1 (err));
   }
 }
@@ -2128,7 +2081,7 @@ SCM_DEFINE (scm_port_encoding, "port-encoding", 1, 0, 0,
   SCM_VALIDATE_PORT (1, port);
 
   pt = SCM_PTAB_ENTRY (port);
-  enc = scm_i_get_port_encoding (port);
+  enc = pt->encoding;
   if (enc)
     return scm_from_locale_string (pt->encoding);
   else
diff --git a/libguile/ports.h b/libguile/ports.h
index 7408b9b..cc0b987 100644
--- a/libguile/ports.h
+++ b/libguile/ports.h
@@ -298,7 +298,8 @@ SCM_API SCM scm_port_column (SCM port);
 SCM_API SCM scm_set_port_column_x (SCM port, SCM line);
 SCM_API SCM scm_port_filename (SCM port);
 SCM_API SCM scm_set_port_filename_x (SCM port, SCM filename);
-SCM_INTERNAL const char *scm_i_get_port_encoding (SCM port);
+SCM_INTERNAL const char *scm_i_default_port_encoding (void);
+SCM_INTERNAL void scm_i_set_default_port_encoding (const char *);
 SCM_INTERNAL void scm_i_set_port_encoding_x (SCM port, const char *str);
 SCM_API SCM scm_port_encoding (SCM port);
 SCM_API SCM scm_set_port_encoding_x (SCM port, SCM encoding);
diff --git a/libguile/posix.c b/libguile/posix.c
index 939e248..97e30df 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1631,8 +1631,10 @@ SCM_DEFINE (scm_setlocale, "setlocale", 1, 1, 0,
     }
 
   enc = locale_charset ();
+
   /* Set the default encoding for new ports.  */
-  scm_i_set_port_encoding_x (SCM_BOOL_F, enc);
+  scm_i_set_default_port_encoding (enc);
+
   /* Set the encoding for the stdio ports.  */
   scm_i_set_port_encoding_x (scm_current_input_port (), enc);
   scm_i_set_port_encoding_x (scm_current_output_port (), enc);
diff --git a/test-suite/tests/ports.test b/test-suite/tests/ports.test
index 3104ca1..72b58ae 100644
--- a/test-suite/tests/ports.test
+++ b/test-suite/tests/ports.test
@@ -783,6 +783,17 @@
       (set-port-line! port n)
       (eqv? n (port-line port)))))
 
+(with-test-prefix "port-encoding"
+
+  (pass-if-exception "set-port-encoding!, wrong encoding"
+    exception:miscellaneous-error
+    (set-port-encoding! (open-input-string "") "does-not-exist"))
+
+  (pass-if-exception "%default-port-encoding, wrong encoding"
+    exception:miscellaneous-error
+    (read (with-fluids ((%default-port-encoding "does-not-exist"))
+            (open-input-string "")))))
+
 ;;;
 ;;; port-for-each
 ;;;
diff --git a/test-suite/tests/rdelim.test b/test-suite/tests/rdelim.test
index dd81dc9..f827f62 100644
--- a/test-suite/tests/rdelim.test
+++ b/test-suite/tests/rdelim.test
@@ -91,7 +91,105 @@
                  (open-bytevector-input-port #vu8(65 255 66 67 68)))))
         (set-port-conversion-strategy! p 'substitute)
         (and (string=? (read-line p) "A?BCD")
-             (eof-object? (read-line p)))))))
+             (eof-object? (read-line p))))))
+
+
+  (with-test-prefix "read-delimited"
+
+    (pass-if "delimiter hit"
+      (let ((p (open-input-string "hello, world!")))
+        (and (string=? "hello" (read-delimited ",.;" p))
+             (string=? " world!" (read-delimited ",.;" p))
+             (eof-object? (read-delimited ",.;" p)))))
+
+    (pass-if "delimiter hit, split"
+      (equal? '("hello" . #\,)
+              (read-delimited ",.;"
+                              (open-input-string "hello, world!")
+                              'split)))
+
+    (pass-if "delimiter hit, concat"
+      (equal? '"hello,"
+              (read-delimited ",.;" (open-input-string "hello, world!")
+                              'concat)))
+
+    (pass-if "delimiter hit, peek"
+      (let ((p (open-input-string "hello, world!")))
+        (and (string=? "hello" (read-delimited ",.;" p 'peek))
+             (char=? #\, (peek-char p)))))
+
+    (pass-if "eof"
+      (eof-object? (read-delimited "}{" (open-input-string "")))))
+
+
+  (with-test-prefix "read-delimited!"
+
+    (pass-if "delimiter hit"
+      (let ((s (make-string 123))
+            (p (open-input-string "hello, world!")))
+        (and (= 5 (read-delimited! ",.;" s p))
+             (string=? (substring s 0 5) "hello")
+             (= 7 (read-delimited! ",.;" s p))
+             (string=? (substring s 0 7) " world!")
+             (eof-object? (read-delimited! ",.;" s p)))))
+
+    (pass-if "delimiter hit, start+end"
+      (let ((s (make-string 123))
+            (p (open-input-string "hello, world!")))
+        (and (= 5 (read-delimited! ",.;" s p 'trim 10 30))
+             (string=? (substring s 10 15) "hello"))))
+
+    (pass-if "delimiter hit, split"
+      (let ((s (make-string 123)))
+        (and (equal? '(5 . #\,)
+                     (read-delimited! ",.;" s
+                                      (open-input-string "hello, world!")
+                                      'split))
+             (string=? (substring s 0 5) "hello"))))
+
+    (pass-if "delimiter hit, concat"
+      (let ((s (make-string 123)))
+        (and (= 6 (read-delimited! ",.;" s
+                                   (open-input-string "hello, world!")
+                                   'concat))
+             (string=? (substring s 0 6) "hello,"))))
+
+    (pass-if "delimiter hit, peek"
+      (let ((s (make-string 123))
+            (p (open-input-string "hello, world!")))
+        (and (= 5 (read-delimited! ",.;" s p 'peek))
+             (string=? (substring s 0 5) "hello")
+             (char=? #\, (peek-char p)))))
+
+    (pass-if "string too small"
+      (let ((s (make-string 7)))
+        (and (= 7 (read-delimited! "}{" s
+                                   (open-input-string "hello, world!")))
+             (string=? s "hello, "))))
+
+    (pass-if "string too small, start+end"
+      (let ((s (make-string 123)))
+        (and (= 7 (read-delimited! "}{" s
+                                   (open-input-string "hello, world!")
+                                   'trim
+                                   70 77))
+             (string=? (substring s 70 77) "hello, "))))
+
+    (pass-if "string too small, split"
+      (let ((s (make-string 7)))
+        (and (equal? '(7 . #f)
+                     (read-delimited! "}{" s
+                                      (open-input-string "hello, world!")
+                                      'split))
+             (string=? s "hello, "))))
+
+    (pass-if "eof"
+      (eof-object? (read-delimited! ":" (make-string 7)
+                                    (open-input-string ""))))
+
+    (pass-if "eof, split"
+      (eof-object? (read-delimited! ":" (make-string 7)
+                                    (open-input-string ""))))))
 
 ;;; Local Variables:
 ;;; eval: (put 'with-test-prefix 'scheme-indent-function 1)


hooks/post-receive
-- 
GNU Guile



reply via email to

[Prev in Thread] Current Thread [Next in Thread]