oj 3.3.7 → 3.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4d5410c27e25a4075040fce057dafda891377af
4
- data.tar.gz: f06d843cbecfc3c54eac85685be54fb9d0a2cafa
3
+ metadata.gz: 28fc69ea25c02c80fd4d5d1622f05350e0fd6d5e
4
+ data.tar.gz: 143ef4198b371f30dbdd12d8e4f1ecd4b43cdb08
5
5
  SHA512:
6
- metadata.gz: 5f5f28ef22ad9c2b60699458eb5a2e98c70a991989649b974b67c25109d31076a48244c4970aea3af4055d734f7e3c121ec9cdc1f73ed643d2a969c8895149f3
7
- data.tar.gz: eee14c01cf62adabfcfe162997e74e7b31da61a5e2446495221446584e9bb39e8baaae20eff8a3245804c29a84812bb73f3a0f85d567deff9c6d90cc0f5f7e51
6
+ metadata.gz: b0478c6f09d46f53827b981ed947002c8b723884c83276384b1316f2d85db9dd29dba0095d4d6a8d618062c313954d5883e05b08e8ba016bb949aae43b797dad
7
+ data.tar.gz: 826fdefe54a411b7b92cc5563caeacccced2a7c0a25f869e1995fca3309cef7e4692e0ddb6e219317e788cc40daf3ddd4c0eb1c45bc932b4ab0e44a7c9d44bae
@@ -1110,7 +1110,7 @@ oj_dump_float(VALUE obj, int depth, Out out, bool as_ok) {
1110
1110
  strncpy(buf, rb_string_value_ptr((VALUE*)&rstr), cnt);
1111
1111
  buf[cnt] = '\0';
1112
1112
  } else {
1113
- cnt = snprintf(buf, sizeof(buf), out->opts->float_fmt, d);
1113
+ cnt = oj_dump_float_printf(buf, sizeof(buf), obj, d, out->opts->float_fmt);
1114
1114
  }
1115
1115
  assure_size(out, cnt);
1116
1116
  for (b = buf; '\0' != *b; b++) {
@@ -1118,3 +1118,18 @@ oj_dump_float(VALUE obj, int depth, Out out, bool as_ok) {
1118
1118
  }
1119
1119
  *out->cur = '\0';
1120
1120
  }
1121
+
1122
+ int
1123
+ oj_dump_float_printf(char *buf, size_t blen, VALUE obj, double d, const char *format) {
1124
+ int cnt = snprintf(buf, blen, format, d);
1125
+
1126
+ // Round off issues at 16 significant digits so check for obvious ones of
1127
+ // 0001 and 9999.
1128
+ if (17 <= cnt && (0 == strcmp("0001", buf + cnt - 4) || 0 == strcmp("9999", buf + cnt - 4))) {
1129
+ volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
1130
+
1131
+ strcpy(buf, rb_string_value_ptr((VALUE*)&rstr));
1132
+ cnt = (int)RSTRING_LEN(rstr);
1133
+ }
1134
+ return cnt;
1135
+ }
@@ -48,6 +48,8 @@ extern void oj_dump_wab_val(VALUE obj, int depth, Out out);
48
48
  extern VALUE oj_add_to_json(int argc, VALUE *argv, VALUE self);
49
49
  extern VALUE oj_remove_to_json(int argc, VALUE *argv, VALUE self);
50
50
 
51
+ extern int oj_dump_float_printf(char *buf, size_t blen, VALUE obj, double d, const char *format);
52
+
51
53
  inline static void
52
54
  assure_size(Out out, size_t len) {
53
55
  if (out->end - out->cur <= (long)len) {
@@ -611,10 +611,9 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
611
611
  raise_json_err("NaN not allowed in JSON.", "GeneratorError");
612
612
  }
613
613
  } else if (d == (double)(long long int)d) {
614
- //cnt = snprintf(buf, sizeof(buf), "%.1Lf", (long double)d);
615
614
  cnt = snprintf(buf, sizeof(buf), "%.1f", d);
616
615
  } else if (oj_rails_float_opt) {
617
- cnt = snprintf(buf, sizeof(buf), "%0.16g", d);
616
+ cnt = oj_dump_float_printf(buf, sizeof(buf), obj, d, "%0.16g");
618
617
  } else {
619
618
  volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
620
619
 
@@ -115,7 +115,7 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
115
115
  strncpy(buf, rb_string_value_ptr((VALUE*)&rstr), cnt);
116
116
  buf[cnt] = '\0';
117
117
  } else {
118
- cnt = snprintf(buf, sizeof(buf), out->opts->float_fmt, d);
118
+ cnt = oj_dump_float_printf(buf, sizeof(buf), obj, d, out->opts->float_fmt);
119
119
  }
120
120
  }
121
121
  assure_size(out, cnt);
@@ -795,7 +795,6 @@ oj_mimic_json_methods(VALUE json) {
795
795
  } else {
796
796
  oj_json_parser_error_class = rb_define_class_under(json, "ParserError", json_error);
797
797
  }
798
- printf("*** setting parse error to %lx %s\n", oj_json_parser_error_class, rb_class2name(oj_json_parser_error_class));
799
798
  if (rb_const_defined_at(json, rb_intern("GeneratorError"))) {
800
799
  oj_json_generator_error_class = rb_const_get(json, rb_intern("GeneratorError"));
801
800
  } else {
@@ -972,7 +972,7 @@ dump_float(VALUE obj, int depth, Out out, bool as_ok) {
972
972
  } else if (d == (double)(long long int)d) {
973
973
  cnt = snprintf(buf, sizeof(buf), "%.1f", d);
974
974
  } else if (oj_rails_float_opt) {
975
- cnt = snprintf(buf, sizeof(buf), "%0.16g", d);
975
+ cnt = oj_dump_float_printf(buf, sizeof(buf), obj, d, "%0.16g");
976
976
  } else {
977
977
  volatile VALUE rstr = rb_funcall(obj, oj_to_s_id, 0);
978
978
 
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.3.7'
4
+ VERSION = '3.3.8'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.7
4
+ version: 3.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-02 00:00:00.000000000 Z
11
+ date: 2017-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler