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

ruby-changes:42559

From: naruse <ko1@a...>
Date: Mon, 18 Apr 2016 16:18:56 +0900 (JST)
Subject: [ruby-changes:42559] naruse:r54633 (ruby_2_3): merge revision(s) 54484: [Backport #12095]

naruse	2016-04-18 17:15:33 +0900 (Mon, 18 Apr 2016)

  New Revision: 54633

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

  Log:
    merge revision(s) 54484: [Backport #12095]
    
    * vm_core.h (rb_vm_struct): make at_exit a single linked list but
      not RArray, not to mark the registered functions by the write
      barrier.  based on the patches by Evan Phoenix.
      [ruby-core:73908] [Bug #12095]

  Added directories:
    branches/ruby_2_3/ext/-test-/vm/
    branches/ruby_2_3/test/-ext-/vm/
  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/ChangeLog
    branches/ruby_2_3/version.h
    branches/ruby_2_3/vm.c
    branches/ruby_2_3/vm_core.h
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 54632)
+++ ruby_2_3/version.h	(revision 54633)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.0"
 #define RUBY_RELEASE_DATE "2016-04-18"
-#define RUBY_PATCHLEVEL 88
+#define RUBY_PATCHLEVEL 89
 
 #define RUBY_RELEASE_YEAR 2016
 #define RUBY_RELEASE_MONTH 4
Index: ruby_2_3/vm.c
===================================================================
--- ruby_2_3/vm.c	(revision 54632)
+++ ruby_2_3/vm.c	(revision 54633)
@@ -468,20 +468,25 @@ rb_frame_pop(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/vm.c#L468
 void
 ruby_vm_at_exit(void (*func)(rb_vm_t *))
 {
-    rb_ary_push((VALUE)&GET_VM()->at_exit, (VALUE)func);
+    rb_vm_t *vm = GET_VM();
+    rb_at_exit_list *nl = ALLOC(rb_at_exit_list);
+    nl->func = func;
+    nl->next = vm->at_exit;
+    vm->at_exit = nl;
 }
 
 static void
 ruby_vm_run_at_exit_hooks(rb_vm_t *vm)
 {
-    VALUE hook = (VALUE)&vm->at_exit;
+    rb_at_exit_list *l = vm->at_exit;
 
-    while (RARRAY_LEN(hook) > 0) {
-	typedef void rb_vm_at_exit_func(rb_vm_t*);
-	rb_vm_at_exit_func *func = (rb_vm_at_exit_func*)rb_ary_pop(hook);
+    while (l) {
+	rb_at_exit_list* t = l->next;
+	rb_vm_at_exit_func *func = l->func;
+	free(l);
+	l = t;
 	(*func)(vm);
     }
-    rb_ary_free(hook);
 }
 
 /* Env */
@@ -2170,8 +2175,6 @@ vm_init2(rb_vm_t *vm) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/vm.c#L2175
     MEMZERO(vm, rb_vm_t, 1);
     rb_vm_living_threads_init(vm);
     vm->src_encoding_index = -1;
-    vm->at_exit.basic.flags = (T_ARRAY | RARRAY_EMBED_FLAG) & ~RARRAY_EMBED_LEN_MASK; /* len set 0 */
-    rb_obj_hide((VALUE)&vm->at_exit);
 
     vm_default_params_setup(vm);
 }
Index: ruby_2_3/ext/-test-/vm/extconf.rb
===================================================================
--- ruby_2_3/ext/-test-/vm/extconf.rb	(revision 0)
+++ ruby_2_3/ext/-test-/vm/extconf.rb	(revision 54633)
@@ -0,0 +1 @@
+create_makefile('-test-/vm/at_exit')

Property changes on: ruby_2_3/ext/-test-/vm/extconf.rb
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ruby_2_3/ext/-test-/vm/at_exit.c
===================================================================
--- ruby_2_3/ext/-test-/vm/at_exit.c	(revision 0)
+++ ruby_2_3/ext/-test-/vm/at_exit.c	(revision 54633)
@@ -0,0 +1,44 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ext/-test-/vm/at_exit.c#L1
+#include <ruby/ruby.h>
+#include <ruby/vm.h>
+
+static void
+do_nothing(ruby_vm_t *vm)
+{
+}
+
+static void
+print_begin(ruby_vm_t *vm)
+{
+    printf("begin\n");
+}
+
+static void
+print_end(ruby_vm_t *vm)
+{
+    printf("end\n");
+}
+
+static VALUE
+register_at_exit(VALUE self, VALUE t)
+{
+    switch (t) {
+      case Qtrue:
+	ruby_vm_at_exit(print_begin);
+	break;
+      case Qfalse:
+	ruby_vm_at_exit(print_end);
+	break;
+      default:
+	ruby_vm_at_exit(do_nothing);
+	break;
+    }
+    return self;
+}
+
+void
+Init_at_exit(void)
+{
+    VALUE m = rb_define_module("Bug");
+    VALUE c = rb_define_class_under(m, "VM", rb_cObject);
+    rb_define_singleton_method(c, "register_at_exit", register_at_exit, 1);
+}

Property changes on: ruby_2_3/ext/-test-/vm/at_exit.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ruby_2_3/test/-ext-/vm/test_at_exit.rb
===================================================================
--- ruby_2_3/test/-ext-/vm/test_at_exit.rb	(revision 0)
+++ ruby_2_3/test/-ext-/vm/test_at_exit.rb	(revision 54633)
@@ -0,0 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/-ext-/vm/test_at_exit.rb#L1
+# frozen_string_literal: false
+class TestVM < Test::Unit::TestCase
+
+  # [Bug #12095]
+  def test_at_exit
+
+    assert_in_out_err([], <<-"end;", %w[begin end]) # do
+      require '-test-/vm/at_exit'
+      Bug::VM.register_at_exit(false)
+      1000.times do
+        Bug::VM.register_at_exit(nil)
+        ["x"]*1000
+      end
+      GC.start
+      Bug::VM.register_at_exit(true)
+    end;
+  end
+end
+

Property changes on: ruby_2_3/test/-ext-/vm/test_at_exit.rb
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ruby_2_3/ChangeLog
===================================================================
--- ruby_2_3/ChangeLog	(revision 54632)
+++ ruby_2_3/ChangeLog	(revision 54633)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1
+Mon Apr 18 17:08:10 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_core.h (rb_vm_struct): make at_exit a single linked list but
+	  not RArray, not to mark the registered functions by the write
+	  barrier.  based on the patches by Evan Phoenix.
+	  [ruby-core:73908] [Bug #12095]
+
 Mon Apr 18 16:56:31 2016  Benoit Daloze  <eregontp@g...>
 
 	* thread.c (update_coverage): Do not track coverage in loaded files
Index: ruby_2_3/vm_core.h
===================================================================
--- ruby_2_3/vm_core.h	(revision 54632)
+++ ruby_2_3/vm_core.h	(revision 54633)
@@ -459,6 +459,14 @@ enum ruby_basic_operators { https://github.com/ruby/ruby/blob/trunk/ruby_2_3/vm_core.h#L459
 #define GetVMPtr(obj, ptr) \
   GetCoreDataFromValue((obj), rb_vm_t, (ptr))
 
+struct rb_vm_struct;
+typedef void rb_vm_at_exit_func(struct rb_vm_struct*);
+
+typedef struct rb_at_exit_list {
+    rb_vm_at_exit_func *func;
+    struct rb_at_exit_list *next;
+} rb_at_exit_list;
+
 struct rb_objspace;
 struct rb_objspace *rb_objspace_alloc(void);
 void rb_objspace_free(struct rb_objspace *);
@@ -527,11 +535,7 @@ typedef struct rb_vm_struct { https://github.com/ruby/ruby/blob/trunk/ruby_2_3/vm_core.h#L535
 
     struct rb_objspace *objspace;
 
-    /*
-     * @shyouhei notes that this is not for storing normal Ruby
-     * objects so do *NOT* mark this when you GC.
-     */
-    struct RArray at_exit;
+    rb_at_exit_list *at_exit;
 
     VALUE *defined_strings;
     st_table *frozen_strings;

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r54484


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

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