From ac28b4bc430e89db490c9bb23ec7aa8d7cfe318a Mon Sep 17 00:00:00 2001 From: Kambiz Darabi Date: Fri, 6 Jan 2012 09:11:36 +0100 Subject: [PATCH] sb-simple-streams: signal an error for bad stream classes in OPEN Instead of silently returning NIL, signal an error if the class does not exist (if argument :class is a symbol) or is not a stream class. lp#969352 --- NEWS | 2 ++ contrib/sb-simple-streams/impl.lisp | 6 +++++- contrib/sb-simple-streams/simple-stream-tests.lisp | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index fbb0734..8c375a1 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ ;;;; -*- coding: utf-8; fill-column: 78 -*- changes relative to sbcl-1.0.55: + * bug fix: SB-SIMPLE-STREAMS signals an error for bogus :CLASS arguments in + OPEN. (lp#969352, thanks to Kambiz Darabi) * documentation: ** improved docstrings: REPLACE (lp#965592) diff --git a/contrib/sb-simple-streams/impl.lisp b/contrib/sb-simple-streams/impl.lisp index 07732f3..3512edf 100644 --- a/contrib/sb-simple-streams/impl.lisp +++ b/contrib/sb-simple-streams/impl.lisp @@ -713,7 +713,11 @@ (remf options :input-handle) (remf options :output-handle) (make-instance class :lisp-stream - (apply #'open-fd-stream filespec options)))))) + (apply #'open-fd-stream filespec options))) + (t (error "Don't know how to handle the stream class ~A" + (etypecase class + (symbol (find-class class t)) + (class class))))))) (declaim (inline read-byte read-char read-char-no-hang unread-char)) diff --git a/contrib/sb-simple-streams/simple-stream-tests.lisp b/contrib/sb-simple-streams/simple-stream-tests.lisp index f0d5a73..20c5a8e 100644 --- a/contrib/sb-simple-streams/simple-stream-tests.lisp +++ b/contrib/sb-simple-streams/simple-stream-tests.lisp @@ -60,6 +60,22 @@ (progn ,@body)) ,(when delete-afterwards `(ignore-errors (delete-file ,file)))))) +(deftest non-existent-class + (handler-case + (with-test-file (s *test-file* :class 'non-existent-stream) + nil) + ;; find-class will raise a simple-error + (simple-error (c) (search "There is no class" (simple-condition-format-control c)))) + 0) + +(deftest non-stream-class + (handler-case + (with-test-file (s *test-file* :class 'standard-class) + nil) + ;; Will fall through sb-simple-streams:open as it is no stream class. + (simple-error (c) (search "Don't know how to handle" (simple-condition-format-control c)))) + 0) + (deftest create-file-1 ;; Create a file-simple-stream, write data. (prog1 -- 1.7.10.4