aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Shanqing Cai <cais@google.com>2016-09-11 10:03:45 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-09-11 11:17:31 -0700
commit645a554a41ef5524e7ec65beeb7976c066886da6 (patch)
treead90a0ec2b833e20941db4aad3c7a5f24b4df0ff
parentd49688f9c2f2acf33a408a1e010f4cc6623b93d0 (diff)
Update OSS protobuf git depedency version to 3.0.2
3.0.2 is the latest release. Add a level of indirection to the int64 type in 1) core/example/feature_util.h, feature_util.cc and the places where the type is used 2) tools/proto_text/gen_proto_text_functions_lib.cc and its tests. This is for dealing with the variability of "int64" type definition among different platforms. On some systems, int64 is "long int", while on others it is "long long int". See GitHub Issue for more details: https://github.com/tensorflow/tensorflow/issues/3626. This change list fixes the issue and eliminates the need to stick to an old (3.0.0-beta-2) commit of protobuf. Change: 132814372
-rw-r--r--tensorflow/core/example/feature_util.cc9
-rw-r--r--tensorflow/core/example/feature_util.h15
-rw-r--r--tensorflow/core/example/feature_util_test.cc27
-rw-r--r--tensorflow/core/platform/default/protobuf.h2
-rw-r--r--tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc15
-rw-r--r--tensorflow/tools/proto_text/gen_proto_text_functions_lib_test.cc8
-rw-r--r--tensorflow/workspace.bzl2
7 files changed, 46 insertions, 32 deletions
diff --git a/tensorflow/core/example/feature_util.cc b/tensorflow/core/example/feature_util.cc
index ddd2435a95..6f3cc6c6c5 100644
--- a/tensorflow/core/example/feature_util.cc
+++ b/tensorflow/core/example/feature_util.cc
@@ -28,7 +28,8 @@ namespace internal {
} // namespace internal
template <>
-bool ExampleHasFeature<int64>(const string& name, const Example& example) {
+bool ExampleHasFeature<protobuf_int64>(const string& name,
+ const Example& example) {
auto it = example.features().feature().find(name);
return (it != example.features().feature().end()) &&
(it->second.kind_case() == Feature::KindCase::kInt64List);
@@ -49,14 +50,14 @@ bool ExampleHasFeature<string>(const string& name, const Example& example) {
}
template <>
-const protobuf::RepeatedField<int64>& GetFeatureValues<int64>(
+const protobuf::RepeatedField<protobuf_int64>& GetFeatureValues<protobuf_int64>(
const string& name, const Example& example) {
return example.features().feature().at(name).int64_list().value();
}
template <>
-protobuf::RepeatedField<int64>* GetFeatureValues<int64>(const string& name,
- Example* example) {
+protobuf::RepeatedField<protobuf_int64>* GetFeatureValues<protobuf_int64>(
+ const string& name, Example* example) {
return internal::ExampleFeature(name, example)
.mutable_int64_list()
->mutable_value();
diff --git a/tensorflow/core/example/feature_util.h b/tensorflow/core/example/feature_util.h
index 048930d235..4004411cb1 100644
--- a/tensorflow/core/example/feature_util.h
+++ b/tensorflow/core/example/feature_util.h
@@ -73,8 +73,8 @@ template <typename FeatureType>
struct RepeatedFieldTrait;
template <>
-struct RepeatedFieldTrait<int64> {
- using Type = protobuf::RepeatedField<int64>;
+struct RepeatedFieldTrait<protobuf_int64> {
+ using Type = protobuf::RepeatedField<protobuf_int64>;
};
template <>
@@ -95,7 +95,7 @@ struct FeatureTrait;
template <typename ValueType>
struct FeatureTrait<ValueType, typename std::enable_if<
std::is_integral<ValueType>::value>::type> {
- using Type = int64;
+ using Type = protobuf_int64;
};
template <typename ValueType>
@@ -178,7 +178,8 @@ void AppendFeatureValues(std::initializer_list<ValueType> container,
}
template <>
-bool ExampleHasFeature<int64>(const string& name, const Example& example);
+bool ExampleHasFeature<protobuf_int64>(const string& name,
+ const Example& example);
template <>
bool ExampleHasFeature<float>(const string& name, const Example& example);
@@ -187,12 +188,12 @@ template <>
bool ExampleHasFeature<string>(const string& name, const Example& example);
template <>
-const protobuf::RepeatedField<int64>& GetFeatureValues<int64>(
+const protobuf::RepeatedField<protobuf_int64>& GetFeatureValues<protobuf_int64>(
const string& name, const Example& example);
template <>
-protobuf::RepeatedField<int64>* GetFeatureValues<int64>(const string& name,
- Example* example);
+protobuf::RepeatedField<protobuf_int64>* GetFeatureValues<protobuf_int64>(
+ const string& name, Example* example);
template <>
const protobuf::RepeatedField<float>& GetFeatureValues<float>(
diff --git a/tensorflow/core/example/feature_util_test.cc b/tensorflow/core/example/feature_util_test.cc
index 9e1d645118..eb7b90af1b 100644
--- a/tensorflow/core/example/feature_util_test.cc
+++ b/tensorflow/core/example/feature_util_test.cc
@@ -32,7 +32,7 @@ TEST(GetFeatureValuesInt64Test, ReadsASingleValue) {
.mutable_int64_list()
->add_value(42);
- auto tag = GetFeatureValues<int64>("tag", example);
+ auto tag = GetFeatureValues<protobuf_int64>("tag", example);
ASSERT_EQ(1, tag.size());
EXPECT_EQ(42, tag.Get(0));
@@ -41,7 +41,7 @@ TEST(GetFeatureValuesInt64Test, ReadsASingleValue) {
TEST(GetFeatureValuesInt64Test, WritesASingleValue) {
Example example;
- GetFeatureValues<int64>("tag", &example)->Add(42);
+ GetFeatureValues<protobuf_int64>("tag", &example)->Add(42);
ASSERT_EQ(1,
example.features().feature().at("tag").int64_list().value_size());
@@ -53,7 +53,7 @@ TEST(GetFeatureValuesInt64Test, CheckUntypedFieldExistence) {
EXPECT_FALSE(ExampleHasFeature("tag", example));
- GetFeatureValues<int64>("tag", &example)->Add(0);
+ GetFeatureValues<protobuf_int64>("tag", &example)->Add(0);
EXPECT_TRUE(ExampleHasFeature("tag", example));
}
@@ -62,12 +62,12 @@ TEST(GetFeatureValuesInt64Test, CheckTypedFieldExistence) {
Example example;
GetFeatureValues<float>("tag", &example)->Add(3.14);
- ASSERT_FALSE(ExampleHasFeature<int64>("tag", example));
+ ASSERT_FALSE(ExampleHasFeature<protobuf_int64>("tag", example));
- GetFeatureValues<int64>("tag", &example)->Add(42);
+ GetFeatureValues<protobuf_int64>("tag", &example)->Add(42);
- EXPECT_TRUE(ExampleHasFeature<int64>("tag", example));
- auto tag_ro = GetFeatureValues<int64>("tag", example);
+ EXPECT_TRUE(ExampleHasFeature<protobuf_int64>("tag", example));
+ auto tag_ro = GetFeatureValues<protobuf_int64>("tag", example);
ASSERT_EQ(1, tag_ro.size());
EXPECT_EQ(42, tag_ro.Get(0));
}
@@ -78,9 +78,9 @@ TEST(GetFeatureValuesInt64Test, CopyIterableToAField) {
std::copy(values.begin(), values.end(),
protobuf::RepeatedFieldBackInserter(
- GetFeatureValues<int64>("tag", &example)));
+ GetFeatureValues<protobuf_int64>("tag", &example)));
- auto tag_ro = GetFeatureValues<int64>("tag", example);
+ auto tag_ro = GetFeatureValues<protobuf_int64>("tag", example);
ASSERT_EQ(3, tag_ro.size());
EXPECT_EQ(1, tag_ro.Get(0));
EXPECT_EQ(2, tag_ro.Get(1));
@@ -114,7 +114,7 @@ TEST(GetFeatureValuesFloatTest, WritesASingleValue) {
TEST(GetFeatureValuesFloatTest, CheckTypedFieldExistence) {
Example example;
- GetFeatureValues<int64>("tag", &example)->Add(42);
+ GetFeatureValues<protobuf_int64>("tag", &example)->Add(42);
ASSERT_FALSE(ExampleHasFeature<float>("tag", example));
GetFeatureValues<float>("tag", &example)->Add(3.14);
@@ -151,7 +151,7 @@ TEST(GetFeatureValuesStringTest, WritesASingleValue) {
TEST(GetFeatureValuesBytesTest, CheckTypedFieldExistence) {
Example example;
- GetFeatureValues<int64>("tag", &example)->Add(42);
+ GetFeatureValues<protobuf_int64>("tag", &example)->Add(42);
ASSERT_FALSE(ExampleHasFeature<string>("tag", example));
*GetFeatureValues<string>("tag", &example)->Add() = "FOO";
@@ -190,9 +190,10 @@ TEST(AppendFeatureValuesTest, FloatValuesUsingInitializerList) {
TEST(AppendFeatureValuesTest, Int64ValuesUsingInitializerList) {
Example example;
- AppendFeatureValues({1, 2, 3}, "tag", &example);
+ std::vector<protobuf_int64> values{1, 2, 3};
+ AppendFeatureValues(values, "tag", &example);
- auto tag_ro = GetFeatureValues<int64>("tag", example);
+ auto tag_ro = GetFeatureValues<protobuf_int64>("tag", example);
ASSERT_EQ(3, tag_ro.size());
EXPECT_EQ(1, tag_ro.Get(0));
EXPECT_EQ(2, tag_ro.Get(1));
diff --git a/tensorflow/core/platform/default/protobuf.h b/tensorflow/core/platform/default/protobuf.h
index 48718f2d00..0f23877297 100644
--- a/tensorflow/core/platform/default/protobuf.h
+++ b/tensorflow/core/platform/default/protobuf.h
@@ -35,6 +35,8 @@ namespace tensorflow {
namespace protobuf = ::google::protobuf;
using protobuf_int64 = ::google::protobuf::int64;
using protobuf_uint64 = ::google::protobuf::uint64;
+static const char* kProtobufInt64Typename = "::google::protobuf::int64";
+static const char* kProtobufUint64Typename = "::google::protobuf::uint64";
} // namespace tensorflow
#endif // TENSORFLOW_CORE_PLATFORM_DEFAULT_PROTOBUF_H_
diff --git a/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc b/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc
index a5b0f03a25..c31f3c4e81 100644
--- a/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc
+++ b/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc
@@ -224,9 +224,18 @@ string GetProtoHeaderName(const FileDescriptor& fd) {
// Returns the C++ class name for the given proto field.
string GetCppClass(const FieldDescriptor& d) {
- return d.cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE
- ? GetQualifiedName(*d.message_type())
- : d.cpp_type_name();
+ string cpp_class = d.cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE
+ ? GetQualifiedName(*d.message_type())
+ : d.cpp_type_name();
+
+ // In open-source TensorFlow, the definition of int64 varies across
+ // platforms. The following line, which is manipulated during internal-
+ // external sync'ing, takes care of the variability.
+ if (cpp_class == "int64") {
+ cpp_class = kProtobufInt64Typename;
+ }
+
+ return cpp_class;
}
// Returns the string that can be used for a header guard for the generated
diff --git a/tensorflow/tools/proto_text/gen_proto_text_functions_lib_test.cc b/tensorflow/tools/proto_text/gen_proto_text_functions_lib_test.cc
index 5d5660c3c3..3fd43e7068 100644
--- a/tensorflow/tools/proto_text/gen_proto_text_functions_lib_test.cc
+++ b/tensorflow/tools/proto_text/gen_proto_text_functions_lib_test.cc
@@ -90,7 +90,7 @@ TEST(CreateProtoDebugStringLibTest, ValidSimpleTypes) {
// Max numeric values.
proto.Clear();
proto.set_optional_int32(std::numeric_limits<int32>::max());
- proto.set_optional_int64(std::numeric_limits<int64>::max());
+ proto.set_optional_int64(std::numeric_limits<protobuf_int64>::max());
proto.set_optional_uint32(std::numeric_limits<uint32>::max());
proto.set_optional_uint64(std::numeric_limits<uint64>::max());
proto.set_optional_float(std::numeric_limits<float>::max());
@@ -106,7 +106,7 @@ TEST(CreateProtoDebugStringLibTest, ValidSimpleTypes) {
// Lowest numeric values.
proto.Clear();
proto.set_optional_int32(std::numeric_limits<int32>::lowest());
- proto.set_optional_int64(std::numeric_limits<int64>::lowest());
+ proto.set_optional_int64(std::numeric_limits<protobuf_int64>::lowest());
proto.set_optional_float(std::numeric_limits<float>::lowest());
proto.set_optional_double(std::numeric_limits<double>::lowest());
EXPECT_TEXT_TRANSFORMS_MATCH();
@@ -394,7 +394,7 @@ TEST(CreateProtoDebugStringLibTest, Map) {
{
auto& map = *proto.mutable_map_string_to_int64();
map["def"] = 0;
- map["abc"] = std::numeric_limits<int64>::max();
+ map["abc"] = std::numeric_limits<protobuf_int64>::max();
map[""] = 20;
}
EXPECT_TEXT_TRANSFORMS_MATCH();
@@ -404,7 +404,7 @@ TEST(CreateProtoDebugStringLibTest, Map) {
{
auto& map = *proto.mutable_map_int64_to_string();
map[0] = "def";
- map[std::numeric_limits<int64>::max()] = "";
+ map[std::numeric_limits<protobuf_int64>::max()] = "";
map[20] = "abc";
}
EXPECT_TEXT_TRANSFORMS_MATCH();
diff --git a/tensorflow/workspace.bzl b/tensorflow/workspace.bzl
index 01655f5d79..3dfbd45f5c 100644
--- a/tensorflow/workspace.bzl
+++ b/tensorflow/workspace.bzl
@@ -90,7 +90,7 @@ def tf_workspace(path_prefix = "", tf_repo_name = ""):
native.git_repository(
name = "protobuf",
remote = "https://github.com/google/protobuf",
- commit = "ed87c1fe2c6e1633cadb62cf54b2723b2b25c280",
+ commit = "1a586735085e817b1f52e53feec92ce418049f69", # Release 3.0.2.
)
native.new_http_archive(