[前][次][番号順一覧][スレッド一覧]

ruby-changes:3327

From: ko1@a...
Date: 1 Jan 2008 00:04:46 +0900
Subject: [ruby-changes:3327] nobu - Ruby:r14817 (trunk): * string.c (rb_str_resize): embeds if ptr is null.

nobu	2007-12-31 23:27:20 +0900 (Mon, 31 Dec 2007)

  New Revision: 14817

  Modified files:
    trunk/ChangeLog
    trunk/bootstraptest/test_knownbug.rb
    trunk/string.c
    trunk/test/ruby/test_string.rb

  Log:
    * string.c (rb_str_resize): embeds if ptr is null.  [ruby-dev:32819]


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_string.rb?r1=14817&r2=14816
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/string.c?r1=14817&r2=14816
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14817&r2=14816
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bootstraptest/test_knownbug.rb?r1=14817&r2=14816

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14816)
+++ ChangeLog	(revision 14817)
@@ -1,3 +1,7 @@
+Mon Dec 31 23:27:17 2007  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (rb_str_resize): embeds if ptr is null.  [ruby-dev:32819]
+
 Mon Dec 31 23:17:22 2007  GOTOU Yuuzou  <gotoyuzo@n...>
 
 	* lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#proxy_service):
Index: bootstraptest/test_knownbug.rb
===================================================================
--- bootstraptest/test_knownbug.rb	(revision 14816)
+++ bootstraptest/test_knownbug.rb	(revision 14817)
@@ -4,11 +4,6 @@
 #
 
 assert_normal_exit %q{
-  null = File.exist?("/dev/null") ? "/dev/null" : "NUL" # maybe DOSISH
-  File.read(null).clone
-}, '[ruby-dev:32819] reported by Kazuhiro NISHIYAMA'
-
-assert_normal_exit %q{
   class Foo
      def self.add_method
        class_eval("def some-bad-name; puts 'hello' unless @some_variable.some_function(''); end")
Index: string.c
===================================================================
--- string.c	(revision 14816)
+++ string.c	(revision 14817)
@@ -924,25 +924,37 @@
 VALUE
 rb_str_resize(VALUE str, long len)
 {
+    long slen;
+
     if (len < 0) {
 	rb_raise(rb_eArgError, "negative string size (or size too big)");
     }
 
     rb_str_modify(str);
-    if (len != RSTRING_LEN(str)) {
+    slen = RSTRING_LEN(str);
+    if (len != slen) {
 	if (STR_EMBED_P(str)) {
 	    char *ptr;
 	    if (len <= RSTRING_EMBED_LEN_MAX) {
 		STR_SET_EMBED_LEN(str, len);
-		RSTRING_PTR(str)[len] = '\0';
+		RSTRING(str)->as.ary[len] = '\0';
 		return str;
 	    }
 	    ptr = ALLOC_N(char,len+1);
-	    MEMCPY(ptr, RSTRING_PTR(str), char, RSTRING_LEN(str));
+	    MEMCPY(ptr, RSTRING(str)->as.ary, char, slen);
 	    RSTRING(str)->as.heap.ptr = ptr;
 	    STR_SET_NOEMBED(str);
 	}
-	else if (RSTRING_LEN(str) < len || RSTRING_LEN(str) - len > 1024) {
+	else if (len <= RSTRING_EMBED_LEN_MAX) {
+	    char *ptr = RSTRING(str)->as.heap.ptr;
+	    STR_SET_EMBED(str);
+	    MEMCPY(RSTRING(str)->as.ary, ptr, char, len);
+	    RSTRING(str)->as.ary[len] = '\0';
+	    STR_SET_EMBED_LEN(str, len);
+	    xfree(ptr);
+	    return str;
+	}
+	else if (slen < len || slen - len > 1024) {
 	    REALLOC_N(RSTRING(str)->as.heap.ptr, char, len+1);
 	}
 	if (!STR_NOCAPA_P(str)) {
Index: test/ruby/test_string.rb
===================================================================
--- test/ruby/test_string.rb	(revision 14816)
+++ test/ruby/test_string.rb	(revision 14817)
@@ -368,6 +368,9 @@
         assert_equal(a.tainted?, b.tainted?)
       end
     end
+
+    null = File.exist?("/dev/null") ? "/dev/null" : "NUL" # maybe DOSISH
+    assert_equal("", File.read(null).clone, '[ruby-dev:32819] reported by Kazuhiro NISHIYAMA')
   end
 
   def test_concat

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]