- In nsInterfaceInfoManager.cpp, get the allocator with nsAllocator::GetGlobalAllocator, not from nsServiceManager. (Allocator now cached with nsCOMPtr.)

- Insure that debugging code in nsInterfaceInfo and TestInterfaceInfo fails gracefully instead of segfaulting.


git-svn-id: svn://10.0.0.236/trunk@48042 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
frankm%eng.sun.com 1999-09-17 22:46:44 +00:00
parent f3e1c4442b
commit 8b6ad17152
4 changed files with 27 additions and 16 deletions

View File

@ -379,10 +379,17 @@ nsInterfaceInfo::GetLengthIsArgNumberForParam(uint16 methodIndex,
void
nsInterfaceInfo::print(FILE *fd)
{
if (this == NULL) {
fprintf(fd, "No record!!\n");
return;
}
const char *name_space = this->mInterfaceRecord->name_space;
fprintf(fd, "iid: %s name: %s name_space: %s\n",
this->mInterfaceRecord->iid.ToString(),
this->mInterfaceRecord->name,
this->mInterfaceRecord->name_space);
(name_space) ? name_space : "(none)");
if (mParent != NULL) {
fprintf(fd, "parent:\n\t");
this->mParent->print(fd);

View File

@ -89,19 +89,15 @@ nsInterfaceInfoManager::GetAllocator(nsInterfaceInfoManager* iim /*= NULL*/)
return al;
}
static NS_DEFINE_CID(kAllocatorCID, NS_ALLOCATOR_CID);
nsInterfaceInfoManager::nsInterfaceInfoManager()
: typelibRecords(NULL), allocator(NULL), ctor_succeeded(PR_FALSE)
{
NS_INIT_REFCNT();
NS_ADDREF_THIS();
nsServiceManager::GetService(kAllocatorCID,
NS_GET_IID(nsIAllocator),
(nsISupports **)&this->allocator);
PR_ASSERT(this->allocator != NULL);
// GetGlobalAllocator add-refs its return value
this->allocator = dont_AddRef(nsAllocator::GetGlobalAllocator());
PR_ASSERT(allocator.get());
if(NS_SUCCEEDED(this->initInterfaceTables()))
ctor_succeeded = PR_TRUE;
@ -110,12 +106,13 @@ nsInterfaceInfoManager::nsInterfaceInfoManager()
static
XPTHeader *getHeader(const char *filename, nsIAllocator *al) {
XPTState *state = NULL;
XPTCursor curs, *cursor = &curs;
XPTCursor curs;
XPTHeader *header = NULL;
PRFileInfo fileinfo;
PRUint32 flen;
char *whole = NULL;
PRFileDesc *in = NULL;
XPTCursor *cursor = &curs;
if (PR_GetFileInfo(filename, &fileinfo) != PR_SUCCESS) {
NS_ERROR("PR_GetFileInfo failed");
@ -331,11 +328,10 @@ nsInterfaceInfoManager::initInterfaceTables()
return NS_ERROR_FAILURE;
}
// this code stolen from SetupRegistry; it might bear further
// examination, as the code there doesn't look quite done.
nsSpecialSystemDirectory sysdir(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
sysdir += "components";
// const char *xptdirname = sysdir.GetCString(); // native path
// this seems to be the One True Way to get the components directory
// (frankm@eng.sun.com, 9.9.99)
nsSpecialSystemDirectory
sysdir(nsSpecialSystemDirectory::XPCOM_CurrentProcessComponentDirectory);
#ifdef XP_MAC
PRBool wasAlias;

View File

@ -27,6 +27,8 @@
#include "nsIInterfaceInfoManager.h"
#include "nsHashtable.h"
#include "nsCOMPtr.h"
#include "xpt_struct.h"
#include "nsInterfaceInfo.h"
@ -70,7 +72,7 @@ private:
// mapping between IIDs and records.
nsHashtable *IIDTable;
nsIAllocator *allocator;
nsCOMPtr<nsIAllocator> allocator;
PRBool ctor_succeeded;
};

View File

@ -82,7 +82,13 @@ int main (int argc, char **argv) {
#ifdef DEBUG
((nsInterfaceInfo *)info5)->print(stderr);
#endif
// XXX: nsIServiceManager is no more; what do we test with?
if (info5 == NULL) {
fprintf(stderr, "\nNo nsIServiceManager; cannot continue.\n");
return 1;
}
uint16 methodcount;
info5->GetMethodCount(&methodcount);
const nsXPTMethodInfo *mi;