Skip to content

Commit c934386

Browse files
authored
Merge pull request #8447 from acozzette/merge-3-15-x
Merge 3.15.x into the master branch
2 parents 6007999 + 87aa9ad commit c934386

36 files changed

+145
-48
lines changed

CHANGES.txt

+9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
4040
JavaScript
4141
* Make Any.pack() chainable.
4242

43+
2021-04-02 version 3.15.7 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
44+
45+
C++
46+
* Remove the ::pb namespace (alias) (#8423)
47+
48+
Ruby
49+
* Fix unbounded memory growth for Ruby <2.7 (#8429)
50+
* Fixed message equality in cases where the message type is different (#8434)
51+
4352
2021-03-10 version 3.15.6 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
4453

4554
Ruby

Protobuf-C++.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Protobuf-C++'
3-
s.version = '3.15.6'
3+
s.version = '3.15.7'
44
s.summary = 'Protocol Buffers v3 runtime library for C++.'
55
s.homepage = 'https://github.com/google/protobuf'
66
s.license = '3-Clause BSD License'

Protobuf.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# dependent projects use the :git notation to refer to the library.
66
Pod::Spec.new do |s|
77
s.name = 'Protobuf'
8-
s.version = '3.15.6'
8+
s.version = '3.15.7'
99
s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.'
1010
s.homepage = 'https://github.com/protocolbuffers/protobuf'
1111
s.license = '3-Clause BSD License'

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ AC_PREREQ(2.59)
1717
# In the SVN trunk, the version should always be the next anticipated release
1818
# version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed
1919
# the size of one file name in the dist tarfile over the 99-char limit.)
20-
AC_INIT([Protocol Buffers],[3.15.6],[[email protected]],[protobuf])
20+
AC_INIT([Protocol Buffers],[3.15.7],[[email protected]],[protobuf])
2121

2222
AM_MAINTAINER_MODE([enable])
2323

csharp/Google.Protobuf.Tools.nuspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>Google Protocol Buffers tools</title>
66
<summary>Tools for Protocol Buffers - Google's data interchange format.</summary>
77
<description>See project site for more info.</description>
8-
<version>3.15.6</version>
8+
<version>3.15.7</version>
99
<authors>Google Inc.</authors>
1010
<owners>protobuf-packages</owners>
1111
<licenseUrl>https://github.com/protocolbuffers/protobuf/blob/master/LICENSE</licenseUrl>

csharp/src/Google.Protobuf/Google.Protobuf.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Description>C# runtime library for Protocol Buffers - Google's data interchange format.</Description>
55
<Copyright>Copyright 2015, Google Inc.</Copyright>
66
<AssemblyTitle>Google Protocol Buffers</AssemblyTitle>
7-
<VersionPrefix>3.15.6</VersionPrefix>
7+
<VersionPrefix>3.15.7</VersionPrefix>
88
<!-- C# 7.2 is required for Span/BufferWriter/ReadOnlySequence -->
99
<LangVersion>7.2</LangVersion>
1010
<Authors>Google Inc.</Authors>

java/bom/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.google.protobuf</groupId>
66
<artifactId>protobuf-bom</artifactId>
7-
<version>3.15.6</version>
7+
<version>3.15.7</version>
88
<packaging>pom</packaging>
99

1010
<name>Protocol Buffers [BOM]</name>

java/core/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.google.protobuf</groupId>
66
<artifactId>protobuf-parent</artifactId>
7-
<version>3.15.6</version>
7+
<version>3.15.7</version>
88
</parent>
99

1010
<artifactId>protobuf-java</artifactId>

java/lite/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.google.protobuf</groupId>
66
<artifactId>protobuf-parent</artifactId>
7-
<version>3.15.6</version>
7+
<version>3.15.7</version>
88
</parent>
99

1010
<artifactId>protobuf-javalite</artifactId>

java/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.google.protobuf</groupId>
66
<artifactId>protobuf-parent</artifactId>
7-
<version>3.15.6</version>
7+
<version>3.15.7</version>
88
<packaging>pom</packaging>
99

1010
<name>Protocol Buffers [Parent]</name>

java/util/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.google.protobuf</groupId>
66
<artifactId>protobuf-parent</artifactId>
7-
<version>3.15.6</version>
7+
<version>3.15.7</version>
88
</parent>
99

1010
<artifactId>protobuf-java-util</artifactId>

js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "google-protobuf",
3-
"version": "3.15.6",
3+
"version": "3.15.7",
44
"description": "Protocol Buffers for JavaScript",
55
"main": "google-protobuf.js",
66
"files": [

php/ext/google/protobuf/package.xml

+20-5
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
<email>[email protected]</email>
1111
<active>yes</active>
1212
</lead>
13-
<date>2021-03-10</date>
14-
<time>10:11:34</time>
13+
<date>2021-04-02</date>
14+
<time>10:01:42</time>
1515
<version>
16-
<release>3.15.6</release>
17-
<api>3.15.6</api>
16+
<release>3.15.7</release>
17+
<api>3.15.7</api>
1818
</version>
1919
<stability>
2020
<release>stable</release>
2121
<api>stable</api>
2222
</stability>
2323
<license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license>
2424
<notes>
25-
No new changes in 3.15.6
25+
No new changes in 3.15.7
2626
</notes>
2727
<contents>
2828
<dir baseinstalldir="/" name="/">
@@ -887,5 +887,20 @@ G A release.
887887
<notes>
888888
</notes>
889889
</release>
890+
<release>
891+
<version>
892+
<release>3.15.7</release>
893+
<api>3.15.7</api>
894+
</version>
895+
<stability>
896+
<release>stable</release>
897+
<api>stable</api>
898+
</stability>
899+
<date>2021-04-02</date>
900+
<time>10:01:42</time>
901+
<license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license>
902+
<notes>
903+
</notes>
904+
</release>
890905
</changelog>
891906
</package>

php/ext/google/protobuf/protobuf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1)
7676
ZEND_ARG_INFO(0, value)
7777
ZEND_END_ARG_INFO()
7878

79-
#define PHP_PROTOBUF_VERSION "3.15.6"
79+
#define PHP_PROTOBUF_VERSION "3.15.7"
8080

8181
// ptr -> PHP object cache. This is a weak map that caches lazily-created
8282
// wrapper objects around upb types:

protoc-artifacts/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</parent>
99
<groupId>com.google.protobuf</groupId>
1010
<artifactId>protoc</artifactId>
11-
<version>3.15.6</version>
11+
<version>3.15.7</version>
1212
<packaging>pom</packaging>
1313
<name>Protobuf Compiler</name>
1414
<description>

python/google/protobuf/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030

3131
# Copyright 2007 Google Inc. All Rights Reserved.
3232

33-
__version__ = '3.15.6'
33+
__version__ = '3.15.7'

ruby/ext/google/protobuf_c/message.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -697,16 +697,13 @@ bool Message_Equal(const upb_msg *m1, const upb_msg *m2, const upb_msgdef *m) {
697697
* field is of a primitive type).
698698
*/
699699
static VALUE Message_eq(VALUE _self, VALUE _other) {
700-
if (TYPE(_self) != TYPE(_other)) {
701-
return Qfalse;
702-
}
700+
if (CLASS_OF(_self) != CLASS_OF(_other)) return Qfalse;
703701

704702
Message* self = ruby_to_Message(_self);
705703
Message* other = ruby_to_Message(_other);
704+
assert(self->msgdef == other->msgdef);
706705

707-
return Message_Equal(self->msg, other->msg, self->msgdef)
708-
? Qtrue
709-
: Qfalse;
706+
return Message_Equal(self->msg, other->msg, self->msgdef) ? Qtrue : Qfalse;
710707
}
711708

712709
uint64_t Message_Hash(const upb_msg* msg, const upb_msgdef* m, uint64_t seed) {

ruby/ext/google/protobuf_c/protobuf.c

+79-6
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,80 @@ void Arena_register(VALUE module) {
251251
// The object is used only for its identity; it does not contain any data.
252252
VALUE secondary_map = Qnil;
253253

254+
// Mutations to the map are under a mutex, because SeconaryMap_MaybeGC()
255+
// iterates over the map which cannot happen in parallel with insertions, or
256+
// Ruby will throw:
257+
// can't add a new key into hash during iteration (RuntimeError)
258+
VALUE secondary_map_mutex = Qnil;
259+
260+
// Lambda that will GC entries from the secondary map that are no longer present
261+
// in the primary map.
262+
VALUE gc_secondary_map_lambda = Qnil;
263+
ID length;
264+
265+
extern VALUE weak_obj_cache;
266+
254267
static void SecondaryMap_Init() {
255268
rb_gc_register_address(&secondary_map);
269+
rb_gc_register_address(&gc_secondary_map_lambda);
270+
rb_gc_register_address(&secondary_map_mutex);
256271
secondary_map = rb_hash_new();
272+
gc_secondary_map_lambda = rb_eval_string(
273+
"->(secondary, weak) {\n"
274+
" secondary.delete_if { |k, v| !weak.key?(v) }\n"
275+
"}\n");
276+
secondary_map_mutex = rb_mutex_new();
277+
length = rb_intern("length");
257278
}
258279

259-
static VALUE SecondaryMap_Get(VALUE key) {
280+
// The secondary map is a regular Hash, and will never shrink on its own.
281+
// The main object cache is a WeakMap that will automatically remove entries
282+
// when the target object is no longer reachable, but unless we manually
283+
// remove the corresponding entries from the secondary map, it will grow
284+
// without bound.
285+
//
286+
// To avoid this unbounded growth we periodically remove entries from the
287+
// secondary map that are no longer present in the WeakMap. The logic of
288+
// how often to perform this GC is an artbirary tuning parameter that
289+
// represents a straightforward CPU/memory tradeoff.
290+
//
291+
// Requires: secondary_map_mutex is held.
292+
static void SecondaryMap_MaybeGC() {
293+
PBRUBY_ASSERT(rb_mutex_locked_p(secondary_map_mutex) == Qtrue);
294+
size_t weak_len = NUM2ULL(rb_funcall(weak_obj_cache, length, 0));
295+
size_t secondary_len = RHASH_SIZE(secondary_map);
296+
if (secondary_len < weak_len) {
297+
// Logically this case should not be possible: a valid entry cannot exist in
298+
// the weak table unless there is a corresponding entry in the secondary
299+
// table. It should *always* be the case that secondary_len >= weak_len.
300+
//
301+
// However ObjectSpace::WeakMap#length (and therefore weak_len) is
302+
// unreliable: it overreports its true length by including non-live objects.
303+
// However these non-live objects are not yielded in iteration, so we may
304+
// have previously deleted them from the secondary map in a previous
305+
// invocation of SecondaryMap_MaybeGC().
306+
//
307+
// In this case, we can't measure any waste, so we just return.
308+
return;
309+
}
310+
size_t waste = secondary_len - weak_len;
311+
// GC if we could remove at least 2000 entries or 20% of the table size
312+
// (whichever is greater). Since the cost of the GC pass is O(N), we
313+
// want to make sure that we condition this on overall table size, to
314+
// avoid O(N^2) CPU costs.
315+
size_t threshold = PBRUBY_MAX(secondary_len * 0.2, 2000);
316+
if (waste > threshold) {
317+
rb_funcall(gc_secondary_map_lambda, rb_intern("call"), 2,
318+
secondary_map, weak_obj_cache);
319+
}
320+
}
321+
322+
// Requires: secondary_map_mutex is held by this thread iff create == true.
323+
static VALUE SecondaryMap_Get(VALUE key, bool create) {
324+
PBRUBY_ASSERT(!create || rb_mutex_locked_p(secondary_map_mutex) == Qtrue);
260325
VALUE ret = rb_hash_lookup(secondary_map, key);
261-
if (ret == Qnil) {
326+
if (ret == Qnil && create) {
327+
SecondaryMap_MaybeGC();
262328
ret = rb_eval_string("Object.new");
263329
rb_hash_aset(secondary_map, key, ret);
264330
}
@@ -267,14 +333,15 @@ static VALUE SecondaryMap_Get(VALUE key) {
267333

268334
#endif
269335

270-
static VALUE ObjectCache_GetKey(const void* key) {
336+
// Requires: secondary_map_mutex is held by this thread iff create == true.
337+
static VALUE ObjectCache_GetKey(const void* key, bool create) {
271338
char buf[sizeof(key)];
272339
memcpy(&buf, &key, sizeof(key));
273340
intptr_t key_int = (intptr_t)key;
274341
PBRUBY_ASSERT((key_int & 3) == 0);
275342
VALUE ret = LL2NUM(key_int >> 2);
276343
#if USE_SECONDARY_MAP
277-
ret = SecondaryMap_Get(ret);
344+
ret = SecondaryMap_Get(ret, create);
278345
#endif
279346
return ret;
280347
}
@@ -298,14 +365,20 @@ static void ObjectCache_Init() {
298365

299366
void ObjectCache_Add(const void* key, VALUE val) {
300367
PBRUBY_ASSERT(ObjectCache_Get(key) == Qnil);
301-
VALUE key_rb = ObjectCache_GetKey(key);
368+
#if USE_SECONDARY_MAP
369+
rb_mutex_lock(secondary_map_mutex);
370+
#endif
371+
VALUE key_rb = ObjectCache_GetKey(key, true);
302372
rb_funcall(weak_obj_cache, item_set, 2, key_rb, val);
373+
#if USE_SECONDARY_MAP
374+
rb_mutex_unlock(secondary_map_mutex);
375+
#endif
303376
PBRUBY_ASSERT(ObjectCache_Get(key) == val);
304377
}
305378

306379
// Returns the cached object for this key, if any. Otherwise returns Qnil.
307380
VALUE ObjectCache_Get(const void* key) {
308-
VALUE key_rb = ObjectCache_GetKey(key);
381+
VALUE key_rb = ObjectCache_GetKey(key, false);
309382
return rb_funcall(weak_obj_cache, item_get, 1, key_rb);
310383
}
311384

ruby/ext/google/protobuf_c/protobuf.h

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ extern VALUE cTypeError;
106106
#define PBRUBY_ASSERT(expr) assert(expr)
107107
#endif
108108

109+
#define PBRUBY_MAX(x, y) (((x) > (y)) ? (x) : (y))
110+
109111
#define UPB_UNUSED(var) (void)var
110112

111113
#endif // __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__

ruby/google-protobuf.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = "google-protobuf"
3-
s.version = "3.15.6"
3+
s.version = "3.15.7"
44
git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag
55
s.licenses = ["BSD-3-Clause"]
66
s.summary = "Protocol Buffers"

ruby/tests/common_tests.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -699,12 +699,13 @@ def test_deep_copy
699699
assert m.repeated_msg[0].object_id != m2.repeated_msg[0].object_id
700700
end
701701

702-
def test_eq
702+
def test_message_eq
703703
m = proto_module::TestMessage.new(:optional_int32 => 42,
704704
:repeated_int32 => [1, 2, 3])
705705
m2 = proto_module::TestMessage.new(:optional_int32 => 43,
706706
:repeated_int32 => [1, 2, 3])
707707
assert m != m2
708+
assert_not_equal proto_module::TestMessage.new, proto_module::TestMessage2.new
708709
end
709710

710711
def test_enum_lookup

src/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ else
1818
PTHREAD_DEF =
1919
endif
2020

21-
PROTOBUF_VERSION = 26:6:0
21+
PROTOBUF_VERSION = 26:7:0
2222

2323
if GCC
2424
# Turn on all warnings except for sign comparison (we ignore sign comparison

src/google/protobuf/any.pb.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/google/protobuf/api.pb.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/google/protobuf/compiler/plugin.pb.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)