oj 3.7.12 → 3.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,6 +45,8 @@ extern void oj_dump_rails_val(VALUE obj, int depth, Out out);
45
45
  extern void oj_dump_custom_val(VALUE obj, int depth, Out out, bool as_ok);
46
46
  extern void oj_dump_wab_val(VALUE obj, int depth, Out out);
47
47
 
48
+ extern void oj_dump_raw_json(VALUE obj, int depth, Out out);
49
+
48
50
  extern VALUE oj_add_to_json(int argc, VALUE *argv, VALUE self);
49
51
  extern VALUE oj_remove_to_json(int argc, VALUE *argv, VALUE self);
50
52
 
@@ -64,12 +64,10 @@ dump_values_array(VALUE *values, int depth, Out out) {
64
64
  } else {
65
65
  if (out->opts->dump_opts.use) {
66
66
  size = d2 * out->opts->dump_opts.indent_size + out->opts->dump_opts.array_size + 2;
67
- } else {
68
- size = d2 * out->indent + 3;
69
- }
70
- if (out->opts->dump_opts.use) {
71
67
  size += out->opts->dump_opts.array_size;
72
68
  size += out->opts->dump_opts.indent_size;
69
+ } else {
70
+ size = d2 * out->indent + 3;
73
71
  }
74
72
  for (; Qundef != *values; values++) {
75
73
  assure_size(out, size);
@@ -80,6 +78,7 @@ dump_values_array(VALUE *values, int depth, Out out) {
80
78
  }
81
79
  if (0 < out->opts->dump_opts.indent_size) {
82
80
  int i;
81
+
83
82
  for (i = d2; 0 < i; i--) {
84
83
  strcpy(out->cur, out->opts->dump_opts.indent_str);
85
84
  out->cur += out->opts->dump_opts.indent_size;
@@ -155,7 +154,7 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
155
154
  if (as_ok && !oj_use_hash_alt && rb_obj_class(a) != rb_cArray && rb_respond_to(a, oj_to_json_id)) {
156
155
  dump_to_json(a, out);
157
156
  return;
158
- }
157
+ }
159
158
  cnt = (int)RARRAY_LEN(a);
160
159
  *out->cur++ = '[';
161
160
  assure_size(out, 2);
@@ -190,9 +189,9 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
190
189
  *out->cur++ = ',';
191
190
  }
192
191
  }
193
- size = depth * out->indent + 1;
194
- assure_size(out, size);
195
192
  if (out->opts->dump_opts.use) {
193
+ size = out->opts->dump_opts.array_size + out->opts->dump_opts.indent_size * depth + 1;
194
+ assure_size(out, size);
196
195
  if (0 < out->opts->dump_opts.array_size) {
197
196
  strcpy(out->cur, out->opts->dump_opts.array_nl);
198
197
  out->cur += out->opts->dump_opts.array_size;
@@ -206,6 +205,8 @@ dump_array(VALUE a, int depth, Out out, bool as_ok) {
206
205
  }
207
206
  }
208
207
  } else {
208
+ size = depth * out->indent + 1;
209
+ assure_size(out, size);
209
210
  fill_indent(out, depth);
210
211
  }
211
212
  *out->cur++ = ']';
@@ -715,7 +716,7 @@ dump_hash(VALUE obj, int depth, Out out, bool as_ok) {
715
716
  if (as_ok && !oj_use_hash_alt && rb_obj_class(obj) != rb_cHash && rb_respond_to(obj, oj_to_json_id)) {
716
717
  dump_to_json(obj, out);
717
718
  return;
718
- }
719
+ }
719
720
  cnt = (int)RHASH_SIZE(obj);
720
721
  assure_size(out, 2);
721
722
  if (0 == cnt) {
@@ -762,9 +763,12 @@ dump_obj(VALUE obj, int depth, Out out, bool as_ok) {
762
763
  exception_alt(obj, depth, out);
763
764
  return;
764
765
  }
766
+ if (Yes == out->opts->raw_json && rb_respond_to(obj, oj_raw_json_id)) {
767
+ oj_dump_raw_json(obj, depth, out);
768
+ return;
769
+ }
765
770
  if (as_ok && rb_respond_to(obj, oj_to_json_id)) {
766
771
  dump_to_json(obj, out);
767
-
768
772
  return;
769
773
  }
770
774
  // Nothing else matched so encode as a JSON object with Ruby obj members
@@ -28,6 +28,7 @@ have_func('rb_ivar_count')
28
28
  have_func('rb_ivar_foreach')
29
29
  have_func('stpcpy')
30
30
  have_func('rb_data_object_wrap')
31
+ have_func('pthread_mutex_init')
31
32
 
32
33
  dflags['OJ_DEBUG'] = true unless ENV['OJ_DEBUG'].nil?
33
34
 
@@ -287,7 +287,7 @@ mimic_walk(VALUE key, VALUE obj, VALUE proc) {
287
287
  * call-seq: restore(source, proc=nil)
288
288
  *
289
289
  * Loads a Ruby Object from a JSON source that can be either a String or an
290
- * IO. If Proc is given or a block is providedit is called with each nested
290
+ * IO. If Proc is given or a block is provided it is called with each nested
291
291
  * element of the loaded Object.
292
292
  *
293
293
  * - *source* [_String_|IO] JSON source
@@ -300,7 +300,7 @@ mimic_walk(VALUE key, VALUE obj, VALUE proc) {
300
300
  * call-seq: load(source, proc=nil)
301
301
  *
302
302
  * Loads a Ruby Object from a JSON source that can be either a String or an
303
- * IO. If Proc is given or a block is providedit is called with each nested
303
+ * IO. If Proc is given or a block is provided it is called with each nested
304
304
  * element of the loaded Object.
305
305
  *
306
306
  * - *source* [_String_|IO] JSON source
@@ -357,6 +357,9 @@ mimic_generate_core(int argc, VALUE *argv, Options copts) {
357
357
  struct _out out;
358
358
  VALUE rstr;
359
359
 
360
+ // TBD
361
+ memset(buf, 0, sizeof(buf));
362
+
360
363
  out.buf = buf;
361
364
  out.end = buf + sizeof(buf) - 10;
362
365
  out.allocated = false;
@@ -677,6 +680,7 @@ static struct _options mimic_object_to_json_options = {
677
680
  No, // to_hash
678
681
  No, // to_json
679
682
  No, // as_json
683
+ No, // raw_json
680
684
  No, // nilnil
681
685
  No, // empty_string
682
686
  Yes, // allow_gc
@@ -685,6 +689,7 @@ static struct _options mimic_object_to_json_options = {
685
689
  No, // create_ok
686
690
  No, // allow_nan
687
691
  No, // trace
692
+ No, // safe
688
693
  0, // integer_range_min
689
694
  0, // integer_range_max
690
695
  oj_json_class,// create_id
@@ -407,7 +407,7 @@ oj_set_obj_ivar(Val parent, Val kval, VALUE value) {
407
407
  ID var_id;
408
408
  ID *slot;
409
409
 
410
- #if HAVE_LIBPTHREAD
410
+ #ifdef HAVE_PTHREAD_MUTEX_INIT
411
411
  pthread_mutex_lock(&oj_cache_mutex);
412
412
  #else
413
413
  rb_mutex_lock(oj_cache_mutex);
@@ -441,7 +441,7 @@ oj_set_obj_ivar(Val parent, Val kval, VALUE value) {
441
441
  }
442
442
  *slot = var_id;
443
443
  }
444
- #if HAVE_LIBPTHREAD
444
+ #ifdef HAVE_PTHREAD_MUTEX_INIT
445
445
  pthread_mutex_unlock(&oj_cache_mutex);
446
446
  #else
447
447
  rb_mutex_unlock(oj_cache_mutex);
@@ -665,7 +665,7 @@ end_hash(ParseInfo pi) {
665
665
  static void
666
666
  array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
667
667
  volatile VALUE rval = Qnil;
668
-
668
+
669
669
  if (3 <= len && 0 != pi->circ_array) {
670
670
  if ('i' == str[1]) {
671
671
  long i = read_long(str + 2, len - 2);
@@ -694,7 +694,7 @@ array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
694
694
  static void
695
695
  array_append_num(ParseInfo pi, NumInfo ni) {
696
696
  volatile VALUE rval = oj_num_as_value(ni);
697
-
697
+
698
698
  rb_ary_push(stack_peek(&pi->stack)->val, rval);
699
699
  if (Yes == pi->options.trace) {
700
700
  oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, rval);
@@ -53,6 +53,7 @@ ID oj_length_id;
53
53
  ID oj_new_id;
54
54
  ID oj_parse_id;
55
55
  ID oj_pos_id;
56
+ ID oj_raw_json_id;
56
57
  ID oj_read_id;
57
58
  ID oj_readpartial_id;
58
59
  ID oj_replace_id;
@@ -94,6 +95,7 @@ VALUE oj_hash_class_sym;
94
95
  VALUE oj_indent_sym;
95
96
  VALUE oj_object_class_sym;
96
97
  VALUE oj_quirks_mode_sym;
98
+ VALUE oj_safe_sym;
97
99
  VALUE oj_trace_sym;
98
100
 
99
101
  static VALUE allow_blank_sym;
@@ -137,6 +139,7 @@ static VALUE unicode_xss_sym;
137
139
  static VALUE unix_sym;
138
140
  static VALUE unix_zone_sym;
139
141
  static VALUE use_as_json_sym;
142
+ static VALUE use_raw_json_sym;
140
143
  static VALUE use_to_hash_sym;
141
144
  static VALUE use_to_json_sym;
142
145
  static VALUE wab_sym;
@@ -146,7 +149,7 @@ static VALUE xss_safe_sym;
146
149
 
147
150
  rb_encoding *oj_utf8_encoding = 0;
148
151
 
149
- #if HAVE_LIBPTHREAD
152
+ #ifdef HAVE_PTHREAD_MUTEX_INIT
150
153
  pthread_mutex_t oj_cache_mutex;
151
154
  #else
152
155
  VALUE oj_cache_mutex = Qnil;
@@ -168,6 +171,7 @@ struct _options oj_default_options = {
168
171
  No, // to_hash
169
172
  No, // to_json
170
173
  No, // as_json
174
+ No, // raw_json
171
175
  No, // nilnil
172
176
  Yes, // empty_string
173
177
  Yes, // allow_gc
@@ -176,6 +180,7 @@ struct _options oj_default_options = {
176
180
  No, // create_ok
177
181
  Yes, // allow_nan
178
182
  No, // trace
183
+ No, // safe
179
184
  0, // integer_range_min
180
185
  0, // integer_range_max
181
186
  oj_json_class, // create_id
@@ -229,6 +234,7 @@ struct _options oj_default_options = {
229
234
  * - *:float_precision* [_Fixnum_|_nil_] number of digits of precision when dumping floats, 0 indicates use Ruby
230
235
  * - *:use_to_json* [_Boolean_|_nil_] call to_json() methods on dump, default is false
231
236
  * - *:use_as_json* [_Boolean_|_nil_] call as_json() methods on dump, default is false
237
+ * - *:use_raw_json* [_Boolean_|_nil_] call raw_json() methods on dump, default is false
232
238
  * - *:nilnil* [_Boolean_|_nil_] if true a nil input to load will return nil and not raise an Exception
233
239
  * - *:empty_string* [_Boolean_|_nil_] if true an empty input will not raise an Exception
234
240
  * - *:allow_gc* [_Boolean_|_nil_] allow or prohibit GC during parsing, default is true (allow)
@@ -245,8 +251,9 @@ struct _options oj_default_options = {
245
251
  * - *:array_class* [_Class_|_nil_] Class to use instead of Array on load
246
252
  * - *:omit_nil* [_true_|_false_] if true Hash and Object attributes with nil values are omitted
247
253
  * - *:ignore* [_nil_|Array] either nil or an Array of classes to ignore when dumping
248
- * - *:integer_range* [_Range_] Dump integers outside range as strings.
254
+ * - *:integer_range* [_Range_] Dump integers outside range as strings.
249
255
  * - *:trace* [_true,_|_false_] Trace all load and dump calls, default is false (trace is off)
256
+ * - *:safe* [_true,_|_false_] Safe mimic breaks JSON mimic to be safer, default is false (safe is off)
250
257
  *
251
258
  * Return [_Hash_] all current option settings.
252
259
  */
@@ -269,6 +276,7 @@ get_def_opts(VALUE self) {
269
276
  rb_hash_aset(opts, use_to_json_sym, (Yes == oj_default_options.to_json) ? Qtrue : ((No == oj_default_options.to_json) ? Qfalse : Qnil));
270
277
  rb_hash_aset(opts, use_to_hash_sym, (Yes == oj_default_options.to_hash) ? Qtrue : ((No == oj_default_options.to_hash) ? Qfalse : Qnil));
271
278
  rb_hash_aset(opts, use_as_json_sym, (Yes == oj_default_options.as_json) ? Qtrue : ((No == oj_default_options.as_json) ? Qfalse : Qnil));
279
+ rb_hash_aset(opts, use_raw_json_sym, (Yes == oj_default_options.raw_json) ? Qtrue : ((No == oj_default_options.raw_json) ? Qfalse : Qnil));
272
280
  rb_hash_aset(opts, nilnil_sym, (Yes == oj_default_options.nilnil) ? Qtrue : ((No == oj_default_options.nilnil) ? Qfalse : Qnil));
273
281
  rb_hash_aset(opts, empty_string_sym, (Yes == oj_default_options.empty_string) ? Qtrue : ((No == oj_default_options.empty_string) ? Qfalse : Qnil));
274
282
  rb_hash_aset(opts, allow_gc_sym, (Yes == oj_default_options.allow_gc) ? Qtrue : ((No == oj_default_options.allow_gc) ? Qfalse : Qnil));
@@ -276,6 +284,7 @@ get_def_opts(VALUE self) {
276
284
  rb_hash_aset(opts, allow_invalid_unicode_sym, (Yes == oj_default_options.allow_invalid) ? Qtrue : ((No == oj_default_options.allow_invalid) ? Qfalse : Qnil));
277
285
  rb_hash_aset(opts, oj_allow_nan_sym, (Yes == oj_default_options.allow_nan) ? Qtrue : ((No == oj_default_options.allow_nan) ? Qfalse : Qnil));
278
286
  rb_hash_aset(opts, oj_trace_sym, (Yes == oj_default_options.trace) ? Qtrue : ((No == oj_default_options.trace) ? Qfalse : Qnil));
287
+ rb_hash_aset(opts, oj_safe_sym, (Yes == oj_default_options.safe) ? Qtrue : ((No == oj_default_options.safe) ? Qfalse : Qnil));
279
288
  rb_hash_aset(opts, float_prec_sym, INT2FIX(oj_default_options.float_prec));
280
289
  switch (oj_default_options.mode) {
281
290
  case StrictMode: rb_hash_aset(opts, mode_sym, strict_sym); break;
@@ -287,7 +296,7 @@ get_def_opts(VALUE self) {
287
296
  case WabMode: rb_hash_aset(opts, mode_sym, wab_sym); break;
288
297
  default: rb_hash_aset(opts, mode_sym, object_sym); break;
289
298
  }
290
-
299
+
291
300
  if (oj_default_options.integer_range_max != 0 || oj_default_options.integer_range_min != 0) {
292
301
  VALUE range = rb_obj_alloc(rb_cRange);
293
302
  VALUE min = LONG2FIX(oj_default_options.integer_range_min);
@@ -320,7 +329,7 @@ get_def_opts(VALUE self) {
320
329
  case AutoDec:
321
330
  default: rb_hash_aset(opts, bigdecimal_load_sym, auto_sym); break;
322
331
  }
323
- rb_hash_aset(opts, create_id_sym, (0 == oj_default_options.create_id) ? Qnil : rb_str_new2(oj_default_options.create_id));
332
+ rb_hash_aset(opts, create_id_sym, (NULL == oj_default_options.create_id) ? Qnil : rb_str_new2(oj_default_options.create_id));
324
333
  rb_hash_aset(opts, oj_space_sym, (0 == oj_default_options.dump_opts.after_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.after_sep));
325
334
  rb_hash_aset(opts, oj_space_before_sym, (0 == oj_default_options.dump_opts.before_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.before_sep));
326
335
  rb_hash_aset(opts, oj_object_nl_sym, (0 == oj_default_options.dump_opts.hash_size) ? Qnil : rb_str_new2(oj_default_options.dump_opts.hash_nl));
@@ -343,7 +352,7 @@ get_def_opts(VALUE self) {
343
352
  } else {
344
353
  VALUE *vp;
345
354
  volatile VALUE a = rb_ary_new();
346
-
355
+
347
356
  for (vp = oj_default_options.ignore; Qnil != *vp; vp++) {
348
357
  rb_ary_push(a, *vp);
349
358
  }
@@ -374,6 +383,7 @@ get_def_opts(VALUE self) {
374
383
  * - *:use_to_json* [_Boolean_|_nil_] call to_json() methods on dump, default is false.
375
384
  * - *:use_as_json* [_Boolean_|_nil_] call as_json() methods on dump, default is false.
376
385
  * - *:use_to_hash* [_Boolean_|_nil_] call to_hash() methods on dump, default is false.
386
+ * - *:use_raw_json* [_Boolean_|_nil_] call raw_json() methods on dump, default is false.
377
387
  * - *:nilnil* [_Boolean_|_nil_] if true a nil input to load will return nil and not raise an Exception.
378
388
  * - *:allow_gc* [_Boolean_|_nil_] allow or prohibit GC during parsing, default is true (allow).
379
389
  * - *:quirks_mode* [_Boolean_|_nil_] allow single JSON values instead of documents, default is true (allow).
@@ -388,8 +398,9 @@ get_def_opts(VALUE self) {
388
398
  * - *:array_class* [_Class_|_nil_] Class to use instead of Array on load.
389
399
  * - *:omit_nil* [_true_|_false_] if true Hash and Object attributes with nil values are omitted.
390
400
  * - *:ignore* [_nil_|Array] either nil or an Array of classes to ignore when dumping
391
- * - *:integer_range* [_Range_] Dump integers outside range as strings.
401
+ * - *:integer_range* [_Range_] Dump integers outside range as strings.
392
402
  * - *:trace* [_Boolean_] turn trace on or off.
403
+ * - *:safe* [_Boolean_] turn safe mimic on or off.
393
404
  */
394
405
  static VALUE
395
406
  set_def_opts(VALUE self, VALUE opts) {
@@ -410,6 +421,7 @@ oj_parse_options(VALUE ropts, Options copts) {
410
421
  { use_to_hash_sym, &copts->to_hash },
411
422
  { use_to_json_sym, &copts->to_json },
412
423
  { use_as_json_sym, &copts->as_json },
424
+ { use_raw_json_sym, &copts->raw_json },
413
425
  { nilnil_sym, &copts->nilnil },
414
426
  { allow_blank_sym, &copts->nilnil }, // same as nilnil
415
427
  { empty_string_sym, &copts->empty_string },
@@ -418,13 +430,14 @@ oj_parse_options(VALUE ropts, Options copts) {
418
430
  { allow_invalid_unicode_sym, &copts->allow_invalid },
419
431
  { oj_allow_nan_sym, &copts->allow_nan },
420
432
  { oj_trace_sym, &copts->trace },
433
+ { oj_safe_sym, &copts->safe },
421
434
  { oj_create_additions_sym, &copts->create_ok },
422
435
  { Qnil, 0 }
423
436
  };
424
437
  YesNoOpt o;
425
438
  volatile VALUE v;
426
439
  size_t len;
427
-
440
+
428
441
  if (T_HASH != rb_type(ropts)) {
429
442
  return;
430
443
  }
@@ -715,7 +728,7 @@ oj_parse_options(VALUE ropts, Options copts) {
715
728
  cnt = (int)RARRAY_LEN(v);
716
729
  if (0 < cnt) {
717
730
  int i;
718
-
731
+
719
732
  copts->ignore = ALLOC_N(VALUE, cnt + 1);
720
733
  for (i = 0; i < cnt; i++) {
721
734
  copts->ignore[i] = rb_ary_entry(v, i);
@@ -802,11 +815,10 @@ oj_parse_opt_match_string(RxClass rc, VALUE ropts) {
802
815
  *
803
816
  * - *json* [_String_|_IO_] JSON String or an Object that responds to read()
804
817
  * - *options* [_Hash_] load options (same as default_options)
805
- * - -
806
818
  * - *obj* [_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_] parsed object.
807
819
  * - *start* [_optional, _Integer_] start position of parsed JSON for obj.
808
820
  * - *len* [_optional, _Integer_] length of parsed JSON for obj.
809
- *
821
+ *
810
822
  * Returns [_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_]
811
823
  */
812
824
  static VALUE
@@ -889,7 +901,6 @@ load(int argc, VALUE *argv, VALUE self) {
889
901
  *
890
902
  * - *path* [_String_] to a file containing a JSON document
891
903
  * - *options* [_Hash_] load options (same as default_options)
892
- * - -
893
904
  * - *obj* [_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_] parsed object.
894
905
  * - *start* [_optional, _Integer_] start position of parsed JSON for obj.
895
906
  * - *len* [_optional, _Integer_] length of parsed JSON for obj.
@@ -1064,7 +1075,7 @@ dump(int argc, VALUE *argv, VALUE self) {
1064
1075
  * Dumps an Object (obj) to a string. If the object has a to_json method that
1065
1076
  * will be called. The mode is set to :compat.
1066
1077
  * - *obj* [_Object_] Object to serialize as an JSON document String
1067
- * - *options* [_Hash_]
1078
+ * - *options* [_Hash_]
1068
1079
  * - *:max_nesting* [_boolean_] It true nesting is limited to 100. The option to detect circular references is available but is not compatible with the json gem., default is false
1069
1080
  * - *:allow_nan* [_boolean_] If true non JSON compliant words such as Nan and Infinity will be used as appropriate, default is true.
1070
1081
  * - *:quirks_mode* [_boolean_] Allow single JSON values instead of documents, default is true (allow).
@@ -1126,7 +1137,7 @@ to_json(int argc, VALUE *argv, VALUE self) {
1126
1137
  static VALUE
1127
1138
  to_file(int argc, VALUE *argv, VALUE self) {
1128
1139
  struct _options copts = oj_default_options;
1129
-
1140
+
1130
1141
  if (3 == argc) {
1131
1142
  oj_parse_options(argv[2], &copts);
1132
1143
  }
@@ -1149,7 +1160,7 @@ to_file(int argc, VALUE *argv, VALUE self) {
1149
1160
  static VALUE
1150
1161
  to_stream(int argc, VALUE *argv, VALUE self) {
1151
1162
  struct _options copts = oj_default_options;
1152
-
1163
+
1153
1164
  if (3 == argc) {
1154
1165
  oj_parse_options(argv[2], &copts);
1155
1166
  }
@@ -1265,7 +1276,6 @@ register_odd_raw(int argc, VALUE *argv, VALUE self) {
1265
1276
  *
1266
1277
  * - *json* [_String_|_IO_] JSON String or an Object that responds to read().
1267
1278
  * - *options* [_Hash_] load options (same as default_options).
1268
- * - -
1269
1279
  * - *obj* [_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_] parsed object.
1270
1280
  * - *start* [_optional, _Integer_] start position of parsed JSON for obj.
1271
1281
  * - *len* [_optional, _Integer_] length of parsed JSON for obj.
@@ -1300,7 +1310,6 @@ extern VALUE oj_strict_parse(int argc, VALUE *argv, VALUE self);
1300
1310
  *
1301
1311
  * - *json* [_String_|_IO_] JSON String or an Object that responds to read().
1302
1312
  * - *options* [_Hash_] load options (same as default_options).
1303
- * - -
1304
1313
  * - *obj* [_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_] parsed object.
1305
1314
  * - *start* [_optional, _Integer_] start position of parsed JSON for obj.
1306
1315
  * - *len* [_optional, _Integer_] length of parsed JSON for obj.
@@ -1331,7 +1340,6 @@ extern VALUE oj_compat_parse(int argc, VALUE *argv, VALUE self);
1331
1340
  *
1332
1341
  * - *json* [_String_|_IO_] JSON String or an Object that responds to read().
1333
1342
  * - *options* [_Hash_] load options (same as default_options).
1334
- * - -
1335
1343
  * - *obj* [_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_] parsed object.
1336
1344
  * - *start* [_optional, _Integer_] start position of parsed JSON for obj.
1337
1345
  * - *len* [_optional, _Integer_] length of parsed JSON for obj.
@@ -1367,7 +1375,6 @@ extern VALUE oj_object_parse(int argc, VALUE *argv, VALUE self);
1367
1375
  *
1368
1376
  * - *json* [_String_|_IO_] JSON String or an Object that responds to read().
1369
1377
  * - *options* [_Hash_] load options (same as default_options).
1370
- * - -
1371
1378
  * - *obj* [_Hash_|_Array_|_String_|_Fixnum_|_Float_|_Boolean_|_nil_] parsed object.
1372
1379
  * - *start* [_optional, _Integer_] start position of parsed JSON for obj.
1373
1380
  * - *len* [_optional, _Integer_] length of parsed JSON for obj.
@@ -1429,16 +1436,16 @@ extern VALUE oj_define_mimic_json(int argc, VALUE *argv, VALUE self);
1429
1436
 
1430
1437
  /* Document-method: generate
1431
1438
  * call-seq: generate(obj, opts=nil)
1432
- *
1439
+ *
1433
1440
  * Encode obj as a JSON String. The obj argument must be a Hash, Array, or
1434
1441
  * respond to to_h or to_json. Options other than those listed such as
1435
1442
  * +:allow_nan+ or +:max_nesting+ are ignored.
1436
- *
1443
+ *
1437
1444
  * - *obj* [_Object__|_Hash_|_Array_] object to convert to a JSON String
1438
1445
  * - *opts* [_Hash_] options
1439
- * - - *:indent* [_String_] String to use for indentation.
1446
+ * - *:indent* [_String_] String to use for indentation.
1440
1447
  * - *:space* [_String_] String placed after a , or : delimiter
1441
- * - *:space * _before [_String_] String placed before a : delimiter
1448
+ * - *:space_before* [_String_] String placed before a : delimiter
1442
1449
  * - *:object_nl* [_String_] String placed after a JSON object
1443
1450
  * - *:array_nl* [_String_] String placed after a JSON array
1444
1451
  * - *:ascii_only* [_Boolean_] if not nil or false then use only ascii characters in the output. Note JSON.generate does support this even if it is not documented.
@@ -1481,15 +1488,15 @@ protect_require(VALUE x) {
1481
1488
  * modes are:
1482
1489
  *
1483
1490
  * - *:strict* mode will only allow the 7 basic JSON types to be serialized. Any other Object
1484
- * will raise an Exception.
1485
- *
1491
+ * will raise an Exception.
1492
+ *
1486
1493
  * - *:null* mode is similar to the :strict mode except any Object that is not
1487
1494
  * one of the JSON base types is replaced by a JSON null.
1488
- *
1495
+ *
1489
1496
  * - *:object* mode will dump any Object as a JSON Object with keys that match
1490
1497
  * the Ruby Object's variable names without the '@' character. This is the
1491
1498
  * highest performance mode.
1492
- *
1499
+ *
1493
1500
  * - *:compat* or *:json* mode is the compatible mode for the json gem. It mimics
1494
1501
  * the json gem including the options, defaults, and restrictions.
1495
1502
  *
@@ -1575,6 +1582,7 @@ Init_oj() {
1575
1582
  oj_new_id = rb_intern("new");
1576
1583
  oj_parse_id = rb_intern("parse");
1577
1584
  oj_pos_id = rb_intern("pos");
1585
+ oj_raw_json_id = rb_intern("raw_json");
1578
1586
  oj_read_id = rb_intern("read");
1579
1587
  oj_readpartial_id = rb_intern("readpartial");
1580
1588
  oj_replace_id = rb_intern("replace");
@@ -1651,6 +1659,7 @@ Init_oj() {
1651
1659
  oj_object_class_sym = ID2SYM(rb_intern("object_class")); rb_gc_register_address(&oj_object_class_sym);
1652
1660
  oj_object_nl_sym = ID2SYM(rb_intern("object_nl")); rb_gc_register_address(&oj_object_nl_sym);
1653
1661
  oj_quirks_mode_sym = ID2SYM(rb_intern("quirks_mode")); rb_gc_register_address(&oj_quirks_mode_sym);
1662
+ oj_safe_sym = ID2SYM(rb_intern("safe")); rb_gc_register_address(&oj_safe_sym);
1654
1663
  oj_space_before_sym = ID2SYM(rb_intern("space_before")); rb_gc_register_address(&oj_space_before_sym);
1655
1664
  oj_space_sym = ID2SYM(rb_intern("space")); rb_gc_register_address(&oj_space_sym);
1656
1665
  oj_trace_sym = ID2SYM(rb_intern("trace")); rb_gc_register_address(&oj_trace_sym);
@@ -1666,6 +1675,7 @@ Init_oj() {
1666
1675
  unix_sym = ID2SYM(rb_intern("unix")); rb_gc_register_address(&unix_sym);
1667
1676
  unix_zone_sym = ID2SYM(rb_intern("unix_zone")); rb_gc_register_address(&unix_zone_sym);
1668
1677
  use_as_json_sym = ID2SYM(rb_intern("use_as_json")); rb_gc_register_address(&use_as_json_sym);
1678
+ use_raw_json_sym = ID2SYM(rb_intern("use_raw_json")); rb_gc_register_address(&use_raw_json_sym);
1669
1679
  use_to_hash_sym = ID2SYM(rb_intern("use_to_hash")); rb_gc_register_address(&use_to_hash_sym);
1670
1680
  use_to_json_sym = ID2SYM(rb_intern("use_to_json")); rb_gc_register_address(&use_to_json_sym);
1671
1681
  wab_sym = ID2SYM(rb_intern("wab")); rb_gc_register_address(&wab_sym);
@@ -1682,7 +1692,7 @@ Init_oj() {
1682
1692
  oj_odd_init();
1683
1693
  oj_mimic_rails_init();
1684
1694
 
1685
- #if HAVE_LIBPTHREAD
1695
+ #ifdef HAVE_PTHREAD_MUTEX_INIT
1686
1696
  if (0 != (err = pthread_mutex_init(&oj_cache_mutex, 0))) {
1687
1697
  rb_raise(rb_eException, "failed to initialize a mutex. %s", strerror(err));
1688
1698
  }