ruby-changes:29175
From: nobu <ko1@a...>
Date: Tue, 11 Jun 2013 16:15:35 +0900 (JST)
Subject: [ruby-changes:29175] nobu:r41227 (trunk): array.c: fix false assertion in ary_make_shared
nobu 2013-06-11 16:15:24 +0900 (Tue, 11 Jun 2013) New Revision: 41227 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41227 Log: 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] Modified files: trunk/ChangeLog trunk/array.c Index: array.c =================================================================== --- array.c (revision 41226) +++ array.c (revision 41227) @@ -180,6 +180,16 @@ ary_resize_capa(VALUE ary, long capacity https://github.com/ruby/ruby/blob/trunk/array.c#L180 } 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) https://github.com/ruby/ruby/blob/trunk/array.c#L520 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; Index: ChangeLog =================================================================== --- ChangeLog (revision 41226) +++ ChangeLog (revision 41227) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Jun 11 16:15:03 2013 Nobuyoshi Nakada <nobu@r...> + + * 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] + Tue Jun 11 12:49:01 2013 Zachary Scott <zachary@z...> * doc/re.rdoc: Rename to doc/regexp.rdoc -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/