From c327e1c6c3689be980e5d761fb38b4fbb86e87b6 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Mon, 1 Jul 2002 20:37:17 +0000 Subject: [PATCH] More XPCOM Glue changes and fixes. r=waterson, sr=rpotts, 154262. --- xpcom/build/nsXPComInit.cpp | 12 ++- xpcom/components/nsICategoryManager.idl | 1 + xpcom/glue/nsGenericFactory.cpp | 4 +- xpcom/glue/standalone/nsXPCOMGlue.cpp | 108 +----------------------- xpcom/sample/Makefile.in | 3 +- xpcom/sample/nsSample.cpp | 5 +- xpcom/sample/nsTestSample.cpp | 14 ++- 7 files changed, 34 insertions(+), 113 deletions(-) diff --git a/xpcom/build/nsXPComInit.cpp b/xpcom/build/nsXPComInit.cpp index bee504e21c3e..035bf326fa6d 100644 --- a/xpcom/build/nsXPComInit.cpp +++ b/xpcom/build/nsXPComInit.cpp @@ -39,6 +39,7 @@ #include "nsXPCOMPrivate.h" #include "nsIRegistry.h" #include "nscore.h" +#include "prlink.h" #include "nsCOMPtr.h" #include "nsObserverList.h" #include "nsObserver.h" @@ -289,6 +290,11 @@ static const nsModuleComponentInfo components[] = { const int components_length = sizeof(components) / sizeof(components[0]); +static const PRStaticLinkTable sGlueSymbols[] = { + "NS_GetFrozenFunctions", + (void (*)())&NS_GetFrozenFunctions +} ; + // gMemory will be freed during shutdown. static nsIMemory* gMemory = nsnull; nsresult NS_COM NS_GetMemoryManager(nsIMemory* *result) @@ -343,6 +349,8 @@ nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result, StartupSpecialSystemDirectory(); + PR_LoadStaticLibrary("XPCOMComponentGlue", sGlueSymbols); + // Start the directory service so that the component manager init can use it. rv = nsDirectoryService::Create(nsnull, NS_GET_IID(nsIProperties), @@ -629,6 +637,8 @@ nsresult NS_COM NS_ShutdownXPCOM(nsIServiceManager* servMgr) // shutting down the component manager nsTimerImpl::Shutdown(); + CallExitRoutines(); + // Shutdown xpcom. This will release all loaders and cause others holding // a refcount to the component manager to release it. rv = (nsComponentManagerImpl::gComponentManager)->Shutdown(); @@ -663,8 +673,6 @@ nsresult NS_COM NS_ShutdownXPCOM(nsIServiceManager* servMgr) nsThread::Shutdown(); NS_PurgeAtomTable(); - CallExitRoutines(); - #ifdef NS_BUILD_REFCNT_LOGGING nsTraceRefcnt::DumpStatistics(); nsTraceRefcnt::ResetStatistics(); diff --git a/xpcom/components/nsICategoryManager.idl b/xpcom/components/nsICategoryManager.idl index 02106f7101d7..881da30b1427 100644 --- a/xpcom/components/nsICategoryManager.idl +++ b/xpcom/components/nsICategoryManager.idl @@ -21,6 +21,7 @@ #include "nsICategoryHandler.idl" #include "nsIFactory.idl" +// change IID if you change this interface! [scriptable, uuid(5a1e1a2c-1dd2-11b2-a72f-967357e43a00)] interface nsICategoryManager : nsISupports { diff --git a/xpcom/glue/nsGenericFactory.cpp b/xpcom/glue/nsGenericFactory.cpp index 14bb5e2d32da..89562a6e8c29 100644 --- a/xpcom/glue/nsGenericFactory.cpp +++ b/xpcom/glue/nsGenericFactory.cpp @@ -361,12 +361,14 @@ nsGenericModule::GetClassObject(nsIComponentManager *aCompMgr, desc++; } // not found in descriptions -#ifdef DEBUG +#ifndef XPCOM_GLUE +#ifdef DEBUG char* cs = aClass.ToString(); fprintf(stderr, "+++ nsGenericModule %s: unable to create factory for %s\n", mModuleName, cs); // leak until we resolve the nsID Allocator. // nsCRT::free(cs); #endif // XXX put in stop-gap so that we don't search for this one again +#endif return NS_ERROR_FACTORY_NOT_REGISTERED; } diff --git a/xpcom/glue/standalone/nsXPCOMGlue.cpp b/xpcom/glue/standalone/nsXPCOMGlue.cpp index 737c29ecdf5e..e73e4908390d 100644 --- a/xpcom/glue/standalone/nsXPCOMGlue.cpp +++ b/xpcom/glue/standalone/nsXPCOMGlue.cpp @@ -54,7 +54,7 @@ static XPCOMFunctions *xpcomFunctions = nsnull; // seawood tells me there isn't a better way... #ifdef XP_PC -#define XPCOM_DLL "xpcom32.dll" +#define XPCOM_DLL "xpcom.dll" #else #ifdef XP_MAC #define XPCOM_DLL "XPCOM_DLL" @@ -249,109 +249,3 @@ NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine) return NS_ERROR_NOT_INITIALIZED; return xpcomFunctions->unregisterExitRoutine(exitRoutine); } - -#if DEBUG_dougt - -struct nsTraceRefcntStats { - nsrefcnt mAddRefs; - nsrefcnt mReleases; - nsrefcnt mCreates; - nsrefcnt mDestroys; - double mRefsOutstandingTotal; - double mRefsOutstandingSquared; - double mObjsOutstandingTotal; - double mObjsOutstandingSquared; -}; - -// Function type used by GatherStatistics. For each type that data has -// been gathered for, this function is called with the counts of the -// various operations that have been logged. The function can return -// PR_FALSE if the gathering should stop. -// -// aCurrentStats is the current value of the counters. aPrevStats is -// the previous value of the counters which is established by the -// nsTraceRefcnt::SnapshotStatistics call. -typedef PRBool (PR_CALLBACK *nsTraceRefcntStatFunc) - (const char* aTypeName, - PRUint32 aInstanceSize, - nsTraceRefcntStats* aCurrentStats, - nsTraceRefcntStats* aPrevStats, - void *aClosure); - -class nsTraceRefcnt { -public: - static NS_EXPORT void Startup(){}; - - static NS_EXPORT void Shutdown(){}; - - static NS_EXPORT void LogAddRef(void* aPtr, - nsrefcnt aNewRefCnt, - const char* aTypeName, - PRUint32 aInstanceSize){}; - - static NS_EXPORT void LogRelease(void* aPtr, - nsrefcnt aNewRefCnt, - const char* aTypeName){}; - - static NS_EXPORT void LogNewXPCOM(void* aPtr, - const char* aTypeName, - PRUint32 aInstanceSize, - const char* aFile, - int aLine){}; - - static NS_EXPORT void LogDeleteXPCOM(void* aPtr, - const char* aFile, - int aLine){}; - - static NS_EXPORT nsrefcnt LogAddRefCall(void* aPtr, - nsrefcnt aNewRefcnt, - const char* aFile, - int aLine){return 0;}; - - static NS_EXPORT nsrefcnt LogReleaseCall(void* aPtr, - nsrefcnt aNewRefcnt, - const char* aFile, - int aLine){return 0;}; - - static NS_EXPORT void LogCtor(void* aPtr, const char* aTypeName, - PRUint32 aInstanceSize){}; - - static NS_EXPORT void LogDtor(void* aPtr, const char* aTypeName, - PRUint32 aInstanceSize){}; - - static NS_EXPORT void LogAddCOMPtr(void *aCOMPtr, nsISupports *aObject){}; - - static NS_EXPORT void LogReleaseCOMPtr(void *aCOMPtr, nsISupports *aObject){}; - - enum StatisticsType { - ALL_STATS, - NEW_STATS - }; - - static NS_EXPORT nsresult DumpStatistics(StatisticsType type = ALL_STATS, - FILE* out = 0){return NS_ERROR_NOT_IMPLEMENTED;}; - - static NS_EXPORT void ResetStatistics(void){}; - - static NS_EXPORT void GatherStatistics(nsTraceRefcntStatFunc aFunc, - void* aClosure){}; - - static NS_EXPORT void LoadLibrarySymbols(const char* aLibraryName, - void* aLibrayHandle){}; - - static NS_EXPORT void DemangleSymbol(const char * aSymbol, - char * aBuffer, - int aBufLen){}; - - static NS_EXPORT void WalkTheStack(FILE* aStream){}; - - static NS_EXPORT void SetPrefServiceAvailability(PRBool avail){}; - - /** - * Tell nsTraceRefcnt whether refcounting, allocation, and destruction - * activity is legal. This is used to trigger assertions for any such - * activity that occurs because of static constructors or destructors. - */ - static NS_EXPORT void SetActivityIsLegal(PRBool aLegal){}; -}; -#endif diff --git a/xpcom/sample/Makefile.in b/xpcom/sample/Makefile.in index adc9c630172a..649e08e3311f 100644 --- a/xpcom/sample/Makefile.in +++ b/xpcom/sample/Makefile.in @@ -64,7 +64,8 @@ EXTRA_COMPONENTS = nsSample.js # seperate libraries linked in. EXTRA_DSO_LDOPTS = \ $(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) \ - $(XPCOM_LIBS) \ + $(DIST)/lib/$(LIB_PREFIX)string_s.$(LIB_SUFFIX) \ + $(DIST)/lib/$(LIB_PREFIX)string_obsolete_s.$(LIB_SUFFIX) \ $(NSPR_LIBS) \ $(NULL) diff --git a/xpcom/sample/nsSample.cpp b/xpcom/sample/nsSample.cpp index f017b5358f67..b4ae63abfcce 100644 --- a/xpcom/sample/nsSample.cpp +++ b/xpcom/sample/nsSample.cpp @@ -47,11 +47,12 @@ #include "nsSample.h" #include "nsMemory.h" - +#include "nsXPCOMGlue.h" //////////////////////////////////////////////////////////////////////// nsSampleImpl::nsSampleImpl() : mValue(nsnull) { + XPCOMGlueStartup("XPCOMComponentGlue"); NS_INIT_ISUPPORTS(); mValue = (char*)nsMemory::Clone("initial value", 14); } @@ -60,6 +61,8 @@ nsSampleImpl::~nsSampleImpl() { if (mValue) nsMemory::Free(mValue); + + XPCOMGlueShutdown(); } /** diff --git a/xpcom/sample/nsTestSample.cpp b/xpcom/sample/nsTestSample.cpp index 68f053ae114d..68a086fd2dbd 100644 --- a/xpcom/sample/nsTestSample.cpp +++ b/xpcom/sample/nsTestSample.cpp @@ -48,6 +48,7 @@ #include "nsIServiceManager.h" #include "nsXPIDLString.h" #include "nsIComponentRegistrar.h" +#include "nsXPCOMGlue.h" #define NS_SAMPLE_CONTRACTID "@mozilla.org/sample;1" @@ -56,6 +57,8 @@ main(void) { nsresult rv; + XPCOMGlueStartup(nsnull); + // Initialize XPCOM nsCOMPtr servMan; rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); @@ -121,8 +124,17 @@ main(void) rv = mysample->WriteValue("Final print :"); printf("Test passed.\n"); - + + // All nsCOMPtr's must be deleted prior to calling shutdown XPCOM + // as we should not hold references passed XPCOM Shutdown. + servMan = 0; + registrar = 0; + manager = 0; + mysample = 0; + // Shutdown XPCOM NS_ShutdownXPCOM(nsnull); + + return 0; }