google-protobuf 4.26.0.rc.2-x86_64-darwin → 4.26.0.rc.3-x86_64-darwin

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of google-protobuf might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2021663449eecc8a05d8dad179c114152d41e93cbc0baca77090104e97944e5a
4
- data.tar.gz: 5d75f3b5573e6553c2118add7fbb7dbcb7a1722d9756edcc17e284f722920002
3
+ metadata.gz: 50d451f0eb1d48217682216253a36019e118a06b3474ce48570600aabd7a55fd
4
+ data.tar.gz: 28aa8e5bb6c2f02c9608c54774f38172c722cd98ee0dd5922ae562aea802e8cb
5
5
  SHA512:
6
- metadata.gz: 463a3ac1d5b4d487d06ecce252b66b7d379f47856eb2a703a27ab6ea7c671afe844e3556eb2c8f560d081e819f3aea51d59f171111495649e7d3eaa9baa1939d
7
- data.tar.gz: 3f3f348adc4d2f6bebca2b860994040349bc463d593e8e8ac80aeff1bece6188909595d4268d8ec7db8e502c4199b94e81dfb73b26073a56de06d241cb09e8f9
6
+ metadata.gz: 0d05171789592bb16d9ebd9582292db620dd2604509e5e11ef81e7eaf0b803d88ac856e953829c18dd0f0a4d00954b1510622774fd48fa31aac37f524624266d
7
+ data.tar.gz: a3faf392f0141c6ed59f862d58e476a5a54f9687478beea65a68e0cdccd9e85a9b7fd6c31bc5f103f6cc9f1b30506b078d26dc6613f31562832141d141804ce9
@@ -38,9 +38,11 @@ static void Map_mark(void* _self) {
38
38
  rb_gc_mark(self->arena);
39
39
  }
40
40
 
41
+ static size_t Map_memsize(const void* _self) { return sizeof(Map); }
42
+
41
43
  const rb_data_type_t Map_type = {
42
44
  "Google::Protobuf::Map",
43
- {Map_mark, RUBY_DEFAULT_FREE, NULL},
45
+ {Map_mark, RUBY_DEFAULT_FREE, Map_memsize},
44
46
  .flags = RUBY_TYPED_FREE_IMMEDIATELY,
45
47
  };
46
48
 
@@ -44,9 +44,11 @@ static void Message_mark(void* _self) {
44
44
  rb_gc_mark(self->arena);
45
45
  }
46
46
 
47
+ static size_t Message_memsize(const void* _self) { return sizeof(Message); }
48
+
47
49
  static rb_data_type_t Message_type = {
48
50
  "Google::Protobuf::Message",
49
- {Message_mark, RUBY_DEFAULT_FREE, NULL},
51
+ {Message_mark, RUBY_DEFAULT_FREE, Message_memsize},
50
52
  .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
51
53
  };
52
54
 
@@ -164,11 +164,23 @@ static void Arena_free(void *data) {
164
164
  xfree(arena);
165
165
  }
166
166
 
167
+ static size_t Arena_memsize(const void *data) {
168
+ const Arena *arena = data;
169
+ size_t fused_count;
170
+ size_t memsize = upb_Arena_SpaceAllocated(arena->arena, &fused_count);
171
+ if (fused_count > 1) {
172
+ // If other arena were fused we attribute an equal
173
+ // share of memory usage to each one.
174
+ memsize /= fused_count;
175
+ }
176
+ return memsize + sizeof(Arena);
177
+ }
178
+
167
179
  static VALUE cArena;
168
180
 
169
181
  const rb_data_type_t Arena_type = {
170
182
  "Google::Protobuf::Internal::Arena",
171
- {Arena_mark, Arena_free, NULL},
183
+ {Arena_mark, Arena_free, Arena_memsize},
172
184
  .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
173
185
  };
174
186
 
