Merge remote-tracking branch 'origin/3.8.x'

This commit is contained in:
Bo Yang 2019-06-21 04:01:45 +00:00
commit bc742640ef
13 changed files with 81 additions and 143 deletions

2
BUILD
View File

@ -219,7 +219,7 @@ cc_library(
# TODO(keveman): Remove this target once the support gets added to Bazel.
cc_library(
name = "protobuf_headers",
hdrs = glob(["src/**/*.h"]),
hdrs = glob(["src/**/*.h", "src/**/*.inc"]),
includes = ["src/"],
visibility = ["//visibility:public"],
)

View File

@ -1230,6 +1230,7 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \
examples/pubspec.yaml \
examples/third_party/zlib.BUILD \
protobuf.bzl \
protobuf_deps.bzl \
python/release/wheel/build_wheel_manylinux.sh \
python/release/wheel/Dockerfile \
python/release/wheel/protobuf_optimized_pip.sh \

View File

@ -6,7 +6,6 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput
Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter
Recommended.Proto3.JsonInput.Int64FieldBeString.Validator
Recommended.Proto3.JsonInput.MapFieldValueIsNull
Recommended.Proto3.JsonInput.OneofZeroBytes.JsonOutput
Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull
@ -17,7 +16,6 @@ Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate
Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate
Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.Uint64FieldBeString.Validator
Recommended.Proto3.ProtobufInput.OneofZeroBytes.JsonOutput
Required.DurationProtoInputTooLarge.JsonOutput
Required.DurationProtoInputTooSmall.JsonOutput

View File

@ -6,7 +6,6 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput
Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter
Recommended.Proto3.JsonInput.Int64FieldBeString.Validator
Recommended.Proto3.JsonInput.MapFieldValueIsNull
Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull
Recommended.Proto3.JsonInput.RepeatedFieldPrimitiveElementIsNull
@ -16,7 +15,6 @@ Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate
Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate
Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.Uint64FieldBeString.Validator
Required.DurationProtoInputTooLarge.JsonOutput
Required.DurationProtoInputTooSmall.JsonOutput
Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput

View File

@ -5,7 +5,6 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput
Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput
Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.Int64FieldBeString.Validator
Recommended.Proto3.JsonInput.MapFieldValueIsNull
Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull
Recommended.Proto3.JsonInput.RepeatedFieldPrimitiveElementIsNull
@ -15,7 +14,6 @@ Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate
Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate
Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.Uint64FieldBeString.Validator
Required.DurationProtoInputTooLarge.JsonOutput
Required.DurationProtoInputTooSmall.JsonOutput
Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput

View File

@ -6,7 +6,7 @@
<parent>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-parent</artifactId>
<version>3.8.0-rc-1</version>
<version>3.8.0</version>
</parent>
<artifactId>protobuf-javalite</artifactId>

View File

@ -1,3 +1,3 @@
FROM grpctesting/rake-compiler-dock_53c22085d091183c528303791e7771359f699bcf
RUN /bin/bash -l -c "gem install bundler"
RUN /bin/bash -l -c "gem update --system '2.7.9' && gem install bundler"

View File

@ -12431,18 +12431,32 @@ static size_t fmt_bool(bool val, char* buf, size_t length) {
return n;
}
static size_t fmt_int64(long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "%ld", val);
static size_t fmt_int64_as_number(long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "%lld", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
static size_t fmt_uint64(unsigned long long val, char* buf, size_t length) {
static size_t fmt_uint64_as_number(
unsigned long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "%llu", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
static size_t fmt_int64_as_string(long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "\"%lld\"", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
static size_t fmt_uint64_as_string(
unsigned long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "\"%llu\"", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
/* Print a map key given a field name. Called by scalar field handlers and by
* startseq for repeated fields. */
static bool putkey(void *closure, const void *handler_data) {
@ -12486,8 +12500,11 @@ static bool putkey(void *closure, const void *handler_data) {
static bool putmapkey_##type(void *closure, const void *handler_data, \
type val) { \
upb_json_printer *p = closure; \
char data[64]; \
size_t length = fmt_func(val, data, sizeof(data)); \
UPB_UNUSED(handler_data); \
print_data(p, "\"", 1); \
CHK(put##type(closure, handler_data, val)); \
print_data(p, data, length); \
print_data(p, "\":", 2); \
return true; \
}
@ -12495,17 +12512,17 @@ static bool putkey(void *closure, const void *handler_data) {
TYPE_HANDLERS(double, fmt_double)
TYPE_HANDLERS(float, fmt_float)
TYPE_HANDLERS(bool, fmt_bool)
TYPE_HANDLERS(int32_t, fmt_int64)
TYPE_HANDLERS(uint32_t, fmt_int64)
TYPE_HANDLERS(int64_t, fmt_int64)
TYPE_HANDLERS(uint64_t, fmt_uint64)
TYPE_HANDLERS(int32_t, fmt_int64_as_number)
TYPE_HANDLERS(uint32_t, fmt_int64_as_number)
TYPE_HANDLERS(int64_t, fmt_int64_as_string)
TYPE_HANDLERS(uint64_t, fmt_uint64_as_string)
/* double and float are not allowed to be map keys. */
TYPE_HANDLERS_MAPKEY(bool, fmt_bool)
TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64)
TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64)
TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64)
TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64)
TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64_as_number)
TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64_as_number)
TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64_as_number)
TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64_as_number)
#undef TYPE_HANDLERS
#undef TYPE_HANDLERS_MAPKEY

View File

@ -24,14 +24,3 @@ message TestWrapperSetters {
map<string, google.protobuf.StringValue> map_string_value = 13;
}
message TestWrapperAccessorConflicts {
int32 normal_vs_wrapper_value = 1;
google.protobuf.Int32Value normal_vs_wrapper = 2;
int32 normal_vs_normal_value = 3;
int32 normal_vs_normal = 4;
google.protobuf.Int32Value wrapper_vs_wrapper_value = 5;
google.protobuf.Int32Value wrapper_vs_wrapper = 6;
}

View File

@ -16,44 +16,6 @@ use Google\Protobuf\UInt64Value;
class WrapperTypeSettersTest extends TestBase
{
public function testConflictNormalVsWrapper()
{
$m = new Foo\TestWrapperAccessorConflicts();
$m->setNormalVsWrapperValue1(1);
$this->assertSame(1, $m->getNormalVsWrapperValue1());
$m->setNormalVsWrapperValue2(1);
$this->assertSame(1, $m->getNormalVsWrapperValue2());
$wrapper = new Int32Value(["value" => 1]);
$m->setNormalVsWrapper($wrapper);
$this->assertSame(1, $m->getNormalVsWrapper()->getValue());
}
public function testConflictNormalVsNormal()
{
$m = new Foo\TestWrapperAccessorConflicts();
$m->setNormalVsNormalValue(1);
$this->assertSame(1, $m->getNormalVsNormalValue());
$m->setNormalVsNormal(1);
$this->assertSame(1, $m->getNormalVsNormal());
}
public function testConflictWrapperVsWrapper()
{
$m = new Foo\TestWrapperAccessorConflicts();
$m->setWrapperVsWrapperValueValue(1);
$this->assertSame(1, $m->getWrapperVsWrapperValueValue());
$wrapper = new Int32Value(["value" => 1]);
$m->setWrapperVsWrapperValue5($wrapper);
$this->assertSame(1, $m->getWrapperVsWrapperValue5()->getValue());
}
/**
* @dataProvider gettersAndSettersDataProvider
*/

View File

@ -16289,18 +16289,32 @@ static size_t fmt_bool(bool val, char* buf, size_t length) {
return n;
}
static size_t fmt_int64(long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "%ld", val);
static size_t fmt_int64_as_number(long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "%lld", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
static size_t fmt_uint64(unsigned long long val, char* buf, size_t length) {
static size_t fmt_uint64_as_number(
unsigned long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "%llu", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
static size_t fmt_int64_as_string(long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "\"%lld\"", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
static size_t fmt_uint64_as_string(
unsigned long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "\"%llu\"", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
/* Print a map key given a field name. Called by scalar field handlers and by
* startseq for repeated fields. */
static bool putkey(void *closure, const void *handler_data) {
@ -16344,8 +16358,11 @@ static bool putkey(void *closure, const void *handler_data) {
static bool putmapkey_##type(void *closure, const void *handler_data, \
type val) { \
upb_json_printer *p = closure; \
char data[64]; \
size_t length = fmt_func(val, data, sizeof(data)); \
UPB_UNUSED(handler_data); \
print_data(p, "\"", 1); \
CHK(put##type(closure, handler_data, val)); \
print_data(p, data, length); \
print_data(p, "\":", 2); \
return true; \
}
@ -16353,17 +16370,17 @@ static bool putkey(void *closure, const void *handler_data) {
TYPE_HANDLERS(double, fmt_double)
TYPE_HANDLERS(float, fmt_float)
TYPE_HANDLERS(bool, fmt_bool)
TYPE_HANDLERS(int32_t, fmt_int64)
TYPE_HANDLERS(uint32_t, fmt_int64)
TYPE_HANDLERS(int64_t, fmt_int64)
TYPE_HANDLERS(uint64_t, fmt_uint64)
TYPE_HANDLERS(int32_t, fmt_int64_as_number)
TYPE_HANDLERS(uint32_t, fmt_int64_as_number)
TYPE_HANDLERS(int64_t, fmt_int64_as_string)
TYPE_HANDLERS(uint64_t, fmt_uint64_as_string)
/* double and float are not allowed to be map keys. */
TYPE_HANDLERS_MAPKEY(bool, fmt_bool)
TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64)
TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64)
TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64)
TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64)
TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64_as_number)
TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64_as_number)
TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64_as_number)
TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64_as_number)
#undef TYPE_HANDLERS
#undef TYPE_HANDLERS_MAPKEY

View File

@ -1108,9 +1108,9 @@ module CommonTests
expected = {
optionalInt32: 0,
optionalInt64: 0,
optionalInt64: "0",
optionalUint32: 0,
optionalUint64: 0,
optionalUint64: "0",
optionalBool: false,
optionalFloat: 0,
optionalDouble: 0,
@ -1142,9 +1142,9 @@ module CommonTests
expected = {
optionalInt32: 0,
optionalInt64: 0,
optionalInt64: "0",
optionalUint32: 0,
optionalUint64: 0,
optionalUint64: "0",
optionalBool: false,
optionalFloat: 0,
optionalDouble: 0,
@ -1177,9 +1177,9 @@ module CommonTests
expected = {
optionalInt32: 0,
optionalInt64: 0,
optionalInt64: "0",
optionalUint32: 0,
optionalUint64: 0,
optionalUint64: "0",
optionalBool: false,
optionalFloat: 0,
optionalDouble: 0,

View File

@ -655,58 +655,27 @@ void GenerateOneofField(const OneofDescriptor* oneof, io::Printer* printer) {
void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor,
io::Printer* printer) {
bool need_other_name_for_accessor = false;
bool need_other_name_for_wrapper_accessor = false;
const Descriptor* desc = field->containing_type();
if (!field->is_repeated() &&
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
IsWrapperType(field)) {
// Check if there is any field called xxx_value
const FieldDescriptor* other =
desc->FindFieldByName(StrCat(field->name(), "_value"));
if (other != NULL) {
need_other_name_for_wrapper_accessor = true;
}
}
if (strings::EndsWith(field->name(), "_value")) {
std::size_t pos = (field->name()).find("_value");
string name = (field->name()).substr(0, pos);
const FieldDescriptor* other = desc->FindFieldByName(name);
if (other != NULL &&
!other->is_repeated() &&
other->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
IsWrapperType(other)) {
need_other_name_for_accessor = true;
}
}
const OneofDescriptor* oneof = field->containing_oneof();
// Generate getter.
if (oneof != NULL) {
GenerateFieldDocComment(printer, field, is_descriptor, kFieldGetter);
printer->Print(
"public function get^camel_name^^field_number^()\n"
"public function get^camel_name^()\n"
"{\n"
" return $this->readOneof(^number^);\n"
"}\n\n",
"camel_name", UnderscoresToCamelCase(field->name(), true),
"number", IntToString(field->number()),
"field_number", need_other_name_for_accessor ?
StrCat(field->number()) : "");
"number", IntToString(field->number()));
} else {
GenerateFieldDocComment(printer, field, is_descriptor, kFieldGetter);
printer->Print(
"public function get^camel_name^^field_number^()\n"
"public function get^camel_name^()\n"
"{\n"
" return $this->^name^;\n"
"}\n\n",
"camel_name", UnderscoresToCamelCase(field->name(), true),
"name", field->name(),
"field_number", need_other_name_for_accessor ?
StrCat(field->number()) : "");
"camel_name", UnderscoresToCamelCase(field->name(), true), "name",
field->name());
}
// For wrapper types, generate an additional getXXXValue getter
@ -715,28 +684,21 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor,
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
IsWrapperType(field)) {
GenerateWrapperFieldGetterDocComment(printer, field);
printer->Print(
"public function get^camel_name^Value^field_number1^()\n"
"public function get^camel_name^Value()\n"
"{\n"
" $wrapper = $this->get^camel_name^^field_number2^();\n"
" $wrapper = $this->get^camel_name^();\n"
" return is_null($wrapper) ? null : $wrapper->getValue();\n"
"}\n\n",
"camel_name", UnderscoresToCamelCase(field->name(), true),
"field_number1", need_other_name_for_wrapper_accessor ?
StrCat(field->number()) : "",
"field_number2", need_other_name_for_accessor ?
StrCat(field->number()) : "");
"camel_name", UnderscoresToCamelCase(field->name(), true));
}
// Generate setter.
GenerateFieldDocComment(printer, field, is_descriptor, kFieldSetter);
printer->Print(
"public function set^camel_name^^field_number^($var)\n"
"public function set^camel_name^($var)\n"
"{\n",
"camel_name", UnderscoresToCamelCase(field->name(), true),
"field_number", need_other_name_for_accessor ?
StrCat(field->number()) : "");
"camel_name", UnderscoresToCamelCase(field->name(), true));
Indent(printer);
@ -836,17 +798,13 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor,
IsWrapperType(field)) {
GenerateWrapperFieldSetterDocComment(printer, field);
printer->Print(
"public function set^camel_name^Value^field_number1^($var)\n"
"public function set^camel_name^Value($var)\n"
"{\n"
" $wrappedVar = is_null($var) ? null : new \\^wrapper_type^(['value' => $var]);\n"
" return $this->set^camel_name^^field_number2^($wrappedVar);\n"
" return $this->set^camel_name^($wrappedVar);\n"
"}\n\n",
"camel_name", UnderscoresToCamelCase(field->name(), true),
"wrapper_type", LegacyFullClassName(field->message_type(), is_descriptor),
"field_number1", need_other_name_for_wrapper_accessor ?
StrCat(field->number()) : "",
"field_number2", need_other_name_for_accessor ?
StrCat(field->number()) : "");
"wrapper_type", LegacyFullClassName(field->message_type(), is_descriptor));
}
// Generate has method for proto2 only.