Bug 350092 - webservices should use plarenas instead of xptarenas, r=doron

This commit is contained in:
benjamin%smedbergs.us 2006-08-25 13:40:29 +00:00
Родитель 6d3790fd72
Коммит d73c9ee8ab
2 изменённых файлов: 27 добавлений и 17 удалений

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

@ -51,6 +51,7 @@
#include "nsWeakReference.h"
#include "nsIGenericFactory.h"
#include "nsVariant.h"
#include "plarena.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
@ -74,10 +75,8 @@ public:
nsGenericInterfaceInfoSet();
virtual ~nsGenericInterfaceInfoSet();
XPTArena* GetArena()
{
return mArena;
}
// allocate from mArena and guarantee zero-fill
void* AllocateFromArena(PRUint32 size);
const XPTTypeDescriptor* GetAdditionalTypeAt(PRUint16 aIndex)
{
@ -113,7 +112,7 @@ private:
private:
nsVoidArray mInterfaces;
nsVoidArray mAdditionalTypes;
XPTArena* mArena;
PLArenaPool mArena;
};
/***************************************************************************/

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

@ -52,8 +52,8 @@ NS_IMPL_THREADSAFE_ISUPPORTS3(nsGenericInterfaceInfoSet,
nsGenericInterfaceInfoSet::nsGenericInterfaceInfoSet()
{
mArena = XPT_NewArena(ARENA_BLOCK_SIZE, sizeof(double),
"nsGenericInterfaceInfoSet Arena");
PL_InitArenaPool(&mArena, "nsGenericInterfaceInfoSet Arena",
ARENA_BLOCK_SIZE, sizeof(double));
}
nsGenericInterfaceInfoSet::~nsGenericInterfaceInfoSet()
@ -69,8 +69,18 @@ nsGenericInterfaceInfoSet::~nsGenericInterfaceInfoSet()
NS_RELEASE(info);
}
if(mArena)
XPT_DestroyArena(mArena);
PL_FinishArenaPool(&mArena);
}
void*
nsGenericInterfaceInfoSet::AllocateFromArena(PRUint32 size)
{
void *buf = nsnull;
PL_ARENA_ALLOCATE(buf, &mArena, size);
if (buf) {
memset(buf, 0, size);
}
return buf;
}
nsresult
@ -126,7 +136,7 @@ nsGenericInterfaceInfoSet::AllocateParamArray(PRUint16 aCount,
XPTParamDescriptor * *_retval)
{
*_retval = (XPTParamDescriptor*)
XPT_MALLOC(GetArena(), sizeof(XPTParamDescriptor) * aCount);
AllocateFromArena(sizeof(XPTParamDescriptor) * aCount);
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
@ -136,7 +146,7 @@ nsGenericInterfaceInfoSet::AllocateAdditionalType(PRUint16 *aIndex,
XPTTypeDescriptor * *_retval)
{
*_retval = (XPTTypeDescriptor*)
XPT_MALLOC(GetArena(), sizeof(XPTTypeDescriptor));
AllocateFromArena(sizeof(XPTTypeDescriptor));
if(!*_retval || !mAdditionalTypes.AppendElement(*_retval))
return NS_ERROR_OUT_OF_MEMORY;
*aIndex = (PRUint16) mAdditionalTypes.Count()-1;
@ -353,7 +363,8 @@ nsGenericInterfaceInfo::nsGenericInterfaceInfo(nsGenericInterfaceInfoSet* aSet,
}
int len = PL_strlen(aName);
mName = (char*) XPT_MALLOC(mSet->GetArena(), len+1);
mName = (char*) mSet->AllocateFromArena(len + 1);
if(mName)
memcpy(mName, aName, len);
}
@ -366,15 +377,15 @@ NS_IMETHODIMP
nsGenericInterfaceInfo::AppendMethod(XPTMethodDescriptor * aMethod,
PRUint16 *_retval)
{
XPTMethodDescriptor* desc = (XPTMethodDescriptor*)
XPT_MALLOC(mSet->GetArena(), sizeof(XPTMethodDescriptor));
XPTMethodDescriptor *desc = (XPTMethodDescriptor*)
mSet->AllocateFromArena(sizeof(XPTMethodDescriptor));
if(!desc)
return NS_ERROR_OUT_OF_MEMORY;
memcpy(desc, aMethod, sizeof(XPTMethodDescriptor));
int len = PL_strlen(aMethod->name);
desc->name = (char*) XPT_MALLOC(mSet->GetArena(), len+1);
desc->name = (char*) mSet->AllocateFromArena(len + 1);
if(!desc->name)
return NS_ERROR_OUT_OF_MEMORY;
@ -397,14 +408,14 @@ nsGenericInterfaceInfo::AppendConst(XPTConstDescriptor * aConst,
"unsupported const type");
XPTConstDescriptor* desc = (XPTConstDescriptor*)
XPT_MALLOC(mSet->GetArena(), sizeof(XPTConstDescriptor));
mSet->AllocateFromArena(sizeof(XPTConstDescriptor));
if(!desc)
return NS_ERROR_OUT_OF_MEMORY;
memcpy(desc, aConst, sizeof(XPTConstDescriptor));
int len = PL_strlen(aConst->name);
desc->name = (char*) XPT_MALLOC(mSet->GetArena(), len+1);
desc->name = (char*) mSet->AllocateFromArena(len + 1);
if(!desc->name)
return NS_ERROR_OUT_OF_MEMORY;