oj 3.7.0 → 3.7.1

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
  SHA256:
3
- metadata.gz: e6defd3e51327c7d866dabb9caf8580c67996b5bd251d9613ec883f186cea522
4
- data.tar.gz: 22a9278def6a95047eb280edd38a0be67872e263a9da259f4bdd5b3ab43f400a
3
+ metadata.gz: bd1a6d1169dfa2ef1c28a09f66c30d1441eeb687580063d9f9e1a7a109aeb12e
4
+ data.tar.gz: 10b6ab680f89ec60767f7cb35753acdf6eff3aad46e2b4ce0df03548854cab75
5
5
  SHA512:
6
- metadata.gz: e0da261cf964ecd359e1ea539715c39ebc740fe8fb716b274c65e4b47a52a55033b6011f90b8a09948582df85d0fa0d942ae422b0cafd61cce34d2c0b6046519
7
- data.tar.gz: 88c99360a4de1367247d76a8aff7e34f75744f58c2b64465fc3fcb90858c33902ae0c2d3aeaf1a04fe03ce29890cf44f314c6666d1cd9487c4b3355c01e71f58
6
+ metadata.gz: ea073f98957802f427450a299867dbabde338fd8dc809e1ff7413ee2601dd8c72ed3e0b0e9fc944e06618e2e14f4980d908637f3ac98a021deb6714bccb9c2e5
7
+ data.tar.gz: f4176bed42ae5092069984ba5f74a07dfacd1f9c6615d5b2ec108b8f37f0c0e95223751528e42f6ab6b17e0eee77cb98f8485df724cbee69df2207ed6274737c
@@ -501,15 +501,11 @@ dump_common(VALUE obj, int depth, Out out) {
501
501
  if (Yes == out->opts->trace) {
502
502
  oj_trace("to_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyIn);
503
503
  }
504
- #if HAS_METHOD_ARITY
505
504
  if (0 == rb_obj_method_arity(obj, oj_to_json_id)) {
506
505
  rs = rb_funcall(obj, oj_to_json_id, 0);
507
506
  } else {
508
507
  rs = rb_funcall2(obj, oj_to_json_id, out->argc, out->argv);
509
508
  }
510
- #else
511
- rs = rb_funcall2(obj, oj_to_json_id, out->argc, out->argv);
512
- #endif
513
509
  if (Yes == out->opts->trace) {
514
510
  oj_trace("to_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
515
511
  }
@@ -528,15 +524,11 @@ dump_common(VALUE obj, int depth, Out out) {
528
524
  }
529
525
  // Some classes elect to not take an options argument so check the arity
530
526
  // of as_json.
531
- #if HAS_METHOD_ARITY
532
527
  if (0 == rb_obj_method_arity(obj, oj_as_json_id)) {
533
528
  aj = rb_funcall(obj, oj_as_json_id, 0);
534
529
  } else {
535
530
  aj = rb_funcall2(obj, oj_as_json_id, out->argc, out->argv);
536
531
  }
537
- #else
538
- aj = rb_funcall2(obj, oj_as_json_id, out->argc, out->argv);
539
- #endif
540
532
  if (Yes == out->opts->trace) {
541
533
  oj_trace("as_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
542
534
  }
@@ -592,11 +584,9 @@ dump_attr_cb(ID key, VALUE value, Out out) {
592
584
  if (NULL == attr) {
593
585
  attr = "";
594
586
  }
595
- #if HAS_EXCEPTION_MAGIC
596
587
  if (0 == strcmp("bt", attr) || 0 == strcmp("mesg", attr)) {
597
588
  return ST_CONTINUE;
598
589
  }
599
- #endif
600
590
  assure_size(out, size);
601
591
  fill_indent(out, depth);
602
592
  if ('@' == *attr) {
@@ -671,7 +661,6 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
671
661
  if (',' == *(out->cur - 1)) {
672
662
  out->cur--; // backup to overwrite last comma
673
663
  }
674
- #if HAS_EXCEPTION_MAGIC
675
664
  if (rb_obj_is_kind_of(obj, rb_eException)) {
676
665
  volatile VALUE rv;
677
666
 
@@ -695,7 +684,6 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
695
684
  oj_dump_custom_val(rv, d2, out, true);
696
685
  assure_size(out, 2);
697
686
  }
698
- #endif
699
687
  out->depth = depth;
700
688
 
701
689
  fill_indent(out, depth);
@@ -821,9 +809,7 @@ dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
821
809
  *out->cur++ = '{';
822
810
  fill_indent(out, d2);
823
811
  size = d3 * out->indent + 2;
824
- #if HAS_STRUCT_MEMBERS
825
812
  ma = rb_struct_s_members(clas);
826
- #endif
827
813
 
828
814
  #ifdef RSTRUCT_LEN
829
815
  #if RSTRUCT_LEN_RETURNS_INTEGER_OBJECT
@@ -311,7 +311,7 @@ dump_unicode(const char *str, const char *end, Out out, const char *orig) {
311
311
  static const char*
312
312
  check_unicode(const char *str, const char *end, const char *orig) {
313
313
  uint8_t b = *(uint8_t*)str;
314
- int cnt;
314
+ int cnt = 0;
315
315
 
316
316
  if (0xC0 == (0xE0 & b)) {
317
317
  cnt = 1;
@@ -375,7 +375,7 @@ oj_dump_time(VALUE obj, Out out, int withZone) {
375
375
  long long sec;
376
376
  long long nsec;
377
377
 
378
- #if HAS_RB_TIME_TIMESPEC
378
+ #ifdef HAVE_RB_TIME_TIMESPEC
379
379
  {
380
380
  struct timespec ts = rb_time_timespec(obj);
381
381
 
@@ -384,11 +384,7 @@ oj_dump_time(VALUE obj, Out out, int withZone) {
384
384
  }
385
385
  #else
386
386
  sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
387
- #if HAS_NANO_TIME
388
387
  nsec = rb_num2ll(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
389
- #else
390
- nsec = rb_num2ll(rb_funcall2(obj, oj_tv_usec_id, 0, 0)) * 1000;
391
- #endif
392
388
  #endif
393
389
 
394
390
  *b-- = '\0';
@@ -478,7 +474,7 @@ oj_dump_xml_time(VALUE obj, Out out) {
478
474
  int tzhour, tzmin;
479
475
  char tzsign = '+';
480
476
 
481
- #if HAS_RB_TIME_TIMESPEC
477
+ #ifdef HAVE_RB_TIME_TIMESPEC
482
478
  {
483
479
  struct timespec ts = rb_time_timespec(obj);
484
480
  sec = ts.tv_sec;
@@ -486,11 +482,7 @@ oj_dump_xml_time(VALUE obj, Out out) {
486
482
  }
487
483
  #else
488
484
  sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
489
- #if HAS_NANO_TIME
490
485
  nsec = rb_num2ll(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
491
- #else
492
- nsec = rb_num2ll(rb_funcall2(obj, oj_tv_usec_id, 0, 0)) * 1000;
493
- #endif
494
486
  #endif
495
487
 
496
488
  assure_size(out, 36);
@@ -704,13 +696,11 @@ oj_write_obj_to_stream(VALUE obj, VALUE stream, Options copts) {
704
696
 
705
697
  void
706
698
  oj_dump_str(VALUE obj, int depth, Out out, bool as_ok) {
707
- #if HAS_ENCODING_SUPPORT
708
699
  rb_encoding *enc = rb_to_encoding(rb_obj_encoding(obj));
709
700
 
710
701
  if (rb_utf8_encoding() != enc) {
711
702
  obj = rb_str_conv_enc(obj, enc, rb_utf8_encoding());
712
703
  }
713
- #endif
714
704
  oj_dump_cstr(rb_string_value_ptr((VALUE*)&obj), (int)RSTRING_LEN(obj), 0, 0, out);
715
705
  }
716
706
 
@@ -123,15 +123,11 @@ dump_to_json(VALUE obj, Out out) {
123
123
  if (Yes == out->opts->trace) {
124
124
  oj_trace("to_json", obj, __FILE__, __LINE__, 0, TraceRubyIn);
125
125
  }
126
- #if HAS_METHOD_ARITY
127
126
  if (0 == rb_obj_method_arity(obj, oj_to_json_id)) {
128
127
  rs = rb_funcall(obj, oj_to_json_id, 0);
129
128
  } else {
130
129
  rs = rb_funcall2(obj, oj_to_json_id, out->argc, out->argv);
131
130
  }
132
- #else
133
- rs = rb_funcall2(obj, oj_to_json_id, out->argc, out->argv);
134
- #endif
135
131
  if (Yes == out->opts->trace) {
136
132
  oj_trace("to_json", obj, __FILE__, __LINE__, 0, TraceRubyOut);
137
133
  }
@@ -474,7 +470,7 @@ time_alt(VALUE obj, int depth, Out out) {
474
470
  time_t sec;
475
471
  long long nsec;
476
472
 
477
- #if HAS_RB_TIME_TIMESPEC
473
+ #ifdef HAVE_RB_TIME_TIMESPEC
478
474
  {
479
475
  struct timespec ts = rb_time_timespec(obj);
480
476
  sec = ts.tv_sec;
@@ -482,11 +478,7 @@ time_alt(VALUE obj, int depth, Out out) {
482
478
  }
483
479
  #else
484
480
  sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
485
- #if HAS_NANO_TIME
486
481
  nsec = rb_num2ll(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
487
- #else
488
- nsec = rb_num2ll(rb_funcall2(obj, oj_tv_usec_id, 0, 0)) * 1000;
489
- #endif
490
482
  #endif
491
483
 
492
484
  attrs[0].num = sec;
@@ -346,7 +346,7 @@ dump_hash_class(VALUE obj, VALUE clas, int depth, Out out) {
346
346
  *out->cur = '\0';
347
347
  }
348
348
 
349
- #if HAS_IVAR_HELPERS
349
+ #ifdef HAVE_RB_IVAR_FOREACH
350
350
  static int
351
351
  dump_attr_cb(ID key, VALUE value, Out out) {
352
352
  int depth = out->depth;
@@ -364,11 +364,9 @@ dump_attr_cb(ID key, VALUE value, Out out) {
364
364
  if (NULL == attr) {
365
365
  attr = "";
366
366
  }
367
- #if HAS_EXCEPTION_MAGIC
368
367
  if (0 == strcmp("bt", attr) || 0 == strcmp("mesg", attr)) {
369
368
  return ST_CONTINUE;
370
369
  }
371
- #endif
372
370
  assure_size(out, size);
373
371
  fill_indent(out, depth);
374
372
  if ('@' == *attr) {
@@ -577,7 +575,7 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
577
575
  }
578
576
  {
579
577
  int cnt;
580
- #if HAS_IVAR_HELPERS
578
+ #ifdef HAVE_RB_IVAR_COUNT
581
579
  cnt = (int)rb_ivar_count(obj);
582
580
  #else
583
581
  volatile VALUE vars = rb_funcall2(obj, oj_instance_variables_id, 0, 0);
@@ -601,7 +599,7 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
601
599
  }
602
600
  }
603
601
  out->depth = depth + 1;
604
- #if HAS_IVAR_HELPERS
602
+ #ifdef HAVE_RB_IVAR_FOREACH
605
603
  rb_ivar_foreach(obj, dump_attr_cb, (VALUE)out);
606
604
  if (',' == *(out->cur - 1)) {
607
605
  out->cur--; // backup to overwrite last comma
@@ -644,7 +642,6 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
644
642
  assure_size(out, 2);
645
643
  }
646
644
  #endif
647
- #if HAS_EXCEPTION_MAGIC
648
645
  if (rb_obj_is_kind_of(obj, rb_eException)) {
649
646
  volatile VALUE rv;
650
647
 
@@ -669,7 +666,6 @@ dump_obj_attrs(VALUE obj, VALUE clas, slot_t id, int depth, Out out) {
669
666
  oj_dump_obj_val(rv, d2, out);
670
667
  assure_size(out, 2);
671
668
  }
672
- #endif
673
669
  out->depth = depth;
674
670
  }
675
671
  fill_indent(out, depth);
@@ -701,7 +697,6 @@ dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
701
697
  *out->cur++ = '"';
702
698
  *out->cur++ = ':';
703
699
  *out->cur++ = '[';
704
- #if HAS_STRUCT_MEMBERS
705
700
  if ('#' == *class_name) {
706
701
  VALUE ma = rb_struct_s_members(clas);
707
702
  const char *name;
@@ -725,9 +720,6 @@ dump_struct(VALUE obj, int depth, Out out, bool as_ok) {
725
720
  }
726
721
  *out->cur++ = ']';
727
722
  } else {
728
- #else
729
- if (true) {
730
- #endif
731
723
  fill_indent(out, d3);
732
724
  *out->cur++ = '"';
733
725
  memcpy(out->cur, class_name, len);
@@ -14,10 +14,6 @@
14
14
  #include "dump.h"
15
15
  #include "trace.h"
16
16
 
17
- #if !HAS_ENCODING_SUPPORT || defined(RUBINIUS_RUBY)
18
- #define rb_eEncodingError rb_eException
19
- #endif
20
-
21
17
  // Workaround in case INFINITY is not defined in math.h or if the OS is CentOS
22
18
  #define OJ_INFINITY (1.0/0.0)
23
19
 
@@ -32,19 +32,11 @@
32
32
  #define __OJ_ENCODE_H__
33
33
 
34
34
  #include "ruby.h"
35
- #if HAS_ENCODING_SUPPORT
36
35
  #include "ruby/encoding.h"
37
- #endif
38
36
 
39
37
  static inline VALUE
40
38
  oj_encode(VALUE rstr) {
41
- #if HAS_ENCODING_SUPPORT
42
39
  rb_enc_associate(rstr, oj_utf8_encoding);
43
- #else
44
- if (Qnil != oj_utf8_encoding) {
45
- rstr = rb_funcall(oj_utf8_encoding, oj_iconv_id, 1, rstr);
46
- }
47
- #endif
48
40
  return rstr;
49
41
  }
50
42
 
@@ -7,7 +7,6 @@ dir_config(extension_name)
7
7
  parts = RUBY_DESCRIPTION.split(' ')
8
8
  type = parts[0]
9
9
  type = type[4..-1] if type.start_with?('tcs-')
10
- type = 'ree' if 'ruby' == type && RUBY_DESCRIPTION.include?('Ruby Enterprise Edition')
11
10
  is_windows = RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
12
11
  platform = RUBY_PLATFORM
13
12
  version = RUBY_VERSION.split('.')
@@ -20,42 +19,15 @@ dflags = {
20
19
  'RUBY_VERSION_MAJOR' => version[0],
21
20
  'RUBY_VERSION_MINOR' => version[1],
22
21
  'RUBY_VERSION_MICRO' => version[2],
23
- 'HAS_RB_TIME_TIMESPEC' => (!is_windows &&
24
- !['arm-linux-gnueabi',
25
- 'arm-linux-gnueabihf',
26
- 'i386-linux-gnu',
27
- 'mips-linux-gnu',
28
- 'mipsel-linux-gnu'].include?(platform) &&
29
- 'ruby' == type &&
30
- ('1.9.3' == RUBY_VERSION || '2' <= version[0])) ? 1 : 0,
31
- 'HAS_ENCODING_SUPPORT' => (('ruby' == type || 'rubinius' == type) &&
32
- (('1' == version[0] && '9' == version[1]) || '2' <= version[0])) ? 1 : 0,
33
- 'HAS_NANO_TIME' => ('ruby' == type && ('1' == version[0] && '9' == version[1]) || '2' <= version[0]) ? 1 : 0,
34
- 'HAS_IVAR_HELPERS' => ('ruby' == type && !is_windows && (('1' == version[0] && '9' == version[1]) || '2' <= version[0])) ? 1 : 0,
35
- 'HAS_EXCEPTION_MAGIC' => ('ruby' == type && ('1' == version[0] && '9' == version[1])) ? 0 : 1,
36
- 'HAS_PROC_WITH_BLOCK' => ('ruby' == type && (('1' == version[0] && '9' == version[1]) || '2' <= version[0])) ? 1 : 0,
37
- 'HAS_TOP_LEVEL_ST_H' => ('ree' == type || ('ruby' == type && '1' == version[0] && '8' == version[1])) ? 1 : 0,
38
- 'NEEDS_RATIONAL' => ('1' == version[0] && '8' == version[1]) ? 1 : 0,
39
22
  'IS_WINDOWS' => is_windows ? 1 : 0,
40
- 'USE_PTHREAD_MUTEX' => is_windows ? 0 : 1,
41
- 'USE_RB_MUTEX' => (is_windows && !('1' == version[0] && '8' == version[1])) ? 1 : 0,
42
- 'NO_TIME_ROUND_PAD' => ('rubinius' == type) ? 1 : 0,
43
- 'HAS_DATA_OBJECT_WRAP' => ('ruby' == type && '2' == version[0] && '3' <= version[1]) ? 1 : 0,
44
- 'HAS_METHOD_ARITY' => ('rubinius' == type) ? 0 : 1,
45
- 'HAS_STRUCT_MEMBERS' => ('rubinius' == type) ? 0 : 1,
46
23
  'RSTRUCT_LEN_RETURNS_INTEGER_OBJECT' => ('ruby' == type && '2' == version[0] && '4' == version[1] && '1' >= version[2]) ? 1 : 0,
47
24
  }
48
- # This is a monster hack to get around issues with 1.9.3-p0 on CentOS 5.4. SO
49
- # some reason math.h and string.h contents are not processed. Might be a
50
- # missing #define. This is the quick and easy way around it.
51
- if 'x86_64-linux' == RUBY_PLATFORM && '1.9.3' == RUBY_VERSION && '2011-10-30' == RUBY_RELEASE_DATE
52
- begin
53
- dflags['NEEDS_STPCPY'] = nil if File.read('/etc/redhat-release').include?('CentOS release 5.4')
54
- rescue Exception
55
- end
56
- else
57
- dflags['NEEDS_STPCPY'] = nil if is_windows
58
- end
25
+
26
+ have_func('rb_time_timespec')
27
+ have_func('rb_ivar_count')
28
+ have_func('rb_ivar_foreach')
29
+ have_func('stpcpy')
30
+ have_func('rb_data_object_wrap')
59
31
 
60
32
  dflags['OJ_DEBUG'] = true unless ENV['OJ_DEBUG'].nil?
61
33
 
@@ -69,6 +41,7 @@ end
69
41
 
70
42
  $CPPFLAGS += ' -Wall'
71
43
  #puts "*** $CPPFLAGS: #{$CPPFLAGS}"
44
+
72
45
  create_makefile(File.join(extension_name, extension_name))
73
46
 
74
- #%x{make clean}
47
+ %x{make clean}
@@ -118,7 +118,7 @@ static VALUE doc_size(VALUE self);
118
118
  VALUE oj_doc_class = Qundef;
119
119
 
120
120
  // This is only for CentOS 5.4 with Ruby 1.9.3-p0.
121
- #ifdef NEEDS_STPCPY
121
+ #ifndef HAVE_STPCPY
122
122
  char *stpcpy(char *dest, const char *src) {
123
123
  size_t cnt = strlen(src);
124
124
 
@@ -847,7 +847,7 @@ parse_json(VALUE clas, char *json, bool given, bool allocated) {
847
847
  }
848
848
  #endif
849
849
  // last arg is free func void* func(void*)
850
- #if HAS_DATA_OBJECT_WRAP
850
+ #ifdef HAVE_RB_DATA_OBJECT_WRAP
851
851
  self = rb_data_object_wrap(clas, doc, mark_doc, free_doc_cb);
852
852
  #else
853
853
  self = rb_data_object_alloc(clas, doc, mark_doc, free_doc_cb);
@@ -275,14 +275,10 @@ mimic_walk(VALUE key, VALUE obj, VALUE proc) {
275
275
  rb_yield(obj);
276
276
  }
277
277
  } else {
278
- #if HAS_PROC_WITH_BLOCK
279
278
  VALUE args[1];
280
279
 
281
280
  *args = obj;
282
281
  rb_proc_call_with_block(proc, 1, args, Qnil);
283
- #else
284
- rb_raise(rb_eNotImpError, "Calling a Proc with a block not supported in this version. Use func() {|x| } syntax instead.");
285
- #endif
286
282
  }
287
283
  return ST_CONTINUE;
288
284
  }
@@ -439,9 +439,9 @@ oj_set_obj_ivar(Val parent, Val kval, VALUE value) {
439
439
  rb_funcall(parent->val, rb_intern("set_backtrace"), 1, value);
440
440
  }
441
441
  }
442
- #if USE_PTHREAD_MUTEX
442
+ #if HAVE_LIBPTHREAD
443
443
  pthread_mutex_lock(&oj_cache_mutex);
444
- #elif USE_RB_MUTEX
444
+ #else
445
445
  rb_mutex_lock(oj_cache_mutex);
446
446
  #endif
447
447
  if (0 == (var_id = oj_attr_hash_get(key, klen, &slot))) {
@@ -473,9 +473,9 @@ oj_set_obj_ivar(Val parent, Val kval, VALUE value) {
473
473
  }
474
474
  *slot = var_id;
475
475
  }
476
- #if USE_PTHREAD_MUTEX
476
+ #if HAVE_LIBPTHREAD
477
477
  pthread_mutex_unlock(&oj_cache_mutex);
478
- #elif USE_RB_MUTEX
478
+ #else
479
479
  rb_mutex_unlock(oj_cache_mutex);
480
480
  #endif
481
481
  rb_ivar_set(parent->val, var_id, value);
@@ -19,10 +19,6 @@
19
19
  #include "rails.h"
20
20
  #include "encode.h"
21
21
 
22
- #if !HAS_ENCODING_SUPPORT || defined(RUBINIUS_RUBY)
23
- #define rb_eEncodingError rb_eException
24
- #endif
25
-
26
22
  typedef struct _YesNoOpt {
27
23
  VALUE sym;
28
24
  char *attr;
@@ -148,15 +144,11 @@ static VALUE word_sym;
148
144
  static VALUE xmlschema_sym;
149
145
  static VALUE xss_safe_sym;
150
146
 
151
- #if HAS_ENCODING_SUPPORT
152
147
  rb_encoding *oj_utf8_encoding = 0;
153
- #else
154
- VALUE oj_utf8_encoding = Qnil;
155
- #endif
156
148
 
157
- #if USE_PTHREAD_MUTEX
149
+ #if HAVE_LIBPTHREAD
158
150
  pthread_mutex_t oj_cache_mutex;
159
- #elif USE_RB_MUTEX
151
+ #else
160
152
  VALUE oj_cache_mutex = Qnil;
161
153
  #endif
162
154
 
@@ -1488,23 +1480,6 @@ hash_test(VALUE self) {
1488
1480
  }
1489
1481
  */
1490
1482
 
1491
- #if !HAS_ENCODING_SUPPORT
1492
- static VALUE
1493
- iconv_encoder(VALUE x) {
1494
- VALUE iconv;
1495
-
1496
- rb_require("iconv");
1497
- iconv = rb_const_get(rb_cObject, rb_intern("Iconv"));
1498
-
1499
- return rb_funcall(iconv, rb_intern("new"), 2, rb_str_new2("ASCII//TRANSLIT"), rb_str_new2("UTF-8"));
1500
- }
1501
-
1502
- static VALUE
1503
- iconv_rescue(VALUE x) {
1504
- return Qnil;
1505
- }
1506
- #endif
1507
-
1508
1483
  static VALUE
1509
1484
  protect_require(VALUE x) {
1510
1485
  rb_require("time");
@@ -1554,17 +1529,8 @@ Init_oj() {
1554
1529
  rb_require("date");
1555
1530
  // On Rubinius the require fails but can be done from a ruby file.
1556
1531
  rb_protect(protect_require, Qnil, &err);
1557
- #if NEEDS_RATIONAL
1558
- rb_require("rational");
1559
- #endif
1560
1532
  rb_require("stringio");
1561
- #if HAS_ENCODING_SUPPORT
1562
1533
  oj_utf8_encoding = rb_enc_find("UTF-8");
1563
- #else
1564
- // need an option to turn this on
1565
- oj_utf8_encoding = rb_rescue(iconv_encoder, Qnil, iconv_rescue, Qnil);
1566
- oj_utf8_encoding = Qnil;
1567
- #endif
1568
1534
 
1569
1535
  //rb_define_module_function(Oj, "hash_test", hash_test, 0);
1570
1536
 
@@ -1732,9 +1698,9 @@ Init_oj() {
1732
1698
  oj_odd_init();
1733
1699
  oj_mimic_rails_init();
1734
1700
 
1735
- #if USE_PTHREAD_MUTEX
1701
+ #if HAVE_LIBPTHREAD
1736
1702
  pthread_mutex_init(&oj_cache_mutex, 0);
1737
- #elif USE_RB_MUTEX
1703
+ #else
1738
1704
  oj_cache_mutex = rb_mutex_new();
1739
1705
  rb_gc_register_address(&oj_cache_mutex);
1740
1706
  #endif
@@ -16,14 +16,12 @@ extern "C" {
16
16
  #define RSTRING_NOT_MODIFIED
17
17
 
18
18
  #include "ruby.h"
19
- #if HAS_ENCODING_SUPPORT
20
19
  #include "ruby/encoding.h"
21
- #endif
22
20
 
23
21
  #include <stdint.h>
24
22
  #include <stdbool.h>
25
23
 
26
- #if USE_PTHREAD_MUTEX
24
+ #if HAVE_LIBPTHREAD
27
25
  #include <pthread.h>
28
26
  #endif
29
27
  #include "cache8.h"
@@ -33,13 +31,8 @@ extern "C" {
33
31
  #undef T_COMPLEX
34
32
  enum st_retval {ST_CONTINUE = 0, ST_STOP = 1, ST_DELETE = 2, ST_CHECK};
35
33
  #else
36
- #if HAS_TOP_LEVEL_ST_H
37
- // Only on travis, local is where it is for all others. Seems to vary depending on the travis machine picked up.
38
- #include "st.h"
39
- #else
40
34
  #include "ruby/st.h"
41
35
  #endif
42
- #endif
43
36
 
44
37
  #include "rxclass.h"
45
38
  #include "err.h"
@@ -292,11 +285,7 @@ extern VALUE oj_rails_encode(int argc, VALUE *argv, VALUE self);
292
285
 
293
286
  extern VALUE Oj;
294
287
  extern struct _Options oj_default_options;
295
- #if HAS_ENCODING_SUPPORT
296
288
  extern rb_encoding *oj_utf8_encoding;
297
- #else
298
- extern VALUE oj_utf8_encoding;
299
- #endif
300
289
 
301
290
  extern VALUE oj_bag_class;
302
291
  extern VALUE oj_bigdecimal_class;
@@ -376,9 +365,9 @@ extern ID oj_write_id;
376
365
  extern bool oj_use_hash_alt;
377
366
  extern bool oj_use_array_alt;
378
367
 
379
- #if USE_PTHREAD_MUTEX
368
+ #if HAVE_LIBPTHREAD
380
369
  extern pthread_mutex_t oj_cache_mutex;
381
- #elif USE_RB_MUTEX
370
+ #else
382
371
  extern VALUE oj_cache_mutex;
383
372
  #endif
384
373
 
@@ -707,12 +707,7 @@ oj_parse2(ParseInfo pi) {
707
707
  if (Qnil == pi->proc) {
708
708
  rb_yield_values2(3, args);
709
709
  } else {
710
- #if HAS_PROC_WITH_BLOCK
711
710
  rb_proc_call_with_block(pi->proc, 3, args, Qnil);
712
- #else
713
- rb_raise(rb_eNotImpError,
714
- "Calling a Proc with a block not supported in this version. Use func() {|x| } syntax instead.");
715
- #endif
716
711
  }
717
712
  } else if (!pi->has_callbacks) {
718
713
  first = 0;
@@ -850,13 +845,11 @@ extern int oj_utf8_index;
850
845
 
851
846
  static void
852
847
  oj_pi_set_input_str(ParseInfo pi, volatile VALUE *inputp) {
853
- #if HAS_ENCODING_SUPPORT
854
848
  rb_encoding *enc = rb_to_encoding(rb_obj_encoding(*inputp));
855
849
 
856
850
  if (rb_utf8_encoding() != enc) {
857
851
  *inputp = rb_str_conv_enc(*inputp, enc, rb_utf8_encoding());
858
852
  }
859
- #endif
860
853
  pi->json = rb_string_value_ptr((VALUE*)inputp);
861
854
  pi->end = pi->json + RSTRING_LEN(*inputp);
862
855
  }
@@ -96,11 +96,9 @@ dump_attr_cb(ID key, VALUE value, Out out) {
96
96
  if (NULL == attr) {
97
97
  attr = "";
98
98
  }
99
- #if HAS_EXCEPTION_MAGIC
100
99
  if (0 == strcmp("bt", attr) || 0 == strcmp("mesg", attr)) {
101
100
  return ST_CONTINUE;
102
101
  }
103
- #endif
104
102
  assure_size(out, size);
105
103
  fill_indent(out, depth);
106
104
  if ('@' == *attr) {
@@ -306,7 +304,7 @@ dump_time(VALUE obj, int depth, Out out, bool as_ok) {
306
304
  time_t sec;
307
305
  long long nsec;
308
306
 
309
- #if HAS_RB_TIME_TIMESPEC
307
+ #ifdef HAVE_RB_TIME_TIMESPEC
310
308
  {
311
309
  struct timespec ts = rb_time_timespec(obj);
312
310
  sec = ts.tv_sec;
@@ -314,11 +312,7 @@ dump_time(VALUE obj, int depth, Out out, bool as_ok) {
314
312
  }
315
313
  #else
316
314
  sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
317
- #if HAS_NANO_TIME
318
315
  nsec = rb_num2ll(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
319
- #else
320
- nsec = rb_num2ll(rb_funcall2(obj, oj_tv_usec_id, 0, 0)) * 1000;
321
- #endif
322
316
  #endif
323
317
  dump_sec_nano(obj, sec, nsec, out);
324
318
  }
@@ -529,15 +523,11 @@ dump_as_json(VALUE obj, int depth, Out out, bool as_ok) {
529
523
  }
530
524
  // Some classes elect to not take an options argument so check the arity
531
525
  // of as_json.
532
- #if HAS_METHOD_ARITY
533
526
  if (0 == rb_obj_method_arity(obj, oj_as_json_id)) {
534
527
  ja = rb_funcall(obj, oj_as_json_id, 0);
535
528
  } else {
536
529
  ja = rb_funcall2(obj, oj_as_json_id, out->argc, out->argv);
537
530
  }
538
- #else
539
- ja = rb_funcall2(obj, oj_as_json_id, out->argc, out->argv);
540
- #endif
541
531
  if (Yes == out->opts->trace) {
542
532
  oj_trace("as_json", obj, __FILE__, __LINE__, depth + 1, TraceRubyOut);
543
533
  }
@@ -1024,16 +1014,11 @@ rails_encode(int argc, VALUE *argv, VALUE self) {
1024
1014
 
1025
1015
  static VALUE
1026
1016
  rails_use_standard_json_time_format(VALUE self, VALUE state) {
1027
- switch (state) {
1028
- case Qtrue:
1029
- case Qfalse:
1030
- break;
1031
- case Qnil:
1017
+ if (Qtrue == state || Qfalse == state) {
1018
+ } else if (Qnil == state) {
1032
1019
  state = Qfalse;
1033
- break;
1034
- default:
1020
+ } else {
1035
1021
  state = Qtrue;
1036
- break;
1037
1022
  }
1038
1023
  rb_iv_set(self, "@use_standard_json_time_format", state);
1039
1024
  xml_time = Qtrue == state;
@@ -6,7 +6,7 @@
6
6
  #include <stdlib.h>
7
7
  #include <stdio.h>
8
8
  #include <string.h>
9
- #if USE_PTHREAD_MUTEX
9
+ #if HAVE_LIBPTHREAD
10
10
  #include <pthread.h>
11
11
  #endif
12
12
 
@@ -75,9 +75,9 @@ oj_name2class(ParseInfo pi, const char *name, size_t len, int auto_define, VALUE
75
75
  if (No == pi->options.class_cache) {
76
76
  return resolve_classpath(pi, name, len, auto_define, error_class);
77
77
  }
78
- #if USE_PTHREAD_MUTEX
78
+ #if HAVE_LIBPTHREAD
79
79
  pthread_mutex_lock(&oj_cache_mutex);
80
- #elif USE_RB_MUTEX
80
+ #else
81
81
  rb_mutex_lock(oj_cache_mutex);
82
82
  #endif
83
83
  if (Qnil == (clas = oj_class_hash_get(name, len, &slot))) {
@@ -85,9 +85,9 @@ oj_name2class(ParseInfo pi, const char *name, size_t len, int auto_define, VALUE
85
85
  *slot = clas;
86
86
  }
87
87
  }
88
- #if USE_PTHREAD_MUTEX
88
+ #if HAVE_LIBPTHREAD
89
89
  pthread_mutex_unlock(&oj_cache_mutex);
90
- #elif USE_RB_MUTEX
90
+ #else
91
91
  rb_mutex_unlock(oj_cache_mutex);
92
92
  #endif
93
93
  return clas;
@@ -756,13 +756,7 @@ oj_sparse2(ParseInfo pi) {
756
756
  if (Qnil == pi->proc) {
757
757
  rb_yield_values2(3, args);
758
758
  } else {
759
- #if HAS_PROC_WITH_BLOCK
760
759
  rb_proc_call_with_block(pi->proc, 3, args, Qnil);
761
- #else
762
- oj_set_error_at(pi, rb_eNotImpError, __FILE__, __LINE__,
763
- "Calling a Proc with a block not supported in this version. Use func() {|x| } syntax instead.");
764
- return;
765
- #endif
766
760
  }
767
761
  } else if (!pi->has_callbacks) {
768
762
  first = 0;
@@ -39,9 +39,9 @@ mark(void *ptr) {
39
39
  if (0 == ptr) {
40
40
  return;
41
41
  }
42
- #if USE_PTHREAD_MUTEX
42
+ #if HAVE_LIBPTHREAD
43
43
  pthread_mutex_lock(&stack->mutex);
44
- #elif USE_RB_MUTEX
44
+ #else
45
45
  rb_mutex_lock(stack->mutex);
46
46
  rb_gc_mark(stack->mutex);
47
47
  #endif
@@ -53,18 +53,18 @@ mark(void *ptr) {
53
53
  rb_gc_mark(v->key_val);
54
54
  }
55
55
  }
56
- #if USE_PTHREAD_MUTEX
56
+ #if HAVE_LIBPTHREAD
57
57
  pthread_mutex_unlock(&stack->mutex);
58
- #elif USE_RB_MUTEX
58
+ #else
59
59
  rb_mutex_unlock(stack->mutex);
60
60
  #endif
61
61
  }
62
62
 
63
63
  VALUE
64
64
  oj_stack_init(ValStack stack) {
65
- #if USE_PTHREAD_MUTEX
65
+ #if HAVE_LIBPTHREAD
66
66
  pthread_mutex_init(&stack->mutex, 0);
67
- #elif USE_RB_MUTEX
67
+ #else
68
68
  stack->mutex = rb_mutex_new();
69
69
  #endif
70
70
  stack->head = stack->base;
@@ -34,7 +34,7 @@
34
34
  #include "ruby.h"
35
35
  #include "odd.h"
36
36
  #include <stdint.h>
37
- #if USE_PTHREAD_MUTEX
37
+ #if HAVE_LIBPTHREAD
38
38
  #include <pthread.h>
39
39
  #endif
40
40
 
@@ -76,9 +76,9 @@ typedef struct _ValStack {
76
76
  Val head; // current stack
77
77
  Val end; // stack end
78
78
  Val tail; // pointer to one past last element name on stack
79
- #if USE_PTHREAD_MUTEX
79
+ #if HAVE_LIBPTHREAD
80
80
  pthread_mutex_t mutex;
81
- #elif USE_RB_MUTEX
81
+ #else
82
82
  VALUE mutex;
83
83
  #endif
84
84
 
@@ -114,17 +114,17 @@ stack_push(ValStack stack, VALUE val, ValNext next) {
114
114
  } else {
115
115
  REALLOC_N(head, struct _Val, len + STACK_INC);
116
116
  }
117
- #if USE_PTHREAD_MUTEX
117
+ #if HAVE_LIBPTHREAD
118
118
  pthread_mutex_lock(&stack->mutex);
119
- #elif USE_RB_MUTEX
119
+ #else
120
120
  rb_mutex_lock(stack->mutex);
121
121
  #endif
122
122
  stack->head = head;
123
123
  stack->tail = stack->head + toff;
124
124
  stack->end = stack->head + len + STACK_INC;
125
- #if USE_PTHREAD_MUTEX
125
+ #if HAVE_LIBPTHREAD
126
126
  pthread_mutex_unlock(&stack->mutex);
127
- #elif USE_RB_MUTEX
127
+ #else
128
128
  rb_mutex_unlock(stack->mutex);
129
129
  #endif
130
130
  }
@@ -199,7 +199,7 @@ dump_time(VALUE obj, Out out) {
199
199
  time_t sec;
200
200
  long long nsec;
201
201
 
202
- #if HAS_RB_TIME_TIMESPEC
202
+ #ifdef HAVE_RB_TIME_TIMESPEC
203
203
  {
204
204
  struct timespec ts = rb_time_timespec(obj);
205
205
  sec = ts.tv_sec;
@@ -207,11 +207,7 @@ dump_time(VALUE obj, Out out) {
207
207
  }
208
208
  #else
209
209
  sec = rb_num2ll(rb_funcall2(obj, oj_tv_sec_id, 0, 0));
210
- #if HAS_NANO_TIME
211
210
  nsec = rb_num2ll(rb_funcall2(obj, oj_tv_nsec_id, 0, 0));
212
- #else
213
- nsec = rb_num2ll(rb_funcall2(obj, oj_tv_usec_id, 0, 0)) * 1000;
214
- #endif
215
211
  #endif
216
212
 
217
213
  assure_size(out, 36);
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '3.7.0'
4
+ VERSION = '3.7.1'
5
5
  end
@@ -6,65 +6,27 @@ $: << '../ext'
6
6
 
7
7
  require 'oj'
8
8
 
9
- #Oj.load(StringIO.new(Oj.dump({ records: 1.upto(25).map{|i| { id: i, name: "record_#{i}" }} }, mode: :strict)))
10
9
 
11
10
  class MyParser
12
- attr_accessor :enum
13
-
14
11
  def initialize
15
- @io = StringIO.new
16
- @writer = Oj::StreamWriter.new(@io)
17
-
18
- json_string = Oj.dump({ records: 1.upto(25).map{|i| { id: i, name: "record_#{i}" }} }, mode: :strict)
19
- @test_json = StringIO.new(json_string)
20
-
21
- @enum = Enumerator.new do |yielder|
22
- @yielder = yielder
23
- Oj.sc_parse(self, @test_json)
24
- end
25
- end
26
-
27
- # Stream parsing methods
28
- def hash_start
29
- @writer.push_object
30
- end
31
-
32
- def hash_end
33
- @writer.pop unless @io.eof
34
- end
35
-
36
- def hash_key(key)
37
- @writer.push_key(key)
12
+ @current_depth = 0
38
13
  end
39
14
 
40
- def hash_set(h, key, value)
41
- @writer.push_value(value)
15
+ def parse(file)
16
+ Oj.sc_parse(self, file)
42
17
  end
43
18
 
44
- def array_start
45
- @writer.push_array
46
- end
47
-
48
- def array_end
49
- @writer.pop
50
- end
51
-
52
- def array_append(a, value)
53
- yield_data
54
- end
55
-
56
- def add_value(value);end
57
-
58
- def yield_data
59
- @writer.pop_all
60
- @yielder << @io.string
61
- @io.reopen("")
62
- array_start
19
+ def hash_start
20
+ puts "start"
21
+ @current_depth += 1
22
+ raise Exception.new("Hello")
23
+ {}
63
24
  end
64
- end
65
25
 
66
- MyParser.new.enum.each.with_index do |r, i|
67
- break if i == 0
26
+ # Other Oj::ScHandler methods go below.
27
+ # The parser's purpose is to find a specific value nested deep within the streaming JSON
28
+ # and to stop parsing immediately afterward.
68
29
  end
69
30
 
70
-
31
+ parser = MyParser.new
32
+ parser.parse(%|{"a":{"b":{"c":{}}}}|)
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.7.0
4
+ version: 3.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-29 00:00:00.000000000 Z
11
+ date: 2018-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler