mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
4d426fc2e0
commit
095886b572
3 changed files with 49 additions and 17 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Wed Jan 14 15:43:48 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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]
|
||||||
|
|
||||||
Tue Jan 13 21:59:24 2015 Michal Papis <mpapis@gmail.com>
|
Tue Jan 13 21:59:24 2015 Michal Papis <mpapis@gmail.com>
|
||||||
|
|
||||||
* tool/rbinstall.rb (gem): fix changing permissions of installed
|
* tool/rbinstall.rb (gem): fix changing permissions of installed
|
||||||
|
|
|
@ -359,6 +359,34 @@ clear_rl_outstream(void)
|
||||||
readline_outstream = Qfalse;
|
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:
|
* call-seq:
|
||||||
* Readline.readline(prompt = "", add_hist = false) -> string or nil
|
* 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);
|
prompt = RSTRING_PTR(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (readline_instream) {
|
prepare_readline();
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
rl_prep_terminal(1);
|
rl_prep_terminal(1);
|
||||||
|
@ -1549,6 +1561,7 @@ readline_s_get_filename_quote_characters(VALUE self, VALUE str)
|
||||||
static VALUE
|
static VALUE
|
||||||
readline_s_refresh_line(VALUE self)
|
readline_s_refresh_line(VALUE self)
|
||||||
{
|
{
|
||||||
|
prepare_readline();
|
||||||
rl_refresh_line(0, 0);
|
rl_refresh_line(0, 0);
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
|
@ -448,6 +448,18 @@ class TestReadline < Test::Unit::TestCase
|
||||||
Readline::HISTORY.clear
|
Readline::HISTORY.clear
|
||||||
end if !/EditLine/n.match(Readline::VERSION)
|
end if !/EditLine/n.match(Readline::VERSION)
|
||||||
|
|
||||||
|
def test_refresh_line
|
||||||
|
bug6232 = '[ruby-core:43957] [Bug #6232] refresh_line after set_screen_size'
|
||||||
|
with_temp_stdio do |stdin, stdout|
|
||||||
|
replace_stdio(stdin.path, stdout.path) do
|
||||||
|
assert_ruby_status(%w[-rreadline -], <<-'end;', bug6232)
|
||||||
|
Readline.set_screen_size(40, 80)
|
||||||
|
Readline.refresh_line
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end if Readline.respond_to?(:refresh_line)
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def replace_stdio(stdin_path, stdout_path)
|
def replace_stdio(stdin_path, stdout_path)
|
||||||
|
|
Loading…
Reference in a new issue