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

ruby-changes:35452

From: ko1 <ko1@a...>
Date: Thu, 11 Sep 2014 19:53:55 +0900 (JST)
Subject: [ruby-changes:35452] ko1:r47534 (trunk): * vm.c (rb_vm_register_special_exception): make new function to

ko1	2014-09-11 19:53:48 +0900 (Thu, 11 Sep 2014)

  New Revision: 47534

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

  Log:
    * vm.c (rb_vm_register_special_exception): make new function to
      make and register special exceptions.
    * vm.c (rb_vm_mark): do not need to mark special exceptions
      because they are registerd by rb_gc_register_mark_object().
    * eval.c (Init_eval): use rb_vm_register_special_exception().
    * gc.c (Init_GC): ditto.
    * proc.c (Init_Proc): ditto.
    * thread.c (Init_Thread): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/eval.c
    trunk/gc.c
    trunk/proc.c
    trunk/thread.c
    trunk/vm.c
    trunk/vm_core.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47533)
+++ ChangeLog	(revision 47534)
@@ -1,3 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Sep 11 19:50:57 2014  Koichi Sasada  <ko1@a...>
+
+	* vm.c (rb_vm_register_special_exception): make new function to
+	  make and register special exceptions.
+
+	* vm.c (rb_vm_mark): do not need to mark special exceptions
+	  because they are registerd by rb_gc_register_mark_object().
+
+	* eval.c (Init_eval): use rb_vm_register_special_exception().
+
+	* gc.c (Init_GC): ditto.
+
+	* proc.c (Init_Proc): ditto.
+
+	* thread.c (Init_Thread): ditto.
+
 Thu Sep 11 19:32:30 2014  Koichi Sasada  <ko1@a...>
 
 	* gc.c (rb_gc_mark_values): added.
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 47533)
+++ vm_core.h	(revision 47534)
@@ -383,7 +383,7 @@ typedef struct rb_vm_struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L383
     /* object management */
     VALUE mark_object_ary;
 
-    VALUE special_exceptions[ruby_special_error_count];
+    const VALUE special_exceptions[ruby_special_error_count];
 
     /* load */
     VALUE top_self;
@@ -956,6 +956,8 @@ void ruby_thread_init_stack(rb_thread_t https://github.com/ruby/ruby/blob/trunk/vm_core.h#L956
 int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, VALUE *klassp);
 void rb_vm_rewind_cfp(rb_thread_t *th, rb_control_frame_t *cfp);
 
+void rb_vm_register_special_exception(enum ruby_special_exceptions sp, VALUE exception_class, const char *mesg);
+
 void rb_gc_mark_machine_stack(rb_thread_t *th);
 
 int rb_autoloading_value(VALUE mod, ID id, VALUE* value);
Index: proc.c
===================================================================
--- proc.c	(revision 47533)
+++ proc.c	(revision 47534)
@@ -2759,10 +2759,7 @@ Init_Proc(void) https://github.com/ruby/ruby/blob/trunk/proc.c#L2759
     rb_define_method(rb_eLocalJumpError, "reason", localjump_reason, 0);
 
     rb_eSysStackError = rb_define_class("SystemStackError", rb_eException);
-    sysstack_error = rb_exc_new3(rb_eSysStackError,
-				 rb_obj_freeze(rb_str_new2("stack level too deep")));
-    OBJ_TAINT(sysstack_error);
-    OBJ_FREEZE(sysstack_error);
+    rb_vm_register_special_exception(ruby_error_sysstack, rb_eSysStackError, "stack level too deep");
 
     /* utility functions */
     rb_define_global_function("proc", rb_block_proc, 0);
Index: thread.c
===================================================================
--- thread.c	(revision 47533)
+++ thread.c	(revision 47534)
@@ -5022,9 +5022,7 @@ Init_Thread(void) https://github.com/ruby/ruby/blob/trunk/thread.c#L5022
 
     rb_define_method(rb_cThread, "inspect", rb_thread_inspect, 0);
 
-    closed_stream_error = rb_exc_new2(rb_eIOError, "stream closed");
-    OBJ_TAINT(closed_stream_error);
-    OBJ_FREEZE(closed_stream_error);
+    rb_vm_register_special_exception(ruby_error_closed_stream, rb_eIOError, "stream closed");
 
     cThGroup = rb_define_class("ThreadGroup", rb_cObject);
     rb_define_alloc_func(cThGroup, thgroup_s_alloc);
Index: eval.c
===================================================================
--- eval.c	(revision 47533)
+++ eval.c	(revision 47534)
@@ -1691,8 +1691,5 @@ Init_eval(void) https://github.com/ruby/ruby/blob/trunk/eval.c#L1691
     rb_define_global_function("trace_var", rb_f_trace_var, -1);	/* in variable.c */
     rb_define_global_function("untrace_var", rb_f_untrace_var, -1);	/* in variable.c */
 
-    exception_error = rb_exc_new3(rb_eFatal,
-				  rb_obj_freeze(rb_str_new2("exception reentered")));
-    OBJ_TAINT(exception_error);
-    OBJ_FREEZE(exception_error);
+    rb_vm_register_special_exception(ruby_error_reenter, rb_eFatal, "exception reentered");
 }
Index: gc.c
===================================================================
--- gc.c	(revision 47533)
+++ gc.c	(revision 47534)
@@ -8585,10 +8585,7 @@ Init_GC(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L8585
 
     rb_define_module_function(rb_mObjSpace, "_id2ref", id2ref, 1);
 
-    nomem_error = rb_exc_new3(rb_eNoMemError,
-			      rb_obj_freeze(rb_str_new2("failed to allocate memory")));
-    OBJ_TAINT(nomem_error);
-    OBJ_FREEZE(nomem_error);
+    rb_vm_register_special_exception(ruby_error_nomemory, rb_eNoMemError, "failed to allocate memory");
 
     rb_define_method(rb_cBasicObject, "__id__", rb_obj_id, 0);
     rb_define_method(rb_mKernel, "object_id", rb_obj_id, 0);
Index: vm.c
===================================================================
--- vm.c	(revision 47533)
+++ vm.c	(revision 47534)
@@ -1751,7 +1751,6 @@ rb_vm_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L1751
 	RUBY_MARK_UNLESS_NULL(vm->top_self);
 	RUBY_MARK_UNLESS_NULL(vm->coverages);
 	RUBY_MARK_UNLESS_NULL(vm->defined_module_hash);
-	rb_gc_mark_locations(vm->special_exceptions, vm->special_exceptions + ruby_special_error_count);
 
 	if (vm->loading_table) {
 	    rb_mark_tbl(vm->loading_table);
@@ -1768,6 +1767,16 @@ rb_vm_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L1767
     RUBY_MARK_LEAVE("vm");
 }
 
+void
+rb_vm_register_special_exception(enum ruby_special_exceptions sp, VALUE cls, const char *mesg)
+{
+    rb_vm_t *vm = GET_VM();
+    VALUE exc = rb_exc_new3(cls, rb_obj_freeze(rb_str_new2(mesg)));
+    OBJ_TAINT(exc);
+    OBJ_FREEZE(exc);
+    ((VALUE *)vm->special_exceptions)[sp] = exc;
+    rb_gc_register_mark_object(exc);
+}
 
 int
 rb_vm_add_root_module(ID id, VALUE module)

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

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