Raymond Toy pushed to branch issue-373-handle-temp-files at cmucl / cmucl Commits: c9181e31 by Raymond Toy at 2025-11-07T10:37:51-08:00 Remove with-temporary-stream As mentioned in the review, we probably don't want this. Hence, remove it. - - - - - ef79c4ec by Raymond Toy at 2025-11-07T10:38:26-08:00 Convert clear-output-1 test to use with-temporary-file - - - - - 2 changed files: - src/code/extensions.lisp - tests/fd-streams.lisp Changes: ===================================== src/code/extensions.lisp ===================================== @@ -645,57 +645,6 @@ default-name)) "XXXXXX")) -;;; WITH-TEMPORARY-STREAM -- Public -;;; -(defmacro with-temporary-stream ((s &key - (direction :output) - (element-type 'base-char) - (external-format :default) - decoding-error - encoding-error) - &parse-body (forms decls)) - _N"Return a stream to a temporary file that is automatically created." - (let ((fd (gensym "FD-")) - (filename (gensym "FILENAME-")) - (dir (gensym "DIRECTION-")) - (okay (gensym "OKAY-")) - (err (gensym "ERR-")) - (file-template (gensym "FILE-TEMPLATE-"))) - `(progn - (unless (member ,direction '(:output :io)) - (error ":direction must be one of :output or :io, not ~S" - ,direction)) - (let ((,file-template (create-template nil "cmucl-temp-stream-")) - ,fd ,filename ,s) - (unwind-protect - (progn - (multiple-value-setq (,fd ,filename) - (unix::unix-mkstemp ,file-template)) - (unless ,fd - (error "Unable to create temporary stream at ~S: ~A~%" - ,file-template - (unix:get-unix-error-msg ,filename))) - (let* ((,dir ,direction)) - (setf ,s (make-fd-stream ,fd - :input (member ,dir '(:input :io)) - :output (member ,dir '(:output :io)) - :element-type ',element-type - :external-format ,external-format - :decoding-error ,decoding-error - :encoding-error ,encoding-error))) - ;; Delete the file; we have an open fd to the file, though. - (multiple-value-bind (,okay ,err) - (unix::unix-unlink ,filename) - (unless ,okay - (error "Unable to unlink temporary file ~S: ~A" - ,filename (unix:get-unix-error-msg ,err)))) - (locally ,@decls - ,@forms)) - ;; Close the stream which will close the fd now that we're - ;; done. - (when ,s - (close ,s))))))) - ;;; WITH-TEMPORARY-FILE -- Public (defmacro with-temporary-file ((filename &key prefix) &parse-body (forms decls)) ===================================== tests/fd-streams.lisp ===================================== @@ -36,6 +36,25 @@ (file-length s)) (delete-file *test-file*)))) +(define-test clear-output-1 + (:tag :trac) + (assert-eql + 0 + (ext:with-temporary-file (test-file) + (let ((s (open test-file + :direction :output + :if-exists :supersede))) + ;; Write a character to the (fully buffered) output + ;; stream. Clear the output and close the file. Nothing + ;; should have been written to the file. + (write-char #\a s) + (clear-output s) + (close s) + (setf s (open test-file)) + (prog1 + (file-length s) + (close s)))))) + (define-test file-position.1 (:tag :issues) ;; Create a short test file View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/346db6a87020bef895a2d8c... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/346db6a87020bef895a2d8c... You're receiving this email because of your account on gitlab.common-lisp.net.
participants (1)
-
Raymond Toy (@rtoy)