usamin 7.7.5 → 7.7.6

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
  SHA256:
3
- metadata.gz: 2dc9e7a6a2f8cf8fd04b8bd8063f014dd6b78a04b6727a0d1a60fec9f5dc3bc6
4
- data.tar.gz: 8fb71ac883d87559cb9a2d4c993925cf3cff431904e141bf82a652a6f57385c5
3
+ metadata.gz: 578850ff19b39ff8950a5d31f890d78cef055935521637ab28cbcda311d1739d
4
+ data.tar.gz: 95705ef10f8fc3dcdf3687d9670638a981c081154cbc1dcdd85b3cb7a9821683
5
5
  SHA512:
6
- metadata.gz: 56d2aa592fc15f8647859d793d025e1a78af802ffc868073997d533b1e62c5563e5d3ec26a0fc5b795fc6c34454e36c4a625cf9f524e51744e9bccba567f6fee
7
- data.tar.gz: fcfdd4ec9ebf5437a16aa1584a1450b218040072961d7cd8e4aff0a3d1a1a2f89996665b01fb1b9861c193fb9fa9f3f2b56af139168e5eb9fd90d61f9daae355
6
+ metadata.gz: d95d14dcdfa3578c75699f529e5d324ef47f4e4eba6961efd76136bcaee3b01d50f35cace24c018824de6b48a3cac96e1c0d1ad3c43a72e17f1a882847b6c4c7
7
+ data.tar.gz: b4f9a8f2cef31b7e7dcfe1e876b59f9164322af8db9a7b970a944559c19d9c83d9490b5dd1c819b34f3f02ec1aa7f83003700c7c243a7af2d2ed96da9947c3cd
@@ -25,9 +25,10 @@ VALUE utf8value, sym_fast, sym_indent, sym_single_line_array;
25
25
  class UsaminValue {
26
26
  public:
27
27
  rapidjson::Value *value;
28
+ VALUE root_document;
28
29
  bool free_flag;
29
30
 
30
- UsaminValue(rapidjson::Value *value = nullptr, bool free_flag = false);
31
+ UsaminValue(rapidjson::Value *value = nullptr, const bool free_flag = false, const VALUE root_document = Qnil);
31
32
  ~UsaminValue();
32
33
  };
33
34
 
@@ -53,20 +54,13 @@ static inline bool str_compare(const char* str1, const long len1, const char* st
53
54
  }
54
55
 
55
56
  static inline bool str_compare_xx(VALUE str1, const rapidjson::Value &str2) {
56
- bool free_flag = true;
57
- if (RB_TYPE_P(str1, T_STRING)) {
57
+ if (RB_TYPE_P(str1, T_STRING))
58
58
  str1 = get_utf8_str(str1);
59
- free_flag = false;
60
- } else if (SYMBOL_P(str1)) {
59
+ else if (SYMBOL_P(str1))
61
60
  str1 = get_utf8_str(rb_sym_to_s(str1));
62
- } else {
63
- StringValue(str1);
64
- str1 = get_utf8_str(str1);
65
- }
66
- bool ret = str_compare(RSTRING_PTR(str1), RSTRING_LEN(str1), str2.GetString(), str2.GetStringLength());
67
- if (free_flag)
68
- rb_str_free(str1);
69
- return ret;
61
+ else
62
+ str1 = get_utf8_str(StringValue(str1));
63
+ return str_compare(RSTRING_PTR(str1), RSTRING_LEN(str1), str2.GetString(), str2.GetStringLength());
70
64
  }
71
65
 
