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

ruby-changes:30099

From: ko1 <ko1@a...>
Date: Wed, 24 Jul 2013 18:42:54 +0900 (JST)
Subject: [ruby-changes:30099] ko1:r42151 (trunk): * array.c, gc.c: move ary_unprotect_logging() into

ko1	2013-07-24 18:42:43 +0900 (Wed, 24 Jul 2013)

  New Revision: 42151

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

  Log:
    * array.c, gc.c: move ary_unprotect_logging() into
      rb_gc_unprotect_logging() which is general version
    * include/ruby/ruby.h: add USE_RGENGC_LOGGING_WB_UNPROTECT
      to enable.

  Modified files:
    trunk/ChangeLog
    trunk/array.c
    trunk/gc.c
    trunk/include/ruby/ruby.h

Index: array.c
===================================================================
--- array.c	(revision 42150)
+++ array.c	(revision 42151)
@@ -11,12 +11,6 @@ https://github.com/ruby/ruby/blob/trunk/array.c#L11
 
 **********************************************************************/
 
-#define RGENGC_UNPROTECT_LOGGING 0
-#if RGENGC_UNPROTECT_LOGGING
-static void ary_unprotect_logging(void *x, const char *filename, int line);
-#define RGENGC_LOGGING_WB_UNPROTECT(x, f, l) ary_unprotect_logging((void *)x, f, l)
-#endif
-
 #include "ruby/ruby.h"
 #include "ruby/util.h"
 #include "ruby/st.h"
@@ -37,46 +31,6 @@ static ID id_cmp, id_div, id_power; https://github.com/ruby/ruby/blob/trunk/array.c#L31
 #define ARY_DEFAULT_SIZE 16
 #define ARY_MAX_SIZE (LONG_MAX / (int)sizeof(VALUE))
 
-#if RGENGC_UNPROTECT_LOGGING
-static st_table *ary_unprotect_logging_table;
-
-static void
-ary_unprotect_logging(void *objptr, const char *filename, int line)
-{
-    VALUE obj = (VALUE)objptr;
-
-    if (OBJ_WB_PROTECTED(obj)) {
-	char buff[0x100];
-	st_data_t cnt = 1;
-	char *ptr = buff;
-
-	snprintf(ptr, 0x100 - 1, "%s:%d", filename, line);
-
-	if (st_lookup(ary_unprotect_logging_table, (st_data_t)ptr, &cnt)) {
-	    cnt++;
-	}
-	else {
-	    ptr = (char *)malloc(strlen(buff) + 1);
-	    strcpy(ptr, buff);
-	}
-	st_insert(ary_unprotect_logging_table, (st_data_t)ptr, cnt);
-    }
-}
-
-static int
-ary_unprotect_logging_exit_func_i(st_data_t key, st_data_t val)
-{
-    fprintf(stderr, "%s\t%d\n", (char *)key, (int)val);
-    return ST_CONTINUE;
-}
-
-static void
-ary_unprotect_logging_exit_func(void)
-{
-    st_foreach(ary_unprotect_logging_table, ary_unprotect_logging_exit_func_i, 0);
-}
-#endif
-
 void
 rb_mem_clear(register VALUE *mem, register long size)
 {
@@ -5559,11 +5513,6 @@ Init_Array(void) https://github.com/ruby/ruby/blob/trunk/array.c#L5513
     rb_cArray  = rb_define_class("Array", rb_cObject);
     rb_include_module(rb_cArray, rb_mEnumerable);
 
-#if RGENGC_UNPROTECT_LOGGING
-    ary_unprotect_logging_table = st_init_strtable();
-    atexit(ary_unprotect_logging_exit_func);
-#endif
-
     rb_define_alloc_func(rb_cArray, empty_ary_alloc);
     rb_define_singleton_method(rb_cArray, "[]", rb_ary_s_create, -1);
     rb_define_singleton_method(rb_cArray, "try_convert", rb_ary_s_try_convert, 1);
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 42150)
+++ include/ruby/ruby.h	(revision 42151)
@@ -1266,11 +1266,16 @@ void rb_gc_writebarrier_unprotect_promot https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1266
 #define OBJ_WRITE(a, slot, b)       rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__)
 #define OBJ_WRITTEN(a, oldv, b)     rb_obj_written((VALUE)(a), (VALUE)(oldv), (VALUE)(b), __FILE__, __LINE__)
 
+#if USE_RGENGC_LOGGING_WB_UNPROTECT
+void rb_gc_unprotect_logging(void *objptr, const char *filename, int line);
+#define RGENGC_LOGGING_WB_UNPROTECT rb_gc_unprotect_logging
+#endif
+
 static inline VALUE
 rb_obj_wb_unprotect(VALUE x, const char *filename, int line)
 {
 #ifdef RGENGC_LOGGING_WB_UNPROTECT
-    RGENGC_LOGGING_WB_UNPROTECT(x, filename, line);
+    RGENGC_LOGGING_WB_UNPROTECT((void *)x, filename, line);
 #endif
 
 #if USE_RGENGC
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42150)
+++ ChangeLog	(revision 42151)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jul 24 18:40:11 2013  Koichi Sasada  <ko1@a...>
+
+	* array.c, gc.c: move ary_unprotect_logging() into
+	  rb_gc_unprotect_logging() which is general version
+
+	* include/ruby/ruby.h: add USE_RGENGC_LOGGING_WB_UNPROTECT
+	  to enable.
+
 Wed Jul 24 17:37:50 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* file.c (rb_file_expand_path_internal): preserve the file name
Index: gc.c
===================================================================
--- gc.c	(revision 42150)
+++ gc.c	(revision 42151)
@@ -3909,6 +3909,49 @@ rb_gc_writebarrier_remember_promoted(VAL https://github.com/ruby/ruby/blob/trunk/gc.c#L3909
     rgengc_remember(objspace, obj);
 }
 
+static st_table *rgengc_unprotect_logging_table;
+
+static int
+rgengc_unprotect_logging_exit_func_i(st_data_t key, st_data_t val)
+{
+    fprintf(stderr, "%s\t%d\n", (char *)key, (int)val);
+    return ST_CONTINUE;
+}
+
+static void
+rgengc_unprotect_logging_exit_func(void)
+{
+    st_foreach(rgengc_unprotect_logging_table, rgengc_unprotect_logging_exit_func_i, 0);
+}
+
+void
+rb_gc_unprotect_logging(void *objptr, const char *filename, int line)
+{
+    VALUE obj = (VALUE)objptr;
+
+    if (rgengc_unprotect_logging_table == 0) {
+	rgengc_unprotect_logging_table = st_init_strtable();
+	atexit(rgengc_unprotect_logging_exit_func);
+    }
+
+    if (OBJ_WB_PROTECTED(obj)) {
+	char buff[0x100];
+	st_data_t cnt = 1;
+	char *ptr = buff;
+
+	snprintf(ptr, 0x100 - 1, "%s|%s:%d", obj_type_name(obj), filename, line);
+
+	if (st_lookup(rgengc_unprotect_logging_table, (st_data_t)ptr, &cnt)) {
+	    cnt++;
+	}
+	else {
+	    ptr = (char *)malloc(strlen(buff) + 1);
+	    strcpy(ptr, buff);
+	}
+	st_insert(rgengc_unprotect_logging_table, (st_data_t)ptr, cnt);
+    }
+}
+
 #endif /* USE_RGENGC */
 
 /* RGENGC analysis information */

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

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