mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #256 from masamitsu-murase/modify_string_slice
"slice" of shared string returns invalid result
This commit is contained in:
+5
-5
@@ -1199,14 +1199,14 @@ mrb_str_eql(mrb_state *mrb, mrb_value self)
|
||||
static mrb_value
|
||||
mrb_str_subseq(mrb_state *mrb, mrb_value str, int beg, int len)
|
||||
{
|
||||
struct RString *s;
|
||||
struct RString *orig, *s;
|
||||
struct mrb_shared_string *shared;
|
||||
|
||||
s = mrb_str_ptr(str);
|
||||
str_make_shared(mrb, s);
|
||||
shared = s->aux.shared;
|
||||
orig = mrb_str_ptr(str);
|
||||
str_make_shared(mrb, orig);
|
||||
shared = orig->aux.shared;
|
||||
s = mrb_obj_alloc_string(mrb);
|
||||
s->ptr = shared->ptr + beg;
|
||||
s->ptr = orig->ptr + beg;
|
||||
s->len = len;
|
||||
s->aux.shared = shared;
|
||||
s->flags |= MRB_STR_SHARED;
|
||||
|
||||
+4
-1
@@ -256,6 +256,9 @@ assert('String#slice', '15.2.10.5.34') do
|
||||
d1 = 'abc'.slice(0, 0)
|
||||
e1 = 'abc'.slice(1, 2)
|
||||
|
||||
# slice of shared string
|
||||
e11 = e1.slice(0)
|
||||
|
||||
# args is RegExp
|
||||
# TODO SEGFAULT ATM
|
||||
|
||||
@@ -265,7 +268,7 @@ assert('String#slice', '15.2.10.5.34') do
|
||||
|
||||
a == 'a' and b == 'c' and c == nil and d == nil and
|
||||
a1 == nil and b1 == nil and c1 == nil and d1 == '' and
|
||||
e1 == 'bc' and
|
||||
e1 == 'bc' and e11 == 'b' and
|
||||
a3 == 'bc' and b3 == nil
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user