ruby-changes:17021
From: nobu <ko1@a...>
Date: Tue, 17 Aug 2010 07:42:59 +0900 (JST)
Subject: [ruby-changes:17021] Ruby:r29018 (trunk): Tue Aug 17 07:42:43 2010 Nobuyoshi Nakada <nobu@r...>
nobu 2010-08-17 07:42:46 +0900 (Tue, 17 Aug 2010) New Revision: 29018 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29018 Log: Tue Aug 17 07:42:43 2010 Nobuyoshi Nakada <nobu@r...> * string.c (str_make_independent_expand): set capacity properly. a patch from Peter Weldon at [ruby-core:31734]. [ruby-core:31653] Modified files: trunk/ChangeLog trunk/string.c Index: ChangeLog =================================================================== --- ChangeLog (revision 29017) +++ ChangeLog (revision 29018) @@ -1,3 +1,8 @@ +Tue Aug 17 07:42:43 2010 Nobuyoshi Nakada <nobu@r...> + + * string.c (str_make_independent_expand): set capacity properly. a + patch from Peter Weldon at [ruby-core:31734]. [ruby-core:31653] + Tue Aug 17 07:38:43 2010 Nobuyoshi Nakada <nobu@r...> * gem_prelude.rb, lib/rubygems.rb (Gem.suffixes): include empty Index: string.c =================================================================== --- string.c (revision 29017) +++ string.c (revision 29018) @@ -1268,18 +1268,19 @@ { char *ptr; long len = RSTRING_LEN(str); + long capa = len + expand; - ptr = ALLOC_N(char, len+expand+1); + if (len > capa) len = capa; + ptr = ALLOC_N(char, capa + 1); if (RSTRING_PTR(str)) { - memcpy(ptr, RSTRING_PTR(str), expand < 0 ? len + expand : len); + memcpy(ptr, RSTRING_PTR(str), len); } - len += expand; STR_SET_NOEMBED(str); + STR_UNSET_NOCAPA(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); + RSTRING(str)->as.heap.aux.capa = capa; } #define str_make_independent(str) str_make_independent_expand(str, 0L) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/