Commit d3a25e58 authored by Robert Goldman's avatar Robert Goldman
Browse files

Merge branch 'fix-call-with-temporary-file' into 'master'

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

See merge request !180
parents a6b85a4b 83e69d3c
......@@ -468,6 +468,11 @@
(assert-equal (read-file-lines p) '("Same thing with :close-stream"))
p))))))
(let ((pn4 (uiop:with-temporary-file (:pathname pn :direction :output :prefix "WTF4")
:close-stream
pn)))
(assert (not (probe-file pn4))))
(DBG :ensure-gethash)
(let ((h (make-hash-table :test 'equal)))
(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
;; or the non-local return causes the file creation to be undone.
(setf results (multiple-value-list
(if want-pathname-p
(funcall thunk stream pathname)
(funcall thunk stream)))))))
(call-function thunk stream pathname)
(call-function thunk stream)))))))
;; 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.
(when okp
(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,
;; either one computed already, or one from AFTER, if that exists.
(if after
......@@ -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))))
(beforef (gensym "BEFORE"))
(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
`((,beforef (,@(when streamp `(,stream)) ,@(when pathnamep `(,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