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

This commit is contained in:
dougt%netscape.com 2002-03-21 23:43:21 +00:00
Родитель 3c4b350d18
Коммит 40642fc34c
31 изменённых файлов: 202 добавлений и 285 удалений

Просмотреть файл

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

Просмотреть файл

@ -32,6 +32,7 @@ EXPORT_LIBRARY = 1
IS_COMPONENT = 1
MODULE_NAME = nsMorkModule
REQUIRES = xpcom \
string \
$(NULL)
CPPSRCS = nsMorkFactory.cpp

Просмотреть файл

@ -23,7 +23,8 @@ DEPTH=..\..\..
MODULE = mork
LIBRARY_NAME = mork
MODULE_NAME = nsMorkModule
REQUIRES = xpcom \
REQUIRES = string \
xpcom \
$(NULL)
################################################################################

Просмотреть файл

@ -38,6 +38,7 @@ EXTRA_DSO_LIBS = gkgfx
endif
REQUIRES = xpcom \
string \
gfx \
$(NULL)

Просмотреть файл

@ -25,6 +25,7 @@ DEPTH=..\..
MODULE=gfx2
REQUIRES = xpcom \
string \
gfx \
$(NULL)
include <$(DEPTH)/config/config.mak>

Просмотреть файл

@ -46,6 +46,7 @@ LIBRARY_NAME = jsj$(MOZ_BITS)$(VERSION_NUMBER)
MAPFILE = $(LIBRARY_NAME).map
endif
REQUIRES = js \
string \
xpcom \
xpconnect \
$(NULL)

Просмотреть файл

@ -47,7 +47,8 @@
DEPTH= ..\..\..
MODULE = java
REQUIRES = xpcom \
js \
string\
js \
xpconnect \
$(NULL)
include <$(DEPTH)/config/config.mak>

Просмотреть файл

@ -34,7 +34,8 @@ ifeq ($(OS_ARCH),WINNT)
EXTRA_DSO_LIBS = gkgfx
endif
REQUIRES = xpcom \
REQUIRES = string \
xpcom \
gfx \
gfx2 \
imglib2 \

Просмотреть файл

@ -21,7 +21,8 @@
DEPTH=..\..\..\..
MODULE = imgmng
REQUIRES = xpcom \
REQUIRES = string \
xpcom \
gfx \
gfx2 \
imglib2 \

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -35,8 +35,8 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsXPCom_h__
#define nsXPCom_h__
#ifndef nsXPCOM_h__
#define nsXPCOM_h__
#include "nscore.h"

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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,6 +141,7 @@ nsCreateInstanceFromCategory::operator()( const nsIID& aIID,
*/
nsresult status;
nsXPIDLCString value;
nsCOMPtr<nsIComponentManager> compMgr;
nsCOMPtr<nsICategoryManager> catman =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &status);
@ -188,10 +161,14 @@ 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;
}
@ -202,88 +179,40 @@ nsCreateInstanceFromCategory::operator()( const nsIID& aIID,
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<nsIServiceManager> 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<nsIServiceManager> 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<nsICategoryManager> 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<nsIServiceManager> mgr;
NS_GetServiceManager(getter_AddRefs(mgr));
if (mgr)
status = mgr->GetServiceByContractID(value, aIID, (void**)aInstancePtr);
nsresult status;
nsXPIDLCString value;
nsCOMPtr<nsICategoryManager> 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<nsIServiceManager> 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;
}
////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -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 <class DestinationType>
inline

Просмотреть файл

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

Просмотреть файл

@ -58,6 +58,7 @@ CPP_OBJS = \
.\$(OBJDIR)\nsGenericFactory.obj \
.\$(OBJDIR)\nsMemory.obj \
.\$(OBJDIR)\nsWeakReference.obj \
.\$(OBJDIR)\nsComponentManagerUtils.obj \
$(NULL)
include <$(DEPTH)\config\rules.mak>

Просмотреть файл

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

Просмотреть файл

@ -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 <class DestinationType>
inline

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -1156,6 +1156,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsComponentManagerUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsComponentManagerObsolete.cpp</PATH>
@ -1988,6 +1995,11 @@
<PATH>nsComponentManager.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsComponentManagerUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsComponentManagerObsolete.cpp</PATH>
@ -3620,6 +3632,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsComponentManagerUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsComponentManagerObsolete.cpp</PATH>
@ -4457,6 +4476,11 @@
<PATH>nsComponentManager.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsComponentManagerUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsComponentManagerObsolete.cpp</PATH>
@ -5102,6 +5126,12 @@
<PATH>nsComponentManager.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>xpcom.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsComponentManagerUtils.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>xpcom.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>

Просмотреть файл

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

Просмотреть файл

@ -43,7 +43,6 @@
* of the interface nsISample.
*
*/
#include "plstr.h"
#include <stdio.h>
#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;
}

Просмотреть файл

@ -67,9 +67,15 @@ main(void)
NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
registrar->AutoRegister(nsnull);
nsCOMPtr<nsIComponentManager> manager = do_QueryInterface(registrar);
NS_ASSERTION(registrar, "Null nsIComponentManager");
// Create an instance of our component
nsCOMPtr<nsISample> mysample = do_CreateInstance(NS_SAMPLE_CONTRACTID, &rv);
nsCOMPtr<nsISample> 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");