oj 3.11.0 → 3.11.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/ext/oj/buf.h +34 -38
  4. data/ext/oj/cache8.c +59 -62
  5. data/ext/oj/cache8.h +8 -7
  6. data/ext/oj/circarray.c +33 -35
  7. data/ext/oj/circarray.h +11 -9
  8. data/ext/oj/code.c +170 -174
  9. data/ext/oj/code.h +21 -20
  10. data/ext/oj/compat.c +159 -166
  11. data/ext/oj/custom.c +802 -851
  12. data/ext/oj/dump.c +766 -778
  13. data/ext/oj/dump.h +49 -51
  14. data/ext/oj/dump_compat.c +1 -0
  15. data/ext/oj/dump_leaf.c +116 -157
  16. data/ext/oj/dump_object.c +609 -628
  17. data/ext/oj/dump_strict.c +318 -327
  18. data/ext/oj/encode.h +3 -4
  19. data/ext/oj/err.c +39 -25
  20. data/ext/oj/err.h +24 -15
  21. data/ext/oj/extconf.rb +2 -1
  22. data/ext/oj/fast.c +1008 -1038
  23. data/ext/oj/hash.c +62 -66
  24. data/ext/oj/hash.h +7 -6
  25. data/ext/oj/hash_test.c +450 -443
  26. data/ext/oj/mimic_json.c +413 -402
  27. data/ext/oj/object.c +559 -528
  28. data/ext/oj/odd.c +123 -128
  29. data/ext/oj/odd.h +27 -25
  30. data/ext/oj/oj.c +1131 -924
  31. data/ext/oj/oj.h +286 -298
  32. data/ext/oj/parse.c +938 -930
  33. data/ext/oj/parse.h +70 -69
  34. data/ext/oj/rails.c +836 -839
  35. data/ext/oj/rails.h +7 -7
  36. data/ext/oj/reader.c +135 -140
  37. data/ext/oj/reader.h +66 -79
  38. data/ext/oj/resolve.c +43 -43
  39. data/ext/oj/resolve.h +3 -2
  40. data/ext/oj/rxclass.c +67 -68
  41. data/ext/oj/rxclass.h +12 -10
  42. data/ext/oj/saj.c +451 -479
  43. data/ext/oj/scp.c +93 -103
  44. data/ext/oj/sparse.c +770 -730
  45. data/ext/oj/stream_writer.c +120 -149
  46. data/ext/oj/strict.c +71 -86
  47. data/ext/oj/string_writer.c +198 -243
  48. data/ext/oj/trace.c +29 -33
  49. data/ext/oj/trace.h +14 -11
  50. data/ext/oj/util.c +103 -103
  51. data/ext/oj/util.h +3 -2
  52. data/ext/oj/val_stack.c +47 -47
  53. data/ext/oj/val_stack.h +79 -86
  54. data/ext/oj/wab.c +291 -309
  55. data/lib/oj/bag.rb +1 -0
  56. data/lib/oj/easy_hash.rb +5 -4
  57. data/lib/oj/mimic.rb +0 -12
  58. data/lib/oj/version.rb +1 -1
  59. data/test/activerecord/result_test.rb +7 -2
  60. data/test/foo.rb +35 -32
  61. data/test/helper.rb +10 -0
  62. data/test/json_gem/json_generator_test.rb +15 -3
  63. data/test/json_gem/test_helper.rb +8 -0
  64. data/test/test_compat.rb +2 -2
  65. data/test/test_generate.rb +21 -0
  66. data/test/test_hash.rb +10 -0
  67. data/test/test_scp.rb +1 -1
  68. metadata +4 -2
data/ext/oj/dump.h CHANGED
@@ -1,4 +1,5 @@
1
1
  // Copyright (c) 2011 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
2
3
 
3
4
  #ifndef OJ_DUMP_H
4
5
  #define OJ_DUMP_H
@@ -12,80 +13,77 @@
12
13
  // Extra padding at end of buffer.
