summaryrefslogtreecommitdiff
path: root/ext/readline
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-14 06:43:50 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-14 06:43:50 +0000
commit095886b572ef84ec7615c3966da4e94ff96a5f50 (patch)
tree39c61da4403c4dc4ebc85e5ca46a0f99f86e6af6 /ext/readline
parent4d426fc2e03078d583d5d573d4863415c3e3eb8d (diff)
readline.c: initialize before rl_refresh_line
* ext/readline/readline.c (readline_s_refresh_line): initialize before rl_refresh_line(), as some function make the internal state non-clean but rl_refresh_line() does not re-initialize it. [ruby-core:43957] [Bug #6232] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/readline')
-rw-r--r--ext/readline/readline.c47
1 files changed, 30 insertions, 17 deletions
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index 5e78af4b07..140bd7f578 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -359,6 +359,34 @@ clear_rl_outstream(void)
readline_outstream = Qfalse;
}
+static void
+prepare_readline(void)
+{
+ static int initialized = 0;
+ if (!initialized) {
+ rl_initialize();
+ initialized = 1;
+ }
+
+ if (readline_instream) {
+ rb_io_t *ifp;
+ rb_io_check_initialized(ifp = RFILE(rb_io_taint_check(readline_instream))->fptr);
+ if (ifp->fd < 0) {
+ clear_rl_instream();
+ rb_raise(rb_eIOError, "closed readline input");
+ }
+ }
+
+ if (readline_outstream) {
+ rb_io_t *ofp;
+ rb_io_check_initialized(ofp = RFILE(rb_io_taint_check(readline_outstream))->fptr);
+ if (ofp->fd < 0) {
+ clear_rl_outstream();
+ rb_raise(rb_eIOError, "closed readline output");
+ }
+ }
+}
+
/*
* call-seq:
* Readline.readline(prompt = "", add_hist = false) -> string or nil
@@ -460,23 +488,7 @@ readline_readline(int argc, VALUE *argv, VALUE self)
prompt = RSTRING_PTR(tmp);
}
- if (readline_instream) {
- rb_io_t *ifp;
- rb_io_check_initialized(ifp = RFILE(rb_io_taint_check(readline_instream))->fptr);
- if (ifp->fd < 0) {
- clear_rl_instream();
- rb_raise(rb_eIOError, "closed readline input");
- }
- }
-
- if (readline_outstream) {
- rb_io_t *ofp;
- rb_io_check_initialized(ofp = RFILE(rb_io_taint_check(readline_outstream))->fptr);
- if (ofp->fd < 0) {
- clear_rl_outstream();
- rb_raise(rb_eIOError, "closed readline output");
- }
- }
+ prepare_readline();
#ifdef _WIN32
rl_prep_terminal(1);
@@ -1549,6 +1561,7 @@ readline_s_get_filename_quote_characters(VALUE self, VALUE str)
static VALUE
readline_s_refresh_line(VALUE self)
{
+ prepare_readline();
rl_refresh_line(0, 0);
return Qnil;
}