From b21b9a46cfadc785f0001b2b34edc0392d79161b Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 20 Sep 2007 16:46:21 +0000 Subject: * string.c (str_alloc): defaults to null_str instead of NULL. [ruby-dev:31774] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@13473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ string.c | 46 +++++++++++++++++++++++++++++++++++----------- version.h | 6 +++--- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8ff0550d39..6ae570373b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Sep 21 01:46:19 2007 Nobuyoshi Nakada + + * string.c (str_alloc): defaults to null_str instead of NULL. + [ruby-dev:31774] + Thu Sep 20 17:24:59 2007 Nobuyoshi Nakada * process.c (rb_detach_process): cast for the platforms where size of diff --git a/string.c b/string.c index cc27550ebe..108a2af128 100644 --- a/string.c +++ b/string.c @@ -59,13 +59,17 @@ str_frozen_check(s) } } +static VALUE str_alloc0 _((VALUE, int)); static VALUE str_alloc _((VALUE)); +static VALUE str_alloc1 _((VALUE)); + static VALUE -str_alloc(klass) +str_alloc0(klass, flags) VALUE klass; + int flags; { NEWOBJ(str, struct RString); - OBJSETUP(str, klass, T_STRING); + OBJSETUP(str, klass, flags); str->ptr = 0; str->len = 0; @@ -74,6 +78,25 @@ str_alloc(klass) return (VALUE)str; } +static const char null_str[] = ""; +#define null_str (char *)null_str + +static VALUE +str_alloc(klass) + VALUE klass; +{ + VALUE str = str_alloc0(klass, T_STRING | ELTS_SHARED); + RSTRING(str)->ptr = null_str; + return str; +} + +static VALUE +str_alloc1(klass) + VALUE klass; +{ + return str_alloc0(klass, T_STRING); +} + static VALUE str_new(klass, ptr, len) VALUE klass; @@ -86,7 +109,7 @@ str_new(klass, ptr, len) rb_raise(rb_eArgError, "negative string size (or size too big)"); } - str = str_alloc(klass); + str = str_alloc1(klass); RSTRING(str)->len = len; RSTRING(str)->aux.capa = len; RSTRING(str)->ptr = ALLOC_N(char,len+1); @@ -145,7 +168,6 @@ str_new3(klass, str) RSTRING(str2)->len = RSTRING(str)->len; RSTRING(str2)->ptr = RSTRING(str)->ptr; RSTRING(str2)->aux.shared = str; - FL_SET(str2, ELTS_SHARED); return str2; } @@ -164,7 +186,7 @@ static VALUE str_new4(klass, str) VALUE klass, str; { - VALUE str2 = str_alloc(klass); + VALUE str2 = str_alloc1(klass); RSTRING(str2)->len = RSTRING(str)->len; RSTRING(str2)->ptr = RSTRING(str)->ptr; @@ -223,7 +245,7 @@ VALUE rb_str_buf_new(capa) long capa; { - VALUE str = str_alloc(rb_cString); + VALUE str = str_alloc1(rb_cString); if (capa < STR_BUF_MIN_SIZE) { capa = STR_BUF_MIN_SIZE; @@ -257,13 +279,14 @@ rb_str_to_str(str) return rb_convert_type(str, T_STRING, "String", "to_str"); } +static int str_independent _((VALUE)); + static void rb_str_shared_replace(str, str2) VALUE str, str2; { if (str == str2) return; - rb_str_modify(str); - if (!FL_TEST(str, ELTS_SHARED)) free(RSTRING(str)->ptr); + if (str_independent(str)) xfree(RSTRING(str)->ptr); if (NIL_P(str2)) { RSTRING(str)->ptr = 0; RSTRING(str)->len = 0; @@ -538,8 +561,6 @@ rb_str_associated(str) return Qfalse; } -static char *null_str = ""; - VALUE rb_string_value(ptr) volatile VALUE *ptr; @@ -2265,8 +2286,11 @@ rb_str_replace(str, str2) FL_UNSET(str, STR_ASSOC); RSTRING(str)->aux.shared = RSTRING(str2)->aux.shared; } + else if (!RSTRING(str2)->len) { + FL_SET(str, ELTS_SHARED); + RSTRING(str)->ptr = null_str; + } else { - rb_str_modify(str); rb_str_resize(str, RSTRING(str2)->len); memcpy(RSTRING(str)->ptr, RSTRING(str2)->ptr, RSTRING(str2)->len); if (FL_TEST(str2, STR_ASSOC)) { diff --git a/version.h b/version.h index 0ea1e7bf98..21414b7ec0 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.8.6" -#define RUBY_RELEASE_DATE "2007-09-20" +#define RUBY_RELEASE_DATE "2007-09-21" #define RUBY_VERSION_CODE 186 -#define RUBY_RELEASE_CODE 20070920 +#define RUBY_RELEASE_CODE 20070921 #define RUBY_PATCHLEVEL 5000 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 6 #define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_MONTH 9 -#define RUBY_RELEASE_DAY 20 +#define RUBY_RELEASE_DAY 21 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; -- cgit v1.2.3