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

ruby-changes:64436

From: zverok <ko1@a...>
Date: Tue, 22 Dec 2020 09:22:56 +0900 (JST)
Subject: [ruby-changes:64436] 843fd1e8cf (master): Document Fiber#backtrace and #backtrace_locations

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

From 843fd1e8cfccdf1efcbb157315e267e4f380e030 Mon Sep 17 00:00:00 2001
From: zverok <zverok.offline@g...>
Date: Mon, 21 Dec 2020 23:42:01 +0200
Subject: Document Fiber#backtrace and #backtrace_locations


diff --git a/cont.c b/cont.c
index bdc29e1..129aad9 100644
--- a/cont.c
+++ b/cont.c
@@ -2369,12 +2369,77 @@ rb_fiber_raise(int argc, VALUE *argv, VALUE fiber_value) https://github.com/ruby/ruby/blob/trunk/cont.c#L2369
     }
 }
 
+/*
+ *  call-seq:
+ *     fiber.backtrace -> array
+ *     fiber.backtrace(start) -> array
+ *     fiber.backtrace(start, count) -> array
+ *     fiber.backtrace(start..end) -> array
+ *
+ *  Returns the current execution stack of the fiber. +start+, +count+ and +end+ allow
+ *  to select only parts of the backtrace.
+ *
+ *     def level3
+ *       Fiber.yield
+ *     end
+ *
+ *     def level2
+ *       level3
+ *     end
+ *
+ *     def level1
+ *       level2
+ *     end
+ *
+ *     f = Fiber.new { level1 }
+ *
+ *     # It is empty before the fiber started
+ *     f.backtrace
+ *     #=> []
+ *
+ *     f.resume
+ *
+ *     f.backtrace
+ *     #=> ["test.rb:2:in `yield'", "test.rb:2:in `level3'", "test.rb:6:in `level2'", "test.rb:10:in `level1'", "test.rb:13:in `block in <main>'"]
+ *     p f.backtrace(1) # start from the item 1
+ *     #=> ["test.rb:2:in `level3'", "test.rb:6:in `level2'", "test.rb:10:in `level1'", "test.rb:13:in `block in <main>'"]
+ *     p f.backtrace(2, 2) # start from item 2, take 2
+ *     #=> ["test.rb:6:in `level2'", "test.rb:10:in `level1'"]
+ *     p f.backtrace(1..3) # take items from 1 to 3
+ *     #=> ["test.rb:2:in `level3'", "test.rb:6:in `level2'", "test.rb:10:in `level1'"]
+ *
+ *     f.resume
+ *
+ *     # It is empty after the fiber is finished
+ *     f.backtrace
+ *     #=> []
+ *
+ */
 static VALUE
 rb_fiber_backtrace(int argc, VALUE *argv, VALUE fiber)
 {
     return rb_vm_backtrace(argc, argv, &fiber_ptr(fiber)->cont.saved_ec);
 }
 
+/*
+ *  call-seq:
+ *     fiber.backtrace_locations -> array
+ *     fiber.backtrace_locations(start) -> array
+ *     fiber.backtrace_locations(start, count) -> array
+ *     fiber.backtrace_locations(start..end) -> array
+ *
+ *  Like #backtrace, but returns each line of the execution stack as a
+ *  Thread::Backtrace::Location. Accepts the same arguments as #backtrace.
+ *
+ *    f = Fiber.new { Fiber.yield }
+ *    f.resume
+ *    loc = f.backtrace_locations.first
+ *    loc.label  #=> "yield"
+ *    loc.path   #=> "test.rb"
+ *    loc.lineno #=> 1
+ *
+ *
+ */
 static VALUE
 rb_fiber_backtrace_locations(int argc, VALUE *argv, VALUE fiber)
 {
-- 
cgit v0.10.2


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

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