streams: bring bivalent streams UNREAD-CHAR and UNREAD-BYTE together

This finishes the commit that adds unread-byte and peek-byte functions to the
mix in that for bivalent stream UNREAD-BYTE will work for the subsequent
READ-CHAR and vice versa. This also caters to transcoding etc.
This commit is contained in:
Daniel Kochmański 2025-07-28 11:44:19 +02:00
parent b7eaf35502
commit 688eceb9ed
2 changed files with 7 additions and 10 deletions

View file

@ -25,11 +25,8 @@ ecl_binary_read_byte(cl_object strm)
unsigned char *buf = strm->stream.byte_buffer;
cl_object byte;
cl_index nbytes;
byte = strm->stream.last_byte;
unlikely_if (byte != OBJNULL) {
strm->stream.last_byte = OBJNULL;
return byte;
}
strm->stream.last_char = EOF;
strm->stream.last_byte = OBJNULL;
read_byte8 = strm->stream.ops->read_byte8;
nbytes = strm->stream.byte_size/8;
if (read_byte8(strm, buf, nbytes) < nbytes)
@ -48,13 +45,11 @@ ecl_binary_write_byte(cl_object strm, cl_object byte)
write_byte8(strm, buf, nbytes);
}
/* FIXME this function should spill octets into the buffer like eformat does, so
that when we read-char next, or change the element type and re-read byte, it
will be possible to reinterpret these octets. */
void
ecl_binary_unread_byte(cl_object strm, cl_object byte)
{
unlikely_if (strm->stream.last_byte != OBJNULL) {
unlikely_if (strm->stream.last_char != EOF
|| strm->stream.last_byte != OBJNULL) {
ecl_unread_twice(strm);
}
strm->stream.last_byte = byte;

View file

@ -67,6 +67,7 @@ ecl_eformat_read_char(cl_object strm)
unsigned char *buffer_end = buffer;
cl_index byte_size = (strm->stream.byte_size / 8);
strm->stream.last_char = EOF;
strm->stream.last_byte = OBJNULL;
do {
if (ecl_read_byte8(strm, buffer_end, byte_size) < byte_size) {
c = EOF;
@ -83,7 +84,8 @@ ecl_eformat_read_char(cl_object strm)
void
ecl_eformat_unread_char(cl_object strm, ecl_character c)
{
unlikely_if (strm->stream.last_char != EOF) {
unlikely_if (strm->stream.last_char != EOF
|| strm->stream.last_byte != OBJNULL) {
ecl_unread_twice(strm);
}
strm->stream.last_char = c;