13
14
  #define BUFFER_EXTRA 64
14
15
 
15
- extern void oj_dump_nil(VALUE obj, int depth, Out out, bool as_ok);
16
- extern void oj_dump_true(VALUE obj, int depth, Out out, bool as_ok);
17
- extern void oj_dump_false(VALUE obj, int depth, Out out, bool as_ok);
18
- extern void oj_dump_fixnum(VALUE obj, int depth, Out out, bool as_ok);
19
- extern void oj_dump_bignum(VALUE obj, int depth, Out out, bool as_ok);
20
- extern void oj_dump_float(VALUE obj, int depth, Out out, bool as_ok);
21
- extern void oj_dump_str(VALUE obj, int depth, Out out, bool as_ok);
22
- extern void oj_dump_sym(VALUE obj, int depth, Out out, bool as_ok);
23
- extern void oj_dump_class(VALUE obj, int depth, Out out, bool as_ok);
16
+ extern void oj_dump_nil(VALUE obj, int depth, Out out, bool as_ok);
17
+ extern void oj_dump_true(VALUE obj, int depth, Out out, bool as_ok);
18
+ extern void oj_dump_false(VALUE obj, int depth, Out out, bool as_ok);
19
+ extern void oj_dump_fixnum(VALUE obj, int depth, Out out, bool as_ok);
20
+ extern void oj_dump_bignum(VALUE obj, int depth, Out out, bool as_ok);
21
+ extern void oj_dump_float(VALUE obj, int depth, Out out, bool as_ok);
22
+ extern void oj_dump_str(VALUE obj, int depth, Out out, bool as_ok);
23
+ extern void oj_dump_sym(VALUE obj, int depth, Out out, bool as_ok);
24
+ extern void oj_dump_class(VALUE obj, int depth, Out out, bool as_ok);
24
25
 
25
- extern void oj_dump_raw(const char *str, size_t cnt, Out out);
26
- extern void oj_dump_cstr(const char *str, size_t cnt, bool is_sym, bool escape1, Out out);
27
- extern void oj_dump_ruby_time(VALUE obj, Out out);
28
- extern void oj_dump_xml_time(VALUE obj, Out out);
29
- extern void oj_dump_time(VALUE obj, Out out, int withZone);
30
- extern void oj_dump_obj_to_s(VALUE obj, Out out);
26
+ extern void oj_dump_raw(const char *str, size_t cnt, Out out);
27
+ extern void oj_dump_cstr(const char *str, size_t cnt, bool is_sym, bool escape1, Out out);
28
+ extern void oj_dump_ruby_time(VALUE obj, Out out);
29
+ extern void oj_dump_xml_time(VALUE obj, Out out);
30
+ extern void oj_dump_time(VALUE obj, Out out, int withZone);
31
+ extern void oj_dump_obj_to_s(VALUE obj, Out out);
31
32
 
32
- extern const char* oj_nan_str(VALUE obj, int opt, int mode, bool plus, int *lenp);
33
+ extern const char *oj_nan_str(VALUE obj, int opt, int mode, bool plus, int *lenp);
33
34
 
34
- extern void oj_grow_out(Out out, size_t len);
35
- extern long oj_check_circular(VALUE obj, Out out);
35
+ extern void oj_grow_out(Out out, size_t len);
36
+ extern long oj_check_circular(VALUE obj, Out out);
36
37
 
