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

ruby-changes:35228

From: normal <ko1@a...>
Date: Fri, 29 Aug 2014 15:30:23 +0900 (JST)
Subject: [ruby-changes:35228] normal:r47310 (trunk): string.c: move frozen_strings table to rb_vm_t

normal	2014-08-29 15:30:03 +0900 (Fri, 29 Aug 2014)

  New Revision: 47310

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

  Log:
    string.c: move frozen_strings table to rb_vm_t
    
    Cleanup in case MVM development proceeds.
    
    * string.c: remove static frozen_strings
    * string.c (Init_frozen_strings): new function
    * string.c (rb_fstring): remove check for frozen strings,
      use per-VM table
    * string.c (rb_str_free): use per-VM table
    * string.c (Init_String): use per-VM table
    * vm_core.h (rb_vm_t): add frozen_strings table
    * internal.h (Init_frozen_strings): new function prototype
    * eval.c (ruby_setup): call Init_frozen_strings
      [Feature #10182]

  Modified files:
    trunk/ChangeLog
    trunk/common.mk
    trunk/eval.c
    trunk/internal.h
    trunk/string.c
    trunk/vm_core.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47309)
+++ ChangeLog	(revision 47310)
@@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Aug 29 15:17:13 2014  Eric Wong  <e@8...>
+
+	* string.c: remove static frozen_strings
+	* string.c (Init_frozen_strings): new function
+	* string.c (rb_fstring): remove check for frozen strings,
+	  use per-VM table
+	* string.c (rb_str_free): use per-VM table
+	* string.c (Init_String): use per-VM table
+	* vm_core.h (rb_vm_t): add frozen_strings table
+	* internal.h (Init_frozen_strings): new function prototype
+	* eval.c (ruby_setup): call Init_frozen_strings
+	  [Feature #10182]
+
 Wed Aug 27 23:10:24 2014  Masaki Matsushita <glass.saga@g...>
 
 	* lib/tempfile.rb: remove "require 'thread'". its features are no
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 47309)
+++ vm_core.h	(revision 47310)
@@ -430,6 +430,7 @@ typedef struct rb_vm_struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L430
     struct RArray at_exit;
 
     VALUE *defined_strings;
+    st_table *frozen_strings;
 
     /* params */
     struct { /* size in byte */
Index: string.c
===================================================================
--- string.c	(revision 47309)
+++ string.c	(revision 47310)
@@ -17,6 +17,7 @@ https://github.com/ruby/ruby/blob/trunk/string.c#L17
 #include "internal.h"
 #include "probes.h"
 #include "gc.h"
+#include "vm_core.h"
 #include <assert.h>
 
 #define BEG(no) (regs->beg[(no)])
@@ -176,8 +177,6 @@ mustnot_broken(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L177
 
 static int fstring_cmp(VALUE a, VALUE b);
 
-static st_table* frozen_strings;
-
 static const struct st_hash_type fstring_hash_type = {
     fstring_cmp,
     rb_str_hash,
@@ -223,15 +222,13 @@ rb_fstring(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L222
 
     Check_Type(str, T_STRING);
 
-    if (!frozen_strings)
-	frozen_strings = st_init_table(&fstring_hash_type);
-
     if (FL_TEST(str, RSTRING_FSTR))
 	return str;
 
     do {
 	ret = str;
-	st_update(frozen_strings, (st_data_t)str, fstr_update_callback, (st_data_t)&ret);
+	st_update(GET_VM()->frozen_strings, (st_data_t)str,
+		    fstr_update_callback, (st_data_t)&ret);
     } while (ret == Qundef);
 
     return ret;
@@ -952,7 +949,7 @@ rb_str_free(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L949
 {
     if (FL_TEST(str, RSTRING_FSTR)) {
 	st_data_t fstr = (st_data_t)str;
-	st_delete(frozen_strings, &fstr, NULL);
+	st_delete(GET_VM()->frozen_strings, &fstr, NULL);
     }
 
     if (!STR_EMBED_P(str) && !FL_TEST(str, STR_SHARED)) {
@@ -8950,6 +8947,13 @@ Init_String(void) https://github.com/ruby/ruby/blob/trunk/string.c#L8947
 
     rb_define_method(rb_cSymbol, "encoding", sym_encoding, 0);
 
-    if (frozen_strings)
-	st_foreach(frozen_strings, fstring_set_class_i, rb_cString);
+    assert(GET_VM()->frozen_strings);
+    st_foreach(GET_VM()->frozen_strings, fstring_set_class_i, rb_cString);
+}
+
+void
+Init_frozen_strings(void)
+{
+    assert(!GET_VM()->frozen_strings);
+    GET_VM()->frozen_strings = st_init_table(&fstring_hash_type);
 }
Index: common.mk
===================================================================
--- common.mk	(revision 47309)
+++ common.mk	(revision 47310)
@@ -777,7 +777,8 @@ st.$(OBJEXT): {$(VPATH)}st.c $(RUBY_H_IN https://github.com/ruby/ruby/blob/trunk/common.mk#L777
 strftime.$(OBJEXT): {$(VPATH)}strftime.c $(RUBY_H_INCLUDES) \
   {$(VPATH)}timev.h $(ENCODING_H_INCLUDES)
 string.$(OBJEXT): {$(VPATH)}string.c $(RUBY_H_INCLUDES) {$(VPATH)}re.h {$(VPATH)}gc.h \
-  {$(VPATH)}regex.h $(ENCODING_H_INCLUDES) {$(VPATH)}internal.h $(PROBES_H_INCLUDES)
+  {$(VPATH)}regex.h $(ENCODING_H_INCLUDES) {$(VPATH)}internal.h \
+  $(PROBES_H_INCLUDES) $(VM_CORE_H_INCLUDES)
 struct.$(OBJEXT): {$(VPATH)}struct.c $(RUBY_H_INCLUDES) {$(VPATH)}internal.h
 symbol.$(OBJEXT): {$(VPATH)}symbol.c $(RUBY_H_INCLUDES) $(ENCODING_H_INCLUDES) \
   {$(VPATH)}internal.h {$(VPATH)}node.h {$(VPATH)}id.h {$(VPATH)}symbol.h \
Index: eval.c
===================================================================
--- eval.c	(revision 47309)
+++ eval.c	(revision 47310)
@@ -52,6 +52,7 @@ ruby_setup(void) https://github.com/ruby/ruby/blob/trunk/eval.c#L52
     Init_BareVM();
     Init_heap();
     Init_vm_objects();
+    Init_frozen_strings();
 
     PUSH_TAG();
     if ((state = EXEC_TAG()) == 0) {
Index: internal.h
===================================================================
--- internal.h	(revision 47309)
+++ internal.h	(revision 47310)
@@ -891,6 +891,7 @@ size_t rb_strftime(char *s, size_t maxsi https://github.com/ruby/ruby/blob/trunk/internal.h#L891
 #endif
 
 /* string.c */
+void Init_frozen_strings(void);
 VALUE rb_fstring(VALUE);
 VALUE rb_fstring_new(const char *ptr, long len);
 #ifdef RUBY_ENCODING_H

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

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