Skip to content

Commit

Permalink
Clean up ICU initialization (youtube#3797)
Browse files Browse the repository at this point in the history
Now that ICU data is linked into the Cobalt binary, ICU no longer loads
the data package from the file system.

b/209049814
  • Loading branch information
hlwarriner committed Jul 9, 2024
1 parent 9491db6 commit 7e6a57e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
20 changes: 4 additions & 16 deletions starboard/client_porting/icu_init/icu_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,12 @@ namespace {
// Once control for initializing ICU.
pthread_once_t g_initialization_once = PTHREAD_ONCE_INIT;

// Initializes ICU and TimeZones so the rest of the functions will work. Should
// only be called once.
// Should only be called once.
void Initialize() {
// Minimal Initialization of ICU.
std::vector<char> base_path(kSbFileMaxPath);
bool result = SbSystemGetPath(kSbSystemPathContentDirectory, base_path.data(),
base_path.size());
SB_DCHECK(result);

std::string data_path(base_path.data());
data_path += kSbFileSepString;
data_path += "icu";

// set this as the data directory.
u_setDataDirectory(data_path.c_str());

UErrorCode err = U_ZERO_ERROR;
udata_setFileAccess(UDATA_PACKAGES_FIRST, &err);

// ICU data is linked into the binary.
udata_setFileAccess(UDATA_NO_FILES, &err);
SB_DCHECK(err <= U_ZERO_ERROR);
}

Expand Down
2 changes: 1 addition & 1 deletion starboard/client_porting/icu_init/icu_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#if defined(STARBOARD)

// Initializes ICU using a standard path based on the Starboard content path.
// Does minimal initialization of ICU.
// This function must be threadsafe and idempotent. Applications that wish to
// initialize ICU differently may define their own IcuInit function rather
// than using the implementation here.
Expand Down
5 changes: 5 additions & 0 deletions third_party/icu/source/common/udata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,11 @@ doOpenChoice(const char *path, const char *type, const char *name,
/* Load from DLL. If we haven't attempted package load, we also haven't had any chance to
try a DLL (static or setCommonData/etc) load.
If we ever have a "UDATA_ONLY_FILES", add it to the or list here. */
#if defined(STARBOARD)
/* To clarify, Cobalt links the common ICU package into the Cobalt binary.
So while this code path is followed, the data is not really loaded from
a DLL. */
#endif // defined(STARBOARD)
if(gDataFileAccess==UDATA_NO_FILES) {
#ifdef UDATA_DEBUG
fprintf(stderr, "Trying common data (UDATA_NO_FILES)\n");
Expand Down

0 comments on commit 7e6a57e

Please sign in to comment.