Skip to content

Commit

Permalink
Deprecate SbStringScan function (#1958)
Browse files Browse the repository at this point in the history
b/307808954

Change-Id: I2d30ba1c332efbb45ff66ab170772bf0201fb3d3
  • Loading branch information
yjzhang111 authored Dec 12, 2023
1 parent 09292e3 commit 0ea59cc
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 23 deletions.
3 changes: 1 addition & 2 deletions cobalt/dom/on_screen_keyboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions net/cookies/canonical_cookie.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 0 additions & 4 deletions net/cookies/cookie_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions starboard/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions starboard/client_porting/poem/stdio_poem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions starboard/doc/c99.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ deprecated and eventually removed.
* tanf
* trunc
* truncf
### <stdio.h>
* sscanf
* vsscanf
### <stdlib.h>
* abs
* atoi
Expand Down
3 changes: 3 additions & 0 deletions starboard/elf_loader/exported_symbols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions starboard/nplb/string_scan_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -93,3 +95,5 @@ TEST(SbStringScanTest, RainyDayIp3) {
} // namespace
} // namespace nplb
} // namespace starboard

#endif // SB_API_VERSION < 16
4 changes: 4 additions & 0 deletions starboard/shared/iso/string_scan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdarg.h>
Expand All @@ -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
3 changes: 1 addition & 2 deletions starboard/shared/starboard/media/mime_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions starboard/shared/stub/string_scan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions starboard/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define STARBOARD_STRING_H_

#include <stdarg.h>
#include <stdio.h>

#include "starboard/configuration.h"
#include "starboard/export.h"
Expand Down Expand Up @@ -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|.
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions third_party/musl/src/starboard/stdio/vsscanf.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#if SB_API_VERSION < 16

#include <stdio.h>
#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
6 changes: 0 additions & 6 deletions third_party/skia/src/gpu/gl/GrGLUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
#endif

#if defined(STARBOARD)
#include "starboard/egl.h"
Expand Down

0 comments on commit 0ea59cc

Please sign in to comment.