Revision: 20283
Author: [email protected]
Date: Wed Mar 26 15:46:05 2014 UTC
Log: Clean up ICU data tables on shutdown.
This is only used by d8 if compiled with external data tables, or an
embedder that uses external data tables and v8's version of ICU.
BUG=none
[email protected]
LOG=n
Review URL: https://codereview.chromium.org/210973007
http://code.google.com/p/v8/source/detail?r=20283
Modified:
/branches/bleeding_edge/src/icu_util.cc
=======================================
--- /branches/bleeding_edge/src/icu_util.cc Tue Mar 25 12:05:33 2014 UTC
+++ /branches/bleeding_edge/src/icu_util.cc Wed Mar 26 15:46:05 2014 UTC
@@ -33,6 +33,7 @@
#if defined(V8_I18N_SUPPORT)
#include <stdio.h>
+#include <stdlib.h>
#include "unicode/putil.h"
#include "unicode/udata.h"
@@ -49,6 +50,17 @@
namespace internal {
+#if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
+namespace {
+char* g_icu_data_ptr = NULL;
+
+void free_icu_data_ptr() {
+ delete[] g_icu_data_ptr;
+}
+
+} // namespace
+#endif
+
bool InitializeICU(const char* icu_data_file) {
#if !defined(V8_I18N_SUPPORT)
return true;
@@ -70,6 +82,8 @@
#elif ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE
if (!icu_data_file) return false;
+ if (g_icu_data_ptr) return true;
+
FILE* inf = fopen(icu_data_file, "rb");
if (!inf) return false;
@@ -77,15 +91,19 @@
size_t size = ftell(inf);
rewind(inf);
- char* addr = new char[size];
- if (fread(addr, 1, size, inf) != size) {
- delete[] addr;
+ g_icu_data_ptr = new char[size];
+ if (fread(g_icu_data_ptr, 1, size, inf) != size) {
+ delete[] g_icu_data_ptr;
+ g_icu_data_ptr = NULL;
fclose(inf);
return false;
}
fclose(inf);
+
+ atexit(free_icu_data_ptr);
+
UErrorCode err = U_ZERO_ERROR;
- udata_setCommonData(reinterpret_cast<void*>(addr), &err);
+ udata_setCommonData(reinterpret_cast<void*>(g_icu_data_ptr), &err);
return err == U_ZERO_ERROR;
#endif
#endif
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.