From a7deb4f150504fbf35b546f474307f13f063cfd0 Mon Sep 17 00:00:00 2001 From: "bsmedberg%covad.net" Date: Wed, 9 Jun 2004 18:36:25 +0000 Subject: [PATCH] Bug 239925 - fix static initializers in DOM/widget/libpr0n so that we can restart XPCOM safely r=jst sr=darin --- content/base/src/nsLayoutStylesheetCache.cpp | 1 - content/html/style/src/nsCSSLoader.cpp | 1 + dom/src/base/nsDOMClassInfo.cpp | 5 +--- dom/src/base/nsJSEnvironment.cpp | 28 +++++++++++++++++--- dom/src/base/nsJSEnvironment.h | 3 +++ layout/build/nsLayoutModule.cpp | 4 ++- layout/style/nsCSSLoader.cpp | 1 + layout/style/nsLayoutStylesheetCache.cpp | 1 - modules/libpr0n/decoders/gif/GIF2.cpp | 1 + widget/src/gtk/nsWindow.cpp | 1 + 10 files changed, 35 insertions(+), 11 deletions(-) diff --git a/content/base/src/nsLayoutStylesheetCache.cpp b/content/base/src/nsLayoutStylesheetCache.cpp index 4614551f6cc9..9d3525aeeb5f 100644 --- a/content/base/src/nsLayoutStylesheetCache.cpp +++ b/content/base/src/nsLayoutStylesheetCache.cpp @@ -44,7 +44,6 @@ #include "nsNetUtil.h" #include "nsIObserverService.h" #include "nsIServiceManagerUtils.h" -#include "nsIProfileChangeStatus.h" NS_IMPL_ISUPPORTS1(nsLayoutStylesheetCache, nsIObserver) diff --git a/content/html/style/src/nsCSSLoader.cpp b/content/html/style/src/nsCSSLoader.cpp index c72d3d75deb9..626b6631e3de 100644 --- a/content/html/style/src/nsCSSLoader.cpp +++ b/content/html/style/src/nsCSSLoader.cpp @@ -251,6 +251,7 @@ void CSSLoaderImpl::Shutdown() { delete gParsers; + gParsers = nsnull; } NS_IMETHODIMP diff --git a/dom/src/base/nsDOMClassInfo.cpp b/dom/src/base/nsDOMClassInfo.cpp index 5599bdfe5916..7dc6bfe033c3 100644 --- a/dom/src/base/nsDOMClassInfo.cpp +++ b/dom/src/base/nsDOMClassInfo.cpp @@ -1280,10 +1280,6 @@ nsDOMClassInfo::RegisterExternalClasses() #define _DOM_CLASSINFO_MAP_BEGIN(_class, _ifptr, _has_class_if) \ { \ nsDOMClassInfoData &d = sClassInfoData[eDOMClassInfo_##_class##_id]; \ - NS_ASSERTION(!d.mProtoChainInterface, "Redeclaration of DOM classinfo " \ - "proto chain interface!"); \ - NS_ASSERTION(!d.mInterfaces, "Redeclaration of DOM classinfo " \ - "interface list!"); \ d.mProtoChainInterface = _ifptr; \ d.mHasClassInterface = _has_class_if; \ static const nsIID *interface_list[] = { @@ -2963,6 +2959,7 @@ nsDOMClassInfo::ShutDown() NS_IF_RELEASE(sXPConnect); NS_IF_RELEASE(sSecMan); + sIsInitialized = PR_FALSE; } diff --git a/dom/src/base/nsJSEnvironment.cpp b/dom/src/base/nsJSEnvironment.cpp index f2651f708d79..5cb7953a6c62 100644 --- a/dom/src/base/nsJSEnvironment.cpp +++ b/dom/src/base/nsJSEnvironment.cpp @@ -111,6 +111,8 @@ static PRLogModuleInfo* gJSDiagnostics; #define NS_GC_DELAY 2000 // ms #define NS_FIRST_GC_DELAY 10000 // ms +// if you add statics here, add them to the list in nsJSEnvironment::Startup + static nsITimer *sGCTimer; static PRBool sReadyForGC; @@ -126,6 +128,7 @@ static PRThread *gDOMThread; static JSGCCallback gOldJSGCCallback; +static PRBool sIsInitialized; static PRBool sDidShutdown; static PRInt32 sContextCount; @@ -1915,13 +1918,30 @@ DOMGCCallback(JSContext *cx, JSGCStatus status) return gOldJSGCCallback ? gOldJSGCCallback(cx, status) : JS_TRUE; } +//static +void +nsJSEnvironment::Startup() +{ + // initialize all our statics, so that we can restart XPCOM + sGCTimer = nsnull; + sReadyForGC = PR_FALSE; + gNameSpaceManager = nsnull; + sRuntimeService = nsnull; + sRuntime = nsnull; + gDOMThread = nsnull; + gOldJSGCCallback = nsnull; + sIsInitialized = PR_FALSE; + sDidShutdown = PR_FALSE; + sContextCount = 0; + sSecurityManager = nsnull; + gCollation = nsnull; +} + // static nsresult nsJSEnvironment::Init() { - static PRBool isInitialized; - - if (isInitialized) { + if (sIsInitialized) { return NS_OK; } @@ -1991,7 +2011,7 @@ nsJSEnvironment::Init() rv = CallGetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &sSecurityManager); - isInitialized = NS_SUCCEEDED(rv); + sIsInitialized = NS_SUCCEEDED(rv); return rv; } diff --git a/dom/src/base/nsJSEnvironment.h b/dom/src/base/nsJSEnvironment.h index d8675bf248b1..4b33bcfefb96 100644 --- a/dom/src/base/nsJSEnvironment.h +++ b/dom/src/base/nsJSEnvironment.h @@ -179,6 +179,9 @@ private: static JSRuntime *sRuntime; public: + // called from the module Ctor to initialize statics + static void Startup(); + static nsresult Init(); static nsJSEnvironment *GetScriptingEnvironment(); diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index ce5e0e1a8ae3..82a1bdab2478 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -100,6 +100,7 @@ #include "nsIXBLService.h" #include "nsIFrameLoader.h" #include "nsICaret.h" +#include "nsJSEnvironment.h" #include "nsLayoutAtoms.h" #include "nsPlainTextSerializer.h" #include "mozSanitizingSerializer.h" @@ -255,7 +256,8 @@ Initialize(nsIModule* aSelf) } gInitialized = PR_TRUE; - + + nsJSEnvironment::Startup(); nsresult rv = nsContentUtils::Init(); if (NS_FAILED(rv)) { NS_ERROR("Could not initialize nsContentUtils"); diff --git a/layout/style/nsCSSLoader.cpp b/layout/style/nsCSSLoader.cpp index c72d3d75deb9..626b6631e3de 100644 --- a/layout/style/nsCSSLoader.cpp +++ b/layout/style/nsCSSLoader.cpp @@ -251,6 +251,7 @@ void CSSLoaderImpl::Shutdown() { delete gParsers; + gParsers = nsnull; } NS_IMETHODIMP diff --git a/layout/style/nsLayoutStylesheetCache.cpp b/layout/style/nsLayoutStylesheetCache.cpp index 4614551f6cc9..9d3525aeeb5f 100644 --- a/layout/style/nsLayoutStylesheetCache.cpp +++ b/layout/style/nsLayoutStylesheetCache.cpp @@ -44,7 +44,6 @@ #include "nsNetUtil.h" #include "nsIObserverService.h" #include "nsIServiceManagerUtils.h" -#include "nsIProfileChangeStatus.h" NS_IMPL_ISUPPORTS1(nsLayoutStylesheetCache, nsIObserver) diff --git a/modules/libpr0n/decoders/gif/GIF2.cpp b/modules/libpr0n/decoders/gif/GIF2.cpp index 05af75ded250..a5ac07ceb2eb 100644 --- a/modules/libpr0n/decoders/gif/GIF2.cpp +++ b/modules/libpr0n/decoders/gif/GIF2.cpp @@ -100,6 +100,7 @@ void nsGifShutdown() { // Release cached buffers from zlib allocator delete gGifAllocator; + gGifAllocator = nsnull; } #define MAX_HOLD 768 /* for now must be big enough for a cmap */ diff --git a/widget/src/gtk/nsWindow.cpp b/widget/src/gtk/nsWindow.cpp index e469d9de524c..a56b1d8e61f6 100644 --- a/widget/src/gtk/nsWindow.cpp +++ b/widget/src/gtk/nsWindow.cpp @@ -393,6 +393,7 @@ nsWindow::ReleaseGlobals() gsGtkCursorCache[i] = nsnull; } } + gGlobalsInitialized = PR_FALSE; } NS_IMETHODIMP nsWindow::Destroy(void)