Tue Aug 17 07:42:43 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (str_make_independent_expand): set capacity properly. a patch from Peter Weldon at [ruby-core:31734]. [ruby-core:31653] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29018 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0afddf7b0a
commit
94fc95c8b0
@ -1,3 +1,8 @@
|
|||||||
|
Tue Aug 17 07:42:43 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Tue Aug 17 07:38:43 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* gem_prelude.rb, lib/rubygems.rb (Gem.suffixes): include empty
|
* gem_prelude.rb, lib/rubygems.rb (Gem.suffixes): include empty
|
||||||
|
11
string.c
11
string.c
@ -1268,18 +1268,19 @@ str_make_independent_expand(VALUE str, long expand)
|
|||||||
{
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
long len = RSTRING_LEN(str);
|
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)) {
|
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_SET_NOEMBED(str);
|
||||||
|
STR_UNSET_NOCAPA(str);
|
||||||
ptr[len] = 0;
|
ptr[len] = 0;
|
||||||
RSTRING(str)->as.heap.ptr = ptr;
|
RSTRING(str)->as.heap.ptr = ptr;
|
||||||
RSTRING(str)->as.heap.len = len;
|
RSTRING(str)->as.heap.len = len;
|
||||||
RSTRING(str)->as.heap.aux.capa = len;
|
RSTRING(str)->as.heap.aux.capa = capa;
|
||||||
STR_UNSET_NOCAPA(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define str_make_independent(str) str_make_independent_expand(str, 0L)
|
#define str_make_independent(str) str_make_independent_expand(str, 0L)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user