Not yet part of Seamonkey.

Changed from using malloc to (much less, but still slightly) hacked
nsIAllocator service.
This commit is contained in:
mccabe%netscape.com 1999-03-02 05:38:27 +00:00
parent 33bdf8086c
commit 8c24b0a7f5
6 changed files with 86 additions and 50 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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