37
- extern void oj_dump_strict_val(VALUE obj, int depth, Out out);
38
- extern void oj_dump_null_val(VALUE obj, int depth, Out out);
39
- extern void oj_dump_obj_val(VALUE obj, int depth, Out out);
40
- extern void oj_dump_compat_val(VALUE obj, int depth, Out out, bool as_ok);
41
- extern void oj_dump_rails_val(VALUE obj, int depth, Out out);
42
- extern void oj_dump_custom_val(VALUE obj, int depth, Out out, bool as_ok);
43
- extern void oj_dump_wab_val(VALUE obj, int depth, Out out);
38
+ extern void oj_dump_strict_val(VALUE obj, int depth, Out out);
39
+ extern void oj_dump_null_val(VALUE obj, int depth, Out out);
40
+ extern void oj_dump_obj_val(VALUE obj, int depth, Out out);
41
+ extern void oj_dump_compat_val(VALUE obj, int depth, Out out, bool as_ok);
42
+ extern void oj_dump_rails_val(VALUE obj, int depth, Out out);
43
+ extern void oj_dump_custom_val(VALUE obj, int depth, Out out, bool as_ok);
44
+ extern void oj_dump_wab_val(VALUE obj, int depth, Out out);
44
45
 
45
- extern void oj_dump_raw_json(VALUE obj, int depth, Out out);
46
+ extern void oj_dump_raw_json(VALUE obj, int depth, Out out);
46
47
 
47
- extern VALUE oj_add_to_json(int argc, VALUE *argv, VALUE self);
48
- extern VALUE oj_remove_to_json(int argc, VALUE *argv, VALUE self);
48
+ extern VALUE oj_add_to_json(int argc, VALUE *argv, VALUE self);
49
+ extern VALUE oj_remove_to_json(int argc, VALUE *argv, VALUE self);
49
50
 
50
- extern int oj_dump_float_printf(char *buf, size_t blen, VALUE obj, double d, const char *format);
51
+ extern int oj_dump_float_printf(char *buf, size_t blen, VALUE obj, double d, const char *format);
51
52
 
52
- extern bool oj_dump_ignore(Options opts, VALUE obj);
53
- extern time_t oj_sec_from_time_hard_way(VALUE obj);
53
+ extern bool oj_dump_ignore(Options opts, VALUE obj);
54
+ extern time_t oj_sec_from_time_hard_way(VALUE obj);
54
55
 
