From 4d3df3766bd3dc33237723beee65bd7b09502725 Mon Sep 17 00:00:00 2001 From: Marius Gerbershagen Date: Sat, 16 Jun 2018 13:04:49 +0200 Subject: [PATCH] printer: fix printing of string input streams Currently ECL crashes because we did not set the array element type for the stack allocated tag. Use the string pool instead. This should be plenty fast enough, since the performance of printing of string input streams is not important anyway. --- src/c/printer/write_ugly.d | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/c/printer/write_ugly.d b/src/c/printer/write_ugly.d index 65dd70c1c..0cdf6facb 100644 --- a/src/c/printer/write_ugly.d +++ b/src/c/printer/write_ugly.d @@ -178,12 +178,7 @@ write_stream(cl_object x, cl_object stream) { const char *prefix; cl_object tag; - union cl_lispunion str; -#ifdef ECL_UNICODE - ecl_character buffer[10]; -#else - ecl_base_char buffer[10]; -#endif + cl_object buffer = OBJNULL; switch ((enum ecl_smmode)x->stream.mode) { case ecl_smm_input_file: prefix = "closed input file"; @@ -252,28 +247,20 @@ write_stream(cl_object x, cl_object stream) tag = ECL_NIL; break; case ecl_smm_string_input: { + buffer = si_get_buffer_string(); cl_object text = x->stream.object0; cl_index ndx, l = ecl_length(text); for (ndx = 0; (ndx < 8) && (ndx < l); ndx++) { - buffer[ndx] = ecl_char(text, ndx); + ecl_char_set(buffer, ndx, ecl_char(text, ndx)); } if (l > ndx) { - buffer[ndx-1] = '.'; - buffer[ndx-2] = '.'; - buffer[ndx-3] = '.'; + ecl_char_set(buffer, ndx-1, '.'); + ecl_char_set(buffer, ndx-2, '.'); + ecl_char_set(buffer, ndx-3, '.'); } - buffer[ndx++] = 0; + si_fill_pointer_set(buffer, ecl_make_fixnum(ndx)); prefix = "closed string-input stream from"; - tag = &str; -#ifdef ECL_UNICODE - tag->string.t = t_string; - tag->string.self = buffer; -#else - tag->base_string.t = t_base_string; - tag->base_string.self = buffer; -#endif - tag->base_string.dim = ndx; - tag->base_string.fillp = ndx-1; + tag = buffer; break; } case ecl_smm_string_output: @@ -294,6 +281,8 @@ write_stream(cl_object x, cl_object stream) if (!x->stream.closed) prefix = prefix + 7; _ecl_write_unreadable(x, prefix, tag, stream); + if (buffer != OBJNULL) + si_put_buffer_string(buffer); } static void