google-protobuf 4.26.0.rc.2-x86-mingw32 → 4.26.0.rc.3-x86-mingw32

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.

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: b1ede334b872f46210f4ab81fa3fc33d7ea61fecda766f602ff8f313ce70590f
4
- data.tar.gz: eb39743f2d7236cd9b9b2d33351e863d0a4fe349cc50064ca8d2c5a65983dd7d
3
+ metadata.gz: 383c372528e9d7d72ca28ae52113f840ddf66b57d94f671fef2c8a5fe783458f
4
+ data.tar.gz: 647f0dba3144db0410ca85088e3e7aa5719330d7f6d8659ab8154f83acf84c8c
5
5
  SHA512:
6
- metadata.gz: 484d44c6d9295a2f29ebe2ae3be06cbc996525fdf62798c4bd44625b2296c44ed32c9a7b8b3ff935f828bf3324a3867c3b5234997c74a0b429c07888c1ff707b
7
- data.tar.gz: cc291392d45d05acf0806b032dcda880bbc3f46a4e27802aa688407ba893ede52ae27b82a0045033765ebf6680b285695e55f82d40e8218cf5f66fe54a4364c7
6
+ metadata.gz: 03c88226e0a590c2f4b514cb2506b906ac1e84225dbefc66b0fc48cc669dc68f7900da92fbc8c6b34ebbae79f774937a810e06af4b319e4f36edd5a654b4dee9
7
+ data.tar.gz: 6f7d58103f9b700665370a127a386117e9b3ed762094bfd32019f648f6866ddad82b872ffec1f0bd5a1853481bfa5032d026ff5ab70f1d6eee169b652a4be1d5
@@ -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-mingw32
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