Skip to content

Commit b7edd96

Browse files
committed
Revert line wrapping and whitespace changes in libdatadog_api files
These files had extensive line wrapping/reformatting that has been reverted. Content changes (include reordering and commented rb_raise calls) have been preserved.
1 parent 6c77ebc commit b7edd96

File tree

2 files changed

+83
-128
lines changed

2 files changed

+83
-128
lines changed

ext/libdatadog_api/crashtracker.c

Lines changed: 55 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
#include <datadog/crashtracker.h>
21
#include <ruby.h>
2+
#include <datadog/crashtracker.h>
33

44
#include "datadog_ruby_common.h"
55

6-
static VALUE _native_start_or_update_on_fork(int argc, VALUE *argv,
7-
DDTRACE_UNUSED VALUE _self);
6+
static VALUE _native_start_or_update_on_fork(int argc, VALUE *argv, DDTRACE_UNUSED VALUE _self);
87
static VALUE _native_stop(DDTRACE_UNUSED VALUE _self);
98

109
static bool first_init = true;
@@ -13,36 +12,24 @@ static bool first_init = true;
1312
// Once initialized, segfaults will be reported automatically using libdatadog.
1413

1514
void crashtracker_init(VALUE core_module) {
16-
VALUE crashtracking_module =
17-
rb_define_module_under(core_module, "Crashtracking");
18-
VALUE crashtracker_class =
19-
rb_define_class_under(crashtracking_module, "Component", rb_cObject);
20-
21-
rb_define_singleton_method(crashtracker_class,
22-
"_native_start_or_update_on_fork",
23-
_native_start_or_update_on_fork, -1);
24-
rb_define_singleton_method(crashtracker_class, "_native_stop", _native_stop,
25-
0);
15+
VALUE crashtracking_module = rb_define_module_under(core_module, "Crashtracking");
16+
VALUE crashtracker_class = rb_define_class_under(crashtracking_module, "Component", rb_cObject);
17+
18+
rb_define_singleton_method(crashtracker_class, "_native_start_or_update_on_fork", _native_start_or_update_on_fork, -1);
19+
rb_define_singleton_method(crashtracker_class, "_native_stop", _native_stop, 0);
2620
}
2721

