Bug 969498 - [Qt] ICU usage conflict, ABORT: JS_SetICUMemoryFunctions failed. r=n.nethercote,nfroyd
authorOleg Romashin <romaxa@gmail.com>
Mon, 10 Feb 2014 22:35:32 -0800
changeset 186258 e546255a136865d22b415d335561998e187e551c
parent 186257 594dda9c7a3a701ba3e329f308e91854824d4fe6
child 186259 feadeb8a7cbbbaebf159d00c62f30087e3147101
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersn
bugs969498
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 969498 - [Qt] ICU usage conflict, ABORT: JS_SetICUMemoryFunctions failed. r=n.nethercote,nfroyd
toolkit/xre/nsQAppInstance.cpp
xpcom/build/nsXPCOMPrivate.h
xpcom/build/nsXPComInit.cpp
--- a/toolkit/xre/nsQAppInstance.cpp
+++ b/toolkit/xre/nsQAppInstance.cpp
@@ -6,16 +6,17 @@
 
 #include "nsQAppInstance.h"
 #include <QApplication>
 #ifdef MOZ_ENABLE_MEEGOTOUCH
 #include <MComponentData>
 #include <MApplicationService>
 #endif
 #include "prenv.h"
+#include "nsXPCOMPrivate.h"
 #include <stdlib.h>
 
 QApplication *nsQAppInstance::sQAppInstance = nullptr;
 #ifdef MOZ_ENABLE_MEEGOTOUCH
 MComponentData* nsQAppInstance::sMComponentData = nullptr;
 #endif
 int nsQAppInstance::sQAppRefCount = 0;
 
@@ -24,16 +25,17 @@ void nsQAppInstance::AddRef(int& aArgc, 
     return;
   if (!sQAppInstance) {
 #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
     const char *graphicsSystem = getenv("MOZ_QT_GRAPHICSSYSTEM");
     if (graphicsSystem) {
       QApplication::setGraphicsSystem(QString(graphicsSystem));
     }
 #endif
+    mozilla::SetICUMemoryFunctions();
     sQAppInstance = new QApplication(aArgc, aArgv);
   }
   sQAppRefCount++;
 }
 
 void nsQAppInstance::Release(void) {
   if (sQAppInstance && !--sQAppRefCount) {
 #ifdef MOZ_ENABLE_MEEGOTOUCH
--- a/xpcom/build/nsXPCOMPrivate.h
+++ b/xpcom/build/nsXPCOMPrivate.h
@@ -189,16 +189,18 @@ namespace mozilla {
  *
  * @return NS_OK for success;
  *         other error codes indicate a failure during shutdown
  *
  */
 nsresult
 ShutdownXPCOM(nsIServiceManager* servMgr);
 
+void SetICUMemoryFunctions();
+
 /**
  * C++ namespaced version of NS_LogTerm.
  */
 void LogTerm();
 
 } // namespace mozilla
 
 
--- a/xpcom/build/nsXPComInit.cpp
+++ b/xpcom/build/nsXPComInit.cpp
@@ -549,20 +549,17 @@ NS_InitXPCOM2(nsIServiceManager* *result
     nsCycleCollector_startup();
 
     // Register ICU memory functions.  This really shouldn't be necessary: the
     // JS engine should do this on its own inside JS_Init, and memory-reporting
     // code should call a JSAPI function to observe ICU memory usage.  But we
     // can't define the alloc/free functions in the JS engine, because it can't
     // depend on the XPCOM-based memory reporting goop.  So for now, we have
     // this oddness.
-    if (!JS_SetICUMemoryFunctions(ICUReporter::Alloc, ICUReporter::Realloc,
-                                  ICUReporter::Free)) {
-        NS_RUNTIMEABORT("JS_SetICUMemoryFunctions failed.");
-    }
+    mozilla::SetICUMemoryFunctions();
 
     // Initialize the JS engine.
     if (!JS_Init()) {
         NS_RUNTIMEABORT("JS_Init failed");
     }
 
     rv = nsComponentManagerImpl::gComponentManager->Init();
     if (NS_FAILED(rv))
@@ -653,16 +650,29 @@ NS_InitXPCOM2(nsIServiceManager* *result
 EXPORT_XPCOM_API(nsresult)
 NS_ShutdownXPCOM(nsIServiceManager* servMgr)
 {
     return mozilla::ShutdownXPCOM(servMgr);
 }
 
 namespace mozilla {
 
+void
+SetICUMemoryFunctions()
+{
+    static bool sICUReporterInitialized = false;
+    if (!sICUReporterInitialized) {
+        if (!JS_SetICUMemoryFunctions(ICUReporter::Alloc, ICUReporter::Realloc,
+                                      ICUReporter::Free)) {
+            NS_RUNTIMEABORT("JS_SetICUMemoryFunctions failed.");
+        }
+        sICUReporterInitialized = true;
+    }
+}
+
 nsresult
 ShutdownXPCOM(nsIServiceManager* servMgr)
 {
     // Make sure the hang monitor is enabled for shutdown.
     HangMonitor::NotifyActivity();
 
     if (!NS_IsMainThread()) {
         NS_RUNTIMEABORT("Shutdown on wrong thread");