aboutsummaryrefslogtreecommitdiffstats
path: root/vm_trace.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-06 03:13:50 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-06 03:13:50 +0000
commitc2f5a574034cacd938d5af888646585c850f2747 (patch)
tree31fa2313b484d48843bdf4342daca0689408c0c4 /vm_trace.c
parent54c40f3db59d6875de0c2c0f47ab7edce0bd3f43 (diff)
downloadruby-c2f5a574034cacd938d5af888646585c850f2747.tar.gz
* vm_trace.c: TracePoint#enable should not cause an error
when it is already enabled. TracePoint#disable is too. [ruby-core:50561] [ruby-trunk - Bug #7513] * test/ruby/test_settracefunc.rb: add tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_trace.c')
-rw-r--r--vm_trace.c57
1 files changed, 31 insertions, 26 deletions
diff --git a/vm_trace.c b/vm_trace.c
index bedf41a9b6..d4c31ec941 100644
--- a/vm_trace.c
+++ b/vm_trace.c
@@ -952,20 +952,23 @@ rb_tracepoint_disable(VALUE tpval)
/*
* call-seq:
- * trace.enable -> trace
+ * trace.enable -> true or false
* trace.enable { block } -> obj
*
* Activates the trace
*
- * Will raise a RuntimeError if the trace is already activated
+ * Return true if trace was enabled.
+ * Return false if trace was disabled.
*
* trace.enabled? #=> false
- * trace.enable #=> #<TracePoint:0x007fa3fad4aaa8>
+ * trace.enable #=> false (previous state)
+ * # trace is enabled
* trace.enabled? #=> true
- * trace.enable #=> RuntimeError
+ * trace.enable #=> true (previous state)
+ * # trace is still enabled
*
* If a block is given, the trace will only be enabled within the scope of the
- * block. Note: You cannot access event hooks within the block.
+ * block.
*
* trace.enabled?
* #=> false
@@ -978,6 +981,8 @@ rb_tracepoint_disable(VALUE tpval)
* trace.enabled?
* #=> false
*
+ * Note: You cannot access event hooks within the block.
+ *
* trace.enable { p tp.lineno }
* #=> RuntimeError: access from outside
*
@@ -986,36 +991,36 @@ static VALUE
tracepoint_enable_m(VALUE tpval)
{
rb_tp_t *tp = tpptr(tpval);
-
- if (tp->tracing) {
- rb_raise(rb_eRuntimeError, "trace is already enable");
- }
-
+ int previous_tracing = tp->tracing;
rb_tracepoint_enable(tpval);
+
if (rb_block_given_p()) {
- return rb_ensure(rb_yield, Qnil, rb_tracepoint_disable, tpval);
+ return rb_ensure(rb_yield, Qnil,
+ previous_tracing ? rb_tracepoint_enable : rb_tracepoint_disable,
+ tpval);
}
else {
- return tpval;
+ return previous_tracing ? Qtrue : Qfalse;
}
}
/*
* call-seq:
- * trace.disable -> trace
+ * trace.disable -> tru eo rfalse
* trace.disable { block } -> obj
*
* Deactivates the trace
*
- * Will raise a RuntimeError if the trace is already deactivated
+ * Return true if trace was enabled.
+ * Return false if trace was disabled.
*
* trace.enabled? #=> true
- * trace.disable #=> #<TracePoint:0x007fa3fad4aaa8>
+ * trace.disable #=> false (previous status)
* trace.enabled? #=> false
- * trace.disable #=> RuntimeError
+ * trace.disable #=> false
*
* If a block is given, the trace will only be disable within the scope of the
- * block. Note: You cannot access event hooks within the block.
+ * block.
*
* trace.enabled?
* #=> true
@@ -1028,25 +1033,25 @@ tracepoint_enable_m(VALUE tpval)
* trace.enabled?
* #=> true
*
- * trace.enable { p trace.lineno }
- * #=> RuntimeError: access from outside
+ * Note: You cannot access event hooks within the block.
*
+ * trace.disable { p tp.lineno }
+ * #=> RuntimeError: access from outside
*/
static VALUE
tracepoint_disable_m(VALUE tpval)
{
rb_tp_t *tp = tpptr(tpval);
-
- if (!tp->tracing) {
- rb_raise(rb_eRuntimeError, "trace is not enable");
- }
-
+ int previous_tracing = tp->tracing;
rb_tracepoint_disable(tpval);
+
if (rb_block_given_p()) {
- return rb_ensure(rb_yield, Qnil, rb_tracepoint_enable, tpval);
+ return rb_ensure(rb_yield, Qnil,
+ previous_tracing ? rb_tracepoint_enable : rb_tracepoint_disable,
+ tpval);
}
else {
- return tpval;
+ return previous_tracing ? Qtrue : Qfalse;
}
}