ruby-changes:8351
From: matz <ko1@a...>
Date: Wed, 22 Oct 2008 00:52:24 +0900 (JST)
Subject: [ruby-changes:8351] Ruby:r19879 (trunk): * string.c (rb_external_str_new_with_enc): wrong condition to
matz 2008-10-22 00:52:07 +0900 (Wed, 22 Oct 2008) New Revision: 19879 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19879 Log: * string.c (rb_external_str_new_with_enc): wrong condition to calculate strlen(). * ext/readline/readline.c: add encoding support. Modified files: trunk/ChangeLog trunk/ext/readline/readline.c trunk/string.c Index: ChangeLog =================================================================== --- ChangeLog (revision 19878) +++ ChangeLog (revision 19879) @@ -3,6 +3,13 @@ * test/rinda/test_rinda.c (test_core_03_notify): Fixed test failures [ruby-dev:36837]. +Wed Oct 22 00:22:06 2008 Yukihiro Matsumoto <matz@r...> + + * string.c (rb_external_str_new_with_enc): wrong condition to + calculate strlen(). + + * ext/readline/readline.c: add encoding support. + Tue Oct 21 23:12:24 2008 Yukihiro Matsumoto <matz@r...> * ext/stringio/stringio.c (strio_write): should convert writing Index: string.c =================================================================== --- string.c (revision 19878) +++ string.c (revision 19879) @@ -484,7 +484,8 @@ if (!to) return str; if (from == to) return str; - if (rb_enc_asciicompat(to) && ENC_CODERANGE(str) == ENC_CODERANGE_7BIT) { + if ((rb_enc_asciicompat(to) && ENC_CODERANGE(str) == ENC_CODERANGE_7BIT) || + to == rb_ascii8bit_encoding()) { if (STR_ENC_GET(str) != to) { str = rb_str_dup(str); rb_enc_associate(str, to); @@ -528,7 +529,7 @@ { VALUE str; - if (len == 0 && !ptr) len = strlen(ptr); + if (len == 0 && ptr) len = strlen(ptr); str = rb_tainted_str_new(ptr, len); rb_enc_associate(str, eenc); return rb_str_conv_enc(str, eenc, rb_default_internal_encoding()); Index: ext/readline/readline.c =================================================================== --- ext/readline/readline.c (revision 19878) +++ ext/readline/readline.c (revision 19879) @@ -63,6 +63,11 @@ static char **readline_attempted_completion_function(const char *text, int start, int end); +#define OutputStringValue(str) do {\ + SafeStringValue(str);\ + str = rb_str_conv_enc(str, rb_enc_get(str), rb_locale_encoding());\ +} while (0)\ + #ifdef HAVE_RL_EVENT_HOOK #define BUSY_WAIT 0 @@ -214,7 +219,7 @@ rb_secure(4); if (rb_scan_args(argc, argv, "02", &tmp, &add_hist) > 0) { - SafeStringValue(tmp); + OutputStringValue(tmp); prompt = RSTRING_PTR(tmp); } @@ -241,8 +246,7 @@ add_history(buff); } if (buff) { - result = rb_tainted_str_new2(buff); - rb_enc_associate(result, rb_locale_encoding()); + result = rb_locale_str_new(buff, strlen(buff)); } else result = Qnil; @@ -381,7 +385,7 @@ rl_attempted_completion_over = 1; #endif case_fold = RTEST(rb_attr_get(mReadline, completion_case_fold)); - ary = rb_funcall(proc, rb_intern("call"), 1, rb_tainted_str_new2(text)); + ary = rb_funcall(proc, rb_intern("call"), 1, rb_locale_str_new(text, strlen(text))); if (TYPE(ary) != T_ARRAY) ary = rb_Array(ary); matches = RARRAY_LEN(ary); @@ -569,7 +573,7 @@ rl_completion_append_character = '\0'; } else { - SafeStringValue(str); + OutputStringValue(str); if (RSTRING_LEN(str) == 0) { rl_completion_append_character = '\0'; } else { @@ -632,7 +636,7 @@ static char *basic_word_break_characters = NULL; rb_secure(4); - SafeStringValue(str); + OutputStringValue(str); if (basic_word_break_characters == NULL) { basic_word_break_characters = ALLOC_N(char, RSTRING_LEN(str) + 1); @@ -669,7 +673,7 @@ rb_secure(4); if (rl_basic_word_break_characters == NULL) return Qnil; - return rb_tainted_str_new2(rl_basic_word_break_characters); + return rb_locale_str_new(rl_basic_word_break_characters, 0); #else rb_notimplement(); return Qnil; /* not reached */ @@ -695,7 +699,7 @@ static char *completer_word_break_characters = NULL; rb_secure(4); - SafeStringValue(str); + OutputStringValue(str); if (completer_word_break_characters == NULL) { completer_word_break_characters = ALLOC_N(char, RSTRING_LEN(str) + 1); @@ -732,7 +736,7 @@ rb_secure(4); if (rl_completer_word_break_characters == NULL) return Qnil; - return rb_tainted_str_new2(rl_completer_word_break_characters); + return rb_locale_str_new(rl_completer_word_break_characters, 0); #else rb_notimplement(); return Qnil; /* not reached */ @@ -756,7 +760,7 @@ static char *basic_quote_characters = NULL; rb_secure(4); - SafeStringValue(str); + OutputStringValue(str); if (basic_quote_characters == NULL) { basic_quote_characters = ALLOC_N(char, RSTRING_LEN(str) + 1); @@ -793,7 +797,7 @@ rb_secure(4); if (rl_basic_quote_characters == NULL) return Qnil; - return rb_tainted_str_new2(rl_basic_quote_characters); + return rb_locale_str_new(rl_basic_quote_characters, 0); #else rb_notimplement(); return Qnil; /* not reached */ @@ -820,7 +824,7 @@ static char *completer_quote_characters = NULL; rb_secure(4); - SafeStringValue(str); + OutputStringValue(str); if (completer_quote_characters == NULL) { completer_quote_characters = ALLOC_N(char, RSTRING_LEN(str) + 1); @@ -857,7 +861,7 @@ rb_secure(4); if (rl_completer_quote_characters == NULL) return Qnil; - return rb_tainted_str_new2(rl_completer_quote_characters); + return rb_locale_str_new(rl_completer_quote_characters, 0); #else rb_notimplement(); return Qnil; /* not reached */ @@ -882,7 +886,7 @@ static char *filename_quote_characters = NULL; rb_secure(4); - SafeStringValue(str); + OutputStringValue(str); if (filename_quote_characters == NULL) { filename_quote_characters = ALLOC_N(char, RSTRING_LEN(str) + 1); @@ -919,7 +923,7 @@ rb_secure(4); if (rl_filename_quote_characters == NULL) return Qnil; - return rb_tainted_str_new2(rl_filename_quote_characters); + return rb_locale_str_new(rl_filename_quote_characters, 0); #else rb_notimplement(); return Qnil; /* not reached */ @@ -961,7 +965,7 @@ if (entry == NULL) { rb_raise(rb_eIndexError, "invalid index"); } - return rb_tainted_str_new2(entry->line); + return rb_locale_str_new(entry->line, 0); } static VALUE @@ -973,7 +977,7 @@ rb_secure(4); i = NUM2INT(index); - SafeStringValue(str); + OutputStringValue(str); if (i < 0) { i += history_length; } @@ -994,7 +998,7 @@ hist_push(VALUE self, VALUE str) { rb_secure(4); - SafeStringValue(str); + OutputStringValue(str); add_history(RSTRING_PTR(str)); return self; } @@ -1007,7 +1011,7 @@ rb_secure(4); while (argc--) { str = *argv++; - SafeStringValue(str); + OutputStringValue(str); add_history(RSTRING_PTR(str)); } return self; @@ -1023,7 +1027,7 @@ rb_secure(4); entry = remove_history(index); if (entry) { - val = rb_tainted_str_new2(entry->line); + val = rb_locale_str_new(entry->line, 0); free((void *) entry->line); free(entry); return val; @@ -1070,7 +1074,7 @@ entry = history_get(history_get_offset_func(i)); if (entry == NULL) break; - rb_yield(rb_tainted_str_new2(entry->line)); + rb_yield(rb_locale_str_new(entry->line, 0)); } return self; } @@ -1129,7 +1133,7 @@ if (matches) { result = rb_ary_new(); for (i = 0; matches[i]; i++) { - rb_ary_push(result, rb_tainted_str_new2(matches[i])); + rb_ary_push(result, rb_locale_str_new(matches[i], 0)); free(matches[i]); } free(matches); @@ -1154,7 +1158,7 @@ if (matches) { result = rb_ary_new(); for (i = 0; matches[i]; i++) { - rb_ary_push(result, rb_tainted_str_new2(matches[i])); + rb_ary_push(result, rb_locale_str_new(matches[i], 0)); free(matches[i]); } free(matches); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/