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

ruby-changes:63025

From: Quang-Minh <ko1@a...>
Date: Sun, 20 Sep 2020 23:11:07 +0900 (JST)
Subject: [ruby-changes:63025] d5fa66156a (master): Add status to Ractor#inspect

https://git.ruby-lang.org/ruby.git/commit/?id=d5fa66156a

From d5fa66156ab116df558448402b93c9c129b30291 Mon Sep 17 00:00:00 2001
From: Quang-Minh Nguyen <nguyenquangminh0711@g...>
Date: Fri, 18 Sep 2020 12:15:32 +0700
Subject: Add status to Ractor#inspect


diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index ab20082..4b6afc2 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -17,6 +17,27 @@ assert_equal "must be called with a block", %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L17
   end
 }
 
+# Ractor#inspect
+assert_equal "#<Ractor:#1 running>", %q{
+  Ractor.current.inspect
+}
+
+assert_match /^#<Ractor:#([^ ]*?) bootstraptest.tmp.rb:[0-9]+ blocking>$/, %q{
+  r = Ractor.new { Ractor.recv }
+  r.inspect
+}
+
+assert_match /^#<Ractor:#([^ ]*?) bootstraptest.tmp.rb:[0-9]+ terminated>$/, %q{
+  r = Ractor.new { '' }
+  r.take
+  r.inspect
+}
+
+assert_match /^#<Ractor:#([^ ]*?) Test Ractor bootstraptest.tmp.rb:[0-9]+ blocking>$/, %q{
+  r = Ractor.new(name: 'Test Ractor') { Ractor.recv }
+  r.inspect
+}
+
 # A return value of a Ractor block will be a message from the Ractor.
 assert_equal 'ok', %q{
   # join
diff --git a/ractor.rb b/ractor.rb
index 893a3f1..4188f39 100644
--- a/ractor.rb
+++ b/ractor.rb
@@ -12,7 +12,7 @@ class Ractor https://github.com/ruby/ruby/blob/trunk/ractor.rb#L12
   # receive them.
   #
   # The result of the block is sent via the outgoing channel
-  # and other 
+  # and other
   #
   # r = Ractor.new do
   #   Ractor.recv    # recv via r's mailbox => 1
@@ -29,7 +29,7 @@ class Ractor https://github.com/ruby/ruby/blob/trunk/ractor.rb#L29
   #
   # other options:
   #   name: Ractor's name
-  # 
+  #
   def self.new *args, name: nil, &block
     b = block # TODO: builtin bug
     raise ArgumentError, "must be called with a block" unless block
@@ -132,7 +132,10 @@ class Ractor https://github.com/ruby/ruby/blob/trunk/ractor.rb#L132
     loc  = __builtin_cexpr! %q{ RACTOR_PTR(self)->loc }
     name = __builtin_cexpr! %q{ RACTOR_PTR(self)->name }
     id   = __builtin_cexpr! %q{ INT2FIX(RACTOR_PTR(self)->id) }
-    "#<Ractor:##{id}#{name ? ' '+name : ''}#{loc ? " " + loc : ''}>"
+    status = __builtin_cexpr! %q{
+      rb_str_new2(ractor_status_str(RACTOR_PTR(self)->status_))
+    }
+    "#<Ractor:##{id}#{name ? ' '+name : ''}#{loc ? " " + loc : ''} #{status}>"
   end
 
   def name
-- 
cgit v0.10.2


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

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