Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate special #654

Merged
merged 2 commits into from Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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`.
Expand Down
4 changes: 2 additions & 2 deletions ext/oj/dump.c
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions ext/oj/mimic_json.c
Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ext/oj/oj.h
Expand Up @@ -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);
Expand Down