Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Aug 16, 2023
1 parent 0e4e6f5 commit b08d7f6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
46 changes: 23 additions & 23 deletions ext/oj/dump_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,36 +851,36 @@ static DumpFunc compat_funcs[] = {
};

static void set_state_depth(VALUE state, int depth) {
if (0 == rb_const_defined(rb_cObject, rb_intern("JSON"))) {
rb_require("oj/json");
}
{
VALUE json_module = rb_const_get_at(rb_cObject, rb_intern("JSON"));
VALUE ext = rb_const_get(json_module, rb_intern("Ext"));
VALUE generator = rb_const_get(ext, rb_intern("Generator"));
VALUE state_class = rb_const_get(generator, rb_intern("State"));

if (state_class == rb_obj_class(state)) {
rb_funcall(state, rb_intern("depth="), 1, INT2NUM(depth));
}
}
if (0 == rb_const_defined(rb_cObject, rb_intern("JSON"))) {
rb_require("oj/json");
}
{
VALUE json_module = rb_const_get_at(rb_cObject, rb_intern("JSON"));
VALUE ext = rb_const_get(json_module, rb_intern("Ext"));
VALUE generator = rb_const_get(ext, rb_intern("Generator"));
VALUE state_class = rb_const_get(generator, rb_intern("State"));

if (state_class == rb_obj_class(state)) {
rb_funcall(state, rb_intern("depth="), 1, INT2NUM(depth));
}
}
}

void oj_dump_compat_val(VALUE obj, int depth, Out out, bool as_ok) {
int type = rb_type(obj);

TRACE(out->opts->trace, "dump", obj, depth, TraceIn);
// The max_nesting logic is that an empty Array or Hash is assumed to have
// content so the max_nesting should fail but a non-collection value is
// okay. That means a check for a collectable value is needed before
// raising.
// The max_nesting logic is that an empty Array or Hash is assumed to have
// content so the max_nesting should fail but a non-collection value is
// okay. That means a check for a collectable value is needed before
// raising.
if (out->opts->dump_opts.max_depth <= depth) {
if (RUBY_T_ARRAY == type || RUBY_T_HASH == type) {
if (0 < out->argc) {
set_state_depth(*out->argv, depth);
}
raise_json_err("Too deeply nested", "NestingError");
}
if (RUBY_T_ARRAY == type || RUBY_T_HASH == type) {
if (0 < out->argc) {
set_state_depth(*out->argv, depth);
}
raise_json_err("Too deeply nested", "NestingError");
}
}
if (0 < type && type <= RUBY_T_FIXNUM) {
DumpFunc f = compat_funcs[type];
Expand Down
20 changes: 10 additions & 10 deletions ext/oj/oj.c
Original file line number Diff line number Diff line change
Expand Up @@ -955,16 +955,16 @@ static int parse_options_cb(VALUE k, VALUE v, VALUE opts) {
copts->sym_key = (Qtrue == v) ? Yes : No;

} else if (oj_max_nesting_sym == k) {
if (Qtrue == v) {
copts->dump_opts.max_depth = 100;
} else if (Qfalse == v || Qnil == v) {
copts->dump_opts.max_depth = MAX_DEPTH;
} else if (T_FIXNUM == rb_type(v)) {
copts->dump_opts.max_depth = NUM2INT(v);
if (0 >= copts->dump_opts.max_depth) {
copts->dump_opts.max_depth = MAX_DEPTH;
}
}
if (Qtrue == v) {
copts->dump_opts.max_depth = 100;
} else if (Qfalse == v || Qnil == v) {
copts->dump_opts.max_depth = MAX_DEPTH;
} else if (T_FIXNUM == rb_type(v)) {
copts->dump_opts.max_depth = NUM2INT(v);
if (0 >= copts->dump_opts.max_depth) {
copts->dump_opts.max_depth = MAX_DEPTH;
}
}
} else if (float_format_sym == k) {
rb_check_type(v, T_STRING);
if (6 < (int)RSTRING_LEN(v)) {
Expand Down
32 changes: 16 additions & 16 deletions ext/oj/oj.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,22 @@ typedef struct _rOptTable {
} *ROptTable;

typedef struct _out {
char stack_buffer[4096];
char *buf;
char *end;
char *cur;
Cache8 circ_cache;
slot_t circ_cnt;
int indent;
int depth; // used by dump_hash
Options opts;
uint32_t hash_cnt;
bool allocated;
bool omit_nil;
bool omit_null_byte;
int argc;
VALUE *argv;
ROptTable ropts;
char stack_buffer[4096];
char *buf;
char *end;
char *cur;
Cache8 circ_cache;
slot_t circ_cnt;
int indent;
int depth; // used by dump_hash
Options opts;
uint32_t hash_cnt;
bool allocated;
bool omit_nil;
bool omit_null_byte;
int argc;
VALUE *argv;
ROptTable ropts;
} *Out;

typedef struct _strWriter {
Expand Down

0 comments on commit b08d7f6

Please sign in to comment.