google-protobuf 3.22.0 → 3.24.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -87,7 +87,6 @@ VALUE RepeatedField_GetRubyWrapper(upb_Array* array, TypeInfo type_info,
87
87
  if (val == Qnil) {
88
88
  val = RepeatedField_alloc(cRepeatedField);
89
89
  RepeatedField* self;
90
- ObjectCache_Add(array, val);
91
90
  TypedData_Get_Struct(val, RepeatedField, &RepeatedField_type, self);
92
91
  self->array = array;
93
92
  self->arena = arena;
@@ -95,11 +94,14 @@ VALUE RepeatedField_GetRubyWrapper(upb_Array* array, TypeInfo type_info,
95
94
  if (self->type_info.type == kUpb_CType_Message) {
96
95
  self->type_class = Descriptor_DefToClass(type_info.def.msgdef);
97
96
  }
97
+ val = ObjectCache_TryAdd(array, val);
98
98
  }
99
99
 
100
100
  PBRUBY_ASSERT(ruby_to_RepeatedField(val)->type_info.type == type_info.type);
101
101
  PBRUBY_ASSERT(ruby_to_RepeatedField(val)->type_info.def.msgdef ==
102
102
  type_info.def.msgdef);
103
+ PBRUBY_ASSERT(ruby_to_RepeatedField(val)->array == array);
104
+
103
105
  return val;
104
106
  }
105
107
 
@@ -613,7 +615,8 @@ VALUE RepeatedField_init(int argc, VALUE* argv, VALUE _self) {
613
615
 
614
616
  self->type_info = TypeInfo_FromClass(argc, argv, 0, &self->type_class, &ary);
615
617
  self->array = upb_Array_New(arena, self->type_info.type);
616
- ObjectCache_Add(self->array, _self);
618
+ VALUE stored_val = ObjectCache_TryAdd(self->array, _self);
619
+ PBRUBY_ASSERT(stored_val == _self);
617
620
 
618
621
  if (ary != Qnil) {
619
622
  if (!RB_TYPE_P(ary, T_ARRAY)) {
@@ -31,8 +31,6 @@
31
31
  #ifndef RUBY_PROTOBUF_REPEATED_FIELD_H_
32
32
  #define RUBY_PROTOBUF_REPEATED_FIELD_H_
33
33
 
34
- #include <ruby/ruby.h>
35
-
36
34
  #include "protobuf.h"
37
35
  #include "ruby-upb.h"
38
36