2013$BG/(B8$B7n(B8$BF|(B 8:05 Tanaka A. [email protected]:
$B$G$b!“(Breadline_getc $B$G$OC1$K(B GVL $B$r30$7$F(B rl_getc
$B$r8F$Y$P$$$$$N$G$O$J$$$+!”$H$$$&5$$b$7$^$9!#(B
$B$3$&$9$k$J$i!"$3$&$G$9$+$M$'!#(B
% svn diff --diff-cmd diff -x ‘-u -p’
Index: ext/readline/readline.c
— ext/readline/readline.c (revision 42429)
+++ ext/readline/readline.c (working copy)
@@ -35,6 +35,7 @@
#include “ruby/ruby.h”
#include “ruby/io.h”
+#include “ruby/thread.h”
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -135,35 +136,35 @@ static VALUE readline_outstream;
#define rl_getc(f) EOF
#endif
-static int readline_getc(FILE *);
+struct getc_struct {
- FILE *input;
- int ret;
+};
-
static int
-readline_getc(FILE *input)
+getc_body(FILE *input)
{
- rb_io_t *ifp = 0;
- VALUE c;
- if (!readline_instream) return rl_getc(input);
- GetOpenFile(readline_instream, ifp);
- if (rl_instream != ifp->stdio_file) return rl_getc(input);
#if defined(_WIN32)
- int fd = fileno(input);
{
INPUT_RECORD ir;
int n;
static int prior_key = ‘0’;
for (; {
if (prior_key > 0xff) {
&ir, 1, &n)) {
&n)) {
if (n == 1) {
if (ir.EventType == KEY_EVENT &&
ir.Event.KeyEvent.bKeyDown) {
ReadConsoleInput((HANDLE)_get_osfhandle(ifp->fd), &ir, 1, &n);
&ir, 1, &n);
}
} else {
@@ -172,21 +173,27 @@ readline_getc(FILE *input)
}
}
#endif
states? */
-
rb_io_read_pending(ifp)) {
-
int meta = 0;
-
c = rb_io_getbyte(readline_instream);
-
if (FIXNUM_P(c) && isascii(FIX2INT(c))) meta = 1;
-
rb_io_ungetbyte(readline_instream, c);
-
if (meta) rl_execute_next(ESC);
-
return ESC;
- }
-#endif
- return FIX2INT(c);
- return rl_getc(input);
+}
-
+static void *
+getc_func(void *data1)
+{
- struct getc_struct *p = data1;
- FILE *input = p->input;
- p->ret = getc_body(input);
- return NULL;
+}
-
+static int readline_getc(FILE *);
+static int
+readline_getc(FILE *input)
+{
- struct getc_struct data;
- data.input = input;
- data.ret = -1;
- rb_thread_call_without_gvl(getc_func, &data, RUBY_UBF_IO, NULL);
- return data.ret;
}
#elif defined HAVE_RL_EVENT_HOOK
#define BUSY_WAIT 0
arton $B$5$s$,=q$$$?(B Windows
$BMQ$N%3!<%I$,I,MW$+$I$&$+$O$h$/$o$+$i$J$$$N$G$9$,!“(B
$B$$$A$*$&;D$7$F$”$j$^$9!#%F%9%H$O$7$F$$$^$;$s!#(B