rotoscope 0.3.0 → 0.3.1.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da519185af3cb3652183905a5005c9666a8479d97075ed258524c2dbae41a22f
4
- data.tar.gz: 9afac7ae131260c434e77a2238b631f0674019a6f3abf71713a525f507a95890
3
+ metadata.gz: f72d8d9a3775c27bafb2214f668282b5defe8731e04befe0957bbd628fe99a82
4
+ data.tar.gz: cbc5bded38b6287945e629c6bc64fbcb1fee23c23c1ed588e04fbe2aabdb60fa
5
5
  SHA512:
6
- metadata.gz: bad9b2c953384b6dde92fc6cbef2a5975dd16a92e86f9b355f1ae3a6c1e5fa6715f0837a3812794fae7759bf1d7391f9adc36a515e7a1640cea913fda12e7b57
7
- data.tar.gz: eac7f35d1d1b0346f047c87eebda7cf47d59ed5dff9bc4ab073601071eb17b9f6b107216812803fa9ba13d62805c548374f5c49cca60fb9ff5de656214ee06a9
6
+ metadata.gz: 4bd1d1a8fdea550f69513e8b36b3753684239d6cb662655cce35b4da1e4b163041265bd3771f6dd2c37e8c07b6efedef2b7b51d1d2a7f313b70adbe0e093e2d4
7
+ data.tar.gz: '009a2baef7ec589dd738077f523aecfa8dbc7af486a1a67eba91cd990530c494caf7134b92f9e6a83e3991bf3484bad69bd5123755cdd24440c0209378e64e80'
@@ -1 +1 @@
1
- 2.4.3
1
+ 2.5.3
data/dev.yml CHANGED
@@ -5,7 +5,7 @@ env:
5
5
  ROTOSCOPE_COMPILE_ERROR: '1'
6
6
 
7
7
  up:
8
- - ruby: 2.4.3
8
+ - ruby: 2.5.3
9
9
  - homebrew:
10
10
  - clang-format
11
11
  - bundler
@@ -1,39 +1,50 @@
1
1
  #include "callsite.h"
2
2
  #include <ruby.h>
3
3
  #include <ruby/debug.h>
4
+ #include <stdbool.h>
4
5
 
