oj 3.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c5c4e44c052cf9e204ada5c41bc6b868b04ec56
4
- data.tar.gz: d2a0352206bb10de6743c8be87d22120f122c7ca
3
+ metadata.gz: 77898b80dc0daaabff6e620f0d9ef0b6eb26eac1
4
+ data.tar.gz: 112de18472976923d86d57a62fa30f611e0c4bbc
5
5
  SHA512:
6
- metadata.gz: f4e47a2c590b33dff4fd7057c9874d1ab95f9c0057cc7f22a30617604865d8999b2dab758c47d89ee6445de033eeb07ac3b32077db52080f08a62bf57af3b9e2
7
- data.tar.gz: 56ea00a656fc87fbc072a240ddcb58223627f4a28874d8b9fe37d1044757bd6e2cab993cadfc711be04adfae11cd2557c084a66e80c853132b6ff40adbef8913
6
+ metadata.gz: f59fca5e3442fcf3d46e5f931ec36657e54f359924e60707ed4962c11f9b7f402e41e2166befb257a7bf6686a4552a6be8553b84552908ca503a30bdd4f94ec1
7
+ data.tar.gz: 9443804d9d931de71e5b9d3f2ba29d05141fb0dd86bd9700d285908d75e5566f50476b5887200c49dc3524637a076c3efb9f489adb4926bf4dd0403753eb5032
@@ -624,7 +624,7 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
624
624
  oj_dump_cstr(buf, strlen(attr) + 1, 0, 0, out);
625
625
  }
626
626
  *out->cur++ = ':';
627
- oj_dump_obj_val(value, d2, out, true);
627
+ oj_dump_obj_val(value, d2, out);
628
628
  assure_size(out, 2);
629
629
  }
630
630
  #endif
@@ -113,7 +113,7 @@ oj_parse_mimic_dump_options(VALUE ropts, Options copts) {
113
113
  if (Qnil != (v = rb_hash_lookup(ropts, oj_indent_sym))) {
114
114
  rb_check_type(v, T_STRING);
115
115
  if (sizeof(copts->dump_opts.indent_str) <= (len = RSTRING_LEN(v))) {
116
- rb_raise(rb_eArgError, "indent string is limited to %lu characters.", sizeof(copts->dump_opts.indent_str));
116
+ rb_raise(rb_eArgError, "indent string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.indent_str));
117
117
  }
118
118
  strcpy(copts->dump_opts.indent_str, StringValuePtr(v));
119
119
  copts->dump_opts.indent_size = (uint8_t)len;
@@ -122,7 +122,7 @@ oj_parse_mimic_dump_options(VALUE ropts, Options copts) {
122
122
  if (Qnil != (v = rb_hash_lookup(ropts, oj_space_sym))) {
123
123
  rb_check_type(v, T_STRING);
124
124
  if (sizeof(copts->dump_opts.after_sep) <= (len = RSTRING_LEN(v))) {
125
- rb_raise(rb_eArgError, "space string is limited to %lu characters.", sizeof(copts->dump_opts.after_sep));
125
+ rb_raise(rb_eArgError, "space string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.after_sep));
126
126
  }
127
127
  strcpy(copts->dump_opts.after_sep, StringValuePtr(v));
128
128
  copts->dump_opts.after_size = (uint8_t)len;
@@ -131,7 +131,7 @@ oj_parse_mimic_dump_options(VALUE ropts, Options copts) {
131
131
  if (Qnil != (v = rb_hash_lookup(ropts, oj_space_before_sym))) {
132
132
  rb_check_type(v, T_STRING);
133
133
  if (sizeof(copts->dump_opts.before_sep) <= (len = RSTRING_LEN(v))) {
134
- rb_raise(rb_eArgError, "space_before string is limited to %lu characters.", sizeof(copts->dump_opts.before_sep));
134
+ rb_raise(rb_eArgError, "space_before string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.before_sep));
135
135
  }
136
136
  strcpy(copts->dump_opts.before_sep, StringValuePtr(v));
137
137
  copts->dump_opts.before_size = (uint8_t)len;
@@ -140,7 +140,7 @@ oj_parse_mimic_dump_options(VALUE ropts, Options copts) {
140
140
  if (Qnil != (v = rb_hash_lookup(ropts, oj_object_nl_sym))) {
141
141
  rb_check_type(v, T_STRING);
142
142
  if (sizeof(copts->dump_opts.hash_nl) <= (len = RSTRING_LEN(v))) {
143
- rb_raise(rb_eArgError, "object_nl string is limited to %lu characters.", sizeof(copts->dump_opts.hash_nl));
143
+ rb_raise(rb_eArgError, "object_nl string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.hash_nl));
144
144
  }
145
145
  strcpy(copts->dump_opts.hash_nl, StringValuePtr(v));
146
146
  copts->dump_opts.hash_size = (uint8_t)len;
@@ -149,7 +149,7 @@ oj_parse_mimic_dump_options(VALUE ropts, Options copts) {
149
149
  if (Qnil != (v = rb_hash_lookup(ropts, oj_array_nl_sym))) {
150
150
  rb_check_type(v, T_STRING);
151
151
  if (sizeof(copts->dump_opts.array_nl) <= (len = RSTRING_LEN(v))) {
152
- rb_raise(rb_eArgError, "array_nl string is limited to %lu characters.", sizeof(copts->dump_opts.array_nl));
152
+ rb_raise(rb_eArgError, "array_nl string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.array_nl));
153
153
  }
154
154
  strcpy(copts->dump_opts.array_nl, StringValuePtr(v));
155
155
  copts->dump_opts.array_size = (uint8_t)len;
@@ -407,7 +407,7 @@ oj_parse_options(VALUE ropts, Options copts) {
407
407
  break;
408
408
  case T_STRING:
409
409
  if (sizeof(copts->dump_opts.indent_str) <= (len = RSTRING_LEN(v))) {
410
- rb_raise(rb_eArgError, "indent string is limited to %lu characters.", sizeof(copts->dump_opts.indent_str));
410
+ rb_raise(rb_eArgError, "indent string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.indent_str));
411
411
  }
412
412
  strcpy(copts->dump_opts.indent_str, StringValuePtr(v));
413
413
  copts->dump_opts.indent_size = (uint8_t)len;
@@ -558,7 +558,7 @@ oj_parse_options(VALUE ropts, Options copts) {
558
558
  } else {
559
559
  rb_check_type(v, T_STRING);
560
560
  if (sizeof(copts->dump_opts.after_sep) <= (len = RSTRING_LEN(v))) {
561
- rb_raise(rb_eArgError, "space string is limited to %lu characters.", sizeof(copts->dump_opts.after_sep));
561
+ rb_raise(rb_eArgError, "space string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.after_sep));
562
562
  }
563
563
  strcpy(copts->dump_opts.after_sep, StringValuePtr(v));
564
564
  copts->dump_opts.after_size = (uint8_t)len;
@@ -571,7 +571,7 @@ oj_parse_options(VALUE ropts, Options copts) {
571
571
  } else {
572
572
  rb_check_type(v, T_STRING);
573
573
  if (sizeof(copts->dump_opts.before_sep) <= (len = RSTRING_LEN(v))) {
574
- rb_raise(rb_eArgError, "sapce_before string is limited to %lu characters.", sizeof(copts->dump_opts.before_sep));
574
+ rb_raise(rb_eArgError, "sapce_before string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.before_sep));
575
575
  }
576
576
  strcpy(copts->dump_opts.before_sep, StringValuePtr(v));
577
577
  copts->dump_opts.before_size = (uint8_t)len;
@@ -584,7 +584,7 @@ oj_parse_options(VALUE ropts, Options copts) {
584
584
  } else {
585
585
  rb_check_type(v, T_STRING);
586
586
  if (sizeof(copts->dump_opts.hash_nl) <= (len = RSTRING_LEN(v))) {
587
- rb_raise(rb_eArgError, "object_nl string is limited to %lu characters.", sizeof(copts->dump_opts.hash_nl));
587
+ rb_raise(rb_eArgError, "object_nl string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.hash_nl));
588
588
  }
589
589
  strcpy(copts->dump_opts.hash_nl, StringValuePtr(v));
590
590
  copts->dump_opts.hash_size = (uint8_t)len;
@@ -597,7 +597,7 @@ oj_parse_options(VALUE ropts, Options copts) {
597
597
  } else {
598
598
  rb_check_type(v, T_STRING);
599
599
  if (sizeof(copts->dump_opts.array_nl) <= (len = RSTRING_LEN(v))) {
600
- rb_raise(rb_eArgError, "array_nl string is limited to %lu characters.", sizeof(copts->dump_opts.array_nl));
600
+ rb_raise(rb_eArgError, "array_nl string is limited to %lu characters.", (unsigned long)sizeof(copts->dump_opts.array_nl));
601
601
  }
602
602
  strcpy(copts->dump_opts.array_nl, StringValuePtr(v));
603
603
  copts->dump_opts.array_size = (uint8_t)len;
@@ -834,6 +834,7 @@ dump_as_json(VALUE obj, int depth, Out out, bool as_ok) {
834
834
  } else {
835
835
  ja = rb_funcall(obj, oj_as_json_id, 0);
836
836
  }
837
+ out->argc = 0;
837
838
  if (ja == obj || !as_ok) {
838
839
  // Once as_json is call it should never be called again on the same
839
840
  // object with as_ok.
@@ -842,7 +843,7 @@ dump_as_json(VALUE obj, int depth, Out out, bool as_ok) {
842
843
  int type = rb_type(ja);
843
844
 
844
845
  if (T_HASH == type || T_ARRAY == type) {
845
- dump_rails_val(ja, depth, out, false);
846
+ dump_rails_val(ja, depth, out, true);
846
847
  } else {
847
848
  dump_rails_val(ja, depth, out, true);
848
849
  }
@@ -851,7 +852,7 @@ dump_as_json(VALUE obj, int depth, Out out, bool as_ok) {
851
852
 
852
853
  static void
853
854
  dump_to_hash(VALUE obj, int depth, Out out) {
854
- dump_rails_val(rb_funcall(obj, oj_to_hash_id, 0), depth, out, false);
855
+ dump_rails_val(rb_funcall(obj, oj_to_hash_id, 0), depth, out, true);
855
856
  }
856
857
 
857
858
  static void
@@ -931,7 +932,7 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
931
932
  } else {
932
933
  fill_indent(out, d2);
933
934
  }
934
- dump_rails_val(rb_ary_entry(a, i), d2, out, as_ok);
935
+ dump_rails_val(rb_ary_entry(a, i), d2, out, true);
935
936
  if (i < cnt) {
936
937
  *out->cur++ = ',';
937
938
  }
@@ -1010,7 +1011,7 @@ hash_cb(VALUE key, VALUE value, Out out) {
1010
1011
  out->cur += out->opts->dump_opts.after_size;
1011
1012
  }
1012
1013
  }
1013
- dump_rails_val(value, depth, out, false);
1014
+ dump_rails_val(value, depth, out, true);
1014
1015
  out->depth = depth;
1015
1016
  *out->cur++ = ',';
1016
1017
 
@@ -1028,7 +1029,11 @@ dump_hash(VALUE obj, int depth, Out out, bool as_ok) {
1028
1029
  return;
1029
1030
  }
1030
1031
  }
1031
- if (as_ok && !oj_rails_hash_opt && rb_respond_to(obj, oj_as_json_id)) {
1032
+ // Nothing good can come from calling as_json on a hash which is supposed
1033
+ // to be a primitive so if the type is a hash and the class is also a hash
1034
+ // then do not call as_json.
1035
+ //if (!oj_rails_hash_opt && as_ok && rb_cHash != rb_obj_class(obj) && rb_respond_to(obj, oj_as_json_id)) {
1036
+ if (!oj_rails_hash_opt && as_ok && rb_respond_to(obj, oj_as_json_id)) {
1032
1037
  dump_as_json(obj, depth, out, false);
1033
1038
  return;
1034
1039
  }
@@ -1071,6 +1076,7 @@ dump_hash(VALUE obj, int depth, Out out, bool as_ok) {
1071
1076
  static void
1072
1077
  dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
1073
1078
  if (oj_code_dump(oj_compat_codes, obj, depth, out)) {
1079
+ out->argc = 0;
1074
1080
  return;
1075
1081
  }
1076
1082
  if (as_ok) {
@@ -1096,6 +1102,7 @@ dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
1096
1102
  static void
1097
1103
  dump_as_string(VALUE obj, int depth, Out out, bool as_ok) {
1098
1104
  if (oj_code_dump(oj_compat_codes, obj, depth, out)) {
1105
+ out->argc = 0;
1099
1106
  return;
1100
1107
  }
1101
1108
  oj_dump_obj_to_s(obj, out);
@@ -6,16 +6,20 @@
6
6
  #include <sys/types.h>
7
7
  #include <stdlib.h>
8
8
  #include <errno.h>
9
- #include <regex.h>
10
9
  #include <string.h>
11
10
  #include <stdio.h>
11
+ #if !IS_WINDOWS
12
+ #include <regex.h>
13
+ #endif
12
14
 
13
15
  #include "rxclass.h"
14
16
 
15
17
  typedef struct _RxC {
16
18
  struct _RxC *next;
17
19
  VALUE rrx;
20
+ #if !IS_WINDOWS
18
21
  regex_t rx;
22
+ #endif
19
23
  VALUE clas;
20
24
  char src[256];
21
25
  } *RxC;
@@ -33,10 +37,12 @@ oj_rxclass_cleanup(RxClass rc) {
33
37
 
34
38
  while (NULL != (rxc = rc->head)) {
35
39
  rc->head = rc->head->next;
40
+ #if !IS_WINDOWS
36
41
  if (Qnil == rxc->rrx) {
37
42
  regfree(&rxc->rx);
38
43
  }
39
44
  xfree(rxc);
45
+ #endif
40
46
  }
41
47
  }
42
48
 
@@ -58,25 +64,29 @@ oj_rxclass_rappend(RxClass rc, VALUE rx, VALUE clas) {
58
64
  // Attempt to compile the expression. If it fails populate the error code..
59
65
  int
60
66
  oj_rxclass_append(RxClass rc, const char *expr, VALUE clas) {
61
- // Use mallow and not ALLOC_N to avoid pulliing ruby.h which conflicts
62
- // with regex_t.
63
67
  RxC rxc;
68
+ #if !IS_WINDOWS
64
69
  int err;
65
70
  int flags = 0;
66
-
71
+ #endif
67
72
  if (sizeof(rxc->src) <= strlen(expr)) {
68
- snprintf(rc->err, sizeof(rc->err), "expressions must be less than %lu chracter", sizeof(rxc->src));
73
+ snprintf(rc->err, sizeof(rc->err), "expressions must be less than %lu characters", sizeof(rxc->src));
69
74
  return EINVAL;
70
75
  }
71
76
  rxc = ALLOC_N(struct _RxC, 1);
72
77
  rxc->next = 0;
73
- rxc->rrx = Qnil;
74
78
  rxc->clas = clas;
79
+
80
+ #if IS_WINDOWS
81
+ rxc->rrx = rb_funcall(rb_cRegexp, rb_intern("new"), 1, rb_str_new2(expr));
82
+ #else
83
+ rxc->rrx = Qnil;
75
84
  if (0 != (err = regcomp(&rxc->rx, expr, flags))) {
76
85
  regerror(err, &rxc->rx, rc->err, sizeof(rc->err));
77
86
  free(rxc);
78
87
  return err;
79
88
  }
89
+ #endif
80
90
  if (NULL == rc->tail) {
81
91
  rc->head = rxc;
82
92
  } else {
@@ -102,12 +112,14 @@ oj_rxclass_match(RxClass rc, const char *str, int len) {
102
112
  return rxc->clas;
103
113
  }
104
114
  } else if (len < (int)sizeof(buf)) {
115
+ #if !IS_WINDOWS
105
116
  // string is not \0 terminated so copy and atempt a match
106
117
  memcpy(buf, str, len);
107
118
  buf[len] = '\0';
108
119
  if (0 == regexec(&rxc->rx, buf, 0, NULL, 0)) { // match
109
120
  return rxc->clas;
110
121
  }
122
+ #endif
111
123
  } else {
112
124
  // TBD allocate a larger buffer and attempt
113
125
  }
@@ -126,7 +138,9 @@ oj_rxclass_copy(RxClass src, RxClass dest) {
126
138
  if (Qnil != rxc->rrx) {
127
139
  oj_rxclass_rappend(dest, rxc->rrx, rxc->clas);
128
140
  } else {
141
+ #if !IS_WINDOWS
129
142
  oj_rxclass_append(dest, rxc->src, rxc->clas);
143
+ #endif
130
144
  }
131
145
  }
132
146
  }
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.0.3'
4
+ VERSION = '3.0.4'
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.0.3
4
+ version: 3.0.4
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-04-30 00:00:00.000000000 Z
11
+ date: 2017-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler