[go: up one dir, main page]

Skip to content

Always close stream in with-input-from-string

If I understand it correctly, the current implementation of with-input-from-string will only close the input stream if the index argument is non-NIL. A quick check seems to confirm this:

(format t "~s~%" (macroexpand '(with-input-from-string (s str)
                                (format t "input: ~a~%" (read-line s)))))

prints:

(LET ((S (MAKE-STRING-INPUT-STREAM STR 0 NIL)))
  (FORMAT T "input: ~a~%" (READ-LINE S)))

This behaviour does not make sense to me. It seems like s should be explicitly closed as it is when index is provided. Is my understanding correct?

I have also looked at sbcl's implementation which wraps code for both situations in the same unwind-protect and closes the stream (sbcl/src/code/macros.lisp).

I have successfully compiled ecl with the changes in this commit. I could not get the checks to run–neither on a clean tree, nor with my changes–, but I have been able to run ecl and verify that it works with the intended changed behaviour in with-input-from-string as far as i understand.

Edited by Moritz Petersen

Merge request reports

Loading