72
66
  static inline void check_value(UsaminValue *ptr) {
@@ -94,10 +88,16 @@ static VALUE usamin_free(UsaminValue **ptr) {
94
88
  return Qnil;
95
89
  }
96
90
 
91
+ static VALUE usamin_mark(UsaminValue **ptr) {
92
+ if (*ptr && (*ptr)->root_document != Qnil)
93
+ rb_gc_mark((*ptr)->root_document);
94
+ return Qnil;
95
+ }
96
+
97
97
  static VALUE usamin_alloc(const VALUE klass) {
98
98
  UsaminValue** ptr = (UsaminValue**)ruby_xmalloc(sizeof(UsaminValue*));
99
99
  *ptr = nullptr;
100
- return Data_Wrap_Struct(klass, NULL, usamin_free, ptr);
100
+ return Data_Wrap_Struct(klass, usamin_mark, usamin_free, ptr);
101
101
  }
102
102
 
103
103
 
@@ -126,24 +126,22 @@ static inline VALUE make_array(UsaminValue *value) {
126
126
  }
127
127
 
128
128
  static inline rapidjson::ParseResult parse(rapidjson::Document &doc, const VALUE str, bool fast = false) {
129
- VALUE v = get_utf8_str(str);
129
+ volatile VALUE v = get_utf8_str(str);
130
130
  return fast ? doc.Parse<kParseFastFlags>(RSTRING_PTR(v), RSTRING_LEN(v)) : doc.Parse(RSTRING_PTR(v), RSTRING_LEN(v));
131
131
  }
132
132
 
133
133
 
134
- static inline VALUE eval_num(rapidjson::Value &value);
135
- static inline VALUE eval_str(rapidjson::Value &value);
136
- static inline VALUE eval_object(rapidjson::Value &value);
137
- static inline VALUE eval_object_r(rapidjson::Value &value);
138
- static inline VALUE eval_array(rapidjson::Value &value);
139
- static inline VALUE eval_array_r(rapidjson::Value &value);
134
+ static inline VALUE eval_num(rapidjson::Value&);
135
+ static inline VALUE eval_str(rapidjson::Value&);
136
+ static inline VALUE eval_object_r(rapidjson::Value&);
137
+ static inline VALUE eval_array_r(rapidjson::Value&);
140
138
 
141
- static VALUE eval(rapidjson::Value &value) {
139
+ static VALUE eval(rapidjson::Value &value, VALUE root_document) {
142
140
  switch (value.GetType()) {
143
141
  case rapidjson::kObjectType:
144
- return make_hash(new UsaminValue(&value, false));
142
+ return make_hash(new UsaminValue(&value, false, root_document));
145
143
  case rapidjson::kArrayType:
146
- return make_array(new UsaminValue(&value, false));
144
+ return make_array(new UsaminValue(&value, false, root_document));
147
145
  case rapidjson::kNullType:
148
146
  return Qnil;
149
147
  case rapidjson::kFalseType:
@@ -199,10 +197,10 @@ static inline VALUE eval_str(rapidjson::Value &value) {
199
197
  return new_utf8_str(value.GetString(), value.GetStringLength());
200
198
  }
201
199
 
202
- static inline VALUE eval_object(rapidjson::Value &value) {
200
+ static inline VALUE eval_object(rapidjson::Value &value, const VALUE root_document) {
203
201
  VALUE ret = rb_hash_new();
204
202
  for (auto &m : value.GetObject())
205
- rb_hash_aset(ret, eval_str(m.name), eval(m.value));
203
+ rb_hash_aset(ret, eval_str(m.name), eval(m.value, root_document));
206
204
  return ret;
207
205
  }
208
206
 
@@ -213,10 +211,10 @@ static inline VALUE eval_object_r(rapidjson::Value &value) {
213
211
  return ret;
214
212
  }
215
213
 
216
- static inline VALUE eval_array(rapidjson::Value &value) {
214
+ static inline VALUE eval_array(rapidjson::Value &value, const VALUE root_document) {
217
215
  VALUE ret = rb_ary_new2(value.Size());
218
216
  for (auto &v : value.GetArray())
219
- rb_ary_push(ret, eval(v));
217
+ rb_ary_push(ret, eval(v, root_document));
220
218
  return ret;
221
219
  }
222
220
 
@@ -296,7 +294,7 @@ template <class Writer> static inline void write_key_to_s(Writer &writer, const
296
294
  write_key_str(writer, rb_funcall(value, id_to_s, 0));
297
295
  }
298
296
 
299
- template <class Writer> static inline int write_hash_each(VALUE key, VALUE value, Writer *writer) {
297
+ template <class Writer> static inline int write_hash_each(const VALUE key, const VALUE value, Writer *writer) {
300
298
  if (RB_TYPE_P(key, T_STRING))
301
299
  write_key_str(*writer, key);
302
300
  else if (RB_TYPE_P(key, T_SYMBOL))
@@ -393,14 +391,15 @@ template <class Writer> static inline void write_to_s(Writer &writer, const VALU
393
391
  }
394
392
 
395
393
 
396
- UsaminValue::UsaminValue(rapidjson::Value *value, bool free_flag) {
394
+ UsaminValue::UsaminValue(rapidjson::Value *value, const bool free_flag, const VALUE root_document) {
397
395
  this->value = value;
398
396
  this->free_flag = free_flag;
397
+ this->root_document = root_document;
399
398
  }
400
399
 
401
400
  UsaminValue::~UsaminValue() {
402
401
  if (value && free_flag)
403
- delete value;
402
+ delete (rapidjson::Document*)value;
404
403
  }
405
404
 
406
405
  /*
@@ -413,7 +412,7 @@ UsaminValue::~UsaminValue() {
413
412
  * @option opts :fast fast mode (but not precise)
414
413
  * @return [Object]
415
414
  */
416
- static VALUE w_load(const int argc, VALUE *argv, const VALUE self) {
415
+ static VALUE w_load(const int argc, const VALUE *argv, const VALUE self) {
417
416
  VALUE source, options;
418
417
  rb_scan_args(argc, argv, "1:", &source, &options);
419
418
  rapidjson::Document *doc = new rapidjson::Document;
@@ -461,7 +460,7 @@ static VALUE w_load(const int argc, VALUE *argv, const VALUE self) {
461
460
  * @option opts :fast fast mode (but not precise)
462
461
  * @return [Object]
463
462
  */
464
- static VALUE w_parse(const int argc, VALUE *argv, const VALUE self) {
463
+ static VALUE w_parse(const int argc, const VALUE *argv, const VALUE self) {
465
464
  VALUE source, options;
466
465
  rb_scan_args(argc, argv, "1:", &source, &options);
467
466
  rapidjson::Document doc;
@@ -498,9 +497,9 @@ static VALUE w_value_eval(const VALUE self) {
498
497
  UsaminValue *value = get_value(self);
499
498
  check_value(value);
500
499
  if (value->value->IsObject())
501
- return eval_object(*(value->value));
500
+ return eval_object(*(value->value), self);
502
501
  else if (value->value->IsArray())
503
- return eval_array(*(value->value));
502
+ return eval_array(*(value->value), self);
504
503
  else
505
504
  return Qnil;
506
505
  }
@@ -542,7 +541,7 @@ static VALUE w_value_marshal_dump(const VALUE self) {
542
541
  *
543
542
  * @return [self]
544
543
  */
545
- static VALUE w_value_marshal_load(const VALUE self, VALUE source) {
544
+ static VALUE w_value_marshal_load(const VALUE self, const VALUE source) {
546
545
  Check_Type(source, T_STRING);
547
546
  rapidjson::Document *doc = new rapidjson::Document();
548
547
  rapidjson::ParseResult result = doc->Parse<rapidjson::kParseFullPrecisionFlag | rapidjson::kParseNanAndInfFlag>(RSTRING_PTR(source), RSTRING_LEN(source));
@@ -566,12 +565,12 @@ static VALUE w_value_marshal_load(const VALUE self, VALUE source) {
566
565
  *
567
566
  * @note This method has linear time complexity.
568
567
  */
569
- static VALUE w_hash_operator_indexer(const VALUE self, VALUE key) {
568
+ static VALUE w_hash_operator_indexer(const VALUE self, const VALUE key) {
570
569
  UsaminValue *value = get_value(self);
571
570
  check_object(value);
572
571
  for (auto &m : value->value->GetObject())
573
572
  if (str_compare_xx(key, m.name))
574
- return eval(m.value);
573
+ return eval(m.value, self);
575
574
  return Qnil;
576
575
  }
577
576
 
@@ -580,12 +579,12 @@ static VALUE w_hash_operator_indexer(const VALUE self, VALUE key) {
580
579
  *
581
580
  * @note This method has linear time complexity.
582
581
  */
583
- static VALUE w_hash_assoc(const VALUE self, VALUE key) {
582
+ static VALUE w_hash_assoc(const VALUE self, const VALUE key) {
584
583
  UsaminValue *value = get_value(self);
585
584
  check_object(value);
586
585
  for (auto &m : value->value->GetObject())
587
586
  if (str_compare_xx(key, m.name))
588
- return rb_assoc_new(eval_str(m.name), eval(m.value));
587
+ return rb_assoc_new(eval_str(m.name), eval(m.value, self));
589
588
  return Qnil;
590
589
  }
591
590
 
@@ -598,11 +597,11 @@ static VALUE w_hash_compact(const VALUE self) {
598
597
  VALUE hash = rb_hash_new();
599
598
  for (auto &m : value->value->GetObject())
600
599
  if (!m.value.IsNull())
601
- rb_hash_aset(hash, eval(m.name), eval(m.value));
600
+ rb_hash_aset(hash, eval(m.name, self), eval(m.value, self));
602
601
  return hash;
603
602
  }
604
603
 
605
- static VALUE hash_enum_size(const VALUE self, VALUE args, VALUE eobj) {
604
+ static VALUE hash_enum_size(const VALUE self, const VALUE args, const VALUE eobj) {
606
605
  return UINT2NUM(get_value(self)->value->MemberCount());
607
606
  }
608
607
 
@@ -618,12 +617,12 @@ static VALUE w_hash_each(const VALUE self) {
618
617
  RETURN_SIZED_ENUMERATOR(self, 0, nullptr, hash_enum_size);
619
618
  if (rb_proc_arity(rb_block_proc()) > 1) {
620
619
  for (auto &m : value->value->GetObject()) {
621
- VALUE args[] = { eval_str(m.name), eval(m.value) };
620
+ VALUE args[] = { eval_str(m.name), eval(m.value, self) };
622
621
  rb_yield_values2(2, args);
623
622
  }
624
623
  } else {
625
624
  for (auto &m : value->value->GetObject())
626
- rb_yield(rb_assoc_new(eval_str(m.name), eval(m.value)));
625
+ rb_yield(rb_assoc_new(eval_str(m.name), eval(m.value, self)));
627
626
  }
628
627
  return self;
629
628
  }
@@ -651,7 +650,7 @@ static VALUE w_hash_each_value(const VALUE self) {
651
650
  check_object(value);
652
651
  RETURN_SIZED_ENUMERATOR(self, 0, nullptr, hash_enum_size);
653
652
  for (auto &m : value->value->GetObject())
654
- rb_yield(eval(m.value));
653
+ rb_yield(eval(m.value, self));
655
654
  return self;
656
655
  }
657
656
 
@@ -672,13 +671,13 @@ static VALUE w_hash_isempty(const VALUE self) {
672
671
  * @yield [key]
673
672
  * @return [Object]
674
673
  */
675
- static VALUE w_hash_fetch(const int argc, VALUE* argv, const VALUE self) {
674
+ static VALUE w_hash_fetch(const int argc, const VALUE *argv, const VALUE self) {
676
675
  rb_check_arity(argc, 1, 2);
677
676
  UsaminValue *value = get_value(self);
678
677
  check_object(value);
679
678
  for (auto &m : value->value->GetObject())
680
679
  if (str_compare_xx(argv[0], m.name))
681
- return eval(m.value);
680
+ return eval(m.value, self);
682
681
  return argc == 2 ? argv[1] : rb_block_given_p() ? rb_yield(argv[0]) : Qnil;
683
682
  }
684
683
 
@@ -694,7 +693,7 @@ static VALUE w_hash_fetch_values(const int argc, VALUE *argv, const VALUE self)
694
693
  bool found = false;
695
694
  for (auto &m : value->value->GetObject()) {
696
695
  if (str_compare_xx(argv[i], m.name)) {
697
- rb_ary_push(ret, eval(m.value));
696
+ rb_ary_push(ret, eval(m.value, self));
698
697
  found = true;
699
698
  break;
700
699
  }
@@ -715,7 +714,7 @@ static VALUE w_hash_fetch_values(const int argc, VALUE *argv, const VALUE self)
715
714
  /*
716
715
  * @note This method has linear time complexity.
717
716
  */
718
- static VALUE w_hash_haskey(const VALUE self, VALUE key) {
717
+ static VALUE w_hash_haskey(const VALUE self, const VALUE key) {
719
718
  UsaminValue *value = get_value(self);
720
719
  check_object(value);
721
720
  for (auto &m : value->value->GetObject())
@@ -724,7 +723,7 @@ static VALUE w_hash_haskey(const VALUE self, VALUE key) {
724
723
  return Qfalse;
725
724
  }
726
725
 
727
- static VALUE w_hash_hasvalue(const VALUE self, VALUE val) {
726
+ static VALUE w_hash_hasvalue(const VALUE self, const VALUE val) {
728
727
  UsaminValue *value = get_value(self);
729
728
  check_object(value);
730
729
  for (auto &m : value->value->GetObject())
@@ -736,7 +735,7 @@ static VALUE w_hash_hasvalue(const VALUE self, VALUE val) {
736
735
  /*
737
736
  * @return [String | nil]
738
737
  */
739
- static VALUE w_hash_key(const VALUE self, VALUE val) {
738
+ static VALUE w_hash_key(const VALUE self, const VALUE val) {
740
739
  UsaminValue *value = get_value(self);
741
740
  check_object(value);
742
741
  for (auto &m : value->value->GetObject())
@@ -769,12 +768,12 @@ static VALUE w_hash_length(const VALUE self) {
769
768
  /*
770
769
  * @return [::Array | nil]
771
770
  */
772
- static VALUE w_hash_rassoc(const VALUE self, VALUE val) {
771
+ static VALUE w_hash_rassoc(const VALUE self, const VALUE val) {
773
772
  UsaminValue *value = get_value(self);
774
773
  check_object(value);
775
774
  for (auto &m : value->value->GetObject())
776
775
  if (rb_funcall(val, rb_intern("=="), 1, eval_r(m.value)))
777
- return rb_assoc_new(eval(m.name), eval(m.value));
776
+ return rb_assoc_new(eval_str(m.name), eval(m.value, self));
778
777
  return Qnil;
779
778
  }
780
779
 
@@ -791,14 +790,14 @@ static VALUE w_hash_select(const VALUE self) {
791
790
  VALUE hash = rb_hash_new();
792
791
  if (rb_proc_arity(rb_block_proc()) > 1) {
793
792
  for (auto &m : value->value->GetObject()) {
794
- VALUE args[] = { eval_str(m.name), eval(m.value) };
793
+ VALUE args[] = { eval_str(m.name), eval(m.value, self) };
795
794
  if (RTEST(rb_yield_values2(2, args)))
796
795
  rb_hash_aset(hash, args[0], args[1]);
797
796
  }
798
797
  } else {
799
798
  for (auto &m : value->value->GetObject()) {
800
799
  VALUE key = eval_str(m.name);
801
- VALUE val = eval(m.value);
800
+ VALUE val = eval(m.value, self);
802
801
  if (RTEST(rb_yield(rb_assoc_new(key, val))))
803
802
  rb_hash_aset(hash, key, val);
804
803
  }
@@ -819,14 +818,14 @@ static VALUE w_hash_reject(const VALUE self) {
819
818
  VALUE hash = rb_hash_new();
820
819
  if (rb_proc_arity(rb_block_proc()) > 1) {
821
820
  for (auto &m : value->value->GetObject()) {
822
- VALUE args[] = { eval_str(m.name), eval(m.value) };
821
+ VALUE args[] = { eval_str(m.name), eval(m.value, self) };
823
822
  if (!RTEST(rb_yield_values2(2, args)))
824
823
  rb_hash_aset(hash, args[0], args[1]);
825
824
  }
826
825
  } else {
827
826
  for (auto &m : value->value->GetObject()) {
828
827
  VALUE key = eval_str(m.name);
829
- VALUE val = eval(m.value);
828
+ VALUE val = eval(m.value, self);
830
829
  if (!RTEST(rb_yield(rb_assoc_new(key, val))))
831
830
  rb_hash_aset(hash, key, val);
832
831
  }
@@ -840,14 +839,14 @@ static VALUE w_hash_reject(const VALUE self) {
840
839
  * @yieldparam value [Object]
841
840
  * @return [Enumerator | ::Hash]
842
841
  */
843
- static VALUE w_hash_slice(const int argc, VALUE* argv, const VALUE self) {
842
+ static VALUE w_hash_slice(const int argc, const VALUE *argv, const VALUE self) {
844
843
  UsaminValue *value = get_value(self);
845
844
  check_object(value);
846
845
  VALUE hash = rb_hash_new();
847
846
  for (int i = 0; i < argc; i++)
848
847
  for (auto &m : value->value->GetObject())
849
848
  if (str_compare_xx(argv[i], m.name))
850
- rb_hash_aset(hash, eval_str(m.name), eval(m.value));
849
+ rb_hash_aset(hash, eval_str(m.name), eval(m.value, self));
851
850
  return hash;
852
851
  }
853
852
 
@@ -859,7 +858,7 @@ static VALUE w_hash_slice(const int argc, VALUE* argv, const VALUE self) {
859
858
  static VALUE w_hash_eval(const VALUE self) {
860
859
  UsaminValue *value = get_value(self);
861
860
  check_object(value);
862
- return eval_object(*(value->value));
861
+ return eval_object(*(value->value), self);
863
862
  }
864
863
 
865
864
  /*
@@ -870,7 +869,7 @@ static VALUE w_hash_to_a(const VALUE self) {
870
869
  check_object(value);
871
870
  VALUE ret = rb_ary_new2(value->value->MemberCount());
872
871
  for (auto &m : value->value->GetObject())
873
- rb_ary_push(ret, rb_assoc_new(eval_str(m.name), eval(m.value)));
872
+ rb_ary_push(ret, rb_assoc_new(eval_str(m.name), eval(m.value, self)));
874
873
  return ret;
875
874
  }
876
875
 
@@ -882,7 +881,7 @@ static VALUE w_hash_values(const VALUE self) {
882
881
  check_object(value);
883
882
  VALUE ret = rb_ary_new2(value->value->MemberCount());
884
883
  for (auto &m : value->value->GetObject())
885
- rb_ary_push(ret, eval(m.value));
884
+ rb_ary_push(ret, eval(m.value, self));
886
885
  return ret;
887
886
  }
888
887
 
@@ -897,7 +896,7 @@ static VALUE w_hash_transform_keys(const VALUE self) {
897
896
  RETURN_SIZED_ENUMERATOR(self, 0, nullptr, hash_enum_size);
898
897
  VALUE hash = rb_hash_new();
899
898
  for (auto &m : value->value->GetObject())
900
- rb_hash_aset(hash, rb_yield(eval_str(m.name)), eval(m.value));
899
+ rb_hash_aset(hash, rb_yield(eval_str(m.name)), eval(m.value, self));
901
900
  return hash;
902
901
  }
903
902
 
@@ -912,7 +911,7 @@ static VALUE w_hash_transform_values(const VALUE self) {
912
911
  RETURN_SIZED_ENUMERATOR(self, 0, nullptr, hash_enum_size);
913
912
  VALUE hash = rb_hash_new();
914
913
  for (auto &m : value->value->GetObject())
915
- rb_hash_aset(hash, eval_str(m.name), rb_yield(eval(m.value)));
914
+ rb_hash_aset(hash, eval_str(m.name), rb_yield(eval(m.value, self)));
916
915
  return hash;
917
916
  }
918
917
 
@@ -920,7 +919,7 @@ static VALUE w_hash_transform_values(const VALUE self) {
920
919
  * @param [String] keys
921
920
  * @return [::Array<Object>]
922
921
  */
923
- static VALUE w_hash_values_at(const int argc, VALUE *argv, const VALUE self) {
922
+ static VALUE w_hash_values_at(const int argc, const VALUE *argv, const VALUE self) {
924
923
  UsaminValue *value = get_value(self);
925
924
  check_object(value);
926
925
  VALUE ret = rb_ary_new2(argc);
@@ -928,7 +927,7 @@ static VALUE w_hash_values_at(const int argc, VALUE *argv, const VALUE self) {
928
927
  VALUE data = Qnil;
929
928
  for (auto &m : value->value->GetObject()) {
930
929
  if (str_compare_xx(argv[i], m.name)) {
931
- data = eval(m.value);
930
+ data = eval(m.value, self);
932
931
  break;
933
932
  }
934
933
  }
@@ -951,7 +950,7 @@ static VALUE w_hash_values_at(const int argc, VALUE *argv, const VALUE self) {
951
950
  * @param [Range] range
952
951
  * @return [::Array<Object> | nil]
953
952
  */
954
- static VALUE w_array_operator_indexer(const int argc, VALUE* argv, const VALUE self) {
953
+ static VALUE w_array_operator_indexer(const int argc, const VALUE *argv, const VALUE self) {
955
954
  rb_check_arity(argc, 1, 2);
956
955
  UsaminValue *value = get_value(self);
957
956
  check_array(value);
@@ -967,7 +966,7 @@ static VALUE w_array_operator_indexer(const int argc, VALUE* argv, const VALUE s
967
966
  end = sz;
968
967
  VALUE ret = rb_ary_new2(end - beg);
969
968
  for (rapidjson::SizeType i = static_cast<rapidjson::SizeType>(beg); i < end; i++)
970
- rb_ary_push(ret, eval((*value->value)[i]));
969
+ rb_ary_push(ret, eval((*value->value)[i], self));
971
970
  return ret;
972
971
  }
973
972
  } else if (rb_obj_is_kind_of(argv[0], rb_cRange)) {
@@ -975,7 +974,7 @@ static VALUE w_array_operator_indexer(const int argc, VALUE* argv, const VALUE s
975
974
  if (rb_range_beg_len(argv[0], &beg, &len, sz, 0) == Qtrue) {
976
975
  VALUE ret = rb_ary_new2(len);
977
976
  for (rapidjson::SizeType i = static_cast<rapidjson::SizeType>(beg); i < beg + len; i++)
978
- rb_ary_push(ret, eval((*value->value)[i]));
977
+ rb_ary_push(ret, eval((*value->value)[i], self));
979
978
  return ret;
980
979
  }
981
980
  } else {
@@ -983,7 +982,7 @@ static VALUE w_array_operator_indexer(const int argc, VALUE* argv, const VALUE s
983
982
  if (l < 0)
984
983
  l += sz;
985
984
  if (0 <= l && l < sz)
986
- return eval((*value->value)[static_cast<rapidjson::SizeType>(l)]);
985
+ return eval((*value->value)[static_cast<rapidjson::SizeType>(l)], self);
987
986
  }
988
987
  return Qnil;
989
988
  }
@@ -992,7 +991,7 @@ static VALUE w_array_operator_indexer(const int argc, VALUE* argv, const VALUE s
992
991
  * @param [Integer] nth
993
992
  * @return [Object]
994
993
  */
995
- static VALUE w_array_at(const VALUE self, VALUE nth) {
994
+ static VALUE w_array_at(const VALUE self, const VALUE nth) {
996
995
  UsaminValue *value = get_value(self);
997
996
  check_array(value);
998
997
  long l = FIX2LONG(nth);
@@ -1000,24 +999,24 @@ static VALUE w_array_at(const VALUE self, VALUE nth) {
1000
999
  if (l < 0)
1001
1000
  l += sz;
1002
1001
  if (0 <= l && l < sz)
1003
- return eval((*value->value)[static_cast<rapidjson::SizeType>(l)]);
1002
+ return eval((*value->value)[static_cast<rapidjson::SizeType>(l)], self);
1004
1003
  return Qnil;
1005
1004
  }
1006
1005
 
1007
1006
  /*
1008
1007
  * @return [::Array]
1009
1008
  */
1010
- static VALUE w_array_compact(const VALUE self, VALUE nth) {
1009
+ static VALUE w_array_compact(const VALUE self, const VALUE nth) {
1011
1010
  UsaminValue *value = get_value(self);
1012
1011
  check_array(value);
1013
1012
  VALUE ret = rb_ary_new2(value->value->Size());
1014
1013
  for (auto &v : value->value->GetArray())
1015
1014
  if (!v.IsNull())
1016
- rb_ary_push(ret, eval(v));
1015
+ rb_ary_push(ret, eval(v, self));
1017
1016
  return ret;
1018
1017
  }
1019
1018
 
1020
- static VALUE array_enum_size(const VALUE self, VALUE args, VALUE eobj) {
1019
+ static VALUE array_enum_size(const VALUE self, const VALUE args, const VALUE eobj) {
1021
1020
  return UINT2NUM(get_value(self)->value->Size());
1022
1021
  }
1023
1022
 
@@ -1030,7 +1029,7 @@ static VALUE w_array_each(const VALUE self) {
1030
1029
  check_array(value);
1031
1030
  RETURN_SIZED_ENUMERATOR(self, 0, nullptr, array_enum_size);
1032
1031
  for (auto &v : value->value->GetArray())
1033
- rb_yield(eval(v));
1032
+ rb_yield(eval(v, self));
1034
1033
  return self;
1035
1034
  }
1036
1035
 
@@ -1070,7 +1069,7 @@ static VALUE w_array_isempty(const VALUE self) {
1070
1069
  * @yield [nth]
1071
1070
  * @return [Object]
1072
1071
  */
1073
- static VALUE w_array_fetch(const int argc, VALUE* argv, const VALUE self) {
1072
+ static VALUE w_array_fetch(const int argc, const VALUE *argv, const VALUE self) {
1074
1073
  rb_check_arity(argc, 1, 2);
1075
1074
  UsaminValue *value = get_value(self);
1076
1075
  check_array(value);
@@ -1080,7 +1079,7 @@ static VALUE w_array_fetch(const int argc, VALUE* argv, const VALUE self) {
1080
1079
  if (l < 0)
1081
1080
  l += sz;
1082
1081
  if (0 <= l && l < sz)
1083
- return eval((*value->value)[static_cast<rapidjson::SizeType>(l)]);
1082
+ return eval((*value->value)[static_cast<rapidjson::SizeType>(l)], self);
1084
1083
 
1085
1084
  if (argc == 2)
1086
1085
  return argv[1];
@@ -1101,7 +1100,7 @@ static VALUE w_array_fetch(const int argc, VALUE* argv, const VALUE self) {
1101
1100
  * @yieldparam item [Object]
1102
1101
  * @return [Integer | nil]
1103
1102
  */
1104
- static VALUE w_array_find_index(int argc, VALUE* argv, const VALUE self) {
1103
+ static VALUE w_array_find_index(const int argc, const VALUE *argv, const VALUE self) {
1105
1104
  rb_check_arity(argc, 0, 1);
1106
1105
  UsaminValue *value = get_value(self);
1107
1106
  check_array(value);
@@ -1116,7 +1115,7 @@ static VALUE w_array_find_index(int argc, VALUE* argv, const VALUE self) {
1116
1115
 
1117
1116
  RETURN_SIZED_ENUMERATOR(self, 0, nullptr, array_enum_size);
1118
1117
  for (rapidjson::SizeType i = 0; i < value->value->Size(); i++) {
1119
- if (RTEST(rb_yield(eval((*value->value)[i]))))
1118
+ if (RTEST(rb_yield(eval((*value->value)[i], self))))
1120
1119
  return UINT2NUM(i);
1121
1120
  }
1122
1121
  return Qnil;
@@ -1132,7 +1131,7 @@ static VALUE w_array_find_index(int argc, VALUE* argv, const VALUE self) {
1132
1131
  * @yieldparam item [Object]
1133
1132
  * @return [Integer | nil]
1134
1133
  */
1135
- static VALUE w_array_index(int argc, VALUE* argv, const VALUE self) {
1134
+ static VALUE w_array_index(const int argc, const VALUE *argv, const VALUE self) {
1136
1135
  return w_array_find_index(argc, argv, self);
1137
1136
  }
1138
1137
 
@@ -1143,7 +1142,7 @@ static VALUE w_array_index(int argc, VALUE* argv, const VALUE self) {
1143
1142
  * @overload first(n)
1144
1143
  * @return [::Array<Object>]
1145
1144
  */
1146
- static VALUE w_array_first(const int argc, VALUE* argv, const VALUE self) {
1145
+ static VALUE w_array_first(const int argc, const VALUE *argv, const VALUE self) {
1147
1146
  rb_check_arity(argc, 0, 1);
1148
1147
  UsaminValue *value = get_value(self);
1149
1148
  check_array(value);
@@ -1152,14 +1151,14 @@ static VALUE w_array_first(const int argc, VALUE* argv, const VALUE self) {
1152
1151
  if (argc == 0) {
1153
1152
  if (sz == 0)
1154
1153
  return Qnil;
1155
- return eval(*value->value->Begin());
1154
+ return eval(*value->value->Begin(), self);
1156
1155
  } else {
1157
1156
  long l = FIX2LONG(argv[0]);
1158
1157
  if (l > sz)
1159
1158
  l = sz;
1160
1159
  VALUE ret = rb_ary_new2(l);
1161
1160
  for (auto v = value->value->Begin(); v < value->value->Begin() + l; v++)
1162
- rb_ary_push(ret, eval(*v));
1161
+ rb_ary_push(ret, eval(*v, self));
1163
1162
  return ret;
1164
1163
  }
1165
1164
  }
@@ -1167,7 +1166,7 @@ static VALUE w_array_first(const int argc, VALUE* argv, const VALUE self) {
1167
1166
  /*
1168
1167
  * @return [Boolean]
1169
1168
  */
1170
- static VALUE w_array_include(const VALUE self, VALUE val) {
1169
+ static VALUE w_array_include(const VALUE self, const VALUE val) {
1171
1170
  UsaminValue *value = get_value(self);
1172
1171
  check_array(value);
1173
1172
  for (auto &v : value->value->GetArray())
@@ -1183,21 +1182,21 @@ static VALUE w_array_include(const VALUE self, VALUE val) {
1183
1182
  * @overload last(n)
1184
1183
  * @return [::Array<Object>]
1185
1184
  */
1186
- static VALUE w_array_last(const int argc, VALUE* argv, const VALUE self) {
1185
+ static VALUE w_array_last(const int argc, const VALUE *argv, const VALUE self) {
1187
1186
  rb_check_arity(argc, 0, 1);
1188
1187
  UsaminValue *value = get_value(self);
1189
1188
  check_array(value);
1190
1189
  rapidjson::SizeType sz = value->value->Size();
1191
1190
 
1192
1191
  if (argc == 0) {
1193
- return sz > 0 ? eval(*(value->value->End() - 1)) : Qnil;
1192
+ return sz > 0 ? eval(*(value->value->End() - 1), self) : Qnil;
1194
1193
  } else {
1195
1194
  long l = FIX2LONG(argv[0]);
1196
1195
  if (l > sz)
1197
1196
  l = sz;
1198
1197
  VALUE ret = rb_ary_new2(l);
1199
1198
  for (auto v = value->value->End() - l; v < value->value->End(); v++)
1200
- rb_ary_push(ret, eval(*v));
1199
+ rb_ary_push(ret, eval(*v, self));
1201
1200
  return ret;
1202
1201
  }
1203
1202
  }
@@ -1225,7 +1224,7 @@ static VALUE w_array_length(const VALUE self) {
1225
1224
  * @param [Range] range
1226
1225
  * @return [::Array<Object> | nil]
1227
1226
  */
1228
- static VALUE w_array_slice(const int argc, VALUE* argv, const VALUE self) {
1227
+ static VALUE w_array_slice(const int argc, const VALUE *argv, const VALUE self) {
1229
1228
  return w_array_operator_indexer(argc, argv, self);
1230
1229
  }
1231
1230
 
@@ -1237,7 +1236,7 @@ static VALUE w_array_slice(const int argc, VALUE* argv, const VALUE self) {
1237
1236
  static VALUE w_array_eval(const VALUE self) {
1238
1237
  UsaminValue *value = get_value(self);
1239
1238
  check_array(value);
1240
- return eval_array(*(value->value));
1239
+ return eval_array(*(value->value), self);
1241
1240
  }
1242
1241
 
1243
1242
 
@@ -1248,7 +1247,7 @@ static VALUE w_array_eval(const VALUE self) {
1248
1247
  * @param [Object] obj an object to serialize
1249
1248
  * @return [String]
1250
1249
  */
1251
- static VALUE w_generate(const VALUE self, VALUE value) {
1250
+ static VALUE w_generate(const VALUE self, const VALUE value) {
1252
1251
  rapidjson::StringBuffer buf;
1253
1252
  rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
1254
1253
  write(writer, value);
@@ -1265,7 +1264,7 @@ static VALUE w_generate(const VALUE self, VALUE value) {
1265
1264
  * @option opts [Boolean] :single_line_array (false)
1266
1265
  * @return [String]
1267
1266
  */
1268
- static VALUE w_pretty_generate(const int argc, VALUE *argv, const VALUE self) {
1267
+ static VALUE w_pretty_generate(const int argc, const VALUE *argv, const VALUE self) {
1269
1268
  VALUE value, options;
1270
1269
  rb_scan_args(argc, argv, "1:", &value, &options);
1271
1270
  rapidjson::StringBuffer buf;
@@ -1,3 +1,3 @@
1
1
  module Usamin
2
- VERSION = "7.7.5"
2
+ VERSION = "7.7.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usamin
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.7.5
4
+ version: 7.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ishotihadus
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-04 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler