diff --git a/tsl/platform/abi.cc b/tsl/platform/abi.cc index 9e969f312..889e02f19 100644 --- a/tsl/platform/abi.cc +++ b/tsl/platform/abi.cc @@ -39,7 +39,7 @@ extern "C" char* __unDName(char* output_string, const char* name, namespace tsl { namespace port { -string MaybeAbiDemangle(const char* name) { +std::string MaybeAbiDemangle(const char* name) { #if defined(_MSC_VER) std::unique_ptr demangled{__unDName(nullptr, name, 0, std::malloc, std::free, diff --git a/tsl/platform/coding.cc b/tsl/platform/coding.cc index d83312b1c..eae1896ff 100644 --- a/tsl/platform/coding.cc +++ b/tsl/platform/coding.cc @@ -15,6 +15,8 @@ limitations under the License. #include "tsl/platform/coding.h" +#include + #include "xla/tsl/platform/byte_order.h" #include "xla/tsl/platform/types.h" #include "tsl/platform/stringpiece.h" @@ -58,19 +60,19 @@ void EncodeFixed64(char* buf, uint64 value) { } } -void PutFixed16(string* dst, uint16 value) { +void PutFixed16(std::string* dst, uint16 value) { char buf[sizeof(value)]; EncodeFixed16(buf, value); dst->append(buf, sizeof(buf)); } -void PutFixed32(string* dst, uint32 value) { +void PutFixed32(std::string* dst, uint32 value) { char buf[sizeof(value)]; EncodeFixed32(buf, value); dst->append(buf, sizeof(buf)); } -void PutFixed64(string* dst, uint64 value) { +void PutFixed64(std::string* dst, uint64 value) { char buf[sizeof(value)]; EncodeFixed64(buf, value); dst->append(buf, sizeof(buf)); @@ -104,7 +106,7 @@ char* EncodeVarint32(char* dst, uint32 v) { return reinterpret_cast(ptr); } -void PutVarint32(string* dst, uint32 v) { +void PutVarint32(std::string* dst, uint32 v) { char buf[5]; char* ptr = EncodeVarint32(buf, v); dst->append(buf, ptr - buf); @@ -127,7 +129,7 @@ char* EncodeVarint64(char* dst, uint64 v) { return reinterpret_cast(ptr); } -void PutVarint64(string* dst, uint64 v) { +void PutVarint64(std::string* dst, uint64 v) { char buf[10]; char* ptr = EncodeVarint64(buf, v); dst->append(buf, ptr - buf); diff --git a/tsl/platform/coding.h b/tsl/platform/coding.h index ddd372b1c..2940901f1 100644 --- a/tsl/platform/coding.h +++ b/tsl/platform/coding.h @@ -21,6 +21,8 @@ limitations under the License. #ifndef TENSORFLOW_TSL_PLATFORM_CODING_H_ #define TENSORFLOW_TSL_PLATFORM_CODING_H_ +#include + #include "absl/strings/string_view.h" #include "xla/tsl/platform/types.h" #include "tsl/platform/stringpiece.h" @@ -40,12 +42,12 @@ static const int kMaxVarint64Bytes = 10; extern void EncodeFixed16(char* dst, uint16 value); extern void EncodeFixed32(char* dst, uint32 value); extern void EncodeFixed64(char* dst, uint64 value); -extern void PutFixed16(string* dst, uint16 value); -extern void PutFixed32(string* dst, uint32 value); -extern void PutFixed64(string* dst, uint64 value); +extern void PutFixed16(std::string* dst, uint16 value); +extern void PutFixed32(std::string* dst, uint32 value); +extern void PutFixed64(std::string* dst, uint64 value); -extern void PutVarint32(string* dst, uint32 value); -extern void PutVarint64(string* dst, uint64 value); +extern void PutVarint32(std::string* dst, uint32 value); +extern void PutVarint64(std::string* dst, uint64 value); extern void PutVarint32(tstring* dst, uint32 value); extern void PutVarint64(tstring* dst, uint64 value); diff --git a/tsl/platform/cpu_info.cc b/tsl/platform/cpu_info.cc index 0b92c6d28..d9b06a388 100644 --- a/tsl/platform/cpu_info.cc +++ b/tsl/platform/cpu_info.cc @@ -312,7 +312,7 @@ class CPUIDInfo { return false; } - string vendor_str() const { return vendor_str_; } + std::string vendor_str() const { return vendor_str_; } int family() const { return family_; } int model_num() { return model_num_; } @@ -364,7 +364,7 @@ class CPUIDInfo { int have_sse4_2_ : 1; int have_ssse3_ : 1; int have_hypervisor_ : 1; - string vendor_str_; + std::string vendor_str_; int family_; int model_num_; }; diff --git a/tsl/platform/demangle.h b/tsl/platform/demangle.h index 4b7576f8d..607afc93d 100644 --- a/tsl/platform/demangle.h +++ b/tsl/platform/demangle.h @@ -16,6 +16,8 @@ limitations under the License. #ifndef TENSORFLOW_TSL_PLATFORM_DEMANGLE_H_ #define TENSORFLOW_TSL_PLATFORM_DEMANGLE_H_ +#include + #include "xla/tsl/platform/types.h" namespace tsl { @@ -23,8 +25,8 @@ namespace port { // If the compiler supports, demangle a mangled symbol name and return // the demangled name. Otherwise, returns 'mangled' as is. -string Demangle(const char* mangled); -inline string Demangle(const string mangled) { +std::string Demangle(const char* mangled); +inline std::string Demangle(const std::string mangled) { return Demangle(mangled.c_str()); } diff --git a/tsl/platform/hash.h b/tsl/platform/hash.h index 0945bf071..4b54b3837 100644 --- a/tsl/platform/hash.h +++ b/tsl/platform/hash.h @@ -94,8 +94,8 @@ struct hash { }; template <> -struct hash { - size_t operator()(const string& s) const { +struct hash { + size_t operator()(const std::string& s) const { return static_cast(Hash64(s)); } }; diff --git a/tsl/platform/hash_test.cc b/tsl/platform/hash_test.cc index 010ccde83..9dec91ea6 100644 --- a/tsl/platform/hash_test.cc +++ b/tsl/platform/hash_test.cc @@ -107,9 +107,9 @@ TEST(StringPieceHasher, Equality) { } TEST(StringPieceHasher, HashMap) { - string s1("foo"); - string s2("bar"); - string s3("baz"); + std::string s1("foo"); + std::string s2("bar"); + std::string s3("baz"); absl::string_view p1(s1); absl::string_view p2(s2); diff --git a/tsl/platform/host_info.h b/tsl/platform/host_info.h index 687045c02..8fb857988 100644 --- a/tsl/platform/host_info.h +++ b/tsl/platform/host_info.h @@ -17,6 +17,7 @@ limitations under the License. #define TENSORFLOW_TSL_PLATFORM_HOST_INFO_H_ #include +#include #include "xla/tsl/platform/types.h" @@ -37,11 +38,11 @@ struct IOStatistics { }; // Return the hostname of the machine on which this process is running. -string Hostname(); +std::string Hostname(); // Return the job name as a string if it exists, otherwise return an empty // string. -string JobName(); +std::string JobName(); // Returns the Borg job UID as an int64_t if it exists. Otherwise return -1. int64_t JobUid(); diff --git a/tsl/platform/human_readable_json.h b/tsl/platform/human_readable_json.h index 3fedff063..897a6b110 100644 --- a/tsl/platform/human_readable_json.h +++ b/tsl/platform/human_readable_json.h @@ -40,9 +40,9 @@ absl::StatusOr ProtoToHumanReadableJson( // Converts a string produced by ProtoToHumanReadableJSON to a protobuf. Not // guaranteed to work for general JSON. -absl::Status HumanReadableJsonToProto(const string& str, +absl::Status HumanReadableJsonToProto(const std::string& str, protobuf::Message* proto); -absl::Status HumanReadableJsonToProto(const string& str, +absl::Status HumanReadableJsonToProto(const std::string& str, protobuf::MessageLite* proto); } // namespace tsl diff --git a/tsl/platform/null_file_system.h b/tsl/platform/null_file_system.h index 8c8829858..f84fe8b36 100644 --- a/tsl/platform/null_file_system.h +++ b/tsl/platform/null_file_system.h @@ -39,70 +39,72 @@ class NullFileSystem : public FileSystem { TF_USE_FILESYSTEM_METHODS_WITH_NO_TRANSACTION_SUPPORT; absl::Status NewRandomAccessFile( - const string& fname, TransactionToken* token, + const std::string& fname, TransactionToken* token, std::unique_ptr* result) override { return errors::Unimplemented("NewRandomAccessFile unimplemented"); } - absl::Status NewWritableFile(const string& fname, TransactionToken* token, + absl::Status NewWritableFile(const std::string& fname, + TransactionToken* token, std::unique_ptr* result) override { return errors::Unimplemented("NewWritableFile unimplemented"); } absl::Status NewAppendableFile( - const string& fname, TransactionToken* token, + const std::string& fname, TransactionToken* token, std::unique_ptr* result) override { return errors::Unimplemented("NewAppendableFile unimplemented"); } absl::Status NewReadOnlyMemoryRegionFromFile( - const string& fname, TransactionToken* token, + const std::string& fname, TransactionToken* token, std::unique_ptr* result) override { return errors::Unimplemented( "NewReadOnlyMemoryRegionFromFile unimplemented"); } - absl::Status FileExists(const string& fname, + absl::Status FileExists(const std::string& fname, TransactionToken* token) override { return errors::Unimplemented("FileExists unimplemented"); } - absl::Status GetChildren(const string& dir, TransactionToken* token, - std::vector* result) override { + absl::Status GetChildren(const std::string& dir, TransactionToken* token, + std::vector* result) override { return errors::Unimplemented("GetChildren unimplemented"); } - absl::Status GetMatchingPaths(const string& pattern, TransactionToken* token, - std::vector* results) override { + absl::Status GetMatchingPaths(const std::string& pattern, + TransactionToken* token, + std::vector* results) override { return internal::GetMatchingPaths(this, Env::Default(), pattern, results); } - absl::Status DeleteFile(const string& fname, + absl::Status DeleteFile(const std::string& fname, TransactionToken* token) override { return errors::Unimplemented("DeleteFile unimplemented"); } - absl::Status CreateDir(const string& dirname, + absl::Status CreateDir(const std::string& dirname, TransactionToken* token) override { return errors::Unimplemented("CreateDir unimplemented"); } - absl::Status DeleteDir(const string& dirname, + absl::Status DeleteDir(const std::string& dirname, TransactionToken* token) override { return errors::Unimplemented("DeleteDir unimplemented"); } - absl::Status GetFileSize(const string& fname, TransactionToken* token, + absl::Status GetFileSize(const std::string& fname, TransactionToken* token, uint64* file_size) override { return errors::Unimplemented("GetFileSize unimplemented"); } - absl::Status RenameFile(const string& src, const string& target, + absl::Status RenameFile(const std::string& src, const std::string& target, TransactionToken* token) override { return errors::Unimplemented("RenameFile unimplemented"); } - absl::Status Stat(const string& fname, TransactionToken* token, + absl::Status Stat(const std::string& fname, TransactionToken* token, FileStatistics* stat) override { return errors::Unimplemented("Stat unimplemented"); } diff --git a/tsl/platform/numbers_test.cc b/tsl/platform/numbers_test.cc index db94c2476..f70727238 100644 --- a/tsl/platform/numbers_test.cc +++ b/tsl/platform/numbers_test.cc @@ -38,7 +38,7 @@ TEST(FpToString, Ints) { for (int s = 0; s < 64; s++) { for (int delta = -1; delta <= 1; delta++) { uint64 fp = (1ull << s) + delta; - string s = FpToString(fp); + std::string s = FpToString(fp); uint64 fp2; EXPECT_TRUE(HexStringToUint64(s, &fp2)); EXPECT_EQ(fp, fp2); diff --git a/tsl/platform/path.cc b/tsl/platform/path.cc index e251972c7..69c4dd8f4 100644 --- a/tsl/platform/path.cc +++ b/tsl/platform/path.cc @@ -46,14 +46,14 @@ namespace { const char kPathSep[] = "/"; } // namespace -string JoinPathImpl(std::initializer_list paths) { - string result; +std::string JoinPathImpl(std::initializer_list paths) { + std::string result; for (absl::string_view path : paths) { if (path.empty()) continue; if (result.empty()) { - result = string(path); + result = std::string(path); continue; } @@ -136,10 +136,10 @@ absl::string_view BasenamePrefix(absl::string_view path) { return internal::SplitBasename(path).first; } -string CleanPath(absl::string_view unclean_path) { - string path(unclean_path); +std::string CleanPath(absl::string_view unclean_path) { + std::string path(unclean_path); const char* src = path.c_str(); - string::iterator dst = path.begin(); + std::string::iterator dst = path.begin(); // Check for absolute path and determine initial backtrack limit. const bool is_absolute_path = *src == '/'; @@ -147,7 +147,7 @@ string CleanPath(absl::string_view unclean_path) { *dst++ = *src++; while (*src == '/') ++src; } - string::const_iterator backtrack_limit = dst; + std::string::const_iterator backtrack_limit = dst; // Process all parts while (*src) { @@ -203,7 +203,7 @@ string CleanPath(absl::string_view unclean_path) { } // Calculate and check the length of the cleaned path. - string::difference_type path_length = dst - path.begin(); + std::string::difference_type path_length = dst - path.begin(); if (path_length != 0) { // Remove trailing '/' except if it is root path ("/" ==> path_length := 1) if (path_length > 1 && path[path_length - 1] == '/') { @@ -249,10 +249,10 @@ void ParseURI(absl::string_view uri, absl::string_view* scheme, *path = uri; } -string CreateURI(absl::string_view scheme, absl::string_view host, - absl::string_view path) { +std::string CreateURI(absl::string_view scheme, absl::string_view host, + absl::string_view path) { if (scheme.empty()) { - return string(path); + return std::string(path); } return absl::StrCat(scheme, "://", host, path); } @@ -265,10 +265,11 @@ int64_t UniqueId() { return ++id; } -string CommonPathPrefix(absl::Span paths) { +std::string CommonPathPrefix(absl::Span paths) { if (paths.empty()) return ""; size_t min_filename_size = - absl::c_min_element(paths, [](const string& a, const string& b) { + absl::c_min_element(paths, [](const std::string& a, + const std::string& b) { return a.size() < b.size(); })->size(); if (min_filename_size == 0) return ""; @@ -294,7 +295,7 @@ string CommonPathPrefix(absl::Span paths) { : std::string(absl::string_view(paths[0]).substr(0, rpos + 1)); } -string GetTempFilename(const string& extension) { +std::string GetTempFilename(const std::string& extension) { #if defined(__ANDROID__) LOG(FATAL) << "GetTempFilename is not implemented in this platform."; #elif defined(PLATFORM_WINDOWS) @@ -325,7 +326,7 @@ string GetTempFilename(const string& extension) { // UniqueId is added here because mkstemps is not as thread safe as it // looks. https://github.com/tensorflow/tensorflow/issues/5804 shows // the problem. - string tmp_filepath; + std::string tmp_filepath; int fd; if (extension.length()) { tmp_filepath = @@ -362,7 +363,7 @@ bool StartsWithSegment(absl::string_view path, absl::string_view segment) { } } // namespace -bool GetTestWorkspaceDir(string* dir) { +bool GetTestWorkspaceDir(std::string* dir) { const char* srcdir = getenv("TEST_SRCDIR"); if (srcdir == nullptr) { return false; @@ -377,7 +378,7 @@ bool GetTestWorkspaceDir(string* dir) { return true; } -bool GetTestUndeclaredOutputsDir(string* dir) { +bool GetTestUndeclaredOutputsDir(std::string* dir) { const char* outputs_dir = getenv("TEST_UNDECLARED_OUTPUTS_DIR"); if (outputs_dir == nullptr) { return false; @@ -388,7 +389,7 @@ bool GetTestUndeclaredOutputsDir(string* dir) { return true; } -bool ResolveTestPrefixes(absl::string_view path, string& resolved_path) { +bool ResolveTestPrefixes(absl::string_view path, std::string& resolved_path) { constexpr absl::string_view kTestWorkspaceSegment = "TEST_WORKSPACE"; constexpr absl::string_view kOutputDirSegment = "TEST_UNDECLARED_OUTPUTS_DIR"; diff --git a/tsl/platform/protobuf_util.cc b/tsl/platform/protobuf_util.cc index 0bab61313..04d9de582 100644 --- a/tsl/platform/protobuf_util.cc +++ b/tsl/platform/protobuf_util.cc @@ -20,7 +20,7 @@ limitations under the License. namespace tsl { bool ParseProtoUnlimited(protobuf::MessageLite* proto, - const string& serialized) { + const std::string& serialized) { return proto->ParseFromString(serialized); } diff --git a/tsl/platform/retrying_file_system.h b/tsl/platform/retrying_file_system.h index 9bf86114d..99262f40d 100644 --- a/tsl/platform/retrying_file_system.h +++ b/tsl/platform/retrying_file_system.h @@ -42,21 +42,22 @@ class RetryingFileSystem : public FileSystem { TF_USE_FILESYSTEM_METHODS_WITH_NO_TRANSACTION_SUPPORT; absl::Status NewRandomAccessFile( - const string& filename, TransactionToken* token, + const std::string& filename, TransactionToken* token, std::unique_ptr* result) override; - absl::Status NewWritableFile(const string& filename, TransactionToken* token, + absl::Status NewWritableFile(const std::string& filename, + TransactionToken* token, std::unique_ptr* result) override; absl::Status NewAppendableFile( - const string& filename, TransactionToken* token, + const std::string& filename, TransactionToken* token, std::unique_ptr* result) override; absl::Status NewReadOnlyMemoryRegionFromFile( - const string& filename, TransactionToken* token, + const std::string& filename, TransactionToken* token, std::unique_ptr* result) override; - absl::Status FileExists(const string& fname, + absl::Status FileExists(const std::string& fname, TransactionToken* token) override { return RetryingUtils::CallWithRetries( [this, &fname, token]() { @@ -65,8 +66,8 @@ class RetryingFileSystem : public FileSystem { retry_config_); } - absl::Status GetChildren(const string& dir, TransactionToken* token, - std::vector* result) override { + absl::Status GetChildren(const std::string& dir, TransactionToken* token, + std::vector* result) override { return RetryingUtils::CallWithRetries( [this, &dir, result, token]() { return base_file_system_->GetChildren(dir, token, result); @@ -74,8 +75,9 @@ class RetryingFileSystem : public FileSystem { retry_config_); } - absl::Status GetMatchingPaths(const string& pattern, TransactionToken* token, - std::vector* result) override { + absl::Status GetMatchingPaths(const std::string& pattern, + TransactionToken* token, + std::vector* result) override { return RetryingUtils::CallWithRetries( [this, &pattern, result, token]() { return base_file_system_->GetMatchingPaths(pattern, token, result); @@ -83,7 +85,7 @@ class RetryingFileSystem : public FileSystem { retry_config_); } - absl::Status Stat(const string& fname, TransactionToken* token, + absl::Status Stat(const std::string& fname, TransactionToken* token, FileStatistics* stat) override { return RetryingUtils::CallWithRetries( [this, &fname, stat, token]() { @@ -92,7 +94,7 @@ class RetryingFileSystem : public FileSystem { retry_config_); } - absl::Status DeleteFile(const string& fname, + absl::Status DeleteFile(const std::string& fname, TransactionToken* token) override { return RetryingUtils::DeleteWithRetries( [this, &fname, token]() { @@ -101,7 +103,7 @@ class RetryingFileSystem : public FileSystem { retry_config_); } - absl::Status CreateDir(const string& dirname, + absl::Status CreateDir(const std::string& dirname, TransactionToken* token) override { return RetryingUtils::CallWithRetries( [this, &dirname, token]() { @@ -110,7 +112,7 @@ class RetryingFileSystem : public FileSystem { retry_config_); } - absl::Status DeleteDir(const string& dirname, + absl::Status DeleteDir(const std::string& dirname, TransactionToken* token) override { return RetryingUtils::DeleteWithRetries( [this, &dirname, token]() { @@ -119,7 +121,7 @@ class RetryingFileSystem : public FileSystem { retry_config_); } - absl::Status GetFileSize(const string& fname, TransactionToken* token, + absl::Status GetFileSize(const std::string& fname, TransactionToken* token, uint64* file_size) override { return RetryingUtils::CallWithRetries( [this, &fname, file_size, token]() { @@ -128,7 +130,7 @@ class RetryingFileSystem : public FileSystem { retry_config_); } - absl::Status RenameFile(const string& src, const string& target, + absl::Status RenameFile(const std::string& src, const std::string& target, TransactionToken* token) override { return RetryingUtils::CallWithRetries( [this, &src, &target, token]() { @@ -137,7 +139,7 @@ class RetryingFileSystem : public FileSystem { retry_config_); } - absl::Status IsDirectory(const string& dirname, + absl::Status IsDirectory(const std::string& dirname, TransactionToken* token) override { return RetryingUtils::CallWithRetries( [this, &dirname, token]() { @@ -146,13 +148,14 @@ class RetryingFileSystem : public FileSystem { retry_config_); } - absl::Status HasAtomicMove(const string& path, + absl::Status HasAtomicMove(const std::string& path, bool* has_atomic_move) override { // this method does not need to be retried return base_file_system_->HasAtomicMove(path, has_atomic_move); } - absl::Status DeleteRecursively(const string& dirname, TransactionToken* token, + absl::Status DeleteRecursively(const std::string& dirname, + TransactionToken* token, int64_t* undeleted_files, int64_t* undeleted_dirs) override { return RetryingUtils::DeleteWithRetries( @@ -248,7 +251,7 @@ class RetryingWritableFile : public WritableFile { template absl::Status RetryingFileSystem::NewRandomAccessFile( - const string& filename, TransactionToken* token, + const std::string& filename, TransactionToken* token, std::unique_ptr* result) { std::unique_ptr base_file; TF_RETURN_IF_ERROR(RetryingUtils::CallWithRetries( @@ -264,7 +267,7 @@ absl::Status RetryingFileSystem::NewRandomAccessFile( template absl::Status RetryingFileSystem::NewWritableFile( - const string& filename, TransactionToken* token, + const std::string& filename, TransactionToken* token, std::unique_ptr* result) { std::unique_ptr base_file; TF_RETURN_IF_ERROR(RetryingUtils::CallWithRetries( @@ -279,7 +282,7 @@ absl::Status RetryingFileSystem::NewWritableFile( template absl::Status RetryingFileSystem::NewAppendableFile( - const string& filename, TransactionToken* token, + const std::string& filename, TransactionToken* token, std::unique_ptr* result) { std::unique_ptr base_file; TF_RETURN_IF_ERROR(RetryingUtils::CallWithRetries( @@ -295,7 +298,7 @@ absl::Status RetryingFileSystem::NewAppendableFile( template absl::Status RetryingFileSystem::NewReadOnlyMemoryRegionFromFile( - const string& filename, TransactionToken* token, + const std::string& filename, TransactionToken* token, std::unique_ptr* result) { return RetryingUtils::CallWithRetries( [this, &filename, result, token]() { diff --git a/tsl/platform/retrying_file_system_test.cc b/tsl/platform/retrying_file_system_test.cc index d60a34445..1862a6ebd 100644 --- a/tsl/platform/retrying_file_system_test.cc +++ b/tsl/platform/retrying_file_system_test.cc @@ -24,9 +24,9 @@ limitations under the License. namespace tsl { namespace { -typedef std::vector> ExpectedCalls; +typedef std::vector> ExpectedCalls; -ExpectedCalls CreateRetriableErrors(const string& method, int n) { +ExpectedCalls CreateRetriableErrors(const std::string& method, int n) { ExpectedCalls expected_calls; expected_calls.reserve(n); for (int i = 0; i < n; i++) { @@ -47,7 +47,7 @@ class MockCallSequence { << "the next expected call: " << std::get<0>(calls_.front()); } - absl::Status ConsumeNextCall(const string& method) { + absl::Status ConsumeNextCall(const std::string& method) { EXPECT_FALSE(calls_.empty()) << "No more calls were expected."; auto call = calls_.front(); calls_.erase(calls_.begin()); @@ -102,82 +102,84 @@ class MockFileSystem : public FileSystem { TF_USE_FILESYSTEM_METHODS_WITH_NO_TRANSACTION_SUPPORT; absl::Status NewRandomAccessFile( - const string& fname, TransactionToken* token, + const std::string& fname, TransactionToken* token, std::unique_ptr* result) override { *result = std::move(random_access_file_to_return); return calls_.ConsumeNextCall("NewRandomAccessFile"); } - absl::Status NewWritableFile(const string& fname, TransactionToken* token, + absl::Status NewWritableFile(const std::string& fname, + TransactionToken* token, std::unique_ptr* result) override { *result = std::move(writable_file_to_return); return calls_.ConsumeNextCall("NewWritableFile"); } absl::Status NewAppendableFile( - const string& fname, TransactionToken* token, + const std::string& fname, TransactionToken* token, std::unique_ptr* result) override { *result = std::move(writable_file_to_return); return calls_.ConsumeNextCall("NewAppendableFile"); } absl::Status NewReadOnlyMemoryRegionFromFile( - const string& fname, TransactionToken* token, + const std::string& fname, TransactionToken* token, std::unique_ptr* result) override { return calls_.ConsumeNextCall("NewReadOnlyMemoryRegionFromFile"); } - absl::Status FileExists(const string& fname, + absl::Status FileExists(const std::string& fname, TransactionToken* token) override { return calls_.ConsumeNextCall("FileExists"); } - absl::Status GetChildren(const string& dir, TransactionToken* token, - std::vector* result) override { + absl::Status GetChildren(const std::string& dir, TransactionToken* token, + std::vector* result) override { return calls_.ConsumeNextCall("GetChildren"); } - absl::Status GetMatchingPaths(const string& dir, TransactionToken* token, - std::vector* result) override { + absl::Status GetMatchingPaths(const std::string& dir, TransactionToken* token, + std::vector* result) override { return calls_.ConsumeNextCall("GetMatchingPaths"); } - absl::Status Stat(const string& fname, TransactionToken* token, + absl::Status Stat(const std::string& fname, TransactionToken* token, FileStatistics* stat) override { return calls_.ConsumeNextCall("Stat"); } - absl::Status DeleteFile(const string& fname, + absl::Status DeleteFile(const std::string& fname, TransactionToken* token) override { return calls_.ConsumeNextCall("DeleteFile"); } - absl::Status CreateDir(const string& dirname, + absl::Status CreateDir(const std::string& dirname, TransactionToken* token) override { return calls_.ConsumeNextCall("CreateDir"); } - absl::Status DeleteDir(const string& dirname, + absl::Status DeleteDir(const std::string& dirname, TransactionToken* token) override { return calls_.ConsumeNextCall("DeleteDir"); } - absl::Status GetFileSize(const string& fname, TransactionToken* token, + absl::Status GetFileSize(const std::string& fname, TransactionToken* token, uint64* file_size) override { return calls_.ConsumeNextCall("GetFileSize"); } - absl::Status RenameFile(const string& src, const string& target, + absl::Status RenameFile(const std::string& src, const std::string& target, TransactionToken* token) override { return calls_.ConsumeNextCall("RenameFile"); } - absl::Status IsDirectory(const string& dirname, + absl::Status IsDirectory(const std::string& dirname, TransactionToken* token) override { return calls_.ConsumeNextCall("IsDirectory"); } - absl::Status DeleteRecursively(const string& dirname, TransactionToken* token, + absl::Status DeleteRecursively(const std::string& dirname, + TransactionToken* token, int64_t* undeleted_files, int64_t* undeleted_dirs) override { return calls_.ConsumeNextCall("DeleteRecursively"); @@ -496,7 +498,7 @@ TEST(RetryingFileSystemTest, GetChildren_SuccessWith2ndTry) { RetryingFileSystem fs( std::move(base_fs), RetryConfig(0 /* init_delay_time_us */)); - std::vector result; + std::vector result; TF_EXPECT_OK(fs.GetChildren("gs://path", nullptr, &result)); } @@ -507,7 +509,7 @@ TEST(RetryingFileSystemTest, GetChildren_AllRetriesFailed) { RetryingFileSystem fs( std::move(base_fs), RetryConfig(0 /* init_delay_time_us */)); - std::vector result; + std::vector result; const auto& status = fs.GetChildren("gs://path", nullptr, &result); EXPECT_TRUE(absl::StrContains(status.message(), "Retriable error #10")) << status; @@ -523,7 +525,7 @@ TEST(RetryingFileSystemTest, GetMatchingPaths_SuccessWith2ndTry) { RetryingFileSystem fs( std::move(base_fs), RetryConfig(0 /* init_delay_time_us */)); - std::vector result; + std::vector result; TF_EXPECT_OK(fs.GetMatchingPaths("gs://path/dir", nullptr, &result)); } @@ -535,7 +537,7 @@ TEST(RetryingFileSystemTest, GetMatchingPaths_AllRetriesFailed) { RetryingFileSystem fs( std::move(base_fs), RetryConfig(0 /* init_delay_time_us */)); - std::vector result; + std::vector result; const auto& status = fs.GetMatchingPaths("gs://path/dir", nullptr, &result); EXPECT_TRUE(absl::StrContains(status.message(), "Retriable error #10")) << status; diff --git a/tsl/platform/scanner_test.cc b/tsl/platform/scanner_test.cc index dead6fb18..1439b3358 100644 --- a/tsl/platform/scanner_test.cc +++ b/tsl/platform/scanner_test.cc @@ -23,8 +23,8 @@ namespace strings { class ScannerTest : public ::testing::Test { protected: // Returns a string with all chars that are in , in byte value order. - string ClassStr(Scanner::CharClass clz) { - string s; + std::string ClassStr(Scanner::CharClass clz) { + std::string s; for (int i = 0; i < 256; ++i) { char ch = i; if (Scanner::Matches(clz, ch)) { diff --git a/tsl/platform/snappy.h b/tsl/platform/snappy.h index d2acb8879..3954df98d 100644 --- a/tsl/platform/snappy.h +++ b/tsl/platform/snappy.h @@ -16,6 +16,8 @@ limitations under the License. #ifndef TENSORFLOW_TSL_PLATFORM_SNAPPY_H_ #define TENSORFLOW_TSL_PLATFORM_SNAPPY_H_ +#include + #include "xla/tsl/platform/types.h" #if !defined(PLATFORM_WINDOWS) @@ -36,10 +38,10 @@ namespace tsl { namespace port { // Snappy compression/decompression support -bool Snappy_Compress(const char* input, size_t length, string* output); +bool Snappy_Compress(const char* input, size_t length, std::string* output); bool Snappy_CompressFromIOVec(const struct iovec* iov, - size_t uncompressed_length, string* output); + size_t uncompressed_length, std::string* output); bool Snappy_GetUncompressedLength(const char* input, size_t length, size_t* result); diff --git a/tsl/platform/str_util.cc b/tsl/platform/str_util.cc index 9a275de74..df9ceb89c 100644 --- a/tsl/platform/str_util.cc +++ b/tsl/platform/str_util.cc @@ -83,9 +83,9 @@ bool ConsumeNonWhitespace(absl::string_view* s, absl::string_view* val) { } } -void TitlecaseString(string* s, absl::string_view delimiters) { +void TitlecaseString(std::string* s, absl::string_view delimiters) { bool upper = true; - for (string::iterator ss = s->begin(); ss != s->end(); ++ss) { + for (std::string::iterator ss = s->begin(); ss != s->end(); ++ss) { if (upper) { *ss = absl::ascii_toupper(*ss); } @@ -93,13 +93,14 @@ void TitlecaseString(string* s, absl::string_view delimiters) { } } -string StringReplace(absl::string_view s, absl::string_view oldsub, - absl::string_view newsub, bool replace_all) { +std::string StringReplace(absl::string_view s, absl::string_view oldsub, + absl::string_view newsub, bool replace_all) { // TODO(jlebar): We could avoid having to shift data around in the string if // we had a StringPiece::find() overload that searched for a StringPiece. - string res(s); + std::string res(s); size_t pos = 0; - while ((pos = res.find(oldsub.data(), pos, oldsub.size())) != string::npos) { + while ((pos = res.find(oldsub.data(), pos, oldsub.size())) != + std::string::npos) { res.replace(pos, oldsub.size(), newsub.data(), newsub.size()); pos += newsub.size(); if (oldsub.empty()) { @@ -112,7 +113,7 @@ string StringReplace(absl::string_view s, absl::string_view oldsub, return res; } -string ArgDefCase(absl::string_view s) { +std::string ArgDefCase(absl::string_view s) { const size_t n = s.size(); // Compute the size of resulting string. @@ -139,7 +140,7 @@ string ArgDefCase(absl::string_view s) { // Initialize result with all '_'s. There is no string // constructor that does not initialize memory. - string result(n + extra_us - to_skip, '_'); + std::string result(n + extra_us - to_skip, '_'); // i - index into s // j - index into result for (size_t i = to_skip, j = 0; i < n; ++i, ++j) { diff --git a/tsl/platform/str_util.h b/tsl/platform/str_util.h index 0242ff350..ca9a1fb1d 100644 --- a/tsl/platform/str_util.h +++ b/tsl/platform/str_util.h @@ -165,26 +165,29 @@ struct SkipWhitespace { // Split strings using any of the supplied delimiters. For example: // Split("a,b.c,d", ".,") would return {"a", "b", "c", "d"}. -inline std::vector Split(absl::string_view text, - absl::string_view delims) { - return text.empty() ? std::vector() +inline std::vector Split(absl::string_view text, + absl::string_view delims) { + return text.empty() ? std::vector() : absl::StrSplit(text, absl::ByAnyChar(delims)); } template -std::vector Split(absl::string_view text, absl::string_view delims, - Predicate p) { - return text.empty() ? std::vector() +std::vector Split(absl::string_view text, absl::string_view delims, + Predicate p) { + return text.empty() ? std::vector() : absl::StrSplit(text, absl::ByAnyChar(delims), p); } -inline std::vector Split(absl::string_view text, char delim) { - return text.empty() ? std::vector() : absl::StrSplit(text, delim); +inline std::vector Split(absl::string_view text, char delim) { + return text.empty() ? std::vector() + : absl::StrSplit(text, delim); } template -std::vector Split(absl::string_view text, char delim, Predicate p) { - return text.empty() ? std::vector() : absl::StrSplit(text, delim, p); +std::vector Split(absl::string_view text, char delim, + Predicate p) { + return text.empty() ? std::vector() + : absl::StrSplit(text, delim, p); } // StartsWith() diff --git a/tsl/platform/str_util_test.cc b/tsl/platform/str_util_test.cc index 4a2e14dd1..fbcad13fa 100644 --- a/tsl/platform/str_util_test.cc +++ b/tsl/platform/str_util_test.cc @@ -29,9 +29,9 @@ TEST(CEscape, Basic) { EXPECT_EQ(absl::CEscape("\320hi\200"), "\\320hi\\200"); } -string ExpectCUnescapeSuccess(absl::string_view source) { - string dest; - string error; +std::string ExpectCUnescapeSuccess(absl::string_view source) { + std::string dest; + std::string error; EXPECT_TRUE(absl::CUnescape(source, &dest, &error)) << error; return dest; } @@ -45,11 +45,11 @@ TEST(CUnescape, Basic) { } TEST(CUnescape, HandlesCopyOnWriteStrings) { - string dest = "hello"; - string read = dest; + std::string dest = "hello"; + std::string read = dest; // For std::string, read and dest now share the same buffer. - string error; + std::string error; absl::string_view source = "llohe"; // CUnescape is going to write "llohe" to dest, so dest's buffer will be // reallocated, and read's buffer remains untouched. @@ -58,7 +58,7 @@ TEST(CUnescape, HandlesCopyOnWriteStrings) { } TEST(StripTrailingWhitespace, Basic) { - string test; + std::string test; test = "hello"; absl::StripTrailingAsciiWhitespace(&test); EXPECT_EQ(test, "hello"); @@ -81,7 +81,7 @@ TEST(StripTrailingWhitespace, Basic) { } TEST(RemoveLeadingWhitespace, Basic) { - string text = " \t \n \r Quick\t"; + std::string text = " \t \n \r Quick\t"; absl::string_view data(text); // check that all whitespace is removed EXPECT_EQ(str_util::RemoveLeadingWhitespace(&data), 11); @@ -93,7 +93,7 @@ TEST(RemoveLeadingWhitespace, Basic) { TEST(RemoveLeadingWhitespace, TerminationHandling) { // check termination handling - string text = "\t"; + std::string text = "\t"; absl::string_view data(text); EXPECT_EQ(str_util::RemoveLeadingWhitespace(&data), 1); EXPECT_EQ(data, absl::string_view("")); @@ -104,7 +104,7 @@ TEST(RemoveLeadingWhitespace, TerminationHandling) { } TEST(RemoveTrailingWhitespace, Basic) { - string text = " \t \n \r Quick \t"; + std::string text = " \t \n \r Quick \t"; absl::string_view data(text); // check that all whitespace is removed EXPECT_EQ(str_util::RemoveTrailingWhitespace(&data), 2); @@ -116,7 +116,7 @@ TEST(RemoveTrailingWhitespace, Basic) { TEST(RemoveTrailingWhitespace, TerminationHandling) { // check termination handling - string text = "\t"; + std::string text = "\t"; absl::string_view data(text); EXPECT_EQ(str_util::RemoveTrailingWhitespace(&data), 1); EXPECT_EQ(data, absl::string_view("")); @@ -127,7 +127,7 @@ TEST(RemoveTrailingWhitespace, TerminationHandling) { } TEST(RemoveWhitespaceContext, Basic) { - string text = " \t \n \r Quick \t"; + std::string text = " \t \n \r Quick \t"; absl::string_view data(text); // check that all whitespace is removed EXPECT_EQ(str_util::RemoveWhitespaceContext(&data), 13); @@ -200,7 +200,7 @@ TEST(ConsumeNonWhitespace, Basic) { } TEST(ConsumePrefix, Basic) { - string s("abcdef"); + std::string s("abcdef"); absl::string_view input(s); EXPECT_FALSE(absl::ConsumePrefix(&input, "abcdefg")); EXPECT_EQ(input, "abcdef"); @@ -232,7 +232,7 @@ TEST(StripPrefix, Basic) { } TEST(JoinStrings, Basic) { - std::vector s; + std::vector s; s = {"hi"}; EXPECT_EQ(absl::StrJoin(s, " "), "hi"); s = {"hi", "there", "strings"}; @@ -246,12 +246,12 @@ TEST(JoinStrings, Basic) { } TEST(JoinStrings, Join3) { - std::vector s; + std::vector s; s = {"hi"}; - auto l1 = [](string* out, string s) { *out += s; }; + auto l1 = [](std::string* out, std::string s) { *out += s; }; EXPECT_EQ(str_util::Join(s, " ", l1), "hi"); s = {"hi", "there", "strings"}; - auto l2 = [](string* out, string s) { *out += s[0]; }; + auto l2 = [](std::string* out, std::string s) { *out += s[0]; }; EXPECT_EQ(str_util::Join(s, " ", l2), "h t s"); } @@ -321,7 +321,7 @@ TEST(SnakeCase, Basic) { } TEST(TitlecaseString, Basic) { - string s = "sparse_lookup"; + std::string s = "sparse_lookup"; str_util::TitlecaseString(&s, "_"); ASSERT_EQ(s, "Sparse_Lookup"); diff --git a/tsl/platform/stringpiece_test.cc b/tsl/platform/stringpiece_test.cc index f50c1275e..e1ef51cde 100644 --- a/tsl/platform/stringpiece_test.cc +++ b/tsl/platform/stringpiece_test.cc @@ -41,7 +41,7 @@ TEST(StringPiece, Ctor) { } { - string hola = "hola"; + std::string hola = "hola"; absl::string_view s30(hola); EXPECT_TRUE(s30.data() == hola.data()); EXPECT_EQ(4, s30.size()); @@ -57,8 +57,8 @@ TEST(StringPiece, Ctor) { } TEST(StringPiece, ConversionToString) { - EXPECT_EQ("", string(absl::string_view(""))); - EXPECT_EQ("foo", string(absl::string_view("foo"))); + EXPECT_EQ("", std::string(absl::string_view(""))); + EXPECT_EQ("foo", std::string(absl::string_view("foo"))); } } // namespace tsl diff --git a/tsl/platform/stringprintf_test.cc b/tsl/platform/stringprintf_test.cc index 94cfd688f..b88e91c5e 100644 --- a/tsl/platform/stringprintf_test.cc +++ b/tsl/platform/stringprintf_test.cc @@ -24,7 +24,7 @@ namespace strings { namespace { TEST(PrintfTest, Empty) { - EXPECT_EQ("", Printf("%s", string().c_str())); + EXPECT_EQ("", Printf("%s", std::string().c_str())); EXPECT_EQ("", Printf("%s", "")); } @@ -36,26 +36,26 @@ TEST(PrintfTest, Misc) { } TEST(AppendfTest, Empty) { - string value("Hello"); + std::string value("Hello"); const char* empty = ""; Appendf(&value, "%s", empty); EXPECT_EQ("Hello", value); } TEST(AppendfTest, EmptyString) { - string value("Hello"); + std::string value("Hello"); Appendf(&value, "%s", ""); EXPECT_EQ("Hello", value); } TEST(AppendfTest, String) { - string value("Hello"); + std::string value("Hello"); Appendf(&value, " %s", "World"); EXPECT_EQ("Hello World", value); } TEST(AppendfTest, Int) { - string value("Hello"); + std::string value("Hello"); Appendf(&value, " %d", 123); EXPECT_EQ("Hello 123", value); } @@ -71,7 +71,7 @@ TEST(PrintfTest, Multibyte) { setlocale(LC_CTYPE, "en_US.utf8"); const char kInvalidCodePoint[] = "\375\067s"; - string value = Printf("%.*s", 3, kInvalidCodePoint); + std::string value = Printf("%.*s", 3, kInvalidCodePoint); // In some versions of glibc (e.g. eglibc-2.11.1, aka GRTEv2), snprintf // returns error given an invalid codepoint. Other versions @@ -97,7 +97,7 @@ TEST(PrintfTest, NoMultibyte) { // No multibyte handling, but the string contains funny chars. char* old_locale = setlocale(LC_CTYPE, nullptr); setlocale(LC_CTYPE, "POSIX"); - string value = Printf("%.*s", 3, "\375\067s"); + std::string value = Printf("%.*s", 3, "\375\067s"); setlocale(LC_CTYPE, old_locale); EXPECT_EQ("\375\067s", value); } @@ -107,7 +107,7 @@ TEST(PrintfTest, DontOverwriteErrno) { // something significantly larger than what people are normally // printing in their badly written PLOG() statements. errno = ECHILD; - string value = Printf("Hello, %s!", "World"); + std::string value = Printf("Hello, %s!", "World"); EXPECT_EQ(ECHILD, errno); } @@ -117,7 +117,7 @@ TEST(PrintfTest, LargeBuf) { char* buf = new char[n + 1]; memset(buf, ' ', n); buf[n] = 0; - string value = Printf("%s", buf); + std::string value = Printf("%s", buf); EXPECT_EQ(buf, value); delete[] buf; }