なかだです。

  String だけ dup したときに extend したモジュールが引き継がれないよう
ですが、そういうもんでしょうか。引き継いでくれた方がありがたいような気
がするんですが、ひょっとして rb_str_new{3,4}() まではやりすぎ?


Sun Jun 18 16:29:34 2000 Nobuyoshi Nakada <nobu.nakada / nifty.ne.jp> * string.c (rb_str_setup): newly added. instantiates a new string which is kind of String. * string.c (rb_str_new): now a wrapper to rb_str_setup() which instantiates String. * string.c (rb_str_new3, rb_str_new4, rb_str_dup): new string is an instance of the class of the original string.
Index: string.c =================================================================== RCS file: /home/cvs/ruby/string.c,v retrieving revision 1.36 diff -u -2 -p -r1.36 string.c --- string.c 2000/06/16 07:44:04 1.36 +++ string.c 2000/06/18 07:28:10 @@ -31,12 +31,12 @@ VALUE rb_cString; VALUE rb_fs; -VALUE -rb_str_new(ptr, len) +static VALUE +rb_str_setup(klass, ptr, len) + VALUE klass; const char *ptr; long len; { NEWOBJ(str, struct RString); - OBJSETUP(str, rb_cString, T_STRING); - + OBJSETUP(str, klass, T_STRING); str->ptr = 0; str->len = len; @@ -51,4 +51,12 @@ rb_str_new(ptr, len) VALUE +rb_str_new(ptr, len) + const char *ptr; + long len; +{ + return rb_str_setup(rb_cString, ptr, len); +} + +VALUE rb_str_new2(ptr) const char *ptr; @@ -83,5 +91,5 @@ rb_str_new3(str) { NEWOBJ(str2, struct RString); - OBJSETUP(str2, rb_cString, T_STRING); + OBJSETUP(str2, RBASIC(str)->klass, T_STRING); str2->len = RSTRING(str)->len; @@ -104,5 +112,5 @@ rb_str_new4(orig) else { NEWOBJ(str, struct RString); - OBJSETUP(str, rb_cString, T_STRING); + OBJSETUP(str, RBASIC(orig)->klass, T_STRING); str->len = RSTRING(orig)->len; @@ -186,12 +194,10 @@ rb_str_dup(str) if (OBJ_FROZEN(str)) return rb_str_new3(str); if (FL_TEST(str, STR_NO_ORIG)) { - str2 = rb_str_new(RSTRING(str)->ptr, RSTRING(str)->len); + str2 = rb_str_setup(RBASIC(str)->klass, RSTRING(str)->ptr, RSTRING(str)->len); OBJ_INFECT(str2, str); return str2; } if (RSTRING(str)->orig) { - str2 = rb_str_new3(RSTRING(str)->orig); - OBJ_INFECT(str2, str); - return str2; + return rb_str_new3(RSTRING(str)->orig); } @@ -199,5 +205,5 @@ rb_str_dup(str) { NEWOBJ(dup, struct RString); - OBJSETUP(dup, rb_cString, T_STRING); + OBJSETUP(dup, RBASIC(str)->klass, T_STRING); dup->len = RSTRING(str2)->len; dup->ptr = RSTRING(str2)->ptr;
-- そうだ 強気に ちょっと インチキに☆彡 中田 "Bugるくらいがちょうどいいかも;-)" 伸悦