streams: make ecl_read_byte return OBJNULL on EOF

This is to allow for sequence streams to return arbitrary objects (when
appropriately constructed) without many changes.
This commit is contained in:
Daniel Kochmański 2025-07-22 22:26:31 +02:00
parent 431132e4d1
commit 407fe456fe
6 changed files with 28 additions and 27 deletions

View file

@ -1741,12 +1741,12 @@ do_read_delimited_list(int d, cl_object in, bool proper_list)
cl_object c;
@
c = ecl_read_byte(binary_input_stream);
if (c == ECL_NIL) {
if (c == OBJNULL) {
if (Null(eof_errorp)) {
@(return eof_value);
}
else
FEend_of_file(binary_input_stream);
FEend_of_file(binary_input_stream);
}
@(return c);
@)

View file

@ -258,8 +258,8 @@ cl_object
si_read_byte(cl_object strm, cl_object eof_value)
{
cl_env_ptr the_env = ecl_process_env();
cl_object c = ecl_read_byte(strm);
ecl_return1(the_env, Null(c) ? eof_value : c);
cl_object byte = ecl_read_byte(strm);
ecl_return1(the_env, (byte == OBJNULL) ? eof_value : byte);
}
/* These two interfaces are clearly missing in the ANSI standard. */
@ -277,7 +277,7 @@ si_peek_byte(cl_object strm, cl_object eof_value)
{
cl_env_ptr the_env = ecl_process_env();
cl_object byte = ecl_peek_byte(strm);
ecl_return1(the_env, Null(c) ? eof_value : byte);
ecl_return1(the_env, (byte == OBJNULL) ? eof_value : byte);
}
#endif

View file

@ -46,15 +46,15 @@ clos_stream_write_byte8(cl_object strm, unsigned char *c, cl_index n)
static cl_object
clos_stream_read_byte(cl_object strm)
{
cl_object b = _ecl_funcall2(@'gray::stream-read-byte', strm);
if (b == @':eof') b = ECL_NIL;
return b;
cl_object out = _ecl_funcall2(@'gray::stream-read-byte', strm);
if (out == @':eof') out = OBJNULL;
return out;
}
static void
clos_stream_write_byte(cl_object strm, cl_object c)
clos_stream_write_byte(cl_object strm, cl_object byte)
{
_ecl_funcall3(@'gray::stream-write-byte', strm, c);
_ecl_funcall3(@'gray::stream-write-byte', strm, byte);
}
static ecl_character

View file

@ -304,7 +304,7 @@ ecl_generic_read_byte_unsigned8(cl_object strm)
{
unsigned char c;
if (strm->stream.ops->read_byte8(strm, &c, 1) < 1) {
return ECL_NIL;
return OBJNULL;
}
return ecl_make_fixnum(c);
}
@ -321,7 +321,7 @@ ecl_generic_read_byte_signed8(cl_object strm)
{
signed char c;
if (strm->stream.ops->read_byte8(strm, (unsigned char *)&c, 1) < 1)
return ECL_NIL;
return OBJNULL;
return ecl_make_fixnum(c);
}
@ -344,7 +344,7 @@ ecl_generic_read_byte_le(cl_object strm)
for (nb = 0; bs >= 8; bs -= 8, nb += 8) {
cl_object aux;
if (read_byte8(strm, &c, 1) < 1)
return ECL_NIL;
return OBJNULL;
if (bs <= 8 && (strm->stream.flags & ECL_STREAM_SIGNED_BYTES))
aux = ecl_make_fixnum((signed char)c);
else
@ -376,13 +376,13 @@ ecl_generic_read_byte(cl_object strm)
{
cl_index (*read_byte8)(cl_object, unsigned char *, cl_index);
unsigned char c;
cl_object output = NULL;
cl_object output = OBJNULL;
cl_index bs;
read_byte8 = strm->stream.ops->read_byte8;
bs = strm->stream.byte_size;
for (; bs >= 8; bs -= 8) {
if (read_byte8(strm, &c, 1) < 1)
return ECL_NIL;
return OBJNULL;
if (output) {
output = cl_logior(2, ecl_make_fixnum(c),
cl_ash(output, ecl_make_fixnum(8)));
@ -530,7 +530,7 @@ ecl_generic_read_vector(cl_object strm, cl_object data, cl_index start, cl_index
cl_object (*read_byte)(cl_object) = ops->read_byte;
for (; start < end; start++) {
cl_object x = read_byte(strm);
if (Null(x)) break;
if (x == OBJNULL) break;
ecl_elt_set(data, start, x);
}
}

View file

@ -423,20 +423,21 @@ echo_write_byte8(cl_object strm, unsigned char *c, cl_index n)
return ecl_write_byte8(ECHO_STREAM_OUTPUT(strm), c, n);
}
static cl_object
echo_read_byte(cl_object strm)
{
cl_object byte = ecl_read_byte(ECHO_STREAM_INPUT(strm));
if (byte != OBJNULL)
ecl_write_byte(byte, ECHO_STREAM_OUTPUT(strm));
return byte;
}
static void
echo_write_byte(cl_object strm, cl_object byte)
{
ecl_write_byte(byte, ECHO_STREAM_OUTPUT(strm));
}
static cl_object
echo_read_byte(cl_object strm)
{
cl_object out = ecl_read_byte(ECHO_STREAM_INPUT(strm));
if (!Null(out)) ecl_write_byte(out, ECHO_STREAM_OUTPUT(strm));
return out;
}
static ecl_character
echo_read_char(cl_object strm)
{
@ -625,10 +626,10 @@ static cl_object
concatenated_read_byte(cl_object strm)
{
cl_object l = CONCATENATED_STREAM_LIST(strm);
cl_object c = ECL_NIL;
cl_object c = OBJNULL;
while (!Null(l)) {
c = ecl_read_byte(ECL_CONS_CAR(l));
if (c != ECL_NIL) break;
if (c != OBJNULL) break;
CONCATENATED_STREAM_LIST(strm) = l = ECL_CONS_CDR(l);
}
return c;

View file

@ -580,7 +580,7 @@ si_do_read_sequence(cl_object seq, cl_object stream, cl_object s, cl_object e)
c = ECL_CODE_CHAR(i);
} else {
c = ops->read_byte(stream);
if (c == ECL_NIL) goto OUTPUT;
if (c == OBJNULL) goto OUTPUT;
}
ECL_RPLACA(seq, c);
start++;