diff --git a/xpcom/libxpt/xptinfo/src/nsInterfaceInfo.cpp b/xpcom/libxpt/xptinfo/src/nsInterfaceInfo.cpp index 402429a82b33..8e7a2bd45bec 100644 --- a/xpcom/libxpt/xptinfo/src/nsInterfaceInfo.cpp +++ b/xpcom/libxpt/xptinfo/src/nsInterfaceInfo.cpp @@ -63,20 +63,18 @@ nsInterfaceInfo::GetName(char** name) { NS_PRECONDITION(name, "bad param"); -// nsIAllocator* allocator; -// if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) { + nsIAllocator* allocator; + if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) { int len = strlen(mEntry->name)+1; -// char* p = (char*)allocator->Alloc(len); - // XXX malloc for now. - char *p = (char *)malloc(len); -// NS_RELEASE(allocator); + char* p = (char*)allocator->Alloc(len); + NS_RELEASE(allocator); if(p) { memcpy(p, mEntry->name, len); *name = p; return NS_OK; } -// } - + } + *name = NULL; return NS_ERROR_FAILURE; } @@ -86,18 +84,16 @@ nsInterfaceInfo::GetIID(nsIID** iid) { NS_PRECONDITION(iid, "bad param"); -// nsIAllocator* allocator; -// if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) { -// nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID)); -// NS_RELEASE(allocator); - // XXX malloc for now. - nsIID* p = (nsIID*)malloc(sizeof(nsIID)); + nsIAllocator* allocator; + if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) { + nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID)); + NS_RELEASE(allocator); if(p) { memcpy(p, &mEntry->iid, sizeof(nsIID)); *iid = p; return NS_OK; } -// } + } *iid = NULL; return NS_ERROR_FAILURE; diff --git a/xpcom/libxpt/xptinfo/src/nsInterfaceInfoManager.cpp b/xpcom/libxpt/xptinfo/src/nsInterfaceInfoManager.cpp index 8e17e21d769c..4d506a1a2a07 100644 --- a/xpcom/libxpt/xptinfo/src/nsInterfaceInfoManager.cpp +++ b/xpcom/libxpt/xptinfo/src/nsInterfaceInfoManager.cpp @@ -147,9 +147,7 @@ nsInterfaceInfoManager::nsInterfaceInfoManager() kIAllocatorIID, (nsISupports **)&mAllocator); - // just added this baby. - // allocator isn't currently registered, so just use malloc instead. -// PR_ASSERT((mAllocator != NULL)); + PR_ASSERT((mAllocator != NULL)); } nsInterfaceInfo * @@ -232,10 +230,8 @@ nsInterfaceInfoManager::GetIIDForName(const char* name, nsIID** iid) if (!strcmp(name, entry->name)) { nsIID* p; - // Allocator isn't registered, so just use malloc for now... -// if(!(p = (nsIID*)mAllocator->Alloc(sizeof(nsIID)))) -// break; - if (!(p = (nsIID*)malloc(sizeof(nsIID)))) + + if(!(p = (nsIID*)mAllocator->Alloc(sizeof(nsIID)))) break; // XXX I'm confused here about the lifetime of IID pointers. diff --git a/xpcom/libxpt/xptinfo/tests/TestInterfaceInfo.cpp b/xpcom/libxpt/xptinfo/tests/TestInterfaceInfo.cpp index 46ccf687293d..06b02252ef03 100644 --- a/xpcom/libxpt/xptinfo/tests/TestInterfaceInfo.cpp +++ b/xpcom/libxpt/xptinfo/tests/TestInterfaceInfo.cpp @@ -24,12 +24,38 @@ #include "nsIInterfaceInfo.h" #include "nsIInterfaceInfoManager.h" - -// XTC_PUBLIC_API(nsIInterfaceInfoManager*) -// XPT_GetInterfaceInfoManager(); +static void RegAllocator(); int main (int argc, char **argv) { + RegAllocator(); + nsIInterfaceInfoManager *iim = XPT_GetInterfaceInfoManager(); nsIID *iid; iim->GetIIDForName("Interface", &iid); } + + +// XXX remove following code when allocator autoregisters. +#include "nsRepository.h" +#include "nsIAllocator.h" + +static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID); +static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID); + +#ifdef XP_PC +#define XPCOM_DLL "xpcom32.dll" +#else +#ifdef XP_MAC +#define XPCOM_DLL "XPCOM_DLL" +#else +#define XPCOM_DLL "libxpcom.so" +#endif +#endif + +static void RegAllocator() +{ + nsRepository::RegisterComponent(kAllocatorCID, NULL, NULL, XPCOM_DLL, + PR_FALSE, PR_FALSE); +} + + diff --git a/xpcom/reflect/xptinfo/src/nsInterfaceInfo.cpp b/xpcom/reflect/xptinfo/src/nsInterfaceInfo.cpp index 402429a82b33..8e7a2bd45bec 100644 --- a/xpcom/reflect/xptinfo/src/nsInterfaceInfo.cpp +++ b/xpcom/reflect/xptinfo/src/nsInterfaceInfo.cpp @@ -63,20 +63,18 @@ nsInterfaceInfo::GetName(char** name) { NS_PRECONDITION(name, "bad param"); -// nsIAllocator* allocator; -// if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) { + nsIAllocator* allocator; + if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) { int len = strlen(mEntry->name)+1; -// char* p = (char*)allocator->Alloc(len); - // XXX malloc for now. - char *p = (char *)malloc(len); -// NS_RELEASE(allocator); + char* p = (char*)allocator->Alloc(len); + NS_RELEASE(allocator); if(p) { memcpy(p, mEntry->name, len); *name = p; return NS_OK; } -// } - + } + *name = NULL; return NS_ERROR_FAILURE; } @@ -86,18 +84,16 @@ nsInterfaceInfo::GetIID(nsIID** iid) { NS_PRECONDITION(iid, "bad param"); -// nsIAllocator* allocator; -// if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) { -// nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID)); -// NS_RELEASE(allocator); - // XXX malloc for now. - nsIID* p = (nsIID*)malloc(sizeof(nsIID)); + nsIAllocator* allocator; + if(NULL != (allocator = nsInterfaceInfoManager::GetAllocator())) { + nsIID* p = (nsIID*)allocator->Alloc(sizeof(nsIID)); + NS_RELEASE(allocator); if(p) { memcpy(p, &mEntry->iid, sizeof(nsIID)); *iid = p; return NS_OK; } -// } + } *iid = NULL; return NS_ERROR_FAILURE; diff --git a/xpcom/reflect/xptinfo/src/nsInterfaceInfoManager.cpp b/xpcom/reflect/xptinfo/src/nsInterfaceInfoManager.cpp index 8e17e21d769c..4d506a1a2a07 100644 --- a/xpcom/reflect/xptinfo/src/nsInterfaceInfoManager.cpp +++ b/xpcom/reflect/xptinfo/src/nsInterfaceInfoManager.cpp @@ -147,9 +147,7 @@ nsInterfaceInfoManager::nsInterfaceInfoManager() kIAllocatorIID, (nsISupports **)&mAllocator); - // just added this baby. - // allocator isn't currently registered, so just use malloc instead. -// PR_ASSERT((mAllocator != NULL)); + PR_ASSERT((mAllocator != NULL)); } nsInterfaceInfo * @@ -232,10 +230,8 @@ nsInterfaceInfoManager::GetIIDForName(const char* name, nsIID** iid) if (!strcmp(name, entry->name)) { nsIID* p; - // Allocator isn't registered, so just use malloc for now... -// if(!(p = (nsIID*)mAllocator->Alloc(sizeof(nsIID)))) -// break; - if (!(p = (nsIID*)malloc(sizeof(nsIID)))) + + if(!(p = (nsIID*)mAllocator->Alloc(sizeof(nsIID)))) break; // XXX I'm confused here about the lifetime of IID pointers. diff --git a/xpcom/reflect/xptinfo/tests/TestInterfaceInfo.cpp b/xpcom/reflect/xptinfo/tests/TestInterfaceInfo.cpp index 46ccf687293d..06b02252ef03 100644 --- a/xpcom/reflect/xptinfo/tests/TestInterfaceInfo.cpp +++ b/xpcom/reflect/xptinfo/tests/TestInterfaceInfo.cpp @@ -24,12 +24,38 @@ #include "nsIInterfaceInfo.h" #include "nsIInterfaceInfoManager.h" - -// XTC_PUBLIC_API(nsIInterfaceInfoManager*) -// XPT_GetInterfaceInfoManager(); +static void RegAllocator(); int main (int argc, char **argv) { + RegAllocator(); + nsIInterfaceInfoManager *iim = XPT_GetInterfaceInfoManager(); nsIID *iid; iim->GetIIDForName("Interface", &iid); } + + +// XXX remove following code when allocator autoregisters. +#include "nsRepository.h" +#include "nsIAllocator.h" + +static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID); +static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID); + +#ifdef XP_PC +#define XPCOM_DLL "xpcom32.dll" +#else +#ifdef XP_MAC +#define XPCOM_DLL "XPCOM_DLL" +#else +#define XPCOM_DLL "libxpcom.so" +#endif +#endif + +static void RegAllocator() +{ + nsRepository::RegisterComponent(kAllocatorCID, NULL, NULL, XPCOM_DLL, + PR_FALSE, PR_FALSE); +} + +