mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/readline/readline.c (readline_attempted_completion_function):
empty completion result does not mean memory error. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34254 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
71935466b7
commit
9fa668f34a
3 changed files with 31 additions and 14 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Tue Jan 10 10:41:11 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/readline/readline.c (readline_attempted_completion_function):
|
||||||
|
empty completion result does not mean memory error.
|
||||||
|
|
||||||
Tue Jan 10 02:19:22 2012 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
|
Tue Jan 10 02:19:22 2012 CHIKANAGA Tomoyuki <nagachika00@gmail.com>
|
||||||
|
|
||||||
* test/ruby/test_io.rb (test_autoclose_true_closed_by_finalizer,
|
* test/ruby/test_io.rb (test_autoclose_true_closed_by_finalizer,
|
||||||
|
|
|
@ -667,10 +667,10 @@ readline_attempted_completion_function(const char *text, int start, int end)
|
||||||
#endif
|
#endif
|
||||||
case_fold = RTEST(rb_attr_get(mReadline, completion_case_fold));
|
case_fold = RTEST(rb_attr_get(mReadline, completion_case_fold));
|
||||||
ary = rb_funcall(proc, rb_intern("call"), 1, rb_locale_str_new_cstr(text));
|
ary = rb_funcall(proc, rb_intern("call"), 1, rb_locale_str_new_cstr(text));
|
||||||
if (TYPE(ary) != T_ARRAY)
|
if (!RB_TYPE_P(ary, T_ARRAY)) {
|
||||||
ary = rb_Array(ary);
|
ary = rb_Array(ary);
|
||||||
matches = RARRAY_LEN(ary);
|
matches = RARRAY_LEN(ary);
|
||||||
if (matches == NULL) rb_memerror();
|
if (matches == 0) return NULL;
|
||||||
result = (char**)malloc((matches + 2)*sizeof(char*));
|
result = (char**)malloc((matches + 2)*sizeof(char*));
|
||||||
if (result == NULL) rb_raise(rb_eNoMemError, "failed to allocate memory");
|
if (result == NULL) rb_raise(rb_eNoMemError, "failed to allocate memory");
|
||||||
for (i = 0; i < matches; i++) {
|
for (i = 0; i < matches; i++) {
|
||||||
|
|
|
@ -85,9 +85,7 @@ class TestReadline < Test::Unit::TestCase
|
||||||
|
|
||||||
if !/EditLine/n.match(Readline::VERSION)
|
if !/EditLine/n.match(Readline::VERSION)
|
||||||
def test_readline
|
def test_readline
|
||||||
stdin = Tempfile.new("test_readline_stdin")
|
with_temp_stdio do |stdin, stdout|
|
||||||
stdout = Tempfile.new("test_readline_stdout")
|
|
||||||
begin
|
|
||||||
stdin.write("hello\n")
|
stdin.write("hello\n")
|
||||||
stdin.close
|
stdin.close
|
||||||
stdout.close
|
stdout.close
|
||||||
|
@ -114,9 +112,6 @@ class TestReadline < Test::Unit::TestCase
|
||||||
replace_stdio(stdin.path, stdout.path) { Readline.readline("> ") }
|
replace_stdio(stdin.path, stdout.path) { Readline.readline("> ") }
|
||||||
}.join
|
}.join
|
||||||
end
|
end
|
||||||
ensure
|
|
||||||
stdin.close(true)
|
|
||||||
stdout.close(true)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -130,9 +125,7 @@ class TestReadline < Test::Unit::TestCase
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
stdin = Tempfile.new("test_readline_stdin")
|
with_temp_stdio do |stdin, stdout|
|
||||||
stdout = Tempfile.new("test_readline_stdout")
|
|
||||||
begin
|
|
||||||
actual_text = nil
|
actual_text = nil
|
||||||
actual_line_buffer = nil
|
actual_line_buffer = nil
|
||||||
actual_point = nil
|
actual_point = nil
|
||||||
|
@ -176,9 +169,6 @@ class TestReadline < Test::Unit::TestCase
|
||||||
assert_equal(Encoding.find("locale"), Readline.line_buffer.encoding)
|
assert_equal(Encoding.find("locale"), Readline.line_buffer.encoding)
|
||||||
assert_equal(true, Readline.line_buffer.tainted?)
|
assert_equal(true, Readline.line_buffer.tainted?)
|
||||||
assert_equal(21, Readline.point)
|
assert_equal(21, Readline.point)
|
||||||
ensure
|
|
||||||
stdin.close(true)
|
|
||||||
stdout.close(true)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -213,6 +203,19 @@ class TestReadline < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_completion_proc_empty_result
|
||||||
|
with_temp_stdio do |stdin, stdout|
|
||||||
|
stdin.write("first\t")
|
||||||
|
stdin.flush
|
||||||
|
actual_text = nil
|
||||||
|
Readline.completion_proc = ->(text) {[]}
|
||||||
|
line = replace_stdio(stdin.path, stdout.path) {
|
||||||
|
Readline.readline("> ")
|
||||||
|
}
|
||||||
|
assert_equal("first", line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_get_screen_size
|
def test_get_screen_size
|
||||||
begin
|
begin
|
||||||
res = Readline.get_screen_size
|
res = Readline.get_screen_size
|
||||||
|
@ -336,6 +339,15 @@ class TestReadline < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_temp_stdio
|
||||||
|
stdin = Tempfile.new("test_readline_stdin")
|
||||||
|
stdout = Tempfile.new("test_readline_stdout")
|
||||||
|
yield stdin, stdout
|
||||||
|
ensure
|
||||||
|
stdin.close(true) if stdin
|
||||||
|
stdout.close(true) if stdout
|
||||||
|
end
|
||||||
|
|
||||||
def get_default_internal_encoding
|
def get_default_internal_encoding
|
||||||
return Encoding.default_internal || Encoding.find("locale")
|
return Encoding.default_internal || Encoding.find("locale")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue