Skip to content

Commit 4a6dc34

Browse files
committed
Sync from Piper @365872496
PROTOBUF_SYNC_PIPER
2 parents 96307d2 + 5941bd1 commit 4a6dc34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+956
-517
lines changed

CHANGES.txt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,32 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
99
* For iterator-pair function parameter types, take both iterators by value.
1010
* Code-space savings and perhaps some modest performance improvements in
1111
RepeatedPtrField.
12+
* Eliminate nullptr check from every tag parse.
13+
* Remove unused _$name$_cached_byte_size_ fields.
14+
* Serialize extension ranges together when not broken by a proto field in the
15+
middle.
16+
* Do out-of-line allocation and deallocation of string object in ArenaString.
17+
* Streamline ParseContext::ParseMessage<T> to avoid code bloat and improve
18+
performance.
19+
* New member functions RepeatedField::Assign, RepeatedPtrField::{Add, Assign}.
20+
* Fix undefined behavior warning due to innocuous uninitialization of value
21+
on an error path.
22+
* Avoid expensive inlined code space for encoding message length for messages
23+
>= 128 bytes and instead do a procedure call to a shared out-of-line routine.
1224

1325
Java:
14-
* Exceptions thrown while reading from an InputStream in parseFrom are now included as causes.
26+
* Exceptions thrown while reading from an InputStream in parseFrom are now
27+
included as causes.
28+
* Support potentially more efficient proto parsing from RopeByteStrings.
29+
* Clarify runtime of ByteString.Output.toStringBuffer().
30+
31+
Python
32+
* Fixed a bug in text format where a trailing colon was printed for repeated field.
33+
* When TextFormat encounters a duplicate message map key, replace the current
34+
one instead of merging.
35+
36+
JavaScript
37+
* Make Any.pack() chainable.
1538

1639
2021-03-10 version 3.15.6 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
1740

Protobuf-C++.podspec

Lines changed: 1 addition & 1 deletion
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.2'
3+
s.version = '3.15.6'
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'

cmake/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ option(protobuf_BUILD_CONFORMANCE "Build conformance tests" OFF)
4545
option(protobuf_BUILD_EXAMPLES "Build examples" OFF)
4646
option(protobuf_BUILD_PROTOC_BINARIES "Build libprotoc and protoc compiler" ON)
4747
option(protobuf_BUILD_LIBPROTOC "Build libprotoc" OFF)
48+
option(protobuf_DISABLE_RTTI "Remove runtime type information in the binaries" OFF)
4849
if (BUILD_SHARED_LIBS)
4950
set(protobuf_BUILD_SHARED_LIBS_DEFAULT ON)
5051
else (BUILD_SHARED_LIBS)
@@ -117,6 +118,10 @@ endif()
117118

118119
add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD)
119120

121+
if (protobuf_DISABLE_RTTI)
122+
add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI=1)
123+
endif()
124+
120125
find_package(Threads REQUIRED)
121126
if (CMAKE_USE_PTHREADS_INIT)
122127
add_definitions(-DHAVE_PTHREAD)

cmake/install.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ endforeach()
3030

3131
if (protobuf_BUILD_PROTOC_BINARIES)
3232
install(TARGETS protoc EXPORT protobuf-targets
33-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
33+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
34+
BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
35+
COMPONENT protoc)
3436
if (UNIX AND NOT APPLE)
3537
set_property(TARGET protoc
3638
PROPERTY INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")

cmake/protobuf-config.cmake.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function(protobuf_generate)
1515
if(COMMAND target_sources)
1616
list(APPEND _singleargs TARGET)
1717
endif()
18-
set(_multiargs PROTOS IMPORT_DIRS GENERATE_EXTENSIONS)
18+
set(_multiargs PROTOS IMPORT_DIRS GENERATE_EXTENSIONS PROTOC_OPTIONS)
1919

2020
cmake_parse_arguments(protobuf_generate "${_options}" "${_singleargs}" "${_multiargs}" "${ARGN}")
2121

@@ -130,9 +130,9 @@ function(protobuf_generate)
130130
add_custom_command(
131131
OUTPUT ${_generated_srcs}
132132
COMMAND protobuf::protoc
133-
ARGS --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file}
133+
ARGS ${protobuf_generate_PROTOC_OPTIONS} --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_protobuf_include_path} ${_abs_file}
134134
DEPENDS ${_abs_file} protobuf::protoc
135-
COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}"
135+
COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}. Custom options: ${protobuf_generate_PROTOC_OPTIONS}"
136136
VERBATIM )
137137
endforeach()
138138

configure.ac

Lines changed: 14 additions & 1 deletion
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.2],[[email protected]],[protobuf])
20+
AC_INIT([Protocol Buffers],[3.15.6],[[email protected]],[protobuf])
2121

2222
AM_MAINTAINER_MODE([enable])
2323

@@ -223,6 +223,19 @@ case "$target_os" in
223223
esac
224224
AM_CONDITIONAL([OBJC_CONFORMANCE_TEST], [test $OBJC_CONFORMANCE_TEST = 1])
225225

226+
AC_MSG_CHECKING(whether -llog is needed)
227+
ANDROID_TEST=no
228+
case "$target_os" in
229+
*android*)
230+
ANDROID_TEST=yes
231+
;;
232+
esac
233+
AC_MSG_RESULT($ANDROID_TEST)
234+
if test "x$ANDROID_TEST" = xyes; then
235+
LIBLOG_LIBS="-llog"
236+
fi
237+
AC_SUBST([LIBLOG_LIBS])
238+
226239
# HACK: Make gmock's configure script pick up our copy of CFLAGS and CXXFLAGS,
227240
# since the flags added by ACX_CHECK_SUNCC must be used when compiling gmock
228241
# too.

conformance/conformance_cpp.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void DoTest(const ConformanceRequest& request, ConformanceResponse* response) {
134134
&proto_binary, options);
135135
if (!status.ok()) {
136136
response->set_parse_error(string("Parse error: ") +
137-
std::string(status.error_message()));
137+
std::string(status.message()));
138138
return;
139139
}
140140

@@ -189,7 +189,7 @@ void DoTest(const ConformanceRequest& request, ConformanceResponse* response) {
189189
if (!status.ok()) {
190190
response->set_serialize_error(
191191
string("Failed to serialize JSON output: ") +
192-
std::string(status.error_message()));
192+
std::string(status.message()));
193193
return;
194194
}
195195
break;

java/core/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ LITE_SRCS = [
8585
"src/main/java/com/google/protobuf/UnknownFieldSetLite.java",
8686
"src/main/java/com/google/protobuf/UnknownFieldSetLiteSchema.java",
8787
"src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java",
88+
"src/main/java/com/google/protobuf/UnsafeByteOperations.java",
8889
"src/main/java/com/google/protobuf/UnsafeUtil.java",
8990
"src/main/java/com/google/protobuf/Utf8.java",
9091
"src/main/java/com/google/protobuf/WireFormat.java",

java/core/src/main/java/com/google/protobuf/CodedInputStream.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3523,9 +3523,25 @@ public ByteString readBytes() throws IOException {
35233523
return ByteString.wrap(bytes);
35243524
}
35253525
} else if (size > 0 && size <= remaining()) {
3526-
byte[] temp = new byte[size];
3527-
readRawBytesTo(temp, 0, size);
3528-
return ByteString.wrap(temp);
3526+
if (immutable && enableAliasing) {
3527+
ArrayList<ByteString> byteStrings = new ArrayList<>();
3528+
int l = size;
3529+
while (l > 0) {
3530+
if (currentRemaining() == 0) {
3531+
getNextByteBuffer();
3532+
}
3533+
int bytesToCopy = Math.min(l, (int) currentRemaining());
3534+
int idx = (int) (currentByteBufferPos - currentAddress);
3535+
byteStrings.add(ByteString.wrap(slice(idx, idx + bytesToCopy)));
3536+
l -= bytesToCopy;
3537+
currentByteBufferPos += bytesToCopy;
3538+
}
3539+
return ByteString.copyFrom(byteStrings);
3540+
} else {
3541+
byte[] temp = new byte[size];
3542+
readRawBytesTo(temp, 0, size);
3543+
return ByteString.wrap(temp);
3544+
}
35293545
}
35303546

