Browse files

Override readline's getc function to use Racket's read-byte.

Eliminates the busy-polling behavior observed in Mac OS X when
xrepl is required at the regular repl.

Closes PR 13350.
  • Loading branch information...
1 parent c19b8a4 commit e63d277a6219fc442c1121020d16c120c7374fb4 @dyoo committed Feb 10, 2013
Showing with 8 additions and 3 deletions.
  1. +8 −3 collects/readline/mzrl.rkt
@@ -115,9 +115,14 @@
(unless (terminal-port? real-input-port)
(log-warning "mzrl warning: input port is not a terminal\n"))
-;; make it possible to run Scheme threads while waiting for input
-(set-ffi-obj! "rl_event_hook" libreadline (_fun -> _int)
- (lambda () (sync/enable-break real-input-port) 0))
+;; We need to tell readline to pull content through our own function,
+;; to avoid buffering issues between C and Racket, and to allow
+;; racket threads to run while waiting for input.
+(set-ffi-obj! "rl_getc_function" libreadline (_fun _pointer -> _int)
+ (lambda (_)
+ (define next-byte (read-byte real-input-port))
+ (if (eof-object? next-byte) -1 next-byte)))
;; force cursor on a new line

0 comments on commit e63d277

Please sign in to comment.