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

ruby-changes:47444

From: ko1 <ko1@a...>
Date: Thu, 10 Aug 2017 12:20:46 +0900 (JST)
Subject: [ruby-changes:47444] ko1:r59560 (trunk): Define Thread#to_s (as Thread#inspect) and make alias `inspect` as `to_s`.

ko1	2017-08-10 12:20:39 +0900 (Thu, 10 Aug 2017)

  New Revision: 59560

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

  Log:
    Define Thread#to_s (as Thread#inspect) and make alias `inspect` as `to_s`.
    
    * thread.c: "Thread#to_s" is not defined without any reason. So this fix
      define "Thread#to_s" which returns a string with some thread information.
      Also this fix makes alias "inspect" which refers "to_s". This manner is
      same as other objects.

  Modified files:
    trunk/thread.c
Index: thread.c
===================================================================
--- thread.c	(revision 59559)
+++ thread.c	(revision 59560)
@@ -552,7 +552,7 @@ thread_cleanup_func(void *th_ptr, int at https://github.com/ruby/ruby/blob/trunk/thread.c#L552
 }
 
 static VALUE rb_threadptr_raise(rb_thread_t *, int, VALUE *);
-static VALUE rb_thread_inspect(VALUE thread);
+static VALUE rb_thread_to_s(VALUE thread);
 
 void
 ruby_thread_init_stack(rb_thread_t *th)
@@ -641,7 +641,7 @@ thread_start_func_2(rb_thread_t *th, VAL https://github.com/ruby/ruby/blob/trunk/thread.c#L641
 		/* exit on main_thread */
 	    }
 	    else if (th->report_on_exception) {
-		VALUE mesg = rb_thread_inspect(th->self);
+		VALUE mesg = rb_thread_to_s(th->self);
 		rb_str_cat_cstr(mesg, " terminated with exception:\n");
 		rb_write_error_str(mesg);
 		rb_threadptr_error_print(th, errinfo);
@@ -2961,13 +2961,13 @@ rb_thread_setname(VALUE thread, VALUE na https://github.com/ruby/ruby/blob/trunk/thread.c#L2961
 
 /*
  * call-seq:
- *   thr.inspect   -> string
+ *   thr.to_s -> string
  *
  * Dump the name, id, and status of _thr_ to a string.
  */
 
 static VALUE
-rb_thread_inspect(VALUE thread)
+rb_thread_to_s(VALUE thread)
 {
     VALUE cname = rb_class_path(rb_obj_class(thread));
     rb_thread_t *target_th = rb_thread_ptr(thread);
@@ -4851,7 +4851,8 @@ Init_Thread(void) https://github.com/ruby/ruby/blob/trunk/thread.c#L4851
 
     rb_define_method(rb_cThread, "name", rb_thread_getname, 0);
     rb_define_method(rb_cThread, "name=", rb_thread_setname, 1);
-    rb_define_method(rb_cThread, "inspect", rb_thread_inspect, 0);
+    rb_define_method(rb_cThread, "to_s", rb_thread_to_s, 0);
+    rb_define_alias(rb_cThread, "inspect", "to_s");
 
     rb_vm_register_special_exception(ruby_error_stream_closed, rb_eIOError,
 				     "stream closed in another thread");

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

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