ruby-changes:2007
From: ko1@a...
Date: 23 Sep 2007 17:20:22 +0900
Subject: [ruby-changes:2007] shyouhei - Ruby:r13498 (ruby_1_8): Sorry nobu, reverting r13473, which turned out to be a SEGV-generator.
shyouhei 2007-09-23 17:20:11 +0900 (Sun, 23 Sep 2007) New Revision: 13498 Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/string.c Log: Sorry nobu, reverting r13473, which turned out to be a SEGV-generator. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=13498&r2=13497 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/string.c?r1=13498&r2=13497 Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 13497) +++ ruby_1_8/ChangeLog (revision 13498) @@ -36,11 +36,6 @@ * eval.c, intern.h, ext/thread/thread.c: should not free queue while any live threads are waiting. [ruby-dev:30653] -Fri Sep 21 01:46:19 2007 Nobuyoshi Nakada <nobu@r...> - - * string.c (str_alloc): defaults to null_str instead of NULL. - [ruby-dev:31774] - Thu Sep 20 17:24:59 2007 Nobuyoshi Nakada <nobu@r...> * process.c (rb_detach_process): cast for the platforms where size of Index: ruby_1_8/string.c =================================================================== --- ruby_1_8/string.c (revision 13497) +++ ruby_1_8/string.c (revision 13498) @@ -59,17 +59,13 @@ } } -static VALUE str_alloc0 _((VALUE, int)); static VALUE str_alloc _((VALUE)); -static VALUE str_alloc1 _((VALUE)); - static VALUE -str_alloc0(klass, flags) +str_alloc(klass) VALUE klass; - int flags; { NEWOBJ(str, struct RString); - OBJSETUP(str, klass, flags); + OBJSETUP(str, klass, T_STRING); str->ptr = 0; str->len = 0; @@ -78,26 +74,7 @@ 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; const char *ptr; @@ -109,7 +86,7 @@ rb_raise(rb_eArgError, "negative string size (or size too big)"); } - str = str_alloc1(klass); + str = str_alloc(klass); RSTRING(str)->len = len; RSTRING(str)->aux.capa = len; RSTRING(str)->ptr = ALLOC_N(char,len+1); @@ -168,6 +145,7 @@ RSTRING(str2)->len = RSTRING(str)->len; RSTRING(str2)->ptr = RSTRING(str)->ptr; RSTRING(str2)->aux.shared = str; + FL_SET(str2, ELTS_SHARED); return str2; } @@ -186,7 +164,7 @@ str_new4(klass, str) VALUE klass, str; { - VALUE str2 = str_alloc1(klass); + VALUE str2 = str_alloc(klass); RSTRING(str2)->len = RSTRING(str)->len; RSTRING(str2)->ptr = RSTRING(str)->ptr; @@ -245,7 +223,7 @@ rb_str_buf_new(capa) long capa; { - VALUE str = str_alloc1(rb_cString); + VALUE str = str_alloc(rb_cString); if (capa < STR_BUF_MIN_SIZE) { capa = STR_BUF_MIN_SIZE; @@ -279,14 +257,13 @@ 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; - if (str_independent(str)) xfree(RSTRING(str)->ptr); + rb_str_modify(str); + if (!FL_TEST(str, ELTS_SHARED)) free(RSTRING(str)->ptr); if (NIL_P(str2)) { RSTRING(str)->ptr = 0; RSTRING(str)->len = 0; @@ -561,6 +538,8 @@ return Qfalse; } +static char *null_str = ""; + VALUE rb_string_value(ptr) volatile VALUE *ptr; @@ -2286,11 +2265,8 @@ 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)) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml