Skip to content

Commit

Permalink
Update for Ruby 2.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Jan 3, 2020
1 parent 3ecec05 commit 0d786fa
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 36 deletions.
12 changes: 4 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ env:
language: ruby
rvm:
- 2.3.8
- 2.4.6
- 2.4.9
- 2.5.5
- 2.5.7
- 2.6.3
- 2.6.5
- 2.7.0
- ruby-head

gemfile:
Expand All @@ -32,19 +30,17 @@ matrix:
- gemfile: gemfiles/no_rails.gemfile
rvm: 2.3.8
- gemfile: gemfiles/no_rails.gemfile
rvm: 2.4.6
rvm: 2.4.9
os: osx
- gemfile: gemfiles/rails_5.gemfile
rvm: 2.4.6
rvm: 2.4.9
os: osx
- gemfile: gemfiles/rails_5.gemfile
rvm: 2.5.5
rvm: 2.5.7
os: osx
# Rails 6 only support Ruby 2.5 and above.
- gemfile: gemfiles/rails_6.gemfile
rvm: 2.3.8
- gemfile: gemfiles/rails_6.gemfile
rvm: 2.4.6
- gemfile: gemfiles/rails_6.gemfile
rvm: 2.4.9
- os: osx
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# CHANGELOG

## 3.10.1 - 2019-12-31
## 3.10.1 - 2020-01-??

- Fixed bug where setting `ActiveSupport::JSON::Encoding.use_standard_json_time_format` before calling `Oj.optimize_rails` did not have an effect on the time format.

- Updated for Ruby 2.7.0

## 3.10.0 - 2019-11-28

- Fixed custom mode load_file to use custom mode.
Expand Down
6 changes: 4 additions & 2 deletions ext/oj/custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ static struct _code codes[] = {
};

