Skip to content

Commit

Permalink
Merge pull request #6752 from rafi-kamal/201910111201
Browse files Browse the repository at this point in the history
Down integrate Google3 changes to Github
  • Loading branch information
rafi-kamal committed Oct 24, 2019
2 parents 2fc8852 + 5e6d57b commit 342a2d6
Show file tree
Hide file tree
Showing 78 changed files with 1,074 additions and 1,151 deletions.
570 changes: 270 additions & 300 deletions conformance/binary_json_conformance_suite.cc

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions conformance/binary_json_conformance_suite.h
Expand Up @@ -115,11 +115,9 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite {
google::protobuf::FieldDescriptor::Type,
std::vector<std::pair<std::string, std::string>> values);
void TestValidDataForRepeatedScalarMessage();
void TestValidDataForMapType(
google::protobuf::FieldDescriptor::Type,
google::protobuf::FieldDescriptor::Type);
void TestValidDataForOneofType(
google::protobuf::FieldDescriptor::Type);
void TestValidDataForMapType(google::protobuf::FieldDescriptor::Type,
google::protobuf::FieldDescriptor::Type);
void TestValidDataForOneofType(google::protobuf::FieldDescriptor::Type);
void TestMergeOneofMessage();
void TestOverwriteMessageValueMap();

Expand Down
11 changes: 0 additions & 11 deletions conformance/failure_list_python.txt
Expand Up @@ -24,19 +24,8 @@ Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.STRING[0].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.UINT32[0].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.UINT32[5].ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataScalarBinary.UINT64[0].ProtobufOutput
Required.Proto2.ProtobufInput.IllegalZeroFieldNum_Case_0
Required.Proto2.ProtobufInput.IllegalZeroFieldNum_Case_1
Required.Proto2.ProtobufInput.IllegalZeroFieldNum_Case_2
Required.Proto2.ProtobufInput.IllegalZeroFieldNum_Case_3
Required.Proto2.ProtobufInput.ValidDataMap.STRING.MESSAGE.MergeValue.ProtobufOutput
Required.Proto3.JsonInput.DoubleFieldTooSmall
Required.Proto3.JsonInput.FloatFieldTooLarge
Required.Proto3.JsonInput.FloatFieldTooSmall
Required.Proto3.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool
Required.Proto3.JsonInput.TimestampJsonInputLowercaseT
Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_0
Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_1
Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_2
Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_3
Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MergeValue.JsonOutput
Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MergeValue.ProtobufOutput
Expand Up @@ -59,26 +59,16 @@ static Class<?> reflectExtensionRegistry() {

/** Construct a new, empty instance. */
public static ExtensionRegistryLite create() {
if (EXTENSION_REGISTRY_CLASS != null) {
try {
return invokeSubclassFactory("newInstance");
} catch (Exception e) {
// return a Lite registry.
}
}
return new ExtensionRegistryLite();
ExtensionRegistryLite result = invokeSubclassFactory("newInstance");

return result != null ? result : new ExtensionRegistryLite();
}

/** Get the unmodifiable singleton empty instance. */
public static ExtensionRegistryLite createEmpty() {
if (EXTENSION_REGISTRY_CLASS != null) {
try {
return invokeSubclassFactory("getEmptyRegistry");
} catch (Exception e) {
// return a Lite registry.
}
}
return EMPTY_REGISTRY_LITE;
ExtensionRegistryLite result = invokeSubclassFactory("getEmptyRegistry");

return result != null ? result : EMPTY_REGISTRY_LITE;
}


Expand All @@ -87,9 +77,17 @@ static boolean isFullRegistry(ExtensionRegistryLite registry) {
&& EXTENSION_REGISTRY_CLASS.isAssignableFrom(registry.getClass());
}

private static final ExtensionRegistryLite invokeSubclassFactory(String methodName)
throws Exception {
return (ExtensionRegistryLite)
EXTENSION_REGISTRY_CLASS.getDeclaredMethod(methodName).invoke(null);
/* @Nullable */
private static final ExtensionRegistryLite invokeSubclassFactory(String methodName) {
if (EXTENSION_REGISTRY_CLASS == null) {
return null;
}

try {
return (ExtensionRegistryLite)
EXTENSION_REGISTRY_CLASS.getDeclaredMethod(methodName).invoke(null);
} catch (Exception e) {
return null;
}
}
}
Expand Up @@ -83,19 +83,21 @@ public class ExtensionRegistryLite {
// Visible for testing.
static final String EXTENSION_CLASS_NAME = "com.google.protobuf.Extension";

/* @Nullable */
static Class<?> resolveExtensionClass() {
try {
return Class.forName(EXTENSION_CLASS_NAME);
} catch (ClassNotFoundException e) {
// See comment in ExtensionRegistryFactory on the potential expense of this.
return null;
private static class ExtensionClassHolder {
/* @Nullable */
static final Class<?> INSTANCE = resolveExtensionClass();

/* @Nullable */
static Class<?> resolveExtensionClass() {
try {
return Class.forName(EXTENSION_CLASS_NAME);
} catch (ClassNotFoundException e) {
// See comment in ExtensionRegistryFactory on the potential expense of this.
return null;
}
}
}

/* @Nullable */
private static final Class<?> extensionClass = resolveExtensionClass();

public static boolean isEagerlyParseMessageSets() {
return eagerlyParseMessageSets;
}
Expand Down Expand Up @@ -175,7 +177,7 @@ public final void add(ExtensionLite<?, ?> extension) {
}
if (doFullRuntimeInheritanceCheck && ExtensionRegistryFactory.isFullRegistry(this)) {
try {
this.getClass().getMethod("add", extensionClass).invoke(this, extension);
this.getClass().getMethod("add", ExtensionClassHolder.INSTANCE).invoke(this, extension);
} catch (Exception e) {
throw new IllegalArgumentException(
String.format("Could not invoke ExtensionRegistry#add for %s", extension), e);
Expand Down
Expand Up @@ -115,7 +115,8 @@ public int hashCode() {

@SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime
@Override
public boolean equals(Object other) {
public boolean equals(
Object other) {
if (this == other) {
return true;
}
Expand Down Expand Up @@ -348,16 +349,20 @@ protected Builder(MessageType defaultInstance) {
* Called before any method that would mutate the builder to ensure that it correctly copies any
* state before the write happens to preserve immutability guarantees.
*/
protected void copyOnWrite() {
protected final void copyOnWrite() {
if (isBuilt) {
MessageType newInstance =
(MessageType) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE);
mergeFromInstance(newInstance, instance);
instance = newInstance;
copyOnWriteInternal();
isBuilt = false;
}
}

protected void copyOnWriteInternal() {
MessageType newInstance =
(MessageType) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE);
mergeFromInstance(newInstance, instance);
instance = newInstance;
}

@Override
public final boolean isInitialized() {
return GeneratedMessageLite.isInitialized(instance, /* shouldMemoize= */ false);
Expand Down Expand Up @@ -919,12 +924,8 @@ void internalSetExtensionSet(FieldSet<ExtensionDescriptor> extensions) {
}

@Override
protected void copyOnWrite() {
if (!isBuilt) {
return;
}

super.copyOnWrite();
protected void copyOnWriteInternal() {
super.copyOnWriteInternal();
instance.extensions = instance.extensions.clone();
}

Expand Down

0 comments on commit 342a2d6

Please sign in to comment.