mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-21 03:51:47 -08:00
sequence streams: fix and simplify stream creation functions
Since we only support vectors with element type size of a byte, we don't need to check for non-base-strings. Also make sure to set the byte size of the stream always to a positive value.
This commit is contained in:
parent
686127588a
commit
25688d1531
1 changed files with 13 additions and 48 deletions
61
src/c/file.d
61
src/c/file.d
|
|
@ -4393,9 +4393,7 @@ make_sequence_input_stream(cl_object vector, cl_index istart, cl_index iend,
|
|||
int byte_size;
|
||||
int flags = 0;
|
||||
if (!ECL_VECTORP(vector) ||
|
||||
((type = ecl_array_elttype(vector)) < ecl_aet_b8 &&
|
||||
type > ecl_aet_bc) ||
|
||||
ecl_aet_size[type] != 1)
|
||||
ecl_aet_size[type = ecl_array_elttype(vector)] != 1)
|
||||
{
|
||||
FEerror("MAKE-SEQUENCE-INPUT-STREAM only accepts vectors whose element has a size of 1 byte.~%~A", 1, vector);
|
||||
}
|
||||
|
|
@ -4406,29 +4404,12 @@ make_sequence_input_stream(cl_object vector, cl_index istart, cl_index iend,
|
|||
strm = alloc_stream();
|
||||
strm->stream.ops = duplicate_dispatch_table(&seq_in_ops);
|
||||
strm->stream.mode = (short)ecl_smm_sequence_input;
|
||||
if (!byte_size) {
|
||||
#if defined(ECL_UNICODE)
|
||||
if (ECL_BASE_STRING_P(vector)) {
|
||||
if (Null(external_format))
|
||||
external_format = @':default';
|
||||
} else {
|
||||
if (Null(external_format)) {
|
||||
# ifdef WORDS_BIGENDIAN
|
||||
external_format = @':ucs-4be';
|
||||
# else
|
||||
external_format = @':ucs-4le';
|
||||
# endif
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (Null(external_format)) {
|
||||
external_format = @':default';
|
||||
}
|
||||
#endif
|
||||
if (!byte_size && Null(external_format)) {
|
||||
external_format = @':default';
|
||||
}
|
||||
set_stream_elt_type(strm, byte_size, flags, external_format);
|
||||
/* Override byte size and elt type */
|
||||
if (byte_size) strm->stream.byte_size = byte_size;
|
||||
/* Override byte size */
|
||||
if (byte_size) strm->stream.byte_size = 8;
|
||||
SEQ_INPUT_VECTOR(strm) = vector;
|
||||
SEQ_INPUT_POSITION(strm) = istart;
|
||||
SEQ_INPUT_LIMIT(strm) = iend;
|
||||
|
|
@ -4462,6 +4443,9 @@ seq_out_write_byte8(cl_object strm, unsigned char *c, cl_index n)
|
|||
cl_fixnum delta = last - curr_pos;
|
||||
if (delta < n) {
|
||||
/* Not enough space, enlarge */
|
||||
if (!ECL_ADJUSTABLE_ARRAY_P(vector)) {
|
||||
FEerror("Can't adjust the dimensions of the sequence of sequence stream ~A", 1, strm);
|
||||
}
|
||||
vector = _ecl_funcall3(@'adjust-array', vector,
|
||||
ecl_ash(ecl_make_fixnum(last), 1));
|
||||
SEQ_OUTPUT_VECTOR(strm) = vector;
|
||||
|
|
@ -4540,9 +4524,7 @@ make_sequence_output_stream(cl_object vector, cl_object external_format)
|
|||
int byte_size;
|
||||
int flags = 0;
|
||||
if (!ECL_VECTORP(vector) ||
|
||||
((type = ecl_array_elttype(vector)) < ecl_aet_b8 &&
|
||||
type > ecl_aet_bc) ||
|
||||
ecl_aet_size[type] != 1)
|
||||
ecl_aet_size[type = ecl_array_elttype(vector)] != 1)
|
||||
{
|
||||
FEerror("MAKE-SEQUENCE-OUTPUT-STREAM only accepts vectors whose element has a size of 1 byte.~%~A", 1, vector);
|
||||
}
|
||||
|
|
@ -4553,29 +4535,12 @@ make_sequence_output_stream(cl_object vector, cl_object external_format)
|
|||
strm = alloc_stream();
|
||||
strm->stream.ops = duplicate_dispatch_table(&seq_out_ops);
|
||||
strm->stream.mode = (short)ecl_smm_sequence_output;
|
||||
if (!byte_size) {
|
||||
#if defined(ECL_UNICODE)
|
||||
if (ECL_BASE_STRING_P(vector)) {
|
||||
if (Null(external_format))
|
||||
external_format = @':default';
|
||||
} else {
|
||||
if (Null(external_format)) {
|
||||
# ifdef WORDS_BIGENDIAN
|
||||
external_format = @':ucs-4be';
|
||||
# else
|
||||
external_format = @':ucs-4le';
|
||||
# endif
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (Null(external_format)) {
|
||||
external_format = @':default';
|
||||
}
|
||||
#endif
|
||||
if (!byte_size && Null(external_format)) {
|
||||
external_format = @':default';
|
||||
}
|
||||
set_stream_elt_type(strm, byte_size, flags, external_format);
|
||||
/* Override byte size and elt type */
|
||||
if (byte_size) strm->stream.byte_size = byte_size;
|
||||
/* Override byte size */
|
||||
if (byte_size) strm->stream.byte_size = 8;
|
||||
SEQ_OUTPUT_VECTOR(strm) = vector;
|
||||
SEQ_OUTPUT_POSITION(strm) = vector->vector.fillp;
|
||||
return strm;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue