From 27535987bedec229294a8f6f7d1d6668b7a3e697 Mon Sep 17 00:00:00 2001 From: ko1 Date: Thu, 10 Aug 2017 03:20:39 +0000 Subject: 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59560 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'thread.c') diff --git a/thread.c b/thread.c index 0fa37b70f0..c994710920 100644 --- a/thread.c +++ b/thread.c @@ -552,7 +552,7 @@ thread_cleanup_func(void *th_ptr, int atfork) } 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, VALUE *stack_start, VALUE *register_stack_s /* 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 name) /* * 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) 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"); -- cgit v1.2.3