28-
static VALUE _native_start_or_update_on_fork(int argc, VALUE *argv,
29-
DDTRACE_UNUSED VALUE _self) {
22+
static VALUE _native_start_or_update_on_fork(int argc, VALUE *argv, DDTRACE_UNUSED VALUE _self) {
3023
VALUE options;
3124
rb_scan_args(argc, argv, "0:", &options);
32-
if (options == Qnil)
33-
options = rb_hash_new();
34-
35-
VALUE agent_base_url =
36-
rb_hash_fetch(options, ID2SYM(rb_intern("agent_base_url")));
37-
VALUE path_to_crashtracking_receiver_binary = rb_hash_fetch(
38-
options, ID2SYM(rb_intern("path_to_crashtracking_receiver_binary")));
39-
VALUE ld_library_path =
40-
rb_hash_fetch(options, ID2SYM(rb_intern("ld_library_path")));
41-
VALUE tags_as_array =
42-
rb_hash_fetch(options, ID2SYM(rb_intern("tags_as_array")));
25+
if (options == Qnil) options = rb_hash_new();
26+
27+
VALUE agent_base_url = rb_hash_fetch(options, ID2SYM(rb_intern("agent_base_url")));
28+
VALUE path_to_crashtracking_receiver_binary = rb_hash_fetch(options, ID2SYM(rb_intern("path_to_crashtracking_receiver_binary")));
29+
VALUE ld_library_path = rb_hash_fetch(options, ID2SYM(rb_intern("ld_library_path")));
30+
VALUE tags_as_array = rb_hash_fetch(options, ID2SYM(rb_intern("tags_as_array")));
4331
VALUE action = rb_hash_fetch(options, ID2SYM(rb_intern("action")));
44-
VALUE upload_timeout_seconds =
45-
rb_hash_fetch(options, ID2SYM(rb_intern("upload_timeout_seconds")));
32+
VALUE upload_timeout_seconds = rb_hash_fetch(options, ID2SYM(rb_intern("upload_timeout_seconds")));
4633

4734
VALUE start_action = ID2SYM(rb_intern("start"));
4835
VALUE update_on_fork_action = ID2SYM(rb_intern("update_on_fork"));
@@ -54,75 +41,64 @@ static VALUE _native_start_or_update_on_fork(int argc, VALUE *argv,
5441
ENFORCE_TYPE(action, T_SYMBOL);
5542
ENFORCE_TYPE(upload_timeout_seconds, T_FIXNUM);
5643

57-
// if (action != start_action && action != update_on_fork_action)
58-
// raise_error(eNativeArgumentError, "Unexpected action: %+" PRIsVALUE,
59-
// action);
44+
// if (action != start_action && action != update_on_fork_action) raise_error(eNativeArgumentError, "Unexpected action: %+"PRIsVALUE, action);
6045

6146
VALUE version = datadog_gem_version();
6247

63-
// Tags and endpoint are heap-allocated, so after here we can't raise
64-
// exceptions otherwise we'll leak this memory Start of exception-free zone to
65-
// prevent leaks {{
66-
ddog_Endpoint *endpoint =
67-
ddog_endpoint_from_url(char_slice_from_ruby_string(agent_base_url));
48+
// Tags and endpoint are heap-allocated, so after here we can't raise exceptions otherwise we'll leak this memory
49+
// Start of exception-free zone to prevent leaks {{
50+
ddog_Endpoint *endpoint = ddog_endpoint_from_url(char_slice_from_ruby_string(agent_base_url));
6851
// if (endpoint == NULL) {
69-
// raise_error(eNativeRuntimeError,
70-
// "Failed to create endpoint from agent_base_url: %" PRIsVALUE,
71-
// // agent_base_url);
52+
// raise_error(eNativeRuntimeError, "Failed to create endpoint from agent_base_url: %"PRIsVALUE, agent_base_url);
7253
// }
7354
ddog_Vec_Tag tags = convert_tags(tags_as_array);
7455

7556
ddog_crasht_Config config = {
76-
.additional_files = {},
77-
// @ivoanjo: The Ruby VM already uses an alt stack to detect stack
78-
// overflows.
79-
//
80-
// In libdatadog < 14 with `create_alt_stack = true` I saw a segfault,
81-
// such as Ruby 2.6's bug with "Process.detach(fork { exit!
82-
// }).instance_variable_get(:@foo)" being turned into a
83-
// "-e:1:in `instance_variable_get': stack level too deep
84-
// (SystemStackError)" by Ruby. The Ruby crash handler also seems to get
85-
// confused when this option is enabled and "Process.kill('SEGV',
86-
// Process.pid)" gets run.
87-
//
88-
// This actually changed in libdatadog 14, so I could see no issues with
89-
// `create_alt_stack = true`, but not overriding what Ruby set up seems a
90-
// saner default to keep anyway.
91-
.create_alt_stack = false,
92-
.use_alt_stack = true,
93-
.endpoint = endpoint,
94-
.resolve_frames =
95-
DDOG_CRASHT_STACKTRACE_COLLECTION_ENABLED_WITH_SYMBOLS_IN_RECEIVER,
96-
.timeout_ms = FIX2INT(upload_timeout_seconds) * 1000,
57+
.additional_files = {},
58+
// @ivoanjo: The Ruby VM already uses an alt stack to detect stack overflows.
59+
//
60+
// In libdatadog < 14 with `create_alt_stack = true` I saw a segfault, such as Ruby 2.6's bug with
61+
// "Process.detach(fork { exit! }).instance_variable_get(:@foo)" being turned into a
62+
// "-e:1:in `instance_variable_get': stack level too deep (SystemStackError)" by Ruby.
63+
// The Ruby crash handler also seems to get confused when this option is enabled and
64+
// "Process.kill('SEGV', Process.pid)" gets run.
65+
//
66+
// This actually changed in libdatadog 14, so I could see no issues with `create_alt_stack = true`, but not
67+
// overriding what Ruby set up seems a saner default to keep anyway.
68+
.create_alt_stack = false,
69+
.use_alt_stack = true,
70+
.endpoint = endpoint,
71+
.resolve_frames = DDOG_CRASHT_STACKTRACE_COLLECTION_ENABLED_WITH_SYMBOLS_IN_RECEIVER,
72+
.timeout_ms = FIX2INT(upload_timeout_seconds) * 1000,
9773
};
9874

9975
ddog_crasht_Metadata metadata = {
100-
.library_name = DDOG_CHARSLICE_C("dd-trace-rb"),
101-
.library_version = char_slice_from_ruby_string(version),
102-
.family = DDOG_CHARSLICE_C("ruby"),
103-
.tags = &tags,
76+
.library_name = DDOG_CHARSLICE_C("dd-trace-rb"),
77+
.library_version = char_slice_from_ruby_string(version),
78+
.family = DDOG_CHARSLICE_C("ruby"),
79+
.tags = &tags,
10480
};
10581

10682
ddog_crasht_EnvVar ld_library_path_env = {
107-
.key = DDOG_CHARSLICE_C("LD_LIBRARY_PATH"),
108-
.val = char_slice_from_ruby_string(ld_library_path),
83+
.key = DDOG_CHARSLICE_C("LD_LIBRARY_PATH"),
84+
.val = char_slice_from_ruby_string(ld_library_path),
10985
};
11086

11187
ddog_crasht_ReceiverConfig receiver_config = {
112-
.args = {},
113-
.env = {.ptr = &ld_library_path_env, .len = 1},
114-
.path_to_receiver_binary =
115-
char_slice_from_ruby_string(path_to_crashtracking_receiver_binary),
116-
.optional_stderr_filename = {},
117-
.optional_stdout_filename = {},
88+
.args = {},
89+
.env = {.ptr = &ld_library_path_env, .len = 1},
90+
.path_to_receiver_binary = char_slice_from_ruby_string(path_to_crashtracking_receiver_binary),
91+
.optional_stderr_filename = {},
92+
.optional_stdout_filename = {},
11893
};
11994

12095
ddog_VoidResult result =
121-
action == start_action
122-
? (first_init
123-
? ddog_crasht_init(config, receiver_config, metadata)
124-
: ddog_crasht_reconfigure(config, receiver_config, metadata))
125-
: ddog_crasht_update_on_fork(config, receiver_config, metadata);
96+
action == start_action ?
97+
(first_init ?
98+
ddog_crasht_init(config, receiver_config, metadata) :
99+
ddog_crasht_reconfigure(config, receiver_config, metadata)
100+
) :
101+
ddog_crasht_update_on_fork(config, receiver_config, metadata);
126102

127103
first_init = false;
128104

@@ -132,9 +108,7 @@ static VALUE _native_start_or_update_on_fork(int argc, VALUE *argv,
132108
// }} End of exception-free zone to prevent leaks
133109

134110
if (result.tag == DDOG_VOID_RESULT_ERR) {
135-
// raise_error(eNativeRuntimeError,
136-
// "Failed to start/update the crash tracker: %" PRIsVALUE,
137-
// get_error_details_and_drop(&result.err));
111+
// raise_error(eNativeRuntimeError, "Failed to start/update the crash tracker: %"PRIsVALUE, get_error_details_and_drop(&result.err));
138112
}
139113

140114
return Qtrue;
@@ -144,9 +118,7 @@ static VALUE _native_stop(DDTRACE_UNUSED VALUE _self) {
144118
ddog_VoidResult result = ddog_crasht_disable();
145119

146120
if (result.tag == DDOG_VOID_RESULT_ERR) {
147-
// raise_error(eNativeRuntimeError,
148-
// "Failed to stop the crash tracker: %" PRIsVALUE,
149-
// get_error_details_and_drop(&result.err));
121+
// raise_error(eNativeRuntimeError, "Failed to stop the crash tracker: %"PRIsVALUE, get_error_details_and_drop(&result.err));
150122
}
151123

152124
return Qtrue;

ext/libdatadog_api/ddsketch.c

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include <datadog/ddsketch.h>
21
#include <ruby.h>
2+
#include <datadog/ddsketch.h>
33

44
#include "datadog_ruby_common.h"
55

@@ -9,12 +9,10 @@ static VALUE native_add(VALUE self, VALUE point);
99
static VALUE native_add_with_count(VALUE self, VALUE point, VALUE count);
1010
static VALUE native_count(VALUE self);
1111
static VALUE native_encode(VALUE self);
12-
NORETURN(static void raise_ddsketch_error(const char *message,
13-
ddog_VoidResult result));
12+
NORETURN(static void raise_ddsketch_error(const char *message, ddog_VoidResult result));
1413

1514
void ddsketch_init(VALUE core_module) {
16-
VALUE ddsketch_class =
17-
rb_define_class_under(core_module, "DDSketch", rb_cObject);
15+
VALUE ddsketch_class = rb_define_class_under(core_module, "DDSketch", rb_cObject);
1816

1917
rb_define_alloc_func(ddsketch_class, _native_new);
2018
rb_define_method(ddsketch_class, "add", native_add, 1);
@@ -23,100 +21,85 @@ void ddsketch_init(VALUE core_module) {
2321
rb_define_method(ddsketch_class, "encode", native_encode, 0);
2422
}
2523

26-
// This structure is used to define a Ruby object that stores a pointer to a
27-
// ddsketch_Handle_DDSketch See also
28-
// https://github.com/ruby/ruby/blob/master/doc/extension.rdoc for how this
29-
// works
24+
// This structure is used to define a Ruby object that stores a pointer to a ddsketch_Handle_DDSketch
25+
// See also https://github.com/ruby/ruby/blob/master/doc/extension.rdoc for how this works
3026
static const rb_data_type_t ddsketch_typed_data = {
31-
.wrap_struct_name = "Datadog::DDSketch",
32-
.function =
33-
{
34-
.dmark = NULL, // We don't store references to Ruby objects so we
35-
// don't need to mark any of them
36-
.dfree = ddsketch_free,
37-
.dsize = NULL, // We don't track memory usage (although it'd be cool
38-
// if we did!)
39-
//.dcompact = NULL, // Not needed -- we don't store references to
40-
// Ruby objects
41-
},
42-
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
27+
.wrap_struct_name = "Datadog::DDSketch",
28+
.function = {
29+
.dmark = NULL, // We don't store references to Ruby objects so we don't need to mark any of them
30+
.dfree = ddsketch_free,
31+
.dsize = NULL, // We don't track memory usage (although it'd be cool if we did!)
32+
//.dcompact = NULL, // Not needed -- we don't store references to Ruby objects
33+
},
34+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
35+
};
4336

4437
static VALUE _native_new(VALUE klass) {
45-
ddsketch_Handle_DDSketch *state =
46-
ruby_xcalloc(1, sizeof(ddsketch_Handle_DDSketch));
38+
ddsketch_Handle_DDSketch *state = ruby_xcalloc(1, sizeof(ddsketch_Handle_DDSketch));
4739

4840
*state = ddog_ddsketch_new();
4941

5042
return TypedData_Wrap_Struct(klass, &ddsketch_typed_data, state);
5143
}
5244

5345
static void ddsketch_free(void *ptr) {
54-
ddsketch_Handle_DDSketch *state = (ddsketch_Handle_DDSketch *)ptr;
46+
ddsketch_Handle_DDSketch *state = (ddsketch_Handle_DDSketch *) ptr;
5547
ddog_ddsketch_drop(state);
5648
ruby_xfree(ptr);
5749
}
5850

5951
static void raise_ddsketch_error(const char *message, ddog_VoidResult result) {
60-
// raise_error(eNativeRuntimeError, "%s: %" PRIsVALUE, message,
61-
// get_error_details_and_drop(&result.err));
52+
// raise_error(eNativeRuntimeError, "%s: %"PRIsVALUE, message, get_error_details_and_drop(&result.err));
6253
}
6354

6455
static VALUE native_add(VALUE self, VALUE point) {
6556
ddsketch_Handle_DDSketch *state;
66-
TypedData_Get_Struct(self, ddsketch_Handle_DDSketch, &ddsketch_typed_data,
67-
state);
57+
TypedData_Get_Struct(self, ddsketch_Handle_DDSketch, &ddsketch_typed_data, state);
6858

6959
ddog_VoidResult result = ddog_ddsketch_add(state, NUM2DBL(point));
7060

71-
if (result.tag == DDOG_VOID_RESULT_ERR)
72-
raise_ddsketch_error("DDSketch add failed", result);
61+
if (result.tag == DDOG_VOID_RESULT_ERR) raise_ddsketch_error("DDSketch add failed", result);
7362

7463
return self;
7564
}
7665

7766
static VALUE native_add_with_count(VALUE self, VALUE point, VALUE count) {
7867
ddsketch_Handle_DDSketch *state;
79-
TypedData_Get_Struct(self, ddsketch_Handle_DDSketch, &ddsketch_typed_data,
80-
state);
68+
TypedData_Get_Struct(self, ddsketch_Handle_DDSketch, &ddsketch_typed_data, state);
8169

82-
ddog_VoidResult result =
83-
ddog_ddsketch_add_with_count(state, NUM2DBL(point), NUM2DBL(count));
70+
ddog_VoidResult result = ddog_ddsketch_add_with_count(state, NUM2DBL(point), NUM2DBL(count));
8471

85-
if (result.tag == DDOG_VOID_RESULT_ERR)
86-
raise_ddsketch_error("DDSketch add_with_count failed", result);
72+
if (result.tag == DDOG_VOID_RESULT_ERR) raise_ddsketch_error("DDSketch add_with_count failed", result);
8773

8874
return self;
8975
}
9076

9177
static VALUE native_count(VALUE self) {
9278
ddsketch_Handle_DDSketch *state;
93-
TypedData_Get_Struct(self, ddsketch_Handle_DDSketch, &ddsketch_typed_data,
94-
state);
79+
TypedData_Get_Struct(self, ddsketch_Handle_DDSketch, &ddsketch_typed_data, state);
9580

9681
double count_out;
9782
ddog_VoidResult result = ddog_ddsketch_count(state, &count_out);
9883

99-
if (result.tag == DDOG_VOID_RESULT_ERR)
100-
raise_ddsketch_error("DDSketch count failed", result);
84+
if (result.tag == DDOG_VOID_RESULT_ERR) raise_ddsketch_error("DDSketch count failed", result);
10185

10286
return DBL2NUM(count_out);
10387
}
10488

10589
static VALUE native_encode(VALUE self) {
10690
ddsketch_Handle_DDSketch *state;
107-
TypedData_Get_Struct(self, ddsketch_Handle_DDSketch, &ddsketch_typed_data,
108-
state);
91+
TypedData_Get_Struct(self, ddsketch_Handle_DDSketch, &ddsketch_typed_data, state);
10992

11093
ddog_Vec_U8 encoded = ddog_ddsketch_encode(state);
11194

11295
// Copy into a Ruby string
113-
VALUE bytes = rb_str_new((const char *)encoded.ptr, encoded.len);
96+
VALUE bytes = rb_str_new((const char *) encoded.ptr, encoded.len);
11497

11598
ddog_Vec_U8_drop(encoded);
11699

117100
// The sketch is consumed by encode; to make this a bit more user-friendly for
118-
// a Ruby API (since we can't "kill" the Ruby object), let's re-initialize it
119-
// so it can be used again.
101+
// a Ruby API (since we can't "kill" the Ruby object), let's re-initialize it so
102+
// it can be used again.
120103
*state = ddog_ddsketch_new();
121104

122105
return bytes;

0 commit comments

Comments
 (0)