From a08bffac6a5d55774983bd3c1dc5b80af324ad19 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Fri, 27 Sep 2002 13:07:01 +0000 Subject: [PATCH] Fixes XPCOM Glue on linux, b=168584, sr=rpotts, r=alec --- xpcom/build/nsXPComInit.cpp | 40 +++++++++++++++++------- xpcom/glue/nsGenericFactory.cpp | 45 +++++++++++++++++++++++++-- xpcom/glue/nsIGenericFactory.h | 1 + xpcom/glue/standalone/nsXPCOMGlue.cpp | 2 +- xpcom/io/Makefile.in | 5 ++- xpcom/io/nsDirectoryService.h | 3 ++ xpcom/io/nsDirectoryServiceDefs.h | 7 ++--- 7 files changed, 82 insertions(+), 21 deletions(-) diff --git a/xpcom/build/nsXPComInit.cpp b/xpcom/build/nsXPComInit.cpp index 3dd8199f48b..da28c0a1439 100644 --- a/xpcom/build/nsXPComInit.cpp +++ b/xpcom/build/nsXPComInit.cpp @@ -109,6 +109,17 @@ #endif #include "nsRecyclingAllocator.h" +// seawood tells me there isn't a better way... +#ifdef XP_PC +#define XPCOM_DLL "xpcom.dll" +#else +#ifdef XP_MAC +#define XPCOM_DLL "XPCOM_DLL" +#else +#define XPCOM_DLL "libxpcom"MOZ_DLL_SUFFIX +#endif +#endif + // Registry Factory creation function defined in nsRegistry.cpp // We hook into this function locally to create and register the registry // Since noone outside xpcom needs to know about this and nsRegistry.cpp @@ -359,11 +370,6 @@ static const nsModuleComponentInfo components[] = { const int components_length = sizeof(components) / sizeof(components[0]); -static const PRStaticLinkTable sGlueSymbols[] = { { - "NS_GetFrozenFunctions", - (void (* PR_CALLBACK)())&NS_GetFrozenFunctions -} } ; - // gMemory will be freed during shutdown. static nsIMemory* gMemory = nsnull; nsresult NS_COM NS_GetMemoryManager(nsIMemory* *result) @@ -417,8 +423,6 @@ 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), @@ -442,14 +446,18 @@ nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result, if (compMgr == NULL) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(compMgr); - + + nsCOMPtr xpcomLib; + PRBool value; if (binDirectory) { rv = binDirectory->IsDirectory(&value); - if (NS_SUCCEEDED(rv) && value) + if (NS_SUCCEEDED(rv) && value) { gDirectoryService->Set(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, binDirectory); + binDirectory->Clone(getter_AddRefs(xpcomLib)); + } //Since people are still using the nsSpecialSystemDirectory, we should init it. nsCAutoString path; @@ -459,6 +467,17 @@ nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result, nsSpecialSystemDirectory::Set(nsSpecialSystemDirectory::Moz_BinDirectory, &spec); } + else { + gDirectoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, + NS_GET_IID(nsIFile), + getter_AddRefs(xpcomLib)); + } + + if (xpcomLib) { + xpcomLib->AppendNative(nsDependentCString(XPCOM_DLL)); + gDirectoryService->Set(NS_XPCOM_LIBRARY_FILE, xpcomLib); + } + if (appFileLocationProvider) { rv = dirService->RegisterProvider(appFileLocationProvider); if (NS_FAILED(rv)) return rv; @@ -775,8 +794,6 @@ nsresult NS_COM NS_ShutdownXPCOM(nsIServiceManager* servMgr) return NS_OK; } - - nsresult NS_COM PR_CALLBACK NS_GetFrozenFunctions(XPCOMFunctions *functions, const char* libraryPath) { @@ -841,7 +858,6 @@ NS_GetFrozenFunctions(XPCOMFunctions *functions, const char* libraryPath) PR_UnloadLibrary(xpcomLib); return NS_ERROR_FAILURE; } - PR_UnloadLibrary(xpcomLib); // the library is refcnt'ed above by the caller. xpcomLib = nsnull; diff --git a/xpcom/glue/nsGenericFactory.cpp b/xpcom/glue/nsGenericFactory.cpp index 89562a6e8c2..9e161530107 100644 --- a/xpcom/glue/nsGenericFactory.cpp +++ b/xpcom/glue/nsGenericFactory.cpp @@ -45,6 +45,14 @@ #include "nsIComponentManager.h" #include "nsIComponentRegistrar.h" +#ifdef XPCOM_GLUE +#include "nsXPCOMGlue.h" +#include "nsIServiceManager.h" +#include "nsIFile.h" +#include "nsDirectoryServiceDefs.h" +#include "nsDirectoryService.h" +#endif + nsGenericFactory::nsGenericFactory(const nsModuleComponentInfo *info) : mInfo(info) { @@ -231,6 +239,11 @@ nsGenericModule::nsGenericModule(const char* moduleName, PRUint32 componentCount nsGenericModule::~nsGenericModule() { Shutdown(); + +#ifdef XPCOM_GLUE + XPCOMGlueShutdown(); +#endif + } NS_IMPL_THREADSAFE_ISUPPORTS1(nsGenericModule, nsIModule) @@ -254,17 +267,45 @@ nsGenericModule::AddFactoryNode(nsIGenericFactory* fact) nsresult nsGenericModule::Initialize(nsIComponentManager *compMgr) { + nsresult rv; + if (mInitialized) { return NS_OK; } if (mCtor) { - nsresult rv = mCtor(this); + rv = mCtor(this); if (NS_FAILED(rv)) return rv; } - nsresult rv; + +#ifdef XPCOM_GLUE + nsCOMPtr servMgr = do_QueryInterface(compMgr, &rv); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr dirService; + rv = servMgr->GetServiceByContractID(NS_DIRECTORY_SERVICE_CONTRACTID, + NS_GET_IID(nsIProperties), + getter_AddRefs(dirService)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr xpcomDll; + rv = dirService->Get(NS_XPCOM_LIBRARY_FILE, NS_GET_IID(nsIFile), getter_AddRefs(xpcomDll)); + if (NS_FAILED(rv)) + return rv; + + nsCAutoString path; + xpcomDll->GetNativePath(path); + rv = XPCOMGlueStartup(path.get()); + + if (NS_FAILED(rv)) + return rv; + +#endif + nsCOMPtr registrar = do_QueryInterface(compMgr, &rv); if (NS_FAILED(rv)) return rv; diff --git a/xpcom/glue/nsIGenericFactory.h b/xpcom/glue/nsIGenericFactory.h index c6251839ff4..e6fe3404586 100644 --- a/xpcom/glue/nsIGenericFactory.h +++ b/xpcom/glue/nsIGenericFactory.h @@ -40,6 +40,7 @@ #include "nsIFactory.h" #include "nsIModule.h" +#include "nsIClassInfo.h" // {3bc97f01-ccdf-11d2-bab8-b548654461fc} #define NS_GENERICFACTORY_CID \ diff --git a/xpcom/glue/standalone/nsXPCOMGlue.cpp b/xpcom/glue/standalone/nsXPCOMGlue.cpp index 499c83610d4..c20a2845d38 100644 --- a/xpcom/glue/standalone/nsXPCOMGlue.cpp +++ b/xpcom/glue/standalone/nsXPCOMGlue.cpp @@ -61,7 +61,7 @@ static XPCOMFunctions *xpcomFunctions = nsnull; #ifdef XP_MAC #define XPCOM_DLL "XPCOM_DLL" #else -#define XPCOM_DLL "libxpcom.so" +#define XPCOM_DLL "libxpcom"MOZ_DLL_SUFFIX #endif #endif diff --git a/xpcom/io/Makefile.in b/xpcom/io/Makefile.in index 86f4b8695a2..8e4009b2016 100644 --- a/xpcom/io/Makefile.in +++ b/xpcom/io/Makefile.in @@ -79,7 +79,6 @@ endif # OS2 EXPORTS = \ nsAppDirectoryServiceDefs.h \ nsDirectoryService.h \ - nsDirectoryServiceDefs.h \ nsDirectoryServiceUtils.h \ nsEscape.h \ nsFastLoadPtr.h \ @@ -144,6 +143,10 @@ SDK_XPIDLSRCS = \ nsIScriptableInputStream.idl \ $(NULL) +SDK_HEADERS = \ + nsDirectoryServiceDefs.h \ + $(NULL) + EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS)) # we don't want the shared lib, but we want to force the creation of a static lib. diff --git a/xpcom/io/nsDirectoryService.h b/xpcom/io/nsDirectoryService.h index 221e39291a0..e3ad9a5ceac 100644 --- a/xpcom/io/nsDirectoryService.h +++ b/xpcom/io/nsDirectoryService.h @@ -45,6 +45,9 @@ #include "nsISupportsArray.h" #include "nsIAtom.h" +#define NS_XPCOM_INIT_CURRENT_PROCESS_DIR "MozBinD" // Can be used to set NS_XPCOM_CURRENT_PROCESS_DIR + // CANNOT be used to GET a location + class nsDirectoryService : public nsIDirectoryService, public nsIProperties, public nsIDirectoryServiceProvider2 diff --git a/xpcom/io/nsDirectoryServiceDefs.h b/xpcom/io/nsDirectoryServiceDefs.h index cc387ddea49..115b6820518 100755 --- a/xpcom/io/nsDirectoryServiceDefs.h +++ b/xpcom/io/nsDirectoryServiceDefs.h @@ -48,16 +48,13 @@ // Keys whose definition ends in "DIR" or "FILE" return a single nsIFile (or subclass). // Keys whose definition ends in "LIST" return an nsISimpleEnumerator which enumerates a // list of file objects. +// //======================================================================================== - - - -#define NS_XPCOM_INIT_CURRENT_PROCESS_DIR "MozBinD" // Can be used to set NS_XPCOM_CURRENT_PROCESS_DIR - // CANNOT be used to GET a location #define NS_XPCOM_CURRENT_PROCESS_DIR "XCurProcD" #define NS_XPCOM_COMPONENT_REGISTRY_FILE "ComRegF" #define NS_XPCOM_COMPONENT_DIR "ComsD" +#define NS_XPCOM_LIBRARY_FILE "XpcomLib" #define NS_GRE_DIR "GreD" #define NS_GRE_COMPONENT_DIR "GreComsD"