5
- VALUE empty_ruby_string;
6
+ static VALUE caller_frame(int *line, bool ruby_call) {
7
+ VALUE frames[2] = {Qnil, Qnil};
8
+ int lines[2] = {0, 0};
6
9
 
7
- rs_callsite_t c_callsite(rb_trace_arg_t *trace_arg) {
8
- VALUE path = rb_tracearg_path(trace_arg);
9
- return (rs_callsite_t){
10
- .filepath = NIL_P(path) ? empty_ruby_string : path,
11
- .lineno = FIX2INT(rb_tracearg_lineno(trace_arg)),
12
- };
13
- }
10
+ // At this point, the top ruby stack frame is for the method
11
+ // being called, so we want to skip that frame and get
12
+ // the caller location. This is why we use 1 for ruby calls.
13
+ //
14
+ // However, rb_profile_frames also automatically skips over
15
+ // non-ruby stack frames, so we don't want to have to skip
16
+ // over any extra stack frames for a C call.
17
+ int frame_index = ruby_call ? 1 : 0;
14
18
 
15
- rs_callsite_t ruby_callsite(rb_trace_arg_t *trace_arg) {
16
- VALUE frames[2];
17
- int lines[2];
18
19
  // There is currently a bug in rb_profile_frames that
19
20
  // causes the start argument to effectively always
20
21
  // act as if it were 0, so we need to also get the top
21
- // frame.
22
- if (rb_profile_frames(0, 2, frames, lines) < 2) {
23
- return (rs_callsite_t){
24
- .filepath = empty_ruby_string,
25
- .lineno = 0,
26
- };
27
- }
22
+ // frame. (https://bugs.ruby-lang.org/issues/14607)
23
+ rb_profile_frames(0, frame_index + 1, frames, lines);
24
+
25
+ *line = lines[frame_index];
26
+ return frames[frame_index];
27
+ }
28
28
 
29
+ rs_callsite_t c_callsite(rb_trace_arg_t *trace_arg) {
30
+ int line;
31
+ VALUE frame = caller_frame(&line, false);
29
32
  return (rs_callsite_t){
30
- .filepath = rb_profile_frame_path(frames[1]),
31
- .lineno = lines[1],
33
+ .filepath = rb_tracearg_path(trace_arg),
34
+ .lineno = FIX2INT(rb_tracearg_lineno(trace_arg)),
35
+ .method_name = rb_profile_frame_method_name(frame),
36
+ .singleton_p = rb_profile_frame_singleton_method_p(frame),
32
37
  };
33
38
  }
34
39
 
35
- void init_callsite() {
36
- empty_ruby_string = rb_str_new_literal("");
37
- RB_OBJ_FREEZE(empty_ruby_string);
38
- rb_global_variable(&empty_ruby_string);
40
+ rs_callsite_t ruby_callsite() {
41
+ int line;
42
+ VALUE frame = caller_frame(&line, true);
43
+
44
+ return (rs_callsite_t){
45
+ .filepath = rb_profile_frame_path(frame),
46
+ .lineno = line,
47
+ .method_name = rb_profile_frame_method_name(frame),
48
+ .singleton_p = rb_profile_frame_singleton_method_p(frame),
49
+ };
39
50
  }
@@ -7,11 +7,11 @@
7
7
  typedef struct {
8
8
  VALUE filepath;
9
9
  unsigned int lineno;
10
+ VALUE method_name;
11
+ VALUE singleton_p;
10
12
  } rs_callsite_t;
11
13
 
12
- void init_callsite();
13
-
14
14
  rs_callsite_t c_callsite(rb_trace_arg_t *trace_arg);
15
- rs_callsite_t ruby_callsite(rb_trace_arg_t *trace_arg);
15
+ rs_callsite_t ruby_callsite();
16
16
 
17
17
  #endif
@@ -49,7 +49,7 @@ static rs_callsite_t tracearg_path(rb_trace_arg_t *trace_arg) {
49
49
  case RUBY_EVENT_C_CALL:
50
50
  return c_callsite(trace_arg);
51
51
  default:
52
- return ruby_callsite(trace_arg);
52
+ return ruby_callsite();
53
53
  }
54
54
  }
55
55
 
@@ -61,9 +61,7 @@ static rs_method_desc_t called_method_desc(rb_trace_arg_t *trace_arg) {
61
61
  SYM2ID(method_id) != id_initialize;
62
62
 
63
63
  return (rs_method_desc_t){
64
- .receiver = receiver,
65
- .id = method_id,
66
- .singleton_p = singleton_p,
64
+ .receiver = receiver, .id = method_id, .singleton_p = singleton_p,
67
65
  };
68
66
  }
69
67
 
@@ -154,8 +152,9 @@ static VALUE rs_alloc(VALUE klass) {
154
152
  config->tid = gettid();
155
153
  config->tracing = false;
156
154
  config->caller = NULL;
157
- config->callsite.filepath = Qnil;
158
- config->callsite.lineno = 0;
155
+ config->callsite = (rs_callsite_t){
156
+ .filepath = Qnil, .lineno = 0, .method_name = Qnil, .singleton_p = Qnil,
157
+ };
159
158
  config->trace_proc = Qnil;
160
159
  rs_stack_init(&config->stack, STACK_CAPACITY);
161
160
  config->tracepoint = rb_tracepoint_new(Qnil, EVENT_CALL | EVENT_RETURN,
@@ -264,18 +263,12 @@ VALUE rotoscope_caller_class_name(VALUE self) {
264
263
 
265
264
  VALUE rotoscope_caller_method_name(VALUE self) {
266
265
  Rotoscope *config = get_config(self);
267
- if (config->caller == NULL) {
268
- return Qnil;
269
- }
270
- return rb_sym2str(config->caller->method.id);
266
+ return config->callsite.method_name;
271
267
  }
272
268
 
273
269
  VALUE rotoscope_caller_singleton_method_p(VALUE self) {
274
270
  Rotoscope *config = get_config(self);
275
- if (config->caller == NULL) {
276
- return Qnil;
277
- }
278
- return config->caller->method.singleton_p ? Qtrue : Qfalse;
271
+ return config->callsite.singleton_p;
279
272
  }
280
273
 
281
274
  VALUE rotoscope_caller_path(VALUE self) {
@@ -317,6 +310,4 @@ void Init_rotoscope(void) {
317
310
  rotoscope_caller_singleton_method_p, 0);
318
311
  rb_define_method(cRotoscope, "caller_path", rotoscope_caller_path, 0);
319
312
  rb_define_method(cRotoscope, "caller_lineno", rotoscope_caller_lineno, 0);
320
-
321
- init_callsite();
322
313
  }
@@ -3,9 +3,7 @@
3
3
  #include <stdbool.h>
4
4
  #include "method_desc.h"
5
5
 
6
- typedef struct {
7
- rs_method_desc_t method;
8
- } rs_stack_frame_t;
6
+ typedef struct { rs_method_desc_t method; } rs_stack_frame_t;
9
7
 
10
8
  typedef struct {
11
9
  int capacity;
@@ -88,15 +88,15 @@ class Rotoscope
88
88
  private
89
89
 
90
90
  def log_call(call)
91
- return if blacklist.match?(call.caller_path)
91
+ caller_path = call.caller_path || ''
92
+ return if blacklist.match?(caller_path)
92
93
  return if self == call.receiver
93
94
 
95
+ caller_class_name = call.caller_class_name || '<UNKNOWN>'
94
96
  if call.caller_method_name.nil?
95
- caller_class_name = '<ROOT>'
96
97
  caller_method_name = '<UNKNOWN>'
97
98
  caller_method_level = '<UNKNOWN>'
98
99
  else
99
- caller_class_name = call.caller_class_name
100
100
  caller_method_name = escape_csv_string(call.caller_method_name)
101
101
  caller_method_level = call.caller_singleton_method? ? 'class' : 'instance'
102
102
  end
@@ -109,7 +109,7 @@ class Rotoscope
109
109
  buffer <<
110
110
  '"' << call.receiver_class_name << '",' \
111
111
  '"' << caller_class_name << '",' \
112
- '"' << call.caller_path << '",' \
112
+ '"' << caller_path << '",' \
113
113
  << call.caller_lineno.to_s << ',' \
114
114
  '"' << method_name << '",' \
115
115
  << call_method_level << ',' \
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class Rotoscope
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1.pre.1"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rotoscope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jahfer Husain
@@ -115,9 +115,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  version: 2.2.0
116
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  requirements:
118
- - - ">="
118
+ - - ">"
119
119
  - !ruby/object:Gem::Version
120
- version: '0'
120
+ version: 1.3.1
121
121
  requirements: []
122
122
  rubyforge_project:
123
123
  rubygems_version: 2.7.6