static int
hash_cb(VALUE key, VALUE value, Out out) {
hash_cb(VALUE key, VALUE value, VALUE ov) {
Out out = (Out)ov;
int depth = out->depth;

if (oj_dump_ignore(out->opts, value)) {
Expand Down Expand Up @@ -592,7 +593,8 @@ dump_common(VALUE obj, int depth, Out out) {
}

static int
dump_attr_cb(ID key, VALUE value, Out out) {
dump_attr_cb(ID key, VALUE value, VALUE ov) {
Out out = (Out)ov;
int depth = out->depth;
size_t size;
const char *attr;
Expand Down
3 changes: 2 additions & 1 deletion ext/oj/dump_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
}

static int
hash_cb(VALUE key, VALUE value, Out out) {
hash_cb(VALUE key, VALUE value, VALUE ov) {
Out out = (Out)ov;
int depth = out->depth;

if (out->omit_nil && Qnil == value) {
Expand Down
6 changes: 4 additions & 2 deletions ext/oj/dump_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ dump_sym(VALUE obj, int depth, Out out, bool as_ok) {
}

static int
hash_cb(VALUE key, VALUE value, Out out) {
hash_cb(VALUE key, VALUE value, VALUE ov) {
Out out = (Out)ov;
int depth = out->depth;
long size = depth * out->indent + 1;

Expand Down Expand Up @@ -348,7 +349,8 @@ dump_hash_class(VALUE obj, VALUE clas, int depth, Out out) {

#ifdef HAVE_RB_IVAR_FOREACH
static int
dump_attr_cb(ID key, VALUE value, Out out) {
dump_attr_cb(ID key, VALUE value, VALUE ov) {
Out out = (Out)ov;
int depth = out->depth;
size_t size = depth * out->indent + 1;
const char *attr = rb_id2name(key);
Expand Down
11 changes: 6 additions & 5 deletions ext/oj/dump_strict.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
cnt = 3;
} else {
NanDump nd = out->opts->dump_opts.nan_dump;

if (AutoNan == nd) {
nd = RaiseNan;
}
Expand Down Expand Up @@ -195,11 +195,12 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
}

static int
hash_cb(VALUE key, VALUE value, Out out) {
hash_cb(VALUE key, VALUE value, VALUE ov) {
Out out = (Out)ov;
int depth = out->depth;
long size;
int rtype = rb_type(key);

if (rtype != T_STRING && rtype != T_SYMBOL) {
rb_raise(rb_eTypeError, "In :strict and :null mode all Hash keys must be Strings or Symbols, not %s.\n", rb_class2name(rb_obj_class(key)));
}
Expand Down Expand Up @@ -359,7 +360,7 @@ static DumpFunc strict_funcs[] = {
void
oj_dump_strict_val(VALUE obj, int depth, Out out) {
int type = rb_type(obj);

if (Yes == out->opts->trace) {
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
}
Expand Down Expand Up @@ -408,7 +409,7 @@ static DumpFunc null_funcs[] = {
void
oj_dump_null_val(VALUE obj, int depth, Out out) {
int type = rb_type(obj);

if (Yes == out->opts->trace) {
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceOut);
}
Expand Down
5 changes: 5 additions & 0 deletions ext/oj/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@

$CPPFLAGS += ' -Wall'
#puts "*** $CPPFLAGS: #{$CPPFLAGS}"
# Adding the __attribute__ flag only works with gcc compilers and even then it
# does not work to check args with varargs so just remove the check.
CONFIG['warnflags'].slice!(/ -Wsuggest-attribute=format/)
CONFIG['warnflags'].slice!(/ -Wdeclaration-after-statement/)
CONFIG['warnflags'].slice!(/ -Wmissing-noreturn/)

create_makefile(File.join(extension_name, extension_name))

Expand Down
4 changes: 3 additions & 1 deletion ext/oj/oj.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,9 @@ oj_parse_options(VALUE ropts, Options copts) {
}

static int
match_string_cb(VALUE key, VALUE value, RxClass rc) {
match_string_cb(VALUE key, VALUE value, VALUE rx) {
RxClass rc = (RxClass)rx;

if (T_CLASS != rb_type(value)) {
rb_raise(rb_eArgError, "for :match_string, the hash values must be a Class.");
}
Expand Down
2 changes: 1 addition & 1 deletion ext/oj/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ oj_parse2(ParseInfo pi) {
}

static VALUE
rescue_big_decimal(VALUE str) {
rescue_big_decimal(VALUE str, VALUE ignore) {
rb_raise(oj_parse_error_class, "Invalid value for BigDecimal()");
return Qnil;
}
Expand Down
6 changes: 4 additions & 2 deletions ext/oj/rails.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ copy_opts(ROptTable src, ROptTable dest) {
}

static int
dump_attr_cb(ID key, VALUE value, Out out) {
dump_attr_cb(ID key, VALUE value, VALUE ov) {
Out out = (Out)ov;
int depth = out->depth;
size_t size = depth * out->indent + 1;
const char *attr = rb_id2name(key);
Expand Down Expand Up @@ -1296,7 +1297,8 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
}

static int
hash_cb(VALUE key, VALUE value, Out out) {
hash_cb(VALUE key, VALUE value, VALUE ov) {
Out out = (Out)ov;
int depth = out->depth;
long size;
int rtype = rb_type(key);
Expand Down
18 changes: 9 additions & 9 deletions ext/oj/wab.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
}

static int
hash_cb(VALUE key, VALUE value, Out out) {
hash_cb(VALUE key, VALUE value, VALUE ov) {
Out out = (Out)ov;
int depth = out->depth;
long size;
int rtype = rb_type(key);

if (rtype != T_SYMBOL) {
rb_raise(rb_eTypeError, "In :wab mode all Hash keys must be Symbols, not %s.\n", rb_class2name(rb_obj_class(key)));
}
Expand Down Expand Up @@ -270,7 +271,7 @@ static DumpFunc wab_funcs[] = {
void
oj_dump_wab_val(VALUE obj, int depth, Out out) {
int type = rb_type(obj);

if (Yes == out->opts->trace) {
oj_trace("dump", obj, __FILE__, __LINE__, depth, TraceIn);
}
Expand Down Expand Up @@ -324,7 +325,7 @@ add_value(ParseInfo pi, VALUE val) {
static bool
uuid_check(const char *str, int len) {
int i;

for (i = 0; i < 8; i++, str++) {
if ('x' != hex_chars[*(uint8_t*)str]) {
return false;
Expand Down Expand Up @@ -380,7 +381,7 @@ time_parse(const char *s, int len) {
long nsecs = 0;
int i;
time_t secs;

memset(&tm, 0, sizeof(tm));
if ('-' == *s) {
s++;
Expand Down Expand Up @@ -444,7 +445,7 @@ protect_uri(VALUE rstr) {
static VALUE
cstr_to_rstr(const char *str, size_t len) {
volatile VALUE v = Qnil;

if (30 == len && '-' == str[4] && '-' == str[7] && 'T' == str[10] && ':' == str[13] && ':' == str[16] && '.' == str[19] && 'Z' == str[29]) {
if (Qnil != (v = time_parse(str, (int)len))) {
return v;
Expand Down Expand Up @@ -521,7 +522,7 @@ hash_set_cstr(ParseInfo pi, Val parent, const char *str, size_t len, const char
static void
hash_set_num(ParseInfo pi, Val parent, NumInfo ni) {
volatile VALUE rval = Qnil;

if (ni->infinity || ni->nan) {
oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "not a number or other value");
}
Expand Down Expand Up @@ -551,7 +552,7 @@ start_array(ParseInfo pi) {
static void
array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
volatile VALUE rval = cstr_to_rstr(str, len);

rb_ary_push(stack_peek(&pi->stack)->val, rval);
if (Yes == pi->options.trace) {
oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, rval);
Expand Down Expand Up @@ -628,4 +629,3 @@ oj_wab_parse_cstr(int argc, VALUE *argv, char *json, size_t len) {

return oj_pi_parse(argc, argv, &pi, json, len, true);
}

23 changes: 19 additions & 4 deletions test/test_custom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,10 @@ def test_openstruct

def test_time
obj = Time.now()
dump_and_load(obj, false, :time_format => :unix, :create_id => "^o", :create_additions => true)
dump_and_load_inspect(obj, false, :time_format => :unix_zone, :create_id => "^o", :create_additions => true)
dump_and_load_inspect(obj, false, :time_format => :xmlschema, :create_id => "^o", :create_additions => true)
dump_and_load_inspect(obj, false, :time_format => :ruby, :create_id => "^o", :create_additions => true)
dump_load_dump(obj, false, :time_format => :unix, :create_id => "^o", :create_additions => true)
dump_load_dump(obj, false, :time_format => :unix_zone, :create_id => "^o", :create_additions => true)
dump_load_dump(obj, false, :time_format => :xmlschema, :create_id => "^o", :create_additions => true)
dump_load_dump(obj, false, :time_format => :ruby, :create_id => "^o", :create_additions => true)
end

def dump_and_load(obj, trace=false, options={})
Expand Down Expand Up @@ -504,4 +504,19 @@ def dump_and_load_inspect(obj, trace=false, options={})
loaded
end

def dump_load_dump(obj, trace=false, options={})
options = options.merge(:indent => 2, :mode => :custom)
json = Oj.dump(obj, options)
puts json if trace

loaded = Oj.load(json, options);
if obj.nil?
assert_nil(loaded)
else
json2 = Oj.dump(loaded, options)
assert_equal(json, json2)
end
loaded
end

end

0 comments on commit 0d786fa

Please sign in to comment.