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

* string.c: Partially reverts r55547 and r55555.

ChangeLog about the reverted changes are also deleted in this file.
  [Bug #12536] [ruby-dev:49699] [ruby-dev:49702]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55559 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ngoto 2016-07-01 18:11:11 +00:00
parent bc1d7b1649
commit 3418a277d8
2 changed files with 12 additions and 30 deletions

View file

@ -1,3 +1,9 @@
Sat Jul 2 03:09:27 2016 Naohisa Goto <ngotogenome@gmail.com>
* string.c: Partially reverts r55547 and r55555.
ChangeLog about the reverted changes are also deleted in this file.
[Bug #12536] [ruby-dev:49699] [ruby-dev:49702]
Sat Jul 2 02:22:22 2016 Naohisa Goto <ngotogenome@gmail.com>
* string.c (str_fill_term): When termlen increases, re-allocation
@ -10,15 +16,6 @@ Fri Jul 1 20:20:20 2016 Naohisa Goto <ngotogenome@gmail.com>
* string.c: Specify termlen as far as possible.
Additional fix for [Bug #12536] [ruby-dev:49699].
* string.c (rb_usascii_str_new, rb_utf8_str_new): Specify termlen
which is apparently 1 for the encodings.
* string.c (str_new0_cstr): New static function to create a String
object from a C string with specifying termlen.
* string.c (rb_usascii_str_new_cstr, rb_utf8_str_new_cstr): Specify
termlen by using new str_new0_cstr().
* string.c (str_new_static): Specify termlen from the given encoding
when creating a new String object is needed.
@ -67,13 +64,6 @@ Thu Jun 30 19:15:13 2016 Naohisa Goto <ngotogenome@gmail.com>
* string.c: Fix memory corruptions when using UTF-16/32 strings.
[Bug #12536] [ruby-dev:49699]
* string.c (TERM_LEN_MAX): Macro for the longest TERM_FILL length,
the same as largest value of rb_enc_mbminlen(enc) among encodings.
* string.c (str_new, rb_str_buf_new, str_shared_replace): Allocate
+TERM_LEN_MAX bytes instead of +1. This change may increase memory
usage.
* string.c (rb_str_new_with_class): Use TERM_LEN of the "obj".
* string.c (rb_str_plus, rb_str_justify): Use str_new0 which is aware

View file

@ -120,7 +120,6 @@ VALUE rb_cSymbol;
if (UNLIKELY(term_fill_len > 1))\
memset(term_fill_ptr, 0, term_fill_len);\
} while (0)
#define TERM_LEN_MAX 4 /* UTF-32LE, UTF-32BE */
#define RESIZE_CAPA(str,capacity) do {\
const int termlen = TERM_LEN(str);\
@ -714,7 +713,7 @@ str_new0(VALUE klass, const char *ptr, long len, int termlen)
static VALUE
str_new(VALUE klass, const char *ptr, long len)
{
return str_new0(klass, ptr, len, TERM_LEN_MAX);
return str_new0(klass, ptr, len, 1);
}
VALUE
@ -726,7 +725,7 @@ rb_str_new(const char *ptr, long len)
VALUE
rb_usascii_str_new(const char *ptr, long len)
{
VALUE str = str_new0(rb_cString, ptr, len, 1); /* termlen == 1 */
VALUE str = rb_str_new(ptr, len);
ENCODING_CODERANGE_SET(str, rb_usascii_encindex(), ENC_CODERANGE_7BIT);
return str;
}
@ -734,7 +733,7 @@ rb_usascii_str_new(const char *ptr, long len)
VALUE
rb_utf8_str_new(const char *ptr, long len)
{
VALUE str = str_new0(rb_cString, ptr, len, 1); /* termlen == 1 */
VALUE str = str_new(rb_cString, ptr, len);
rb_enc_associate_index(str, rb_utf8_encindex());
return str;
}
@ -758,17 +757,10 @@ rb_str_new_cstr(const char *ptr)
return rb_str_new(ptr, strlen(ptr));
}
static VALUE
str_new0_cstr(const char *ptr, int termlen)
{
must_not_null(ptr);
return str_new0(rb_cString, ptr, strlen(ptr), termlen);
}
VALUE
rb_usascii_str_new_cstr(const char *ptr)
{
VALUE str = str_new0_cstr(ptr, 1); /* termlen == 1 */
VALUE str = rb_str_new_cstr(ptr);
ENCODING_CODERANGE_SET(str, rb_usascii_encindex(), ENC_CODERANGE_7BIT);
return str;
}
@ -776,7 +768,7 @@ rb_usascii_str_new_cstr(const char *ptr)
VALUE
rb_utf8_str_new_cstr(const char *ptr)
{
VALUE str = str_new0_cstr(ptr, 1); /* termlen == 1 */
VALUE str = rb_str_new_cstr(ptr);
rb_enc_associate_index(str, rb_utf8_encindex());
return str;
}
@ -1202,7 +1194,7 @@ rb_str_buf_new(long capa)
}
FL_SET(str, STR_NOEMBED);
RSTRING(str)->as.heap.aux.capa = capa;
RSTRING(str)->as.heap.ptr = ALLOC_N(char, capa + TERM_LEN_MAX);
RSTRING(str)->as.heap.ptr = ALLOC_N(char, capa+1);
RSTRING(str)->as.heap.ptr[0] = '\0';
return str;