* 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,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
|
* test/rinda/test_rinda.c (test_core_03_notify): Fixed test failures
|
||||||
[ruby-dev:36837].
|
[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>
|
Tue Oct 21 23:12:24 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* ext/stringio/stringio.c (strio_write): should convert writing
|
* 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,
|
static char **readline_attempted_completion_function(const char *text,
|
||||||
int start, int end);
|
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
|
#ifdef HAVE_RL_EVENT_HOOK
|
||||||
#define BUSY_WAIT 0
|
#define BUSY_WAIT 0
|
||||||
|
|
||||||
@ -214,7 +219,7 @@ readline_readline(int argc, VALUE *argv, VALUE self)
|
|||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
if (rb_scan_args(argc, argv, "02", &tmp, &add_hist) > 0) {
|
if (rb_scan_args(argc, argv, "02", &tmp, &add_hist) > 0) {
|
||||||
SafeStringValue(tmp);
|
OutputStringValue(tmp);
|
||||||
prompt = RSTRING_PTR(tmp);
|
prompt = RSTRING_PTR(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,8 +246,7 @@ readline_readline(int argc, VALUE *argv, VALUE self)
|
|||||||
add_history(buff);
|
add_history(buff);
|
||||||
}
|
}
|
||||||
if (buff) {
|
if (buff) {
|
||||||
result = rb_tainted_str_new2(buff);
|
result = rb_locale_str_new(buff, strlen(buff));
|
||||||
rb_enc_associate(result, rb_locale_encoding());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
result = Qnil;
|
result = Qnil;
|
||||||
@ -381,7 +385,7 @@ readline_attempted_completion_function(const char *text, int start, int end)
|
|||||||
rl_attempted_completion_over = 1;
|
rl_attempted_completion_over = 1;
|
||||||
#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_tainted_str_new2(text));
|
ary = rb_funcall(proc, rb_intern("call"), 1, rb_locale_str_new(text, strlen(text)));
|
||||||
if (TYPE(ary) != T_ARRAY)
|
if (TYPE(ary) != T_ARRAY)
|
||||||
ary = rb_Array(ary);
|
ary = rb_Array(ary);
|
||||||
matches = RARRAY_LEN(ary);
|
matches = RARRAY_LEN(ary);
|
||||||
@ -569,7 +573,7 @@ readline_s_set_completion_append_character(VALUE self, VALUE str)
|
|||||||
rl_completion_append_character = '\0';
|
rl_completion_append_character = '\0';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SafeStringValue(str);
|
OutputStringValue(str);
|
||||||
if (RSTRING_LEN(str) == 0) {
|
if (RSTRING_LEN(str) == 0) {
|
||||||
rl_completion_append_character = '\0';
|
rl_completion_append_character = '\0';
|
||||||
} else {
|
} else {
|
||||||
@ -632,7 +636,7 @@ readline_s_set_basic_word_break_characters(VALUE self, VALUE str)
|
|||||||
static char *basic_word_break_characters = NULL;
|
static char *basic_word_break_characters = NULL;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
SafeStringValue(str);
|
OutputStringValue(str);
|
||||||
if (basic_word_break_characters == NULL) {
|
if (basic_word_break_characters == NULL) {
|
||||||
basic_word_break_characters =
|
basic_word_break_characters =
|
||||||
ALLOC_N(char, RSTRING_LEN(str) + 1);
|
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);
|
rb_secure(4);
|
||||||
if (rl_basic_word_break_characters == NULL)
|
if (rl_basic_word_break_characters == NULL)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
return rb_tainted_str_new2(rl_basic_word_break_characters);
|
return rb_locale_str_new(rl_basic_word_break_characters, 0);
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
return Qnil; /* not reached */
|
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;
|
static char *completer_word_break_characters = NULL;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
SafeStringValue(str);
|
OutputStringValue(str);
|
||||||
if (completer_word_break_characters == NULL) {
|
if (completer_word_break_characters == NULL) {
|
||||||
completer_word_break_characters =
|
completer_word_break_characters =
|
||||||
ALLOC_N(char, RSTRING_LEN(str) + 1);
|
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);
|
rb_secure(4);
|
||||||
if (rl_completer_word_break_characters == NULL)
|
if (rl_completer_word_break_characters == NULL)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
return rb_tainted_str_new2(rl_completer_word_break_characters);
|
return rb_locale_str_new(rl_completer_word_break_characters, 0);
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
return Qnil; /* not reached */
|
return Qnil; /* not reached */
|
||||||
@ -756,7 +760,7 @@ readline_s_set_basic_quote_characters(VALUE self, VALUE str)
|
|||||||
static char *basic_quote_characters = NULL;
|
static char *basic_quote_characters = NULL;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
SafeStringValue(str);
|
OutputStringValue(str);
|
||||||
if (basic_quote_characters == NULL) {
|
if (basic_quote_characters == NULL) {
|
||||||
basic_quote_characters =
|
basic_quote_characters =
|
||||||
ALLOC_N(char, RSTRING_LEN(str) + 1);
|
ALLOC_N(char, RSTRING_LEN(str) + 1);
|
||||||
@ -793,7 +797,7 @@ readline_s_get_basic_quote_characters(VALUE self, VALUE str)
|
|||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
if (rl_basic_quote_characters == NULL)
|
if (rl_basic_quote_characters == NULL)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
return rb_tainted_str_new2(rl_basic_quote_characters);
|
return rb_locale_str_new(rl_basic_quote_characters, 0);
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
return Qnil; /* not reached */
|
return Qnil; /* not reached */
|
||||||
@ -820,7 +824,7 @@ readline_s_set_completer_quote_characters(VALUE self, VALUE str)
|
|||||||
static char *completer_quote_characters = NULL;
|
static char *completer_quote_characters = NULL;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
SafeStringValue(str);
|
OutputStringValue(str);
|
||||||
if (completer_quote_characters == NULL) {
|
if (completer_quote_characters == NULL) {
|
||||||
completer_quote_characters =
|
completer_quote_characters =
|
||||||
ALLOC_N(char, RSTRING_LEN(str) + 1);
|
ALLOC_N(char, RSTRING_LEN(str) + 1);
|
||||||
@ -857,7 +861,7 @@ readline_s_get_completer_quote_characters(VALUE self, VALUE str)
|
|||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
if (rl_completer_quote_characters == NULL)
|
if (rl_completer_quote_characters == NULL)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
return rb_tainted_str_new2(rl_completer_quote_characters);
|
return rb_locale_str_new(rl_completer_quote_characters, 0);
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
return Qnil; /* not reached */
|
return Qnil; /* not reached */
|
||||||
@ -882,7 +886,7 @@ readline_s_set_filename_quote_characters(VALUE self, VALUE str)
|
|||||||
static char *filename_quote_characters = NULL;
|
static char *filename_quote_characters = NULL;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
SafeStringValue(str);
|
OutputStringValue(str);
|
||||||
if (filename_quote_characters == NULL) {
|
if (filename_quote_characters == NULL) {
|
||||||
filename_quote_characters =
|
filename_quote_characters =
|
||||||
ALLOC_N(char, RSTRING_LEN(str) + 1);
|
ALLOC_N(char, RSTRING_LEN(str) + 1);
|
||||||
@ -919,7 +923,7 @@ readline_s_get_filename_quote_characters(VALUE self, VALUE str)
|
|||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
if (rl_filename_quote_characters == NULL)
|
if (rl_filename_quote_characters == NULL)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
return rb_tainted_str_new2(rl_filename_quote_characters);
|
return rb_locale_str_new(rl_filename_quote_characters, 0);
|
||||||
#else
|
#else
|
||||||
rb_notimplement();
|
rb_notimplement();
|
||||||
return Qnil; /* not reached */
|
return Qnil; /* not reached */
|
||||||
@ -961,7 +965,7 @@ hist_get(VALUE self, VALUE index)
|
|||||||
if (entry == NULL) {
|
if (entry == NULL) {
|
||||||
rb_raise(rb_eIndexError, "invalid index");
|
rb_raise(rb_eIndexError, "invalid index");
|
||||||
}
|
}
|
||||||
return rb_tainted_str_new2(entry->line);
|
return rb_locale_str_new(entry->line, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -973,7 +977,7 @@ hist_set(VALUE self, VALUE index, VALUE str)
|
|||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
i = NUM2INT(index);
|
i = NUM2INT(index);
|
||||||
SafeStringValue(str);
|
OutputStringValue(str);
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
i += history_length;
|
i += history_length;
|
||||||
}
|
}
|
||||||
@ -994,7 +998,7 @@ static VALUE
|
|||||||
hist_push(VALUE self, VALUE str)
|
hist_push(VALUE self, VALUE str)
|
||||||
{
|
{
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
SafeStringValue(str);
|
OutputStringValue(str);
|
||||||
add_history(RSTRING_PTR(str));
|
add_history(RSTRING_PTR(str));
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -1007,7 +1011,7 @@ hist_push_method(int argc, VALUE *argv, VALUE self)
|
|||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
while (argc--) {
|
while (argc--) {
|
||||||
str = *argv++;
|
str = *argv++;
|
||||||
SafeStringValue(str);
|
OutputStringValue(str);
|
||||||
add_history(RSTRING_PTR(str));
|
add_history(RSTRING_PTR(str));
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@ -1023,7 +1027,7 @@ rb_remove_history(int index)
|
|||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
entry = remove_history(index);
|
entry = remove_history(index);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
val = rb_tainted_str_new2(entry->line);
|
val = rb_locale_str_new(entry->line, 0);
|
||||||
free((void *) entry->line);
|
free((void *) entry->line);
|
||||||
free(entry);
|
free(entry);
|
||||||
return val;
|
return val;
|
||||||
@ -1070,7 +1074,7 @@ hist_each(VALUE self)
|
|||||||
entry = history_get(history_get_offset_func(i));
|
entry = history_get(history_get_offset_func(i));
|
||||||
if (entry == NULL)
|
if (entry == NULL)
|
||||||
break;
|
break;
|
||||||
rb_yield(rb_tainted_str_new2(entry->line));
|
rb_yield(rb_locale_str_new(entry->line, 0));
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -1129,7 +1133,7 @@ filename_completion_proc_call(VALUE self, VALUE str)
|
|||||||
if (matches) {
|
if (matches) {
|
||||||
result = rb_ary_new();
|
result = rb_ary_new();
|
||||||
for (i = 0; matches[i]; i++) {
|
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[i]);
|
||||||
}
|
}
|
||||||
free(matches);
|
free(matches);
|
||||||
@ -1154,7 +1158,7 @@ username_completion_proc_call(VALUE self, VALUE str)
|
|||||||
if (matches) {
|
if (matches) {
|
||||||
result = rb_ary_new();
|
result = rb_ary_new();
|
||||||
for (i = 0; matches[i]; i++) {
|
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[i]);
|
||||||
}
|
}
|
||||||
free(matches);
|
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 (!to) return str;
|
||||||
if (from == 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) {
|
if (STR_ENC_GET(str) != to) {
|
||||||
str = rb_str_dup(str);
|
str = rb_str_dup(str);
|
||||||
rb_enc_associate(str, to);
|
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;
|
VALUE str;
|
||||||
|
|
||||||
if (len == 0 && !ptr) len = strlen(ptr);
|
if (len == 0 && ptr) len = strlen(ptr);
|
||||||
str = rb_tainted_str_new(ptr, len);
|
str = rb_tainted_str_new(ptr, len);
|
||||||
rb_enc_associate(str, eenc);
|
rb_enc_associate(str, eenc);
|
||||||
return rb_str_conv_enc(str, eenc, rb_default_internal_encoding());
|
return rb_str_conv_enc(str, eenc, rb_default_internal_encoding());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user