35313547
if (size == 0) {

java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void setThrownFromInputStream() {
7878
/* This write can be racy if the same exception is stored and then thrown by multiple custom
7979
* InputStreams on different threads. But since it only ever moves from false->true, there's no
8080
* problem. A thread checking this condition after catching this exception from a delegate
81-
* stram of CodedInputStream is guaranteed to always observe true, because a write on the same
81+
* stream of CodedInputStream is guaranteed to always observe true, because a write on the same
8282
* thread set the value when the exception left the delegate. A thread checking the same
8383
* condition with an exception created by CodedInputStream is guaranteed to always see false,
8484
* because the exception has not been exposed to any code that could publish it to other threads

java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,39 @@ public void testReadByteBufferAliasing() throws Exception {
11421142
}
11431143
}
11441144

1145+
public void testIterableByteBufferInputStreamReadBytesWithAlias() throws Exception {
1146+
ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
1147+
CodedOutputStream output = CodedOutputStream.newInstance(byteArrayStream);
1148+
// A bytes field large enough that won't fit into the default block buffer.
1149+
// 4.5 is to test the case where the total size of input is not aligned with DEFAULT_BLOCK_SIZE.
1150+
final int bytesLength = DEFAULT_BLOCK_SIZE * 4 + (DEFAULT_BLOCK_SIZE / 2);
1151+
byte[] bytes = new byte[bytesLength];
1152+
for (int i = 0; i < bytesLength; i++) {
1153+
bytes[i] = (byte) (i % 256);
1154+
}
1155+
output.writeByteArrayNoTag(bytes);
1156+
output.flush();
1157+
1158+
// Input data is split into multiple ByteBuffers so that a single bytes spans across them.
1159+
// CodedInputStream with aliasing will decode it as a consequent rope by wrapping ByteBuffers.
1160+
byte[] data = byteArrayStream.toByteArray();
1161+
ArrayList<ByteBuffer> input = new ArrayList<>();
1162+
for (int i = 0; i < data.length; i += DEFAULT_BLOCK_SIZE) {
1163+
int rl = Math.min(DEFAULT_BLOCK_SIZE, data.length - i);
1164+
ByteBuffer rb = ByteBuffer.allocateDirect(rl);
1165+
rb.put(data, i, rl);
1166+
rb.flip();
1167+
input.add(rb);
1168+
}
1169+
final CodedInputStream inputStream = CodedInputStream.newInstance(input, true);
1170+
inputStream.enableAliasing(true);
1171+
1172+
ByteString result = inputStream.readBytes();
1173+
for (int i = 0; i < bytesLength; i++) {
1174+
assertEquals((byte) (i % 256), result.byteAt(i));
1175+
}
1176+
}
1177+
11451178
public void testCompatibleTypes() throws Exception {
11461179
long data = 0x100000000L;
11471180
Int64Message message = Int64Message.newBuilder().setData(data).build();
@@ -1196,7 +1229,7 @@ public void testSkipPastEndOfByteArrayInput() throws Exception {
11961229
// Expected
11971230
}
11981231
}
1199-
1232+
12001233
public void testMaliciousInputStream() throws Exception {
12011234
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
12021235
CodedOutputStream codedOutputStream = CodedOutputStream.newInstance(outputStream);
@@ -1210,28 +1243,28 @@ public synchronized int read(byte[] b, int off, int len) {
12101243
return super.read(b, off, len);
12111244
}
12121245
};
1213-
1246+
12141247
// test ByteString
1215-
1248+
12161249
CodedInputStream codedInputStream = CodedInputStream.newInstance(inputStream, 1);
12171250
ByteString byteString = codedInputStream.readBytes();
12181251
assertEquals(0x0, byteString.byteAt(0));
12191252
maliciousCapture.get(1)[0] = 0x9;
12201253
assertEquals(0x0, byteString.byteAt(0));
1221-
1254+
12221255
// test ByteBuffer
1223-
1256+
12241257
inputStream.reset();
12251258
maliciousCapture.clear();
12261259
codedInputStream = CodedInputStream.newInstance(inputStream, 1);
12271260
ByteBuffer byteBuffer = codedInputStream.readByteBuffer();
12281261
assertEquals(0x0, byteBuffer.get(0));
12291262
maliciousCapture.get(1)[0] = 0x9;
12301263
assertEquals(0x0, byteBuffer.get(0));
1231-
1264+
12321265

12331266
// test byte[]
1234-
1267+
12351268
inputStream.reset();
12361269
maliciousCapture.clear();
12371270
codedInputStream = CodedInputStream.newInstance(inputStream, 1);
@@ -1241,7 +1274,7 @@ public synchronized int read(byte[] b, int off, int len) {
12411274
assertEquals(0x9, byteArray[0]); // MODIFICATION! Should we fix?
12421275

12431276
// test rawBytes
1244-
1277+
12451278
inputStream.reset();
12461279
maliciousCapture.clear();
12471280
codedInputStream = CodedInputStream.newInstance(inputStream, 1);

java/lite/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
<include>UnknownFieldSetLite.java</include>
174174
<include>UnknownFieldSetLiteSchema.java</include>
175175
<include>UnmodifiableLazyStringList.java</include>
176+
<include>UnsafeByteOperations.java</include>
176177
<include>UnsafeUtil.java</include>
177178
<include>Utf8.java</include>
178179
<include>WireFormat.java</include>

java/util/src/main/java/com/google/protobuf/util/Durations.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ public static boolean isNegative(Duration duration) {
149149
return (duration.getSeconds() == 0) ? duration.getNanos() < 0 : duration.getSeconds() < 0;
150150
}
151151

152+
/** Returns whether the given {@link Duration} is positive or not. */
153+
public static boolean isPositive(Duration duration) {
154+
checkValid(duration);
155+
return !isNegative(duration) && !duration.equals(ZERO);
156+
}
157+
152158
/**
153159
* Ensures that the given {@link Duration} is not negative.
154160
*
@@ -157,7 +163,6 @@ public static boolean isNegative(Duration duration) {
157163
*/
158164
@CanIgnoreReturnValue
159165
public static Duration checkNotNegative(Duration duration) {
160-
checkValid(duration);
161166
checkArgument(!isNegative(duration), "duration (%s) must not be negative", toString(duration));
162167
return duration;
163168
}
@@ -170,11 +175,7 @@ public static Duration checkNotNegative(Duration duration) {
170175
*/
171176
@CanIgnoreReturnValue
172177
public static Duration checkPositive(Duration duration) {
173-
checkValid(duration);
174-
checkArgument(
175-
!isNegative(duration) && !duration.equals(ZERO),
176-
"duration (%s) must be positive",
177-
toString(duration));
178+
checkArgument(isPositive(duration), "duration (%s) must be positive", toString(duration));
178179
return duration;
179180
}
180181

js/package.json

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

kokoro/release/python/linux/build_artifacts.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,31 @@ build_artifact_version() {
4949
sudo rm -rf $REPO_DIR
5050
}
5151

52+
build_crosscompiled_aarch64_artifact_version() {
53+
# crosscompilation is only supported with the dockcross manylinux2014 image
54+
DOCKER_IMAGE=dockcross/manylinux2014-aarch64
55+
PLAT=aarch64
56+
57+
# TODO(jtatermusch): currently when crosscompiling, "auditwheel repair" will be disabled
58+
# since auditwheel doesn't work for crosscomiled wheels.
59+
build_artifact_version $@
60+
}
61+
5262
build_artifact_version 2.7
5363
build_artifact_version 3.5
5464
build_artifact_version 3.6
5565
build_artifact_version 3.7
5666
build_artifact_version 3.8
5767
build_artifact_version 3.9
68+
69+
build_crosscompiled_aarch64_artifact_version 3.7
70+
build_crosscompiled_aarch64_artifact_version 3.8
71+
build_crosscompiled_aarch64_artifact_version 3.9
72+
73+
# Put the aarch64 manylinux wheels under the "unofficial" subdirectory.
74+
# Only wheels directly under the artifacts/ directory will be published
75+
# to PyPI as part of the protobuf release process.
76+
# TODO(jtattermusch): include aarch64 wheels in the release
77+
# once they are sufficiently tested.
78+
mkdir -p $ARTIFACT_DIR/unofficial
79+
mv $ARTIFACT_DIR/protobuf-*-manylinux*_aarch64.whl $ARTIFACT_DIR/unofficial

0 commit comments

Comments
 (0)