rotoscope 0.3.0.pre.5 → 0.3.0.pre.6

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
  SHA1:
3
- metadata.gz: 1820c6d940f6bf81fed89461da5327dea609dc2a
4
- data.tar.gz: 137ad7162d730b0749bbe8d1eddb1d79408533b4
3
+ metadata.gz: 5e1efb6a5e9839ddf8219a7cfe6287195f0efbc5
4
+ data.tar.gz: 91bb41de1a6c892ccd9bb0f6e9b437c67fe90c68
5
5
  SHA512:
6
- metadata.gz: 65a8c8f40541881b178b4657a0b0f1784adf49e55be1123cc463a36efdc20fdfdf615f19686bcda68608a28931e2014f2842cce55a331e98d0bce4e30431da12
7
- data.tar.gz: 673e6eae938960169f417005f50866fc44eecf89fe227dfbdb70439e9d1efeb9457c23408b7882e76ce1b8d1754d58a01d7443164c687cade8411d7d8b536442
6
+ metadata.gz: 436314656fd8c5e6ebabfd3b89b3ad2951b7073f530b3ac1381c04ad0a972fe3e434595c8e0a07e0c13e6ef1c5f1177bcc270b5995a15538466a7c2553637a26
7
+ data.tar.gz: fae7fbf6c7c84b337579b1270f0620860dde11c0f88f8a526d2bfca87cf3eae8b2eee15de56c2ca3aca631538233bb351770f3c30cfda77fd0b4f1c3d73096d8
@@ -14,7 +14,8 @@
14
14
  #include "tracepoint.h"
15
15
 
16
16
  VALUE cRotoscope, cTracePoint;
17
- ID id_initialize;
17
+ ID id_initialize, id_gsub;
18
+ VALUE str_quote, str_escaped_quote;
18
19
 
