1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* string.c (str_make_independent): should set length.

* string.c (rb_str_associate): hide associated array from ObjectSpace.

* string.c (rb_str_associated): return associated array with freezing
  instead of false.  [ruby-dev:33282]

* string.c (rb_str_freeze): freeze associated array together.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-01-23 06:04:13 +00:00
parent ce49faf546
commit e94ece76d8
3 changed files with 34 additions and 2 deletions

View file

@ -1,3 +1,14 @@
Wed Jan 23 15:04:11 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (str_make_independent): should set length.
* string.c (rb_str_associate): hide associated array from ObjectSpace.
* string.c (rb_str_associated): return associated array with freezing
instead of false. [ruby-dev:33282]
* string.c (rb_str_freeze): freeze associated array together.
Wed Jan 23 13:39:48 2008 Tanaka Akira <akr@fsij.org>
* re.c (rb_reg_prepare_re): fix SEGV by

View file

@ -742,6 +742,7 @@ str_make_independent(VALUE str)
STR_SET_NOEMBED(str);
ptr[len] = 0;
RSTRING(str)->as.heap.ptr = ptr;
RSTRING(str)->as.heap.len = len;
RSTRING(str)->as.heap.aux.capa = len;
STR_UNSET_NOCAPA(str);
}
@ -771,6 +772,7 @@ rb_str_associate(VALUE str, VALUE add)
RESIZE_CAPA(str, RSTRING_LEN(str));
}
FL_SET(str, STR_ASSOC);
RBASIC(add)->klass = 0;
RSTRING(str)->as.heap.aux.shared = add;
}
}
@ -779,8 +781,9 @@ VALUE
rb_str_associated(VALUE str)
{
if (STR_ASSOC_P(str)) {
if (OBJ_FROZEN(str)) return Qfalse;
return RSTRING(str)->as.heap.aux.shared;
VALUE ary = RSTRING(str)->as.heap.aux.shared;
if (OBJ_FROZEN(str)) OBJ_FREEZE(ary);
return ary;
}
return Qfalse;
}
@ -953,6 +956,10 @@ rb_str_substr(VALUE str, long beg, long len)
VALUE
rb_str_freeze(VALUE str)
{
if (STR_ASSOC_P(str)) {
VALUE ary = RSTRING(str)->as.heap.aux.shared;
OBJ_FREEZE(ary);
}
return rb_obj_freeze(str);
}

View file

@ -57,4 +57,18 @@ class TestPack < Test::Unit::TestCase
assert_raises(RangeError) { [0x80000000].pack("U") }
assert_raises(RangeError) { [0x100000000].pack("U") }
end
def test_pack_P
a = ["abc"]
assert_equal a, a.pack("P").unpack("P*")
assert_equal "a", a.pack("P").unpack("P")[0]
assert_equal a, a.pack("P").freeze.unpack("P*")
end
def test_pack_p
a = ["abc"]
assert_equal a, a.pack("p").unpack("p*")
assert_equal a[0], a.pack("p").unpack("p")[0]
assert_equal a, a.pack("p").freeze.unpack("p*")
end
end