Commit 83e69d3c authored by Eric Timmons's avatar Eric Timmons Committed by Robert Goldman
Browse files

Fix bug in WITH-TEMPORARY-FILE if stream is immediately closed.

Previously, if the first form in the body of `with-temporary-file` was `close-stream`, odd things would happen. This fixes that and also emits a style-warning in that case, since it's an anomalous thing to do.
parent a6b85a4b
...@@ -468,6 +468,11 @@ ...@@ -468,6 +468,11 @@
(assert-equal (read-file-lines p) '("Same thing with :close-stream")) (assert-equal (read-file-lines p) '("Same thing with :close-stream"))
p)))))) p))))))
(let ((pn4 (uiop:with-temporary-file (:pathname pn :direction :output :prefix "WTF4")
:close-stream
pn)))
(assert (not (probe-file pn4))))
(DBG :ensure-gethash) (DBG :ensure-gethash)
(let ((h (make-hash-table :test 'equal))) (let ((h (make-hash-table :test 'equal)))
(assert-equal (multiple-value-list (gethash 1 h 2)) '(2 nil)) (assert-equal (multiple-value-list (gethash 1 h 2)) '(2 nil))
......
...@@ -627,13 +627,13 @@ Finally, the file will be deleted, unless the KEEP argument when CALL-FUNCTION'e ...@@ -627,13 +627,13 @@ Finally, the file will be deleted, unless the KEEP argument when CALL-FUNCTION'e
;; or the non-local return causes the file creation to be undone. ;; or the non-local return causes the file creation to be undone.
(setf results (multiple-value-list (setf results (multiple-value-list
(if want-pathname-p (if want-pathname-p
(funcall thunk stream pathname) (call-function thunk stream pathname)
(funcall thunk stream))))))) (call-function thunk stream)))))))
;; if we don't want a stream, then we must call the thunk *after* ;; if we don't want a stream, then we must call the thunk *after*
;; the stream is closed, but only if it was successfully opened. ;; the stream is closed, but only if it was successfully opened.
(when okp (when okp
(when (and want-pathname-p (not want-stream-p)) (when (and want-pathname-p (not want-stream-p))
(setf results (multiple-value-list (funcall thunk okp)))) (setf results (multiple-value-list (call-function thunk okp))))
;; if the stream was successfully opened, then return a value, ;; if the stream was successfully opened, then return a value,
;; either one computed already, or one from AFTER, if that exists. ;; either one computed already, or one from AFTER, if that exists.
(if after (if after
...@@ -664,6 +664,8 @@ Upon success, the KEEP form is evaluated and the file is is deleted unless it ev ...@@ -664,6 +664,8 @@ Upon success, the KEEP form is evaluated and the file is is deleted unless it ev
(after (when afterp (subseq body (1+ afterp)))) (after (when afterp (subseq body (1+ afterp))))
(beforef (gensym "BEFORE")) (beforef (gensym "BEFORE"))
(afterf (gensym "AFTER"))) (afterf (gensym "AFTER")))
(when (eql afterp 0)
(style-warn ":CLOSE-STREAM should not be the first form of BODY in WITH-TEMPORARY-FILE. Instead, do not provide a STREAM."))
`(flet (,@(when before `(flet (,@(when before
`((,beforef (,@(when streamp `(,stream)) ,@(when pathnamep `(,pathname))) `((,beforef (,@(when streamp `(,stream)) ,@(when pathnamep `(,pathname)))
,@(when after `((declare (ignorable ,pathname)))) ,@(when after `((declare (ignorable ,pathname))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment