More XPCOM Glue changes and fixes. r=waterson, sr=rpotts, 154262.

This commit is contained in:
dougt%netscape.com 2002-07-01 20:37:17 +00:00
parent 00c8c0eeca
commit c327e1c6c3
7 changed files with 34 additions and 113 deletions

View File

@ -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();

View File

@ -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
{

View File

@ -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;
}

View File

@ -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

View File

@ -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)

View File

@ -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();
}
/**

View File

@ -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<nsIServiceManager> 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;
}