]> gitweb.factorcode.org Git - factor.git/commitdiff
fix signed -vs- unsigned issue; chars > 127 were being read incorrectly in cfactor
authorSlava Pestov <slava@factorcode.org>
Fri, 3 Sep 2004 02:53:50 +0000 (02:53 +0000)
committerSlava Pestov <slava@factorcode.org>
Fri, 3 Sep 2004 02:53:50 +0000 (02:53 +0000)
native/factor.h
native/io.c
native/memory.h
native/read.c
native/string.c
native/string.h
native/write.c
native/write.h

index 424c6d5e9853485f1f03114eaaeb755c035ad2db..02ce59703dae68b4d7789cf1af7e0c06c225cad8 100644 (file)
@@ -33,6 +33,9 @@ typedef unsigned long int CELL;
 typedef unsigned short CHAR;
 #define CHARS ((signed)sizeof(CHAR))
 
+/* must always be 8 bits */
+typedef unsigned char BYTE;
+
 /* Memory heap size */
 #define DEFAULT_ARENA (5 * 1024 * 1024)
 
index af153e3c83e99bc2467b1eeccd54377dd7d5400e..dd1831c1874efc291881f4131bdf757302d7a56f 100644 (file)
@@ -92,7 +92,7 @@ bool perform_copy_from_io_task(PORT* port, PORT* other_port)
        if(can_write(other_port,port->buf_fill))
        {
                write_string_raw(other_port,
-                       (char*)(port->buffer + 1),
+                       (BYTE*)(port->buffer + 1),
                        port->buf_fill);
                port->buf_pos = port->buf_fill = 0;
        }
index bcbbf018a2f755b5f3a39053f88004e7fa3deaae..74a2ead4092c8baf24d6df082ec9f8503846d233 100644 (file)
@@ -55,14 +55,14 @@ INLINE void cput(CELL where, CHAR what)
        *((CHAR*)where) = what;
 }
 
-INLINE char bget(CELL where)
+INLINE BYTE bget(CELL where)
 {
-       return *((char*)where);
+       return *((BYTE*)where);
 }
 
-INLINE void bput(CELL where, char what)
+INLINE void bput(CELL where, BYTE what)
 {
-       *((char*)where) = what;
+       *((BYTE*)where) = what;
 }
 
 bool in_zone(ZONE* z, CELL pointer);
index 5430798896e4e1717ccb77f491034a7e526ccc5c..35abaa101db46e3bf9f560b0e31db5ff58bd4ac9 100644 (file)
@@ -42,7 +42,7 @@ bool read_step(PORT* port)
 bool read_line_step(PORT* port)
 {
        int i;
-       char ch;
+       BYTE ch;
 
        SBUF* line = untag_sbuf(port->line);
 
@@ -158,7 +158,7 @@ void primitive_read_line_8(void)
 bool read_count_step(PORT* port)
 {
        int i;
-       char ch;
+       BYTE ch;
 
        SBUF* line = untag_sbuf(port->line);
 
index 17b5ce72d65353b3018169a20b540af2ba343c5d..c1164301045abaed1f42b43ae3110f8a78c13d0f 100644 (file)
@@ -54,7 +54,7 @@ STRING* grow_string(STRING* string, FIXNUM capacity, CHAR fill)
 }
 
 /* untagged */
-STRING* from_c_string(const char* c_string)
+STRING* from_c_string(const BYTE* c_string)
 {
        CELL length = strlen(c_string);
        STRING* s = allot_string(length);
@@ -72,12 +72,12 @@ STRING* from_c_string(const char* c_string)
 }
 
 /* untagged */
-char* to_c_string(STRING* s)
+BYTE* to_c_string(STRING* s)
 {
        STRING* _c_str = allot_string(s->capacity / CHARS + 1);
        CELL i;
 
-       char* c_str = (char*)(_c_str + 1);
+       BYTE* c_str = (BYTE*)(_c_str + 1);
        
        for(i = 0; i < s->capacity; i++)
                c_str[i] = string_nth(s,i);
index fa3ebae962c6a21eb49b3b2a2250fb945a1847e4..308cd69dfc0dd5aab37fe3c6d50185ea7a35813b 100644 (file)
@@ -16,8 +16,8 @@ STRING* allot_string(FIXNUM capacity);
 STRING* string(FIXNUM capacity, CELL fill);
 void hash_string(STRING* str);
 STRING* grow_string(STRING* string, FIXNUM capacity, CHAR fill);
-char* to_c_string(STRING* s);
-STRING* from_c_string(const char* c_string);
+BYTE* to_c_string(STRING* s);
+STRING* from_c_string(const BYTE* c_string);
 
 #define SREF(string,index) ((CELL)string + sizeof(STRING) + index * CHARS)
 
index c918a9adc0b6d13e13d4f9c96776c01cf3743a47..84e6c7dd2840e3f6d2c2345dfff0b2d6afe3718b 100644 (file)
@@ -3,7 +3,7 @@
 /* Return true if write was done */
 void write_step(PORT* port)
 {
-       char* chars = (char*)port->buffer + sizeof(STRING);
+       BYTE* chars = (BYTE*)port->buffer + sizeof(STRING);
 
        FIXNUM amount = write(port->fd,chars + port->buf_pos,
                port->buf_fill - port->buf_pos);
@@ -70,7 +70,7 @@ bool perform_write_io_task(PORT* port)
 
 void write_char_8(PORT* port, FIXNUM ch)
 {
-       char c = (char)ch;
+       BYTE c = (BYTE)ch;
 
        pending_io_error(port);
 
@@ -82,7 +82,7 @@ void write_char_8(PORT* port, FIXNUM ch)
 }
 
 /* Caller must ensure buffer is of the right size. */
-void write_string_raw(PORT* port, char* str, CELL len)
+void write_string_raw(PORT* port, BYTE* str, CELL len)
 {
        /* Append string to buffer */
        memcpy((void*)((CELL)port->buffer + sizeof(STRING)
@@ -93,7 +93,7 @@ void write_string_raw(PORT* port, char* str, CELL len)
 
 void write_string_8(PORT* port, STRING* str)
 {
-       char* c_str;
+       BYTE* c_str;
        
        pending_io_error(port);
 
index f11ddea0ef08b86634f5119f7106413d4c87af42..a42bb2cf71899034aa26b90024cf8c36bdf51261 100644 (file)
@@ -4,6 +4,6 @@ void primitive_can_write(void);
 void primitive_add_write_io_task(void);
 bool perform_write_io_task(PORT* port);
 void write_char_8(PORT* port, FIXNUM ch);
-void write_string_raw(PORT* port, char* str, CELL len);
+void write_string_raw(PORT* port, BYTE* str, CELL len);
 void write_string_8(PORT* port, STRING* str);
 void primitive_write_8(void);