0.8.7.22:
[sbcl.git] / src / pcl / gray-streams.lisp
index b273412..3ad52a1 100644 (file)
 ;;;; more information.
 
 (in-package "SB-GRAY")
+
+;;; BUG-OR-ERROR: because we have extensible streams, wherewith the
+;;; user is responsible for some of the protocol implementation, it's
+;;; not necessarily a bug in SBCL itself if we fall through to one of
+;;; these default methods.
+(defmacro bug-or-error (stream fun)
+  `(error "~@<The stream ~S has no suitable method for ~S, ~
+           and so has fallen through to this method.  If you think that this is ~
+           a bug, please report it to the applicable authority (bugs in SBCL itself ~
+           should go to the mailing lists referenced from <http://www.sbcl.org/>).~@:>"
+           ,stream ,fun))
+
 \f
 (fmakunbound 'stream-element-type)
 
 
 (defmethod stream-element-type ((stream fundamental-character-stream))
   'character)
+
+(defmethod stream-element-type ((stream stream))
+  (bug-or-error stream 'stream-element-type))
+
+(defmethod stream-element-type ((non-stream t))
+  (error 'type-error :datum non-stream :expected-type 'stream))
 \f
 (defgeneric pcl-open-stream-p (stream)
   #+sb-doc
 (defmethod pcl-open-stream-p ((stream fundamental-stream))
   (stream-open-p stream))
 
+(defmethod pcl-open-stream-p ((stream stream))
+  (bug-or-error stream 'open-stream-p))
+
+(defmethod pcl-open-stream-p ((non-stream t))
+  (error 'type-error :datum non-stream :expected-type 'stream))
+
 ;;; bootstrapping hack
 (pcl-open-stream-p (make-string-output-stream))
 (setf (fdefinition 'open-stream-p) #'pcl-open-stream-p)
 
 (setf (fdefinition 'close) #'pcl-close)
 \f
-(fmakunbound 'input-stream-p)
-
-(defgeneric input-stream-p (stream)
-  #+sb-doc
-  (:documentation "Can STREAM perform input operations?"))
+(let ()
+  (fmakunbound 'input-stream-p)
+
+  (defgeneric input-stream-p (stream)
+    #+sb-doc
+    (:documentation "Can STREAM perform input operations?"))
+  
+  (defmethod input-stream-p ((stream ansi-stream))
+    (ansi-stream-input-stream-p stream))
+  
+  (defmethod input-stream-p ((stream fundamental-input-stream))
+    t)
+
+  (defmethod input-stream-p ((stream stream))
+    (bug-or-error stream 'input-stream-p))
+  
+  (defmethod input-stream-p ((non-stream t))
+    (error 'type-error :datum non-stream :expected-type 'stream)))
+\f
+(let ()
+  (fmakunbound 'output-stream-p)
 
-(defmethod input-stream-p ((stream ansi-stream))
-  (ansi-stream-input-stream-p stream))
+  (defgeneric output-stream-p (stream)
+    #+sb-doc
+    (:documentation "Can STREAM perform output operations?"))
 
-(defmethod input-stream-p ((stream fundamental-input-stream))
-  t)
-\f
-(fmakunbound 'output-stream-p)
+  (defmethod output-stream-p ((stream ansi-stream))
+    (ansi-stream-output-stream-p stream))
 
-(defgeneric output-stream-p (stream)
-  #+sb-doc
-  (:documentation "Can STREAM perform output operations?"))
+  (defmethod output-stream-p ((stream fundamental-output-stream))
+    t)
 
-(defmethod output-stream-p ((stream ansi-stream))
-  (ansi-stream-output-stream-p stream))
+  (defmethod output-stream-p ((stream stream))
+    (bug-or-error stream 'output-stream-p))
 
-(defmethod output-stream-p ((stream fundamental-output-stream))
-  t)
+  (defmethod output-stream-p ((non-stream t))
+    (error 'type-error :datum non-stream :expected-type 'stream)))
 \f
 ;;; character input streams
 ;;;