summaryrefslogtreecommitdiff
path: root/ext/objspace/objspace_dump.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-07-22 10:41:44 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-07-22 10:41:44 +0900
commitc6aa65430fbb94651f4d15e2a976f59b5475ca19 (patch)
treea9c7d63275a99aea9f2bd513d53688a7e105bf54 /ext/objspace/objspace_dump.c
parentcf7d07570f50ef9c16007019afcff11ba6500d70 (diff)
Get rid of magic numbers
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6166
Diffstat (limited to 'ext/objspace/objspace_dump.c')
-rw-r--r--ext/objspace/objspace_dump.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c
index 24a2b0b245..91d9eec4f3 100644
--- a/ext/objspace/objspace_dump.c
+++ b/ext/objspace/objspace_dump.c
@@ -145,7 +145,7 @@ static void
dump_append_c(struct dump_config *dc, unsigned char c)
{
if (c <= 0x1f) {
- const unsigned int width = (sizeof(c) * CHAR_BIT / 4) + 5;
+ const unsigned int width = rb_strlen_lit("\\u0000") + 1;
buffer_ensure_capa(dc, width);
unsigned long required = snprintf(dc->buffer + dc->buffer_len, width, "\\u00%02x", c);
RUBY_ASSERT(required <= width);
@@ -163,7 +163,7 @@ dump_append_ref(struct dump_config *dc, VALUE ref)
{
RUBY_ASSERT(ref > 0);
- char buffer[((sizeof(VALUE) * CHAR_BIT + 3) / 4) + 4];
+ char buffer[roomof(sizeof(VALUE) * CHAR_BIT, 4) + rb_strlen_lit("\"0x\"")];
char *buffer_start, *buffer_end;
buffer_start = buffer_end = &buffer[sizeof(buffer)];
@@ -481,7 +481,8 @@ dump_object(VALUE obj, struct dump_config *dc)
dump_append(dc, ", \"name\":\"");
dump_append(dc, RSTRING_PTR(mod_name));
dump_append(dc, "\"");
- } else {
+ }
+ else {
VALUE real_mod_name = rb_mod_name(rb_class_real(obj));
if (RTEST(real_mod_name)) {
dump_append(dc, ", \"real_class_name\":\"");
@@ -625,7 +626,8 @@ dump_output(struct dump_config *dc, VALUE output, VALUE full, VALUE since)
if (TYPE(output) == T_STRING) {
dc->stream = Qfalse;
dc->string = output;
- } else {
+ }
+ else {
dc->stream = output;
dc->string = Qfalse;
}
@@ -637,7 +639,8 @@ dump_output(struct dump_config *dc, VALUE output, VALUE full, VALUE since)
if (RTEST(since)) {
dc->partial_dump = 1;
dc->since = NUM2SIZET(since);
- } else {
+ }
+ else {
dc->partial_dump = 0;
}
}
@@ -649,7 +652,8 @@ dump_result(struct dump_config *dc)
if (dc->string) {
return dc->string;
- } else {
+ }
+ else {
rb_io_flush(dc->stream);
return dc->stream;
}