This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Sign of uniform-vector of characters


   Date: Wed, 4 Mar 1998 09:21:54 +0100
   From: Ole Myren R|hne <o.m.rohne@fys.uio.no>
   Content-Type: text/plain; charset=iso-8859-1
   X-Mime-Autoconverted: from quoted-printable to 8bit by cygnus.com id AAA20829
   Sender: owner-guile@cygnus.com
   Precedence: bulk
   X-UIDL: aae12e62ff9795baff5b2d3b7f6c457d

   I am puzzled by the sign of characters in guile-core-980123:

   In ordinary vectors, characters are unsigned:

   guile> (define v (make-vector 1 #\a))
   guile> (vector-set! v 0 (integer->char 128))
   guile> (vector-ref v 0)
   #\200

   In uniform vectors, characters appear to be signed:

   guile> (define v (make-uniform-vector 1 #\a))
   guile> (uniform-vector-set! v 0 (integer->char 128))
   guile> (uniform-vector-ref v 0)
   #\-200

   I would prefer that characters are always unsigned. Signed characters
   does not have a valid read syntax:

   guile> #\-200
   ERROR: In procedure -200:
   ERROR: unknown # object: #\
   ABORT: (misc-error)


   Sorry if this has already been discussed and/or corrected!

	   Regards,

	   Ole Myren Røhne

SCM had this problem.  Here is the SCM patch:


Return-Path: <amu@media.mit.edu>
Date: Mon, 9 Feb 1998 10:20:13 -0500
From: amu@mit.edu
To: jaffer@ai.mit.edu
Cc: yenta-devo@media.mit.edu
Subject: Don't mix (possibly signed) chars and EOF!
X-UIDL: 4cfd141bad714208558d5a0eaf194fc6

I found two places where SCM uses a possibly signed type for
characters in a stream and risks confusing '\377' (a legitimate
character) with EOF (-1).  The following patch addresses this problem,
and should make SCM's streams completely 8-bit clean:

--- scm.h~	Thu Nov 13 17:22:22 1997
+++ scm.h	Wed Feb  4 18:01:12 1998
@@ -273,7 +273,7 @@
 #define SETSTREAM SETCDR
 #define CRDYP(port) (CAR(port) & CRDY)
 #define CLRDY(port) {CAR(port) &= CUC;}
-#define CGETUN(port) ((int)SRS(CAR(port), 22))
+#define CGETUN(port) ((unsigned char)SRS(CAR(port), 22))
 #define CUNGET(c, port) {CAR(port) += ((long)c<<22) + CRDY;}
 
 #define tc_socket (tc7_port | OPN)
--- sys.c~	Wed Dec 10 16:43:15 1997
+++ sys.c	Wed Feb  4 18:32:48 1998
@@ -337,7 +337,7 @@
   sizet ind = INUM(CAR(p));
   if (ind >= LENGTH(CDR(p))) return EOF;
   CAR(p) = MAKINUM(ind + 1);
-  return CHARS(CDR(p))[ind];
+  return UCHARS(CDR(p))[ind];
 }
 int noop0(stream)
      FILE *stream;