From 44cc6fc3b77725e4e8291f188ebcf54d6efa0ad4 Mon Sep 17 00:00:00 2001 From: Max Zhang Date: Thu, 16 Nov 2023 15:18:32 -0800 Subject: [PATCH] WIP: Deprecate SbStringFormat functions Replace SbStringFormat*() calls with POSIX vsnprintf(). SbStringFormat -> vsnprintf SbStringFormatF -> snprintf SbStringFormatWide -> vswprintf SbStringFormatUnsafeF -> sprintf Backward compatibility is protected by "SB_API_VERSION < 16". Tested on Linux, Android, Evergreen, Win32 b/307941391 Change-Id: I437ff3d7bf735b46767867ea844aeffb28e58b4d --- base/strings/string_util.h | 3 ++- base/strings/string_util_starboard.h | 15 ----------- base/strings/stringprintf.cc | 2 +- base/strings/stringprintf_unittest.cc | 2 +- ...eap_profiler_allocation_context_tracker.cc | 2 +- .../browser/memory_settings/pretty_print.cc | 2 +- .../trust_store_in_memory_starboard.cc | 2 +- .../android/shared/system_get_property.cc | 4 +-- starboard/client_porting/poem/stdio_poem.h | 6 ----- starboard/client_porting/poem/wchar_poem.h | 3 --- starboard/common/string.h | 5 ++-- starboard/elf_loader/exported_symbols.cc | 3 +-- starboard/linux/shared/system_get_path.cc | 11 ++++---- starboard/loader_app/installation_manager.cc | 25 +++++++++---------- starboard/loader_app/slot_management.cc | 18 ++++++------- starboard/nplb/BUILD.gn | 2 ++ starboard/nplb/string_format_test.cc | 2 +- starboard/nplb/string_format_wide_test.cc | 2 ++ .../ffmpeg_dynamic_load_dispatch_impl.cc | 2 +- starboard/shared/posix/string_format.cc | 2 ++ starboard/shared/posix/string_format_wide.cc | 2 ++ starboard/shared/starboard/link_receiver.cc | 2 +- starboard/shared/starboard/log_raw_format.cc | 3 ++- starboard/shared/stub/string_format.cc | 2 ++ starboard/shared/stub/string_format_wide.cc | 2 ++ starboard/shared/win32/string_format.cc | 2 ++ starboard/shared/win32/string_format_wide.cc | 2 ++ starboard/string.h | 12 ++++++--- .../boringssl/src/crypto/mem_starboard.c | 2 +- .../src/colorprint_starboard.cc | 5 ++-- .../include/gtest/internal/gtest-port.h | 3 ++- third_party/harfbuzz-ng/src/hb-starboard.hh | 1 - .../base/strings/stringprintf.cc | 2 +- third_party/musl/BUILD.gn | 4 +-- .../musl/src/starboard/stdio/vsnprintf.c | 6 ----- .../musl/src/starboard/stdio/vswprintf.c | 6 ----- .../src/google/protobuf/stubs/common.cc | 1 - .../src/google/protobuf/stubs/strutil.cc | 13 ++++------ .../src/base/platform/platform-starboard.cc | 4 ++- url/url_canon_etc.cc | 2 +- url/url_canon_internal.cc | 2 +- url/url_canon_ip.cc | 4 +-- 42 files changed, 88 insertions(+), 107 deletions(-) delete mode 100644 third_party/musl/src/starboard/stdio/vsnprintf.c delete mode 100644 third_party/musl/src/starboard/stdio/vswprintf.c diff --git a/base/strings/string_util.h b/base/strings/string_util.h index b3d48548b4e0..31975a4ec978 100644 --- a/base/strings/string_util.h +++ b/base/strings/string_util.h @@ -9,6 +9,7 @@ #include #include // va_list +#include #include #include @@ -47,7 +48,7 @@ inline int snprintf(char* buffer, ...) { va_list arguments; va_start(arguments, format); - int result = vsnprintf(buffer, size, format, arguments); + int result = ::vsnprintf(buffer, size, format, arguments); va_end(arguments); return result; } diff --git a/base/strings/string_util_starboard.h b/base/strings/string_util_starboard.h index 6bb3f65b7e29..ffb5793941b8 100644 --- a/base/strings/string_util_starboard.h +++ b/base/strings/string_util_starboard.h @@ -33,15 +33,6 @@ inline int strncasecmp(const char* string1, const char* string2, size_t count) { return SbStringCompareNoCaseN(string1, string2, count); } -#if defined(vsnprintf) -#undef vsnprintf -#endif - -inline int vsnprintf(char* buffer, size_t size, - const char* format, va_list arguments) { - return SbStringFormat(buffer, size, format, arguments); -} - inline int strncmp16(const char16* s1, const char16* s2, size_t count) { #if defined(WCHAR_T_IS_UTF16) return wcsncmp(s1, s2, count); @@ -50,12 +41,6 @@ inline int strncmp16(const char16* s1, const char16* s2, size_t count) { #endif } -inline int vswprintf(wchar_t* buffer, size_t size, - const wchar_t* format, va_list arguments) { - DCHECK(base::IsWprintfFormatPortable(format)); - return SbStringFormatWide(buffer, size, format, arguments); -} - } // namespace base #endif // BASE_STRING_UTIL_STARBOARD_H_ diff --git a/base/strings/stringprintf.cc b/base/strings/stringprintf.cc index c260b9ce0542..f371b37d81df 100644 --- a/base/strings/stringprintf.cc +++ b/base/strings/stringprintf.cc @@ -29,7 +29,7 @@ inline int vsnprintfT(char* buffer, size_t buf_size, const char* format, va_list argptr) { - return base::vsnprintf(buffer, buf_size, format, argptr); + return ::vsnprintf(buffer, buf_size, format, argptr); } #if defined(OS_WIN) diff --git a/base/strings/stringprintf_unittest.cc b/base/strings/stringprintf_unittest.cc index ad617ed5f74c..d31916a3562e 100644 --- a/base/strings/stringprintf_unittest.cc +++ b/base/strings/stringprintf_unittest.cc @@ -120,7 +120,7 @@ TEST(StringPrintfTest, Grow) { const int kRefSize = 320000; char* ref = new char[kRefSize]; #if defined(STARBOARD) - SbStringFormatF(ref, kRefSize, fmt, src, src, src, src, src, src, src); + snprintf(ref, kRefSize, fmt, src, src, src, src, src, src, src); #else #if defined(OS_WIN) sprintf_s(ref, kRefSize, fmt, src, src, src, src, src, src, src); diff --git a/base/trace_event/heap_profiler_allocation_context_tracker.cc b/base/trace_event/heap_profiler_allocation_context_tracker.cc index a2725dc4d893..c8bed1bcf8a5 100644 --- a/base/trace_event/heap_profiler_allocation_context_tracker.cc +++ b/base/trace_event/heap_profiler_allocation_context_tracker.cc @@ -71,7 +71,7 @@ const char* GetAndLeakThreadName() { #endif // defined(OS_LINUX) || defined(OS_ANDROID) // Use tid if we don't have a thread name. - SbStringFormatF(name, sizeof(name), "%lu", + snprintf(name, sizeof(name), "%lu", static_cast(PlatformThread::CurrentId())); return strdup(name); } diff --git a/cobalt/browser/memory_settings/pretty_print.cc b/cobalt/browser/memory_settings/pretty_print.cc index 4dd633b2f467..1449c7930e9b 100644 --- a/cobalt/browser/memory_settings/pretty_print.cc +++ b/cobalt/browser/memory_settings/pretty_print.cc @@ -149,7 +149,7 @@ std::string ToMegabyteString(int64_t bytes, int decimal_places) { ss_fmt << "%." << decimal_places << "f MB"; char buff[128]; - SbStringFormatF(buff, sizeof(buff), ss_fmt.str().c_str(), megabytes); + snprintf(buff, sizeof(buff), ss_fmt.str().c_str(), megabytes); // Use 16 return std::string(buff); } diff --git a/net/cert/internal/trust_store_in_memory_starboard.cc b/net/cert/internal/trust_store_in_memory_starboard.cc index 53e5f790e395..52638f7b0442 100644 --- a/net/cert/internal/trust_store_in_memory_starboard.cc +++ b/net/cert/internal/trust_store_in_memory_starboard.cc @@ -95,7 +95,7 @@ scoped_refptr TrustStoreInMemoryStarboard::TryLoadCert( const base::StringPiece& cert_name) const { auto hash = CertNameHash(cert_name.data(), cert_name.length()); char cert_file_name[256]; - SbStringFormatF(cert_file_name, 256, "%08lx.%d", hash, 0); + snprintf(cert_file_name, 256, "%08lx.%d", hash, 0); if (trusted_cert_names_on_disk_.find(cert_file_name) == trusted_cert_names_on_disk_.end()) { diff --git a/starboard/android/shared/system_get_property.cc b/starboard/android/shared/system_get_property.cc index 9a8827164bd8..ea41eb10b1be 100644 --- a/starboard/android/shared/system_get_property.cc +++ b/starboard/android/shared/system_get_property.cc @@ -77,8 +77,8 @@ bool CopyAndroidPlatformName(char* out_value, int value_length) { } char result_string[kStringBufferSize]; - SbStringFormatF(result_string, kStringBufferSize, kPlatformNameFormat, - version_string_buffer); + snprintf(result_string, kStringBufferSize, kPlatformNameFormat, + version_string_buffer); return CopyStringAndTestIfSuccess(out_value, value_length, result_string); } diff --git a/starboard/client_porting/poem/stdio_poem.h b/starboard/client_porting/poem/stdio_poem.h index deddeefc2f12..be9c95ef14d5 100644 --- a/starboard/client_porting/poem/stdio_poem.h +++ b/starboard/client_porting/poem/stdio_poem.h @@ -27,12 +27,6 @@ // the following functions can have variable number of arguments // and, out of compatibility concerns, we chose to not use // __VA_ARGS__ functionality. -#undef vsnprintf -#define vsnprintf SbStringFormat -#undef snprintf -#define snprintf SbStringFormatF -#undef sprintf -#define sprintf SbStringFormatUnsafeF #undef vsscanf #define vsscanf SbStringScan #undef sscanf diff --git a/starboard/client_porting/poem/wchar_poem.h b/starboard/client_porting/poem/wchar_poem.h index 41ca02865b3b..4d89eca54738 100644 --- a/starboard/client_porting/poem/wchar_poem.h +++ b/starboard/client_porting/poem/wchar_poem.h @@ -23,9 +23,6 @@ #include "starboard/string.h" -#undef vswprintf -#define vswprintf SbStringFormatWide - #endif // POEM_NO_EMULATION #endif // STARBOARD diff --git a/starboard/common/string.h b/starboard/common/string.h index 3e80e46b5fc5..975fdf48a908 100644 --- a/starboard/common/string.h +++ b/starboard/common/string.h @@ -20,6 +20,7 @@ #define STARBOARD_COMMON_STRING_H_ #include +#include #include #include #include @@ -35,7 +36,7 @@ SB_C_INLINE std::string FormatString(const char* format, ...) SB_C_INLINE std::string FormatString(const char* format, ...) { va_list arguments; va_start(arguments, format); - int expected_size = ::SbStringFormat(NULL, 0, format, arguments); + int expected_size = vsnprintf(NULL, 0, format, arguments); va_end(arguments); std::string result; @@ -45,7 +46,7 @@ SB_C_INLINE std::string FormatString(const char* format, ...) { std::vector buffer(expected_size + 1); va_start(arguments, format); - ::SbStringFormat(buffer.data(), buffer.size(), format, arguments); + vsnprintf(buffer.data(), buffer.size(), format, arguments); va_end(arguments); return std::string(buffer.data(), expected_size); } diff --git a/starboard/elf_loader/exported_symbols.cc b/starboard/elf_loader/exported_symbols.cc index d3bb80696d95..8327cefb502a 100644 --- a/starboard/elf_loader/exported_symbols.cc +++ b/starboard/elf_loader/exported_symbols.cc @@ -308,10 +308,9 @@ ExportedSymbols::ExportedSymbols() { #if SB_API_VERSION < 16 REGISTER_SYMBOL(SbStringDuplicate); -#endif // #if SB_API_VERSION < 16 - REGISTER_SYMBOL(SbStringFormat); REGISTER_SYMBOL(SbStringFormatWide); +#endif REGISTER_SYMBOL(SbStringScan); REGISTER_SYMBOL(SbSystemBreakIntoDebugger); REGISTER_SYMBOL(SbSystemClearLastError); diff --git a/starboard/linux/shared/system_get_path.cc b/starboard/linux/shared/system_get_path.cc index eb193f6831c5..3992280f2771 100644 --- a/starboard/linux/shared/system_get_path.cc +++ b/starboard/linux/shared/system_get_path.cc @@ -41,8 +41,7 @@ bool GetCacheDirectory(char* out_path, int path_size) { kMaxPathSize)) { return false; } - int result = - SbStringFormatF(out_path, path_size, "%s/.cache", home_path.data()); + int result = snprintf(out_path, path_size, "%s/.cache", home_path.data()); if (result < 0 || result >= path_size) { out_path[0] = '\0'; return false; @@ -57,8 +56,8 @@ bool GetStorageDirectory(char* out_path, int path_size) { kMaxPathSize)) { return false; } - int result = SbStringFormatF(out_path, path_size, "%s/.cobalt_storage", - home_path.data()); + int result = + snprintf(out_path, path_size, "%s/.cobalt_storage", home_path.data()); if (result < 0 || result >= path_size) { out_path[0] = '\0'; return false; @@ -159,8 +158,8 @@ bool GetTemporaryDirectory(char* out_path, int path_size) { return false; } - int result = SbStringFormatF(out_path, path_size, "/tmp/%s-%d", - binary_name.data(), static_cast(getpid())); + int result = snprintf(out_path, path_size, "/tmp/%s-%d", binary_name.data(), + static_cast(getpid())); if (result < 0 || result >= path_size) { out_path[0] = '\0'; return false; diff --git a/starboard/loader_app/installation_manager.cc b/starboard/loader_app/installation_manager.cc index 6228d9e79870..354fef637009 100644 --- a/starboard/loader_app/installation_manager.cc +++ b/starboard/loader_app/installation_manager.cc @@ -201,18 +201,17 @@ std::string InstallationManager::DumpInstallationSlots() { out << "size="; const int kBufSize = 50; char buf_num[kBufSize]; - SbStringFormatF(buf_num, kBufSize, "%d", - installation_store_.installations_size()); + snprintf(buf_num, kBufSize, "%d", installation_store_.installations_size()); out << buf_num; out << " roll_forward_to_installation="; - SbStringFormatF(buf_num, kBufSize, "%d", - installation_store_.roll_forward_to_installation()); + snprintf(buf_num, kBufSize, "%d", + installation_store_.roll_forward_to_installation()); out << buf_num; out << ";"; for (int i = 0; i < installation_store_.installations_size(); i++) { out << " installation_"; - SbStringFormatF(buf_num, kBufSize, "%d", i); + snprintf(buf_num, kBufSize, "%d", i); out << buf_num; out << " is_successful="; if (installation_store_.installations(i).is_successful()) { @@ -222,13 +221,13 @@ std::string InstallationManager::DumpInstallationSlots() { } out << " num_tries_left="; - SbStringFormatF(buf_num, kBufSize, "%d", - installation_store_.installations(i).num_tries_left()); + snprintf(buf_num, kBufSize, "%d", + installation_store_.installations(i).num_tries_left()); out << buf_num; out << " priority="; - SbStringFormatF(buf_num, kBufSize, "%d", - installation_store_.installations(i).priority()); + snprintf(buf_num, kBufSize, "%d", + installation_store_.installations(i).priority()); out << buf_num; out << ";"; } @@ -686,11 +685,11 @@ bool InstallationManager::GetInstallationPathInternal(int installation_index, // SLOT_0 is placed in |kSbSystemPathContentDirectory|, under the subdirectory // 'app/cobalt'. if (installation_index == 0) { - SbStringFormatF(path, path_length, "%s%s%s%s%s", content_dir_.c_str(), - kSbFileSepString, "app", kSbFileSepString, "cobalt"); + snprintf(path, path_length, "%s%s%s%s%s", content_dir_.c_str(), + kSbFileSepString, "app", kSbFileSepString, "cobalt"); } else { - SbStringFormatF(path, path_length, "%s%s%s%d", storage_dir_.c_str(), - kSbFileSepString, "installation_", installation_index); + snprintf(path, path_length, "%s%s%s%d", storage_dir_.c_str(), + kSbFileSepString, "installation_", installation_index); } return true; diff --git a/starboard/loader_app/slot_management.cc b/starboard/loader_app/slot_management.cc index 8b1af986bfdb..ab02b9177883 100644 --- a/starboard/loader_app/slot_management.cc +++ b/starboard/loader_app/slot_management.cc @@ -223,14 +223,13 @@ void* LoadSlotManagedLibrary(const std::string& app_key, // installation_n/lib/libcobalt.so std::vector compressed_lib_path(kSbFileMaxPath); - SbStringFormatF(compressed_lib_path.data(), kSbFileMaxPath, "%s%s%s%s%s", - installation_path.data(), kSbFileSepString, - kCobaltLibraryPath, kSbFileSepString, - kCompressedCobaltLibraryName); + snprintf(compressed_lib_path.data(), kSbFileMaxPath, "%s%s%s%s%s", + installation_path.data(), kSbFileSepString, kCobaltLibraryPath, + kSbFileSepString, kCompressedCobaltLibraryName); std::vector uncompressed_lib_path(kSbFileMaxPath); - SbStringFormatF(uncompressed_lib_path.data(), kSbFileMaxPath, "%s%s%s%s%s", - installation_path.data(), kSbFileSepString, - kCobaltLibraryPath, kSbFileSepString, kCobaltLibraryName); + snprintf(uncompressed_lib_path.data(), kSbFileMaxPath, "%s%s%s%s%s", + installation_path.data(), kSbFileSepString, kCobaltLibraryPath, + kSbFileSepString, kCobaltLibraryName); std::string lib_path; bool use_compression; @@ -258,9 +257,8 @@ void* LoadSlotManagedLibrary(const std::string& app_key, if (alternative_content_path.empty()) { // installation_n/content std::vector content_path(kSbFileMaxPath); - SbStringFormatF(content_path.data(), kSbFileMaxPath, "%s%s%s", - installation_path.data(), kSbFileSepString, - kCobaltContentPath); + snprintf(content_path.data(), kSbFileMaxPath, "%s%s%s", + installation_path.data(), kSbFileSepString, kCobaltContentPath); content = content_path.data(); } else { content = alternative_content_path.c_str(); diff --git a/starboard/nplb/BUILD.gn b/starboard/nplb/BUILD.gn index cfc2e867ebfb..866a9275ad22 100644 --- a/starboard/nplb/BUILD.gn +++ b/starboard/nplb/BUILD.gn @@ -173,6 +173,8 @@ target(gtest_target_type, "nplb") { "string_compare_no_case_n_test.cc", "string_compare_no_case_test.cc", "string_duplicate_test.cc", + + # TODO: b/307941391: test "SbStringFormatWideTest" is deprecated in SB16 "string_format_test.cc", "string_format_wide_test.cc", "string_scan_test.cc", diff --git a/starboard/nplb/string_format_test.cc b/starboard/nplb/string_format_test.cc index 7505d64f443c..3ee33618b623 100644 --- a/starboard/nplb/string_format_test.cc +++ b/starboard/nplb/string_format_test.cc @@ -25,7 +25,7 @@ namespace { int Format(char* out_buffer, size_t buffer_size, const char* format, ...) { va_list arguments; va_start(arguments, format); - int result = SbStringFormat(out_buffer, buffer_size, format, arguments); + int result = vsnprintf(out_buffer, buffer_size, format, arguments); va_end(arguments); return result; } diff --git a/starboard/nplb/string_format_wide_test.cc b/starboard/nplb/string_format_wide_test.cc index b2f6b286ff3e..b51c9c4a9cf9 100644 --- a/starboard/nplb/string_format_wide_test.cc +++ b/starboard/nplb/string_format_wide_test.cc @@ -22,6 +22,7 @@ namespace starboard { namespace nplb { namespace { +#if SB_API_VERSION <= 15 int Format(wchar_t* out_buffer, size_t buffer_size, const wchar_t* format, @@ -44,6 +45,7 @@ TEST(SbStringFormatWideTest, SunnyDay) { EXPECT_EQ(kExpected[i], destination[i]); } } +#endif } // namespace } // namespace nplb diff --git a/starboard/shared/ffmpeg/ffmpeg_dynamic_load_dispatch_impl.cc b/starboard/shared/ffmpeg/ffmpeg_dynamic_load_dispatch_impl.cc index 987d42d3e681..9d0e7ef43114 100644 --- a/starboard/shared/ffmpeg/ffmpeg_dynamic_load_dispatch_impl.cc +++ b/starboard/shared/ffmpeg/ffmpeg_dynamic_load_dispatch_impl.cc @@ -153,7 +153,7 @@ const int kMaxVersionedLibraryNameLength = 32; std::string GetVersionedLibraryName(const char* name, const int version) { char s[kMaxVersionedLibraryNameLength]; - SbStringFormatF(s, kMaxVersionedLibraryNameLength, "%s.%d", name, version); + snprintf(s, kMaxVersionedLibraryNameLength, "%s.%d", name, version); return std::string(s); } diff --git a/starboard/shared/posix/string_format.cc b/starboard/shared/posix/string_format.cc index 84edc16e35a5..6835afe2887a 100644 --- a/starboard/shared/posix/string_format.cc +++ b/starboard/shared/posix/string_format.cc @@ -17,9 +17,11 @@ #include #include +#if SB_API_VERSION < 16 int SbStringFormat(char* out_buffer, size_t buffer_size, const char* format, va_list arguments) { return vsnprintf(out_buffer, buffer_size, format, arguments); } +#endif diff --git a/starboard/shared/posix/string_format_wide.cc b/starboard/shared/posix/string_format_wide.cc index ab641086bdaa..9e77eec6d028 100644 --- a/starboard/shared/posix/string_format_wide.cc +++ b/starboard/shared/posix/string_format_wide.cc @@ -18,9 +18,11 @@ #include #include +#if SB_API_VERSION < 16 int SbStringFormatWide(wchar_t* out_buffer, size_t buffer_size, const wchar_t* format, va_list arguments) { return vswprintf(out_buffer, buffer_size, format, arguments); } +#endif diff --git a/starboard/shared/starboard/link_receiver.cc b/starboard/shared/starboard/link_receiver.cc index d67735afc0ca..f4b703f61fc1 100644 --- a/starboard/shared/starboard/link_receiver.cc +++ b/starboard/shared/starboard/link_receiver.cc @@ -293,7 +293,7 @@ void LinkReceiver::Impl::Run() { } char port_string[32] = {0}; - SbStringFormatF(port_string, SB_ARRAY_SIZE(port_string), "%d", actual_port_); + snprintf(port_string, SB_ARRAY_SIZE(port_string), "%d", actual_port_); CreateTemporaryFile("link_receiver_port", port_string, strlen(port_string)); if (!AddForAccept(listen_socket_.get())) { diff --git a/starboard/shared/starboard/log_raw_format.cc b/starboard/shared/starboard/log_raw_format.cc index e0a953811a49..dc669b5b4309 100644 --- a/starboard/shared/starboard/log_raw_format.cc +++ b/starboard/shared/starboard/log_raw_format.cc @@ -15,11 +15,12 @@ #include "starboard/common/log.h" #include +#include #include "starboard/common/string.h" void SbLogRawFormat(const char* format, va_list arguments) { char message[128]; - SbStringFormat(message, sizeof(message), format, arguments); + vsnprintf(message, sizeof(message), format, arguments); SbLogRaw(message); } diff --git a/starboard/shared/stub/string_format.cc b/starboard/shared/stub/string_format.cc index a6874ac8bec5..eb2115f69157 100644 --- a/starboard/shared/stub/string_format.cc +++ b/starboard/shared/stub/string_format.cc @@ -14,9 +14,11 @@ #include "starboard/common/string.h" +#if SB_API_VERSION <= 15 int SbStringFormat(char* out_buffer, size_t buffer_size, const char* format, va_list arguments) { return 0; } +#endif diff --git a/starboard/shared/stub/string_format_wide.cc b/starboard/shared/stub/string_format_wide.cc index 150bd1b82081..62ddfe780fe4 100644 --- a/starboard/shared/stub/string_format_wide.cc +++ b/starboard/shared/stub/string_format_wide.cc @@ -14,9 +14,11 @@ #include "starboard/common/string.h" +#if SB_API_VERSION <= 15 int SbStringFormatWide(wchar_t* out_buffer, size_t buffer_size, const wchar_t* format, va_list arguments) { return 0; } +#endif diff --git a/starboard/shared/win32/string_format.cc b/starboard/shared/win32/string_format.cc index d4dd55b2892a..90d5081e4db7 100644 --- a/starboard/shared/win32/string_format.cc +++ b/starboard/shared/win32/string_format.cc @@ -16,9 +16,11 @@ #include +#if SB_API_VERSION <= 15 int SbStringFormat(char* out_buffer, size_t buffer_size, const char* format, va_list arguments) { return vsnprintf(out_buffer, buffer_size, format, arguments); } +#endif diff --git a/starboard/shared/win32/string_format_wide.cc b/starboard/shared/win32/string_format_wide.cc index 852f65b1b783..30987e179e66 100644 --- a/starboard/shared/win32/string_format_wide.cc +++ b/starboard/shared/win32/string_format_wide.cc @@ -16,9 +16,11 @@ #include +#if SB_API_VERSION <= 15 int SbStringFormatWide(wchar_t* out_buffer, size_t buffer_size, const wchar_t* format, va_list arguments) { return _vsnwprintf(out_buffer, buffer_size, format, arguments); } +#endif diff --git a/starboard/string.h b/starboard/string.h index be8e29d8dfe6..df9df46c28ed 100644 --- a/starboard/string.h +++ b/starboard/string.h @@ -20,6 +20,8 @@ #define STARBOARD_STRING_H_ #include +#include +#include #include "starboard/configuration.h" #include "starboard/export.h" @@ -64,6 +66,7 @@ SB_EXPORT int SbStringCompareNoCaseN(const char* string1, const char* string2, size_t count); +#if SB_API_VERSION <= 15 // Produces a string formatted with |format| and |arguments|, placing as much // of the result that will fit into |out_buffer|. The return value specifies // the number of characters that the format would produce if |buffer_size| were @@ -79,7 +82,6 @@ SB_EXPORT int SbStringFormat(char* out_buffer, size_t buffer_size, const char* format, va_list arguments) SB_PRINTF_FORMAT(3, 0); - // An inline wrapper of SbStringFormat that converts from ellipsis to va_args. // This function is meant to be a drop-in replacement for |snprintf|. // @@ -97,7 +99,7 @@ static SB_C_INLINE int SbStringFormatF(char* out_buffer, ...) { va_list arguments; va_start(arguments, format); - int result = SbStringFormat(out_buffer, buffer_size, format, arguments); + int result = vsnprintf(out_buffer, buffer_size, format, arguments); va_end(arguments); return result; } @@ -116,7 +118,7 @@ static SB_C_INLINE int SbStringFormatUnsafeF(char* out_buffer, ...) { va_list arguments; va_start(arguments, format); - int result = SbStringFormat(out_buffer, SSIZE_MAX, format, arguments); + int result = vsnprintf(out_buffer, SSIZE_MAX, format, arguments); va_end(arguments); return result; } @@ -140,16 +142,18 @@ SB_EXPORT int SbStringFormatWide(wchar_t* out_buffer, // |buffer_size|: The size of |out_buffer|. // |format|: A string that specifies how the data should be formatted. // |...|: Arguments used in the string. + static SB_C_INLINE int SbStringFormatWideF(wchar_t* out_buffer, size_t buffer_size, const wchar_t* format, ...) { va_list arguments; va_start(arguments, format); - int result = SbStringFormatWide(out_buffer, buffer_size, format, arguments); + int result = vswprintf(out_buffer, buffer_size, format, arguments); va_end(arguments); return result; } +#endif // Scans |buffer| for |pattern|, placing the extracted values in |arguments|. // The return value specifies the number of successfully matched items, which diff --git a/third_party/boringssl/src/crypto/mem_starboard.c b/third_party/boringssl/src/crypto/mem_starboard.c index b0906d6a5d64..a0cc626189d9 100644 --- a/third_party/boringssl/src/crypto/mem_starboard.c +++ b/third_party/boringssl/src/crypto/mem_starboard.c @@ -221,5 +221,5 @@ int BIO_snprintf(char *buf, size_t n, const char *format, ...) { } int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) { - return SbStringFormat(buf, n, format, args); + return vsnprintf(buf, n, format, args); } diff --git a/third_party/google_benchmark/src/colorprint_starboard.cc b/third_party/google_benchmark/src/colorprint_starboard.cc index d68d5a71c4b6..e2d83e4142f1 100644 --- a/third_party/google_benchmark/src/colorprint_starboard.cc +++ b/third_party/google_benchmark/src/colorprint_starboard.cc @@ -14,6 +14,7 @@ #include "colorprint.h" +#include #include #include "starboard/string.h" @@ -24,7 +25,7 @@ std::string FormatString(const char* msg, va_list args) { va_list args_copy; va_copy(args_copy, args); - int expected_size = ::SbStringFormat(NULL, 0, msg, args_copy); + int expected_size = ::vsnprintf(NULL, 0, msg, args_copy); va_end(args_copy); @@ -33,7 +34,7 @@ std::string FormatString(const char* msg, va_list args) { } std::vector buffer(expected_size + 1); - ::SbStringFormat(buffer.data(), buffer.size(), msg, args); + ::vsnprintf(buffer.data(), buffer.size(), msg, args); return std::string(buffer.data(), expected_size); } diff --git a/third_party/googletest/src/googletest/include/gtest/internal/gtest-port.h b/third_party/googletest/src/googletest/include/gtest/internal/gtest-port.h index b6fa7c6137df..79d24b24382c 100644 --- a/third_party/googletest/src/googletest/include/gtest/internal/gtest-port.h +++ b/third_party/googletest/src/googletest/include/gtest/internal/gtest-port.h @@ -302,6 +302,7 @@ #include #include +#include #include "gtest/internal/custom/gtest-port.h" #include "gtest/internal/gtest-port-arch.h" @@ -2106,7 +2107,7 @@ inline void Abort() { SbSystemBreakIntoDebugger(); } inline int VSNPrintF(char* out_buffer, size_t size, const char* format, va_list args) { - return SbStringFormat(out_buffer, size, format, args); + return vsnprintf(out_buffer, size, format, args); } inline size_t StrLen(const char *str) { diff --git a/third_party/harfbuzz-ng/src/hb-starboard.hh b/third_party/harfbuzz-ng/src/hb-starboard.hh index e88bd4b8b16a..123706eee41d 100644 --- a/third_party/harfbuzz-ng/src/hb-starboard.hh +++ b/third_party/harfbuzz-ng/src/hb-starboard.hh @@ -31,6 +31,5 @@ #undef assert #define assert SB_DCHECK #define getenv(x) NULL -#define snprintf SbStringFormatF #endif // HB_STARBOARD_HH diff --git a/third_party/mini_chromium/base/strings/stringprintf.cc b/third_party/mini_chromium/base/strings/stringprintf.cc index d4c9a392f3ca..47b6a2f6f1b1 100644 --- a/third_party/mini_chromium/base/strings/stringprintf.cc +++ b/third_party/mini_chromium/base/strings/stringprintf.cc @@ -21,7 +21,7 @@ inline int vsnprintfT(char* buffer, size_t buf_size, const char* format, va_list argptr) { - return base::vsnprintf(buffer, buf_size, format, argptr); + return vsnprintf(buffer, buf_size, format, argptr); } template diff --git a/third_party/musl/BUILD.gn b/third_party/musl/BUILD.gn index 0c7d0578f439..7088b623b99a 100644 --- a/third_party/musl/BUILD.gn +++ b/third_party/musl/BUILD.gn @@ -385,9 +385,7 @@ static_library("c_internal") { "src/starboard/stdio/stderr.c", "src/starboard/stdio/stdout.c", "src/starboard/stdio/vfprintf.c", - "src/starboard/stdio/vsnprintf.c", "src/starboard/stdio/vsscanf.c", - "src/starboard/stdio/vswprintf.c", "src/starboard/stdlib/strtod_l.c", "src/starboard/time/__tz.c", "src/starboard/time/clock_gettime.c", @@ -402,6 +400,8 @@ static_library("c_internal") { "src/stdio/vasprintf.c", "src/stdio/vprintf.c", "src/stdio/vsprintf.c", + "src/stdio/vsnprintf.c", + "src/stdio/vswprintf.c", "src/stdlib/abs.c", "src/stdlib/atof.c", "src/stdlib/atoi.c", diff --git a/third_party/musl/src/starboard/stdio/vsnprintf.c b/third_party/musl/src/starboard/stdio/vsnprintf.c deleted file mode 100644 index 1eec0c0831b0..000000000000 --- a/third_party/musl/src/starboard/stdio/vsnprintf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include -#include "starboard/string.h" - -int vsnprintf(char *restrict s, size_t n, const char *restrict fmt, va_list ap) { - return SbStringFormat(s, n, fmt, ap); -} diff --git a/third_party/musl/src/starboard/stdio/vswprintf.c b/third_party/musl/src/starboard/stdio/vswprintf.c deleted file mode 100644 index b8b69eb4bade..000000000000 --- a/third_party/musl/src/starboard/stdio/vswprintf.c +++ /dev/null @@ -1,6 +0,0 @@ -#include -#include "starboard/string.h" - -int vswprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, va_list ap) { - return SbStringFormatWide(s, n, fmt, ap); -} diff --git a/third_party/protobuf/src/google/protobuf/stubs/common.cc b/third_party/protobuf/src/google/protobuf/stubs/common.cc index 660de2fd6c25..c51428209449 100644 --- a/third_party/protobuf/src/google/protobuf/stubs/common.cc +++ b/third_party/protobuf/src/google/protobuf/stubs/common.cc @@ -48,7 +48,6 @@ #include "starboard/system.h" #define abort SbSystemBreakIntoDebugger #define fflush(stderr) SbLogFlush() -#define snprintf SbStringFormatF #else // STARBOARD #include #include diff --git a/third_party/protobuf/src/google/protobuf/stubs/strutil.cc b/third_party/protobuf/src/google/protobuf/stubs/strutil.cc index d9fc5071de40..307598581520 100644 --- a/third_party/protobuf/src/google/protobuf/stubs/strutil.cc +++ b/third_party/protobuf/src/google/protobuf/stubs/strutil.cc @@ -42,9 +42,6 @@ // "reverse poems" to move past this issue for host builds. For why we don't // just use poems, see the comment in the #else clause. -#define SbStringFormatF snprintf -#define SbStringFormatUnsafeF sprintf - #else // STARBOARD #include @@ -531,7 +528,7 @@ int CEscapeInternal(const char* src, int src_len, char* dest, (last_hex_escape && isxdigit(*src)))) { if (dest_len - used < 4) // need space for 4 letter escape return -1; - SbStringFormatUnsafeF(dest + used, (use_hex ? "\\x%02x" : "\\%03o"), + sprintf(dest + used, (use_hex ? "\\x%02x" : "\\%03o"), static_cast(*src)); is_hex_escape = use_hex; used += 4; @@ -1291,7 +1288,7 @@ char* DoubleToBuffer(double value, char* buffer) { } int snprintf_result = - SbStringFormatF(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG, value); + snprintf(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG, value); // The snprintf should never overflow because the buffer is significantly // larger than the precision we asked for. @@ -1306,7 +1303,7 @@ char* DoubleToBuffer(double value, char* buffer) { volatile double parsed_value = strtod(buffer, NULL); if (parsed_value != value) { int snprintf_result = - SbStringFormatF(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG+2, value); + snprintf(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG+2, value); // Should never overflow; see above. GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kDoubleToBufferSize); @@ -1409,7 +1406,7 @@ char* FloatToBuffer(float value, char* buffer) { } int snprintf_result = - SbStringFormatF(buffer, kFloatToBufferSize, "%.*g", FLT_DIG, value); + snprintf(buffer, kFloatToBufferSize, "%.*g", FLT_DIG, value); // The snprintf should never overflow because the buffer is significantly // larger than the precision we asked for. @@ -1418,7 +1415,7 @@ char* FloatToBuffer(float value, char* buffer) { float parsed_value; if (!safe_strtof(buffer, &parsed_value) || parsed_value != value) { int snprintf_result = - SbStringFormatF(buffer, kFloatToBufferSize, "%.*g", FLT_DIG+2, value); + snprintf(buffer, kFloatToBufferSize, "%.*g", FLT_DIG+2, value); // Should never overflow; see above. GOOGLE_DCHECK(snprintf_result > 0 && snprintf_result < kFloatToBufferSize); diff --git a/third_party/v8/src/base/platform/platform-starboard.cc b/third_party/v8/src/base/platform/platform-starboard.cc index 37ecba21eec9..c3bacee28d8e 100644 --- a/third_party/v8/src/base/platform/platform-starboard.cc +++ b/third_party/v8/src/base/platform/platform-starboard.cc @@ -6,6 +6,8 @@ // abstraction layer for Cobalt, an HTML5 container used mainly by YouTube // apps in the living room. +#include + #include "src/base/lazy-instance.h" #include "src/base/macros.h" #include "src/base/platform/platform.h" @@ -345,7 +347,7 @@ int OS::SNPrintF(char* str, int length, const char* format, ...) { } int OS::VSNPrintF(char* str, int length, const char* format, va_list args) { - int n = SbStringFormat(str, length, format, args); + int n = vsnprintf(str, length, format, args); if (n < 0 || n >= length) { // If the length is zero, the assignment fails. if (length > 0) str[length - 1] = '\0'; diff --git a/url/url_canon_etc.cc b/url/url_canon_etc.cc index 0eef867a4618..dcb5835c37a6 100644 --- a/url/url_canon_etc.cc +++ b/url/url_canon_etc.cc @@ -204,7 +204,7 @@ bool DoUserInfo(const CHAR* username_spec, // Helper functions for converting port integers to strings. inline void WritePortInt(char* output, int output_len, int port) { #if defined(STARBOARD) - SbStringFormatF(output, output_len, "%d", port); + snprintf(output, output_len, "%d", port); #else _itoa_s(port, output, output_len, 10); #endif diff --git a/url/url_canon_internal.cc b/url/url_canon_internal.cc index 9f6d9953468e..7294e358f335 100644 --- a/url/url_canon_internal.cc +++ b/url/url_canon_internal.cc @@ -9,7 +9,7 @@ #ifndef EINVAL #define EINVAL 22 #endif -#define snprintf SbStringFormatF + #else #include #include diff --git a/url/url_canon_ip.cc b/url/url_canon_ip.cc index 5d96e824ed93..23ae7fcabd67 100644 --- a/url/url_canon_ip.cc +++ b/url/url_canon_ip.cc @@ -600,7 +600,7 @@ void AppendIPv4Address(const unsigned char address[4], CanonOutput* output) { for (int i = 0; i < 4; i++) { char str[16]; #if defined(STARBOARD) - SbStringFormatF(str, 16, "%d", address[i]); + snprintf(str, 16, "%d", address[i]); #else _itoa_s(address[i], str, 10); #endif @@ -639,7 +639,7 @@ void AppendIPv6Address(const unsigned char address[16], CanonOutput* output) { // Stringify the 16 bit number (at most requires 4 hex digits). char str[5]; #if defined(STARBOARD) - SbStringFormatF(str, 5, "%x", x); + snprintf(str, 5, "%x", x); #else _itoa_s(x, str, 16); #endif