Skip to content

Commit

Permalink
Get rid of magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Jul 22, 2022
1 parent cf7d075 commit c6aa654
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions ext/objspace/objspace_dump.c
Expand Up @@ -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);
Expand All @@ -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)];
Expand Down Expand Up @@ -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\":\"");
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
Expand Down

0 comments on commit c6aa654

Please sign in to comment.