mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (rb_external_str_new_with_enc): wrong condition to
calculate strlen(). * ext/readline/readline.c: add encoding support. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
73e221a1be
commit
fa127bbb18
3 changed files with 37 additions and 25 deletions
|
@ -3,6 +3,13 @@ Wed Oct 22 00:29:13 2008 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
|||
* 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@ruby-lang.org>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* ext/stringio/stringio.c (strio_write): should convert writing
|
||||
|
|
|
@ -63,6 +63,11 @@ static int (*history_get_offset_func)(int);
|
|||
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 @@ readline_readline(int argc, VALUE *argv, VALUE self)
|
|||
|
||||
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 @@ readline_readline(int argc, VALUE *argv, VALUE self)
|
|||
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 @@ readline_attempted_completion_function(const char *text, int start, int end)
|
|||
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 @@ readline_s_set_completion_append_character(VALUE self, VALUE str)
|
|||
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 @@ readline_s_set_basic_word_break_characters(VALUE self, VALUE str)
|
|||
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 @@ readline_s_get_basic_word_break_characters(VALUE self, VALUE str)
|
|||
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 @@ readline_s_set_completer_word_break_characters(VALUE self, VALUE str)
|
|||
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 @@ readline_s_get_completer_word_break_characters(VALUE self, VALUE str)
|
|||
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 @@ readline_s_set_basic_quote_characters(VALUE self, VALUE str)
|
|||
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 @@ readline_s_get_basic_quote_characters(VALUE self, VALUE str)
|
|||
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 @@ readline_s_set_completer_quote_characters(VALUE self, VALUE str)
|
|||
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 @@ readline_s_get_completer_quote_characters(VALUE self, VALUE str)
|
|||
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 @@ readline_s_set_filename_quote_characters(VALUE self, VALUE str)
|
|||
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 @@ readline_s_get_filename_quote_characters(VALUE self, VALUE str)
|
|||
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 @@ hist_get(VALUE self, VALUE index)
|
|||
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 @@ hist_set(VALUE self, VALUE index, VALUE str)
|
|||
|
||||
rb_secure(4);
|
||||
i = NUM2INT(index);
|
||||
SafeStringValue(str);
|
||||
OutputStringValue(str);
|
||||
if (i < 0) {
|
||||
i += history_length;
|
||||
}
|
||||
|
@ -994,7 +998,7 @@ static VALUE
|
|||
hist_push(VALUE self, VALUE str)
|
||||
{
|
||||
rb_secure(4);
|
||||
SafeStringValue(str);
|
||||
OutputStringValue(str);
|
||||
add_history(RSTRING_PTR(str));
|
||||
return self;
|
||||
}
|
||||
|
@ -1007,7 +1011,7 @@ hist_push_method(int argc, VALUE *argv, VALUE self)
|
|||
rb_secure(4);
|
||||
while (argc--) {
|
||||
str = *argv++;
|
||||
SafeStringValue(str);
|
||||
OutputStringValue(str);
|
||||
add_history(RSTRING_PTR(str));
|
||||
}
|
||||
return self;
|
||||
|
@ -1023,7 +1027,7 @@ rb_remove_history(int index)
|
|||
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 @@ hist_each(VALUE self)
|
|||
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 @@ filename_completion_proc_call(VALUE self, VALUE str)
|
|||
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 @@ username_completion_proc_call(VALUE self, VALUE str)
|
|||
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);
|
||||
|
|
5
string.c
5
string.c
|
@ -484,7 +484,8 @@ rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
|
|||
|
||||
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 @@ rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *eenc)
|
|||
{
|
||||
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());
|
||||
|
|
Loading…
Reference in a new issue