Issue #351 - Prevent compiled warnings on clang

Cleaned up code to prevent compiler warnings with respect to comparing uint8 with EOF (IE, -1).
This commit is contained in:
Justin Ethier 2021-07-15 19:20:47 -07:00
parent 92aeec6a2e
commit d9d1b35a62
2 changed files with 8 additions and 8 deletions

View file

@ -7,6 +7,7 @@ Bug Fixes
- Fix `read-line` to prevent data loss when used in conjunction with other I/O functions (such as `read-char`) to read from the same port. Previous versions of `read-line` would use a different internal buffer than our other I/O functions. - Fix `read-line` to prevent data loss when used in conjunction with other I/O functions (such as `read-char`) to read from the same port. Previous versions of `read-line` would use a different internal buffer than our other I/O functions.
- Properly handle literal vectors at the top level of compiled code. - Properly handle literal vectors at the top level of compiled code.
- Properly escape C strings in compiled code to avoid trigraphs. - Properly escape C strings in compiled code to avoid trigraphs.
- Eliminate clang compiler warnings referencing `EOF` when building the runtime.
## 0.30.0 - July 2, 2021 ## 0.30.0 - July 2, 2021

View file

@ -7796,12 +7796,12 @@ object Cyc_io_peek_char(void *data, object cont, object port)
buf[0] = c; buf[0] = c;
i = 1; i = 1;
while (i < 5) { // TODO: limit to 4 chars?? while (i < 5) {
if (p->mem_buf_len == p->buf_idx + i) { if (p->mem_buf_len == p->buf_idx + i) {
// No more buffered chars // No more buffered chars
at_mem_buf_end = 1; at_mem_buf_end = 1;
c = fgetc(stream); c = fgetc(stream);
if (c == EOF) break; // TODO: correct to do this here???? if (c == EOF) break;
} else { } else {
c = p->mem_buf[p->buf_idx + i]; c = p->mem_buf[p->buf_idx + i];
} }
@ -7840,7 +7840,7 @@ object Cyc_io_peek_u8(void *data, object cont, object port)
_read_next_char(data, cont, p); _read_next_char(data, cont, p);
} }
c = p->mem_buf[p->buf_idx]; c = p->mem_buf[p->buf_idx];
return_thread_runnable_with_obj(data, (c != EOF) ? obj_int2obj(c) : Cyc_EOF, p); return_thread_runnable_with_obj(data, obj_int2obj(c), p);
} }
return Cyc_EOF; return Cyc_EOF;
} }
@ -7860,11 +7860,9 @@ object Cyc_io_read_char(void *data, object cont, object port)
do { do {
_read_next_char(data, cont, p); _read_next_char(data, cont, p);
c = p->mem_buf[p->buf_idx++]; c = p->mem_buf[p->buf_idx++];
if (c == EOF) break;
} while(Cyc_utf8_decode(&state, &codepoint, (uint8_t)c)); } while(Cyc_utf8_decode(&state, &codepoint, (uint8_t)c));
// TODO: limit above to 4 chars and then thrown an error?
p->col_num++; p->col_num++;
return_thread_runnable_with_obj(data, (c != EOF) ? obj_char2obj(codepoint) : Cyc_EOF, p); return_thread_runnable_with_obj(data, obj_char2obj(codepoint), p);
} }
return Cyc_EOF; return Cyc_EOF;
} }
@ -7882,7 +7880,7 @@ object Cyc_io_read_u8(void *data, object cont, object port)
_read_next_char(data, cont, p); _read_next_char(data, cont, p);
c = p->mem_buf[p->buf_idx++]; c = p->mem_buf[p->buf_idx++];
p->col_num++; p->col_num++;
return_thread_runnable_with_obj(data, (c != EOF) ? obj_int2obj(c) : Cyc_EOF, p); return_thread_runnable_with_obj(data, obj_int2obj(c), p);
} }
return Cyc_EOF; return Cyc_EOF;
} }
@ -7905,7 +7903,8 @@ object Cyc_io_read_line_slow(void *data, object cont, object port)
p = (port_type *)port; p = (port_type *)port;
for (i = 0; i < limit; i++) { for (i = 0; i < limit; i++) {
//_read_next_char(data, NULL, p); // Can't use this because it bails on EOF: _read_next_char(data, NULL, p);
// instead we use code based on that macro:
if (p->mem_buf_len == 0 || p->mem_buf_len == p->buf_idx) { if (p->mem_buf_len == 0 || p->mem_buf_len == p->buf_idx) {
int rv = read_from_port(p); int rv = read_from_port(p);
if (!rv) { if (!rv) {