ruby-changes:22430
From: naruse <ko1@a...>
Date: Wed, 8 Feb 2012 10:58:42 +0900 (JST)
Subject: [ruby-changes:22430] naruse:r34479 (ruby_1_9_3): merge revision(s) 34254,34256:
naruse 2012-02-08 10:58:31 +0900 (Wed, 08 Feb 2012) New Revision: 34479 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34479 Log: merge revision(s) 34254,34256: * ext/readline/readline.c (readline_attempted_completion_function): empty completion result does not mean memory error. * ext/readline/readline.c (readline_attempted_completion_function): fix compile error. Modified files: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/ext/readline/readline.c branches/ruby_1_9_3/test/readline/test_readline.rb branches/ruby_1_9_3/version.h Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 34478) +++ ruby_1_9_3/ChangeLog (revision 34479) @@ -1,3 +1,13 @@ +Wed Feb 8 10:56:00 2012 Kazuhiro NISHIYAMA <zn@m...> + + * ext/readline/readline.c (readline_attempted_completion_function): + fix compile error. + +Wed Feb 8 10:56:00 2012 Nobuyoshi Nakada <nobu@r...> + + * ext/readline/readline.c (readline_attempted_completion_function): + empty completion result does not mean memory error. + Wed Feb 8 10:54:49 2012 Nobuyoshi Nakada <nobu@r...> * ext/readline/readline.c (readline_readline): check if outstream Index: ruby_1_9_3/ext/readline/readline.c =================================================================== --- ruby_1_9_3/ext/readline/readline.c (revision 34478) +++ ruby_1_9_3/ext/readline/readline.c (revision 34479) @@ -667,12 +667,12 @@ #endif case_fold = RTEST(rb_attr_get(mReadline, completion_case_fold)); 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); matches = RARRAY_LEN(ary); - if (matches == 0) - return NULL; - result = ALLOC_N(char *, matches + 2); + if (matches == 0) return NULL; + result = (char**)malloc((matches + 2)*sizeof(char*)); + if (result == NULL) rb_raise(rb_eNoMemError, "failed to allocate memory"); for (i = 0; i < matches; i++) { temp = rb_obj_as_string(RARRAY_PTR(ary)[i]); result[i + 1] = ALLOC_N(char, RSTRING_LEN(temp) + 1); Index: ruby_1_9_3/version.h =================================================================== --- ruby_1_9_3/version.h (revision 34478) +++ ruby_1_9_3/version.h (revision 34479) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 62 +#define RUBY_PATCHLEVEL 63 #define RUBY_RELEASE_DATE "2012-02-08" #define RUBY_RELEASE_YEAR 2012 Index: ruby_1_9_3/test/readline/test_readline.rb =================================================================== --- ruby_1_9_3/test/readline/test_readline.rb (revision 34478) +++ ruby_1_9_3/test/readline/test_readline.rb (revision 34479) @@ -85,9 +85,7 @@ if !/EditLine/n.match(Readline::VERSION) def test_readline - stdin = Tempfile.new("test_readline_stdin") - stdout = Tempfile.new("test_readline_stdout") - begin + with_temp_stdio do |stdin, stdout| stdin.write("hello\n") stdin.close stdout.close @@ -114,9 +112,6 @@ replace_stdio(stdin.path, stdout.path) { Readline.readline("> ") } }.join end - ensure - stdin.close(true) - stdout.close(true) end end @@ -130,9 +125,7 @@ return end - stdin = Tempfile.new("test_readline_stdin") - stdout = Tempfile.new("test_readline_stdout") - begin + with_temp_stdio do |stdin, stdout| actual_text = nil actual_line_buffer = nil actual_point = nil @@ -156,9 +149,6 @@ assert_equal(Encoding.find("locale"), Readline.line_buffer.encoding) assert_equal(true, Readline.line_buffer.tainted?) assert_equal(21, Readline.point) - ensure - stdin.close(true) - stdout.close(true) end end end @@ -193,6 +183,19 @@ 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 begin res = Readline.get_screen_size @@ -316,6 +319,15 @@ } 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 return Encoding.default_internal || Encoding.find("locale") end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/