[#29374] nil.to_s — Shugo Maeda <shugo@...>

前田です。

59 messages 2006/09/01
[#29375] Re: nil.to_s — "U.Nakamura" <usa@...> 2006/09/01

こんにちは、なかむら(う)です。

[#29380] Re: nil.to_s — Yukihiro Matsumoto <matz@...> 2006/09/01

まつもと ゆきひろです

[#29387] Re: nil.to_s — Shugo Maeda <shugo@...> 2006/09/01

前田です。

[#29390] Re: nil.to_s — Yukihiro Matsumoto <matz@...> 2006/09/01

まつもと ゆきひろです

[#29398] Re: nil.to_s — "NARUSE, Yui" <naruse@...> 2006/09/01

成瀬です。

[#29400] Re: nil.to_s — Yukihiro Matsumoto <matz@...> 2006/09/01

まつもと ゆきひろです

[#29491] symbol and string — Tanaka Akira <akr@...>

open-uri で :proxy=>nil という指定を行うと、以下のようにエラーになります。

33 messages 2006/09/05
[#29499] Re: symbol and string — Yukihiro Matsumoto <matz@...> 2006/09/05

まつもと ゆきひろです

[#29500] Re: symbol and string — Tanaka Akira <akr@...> 2006/09/05

In article <1157470154.047826.13379.nullmailer@x31.priv.netlab.jp>,

[#29503] Re: symbol and string — Yukihiro Matsumoto <matz@...> 2006/09/06

まつもと ゆきひろです

[#29504] Re: symbol and string — Tanaka Akira <akr@...> 2006/09/06

In article <1157505538.340126.8472.nullmailer@x31.priv.netlab.jp>,

[#29507] Re: symbol and string — Yukihiro Matsumoto <matz@...> 2006/09/06

まつもと ゆきひろです

[#29512] Re: symbol and string — keiju@... (石塚圭樹) 2006/09/06

けいじゅ@いしつかです.

[#29529] Re: symbol and string — SASADA Koichi <ko1@...> 2006/09/08

 ささだです。

[#29530] Re: symbol and string — Yukihiro Matsumoto <matz@...> 2006/09/08

まつもと ゆきひろです

[ruby-dev:29369] Re: File.read produces \0 as the first byte.

From: nobu@...
Date: 2006-09-01 00:17:28 UTC
List: ruby-dev #29369
なかだです。

At Fri, 1 Sep 2006 07:06:58 +0900,
Tanaka Akira wrote in [ruby-dev:29368]:
> File.read で /proc/self/status を読んだときに、最初のバイト
> が \0 になります。

embedからnoembedにresizeするときに既存の内容をコピーしていない
ようです。

ついでに64bit環境だとRSTRING_EMBED_LEN_MASKが足りなくなりそうな
件も。


Index: ruby.h
===================================================================
RCS file: /cvs/ruby/src/ruby/ruby.h,v
retrieving revision 1.148
diff -p -u -2 -r1.148 ruby.h
--- ruby.h	31 Aug 2006 10:47:43 -0000	1.148
+++ ruby.h	1 Sep 2006 00:11:33 -0000
@@ -363,5 +363,5 @@ struct RFloat {
 #define ELTS_SHARED FL_USER2
 
-#define RSTRING_EMBED_LEN_MAX ((sizeof(VALUE)*3)/sizeof(char)-1)
+#define RSTRING_EMBED_LEN_MAX (SIZEOF_VALUE*3-1)
 struct RString {
     struct RBasic basic;
@@ -381,4 +381,8 @@ struct RString {
 #define RSTRING_EMBED_LEN_MASK (FL_USER2|FL_USER3|FL_USER4|FL_USER5)
 #define RSTRING_EMBED_LEN_SHIFT (FL_USHIFT+2)
+#if RSTRING_EMBED_LEN_MAX > (RSTRING_EMBED_LEN_MASK >> RSTRING_EMBED_LEN_SHIFT)
+#undef RSTRING_EMBED_LEN_MAX
+#define RSTRING_EMBED_LEN_MAX (RSTRING_EMBED_LEN_MASK >> RSTRING_EMBED_LEN_SHIFT)
+#endif
 #define RSTRING_LEN(str) \
     (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
Index: string.c
===================================================================
RCS file: /cvs/ruby/src/ruby/string.c,v
retrieving revision 1.258
diff -p -u -2 -r1.258 string.c
--- string.c	31 Aug 2006 10:47:43 -0000	1.258
+++ string.c	1 Sep 2006 00:12:08 -0000
@@ -683,4 +683,5 @@ rb_str_resize(VALUE str, long len)
     if (len != RSTRING_LEN(str)) {
 	if (STR_EMBED_P(str)) {
+	    char *ptr;
 	    if (len <= RSTRING_EMBED_LEN_MAX) {
 		STR_SET_EMBED_LEN(str, len);
@@ -688,5 +689,7 @@ rb_str_resize(VALUE str, long len)
 		return str;
 	    }
-	    RSTRING(str)->as.heap.ptr = ALLOC_N(char,len+1);
+	    ptr = ALLOC_N(char, len+1);
+	    MEMCPY(ptr, RSTRING(str)->ary, char, RSTRING_LEN(str));
+	    RSTRING(str)->as.heap.ptr = ptr;
 	    STR_SET_NOEMBED(str);
 	}
@@ -4166,5 +4169,5 @@ rb_str_ord(VALUE s)
     if (RSTRING_LEN(s) != 1) {
 	rb_raise(rb_eTypeError,
-		 "expacted a characer, but string of size %d given",
+		 "expacted a characer, but string of size %ld given",
 		 RSTRING_LEN(s));
     }


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread