diff --git a/CHANGELOG.md b/CHANGELOG.md index 73b17e34..246a25b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,13 @@ - Code re-formatted with clang-format. Thanks goes to BuonOmo for suggesting and encouraging the use of a formatter and getting the effort started. + - Added support for `GC.compact` on `Oj::Doc` +- Fixed compatibility issue with Rails and the JSON gem that requires + a special case when using JSON.generate versus call `to_json` on an + object. + ## 3.11.3 - 2021-03-09 - Fixed `respond_to?` method on `Oj::EasyHash`. diff --git a/ext/oj/dump.c b/ext/oj/dump.c index 56e387df..ded508df 100644 --- a/ext/oj/dump.c +++ b/ext/oj/dump.c @@ -599,8 +599,8 @@ void oj_dump_obj_to_json(VALUE obj, Options copts, Out out) { void oj_dump_obj_to_json_using_params(VALUE obj, Options copts, Out out, int argc, VALUE *argv) { if (0 == out->buf) { out->buf = ALLOC_N(char, 4096); - out->end = out->buf + 4095 - - BUFFER_EXTRA; // 1 less than end plus extra for possible errors + // 1 less than end plus extra for possible errors + out->end = out->buf + 4095 - BUFFER_EXTRA; out->allocated = true; } out->cur = out->buf; diff --git a/ext/oj/mimic_json.c b/ext/oj/mimic_json.c index 483e7f6b..c6a9cc08 100644 --- a/ext/oj/mimic_json.c +++ b/ext/oj/mimic_json.c @@ -384,8 +384,14 @@ static VALUE mimic_generate_core(int argc, VALUE *argv, Options copts) { rb_raise(rb_eTypeError, "nil not allowed."); } */ - oj_dump_obj_to_json_using_params(*argv, copts, &out, argc - 1, argv + 1); + if (1 < argc) { + oj_dump_obj_to_json_using_params(*argv, copts, &out, argc - 1, argv + 1); + } else { + VALUE active_hack[1]; + active_hack[0] = rb_funcall(state_class, oj_new_id, 0); + oj_dump_obj_to_json_using_params(*argv, copts, &out, 1, active_hack); + } if (0 == out.buf) { rb_raise(rb_eNoMemError, "Not enough memory."); } @@ -755,7 +761,7 @@ static VALUE mimic_object_to_json(int argc, VALUE *argv, VALUE self) { // seem to prefer the option of changing that. // oj_dump_obj_to_json(self, &mimic_object_to_json_options, &out); oj_dump_obj_to_json_using_params(self, &copts, &out, argc, argv); - if (0 == out.buf) { + if (NULL == out.buf) { rb_raise(rb_eNoMemError, "Not enough memory."); } rstr = rb_str_new2(out.buf); diff --git a/ext/oj/oj.h b/ext/oj/oj.h index a49da513..de14eaeb 100644 --- a/ext/oj/oj.h +++ b/ext/oj/oj.h @@ -247,7 +247,7 @@ extern void oj_parse_options(VALUE ropts, Options copts); extern void oj_dump_obj_to_json(VALUE obj, Options copts, Out out); extern void - oj_dump_obj_to_json_using_params(VALUE obj, Options copts, Out out, int argc, VALUE *argv); +oj_dump_obj_to_json_using_params(VALUE obj, Options copts, Out out, int argc, VALUE *argv); extern void oj_write_obj_to_file(VALUE obj, const char *path, Options copts); extern void oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts); extern void oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out);