@@ -241,16 +253,17 @@ static void ObjectCache_Init(VALUE protobuf) {
241
253
  item_try_add = rb_intern("try_add");
242
254
 
243
255
  rb_gc_register_address(&weak_obj_cache);
256
+ VALUE internal = rb_const_get(protobuf, rb_intern("Internal"));
244
257
  #if SIZEOF_LONG >= SIZEOF_VALUE
245
- VALUE cache_class = rb_const_get(protobuf, rb_intern("ObjectCache"));
258
+ VALUE cache_class = rb_const_get(internal, rb_intern("ObjectCache"));
246
259
  #else
247
- VALUE cache_class = rb_const_get(protobuf, rb_intern("LegacyObjectCache"));
260
+ VALUE cache_class = rb_const_get(internal, rb_intern("LegacyObjectCache"));
248
261
  #endif
249
262
 
250
263
  weak_obj_cache = rb_class_new_instance(0, NULL, cache_class);
251
- rb_const_set(protobuf, rb_intern("OBJECT_CACHE"), weak_obj_cache);
252
- rb_const_set(protobuf, rb_intern("SIZEOF_LONG"), INT2NUM(SIZEOF_LONG));
253
- rb_const_set(protobuf, rb_intern("SIZEOF_VALUE"), INT2NUM(SIZEOF_VALUE));
264
+ rb_const_set(internal, rb_intern("OBJECT_CACHE"), weak_obj_cache);
265
+ rb_const_set(internal, rb_intern("SIZEOF_LONG"), INT2NUM(SIZEOF_LONG));
266
+ rb_const_set(internal, rb_intern("SIZEOF_VALUE"), INT2NUM(SIZEOF_VALUE));
254
267
  }
255
268
 
256
269
  static VALUE ObjectCache_GetKey(const void *key) {
@@ -4085,9 +4085,10 @@ static upb_ArenaRoot _upb_Arena_FindRoot(upb_Arena* a) {
4085
4085
  return (upb_ArenaRoot){.root = ai, .tagged_count = poc};
4086
4086
  }
4087
4087
 
4088
- size_t upb_Arena_SpaceAllocated(upb_Arena* arena) {
4088
+ size_t upb_Arena_SpaceAllocated(upb_Arena* arena, size_t* fused_count) {
4089
4089
  upb_ArenaInternal* ai = _upb_Arena_FindRoot(arena).root;
4090
4090
  size_t memsize = 0;
4091
+ size_t local_fused_count = 0;
4091
4092
 
4092
4093
  while (ai != NULL) {
4093
4094
  upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_relaxed);
@@ -4096,8 +4097,10 @@ size_t upb_Arena_SpaceAllocated(upb_Arena* arena) {
4096
4097
  block = upb_Atomic_Load(&block->next, memory_order_relaxed);
4097
4098
  }
4098
4099
  ai = upb_Atomic_Load(&ai->next, memory_order_relaxed);
4100
+ local_fused_count++;
4099
4101
  }
4100
4102
 
4103
+ if (fused_count) *fused_count = local_fused_count;
4101
4104
  return memsize;
4102
4105
  }
4103
4106
 
@@ -349,7 +349,7 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
349
349
 
350
350
  // Must be last.
351
351
 
352
- #define _kUpb_Status_MaxMessage 127
352
+ #define _kUpb_Status_MaxMessage 511
353
353
 
354
354
  typedef struct {
355
355
  bool ok;
@@ -780,7 +780,7 @@ UPB_API bool upb_Arena_Fuse(upb_Arena* a, upb_Arena* b);
780
780
  bool upb_Arena_IncRefFor(upb_Arena* a, const void* owner);
781
781
  void upb_Arena_DecRefFor(upb_Arena* a, const void* owner);
782
782
 
783
- size_t upb_Arena_SpaceAllocated(upb_Arena* a);
783
+ size_t upb_Arena_SpaceAllocated(upb_Arena* a, size_t* fused_count);
784
784
  uint32_t upb_Arena_DebugRefCount(upb_Arena* a);
785
785
 
786
786
  UPB_API_INLINE upb_Arena* upb_Arena_New(void) {
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -18,13 +18,13 @@ module Google
18
18
 
19
19
  def self.cache_implementation
20
20
  if interpreter_supports_non_finalized_keys_in_weak_map? and SIZEOF_LONG >= SIZEOF_VALUE
21
- Google::Protobuf::ObjectCache
21
+ Google::Protobuf::Internal::ObjectCache
22
22
  else
23
- Google::Protobuf::LegacyObjectCache
23
+ Google::Protobuf::Internal::LegacyObjectCache
24
24
  end
25
25
  end
26
26
 
27
27
  public
28
28
  OBJECT_CACHE = cache_implementation.new
29
29
  end
30
- end
30
+ end
@@ -0,0 +1,99 @@
1
+ # Protocol Buffers - Google's data interchange format
2
+ # Copyright 2023 Google Inc. All rights reserved.
3
+ #
4
+ # Use of this source code is governed by a BSD-style
5
+ # license that can be found in the LICENSE file or at
6
+ # https://developers.google.com/open-source/licenses/bsd
7
+
8
+ module Google
9
+ module Protobuf
10
+ module Internal
11
+ # A pointer -> Ruby Object cache that keeps references to Ruby wrapper
12
+ # objects. This allows us to look up any Ruby wrapper object by the address
13
+ # of the object it is wrapping. That way we can avoid ever creating two
14
+ # different wrapper objects for the same C object, which saves memory and
15
+ # preserves object identity.
16
+ #
17
+ # We use WeakMap for the cache. If sizeof(long) > sizeof(VALUE), we also
18
+ # need a secondary Hash to store WeakMap keys, because our pointer keys may
19
+ # need to be stored as Bignum instead of Fixnum. Since WeakMap is weak for
20
+ # both keys and values, a Bignum key will cause the WeakMap entry to be
21
+ # collected immediately unless there is another reference to the Bignum.
22
+ # This happens on 64-bit Windows, on which pointers are 64 bits but longs
23
+ # are 32 bits. In this case, we enable the secondary Hash to hold the keys
24
+ # and prevent them from being collected.
25
+ class ObjectCache
26
+ def initialize
27
+ @map = ObjectSpace::WeakMap.new
28
+ @mutex = Mutex.new
29
+ end
30
+
31
+ def get(key)
32
+ @map[key]
33
+ end
34
+
35
+ def try_add(key, value)
36
+ @map[key] || @mutex.synchronize do
37
+ @map[key] ||= value
38
+ end
39
+ end
40
+ end
41
+
42
+ class LegacyObjectCache
43
+ def initialize
44
+ @secondary_map = {}
45
+ @map = ObjectSpace::WeakMap.new
46
+ @mutex = Mutex.new
47
+ end
48
+
49
+ def get(key)
50
+ value = if secondary_key = @secondary_map[key]
51
+ @map[secondary_key]
52
+ else
53
+ @mutex.synchronize do
54
+ @map[(@secondary_map[key] ||= Object.new)]
55
+ end
56
+ end
57
+
58
+ # GC if we could remove at least 2000 entries or 20% of the table size
59
+ # (whichever is greater). Since the cost of the GC pass is O(N), we
60
+ # want to make sure that we condition this on overall table size, to
61
+ # avoid O(N^2) CPU costs.
62
+ cutoff = (@secondary_map.size * 0.2).ceil
63
+ cutoff = 2_000 if cutoff < 2_000
64
+ if (@secondary_map.size - @map.size) > cutoff
65
+ purge
66
+ end
67
+
68
+ value
69
+ end
70
+
71
+ def try_add(key, value)
72
+ if secondary_key = @secondary_map[key]
73
+ if old_value = @map[secondary_key]
74
+ return old_value
75
+ end
76
+ end
77
+
78
+ @mutex.synchronize do
79
+ secondary_key ||= (@secondary_map[key] ||= Object.new)
80
+ @map[secondary_key] ||= value
81
+ end
82
+ end
83
+
84
+ private
85
+
86
+ def purge
87
+ @mutex.synchronize do
88
+ @secondary_map.each do |key, secondary_key|
89
+ unless @map.key?(secondary_key)
90
+ @secondary_map.delete(key)
91
+ end
92
+ end
93
+ end
94
+ nil
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -7,7 +7,7 @@
7
7
 
8
8
  # require mixins before we hook them into the java & c code
9
9
  require 'google/protobuf/message_exts'
10
- require 'google/protobuf/object_cache'
10
+ require 'google/protobuf/internal/object_cache'
11
11
 
12
12
  # We define these before requiring the platform-specific modules.
13
13
  # That way the module init can grab references to these.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.26.0.rc.2
4
+ version: 4.26.0.rc.3
5
5
  platform: x86_64-darwin
6
6
  authors:
7
7
  - Protobuf Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-06 00:00:00.000000000 Z
11
+ date: 2024-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler-dock
@@ -158,8 +158,8 @@ files:
158
158
  - lib/google/protobuf/ffi/oneof_descriptor.rb
159
159
  - lib/google/protobuf/ffi/repeated_field.rb
160
160
  - lib/google/protobuf/field_mask_pb.rb
161
+ - lib/google/protobuf/internal/object_cache.rb
161
162
  - lib/google/protobuf/message_exts.rb
162
- - lib/google/protobuf/object_cache.rb
163
163
  - lib/google/protobuf/plugin_pb.rb
164
164
  - lib/google/protobuf/repeated_field.rb
165
165
  - lib/google/protobuf/source_context_pb.rb
@@ -175,7 +175,7 @@ homepage: https://developers.google.com/protocol-buffers
175
175
  licenses:
176
176
  - BSD-3-Clause
177
177
  metadata:
178
- source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v4.26.0-rc2/ruby
178
+ source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v4.26.0-rc3/ruby
179
179
  post_install_message:
180
180
  rdoc_options: []
181
181
  require_paths:
@@ -1,97 +0,0 @@
1
- # Protocol Buffers - Google's data interchange format
2
- # Copyright 2023 Google Inc. All rights reserved.
3
- #
4
- # Use of this source code is governed by a BSD-style
5
- # license that can be found in the LICENSE file or at
6
- # https://developers.google.com/open-source/licenses/bsd
7
-
8
- module Google
9
- module Protobuf
10
- # A pointer -> Ruby Object cache that keeps references to Ruby wrapper
11
- # objects. This allows us to look up any Ruby wrapper object by the address
12
- # of the object it is wrapping. That way we can avoid ever creating two
13
- # different wrapper objects for the same C object, which saves memory and
14
- # preserves object identity.
15
- #
16
- # We use WeakMap for the cache. If sizeof(long) > sizeof(VALUE), we also
17
- # need a secondary Hash to store WeakMap keys, because our pointer keys may
18
- # need to be stored as Bignum instead of Fixnum. Since WeakMap is weak for
19
- # both keys and values, a Bignum key will cause the WeakMap entry to be
20
- # collected immediately unless there is another reference to the Bignum.
21
- # This happens on 64-bit Windows, on which pointers are 64 bits but longs
22
- # are 32 bits. In this case, we enable the secondary Hash to hold the keys
23
- # and prevent them from being collected.
24
- class ObjectCache
25
- def initialize
26
- @map = ObjectSpace::WeakMap.new
27
- @mutex = Mutex.new
28
- end
29
-
30
- def get(key)
31
- @map[key]
32
- end
33
-
34
- def try_add(key, value)
35
- @map[key] || @mutex.synchronize do
36
- @map[key] ||= value
37
- end
38
- end
39
- end
40
-
41
- class LegacyObjectCache
42
- def initialize
43
- @secondary_map = {}
44
- @map = ObjectSpace::WeakMap.new
45
- @mutex = Mutex.new
46
- end
47
-
48
- def get(key)
49
- value = if secondary_key = @secondary_map[key]
50
- @map[secondary_key]
51
- else
52
- @mutex.synchronize do
53
- @map[(@secondary_map[key] ||= Object.new)]
54
- end
55
- end
56
-
57
- # GC if we could remove at least 2000 entries or 20% of the table size
58
- # (whichever is greater). Since the cost of the GC pass is O(N), we
59
- # want to make sure that we condition this on overall table size, to
60
- # avoid O(N^2) CPU costs.
61
- cutoff = (@secondary_map.size * 0.2).ceil
62
- cutoff = 2_000 if cutoff < 2_000
63
- if (@secondary_map.size - @map.size) > cutoff
64
- purge
65
- end
66
-
67
- value
68
- end
69
-
70
- def try_add(key, value)
71
- if secondary_key = @secondary_map[key]
72
- if old_value = @map[secondary_key]
73
- return old_value
74
- end
75
- end
76
-
77
- @mutex.synchronize do
78
- secondary_key ||= (@secondary_map[key] ||= Object.new)
79
- @map[secondary_key] ||= value
80
- end
81
- end
82
-
83
- private
84
-
85
- def purge
86
- @mutex.synchronize do
87
- @secondary_map.each do |key, secondary_key|
88
- unless @map.key?(secondary_key)
89
- @secondary_map.delete(key)
90
- end
91
- end
92
- end
93
- nil
94
- end
95
- end
96
- end
97
- end