From 4c803332db3d65e69023449aa65d771d08b1f0fa Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Thu, 21 Mar 2002 23:43:21 +0000 Subject: [PATCH] 130405. Makes the xpcom glue library usable. Updates XPCOM Samples. Adds requires lines to a few implict string/category consumers sr=alecf, sr=brendan@mozilla.org a=asa@mozilla.org --- allmakefiles.sh | 1 + db/mork/build/Makefile.in | 1 + db/mork/build/makefile.win | 53 ------- gfx2/src/Makefile.in | 1 + gfx2/src/makefile.win | 47 ------ js/src/liveconnect/Makefile.in | 1 + js/src/liveconnect/makefile.win | 3 +- modules/libpr0n/decoders/mng/Makefile.in | 3 +- modules/libpr0n/decoders/mng/makefile.win | 52 ------- xpcom/base/nscore.h | 2 + xpcom/build/Makefile.in | 2 +- xpcom/build/nsXPCOM.h | 4 +- xpcom/components/Makefile.in | 13 +- xpcom/components/makefile.win | 33 +++-- xpcom/components/nsComponentManager.cpp | 165 ++++++--------------- xpcom/components/nsComponentManagerUtils.h | 37 ----- xpcom/glue/Makefile.in | 28 ++-- xpcom/glue/makefile.win | 1 + xpcom/glue/nsCOMPtr.h | 12 +- xpcom/glue/nsComponentManagerUtils.h | 37 ----- xpcom/glue/nsDebug.cpp | 4 +- xpcom/glue/nsIGenericFactory.h | 6 +- xpcom/glue/nsIInterfaceRequestorUtils.h | 2 +- xpcom/glue/nsISupportsImpl.h | 4 +- xpcom/glue/nsIWeakReferenceUtils.h | 2 +- xpcom/glue/nsMemory.cpp | 18 +-- xpcom/glue/nsMemory.h | 12 +- xpcom/macbuild/xpcomPPC.xml | 30 ++++ xpcom/sample/Makefile.in | 34 ++++- xpcom/sample/nsSample.cpp | 13 +- xpcom/sample/nsTestSample.cpp | 11 +- 31 files changed, 197 insertions(+), 435 deletions(-) diff --git a/allmakefiles.sh b/allmakefiles.sh index 0d7f799c6fa..9ac57a40941 100755 --- a/allmakefiles.sh +++ b/allmakefiles.sh @@ -545,6 +545,7 @@ xpcom/build/Makefile xpcom/components/Makefile xpcom/ds/Makefile xpcom/glue/Makefile +xpcom/glue/standalone/Makefile xpcom/io/Makefile xpcom/typelib/Makefile xpcom/reflect/Makefile diff --git a/db/mork/build/Makefile.in b/db/mork/build/Makefile.in index 0ec065c1b55..ea84cbef3c5 100644 --- a/db/mork/build/Makefile.in +++ b/db/mork/build/Makefile.in @@ -32,6 +32,7 @@ EXPORT_LIBRARY = 1 IS_COMPONENT = 1 MODULE_NAME = nsMorkModule REQUIRES = xpcom \ + string \ $(NULL) CPPSRCS = nsMorkFactory.cpp diff --git a/db/mork/build/makefile.win b/db/mork/build/makefile.win index 3b1e1525d7b..e69de29bb2d 100644 --- a/db/mork/build/makefile.win +++ b/db/mork/build/makefile.win @@ -1,53 +0,0 @@ -#!gmake -# -# The contents of this file are subject to the Netscape Public -# License Version 1.1 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.mozilla.org/NPL/ -# -# Software distributed under the License is distributed on an "AS -# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or -# implied. See the License for the specific language governing -# rights and limitations under the License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is Netscape -# Communications Corporation. Portions created by Netscape are -# Copyright (C) 1998 Netscape Communications Corporation. All -# Rights Reserved. -# -# Contributor(s): - -DEPTH=..\..\.. -MODULE = mork -LIBRARY_NAME = mork -MODULE_NAME = nsMorkModule -REQUIRES = xpcom \ - $(NULL) - -################################################################################ -## exports - -EXPORTS= \ - nsMorkCID.h \ - nsIMdbFactoryFactory.h \ - $(NULL) - -################################################################################ -## library - -CPP_OBJS= \ - .\$(OBJDIR)\nsMorkFactory.obj \ - $(NULL) - -SUB_LIBRARIES= \ - $(DIST)\lib\msgmork_s.lib \ - $(NULL) - -LLIBS= \ - $(DIST)\lib\xpcom.lib \ - $(LIBNSPR) \ - $(NULL) - -include <$(DEPTH)\config\rules.mak> diff --git a/gfx2/src/Makefile.in b/gfx2/src/Makefile.in index 2cab4c5934c..ebfc3365e43 100644 --- a/gfx2/src/Makefile.in +++ b/gfx2/src/Makefile.in @@ -38,6 +38,7 @@ EXTRA_DSO_LIBS = gkgfx endif REQUIRES = xpcom \ + string \ gfx \ $(NULL) diff --git a/gfx2/src/makefile.win b/gfx2/src/makefile.win index 5d742ebb9db..e69de29bb2d 100644 --- a/gfx2/src/makefile.win +++ b/gfx2/src/makefile.win @@ -1,47 +0,0 @@ -#!nmake -# -# The contents of this file are subject to the Mozilla Public -# License Version 1.1 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS -# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or -# implied. See the License for the specific language governing -# rights and limitations under the License. -# -# The Original Code is mozilla.org code -# -# The Initial Developer of the Original Code is Netscape -# Communications Corporation. Portions created by Netscape are -# Copyright (C) 2000 Netscape Communications Corporation. All -# Rights Reserved. -# -# Contributor(s): -# Stuart Parmenter -# - -DEPTH=..\.. - -MODULE=gfx2 -REQUIRES = xpcom \ - gfx \ - $(NULL) -include <$(DEPTH)/config/config.mak> - -LIBRARY_NAME=gfx2 -MODULE_NAME=nsGfx2Module - -LCFLAGS = -DWIN32_LEAN_AND_MEAN - -CPP_OBJS = \ - .\$(OBJDIR)\nsGfxFactory.obj \ - .\$(OBJDIR)\gfxImageFrame.obj \ - $(NULL) - -LLIBS = \ - $(DIST)\lib\gkgfx.lib \ - $(DIST)\lib\xpcom.lib - -include <$(DEPTH)\config\rules.mak> - diff --git a/js/src/liveconnect/Makefile.in b/js/src/liveconnect/Makefile.in index 081561ba330..9b8f30f19a0 100644 --- a/js/src/liveconnect/Makefile.in +++ b/js/src/liveconnect/Makefile.in @@ -46,6 +46,7 @@ LIBRARY_NAME = jsj$(MOZ_BITS)$(VERSION_NUMBER) MAPFILE = $(LIBRARY_NAME).map endif REQUIRES = js \ + string \ xpcom \ xpconnect \ $(NULL) diff --git a/js/src/liveconnect/makefile.win b/js/src/liveconnect/makefile.win index d8860fdd081..3e77a2709f6 100644 --- a/js/src/liveconnect/makefile.win +++ b/js/src/liveconnect/makefile.win @@ -47,7 +47,8 @@ DEPTH= ..\..\.. MODULE = java REQUIRES = xpcom \ - js \ + string\ + js \ xpconnect \ $(NULL) include <$(DEPTH)/config/config.mak> diff --git a/modules/libpr0n/decoders/mng/Makefile.in b/modules/libpr0n/decoders/mng/Makefile.in index 0a131bb9b68..11bc53c465a 100644 --- a/modules/libpr0n/decoders/mng/Makefile.in +++ b/modules/libpr0n/decoders/mng/Makefile.in @@ -34,7 +34,8 @@ ifeq ($(OS_ARCH),WINNT) EXTRA_DSO_LIBS = gkgfx endif -REQUIRES = xpcom \ +REQUIRES = string \ + xpcom \ gfx \ gfx2 \ imglib2 \ diff --git a/modules/libpr0n/decoders/mng/makefile.win b/modules/libpr0n/decoders/mng/makefile.win index 7bb2f1ca97b..e69de29bb2d 100644 --- a/modules/libpr0n/decoders/mng/makefile.win +++ b/modules/libpr0n/decoders/mng/makefile.win @@ -1,52 +0,0 @@ -#!nmake -# -# The contents of this file are subject to the Mozilla Public -# License Version 1.1 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS -# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or -# implied. See the License for the specific language governing -# rights and limitations under the License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is Tim Rowley. -# Portions created by Tim Rowley are -# Copyright (C) 2001 Tim Rowley. Rights Reserved. -# -# Contributor(s): -# Tim Rowley - -DEPTH=..\..\..\.. -MODULE = imgmng -REQUIRES = xpcom \ - gfx \ - gfx2 \ - imglib2 \ - mng \ - jpeg \ - zlib \ - $(NULL) -include <$(DEPTH)/config/config.mak> - -LIBRARY_NAME = imgmng -MODULE_NAME = nsMNGDecoderModule - -OBJS = \ - .\$(OBJDIR)\nsMNGDecoder.obj \ - .\$(OBJDIR)\imgContainerMNG.obj \ - .\$(OBJDIR)\nsMNGFactory.obj \ - $(NULL) - -LLIBS=\ - $(LIBNSPR) \ - $(DIST)\lib\xpcom.lib \ - $(DIST)\lib\mng.lib \ - $(DIST)\lib\jpeg3250.lib \ - $(DIST)\lib\zlib.lib \ - $(DIST)\lib\gkgfx.lib \ - $(NULL) - -include <$(DEPTH)\config\rules.mak> diff --git a/xpcom/base/nscore.h b/xpcom/base/nscore.h index 9a8e641701e..ee609532b3a 100644 --- a/xpcom/base/nscore.h +++ b/xpcom/base/nscore.h @@ -119,6 +119,8 @@ #ifdef _IMPL_NS_COM #define NS_COM NS_EXPORT +#elif _IMPL_NS_COM_OFF +#define NS_COM #else #define NS_COM NS_IMPORT #endif diff --git a/xpcom/build/Makefile.in b/xpcom/build/Makefile.in index edd7225afe0..09e303b001f 100644 --- a/xpcom/build/Makefile.in +++ b/xpcom/build/Makefile.in @@ -67,7 +67,7 @@ SHARED_LIBRARY_LIBS = \ $(DIST)/lib/$(LIB_PREFIX)mozreg_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)string_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)string_obsolete_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) \ + $(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \ $(NULL) LOCAL_INCLUDES = \ diff --git a/xpcom/build/nsXPCOM.h b/xpcom/build/nsXPCOM.h index 72027624110..e4ceea39fd9 100644 --- a/xpcom/build/nsXPCOM.h +++ b/xpcom/build/nsXPCOM.h @@ -35,8 +35,8 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef nsXPCom_h__ -#define nsXPCom_h__ +#ifndef nsXPCOM_h__ +#define nsXPCOM_h__ #include "nscore.h" diff --git a/xpcom/components/Makefile.in b/xpcom/components/Makefile.in index 8bb09f912ab..3d27280e2f0 100644 --- a/xpcom/components/Makefile.in +++ b/xpcom/components/Makefile.in @@ -45,11 +45,12 @@ CPPSRCS = \ # XXX not really right. ifdef MOZ_STATIC_COMPONENT_LIBS -CPPSRCS += nsStaticComponentLoader.cpp +CPPSRCS += nsStaticComponentLoader.cpp DEFINES += -DENABLE_STATIC_COMPONENT_LOADER=1 endif EXPORTS = \ + nsCategoryManagerUtils.h \ nsComponentManagerUtils.h \ nsComponentManagerObsolete.h \ nsIRegistryUtils.h \ @@ -71,11 +72,11 @@ XPIDLSRCS = \ nsIRegistry.idl \ $(NULL) -SDK_XPIDLSRCS = \ - nsIClassInfo.idl \ - nsIFactory.idl \ - nsIModule.idl \ - nsIServiceManager.idl \ +SDK_XPIDLSRCS = \ + nsIClassInfo.idl \ + nsIFactory.idl \ + nsIModule.idl \ + nsIServiceManager.idl \ nsIComponentManager.idl \ $(NULL) diff --git a/xpcom/components/makefile.win b/xpcom/components/makefile.win index 651a8b53864..4afca3a3930 100644 --- a/xpcom/components/makefile.win +++ b/xpcom/components/makefile.win @@ -24,38 +24,39 @@ DEPTH=..\.. MODULE = xpcom XPIDL_MODULE = xpcom_components -REQUIRES = mozreg \ - string \ - $(NULL) +REQUIRES = mozreg \ + string \ + $(NULL) ################################################################################ ## exports EXPORTS = \ + nsCategoryManagerUtil.h \ nsComponentManagerObsolete.h \ - nsComponentManagerUtils.h \ + nsComponentManagerUtils.h \ nsIComponentManagerUtils.h \ nsIRegistryUtils.h \ nsIServiceManagerObsolete.h \ nsIServiceManagerUtils.h \ nsXPComFactory.h \ - nsNativeComponentLoader.h \ + nsNativeComponentLoader.h \ nsStaticComponent.h \ - xcDll.h \ + xcDll.h \ nsObsoleteModuleLoading.h \ - $(NULL) + $(NULL) XPIDLSRCS = \ - .\nsICategoryHandler.idl \ - .\nsICategoryManager.idl \ - .\nsIClassInfo.idl \ + .\nsICategoryHandler.idl \ + .\nsICategoryManager.idl \ + .\nsIClassInfo.idl \ .\nsIComponentLoader.idl \ - .\nsIComponentManager.idl \ + .\nsIComponentManager.idl \ .\nsIComponentManagerObsolete.idl \ .\nsIComponentRegistrar.idl \ - .\nsIFactory.idl \ - .\nsIModule.idl \ - .\nsIRegistry.idl \ + .\nsIFactory.idl \ + .\nsIModule.idl \ + .\nsIRegistry.idl \ .\nsIServiceManager.idl \ $(NULL) @@ -68,7 +69,7 @@ LINCS = \ -I..\base \ -I..\threads \ -I..\io \ - $(NULL) + $(NULL) LCFLAGS = -DUSE_NSREG -D_IMPL_NS_COM -D_IMPL_NS_BASE -DWIN32_LEAN_AND_MEAN @@ -90,7 +91,7 @@ CPP_OBJS = \ include <$(DEPTH)\config\rules.mak> libs:: $(LIBRARY) - $(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib + $(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib clobber:: $(RM) $(DIST)\lib\$(LIBRARY_NAME).lib diff --git a/xpcom/components/nsComponentManager.cpp b/xpcom/components/nsComponentManager.cpp index 5c1bf27fb1d..7d394ef7a5d 100644 --- a/xpcom/components/nsComponentManager.cpp +++ b/xpcom/components/nsComponentManager.cpp @@ -42,6 +42,7 @@ #include "nsDirectoryService.h" #include "nsDirectoryServiceDefs.h" #include "nsICategoryManager.h" +#include "nsCategoryManagerUtils.h" #include "nsIComponentLoader.h" #include "nsIEnumerator.h" #include "nsIInterfaceInfoManager.h" @@ -130,38 +131,9 @@ extern PRBool gXPCOMShuttingDown; #define USE_REGISTRY #endif /* USE_NSREG */ -nsresult -nsCreateInstanceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const - { - nsresult status = nsComponentManager::CreateInstance(mCID, mOuter, aIID, aInstancePtr); - if ( NS_FAILED(status) ) - *aInstancePtr = 0; - - if ( mErrorPtr ) - *mErrorPtr = status; - return status; - } nsresult -nsCreateInstanceByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const - { - nsresult status; - if ( mContractID ) - { - if ( NS_FAILED(status = nsComponentManager::CreateInstance(mContractID, mOuter, aIID, aInstancePtr)) ) - *aInstancePtr = 0; - } - else - status = NS_ERROR_NULL_POINTER; - - if ( mErrorPtr ) - *mErrorPtr = status; - return status; - } - -nsresult -nsCreateInstanceFromCategory::operator()( const nsIID& aIID, - void** aInstancePtr ) const +nsCreateInstanceFromCategory::operator()( const nsIID& aIID, void** aInstancePtr) const { /* * If I were a real man, I would consolidate this with @@ -169,11 +141,12 @@ nsCreateInstanceFromCategory::operator()( const nsIID& aIID, */ nsresult status; nsXPIDLCString value; + nsCOMPtr compMgr; nsCOMPtr catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &status); - + if (NS_FAILED(status)) goto error; - + if (!mCategory || !mEntry) { // when categories have defaults, use that for null mEntry status = NS_ERROR_NULL_POINTER; @@ -188,104 +161,60 @@ nsCreateInstanceFromCategory::operator()( const nsIID& aIID, status = NS_ERROR_SERVICE_NOT_FOUND; goto error; } - - status = nsComponentManager::CreateInstance(value, mOuter, aIID, - aInstancePtr); - error: + NS_GetComponentManager(getter_AddRefs(compMgr)); + if (!compMgr) + return NS_ERROR_FAILURE; + compMgr->CreateInstanceByContractID(value, + mOuter, + aIID, + aInstancePtr); + error: if (NS_FAILED(status)) { *aInstancePtr = 0; } - + *mErrorPtr = status; return status; } nsresult -nsGetServiceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const - { - nsresult status = NS_ERROR_FAILURE; - if ( mServiceManager ) { - status = mServiceManager->GetService(mCID, aIID, (void**)aInstancePtr); - } else { - nsCOMPtr mgr; - NS_GetServiceManager(getter_AddRefs(mgr)); - if (mgr) - status = mgr->GetService(mCID, aIID, (void**)aInstancePtr); - } - if ( NS_FAILED(status) ) - *aInstancePtr = 0; - - if ( mErrorPtr ) - *mErrorPtr = status; - return status; - } - -nsresult -nsGetServiceByContractID::operator()( const nsIID& aIID, void** aInstancePtr ) const - { - nsresult status = NS_ERROR_FAILURE; - if ( mServiceManager ) { - status = mServiceManager->GetServiceByContractID(mContractID, aIID, (void**)aInstancePtr); - } else { - nsCOMPtr mgr; - NS_GetServiceManager(getter_AddRefs(mgr)); - if (mgr) - status = mgr->GetServiceByContractID(mContractID, aIID, (void**)aInstancePtr); - } - - if ( NS_FAILED(status) ) - *aInstancePtr = 0; - - if ( mErrorPtr ) - *mErrorPtr = status; - return status; -} - -nsresult -nsGetServiceFromCategory::operator()( const nsIID& aIID, void** aInstancePtr) - const +nsGetServiceFromCategory::operator()( const nsIID& aIID, void** aInstancePtr) const { - nsresult status; - nsXPIDLCString value; - nsCOMPtr catman = - do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &status); - - if (NS_FAILED(status)) goto error; - - if (!mCategory || !mEntry) { - // when categories have defaults, use that for null mEntry - status = NS_ERROR_NULL_POINTER; - goto error; - } - - /* find the contractID for category.entry */ - status = catman->GetCategoryEntry(mCategory, mEntry, - getter_Copies(value)); - if (NS_FAILED(status)) goto error; - if (!value) { - status = NS_ERROR_SERVICE_NOT_FOUND; - goto error; - } - - if ( mServiceManager ) { - status = mServiceManager->GetServiceByContractID(value, aIID, (void**)aInstancePtr); - } else { - nsCOMPtr mgr; - NS_GetServiceManager(getter_AddRefs(mgr)); - if (mgr) - status = mgr->GetServiceByContractID(value, aIID, (void**)aInstancePtr); + nsresult status; + nsXPIDLCString value; + nsCOMPtr catman = + do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &status); + if (NS_FAILED(status)) goto error; + if (!mCategory || !mEntry) { + // when categories have defaults, use that for null mEntry + status = NS_ERROR_NULL_POINTER; + goto error; } - - if (NS_FAILED(status)) { - error: - *aInstancePtr = 0; - } - - *mErrorPtr = status; - return status; + /* find the contractID for category.entry */ + status = catman->GetCategoryEntry(mCategory, mEntry, + getter_Copies(value)); + if (NS_FAILED(status)) goto error; + if (!value) { + status = NS_ERROR_SERVICE_NOT_FOUND; + goto error; + } + if ( mServiceManager ) { + status = mServiceManager->GetServiceByContractID(value, aIID, (void**)aInstancePtr); + } else { + nsCOMPtr mgr; + NS_GetServiceManager(getter_AddRefs(mgr)); + if (mgr) + status = mgr->GetServiceByContractID(value, aIID, (void**)aInstancePtr); + } + if (NS_FAILED(status)) { + error: + *aInstancePtr = 0; + } + *mErrorPtr = status; + return status; } - + //////////////////////////////////////////////////////////////////////////////// // Hashtable Callbacks //////////////////////////////////////////////////////////////////////////////// diff --git a/xpcom/components/nsComponentManagerUtils.h b/xpcom/components/nsComponentManagerUtils.h index bf3d78f9771..2f17dfefc1a 100644 --- a/xpcom/components/nsComponentManagerUtils.h +++ b/xpcom/components/nsComponentManagerUtils.h @@ -78,27 +78,6 @@ private: nsresult* mErrorPtr; }; -class nsCreateInstanceFromCategory : public nsCOMPtr_helper -{ -public: - nsCreateInstanceFromCategory(const char *aCategory, const char *aEntry, - nsISupports *aOuter, nsresult *aErrorPtr) - : mCategory(aCategory), - mEntry(aEntry), - mErrorPtr(aErrorPtr) - { - // nothing else to do; - } - virtual nsresult operator()( const nsIID&, void** ) const; - virtual ~nsCreateInstanceFromCategory() {}; - -private: - const char *mCategory; - const char *mEntry; - nsISupports *mOuter; - nsresult *mErrorPtr; -}; - inline const nsCreateInstanceByCID do_CreateInstance( const nsCID& aCID, nsresult* error = 0 ) @@ -127,22 +106,6 @@ do_CreateInstance( const char* aContractID, nsISupports* aOuter, nsresult* error return nsCreateInstanceByContractID(aContractID, aOuter, error); } -inline -const nsCreateInstanceFromCategory -do_CreateInstanceFromCategory( const char *aCategory, const char *aEntry, - nsresult *aErrorPtr = 0) -{ - return nsCreateInstanceFromCategory(aCategory, aEntry, 0, aErrorPtr); -} - -inline -const nsCreateInstanceFromCategory -do_CreateInstanceFromCategory( const char *aCategory, const char *aEntry, - nsISupports *aOuter, nsresult *aErrorPtr = 0) -{ - return nsCreateInstanceFromCategory(aCategory, aEntry, aOuter, aErrorPtr); -} - // type-safe shortcuts for calling |CreateInstance| template inline diff --git a/xpcom/glue/Makefile.in b/xpcom/glue/Makefile.in index 431884194e8..cab5e89086b 100644 --- a/xpcom/glue/Makefile.in +++ b/xpcom/glue/Makefile.in @@ -25,23 +25,24 @@ srcdir = @srcdir@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk +include $(srcdir)/objs.mk + +DIRS = standalone MODULE = xpcom XPIDL_MODULE = xpcom_glue -LIBRARY_NAME = xpcomglue +LIBRARY_NAME = xpcomglue_s -CPPSRCS = \ - nsCOMPtr.cpp \ - nsDebug.cpp \ - nsGenericFactory.cpp \ - nsMemory.cpp \ - nsWeakReference.cpp \ - $(NULL) +REQUIRES = $(NULL) LOCAL_INCLUDES = \ -I$(srcdir)/../build \ $(NULL) +CPPSRCS = \ + $(XPCOM_GLUE_SRC_LCSRCS) \ + $(NULL) + EXPORTS = \ nsIGenericFactory.h \ nsIInterfaceRequestorUtils.h \ @@ -51,14 +52,11 @@ EXPORTS = \ $(NULL) SDK_HEADERS = \ - nsCOMPtr.h \ - nsDebug.h \ - nsMemory.h \ - nsWeakReference.h\ + $(XPCOM_GLUE_SRC_LEXPORTS) \ $(NULL) SDK_BINARY = \ - $(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) \ + $(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \ $(NULL) # we don't want the shared lib, but we want to force the creation of a static lib. @@ -69,7 +67,9 @@ FORCE_USE_PIC = 1 include $(topsrcdir)/config/rules.mk -DEFINES += -D_IMPL_NS_COM -D_IMPL_NS_BASE +DEFINES += \ + -D_IMPL_NS_COM \ + -D_IMPL_NS_BASE ifeq ($(OS_ARCH),WINNT) DEFINES += -DWIN32_LEAN_AND_MEAN diff --git a/xpcom/glue/makefile.win b/xpcom/glue/makefile.win index 281890c673b..6a21a504539 100755 --- a/xpcom/glue/makefile.win +++ b/xpcom/glue/makefile.win @@ -58,6 +58,7 @@ CPP_OBJS = \ .\$(OBJDIR)\nsGenericFactory.obj \ .\$(OBJDIR)\nsMemory.obj \ .\$(OBJDIR)\nsWeakReference.obj \ + .\$(OBJDIR)\nsComponentManagerUtils.obj \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/xpcom/glue/nsCOMPtr.h b/xpcom/glue/nsCOMPtr.h index b0e8bcd8f07..2ec46a970fd 100644 --- a/xpcom/glue/nsCOMPtr.h +++ b/xpcom/glue/nsCOMPtr.h @@ -67,7 +67,7 @@ #ifndef nscore_h___ #include "nscore.h" - // for |NS_..._CAST|, |NS_EXPORT| + // for |NS_..._CAST|, |NS_COM| #endif @@ -403,16 +403,16 @@ class nsCOMPtr_base } #ifdef NSCAP_FEATURE_FACTOR_DESTRUCTOR - NS_EXPORT ~nsCOMPtr_base(); + NS_COM ~nsCOMPtr_base(); #else // Allow debug builds to link with optimized versions of nsCOMPtr-using // plugins (e.g., JVMs). - NS_EXPORT ~nsCOMPtr_base() { } + NS_COM ~nsCOMPtr_base() { } #endif - NS_EXPORT void assign_with_AddRef( nsISupports* ); - NS_EXPORT void assign_from_helper( const nsCOMPtr_helper&, const nsIID& ); - NS_EXPORT void** begin_assignment(); + NS_COM void assign_with_AddRef( nsISupports* ); + NS_COM void assign_from_helper( const nsCOMPtr_helper&, const nsIID& ); + NS_COM void** begin_assignment(); protected: nsISupports* mRawPtr; diff --git a/xpcom/glue/nsComponentManagerUtils.h b/xpcom/glue/nsComponentManagerUtils.h index bf3d78f9771..2f17dfefc1a 100644 --- a/xpcom/glue/nsComponentManagerUtils.h +++ b/xpcom/glue/nsComponentManagerUtils.h @@ -78,27 +78,6 @@ private: nsresult* mErrorPtr; }; -class nsCreateInstanceFromCategory : public nsCOMPtr_helper -{ -public: - nsCreateInstanceFromCategory(const char *aCategory, const char *aEntry, - nsISupports *aOuter, nsresult *aErrorPtr) - : mCategory(aCategory), - mEntry(aEntry), - mErrorPtr(aErrorPtr) - { - // nothing else to do; - } - virtual nsresult operator()( const nsIID&, void** ) const; - virtual ~nsCreateInstanceFromCategory() {}; - -private: - const char *mCategory; - const char *mEntry; - nsISupports *mOuter; - nsresult *mErrorPtr; -}; - inline const nsCreateInstanceByCID do_CreateInstance( const nsCID& aCID, nsresult* error = 0 ) @@ -127,22 +106,6 @@ do_CreateInstance( const char* aContractID, nsISupports* aOuter, nsresult* error return nsCreateInstanceByContractID(aContractID, aOuter, error); } -inline -const nsCreateInstanceFromCategory -do_CreateInstanceFromCategory( const char *aCategory, const char *aEntry, - nsresult *aErrorPtr = 0) -{ - return nsCreateInstanceFromCategory(aCategory, aEntry, 0, aErrorPtr); -} - -inline -const nsCreateInstanceFromCategory -do_CreateInstanceFromCategory( const char *aCategory, const char *aEntry, - nsISupports *aOuter, nsresult *aErrorPtr = 0) -{ - return nsCreateInstanceFromCategory(aCategory, aEntry, aOuter, aErrorPtr); -} - // type-safe shortcuts for calling |CreateInstance| template inline diff --git a/xpcom/glue/nsDebug.cpp b/xpcom/glue/nsDebug.cpp index 944f38d4630..eadb24ae62e 100644 --- a/xpcom/glue/nsDebug.cpp +++ b/xpcom/glue/nsDebug.cpp @@ -492,8 +492,8 @@ NS_ErrorAccordingToNSPR() #include "nsISupportsUtils.h" #include "prthread.h" -extern "C" NS_EXPORT void* NS_CurrentThread(void); -extern "C" NS_EXPORT void NS_CheckThreadSafe(void* owningThread, const char* msg); +extern "C" NS_COM void* NS_CurrentThread(void); +extern "C" NS_COM void NS_CheckThreadSafe(void* owningThread, const char* msg); void* NS_CurrentThread(void) diff --git a/xpcom/glue/nsIGenericFactory.h b/xpcom/glue/nsIGenericFactory.h index 254fa2fdd31..c6251839ff4 100644 --- a/xpcom/glue/nsIGenericFactory.h +++ b/xpcom/glue/nsIGenericFactory.h @@ -68,7 +68,7 @@ public: NS_IMETHOD GetComponentInfo(const nsModuleComponentInfo **infop) = 0; }; -extern NS_COM nsresult +NS_COM nsresult NS_NewGenericFactory(nsIGenericFactory **result, const nsModuleComponentInfo *info); @@ -299,13 +299,13 @@ struct nsModuleInfo { * Create a new generic module. Use the NS_IMPL_NSGETMODULE macro, or * one of its relatives, rather than using this directly. */ -extern NS_COM nsresult +NS_COM nsresult NS_NewGenericModule2(nsModuleInfo *info, nsIModule* *result); /** * Obsolete. Use NS_NewGenericModule2() instead. */ -extern NS_COM nsresult +NS_COM nsresult NS_NewGenericModule(const char* moduleName, PRUint32 componentCount, nsModuleComponentInfo* components, diff --git a/xpcom/glue/nsIInterfaceRequestorUtils.h b/xpcom/glue/nsIInterfaceRequestorUtils.h index 0b1fd03c8ad..89bd60b6393 100644 --- a/xpcom/glue/nsIInterfaceRequestorUtils.h +++ b/xpcom/glue/nsIInterfaceRequestorUtils.h @@ -38,7 +38,7 @@ CallGetInterface( T* aSource, DestinationType** aDestination ) NS_REINTERPRET_CAST(void**, aDestination)); } -class NS_EXPORT nsGetInterface : public nsCOMPtr_helper +class NS_COM nsGetInterface : public nsCOMPtr_helper { public: nsGetInterface( nsISupports* aSource, nsresult* error ) diff --git a/xpcom/glue/nsISupportsImpl.h b/xpcom/glue/nsISupportsImpl.h index 867ebad792e..5b6a5ed78a7 100644 --- a/xpcom/glue/nsISupportsImpl.h +++ b/xpcom/glue/nsISupportsImpl.h @@ -53,8 +53,8 @@ #if defined(NS_DEBUG) && defined(NS_MT_SUPPORTED) -extern "C" NS_EXPORT void* NS_CurrentThread(void); -extern "C" NS_EXPORT void NS_CheckThreadSafe(void* owningThread, +extern "C" NS_COM void* NS_CurrentThread(void); +extern "C" NS_COM void NS_CheckThreadSafe(void* owningThread, const char* msg); #define NS_DECL_OWNINGTHREAD void* _mOwningThread; diff --git a/xpcom/glue/nsIWeakReferenceUtils.h b/xpcom/glue/nsIWeakReferenceUtils.h index 051d37f85ba..034c697ab90 100644 --- a/xpcom/glue/nsIWeakReferenceUtils.h +++ b/xpcom/glue/nsIWeakReferenceUtils.h @@ -64,7 +64,7 @@ CallQueryReferent( T* aSource, DestinationType** aDestination ) } -class NS_EXPORT nsQueryReferent : public nsCOMPtr_helper +class NS_COM nsQueryReferent : public nsCOMPtr_helper { public: nsQueryReferent( nsIWeakReference* aWeakPtr, nsresult* error ) diff --git a/xpcom/glue/nsMemory.cpp b/xpcom/glue/nsMemory.cpp index e26c79e36a2..ec4879ad94b 100644 --- a/xpcom/glue/nsMemory.cpp +++ b/xpcom/glue/nsMemory.cpp @@ -35,12 +35,8 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsCOMPtr.h" +#include "nsXPCOM.h" #include "nsMemory.h" -#include "nsIObserver.h" -#include "nsIObserverService.h" -#include "nsIServiceManager.h" - #include "nsXPCOMPrivate.h" @@ -72,7 +68,7 @@ SetupGlobalMemory() //////////////////////////////////////////////////////////////////////////////// // nsMemory static helper routines -NS_EXPORT void* +NS_COM void* nsMemory::Alloc(PRSize size) { if (!ENSURE_ALLOCATOR) @@ -81,7 +77,7 @@ nsMemory::Alloc(PRSize size) return gMemory->Alloc(size); } -NS_EXPORT void* +NS_COM void* nsMemory::Realloc(void* ptr, PRSize size) { if (!ENSURE_ALLOCATOR) @@ -90,7 +86,7 @@ nsMemory::Realloc(void* ptr, PRSize size) return gMemory->Realloc(ptr, size); } -NS_EXPORT void +NS_COM void nsMemory::Free(void* ptr) { if (!ENSURE_ALLOCATOR) @@ -99,7 +95,7 @@ nsMemory::Free(void* ptr) gMemory->Free(ptr); } -NS_EXPORT nsresult +NS_COM nsresult nsMemory::HeapMinimize(PRBool aImmediate) { if (!ENSURE_ALLOCATOR) @@ -108,7 +104,7 @@ nsMemory::HeapMinimize(PRBool aImmediate) return gMemory->HeapMinimize(aImmediate); } -NS_EXPORT void* +NS_COM void* nsMemory::Clone(const void* ptr, PRSize size) { if (!ENSURE_ALLOCATOR) @@ -120,7 +116,7 @@ nsMemory::Clone(const void* ptr, PRSize size) return newPtr; } -NS_EXPORT nsIMemory* +NS_COM nsIMemory* nsMemory::GetGlobalMemoryService() { if (!ENSURE_ALLOCATOR) diff --git a/xpcom/glue/nsMemory.h b/xpcom/glue/nsMemory.h index 7046da92566..4a53a7b521d 100644 --- a/xpcom/glue/nsMemory.h +++ b/xpcom/glue/nsMemory.h @@ -63,12 +63,12 @@ class nsMemory { public: - static NS_EXPORT void* Alloc(size_t size); - static NS_EXPORT void* Realloc(void* ptr, size_t size); - static NS_EXPORT void Free(void* ptr); - static NS_EXPORT nsresult HeapMinimize(PRBool aImmediate); - static NS_EXPORT void* Clone(const void* ptr, size_t size); - static NS_EXPORT nsIMemory* GetGlobalMemoryService(); // AddRefs + static NS_COM void* Alloc(size_t size); + static NS_COM void* Realloc(void* ptr, size_t size); + static NS_COM void Free(void* ptr); + static NS_COM nsresult HeapMinimize(PRBool aImmediate); + static NS_COM void* Clone(const void* ptr, size_t size); + static NS_COM nsIMemory* GetGlobalMemoryService(); // AddRefs }; /** diff --git a/xpcom/macbuild/xpcomPPC.xml b/xpcom/macbuild/xpcomPPC.xml index 40cb5ddc4d2..ceedb1d954c 100644 --- a/xpcom/macbuild/xpcomPPC.xml +++ b/xpcom/macbuild/xpcomPPC.xml @@ -1156,6 +1156,13 @@ Text Debug + + Name + nsComponentManagerUtils.cpp + MacOS + Text + Debug + Name nsComponentManagerObsolete.cpp @@ -1988,6 +1995,11 @@ nsComponentManager.cpp MacOS + + Name + nsComponentManagerUtils.cpp + MacOS + Name nsComponentManagerObsolete.cpp @@ -3620,6 +3632,13 @@ Text Debug + + Name + nsComponentManagerUtils.cpp + MacOS + Text + Debug + Name nsComponentManagerObsolete.cpp @@ -4457,6 +4476,11 @@ nsComponentManager.cpp MacOS + + Name + nsComponentManagerUtils.cpp + MacOS + Name nsComponentManagerObsolete.cpp @@ -5102,6 +5126,12 @@ nsComponentManager.cpp MacOS + + xpcom.shlb + Name + nsComponentManagerUtils.cpp + MacOS + xpcom.shlb Name diff --git a/xpcom/sample/Makefile.in b/xpcom/sample/Makefile.in index ead2dc34a7f..6ccb8cf357a 100644 --- a/xpcom/sample/Makefile.in +++ b/xpcom/sample/Makefile.in @@ -26,14 +26,22 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -MODULE = xpcom -XPIDL_MODULE = sample -LIBRARY_NAME = sample +MODULE = xpcomsample +XPIDL_MODULE = xpcomsample +LIBRARY_NAME = xpcomsample + IS_COMPONENT = 1 MODULE_NAME = nsSampleModule -REQUIRES = string \ - $(NULL) +# Ensure that the xpcom classes that we build +# do not export themselves +DEFINES += -D_IMPL_NS_COM_OFF + + +REQUIRES = string \ + xpcom \ + xpcomsample \ + $(NULL) CPPSRCS = \ nsSample.cpp \ @@ -43,12 +51,24 @@ CPPSRCS = \ XPIDLSRCS = nsISample.idl TESTCPPSRCS = nsTestSample.cpp + CPPSRCS += $(TESTCPPSRCS) + SIMPLE_PROGRAMS = $(TESTCPPSRCS:.cpp=$(BIN_SUFFIX)) include $(topsrcdir)/config/config.mk -LIBS += \ +# seperate libraries linked in. +EXTRA_DSO_LDOPTS = \ + $(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) \ + $(XPCOM_LIBS) \ + $(NSPR_LIBS) \ + $(NULL) + +LIBS = \ + $(DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX) \ + $(DIST)/lib/$(LIB_PREFIX)string_s.$(LIB_SUFFIX) \ + $(DIST)/lib/$(LIB_PREFIX)string_obsolete_s.$(LIB_SUFFIX) \ $(XPCOM_LIBS) \ $(NSPR_LIBS) \ $(NULL) @@ -60,8 +80,6 @@ endif include $(topsrcdir)/config/rules.mk -EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS) - libs:: $(TARGETS) $(INSTALL) $(srcdir)/xpconnect-sample.html $(DIST)/bin/res/samples $(INSTALL) $(srcdir)/nsSample.js $(DIST)/bin/components diff --git a/xpcom/sample/nsSample.cpp b/xpcom/sample/nsSample.cpp index b47b0620b63..f017b5358f6 100644 --- a/xpcom/sample/nsSample.cpp +++ b/xpcom/sample/nsSample.cpp @@ -43,7 +43,6 @@ * of the interface nsISample. * */ -#include "plstr.h" #include #include "nsSample.h" @@ -54,13 +53,13 @@ nsSampleImpl::nsSampleImpl() : mValue(nsnull) { NS_INIT_ISUPPORTS(); - mValue = PL_strdup("initial value"); + mValue = (char*)nsMemory::Clone("initial value", 14); } nsSampleImpl::~nsSampleImpl() { if (mValue) - PL_strfree(mValue); + nsMemory::Free(mValue); } /** @@ -105,11 +104,9 @@ nsSampleImpl::GetValue(char** aValue) * This convention lets things like JavaScript reflection do their * job, and simplifies the way C++ clients deal with returned buffers. */ - *aValue = (char*) nsMemory::Alloc(PL_strlen(mValue) + 1); + *aValue = (char*) nsMemory::Clone(mValue, strlen(mValue) + 1); if (! *aValue) return NS_ERROR_NULL_POINTER; - - PL_strcpy(*aValue, mValue); } else { *aValue = nsnull; @@ -125,7 +122,7 @@ nsSampleImpl::SetValue(const char* aValue) return NS_ERROR_NULL_POINTER; if (mValue) { - PL_strfree(mValue); + nsMemory::Free(mValue); } /** @@ -134,7 +131,7 @@ nsSampleImpl::SetValue(const char* aValue) * declared "inout". If you want to keep the value for posterity, * you will have to make a copy of it. */ - mValue = PL_strdup(aValue); + mValue = (char*) nsMemory::Clone(aValue, strlen(aValue) + 1); return NS_OK; } diff --git a/xpcom/sample/nsTestSample.cpp b/xpcom/sample/nsTestSample.cpp index 2b2df42c376..48b86dcb338 100644 --- a/xpcom/sample/nsTestSample.cpp +++ b/xpcom/sample/nsTestSample.cpp @@ -67,9 +67,15 @@ main(void) NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); registrar->AutoRegister(nsnull); - + nsCOMPtr manager = do_QueryInterface(registrar); + NS_ASSERTION(registrar, "Null nsIComponentManager"); + // Create an instance of our component - nsCOMPtr mysample = do_CreateInstance(NS_SAMPLE_CONTRACTID, &rv); + nsCOMPtr mysample; + rv = manager->CreateInstanceByContractID(NS_SAMPLE_CONTRACTID, + nsnull, + NS_GET_IID(nsISample), + getter_AddRefs(mysample)); if (NS_FAILED(rv)) { printf("ERROR: Cannot create instance of component " NS_SAMPLE_CONTRACTID " [%x].\n" @@ -110,6 +116,7 @@ main(void) printf("Test FAILED.\n"); return -4; } + rv = mysample->WriteValue("Final print :"); printf("Test passed.\n");