From eaacbf635e71b8d18491affc7e5dc0067bdef2cd Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 3 Sep 2004 02:53:50 +0000 Subject: [PATCH] fix signed -vs- unsigned issue; chars > 127 were being read incorrectly in cfactor --- native/factor.h | 3 +++ native/io.c | 2 +- native/memory.h | 8 ++++---- native/read.c | 4 ++-- native/string.c | 6 +++--- native/string.h | 4 ++-- native/write.c | 8 ++++---- native/write.h | 2 +- 8 files changed, 20 insertions(+), 17 deletions(-) diff --git a/native/factor.h b/native/factor.h index 424c6d5e98..02ce59703d 100644 --- a/native/factor.h +++ b/native/factor.h @@ -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) diff --git a/native/io.c b/native/io.c index af153e3c83..dd1831c187 100644 --- a/native/io.c +++ b/native/io.c @@ -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; } diff --git a/native/memory.h b/native/memory.h index bcbbf018a2..74a2ead409 100644 --- a/native/memory.h +++ b/native/memory.h @@ -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); diff --git a/native/read.c b/native/read.c index 5430798896..35abaa101d 100644 --- a/native/read.c +++ b/native/read.c @@ -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); diff --git a/native/string.c b/native/string.c index 17b5ce72d6..c116430104 100644 --- a/native/string.c +++ b/native/string.c @@ -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); diff --git a/native/string.h b/native/string.h index fa3ebae962..308cd69dfc 100644 --- a/native/string.h +++ b/native/string.h @@ -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) diff --git a/native/write.c b/native/write.c index c918a9adc0..84e6c7dd28 100644 --- a/native/write.c +++ b/native/write.c @@ -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); diff --git a/native/write.h b/native/write.h index f11ddea0ef..a42bb2cf71 100644 --- a/native/write.h +++ b/native/write.h @@ -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);