Skip to content

Commit

Permalink
input: use type REAL, not NUMBER for timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
scymtym authored and dkochmanski committed Nov 5, 2019
1 parent 7651f5b commit 534981e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
14 changes: 7 additions & 7 deletions buffer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@

(defun with-buffer-function (buffer timeout function)
(declare (type display buffer)
(type (or null number) timeout)
(type function function)
(dynamic-extent function)
;; FIXME: This is probably more a bug in SBCL (logged as
;; bug #243)
(ignorable timeout))
(type (or null real) timeout)
(type function function)
(dynamic-extent function)
;; FIXME: This is probably more a bug in SBCL (logged as
;; bug #243)
(ignorable timeout))
(with-buffer (buffer :timeout timeout :inline t)
(funcall function)))

Expand Down Expand Up @@ -404,7 +404,7 @@
(declare (type buffer buffer)
(type vector vector)
(type array-index start end)
(type (or null number) timeout))
(type (or null real) timeout))
(declare (clx-values eof-p))
(when (buffer-dead buffer)
(x-error 'closed-display :display buffer))
Expand Down
6 changes: 3 additions & 3 deletions dependent.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@
:input t :output t :buffering :none))

#+clasp
(defun open-x-stream (host display protocol)
(defun open-x-stream (host display protocol)
(declare (ignore protocol)
(type (integer 0) display))
(SB-BSD-SOCKETS:socket-make-stream
Expand Down Expand Up @@ -984,7 +984,7 @@
(declare (type display display)
(type buffer-bytes vector)
(type array-index start end)
(type (or null fixnum) timeout))
(type (or null real) timeout))
#.(declare-buffun)
(cond ((and (eql timeout 0)
(not (listen (display-input-stream display))))
Expand All @@ -1001,7 +1001,7 @@
(declare (type display display)
(type buffer-bytes vector)
(type array-index start end)
(type (or null fixnum) timeout))
(type (or null real) timeout))
#.(declare-buffun)
(cond ((and (eql timeout 0)
(not (listen (display-input-stream display))))
Expand Down
55 changes: 27 additions & 28 deletions input.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@

(defun read-input (display timeout force-output-p predicate &rest predicate-args)
(declare (type display display)
(type (or null number) timeout)
(type (or null real) timeout)
(type generalized-boolean force-output-p)
(dynamic-extent predicate-args))
(declare (type function predicate)
Expand Down Expand Up @@ -501,7 +501,7 @@

(defun wait-for-event (display timeout force-output-p)
(declare (type display display)
(type (or null number) timeout)
(type (or null real) timeout)
(type generalized-boolean force-output-p))
(let ((event-process-p (not (eql timeout 0))))
(declare (type generalized-boolean event-process-p))
Expand Down Expand Up @@ -1020,7 +1020,7 @@

(defun event-loop-step-before (display timeout force-output-p current-event-symbol)
(declare (type display display)
(type (or null number) timeout)
(type (or null real) timeout)
(type generalized-boolean force-output-p)
(type symbol current-event-symbol)
(clx-values event eof-or-timeout))
Expand Down Expand Up @@ -1165,36 +1165,35 @@
;;
;; T for peek-p means the event (for which the handler returns non-nil) is not removed
;; from the queue (it is left in place), NIL means the event is removed.

(declare (type display display)
(type (or null number) timeout)
(type generalized-boolean peek-p discard-p force-output-p))
(declare (type t handler)
(dynamic-extent handler))
(type (or null real) timeout)
(type generalized-boolean peek-p discard-p force-output-p)
(type t handler)
(dynamic-extent handler))
(event-loop (display event timeout force-output-p discard-p)
(let* ((event-code (event-code event)) ;; Event decoder defined by DECLARE-EVENT
(event-decoder (and (index< event-code (length *event-handler-vector*))
(svref *event-handler-vector* event-code))))
(event-decoder (and (index< event-code (length *event-handler-vector*))
(svref *event-handler-vector* event-code))))
(declare (type array-index event-code)
(type (or null function) event-decoder))
(type (or null function) event-decoder))
(if event-decoder
(let ((event-handler (if (functionp handler)
handler
(and (type? handler 'sequence)
(< event-code (length handler))
(elt handler event-code)))))
(if event-handler
(let ((result (funcall event-decoder display event event-handler)))
(when result
(unless peek-p
(discard-current-event display))
(return result)))
(cerror "Ignore this event"
"No handler for ~s event"
(svref *event-key-vector* event-code))))
(cerror "Ignore this event"
"Server Error: event with unknown event code ~d received."
event-code)))))
(let ((event-handler (if (functionp handler)
handler
(and (type? handler 'sequence)
(< event-code (length handler))
(elt handler event-code)))))
(if event-handler
(let ((result (funcall event-decoder display event event-handler)))
(when result
(unless peek-p
(discard-current-event display))
(return result)))
(cerror "Ignore this event"
"No handler for ~s event"
(svref *event-key-vector* event-code))))
(cerror "Ignore this event"
"Server Error: event with unknown event code ~d received."
event-code)))))

(defun make-event-handlers (&key (type 'vector) default)
(declare (type t type) ;Sequence type specifier
Expand Down

0 comments on commit 534981e

Please sign in to comment.