55
- inline static void
56
- assure_size(Out out, size_t len) {
56
+ inline static void assure_size(Out out, size_t len) {
57
57
  if (out->end - out->cur <= (long)len) {
58
- oj_grow_out(out, len);
58
+ oj_grow_out(out, len);
59
59
  }
60
60
  }
61
61
 
62
- inline static void
63
- fill_indent(Out out, int cnt) {
62
+ inline static void fill_indent(Out out, int cnt) {
64
63
  if (0 < out->indent) {
65
- cnt *= out->indent;
66
- *out->cur++ = '\n';
67
- for (; 0 < cnt; cnt--) {
68
- *out->cur++ = ' ';
69
- }
64
+ cnt *= out->indent;
65
+ *out->cur++ = '\n';
66
+ for (; 0 < cnt; cnt--) {
67
+ *out->cur++ = ' ';
68
+ }
70
69
  }
71
70
  }
72
71
 
73
- inline static void
74
- dump_ulong(unsigned long num, Out out) {
75
- char buf[32];
76
- char *b = buf + sizeof(buf) - 1;
72
+ inline static void dump_ulong(unsigned long num, Out out) {
73
+ char buf[32];
74
+ char *b = buf + sizeof(buf) - 1;
77
75
 
78
76
  *b-- = '\0';
79
77
  if (0 < num) {
80
- for (; 0 < num; num /= 10, b--) {
81
- *b = (num % 10) + '0';
82
- }
83
- b++;
78
+ for (; 0 < num; num /= 10, b--) {
79
+ *b = (num % 10) + '0';
80
+ }
81
+ b++;
84
82
  } else {
85
- *b = '0';
83
+ *b = '0';
86
84
  }
87
85
  for (; '\0' != *b; b++) {
88
- *out->cur++ = *b;
86
+ *out->cur++ = *b;
89
87
  }
90
88
  *out->cur = '\0';
91
89
  }
data/ext/oj/dump_compat.c CHANGED
@@ -1,4 +1,5 @@
1
1
  // Copyright (c) 2012, 2017 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
2
3
 
3
4
  #include "code.h"
4
5
  #include "dump.h"
data/ext/oj/dump_leaf.c CHANGED
@@ -1,249 +1,208 @@
1
1
  // Copyright (c) 2012, 2017 Peter Ohler. All rights reserved.
2
+ // Licensed under the MIT License. See LICENSE file in the project root for license details.
2
3
 
3
4
  #include <errno.h>
4
5
 
5
- #include "oj.h"
6
6
  #include "dump.h"
7
+ #include "oj.h"
7
8
 
8
- static void dump_leaf(Leaf leaf, int depth, Out out);
9
+ static void dump_leaf(Leaf leaf, int depth, Out out);
9
10
 
10
- static void
11
- grow(Out out, size_t len) {
12
- size_t size = out->end - out->buf;
13
- long pos = out->cur - out->buf;
14
- char *buf;
11
+ static void grow(Out out, size_t len) {
12
+ size_t size = out->end - out->buf;
13
+ long pos = out->cur - out->buf;
14
+ char * buf;
15
15
 
16
16
  size *= 2;
17
17
  if (size <= len * 2 + pos) {
18
- size += len;
18
+ size += len;
19
19
  }
20
20
  if (out->allocated) {
21
- buf = REALLOC_N(out->buf, char, (size + BUFFER_EXTRA));
21
+ buf = REALLOC_N(out->buf, char, (size + BUFFER_EXTRA));
22
22
  } else {
23
- buf = ALLOC_N(char, (size + BUFFER_EXTRA));
24
- out->allocated = true;
25
- memcpy(buf, out->buf, out->end - out->buf + BUFFER_EXTRA);
23
+ buf = ALLOC_N(char, (size + BUFFER_EXTRA));
24
+ out->allocated = true;
25
+ memcpy(buf, out->buf, out->end - out->buf + BUFFER_EXTRA);
26
26
  }
27
27
  if (0 == buf) {
28
- rb_raise(rb_eNoMemError, "Failed to create string. [%d:%s]\n", ENOSPC, strerror(ENOSPC));
28
+ rb_raise(rb_eNoMemError, "Failed to create string. [%d:%s]\n", ENOSPC, strerror(ENOSPC));
29
29
  }
30
30
  out->buf = buf;
31
31
  out->end = buf + size;
32
32
  out->cur = out->buf + pos;
33
33
  }
34
34
 
35
-
36
- inline static void
37
- dump_chars(const char *s, size_t size, Out out) {
35
+ inline static void dump_chars(const char *s, size_t size, Out out) {
38
36
  if (out->end - out->cur <= (long)size) {
39
- grow(out, size);
37
+ grow(out, size);
40
38
  }
41
39
  memcpy(out->cur, s, size);
42
40
  out->cur += size;
43
41
  *out->cur = '\0';
44
42
  }
45
43
 
46
- static void
47
- dump_leaf_str(Leaf leaf, Out out) {
44
+ static void dump_leaf_str(Leaf leaf, Out out) {
48
45
  switch (leaf->value_type) {
49
- case STR_VAL:
50
- oj_dump_cstr(leaf->str, strlen(leaf->str), 0, 0, out);
51
- break;
46
+ case STR_VAL: oj_dump_cstr(leaf->str, strlen(leaf->str), 0, 0, out); break;
52
47
  case RUBY_VAL:
53
- oj_dump_cstr(rb_string_value_cstr(&leaf->value), (int)RSTRING_LEN(leaf->value), 0, 0, out);
54
- break;
48
+ oj_dump_cstr(rb_string_value_cstr(&leaf->value), (int)RSTRING_LEN(leaf->value), 0, 0, out);
49
+ break;
55
50
  case COL_VAL:
56
- default:
57
- rb_raise(rb_eTypeError, "Unexpected value type %02x.\n", leaf->value_type);
58
- break;
51
+ default: rb_raise(rb_eTypeError, "Unexpected value type %02x.\n", leaf->value_type); break;
59
52
  }
60
53
  }
61
54
 
62
- static void
63
- dump_leaf_fixnum(Leaf leaf, Out out) {
55
+ static void dump_leaf_fixnum(Leaf leaf, Out out) {
64
56
  switch (leaf->value_type) {
65
- case STR_VAL:
66
- dump_chars(leaf->str, strlen(leaf->str), out);
67
- break;
57
+ case STR_VAL: dump_chars(leaf->str, strlen(leaf->str), out); break;
68
58
  case RUBY_VAL:
69
- if (T_BIGNUM == rb_type(leaf->value)) {
70
- oj_dump_bignum(leaf->value, 0, out, false);
71
- } else {
72
- oj_dump_fixnum(leaf->value, 0, out, false);
73
- }
74
- break;
59
+ if (T_BIGNUM == rb_type(leaf->value)) {
60
+ oj_dump_bignum(leaf->value, 0, out, false);
61
+ } else {
62
+ oj_dump_fixnum(leaf->value, 0, out, false);
63
+ }
64
+ break;
75
65
  case COL_VAL:
76
- default:
77
- rb_raise(rb_eTypeError, "Unexpected value type %02x.\n", leaf->value_type);
78
- break;
66
+ default: rb_raise(rb_eTypeError, "Unexpected value type %02x.\n", leaf->value_type); break;
79
67
  }
80
68
  }
81
69
 
82
- static void
83
- dump_leaf_float(Leaf leaf, Out out) {
70
+ static void dump_leaf_float(Leaf leaf, Out out) {
84
71
  switch (leaf->value_type) {
85
- case STR_VAL:
86
- dump_chars(leaf->str, strlen(leaf->str), out);
87
- break;
88
- case RUBY_VAL:
89
- oj_dump_float(leaf->value, 0, out, false);
90
- break;
72
+ case STR_VAL: dump_chars(leaf->str, strlen(leaf->str), out); break;
73
+ case RUBY_VAL: oj_dump_float(leaf->value, 0, out, false); break;
91
74
  case COL_VAL:
92
- default:
93
- rb_raise(rb_eTypeError, "Unexpected value type %02x.\n", leaf->value_type);
94
- break;
75
+ default: rb_raise(rb_eTypeError, "Unexpected value type %02x.\n", leaf->value_type); break;
95
76
  }
96
77
  }
97
78
 
98
- static void
99
- dump_leaf_array(Leaf leaf, int depth, Out out) {
100
- size_t size;
101
- int d2 = depth + 1;
79
+ static void dump_leaf_array(Leaf leaf, int depth, Out out) {
80
+ size_t size;
81
+ int d2 = depth + 1;
102
82
 
103
83
  size = 2;
104
84
  if (out->end - out->cur <= (long)size) {
105
- grow(out, size);
85
+ grow(out, size);
106
86
  }
107
87
  *out->cur++ = '[';
108
88
  if (0 == leaf->elements) {
109
- *out->cur++ = ']';
89
+ *out->cur++ = ']';
110
90
  } else {
111
- Leaf first = leaf->elements->next;
112
- Leaf e = first;
113
-
114
- size = d2 * out->indent + 2;
115
- do {
116
- if (out->end - out->cur <= (long)size) {
117
- grow(out, size);
118
- }
119
- fill_indent(out, d2);
120
- dump_leaf(e, d2, out);
121
- if (e->next != first) {
122
- *out->cur++ = ',';
123
- }
124
- e = e->next;
125
- } while (e != first);
126
- size = depth * out->indent + 1;
127
- if (out->end - out->cur <= (long)size) {
128
- grow(out, size);
129
- }
130
- fill_indent(out, depth);
131
- *out->cur++ = ']';
91
+ Leaf first = leaf->elements->next;
92
+ Leaf e = first;
93
+
94
+ size = d2 * out->indent + 2;
95
+ do {
96
+ if (out->end - out->cur <= (long)size) {
97
+ grow(out, size);
98
+ }
99
+ fill_indent(out, d2);
100
+ dump_leaf(e, d2, out);
101
+ if (e->next != first) {
102
+ *out->cur++ = ',';
103
+ }
104
+ e = e->next;
105
+ } while (e != first);
106
+ size = depth * out->indent + 1;
107
+ if (out->end - out->cur <= (long)size) {
108
+ grow(out, size);
109
+ }
110
+ fill_indent(out, depth);
111
+ *out->cur++ = ']';
132
112
  }
133
113
  *out->cur = '\0';
134
114
  }
135
115
 
136
- static void
137
- dump_leaf_hash(Leaf leaf, int depth, Out out) {
138
- size_t size;
139
- int d2 = depth + 1;
116
+ static void dump_leaf_hash(Leaf leaf, int depth, Out out) {
117
+ size_t size;
118
+ int d2 = depth + 1;
140
119
 
141
120
  size = 2;
142
121
  if (out->end - out->cur <= (long)size) {
143
- grow(out, size);
122
+ grow(out, size);
144
123
  }
145
124
  *out->cur++ = '{';
146
125
  if (0 == leaf->elements) {
147
- *out->cur++ = '}';
126
+ *out->cur++ = '}';
148
127
  } else {
149
- Leaf first = leaf->elements->next;
150
- Leaf e = first;
151
-
152
- size = d2 * out->indent + 2;
153
- do {
154
- if (out->end - out->cur <= (long)size) {
155
- grow(out, size);
156
- }
157
- fill_indent(out, d2);
158
- oj_dump_cstr(e->key, strlen(e->key), 0, 0, out);
159
- *out->cur++ = ':';
160
- dump_leaf(e, d2, out);
161
- if (e->next != first) {
162
- *out->cur++ = ',';
163
- }
164
- e = e->next;
165
- } while (e != first);
166
- size = depth * out->indent + 1;
167
- if (out->end - out->cur <= (long)size) {
168
- grow(out, size);
169
- }
170
- fill_indent(out, depth);
171
- *out->cur++ = '}';
128
+ Leaf first = leaf->elements->next;
129
+ Leaf e = first;
130
+
131
+ size = d2 * out->indent + 2;
132
+ do {
133
+ if (out->end - out->cur <= (long)size) {
134
+ grow(out, size);
135
+ }
136
+ fill_indent(out, d2);
137
+ oj_dump_cstr(e->key, strlen(e->key), 0, 0, out);
138
+ *out->cur++ = ':';
139
+ dump_leaf(e, d2, out);
140
+ if (e->next != first) {
141
+ *out->cur++ = ',';
142
+ }
143
+ e = e->next;
144
+ } while (e != first);
145
+ size = depth * out->indent + 1;
146
+ if (out->end - out->cur <= (long)size) {
147
+ grow(out, size);
148
+ }
149
+ fill_indent(out, depth);
150
+ *out->cur++ = '}';
172
151
  }
173
152
  *out->cur = '\0';
174
153
  }
175
154
 
176
- static void
177
- dump_leaf(Leaf leaf, int depth, Out out) {
155
+ static void dump_leaf(Leaf leaf, int depth, Out out) {
178
156
  switch (leaf->rtype) {
179
- case T_NIL:
180
- oj_dump_nil(Qnil, 0, out, false);
181
- break;
182
- case T_TRUE:
183
- oj_dump_true(Qtrue, 0, out, false);
184
- break;
185
- case T_FALSE:
186
- oj_dump_false(Qfalse, 0, out, false);
187
- break;
188
- case T_STRING:
189
- dump_leaf_str(leaf, out);
190
- break;
191
- case T_FIXNUM:
192
- dump_leaf_fixnum(leaf, out);
193
- break;
194
- case T_FLOAT:
195
- dump_leaf_float(leaf, out);
196
- break;
197
- case T_ARRAY:
198
- dump_leaf_array(leaf, depth, out);
199
- break;
200
- case T_HASH:
201
- dump_leaf_hash(leaf, depth, out);
202
- break;
203
- default:
204
- rb_raise(rb_eTypeError, "Unexpected type %02x.\n", leaf->rtype);
205
- break;
157
+ case T_NIL: oj_dump_nil(Qnil, 0, out, false); break;
158
+ case T_TRUE: oj_dump_true(Qtrue, 0, out, false); break;
159
+ case T_FALSE: oj_dump_false(Qfalse, 0, out, false); break;
160
+ case T_STRING: dump_leaf_str(leaf, out); break;
161
+ case T_FIXNUM: dump_leaf_fixnum(leaf, out); break;
162
+ case T_FLOAT: dump_leaf_float(leaf, out); break;
163
+ case T_ARRAY: dump_leaf_array(leaf, depth, out); break;
164
+ case T_HASH: dump_leaf_hash(leaf, depth, out); break;
165
+ default: rb_raise(rb_eTypeError, "Unexpected type %02x.\n", leaf->rtype); break;
206
166
  }
207
167
  }
208
168
 
209
- void
210
- oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out) {
169
+ void oj_dump_leaf_to_json(Leaf leaf, Options copts, Out out) {
211
170
  if (0 == out->buf) {
212
- out->buf = ALLOC_N(char, 4096);
213
- out->end = out->buf + 4095 - BUFFER_EXTRA; // 1 less than end plus extra for possible errors
214
- out->allocated = true;
171
+ out->buf = ALLOC_N(char, 4096);
172
+ out->end = out->buf + 4095 -
173
+ BUFFER_EXTRA; // 1 less than end plus extra for possible errors
174
+ out->allocated = true;
215
175
  }
216
- out->cur = out->buf;
176
+ out->cur = out->buf;
217
177
  out->circ_cnt = 0;
218
- out->opts = copts;
178
+ out->opts = copts;
219
179
  out->hash_cnt = 0;
220
- out->indent = copts->indent;
180
+ out->indent = copts->indent;
221
181
  dump_leaf(leaf, 0, out);
222
182
  }
223
183
 
224
- void
225
- oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts) {
226
- char buf[4096];
184
+ void oj_write_leaf_to_file(Leaf leaf, const char *path, Options copts) {
185
+ char buf[4096];
227
186
  struct _out out;
228
- size_t size;
229
- FILE *f;
187
+ size_t size;
188
+ FILE * f;
230
189
 
231
- out.buf = buf;
232
- out.end = buf + sizeof(buf) - BUFFER_EXTRA;
190
+ out.buf = buf;
191
+ out.end = buf + sizeof(buf) - BUFFER_EXTRA;
233
192
  out.allocated = false;
234
- out.omit_nil = copts->dump_opts.omit_nil;
193
+ out.omit_nil = copts->dump_opts.omit_nil;
235
194
  oj_dump_leaf_to_json(leaf, copts, &out);
236
195
  size = out.cur - out.buf;
237
196
  if (0 == (f = fopen(path, "w"))) {
238
- rb_raise(rb_eIOError, "%s\n", strerror(errno));
197
+ rb_raise(rb_eIOError, "%s\n", strerror(errno));
239
198
  }
240
199
  if (size != fwrite(out.buf, 1, size, f)) {
241
- int err = ferror(f);
200
+ int err = ferror(f);
242
201
 
243
- rb_raise(rb_eIOError, "Write failed. [%d:%s]\n", err, strerror(err));
202
+ rb_raise(rb_eIOError, "Write failed. [%d:%s]\n", err, strerror(err));
244
203
  }
245
204
  if (out.allocated) {
246
- xfree(out.buf);
205
+ xfree(out.buf);
247
206
  }
248
207
  fclose(f);
249
208
  }