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

ruby-changes:37917

From: ko1 <ko1@a...>
Date: Wed, 18 Mar 2015 05:38:22 +0900 (JST)
Subject: [ruby-changes:37917] ko1:r49998 (trunk): * string.c: introduce STR_FAKESTR to show string is FAKESTR or not.

ko1	2015-03-18 05:38:02 +0900 (Wed, 18 Mar 2015)

  New Revision: 49998

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49998

  Log:
    * string.c: introduce STR_FAKESTR to show string is FAKESTR or not.
    * string.c (STR_SET_SHARED): ignore FAKESTR because only Ruby objects
      can use write barrier.

  Modified files:
    trunk/ChangeLog
    trunk/string.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49997)
+++ ChangeLog	(revision 49998)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Mar 18 05:34:32 2015  Koichi Sasada  <ko1@a...>
+
+	* string.c: introduce STR_FAKESTR to show string is FAKESTR or not.
+
+	* string.c (STR_SET_SHARED): ignore FAKESTR because only Ruby objects
+	  can use write barrier.
+
 Tue Mar 17 18:59:16 2015  Koichi Sasada  <ko1@a...>
 
 	* include/ruby/ruby.h: use rb_gc_writebrrier() simply.
Index: string.c
===================================================================
--- string.c	(revision 49997)
+++ string.c	(revision 49998)
@@ -52,9 +52,22 @@ static VALUE rb_str_clear(VALUE str); https://github.com/ruby/ruby/blob/trunk/string.c#L52
 VALUE rb_cString;
 VALUE rb_cSymbol;
 
+/* FLAGS of RString
+ *
+ * 1:     RSTRING_NOEMBED
+ * 2:     STR_SHARED (== ELTS_SHARED)
+ * 2-6:   RSTRING_EMBED_LEN (5 bits == 32)
+ * 7:     STR_TMPLOCK
+ * 8-9:   ENC_CODERANGE (2 bits)
+ * 10-16: ENCODING (7 bits == 128)
+ * 18:    STR_NOFREE
+ * 19:    STR_FAKESTR
+ */
+
 #define RUBY_MAX_CHAR_LEN 16
 #define STR_TMPLOCK FL_USER7
 #define STR_NOFREE FL_USER18
+#define STR_FAKESTR FL_USER19
 
 #define STR_SET_NOEMBED(str) do {\
     FL_SET((str), STR_NOEMBED);\
@@ -120,8 +133,10 @@ VALUE rb_cSymbol; https://github.com/ruby/ruby/blob/trunk/string.c#L133
 } while (0)
 
 #define STR_SET_SHARED(str, shared_str) do { \
-    RB_OBJ_WRITE((str), &RSTRING(str)->as.heap.aux.shared, (shared_str)); \
-    FL_SET((str), STR_SHARED); \
+    if (!FL_TEST(str, STR_FAKESTR)) { \
+	RB_OBJ_WRITE((str), &RSTRING(str)->as.heap.aux.shared, (shared_str)); \
+	FL_SET((str), STR_SHARED); \
+    } \
 } while (0)
 
 #define STR_HEAP_PTR(str)  (RSTRING(str)->as.heap.ptr)
@@ -262,7 +277,7 @@ rb_fstring(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L277
 static VALUE
 setup_fake_str(struct RString *fake_str, const char *name, long len, int encidx)
 {
-    fake_str->basic.flags = T_STRING|RSTRING_NOEMBED|STR_NOFREE;
+    fake_str->basic.flags = T_STRING|RSTRING_NOEMBED|STR_NOFREE|STR_FAKESTR;
     /* SHARED to be allocated by the callback */
 
     ENCODING_SET_INLINED((VALUE)fake_str, encidx);

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

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