streams: sequence input stream follows the vector length

This is to allow working with sequence streams where the vector may change after
the stream has been created.

When the user specifies :END to be some fixed value, then we upkeep that
promise, but when :END is NIL, then we always consult the vector fillp.
This commit is contained in:
Daniel Kochmański 2025-07-24 10:07:38 +02:00
parent 086f0a4bef
commit c7f534771a
4 changed files with 24 additions and 7 deletions

View file

@ -315,7 +315,7 @@ make_sequence_input_stream(cl_object vector, cl_index istart, cl_index iend,
}
SEQ_STREAM_VECTOR(strm) = vector;
SEQ_STREAM_POSITION(strm) = istart;
SEQ_INPUT_LIMIT(strm) = iend;
SEQ_INPUT_VECTOR_END(strm) = iend;
return strm;
}
@ -324,11 +324,15 @@ make_sequence_input_stream(cl_object vector, cl_index istart, cl_index iend,
(end ECL_NIL)
(external_format ECL_NIL))
cl_index_pair p;
cl_object strm;
@
p = ecl_vector_start_end(@[ext::make-sequence-input-stream],
vector, start, end);
@(return make_sequence_input_stream(vector, p.start, p.end,
external_format))
strm = make_sequence_input_stream(vector, p.start, p.end,
external_format);
if (Null(end))
strm->stream.flags |= ECL_STREAM_USE_VECTOR_FILLP;
@(return strm)
@)
/**********************************************************************

View file

@ -318,6 +318,9 @@ bytes comprising the character in the given external format.
@defun ext:make-sequence-input-stream vector &key (start 0) (end nil) (external-format nil)
Create a sequence input stream with the subsequence bounded by
@var{start} and @var{end} of the given vector.
When @var{end} is @code{nil}, then the end bound is the vector's length.
When the vector is adjusted the end bound is updated as well.
@end defun
@lspdef ext:make-sequence-output-stream
@defun ext:make-sequence-output-stream vector &key (external-format nil)

View file

@ -533,7 +533,13 @@ write_char_increment_column(cl_object strm, ecl_character c)
#define SEQ_STREAM_ELT_TYPE(strm) (strm)->stream.object0
#define SEQ_STREAM_VECTOR(strm) (strm)->stream.object1
#define SEQ_STREAM_POSITION(strm) (strm)->stream.int0
#define SEQ_INPUT_LIMIT(strm) (strm)->stream.int1
#define SEQ_INPUT_VECTOR_END(strm) (strm)->stream.int1
#define SEQ_INPUT_LIMIT(strm) \
((strm)->stream.flags & ECL_STREAM_USE_VECTOR_FILLP \
? SEQ_STREAM_VECTOR(strm)->vector.fillp \
: SEQ_INPUT_VECTOR_END(strm))
#ifndef HAVE_FSEEKO
#define ecl_off_t int

View file

@ -645,15 +645,19 @@ enum {
ECL_STREAM_USER_FORMAT = 8,
ECL_STREAM_US_ASCII = 10,
#endif
/* External Format */
ECL_STREAM_CR = 16,
ECL_STREAM_LF = 32,
ECL_STREAM_SIGNED_BYTES = 64,
ECL_STREAM_LITTLE_ENDIAN = 128,
/* OS Streams */
ECL_STREAM_C_STREAM = 256,
ECL_STREAM_MIGHT_SEEK = 512,
ECL_STREAM_CLOSE_COMPONENTS = 1024,
ECL_STREAM_CLOSE_ON_EXEC = 2048,
ECL_STREAM_NONBLOCK = 4096
ECL_STREAM_CLOSE_ON_EXEC = 1024,
ECL_STREAM_NONBLOCK = 2048,
/* Lisp Streams */
ECL_STREAM_CLOSE_COMPONENTS = 4096,
ECL_STREAM_USE_VECTOR_FILLP = 8192
};
/* buffer points to an array of bytes ending at buffer_end. Decode one