summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-11 07:15:24 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-11 07:15:24 +0000
commitc5c201f6242b15e00a2f158c30bb196c0455f87f (patch)
tree376c91f4d2f630e23f4946f73dff971c136befec /array.c
parent4cdd6f6ab8abb1b960a7cdbe3f932b6a792787a5 (diff)
array.c: fix false assertion in ary_make_shared
* array.c (ary_shrink_capa): shrink the capacity so it fits just with the length. * array.c (ary_make_shared): release never used elements from frozen array to be shared. [ruby-dev:47416] [Bug #8510] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/array.c b/array.c
index 8ef0b86..eed646b 100644
--- a/array.c
+++ b/array.c
@@ -180,6 +180,16 @@ ary_resize_capa(VALUE ary, long capacity)
}
static void
+ary_shrink_capa(VALUE ary)
+{
+ long capacity = ARY_HEAP_LEN(ary);
+ long old_capa = RARRAY(ary)->as.heap.aux.capa;
+ assert(old_capa >= capacity);
+ if (old_capa > capacity)
+ REALLOC_N(RARRAY(ary)->as.heap.ptr, VALUE, capacity);
+}
+
+static void
ary_double_capa(VALUE ary, long min)
{
long new_capa = ARY_CAPA(ary) / 2;
@@ -510,7 +520,7 @@ ary_make_shared(VALUE ary)
return ary;
}
else if (OBJ_FROZEN(ary)) {
- ary_resize_capa(ary, ARY_HEAP_LEN(ary));
+ ary_shrink_capa(ary);
FL_SET_SHARED_ROOT(ary);
ARY_SET_SHARED_NUM(ary, 1);
return ary;