19
20
  static unsigned long gettid() {
20
21
  return NUM2ULONG(rb_obj_id(rb_thread_current()));
@@ -119,8 +120,18 @@ static rs_tracepoint_t extract_full_tracevals(rb_trace_arg_t *trace_arg,
119
120
 
120
121
  static bool in_fork(Rotoscope *config) { return config->pid != getpid(); }
121
122
 
123
+ VALUE escape_csv_string(VALUE string) {
124
+ if (!memchr(RSTRING_PTR(string), '"', RSTRING_LEN(string))) {
125
+ return string;
126
+ }
127
+ return rb_funcall(string, id_gsub, 2, str_quote, str_escaped_quote);
128
+ }
129
+
122
130
  static void log_trace_event(FILE *stream, rs_tracepoint_t *trace) {
123
- fprintf(stream, RS_CSV_FORMAT "\n", RS_CSV_VALUES(trace));
131
+ VALUE escaped_method_name = escape_csv_string(trace->method_name);
132
+ fprintf(stream, RS_CSV_FORMAT "\n",
133
+ RS_CSV_VALUES(trace, escaped_method_name));
134
+ RB_GC_GUARD(escaped_method_name);
124
135
  }
125
136
 
126
137
  unsigned char output_buffer[LOG_BUFFER_SIZE];
@@ -128,8 +139,15 @@ static void log_trace_event_with_caller(FILE *stream,
128
139
  rs_stack_frame_t *stack_frame,
129
140
  rs_stack_frame_t *caller_frame,
130
141
  rs_strmemo_t **call_memo) {
131
- snprintf((char *)output_buffer, LOG_BUFFER_SIZE, RS_FLATTENED_CSV_FORMAT "\n",
132
- RS_FLATTENED_CSV_VALUES(&stack_frame->tp, &caller_frame->tp));
142
+ VALUE escaped_method_name = escape_csv_string(stack_frame->tp.method_name);
143
+ VALUE escaped_caller_method_name =
144
+ escape_csv_string(caller_frame->tp.method_name);
145
+ snprintf(
146
+ (char *)output_buffer, LOG_BUFFER_SIZE, RS_FLATTENED_CSV_FORMAT "\n",
147
+ RS_FLATTENED_CSV_VALUES(&stack_frame->tp, &caller_frame->tp,
148
+ escaped_method_name, escaped_caller_method_name));
149
+ RB_GC_GUARD(escaped_method_name);
150
+ RB_GC_GUARD(escaped_caller_method_name);
133
151
 
134
152
  if (rs_strmemo_uniq(call_memo, output_buffer)) {
135
153
  fputs((char *)output_buffer, stream);
@@ -368,6 +386,12 @@ void Init_rotoscope(void) {
368
386
  cTracePoint = rb_const_get(rb_cObject, rb_intern("TracePoint"));
369
387
 
370
388
  id_initialize = rb_intern("initialize");
389
+ id_gsub = rb_intern("gsub");
390
+
391
+ str_quote = rb_str_new_literal("\"");
392
+ rb_global_variable(&str_quote);
393
+ str_escaped_quote = rb_str_new_literal("\"\"");
394
+ rb_global_variable(&str_escaped_quote);
371
395
 
372
396
  cRotoscope = rb_define_class("Rotoscope", rb_cObject);
373
397
  rb_define_alloc_func(cRotoscope, rs_alloc);
@@ -15,27 +15,30 @@
15
15
  #define LOG_BUFFER_SIZE 1000
16
16
 
17
17
  // clang-format off
18
- #define _RS_COMMON_CSV_HEADER "entity,method_name,method_level,filepath,lineno"
19
- #define _RS_COMMON_CSV_FORMAT "\"%s\",\"%s\",%s,\"%s\",%d"
20
- #define _RS_COMMON_CSV_VALUES(trace) \
21
- StringValueCStr((trace)->entity), \
22
- StringValueCStr((trace)->method_name), \
23
- (trace)->method_level, \
24
- StringValueCStr((trace)->filepath), \
25
- (trace)->lineno
26
18
 
27
- #define RS_CSV_HEADER "event," _RS_COMMON_CSV_HEADER
28
- #define RS_CSV_FORMAT "%s," _RS_COMMON_CSV_FORMAT
29
- #define RS_CSV_VALUES(trace) trace->event, _RS_COMMON_CSV_VALUES(trace)
19
+ #define RS_CSV_HEADER "event,entity,filepath,lineno,method_name,method_level"
20
+ #define RS_CSV_FORMAT "%s,\"%s\",\"%s\",%d,\"%s\",%s"
21
+ #define RS_CSV_VALUES(trace, method_name) \
22
+ trace->event, \
23
+ StringValueCStr((trace)->entity), \
24
+ StringValueCStr((trace)->filepath), \
25
+ (trace)->lineno, \
26
+ StringValueCStr(method_name), \
27
+ (trace)->method_level
30
28
 
31
29
  #define RS_FLATTENED_CSV_HEADER \
32
- _RS_COMMON_CSV_HEADER ",caller_entity,caller_method_name,caller_method_level"
33
- #define RS_FLATTENED_CSV_FORMAT _RS_COMMON_CSV_FORMAT ",\"%s\",\"%s\",%s"
34
- #define RS_FLATTENED_CSV_VALUES(trace, caller_trace) \
35
- _RS_COMMON_CSV_VALUES(trace), \
36
- StringValueCStr((caller_trace)->entity), \
37
- StringValueCStr((caller_trace)->method_name), \
30
+ "entity,caller_entity,filepath,lineno,method_name,method_level,caller_method_name,caller_method_level"
31
+ #define RS_FLATTENED_CSV_FORMAT "\"%s\",\"%s\",\"%s\",%d,\"%s\",%s,\"%s\",%s"
32
+ #define RS_FLATTENED_CSV_VALUES(trace, caller_trace, method_name, caller_method_name) \
33
+ StringValueCStr((trace)->entity), \
34
+ StringValueCStr((caller_trace)->entity), \
35
+ StringValueCStr((trace)->filepath), \
36
+ (trace)->lineno, \
37
+ StringValueCStr(method_name), \
38
+ (trace)->method_level, \
39
+ StringValueCStr(caller_method_name), \
38
40
  (caller_trace)->method_level
41
+
39
42
  // clang-format on
40
43
 
41
44
  typedef enum {
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class Rotoscope
3
- VERSION = "0.3.0.pre.5"
3
+ VERSION = "0.3.0.pre.6"
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.pre.5
4
+ version: 0.3.0.pre.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jahfer Husain