From 0ea59cc13e7333507750d4b6ad85bf800da069b9 Mon Sep 17 00:00:00 2001 From: Yijia Zhang <45114178+yjzhang111@users.noreply.github.com> Date: Tue, 12 Dec 2023 15:28:53 -0800 Subject: [PATCH] Deprecate SbStringScan function (#1958) b/307808954 Change-Id: I2d30ba1c332efbb45ff66ab170772bf0201fb3d3 --- cobalt/dom/on_screen_keyboard.cc | 3 +-- net/cookies/canonical_cookie.cc | 4 ---- net/cookies/cookie_util.cc | 4 ---- starboard/CHANGELOG.md | 3 +++ starboard/client_porting/poem/stdio_poem.h | 4 ---- starboard/doc/c99.md | 3 +++ starboard/elf_loader/exported_symbols.cc | 3 +++ starboard/nplb/string_scan_test.cc | 4 ++++ starboard/shared/iso/string_scan.cc | 4 ++++ starboard/shared/starboard/media/mime_type.cc | 3 +-- starboard/shared/stub/string_scan.cc | 4 ++++ starboard/string.h | 3 +++ .../boringssl/src/config/starboard/openssl/opensslconf.h | 2 +- third_party/musl/src/starboard/stdio/vsscanf.c | 4 ++++ third_party/skia/src/gpu/gl/GrGLUtil.cpp | 6 ------ 15 files changed, 31 insertions(+), 23 deletions(-) diff --git a/cobalt/dom/on_screen_keyboard.cc b/cobalt/dom/on_screen_keyboard.cc index 74fbe8315e16..9ebf84ddeeaa 100644 --- a/cobalt/dom/on_screen_keyboard.cc +++ b/cobalt/dom/on_screen_keyboard.cc @@ -41,8 +41,7 @@ bool ParseColor(const char* color_str, int& r, int& g, int& b) { // Handle hexadecimal color notation #RRGGBB int r_tmp, g_tmp, b_tmp; - bool is_hex = - SbStringScanF(color_str, "#%02x%02x%02x", &r_tmp, &g_tmp, &b_tmp) == 3; + bool is_hex = sscanf(color_str, "#%02x%02x%02x", &r_tmp, &g_tmp, &b_tmp) == 3; if (is_hex && IsValidRGB(r_tmp, g_tmp, b_tmp)) { r = r_tmp; g = g_tmp; diff --git a/net/cookies/canonical_cookie.cc b/net/cookies/canonical_cookie.cc index ec5bfb81664a..56421e3c0d67 100644 --- a/net/cookies/canonical_cookie.cc +++ b/net/cookies/canonical_cookie.cc @@ -162,15 +162,11 @@ Time CanonicalCookie::CanonExpiration(const ParsedCookie& pc, // First, try the Max-Age attribute. uint64_t max_age = 0; if (pc.HasMaxAge() && -#ifdef STARBOARD - SbStringScanF( -#else #ifdef COMPILER_MSVC sscanf_s( #else sscanf( #endif -#endif // STARBOARD pc.MaxAge().c_str(), " %" PRIu64, &max_age) == 1) { return current + TimeDelta::FromSeconds(max_age); } diff --git a/net/cookies/cookie_util.cc b/net/cookies/cookie_util.cc index e513df30ee43..e958df56ba3e 100644 --- a/net/cookies/cookie_util.cc +++ b/net/cookies/cookie_util.cc @@ -207,15 +207,11 @@ base::Time ParseCookieExpirationTime(const std::string& time_string) { // Numeric field w/ a colon } else if (token.find(':') != std::string::npos) { if (!found_time && -#ifdef STARBOARD - SbStringScanF( -#else #ifdef COMPILER_MSVC sscanf_s( #else sscanf( #endif -#endif // STARBOARD token.c_str(), "%2u:%2u:%2u", &exploded.hour, &exploded.minute, &exploded.second) == 3) { found_time = true; diff --git a/starboard/CHANGELOG.md b/starboard/CHANGELOG.md index afc54a3fe70d..a68060a68228 100644 --- a/starboard/CHANGELOG.md +++ b/starboard/CHANGELOG.md @@ -40,6 +40,9 @@ deprecated. This value allows IAMF samples to be written to Starboard along with IAMF Config OBUs as side data. +### Deprecated SbStringScan and SbStringScanF +The APIs defined in `starboard/string.h` are deprecated and the standard API `vsscanf` and `sscanf` are used instead. + ## Version 15 ### SbMemoryReporter is no longer used diff --git a/starboard/client_porting/poem/stdio_poem.h b/starboard/client_porting/poem/stdio_poem.h index deddeefc2f12..b2118fba93c2 100644 --- a/starboard/client_porting/poem/stdio_poem.h +++ b/starboard/client_porting/poem/stdio_poem.h @@ -33,10 +33,6 @@ #define snprintf SbStringFormatF #undef sprintf #define sprintf SbStringFormatUnsafeF -#undef vsscanf -#define vsscanf SbStringScan -#undef sscanf -#define sscanf SbStringScanF #endif // POEM_NO_EMULATION diff --git a/starboard/doc/c99.md b/starboard/doc/c99.md index 88c41b742c19..808f4ed6a87b 100644 --- a/starboard/doc/c99.md +++ b/starboard/doc/c99.md @@ -88,6 +88,9 @@ deprecated and eventually removed. * tanf * trunc * truncf +### +* sscanf +* vsscanf ### * abs * atoi diff --git a/starboard/elf_loader/exported_symbols.cc b/starboard/elf_loader/exported_symbols.cc index c0134d22a875..e3fcbb523663 100644 --- a/starboard/elf_loader/exported_symbols.cc +++ b/starboard/elf_loader/exported_symbols.cc @@ -310,7 +310,9 @@ ExportedSymbols::ExportedSymbols() { #endif // SB_API_VERSION < 16 REGISTER_SYMBOL(SbStringFormat); REGISTER_SYMBOL(SbStringFormatWide); +#if SB_API_VERSION < 16 REGISTER_SYMBOL(SbStringScan); +#endif // SB_API_VERSION < 16 REGISTER_SYMBOL(SbSystemBreakIntoDebugger); REGISTER_SYMBOL(SbSystemClearLastError); #if SB_API_VERSION < 14 @@ -404,6 +406,7 @@ ExportedSymbols::ExportedSymbols() { REGISTER_SYMBOL(calloc); REGISTER_SYMBOL(posix_memalign); REGISTER_SYMBOL(free); + REGISTER_SYMBOL(vsscanf); #endif // SB_API_VERSION >= 16 } // NOLINT diff --git a/starboard/nplb/string_scan_test.cc b/starboard/nplb/string_scan_test.cc index fb47ee748f1a..0f6d66bc366e 100644 --- a/starboard/nplb/string_scan_test.cc +++ b/starboard/nplb/string_scan_test.cc @@ -15,6 +15,8 @@ // Here we are not trying to do anything fancy, just to really sanity check that // this is hooked up to something. +#if SB_API_VERSION < 16 + #include "starboard/common/string.h" #include "testing/gtest/include/gtest/gtest.h" @@ -93,3 +95,5 @@ TEST(SbStringScanTest, RainyDayIp3) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/iso/string_scan.cc b/starboard/shared/iso/string_scan.cc index 98fe10b86d5c..50c0fd4c60d6 100644 --- a/starboard/shared/iso/string_scan.cc +++ b/starboard/shared/iso/string_scan.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/common/string.h" #include @@ -20,3 +22,5 @@ int SbStringScan(const char* buffer, const char* pattern, va_list arguments) { return vsscanf(buffer, pattern, arguments); } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/starboard/media/mime_type.cc b/starboard/shared/starboard/media/mime_type.cc index 66d8e4cffa0d..035c75568434 100644 --- a/starboard/shared/starboard/media/mime_type.cc +++ b/starboard/shared/starboard/media/mime_type.cc @@ -50,8 +50,7 @@ void ParseParamTypeAndValue(const std::string& name, int count; int i; - if (SbStringScanF(value.c_str(), "%d%n", &i, &count) == 1 && - count == value.size()) { + if (sscanf(value.c_str(), "%d%n", &i, &count) == 1 && count == value.size()) { param->type = MimeType::kParamTypeInteger; param->int_value = i; return; diff --git a/starboard/shared/stub/string_scan.cc b/starboard/shared/stub/string_scan.cc index 67bdc913e5b4..6646a905a8e7 100644 --- a/starboard/shared/stub/string_scan.cc +++ b/starboard/shared/stub/string_scan.cc @@ -12,8 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 16 + #include "starboard/common/string.h" int SbStringScan(const char* buffer, const char* pattern, va_list arguments) { return 0; } + +#endif // SB_API_VERSION < 16 diff --git a/starboard/string.h b/starboard/string.h index 945d6f1ee861..43f462250814 100644 --- a/starboard/string.h +++ b/starboard/string.h @@ -20,6 +20,7 @@ #define STARBOARD_STRING_H_ #include +#include #include "starboard/configuration.h" #include "starboard/export.h" @@ -151,6 +152,7 @@ static SB_C_INLINE int SbStringFormatWideF(wchar_t* out_buffer, return result; } +#if SB_API_VERSION < 16 // Scans |buffer| for |pattern|, placing the extracted values in |arguments|. // The return value specifies the number of successfully matched items, which // may be |0|. @@ -178,6 +180,7 @@ static SB_C_INLINE int SbStringScanF(const char* buffer, va_end(arguments); return result; } +#endif // SB_API_VERSION < 16 #ifdef __cplusplus } // extern "C" diff --git a/third_party/boringssl/src/config/starboard/openssl/opensslconf.h b/third_party/boringssl/src/config/starboard/openssl/opensslconf.h index 8a8e388c5b0e..a36d295b4e29 100644 --- a/third_party/boringssl/src/config/starboard/openssl/opensslconf.h +++ b/third_party/boringssl/src/config/starboard/openssl/opensslconf.h @@ -234,6 +234,7 @@ #define OPENSSL_port_free free #define OPENSSL_port_malloc malloc #define OPENSSL_port_realloc realloc +#define OPENSSL_port_sscanf sscanf #define OPENSSL_port_strdup strdup #define OPENSSL_port_abort SbSystemBreakIntoDebugger @@ -243,7 +244,6 @@ #define OPENSSL_port_gmtime_r EzTimeTExplodeUTC #define OPENSSL_port_printf SbLogFormatF #define OPENSSL_port_printferr SbLogFormatF -#define OPENSSL_port_sscanf SbStringScanF #define OPENSSL_port_strcasecmp SbStringCompareNoCase #define OPENSSL_port_strerror(x) "" #define OPENSSL_port_strncasecmp SbStringCompareNoCaseN diff --git a/third_party/musl/src/starboard/stdio/vsscanf.c b/third_party/musl/src/starboard/stdio/vsscanf.c index 7c972f12cacf..e84ba5097c67 100644 --- a/third_party/musl/src/starboard/stdio/vsscanf.c +++ b/third_party/musl/src/starboard/stdio/vsscanf.c @@ -1,6 +1,10 @@ +#if SB_API_VERSION < 16 + #include #include "starboard/string.h" int vsscanf(const char *restrict s, const char *restrict fmt, va_list ap) { return SbStringScan(s, fmt, ap); } + +#endif // SB_API_VERSION < 16 diff --git a/third_party/skia/src/gpu/gl/GrGLUtil.cpp b/third_party/skia/src/gpu/gl/GrGLUtil.cpp index 6970e9c5da54..7fa8a91b80cc 100644 --- a/third_party/skia/src/gpu/gl/GrGLUtil.cpp +++ b/third_party/skia/src/gpu/gl/GrGLUtil.cpp @@ -23,13 +23,7 @@ bool gCheckErrorGL = !!(GR_GL_CHECK_ERROR_START); /////////////////////////////////////////////////////////////////////////////// -#if defined(STARBOARD) -#include "starboard/common/string.h" -#include "starboard/configuration.h" -#define sscanf SbStringScanF -#else #include -#endif #if defined(STARBOARD) #include "starboard/egl.h"