summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f>2010-07-30 20:02:05 +0000
committervboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f>2010-07-30 20:02:05 +0000
commit4ddbb63e4be3905a7f0e69edd8e0157862be7046 (patch)
tree86a81f980f9e239567be761568ec8586a29196e5
parent5d288a7bee5d5ca48e2edd39c403f7d6e7d327f7 (diff)
downloadVirtualBox-svn-4ddbb63e4be3905a7f0e69edd8e0157862be7046.tar.gz
xpcom: Use RTMem* for memory alloc so that we can more easily wrap direct it to the electric fence heap.
git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@31259 cfe28804-0f27-0410-a406-dd0f0b0b656f
-rw-r--r--src/libs/xpcom18a4/Config.kmk16
-rw-r--r--src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmTransaction.cpp23
-rw-r--r--src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmVector.cpp21
-rw-r--r--src/libs/xpcom18a4/ipc/ipcd/shared/src/ipcMessage.cpp39
-rw-r--r--src/libs/xpcom18a4/ipc/ipcd/util/src/ipcMessageWriter.cpp29
-rw-r--r--src/libs/xpcom18a4/nsprpub/lib/libc/src/strdup.c15
-rw-r--r--src/libs/xpcom18a4/nsprpub/pr/src/io/prlog.c15
-rw-r--r--src/libs/xpcom18a4/nsprpub/pr/src/linking/prlink.c32
-rw-r--r--src/libs/xpcom18a4/nsprpub/pr/src/malloc/prmem.c46
-rw-r--r--src/libs/xpcom18a4/nsprpub/pr/src/misc/prdtoa.c9
-rw-r--r--src/libs/xpcom18a4/xpcom/components/xcDll.cpp57
-rw-r--r--src/libs/xpcom18a4/xpcom/ds/nsRecyclingAllocator.cpp47
-rw-r--r--src/libs/xpcom18a4/xpcom/ds/pldhash.c27
-rw-r--r--src/libs/xpcom18a4/xpcom/proxy/src/nsProxyEvent.cpp222
-rw-r--r--src/libs/xpcom18a4/xpcom/string/src/nsStringObsolete.cpp109
-rw-r--r--src/libs/xpcom18a4/xpcom/string/src/nsSubstring.cpp19
-rw-r--r--src/libs/xpcom18a4/xpcom/threads/nsProcessCommon.cpp28
-rw-r--r--src/libs/xpcom18a4/xpcom/typelib/xpt/src/xpt_arena.c84
18 files changed, 573 insertions, 265 deletions
diff --git a/src/libs/xpcom18a4/Config.kmk b/src/libs/xpcom18a4/Config.kmk
index 5c193e63c44..f9588c9b807 100644
--- a/src/libs/xpcom18a4/Config.kmk
+++ b/src/libs/xpcom18a4/Config.kmk
@@ -58,10 +58,14 @@ TEMPLATE_XPCOM_CFLAGS.freebsd = -pthread
TEMPLATE_XPCOM_CFLAGS.l4 = -nostdinc
TEMPLATE_XPCOM_CFLAGS.linux = -pthread -ansi
TEMPLATE_XPCOM_CFLAGS.solaris = -fno-omit-frame-pointer # for now anyway.
-TEMPLATE_XPCOM_DEFS = MOZILLA_CLIENT=1 NDEBUG=1 _IMPL_NS_COM \
- XPCOM_DLL_BASE=\"$(basename $(notdir $(LIB_XPCOM)))\" \
- MOZ_DLL_SUFFIX=\"$(suffix $(LIB_XPCOM))\" \
- IN_RING3
+TEMPLATE_XPCOM_DEFS = \
+ MOZILLA_CLIENT=1 \
+ NDEBUG=1 \
+ _IMPL_NS_COM \
+ XPCOM_DLL_BASE=\"$(basename $(notdir $(LIB_XPCOM)))\" \
+ MOZ_DLL_SUFFIX=\"$(suffix $(LIB_XPCOM))\" \
+ IN_RING3 \
+ VBOX_USE_IPRT_IN_XPCOM
ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
TEMPLATE_XPCOM_DEFS += VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
endif
@@ -190,7 +194,9 @@ TEMPLATE_XPCOMTSTEXE_CFLAGS = $(TEMPLATE_XPCOMEXE_CFLAGS) -Wno-format
TEMPLATE_XPCOMBLDPROG = XPCOM Build programs executables
TEMPLATE_XPCOMBLDPROG_EXTENDS = VBOXBLDPROG
## @todo Verify that this doesn't blow up because of template inheriance ordering. (we're assuming XPCOMEXE is expanded when this is being used.)
-TEMPLATE_XPCOMBLDPROG_DEFS = $(TEMPLATE_VBOXBLDPROG_DEFS) $(TEMPLATE_XPCOMEXE_DEFS)
+TEMPLATE_XPCOMBLDPROG_DEFS = \
+ $(TEMPLATE_VBOXBLDPROG_DEFS) \
+ $(filter-out VBOX_USE_IPRT_IN_XPCOM, $(TEMPLATE_XPCOMEXE_DEFS))
TEMPLATE_XPCOMBLDPROG_DEFS.$(KBUILD_HOST) = $(TEMPLATE_VBOXBLDPROG_DEFS.$(KBUILD_HOST)) $(TEMPLATE_XPCOMEXE_DEFS.$(KBUILD_HOST))
TEMPLATE_XPCOMBLDPROG_DEFS.x86 = $(TEMPLATE_VBOXBLDPROG_DEFS.x86) $(TEMPLATE_XPCOMEXE_DEFS.x86)
TEMPLATE_XPCOMBLDPROG_DEFS.amd64 = $(TEMPLATE_VBOXBLDPROG_DEFS.amd64) $(TEMPLATE_XPCOMEXE_DEFS.amd64)
diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmTransaction.cpp b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmTransaction.cpp
index 62775d980d9..5fb7e5bfcc1 100644
--- a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmTransaction.cpp
+++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmTransaction.cpp
@@ -37,30 +37,41 @@
#include <stdlib.h>
#include "tmTransaction.h"
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+# include <iprt/mem.h>
+#endif
///////////////////////////////////////////////////////////////////////////////
// Constructor(s) & Destructor
tmTransaction::~tmTransaction() {
if (mHeader)
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(mHeader);
+#else
free(mHeader);
+#endif
}
// call only once per lifetime of object. does not reclaim the
// raw message, only sets it.
nsresult
tmTransaction::Init(PRUint32 aOwnerID,
- PRInt32 aQueueID,
- PRUint32 aAction,
- PRInt32 aStatus,
- const PRUint8 *aMessage,
+ PRInt32 aQueueID,
+ PRUint32 aAction,
+ PRInt32 aStatus,
+ const PRUint8 *aMessage,
PRUint32 aLength) {
nsresult rv = NS_OK;
tmHeader *header = nsnull;
// indicates the message is the entire raw message
if (aQueueID == TM_INVALID_ID) {
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ header = (tmHeader*) RTMemAlloc(aLength);
+#else
header = (tmHeader*) malloc(aLength);
+#endif
if (header) {
mRawMessageLength = aLength;
memcpy(header, aMessage, aLength);
@@ -69,7 +80,11 @@ tmTransaction::Init(PRUint32 aOwnerID,
rv = NS_ERROR_OUT_OF_MEMORY;
}
else { // need to create the tmHeader and concat the message
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ header = (tmHeader*) RTMemAlloc (sizeof(tmHeader) + aLength);
+#else
header = (tmHeader*) malloc (sizeof(tmHeader) + aLength);
+#endif
if (header) {
mRawMessageLength = sizeof(tmHeader) + aLength;
header->action = aAction;
diff --git a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmVector.cpp b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmVector.cpp
index d63c507a55c..99213f2714e 100644
--- a/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmVector.cpp
+++ b/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/common/tmVector.cpp
@@ -37,6 +37,9 @@
#include <stdlib.h>
#include "tmVector.h"
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+# include <iprt/mem.h>
+#endif
////////////////////////////////////////////////////////////////////////////
// Constructor(s) & Destructor
@@ -45,7 +48,11 @@
// the collection - how would we reclaim, don't know how they were allocated
tmVector::~tmVector() {
if (mElements)
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree((void*)mElements);
+#else
free((void*)mElements);
+#endif
}
///////////////////////////////////////////////////////////////////////////////
@@ -54,7 +61,11 @@ tmVector::~tmVector() {
nsresult
tmVector::Init() {
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ mElements = (void**) RTMemAllocZ (mCapacity * sizeof(void*));
+#else
mElements = (void**) calloc (mCapacity, sizeof(void*));
+#endif
if (!mElements)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
@@ -116,7 +127,7 @@ tmVector::RemoveAt(PRUint32 aIndex) {
//void*
//tmVector::operator[](int index) {
// if (index < mNext && index >= 0)
-// return mElements[index];
+// return mElements[index];
// return nsnull;
//}
@@ -136,7 +147,11 @@ nsresult
tmVector::Grow() {
PRUint32 newcap = mCapacity + GROWTH_INC;
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ mElements = (void**) RTMemRealloc(mElements, (newcap * sizeof(void*)));
+#else
mElements = (void**) realloc(mElements, (newcap * sizeof(void*)));
+#endif
if (mElements) {
mCapacity = newcap;
return NS_OK;
@@ -151,7 +166,11 @@ tmVector::Shrink() {
PRUint32 newcap = mCapacity - GROWTH_INC;
if (mNext < newcap) {
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ mElements = (void**) RTMemRealloc(mElements, newcap * sizeof(void*));
+#else
mElements = (void**) realloc(mElements, newcap * sizeof(void*));
+#endif
if (!mElements)
return NS_ERROR_OUT_OF_MEMORY;
mCapacity = newcap;
diff --git a/src/libs/xpcom18a4/ipc/ipcd/shared/src/ipcMessage.cpp b/src/libs/xpcom18a4/ipc/ipcd/shared/src/ipcMessage.cpp
index e4e097baac9..bfdc7efec25 100644
--- a/src/libs/xpcom18a4/ipc/ipcd/shared/src/ipcMessage.cpp
+++ b/src/libs/xpcom18a4/ipc/ipcd/shared/src/ipcMessage.cpp
@@ -39,18 +39,29 @@
#include <string.h>
#include "prlog.h"
#include "ipcMessage.h"
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+# include <iprt/mem.h>
+#endif
ipcMessage::~ipcMessage()
{
if (mMsgHdr)
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(mMsgHdr);
+#else
free(mMsgHdr);
+#endif
}
void
ipcMessage::Reset()
{
if (mMsgHdr) {
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(mMsgHdr);
+#else
free(mMsgHdr);
+#endif
mMsgHdr = NULL;
}
@@ -67,8 +78,12 @@ ipcMessage::Clone() const
// copy buf if non-null
if (mMsgHdr) {
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ clone->mMsgHdr = (ipcMessageHeader *) RTMemDup(mMsgHdr, mMsgHdr->mLen);
+#else
clone->mMsgHdr = (ipcMessageHeader *) malloc(mMsgHdr->mLen);
memcpy(clone->mMsgHdr, mMsgHdr, mMsgHdr->mLen);
+#endif
}
else
clone->mMsgHdr = NULL;
@@ -83,12 +98,20 @@ PRStatus
ipcMessage::Init(const nsID &target, const char *data, PRUint32 dataLen)
{
if (mMsgHdr)
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(mMsgHdr);
+#else
free(mMsgHdr);
+#endif
mMsgComplete = PR_FALSE;
// allocate message data
PRUint32 msgLen = IPC_MSG_HEADER_SIZE + dataLen;
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ mMsgHdr = (ipcMessageHeader *) RTMemAlloc(msgLen);
+#else
mMsgHdr = (ipcMessageHeader *) malloc(msgLen);
+#endif
if (!mMsgHdr) {
mMsgHdr = NULL;
return PR_FAILURE;
@@ -122,7 +145,7 @@ ipcMessage::SetData(PRUint32 offset, const char *data, PRUint32 dataLen)
PRBool
ipcMessage::Equals(const nsID &target, const char *data, PRUint32 dataLen) const
{
- return mMsgComplete &&
+ return mMsgComplete &&
mMsgHdr->mTarget.Equals(target) &&
DataLen() == dataLen &&
memcmp(Data(), data, dataLen) == 0;
@@ -198,10 +221,14 @@ ipcMessage::ReadFrom(const char *buf,
buf += count;
bufLen -= count;
*bytesRead = count;
-
+
if (MsgLen() > IPC_MSG_GUESSED_SIZE) {
// realloc message buffer to the correct size
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ mMsgHdr = (ipcMessageHeader *) RTMemRealloc(mMsgHdr, MsgLen());
+#else
mMsgHdr = (ipcMessageHeader *) realloc(mMsgHdr, MsgLen());
+#endif
}
}
}
@@ -211,7 +238,11 @@ ipcMessage::ReadFrom(const char *buf,
// not enough data available in buffer to determine allocation size
// allocate a partial buffer
PRUint32 msgLen = IPC_MSG_GUESSED_SIZE;
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ mMsgHdr = (ipcMessageHeader *) RTMemAlloc(msgLen);
+#else
mMsgHdr = (ipcMessageHeader *) malloc(msgLen);
+#endif
if (!mMsgHdr)
return PR_FAILURE;
memcpy(mMsgHdr, buf, bufLen);
@@ -222,7 +253,11 @@ ipcMessage::ReadFrom(const char *buf,
}
else {
PRUint32 msgLen = *(PRUint32 *) buf;
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ mMsgHdr = (ipcMessageHeader *) RTMemAlloc(msgLen);
+#else
mMsgHdr = (ipcMessageHeader *) malloc(msgLen);
+#endif
if (!mMsgHdr)
return PR_FAILURE;
mMsgHdr->mLen = msgLen;
diff --git a/src/libs/xpcom18a4/ipc/ipcd/util/src/ipcMessageWriter.cpp b/src/libs/xpcom18a4/ipc/ipcd/util/src/ipcMessageWriter.cpp
index 9280628d314..4af0dcba23d 100644
--- a/src/libs/xpcom18a4/ipc/ipcd/util/src/ipcMessageWriter.cpp
+++ b/src/libs/xpcom18a4/ipc/ipcd/util/src/ipcMessageWriter.cpp
@@ -39,27 +39,34 @@
#include "ipcMessageWriter.h"
#include "prmem.h"
#include <string.h>
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+# include <iprt/mem.h>
+#endif
//*****************************************************************************
// ipcMessageWriter
-//*****************************************************************************
+//*****************************************************************************
ipcMessageWriter::~ipcMessageWriter()
{
if (mBuf)
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(mBuf);
+#else
free(mBuf);
+#endif
}
-
+
void ipcMessageWriter::PutInt8(PRUint8 val)
{
- if (EnsureCapacity(sizeof(PRUint8)))
+ if (EnsureCapacity(sizeof(PRUint8)))
*mBufPtr++ = val;
}
// PutInt16 and PutInt32 go to pains to avoid unaligned memory accesses that
// are larger than a byte. On some platforms, that causes a performance penalty.
// On other platforms, Tru64 for instance, it's an error.
-
+
void ipcMessageWriter::PutInt16(PRUint16 val)
{
if (EnsureCapacity(sizeof(PRUint16))) {
@@ -69,7 +76,7 @@ void ipcMessageWriter::PutInt16(PRUint16 val)
*mBufPtr++ = temp[1];
}
}
-
+
void ipcMessageWriter::PutInt32(PRUint32 val)
{
if (EnsureCapacity(sizeof(PRUint32))) {
@@ -78,10 +85,10 @@ void ipcMessageWriter::PutInt32(PRUint32 val)
*mBufPtr++ = temp[0];
*mBufPtr++ = temp[1];
*mBufPtr++ = temp[2];
- *mBufPtr++ = temp[3];
+ *mBufPtr++ = temp[3];
}
}
-
+
PRUint32 ipcMessageWriter::PutBytes(const void* src, PRUint32 n)
{
if (EnsureCapacity(n)) {
@@ -91,7 +98,7 @@ PRUint32 ipcMessageWriter::PutBytes(const void* src, PRUint32 n)
}
return 0;
}
-
+
PRBool ipcMessageWriter::GrowCapacity(PRInt32 sizeNeeded)
{
if (sizeNeeded < 0)
@@ -106,9 +113,13 @@ PRBool ipcMessageWriter::GrowCapacity(PRInt32 sizeNeeded)
if (newCapacity > mCapacity) // if we broke out because of rollover
return PR_FALSE;
}
-
+
PRInt32 curPos = mBufPtr - mBuf;
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ mBuf = (PRUint8*)RTMemRealloc(mBuf, mCapacity);
+#else
mBuf = (PRUint8*)realloc(mBuf, mCapacity);
+#endif
if (!mBuf) {
mError = PR_TRUE;
return PR_FALSE;
diff --git a/src/libs/xpcom18a4/nsprpub/lib/libc/src/strdup.c b/src/libs/xpcom18a4/nsprpub/lib/libc/src/strdup.c
index 27a553c6629..f5fe61ad021 100644
--- a/src/libs/xpcom18a4/nsprpub/lib/libc/src/strdup.c
+++ b/src/libs/xpcom18a4/nsprpub/lib/libc/src/strdup.c
@@ -38,6 +38,9 @@
#include "plstr.h"
#include "prmem.h"
#include <string.h>
+#ifdef VBOX_USE_IPRT_IN_NSPR
+#include <iprt/mem.h>
+#endif
PR_IMPLEMENT(char *)
PL_strdup(const char *s)
@@ -50,7 +53,11 @@ PL_strdup(const char *s)
n = strlen(s) + 1;
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ rv = (char *)RTMemAlloc(n);
+#else
rv = (char *)malloc(n);
+#endif
if( (char *)0 == rv ) return rv;
(void)memcpy(rv, s, n);
@@ -61,7 +68,11 @@ PL_strdup(const char *s)
PR_IMPLEMENT(void)
PL_strfree(char *s)
{
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ RTMemFree(s);
+#else
free(s);
+#endif
}
PR_IMPLEMENT(char *)
@@ -75,7 +86,11 @@ PL_strndup(const char *s, PRUint32 max)
l = PL_strnlen(s, max);
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ rv = (char *)RTMemAlloc(l+1);
+#else
rv = (char *)malloc(l+1);
+#endif
if( (char *)0 == rv ) return rv;
(void)memcpy(rv, s, l);
diff --git a/src/libs/xpcom18a4/nsprpub/pr/src/io/prlog.c b/src/libs/xpcom18a4/nsprpub/pr/src/io/prlog.c
index bb734e06764..1432b06ebc2 100644
--- a/src/libs/xpcom18a4/nsprpub/pr/src/io/prlog.c
+++ b/src/libs/xpcom18a4/nsprpub/pr/src/io/prlog.c
@@ -50,8 +50,11 @@
*/
#if defined(VBOX) && defined(DEBUG)
-#include <iprt/initterm.h> /* for RTR3Init */
-#include <iprt/log.h>
+# include <iprt/initterm.h> /* for RTR3Init */
+# include <iprt/log.h>
+#endif
+#ifdef VBOX_USE_IPRT_IN_NSPR
+# include <iprt/string.h>
#endif
#include "primpl.h"
@@ -336,7 +339,11 @@ void _PR_LogCleanup(void)
while (lm != NULL) {
PRLogModuleInfo *next = lm->next;
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ RTStrFree((/*const*/ char *)lm->name);
+#else
free((/*const*/ char *)lm->name);
+#endif
PR_Free(lm);
lm = next;
}
@@ -394,7 +401,11 @@ PR_IMPLEMENT(PRLogModuleInfo*) PR_NewLogModule(const char *name)
lm = PR_NEWZAP(PRLogModuleInfo);
if (lm) {
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ lm->name = RTStrDup(name);
+#else
lm->name = strdup(name);
+#endif
lm->level = PR_LOG_NONE;
lm->next = logModules;
logModules = lm;
diff --git a/src/libs/xpcom18a4/nsprpub/pr/src/linking/prlink.c b/src/libs/xpcom18a4/nsprpub/pr/src/linking/prlink.c
index 8ab80e8b31a..faad8af2fac 100644
--- a/src/libs/xpcom18a4/nsprpub/pr/src/linking/prlink.c
+++ b/src/libs/xpcom18a4/nsprpub/pr/src/linking/prlink.c
@@ -112,6 +112,12 @@
#endif /* XP_UNIX */
#endif /* !VBOX_USE_MORE_IPRT_IN_NSPR */
+#ifdef VBOX_USE_IPRT_IN_NSPR
+# include <iprt/mem.h>
+# include <iprt/string.h>
+# undef strdup
+# define strdup(str) RTStrDup(str)
+#endif
#define _PR_DEFAULT_LD_FLAGS PR_LD_LAZY
@@ -417,7 +423,11 @@ void _PR_ShutdownLinker(void)
pr_linker_lock = NULL;
if (_pr_currentLibPath) {
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ RTStrFree(_pr_currentLibPath);
+#else
free(_pr_currentLibPath);
+#endif
_pr_currentLibPath = NULL;
}
@@ -436,7 +446,11 @@ PR_IMPLEMENT(PRStatus) PR_SetLibraryPath(const char *path)
if (!_pr_initialized) _PR_ImplicitInitialization();
PR_EnterMonitor(pr_linker_lock);
if (_pr_currentLibPath) {
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ RTStrFree(_pr_currentLibPath);
+#else
free(_pr_currentLibPath);
+#endif
}
if (path) {
_pr_currentLibPath = strdup(path);
@@ -487,7 +501,11 @@ PR_GetLibraryPath(void)
ev = "";
len = strlen(ev) + 1; /* +1 for the null */
+# ifdef VBOX_USE_IPRT_IN_NSPR
+ p = (char*) RTStrAlloc(len);
+# else
p = (char*) malloc(len);
+# endif
if (p) {
strcpy(p, ev);
}
@@ -518,7 +536,11 @@ PR_GetLibraryPath(void)
#endif
len = strlen(ev) + 1; /* +1 for the null */
+# ifdef VBOX_USE_IPRT_IN_NSPR
+ p = (char*) RTStrAlloc(len);
+# else
p = (char*) malloc(len);
+# endif
if (p) {
strcpy(p, ev);
} /* if (p) */
@@ -529,7 +551,7 @@ PR_GetLibraryPath(void)
#else
/* AFAIK there isn't a library path with the HP SHL interface --Rob */
ev = strdup("");
-#endif
+# endif
#endif
/*
@@ -539,7 +561,11 @@ PR_GetLibraryPath(void)
exit:
if (_pr_currentLibPath) {
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ copy = RTMemDup(_pr_currentLibPath, strlen(_pr_currentLibPath) + 1);
+#else
copy = strdup(_pr_currentLibPath);
+#endif
}
PR_ExitMonitor(pr_linker_lock);
if (!copy) {
@@ -1474,7 +1500,11 @@ PR_UnloadLibrary(PRLibrary *lib)
freeLib:
PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Unloaded library %s", lib->name));
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ RTStrFree(lib->name);
+#else
free(lib->name);
+#endif
lib->name = NULL;
PR_DELETE(lib);
if (result != 0) {
diff --git a/src/libs/xpcom18a4/nsprpub/pr/src/malloc/prmem.c b/src/libs/xpcom18a4/nsprpub/pr/src/malloc/prmem.c
index 76541535f3b..0859628cb9a 100644
--- a/src/libs/xpcom18a4/nsprpub/pr/src/malloc/prmem.c
+++ b/src/libs/xpcom18a4/nsprpub/pr/src/malloc/prmem.c
@@ -40,7 +40,7 @@
*/
#include "primpl.h"
-#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
+#ifdef VBOX_USE_IPRT_IN_NSPR
# include <iprt/mem.h>
#endif
@@ -107,7 +107,11 @@ _PR_DestroyZones(void)
while (mz->head) {
MemBlockHdr *hdr = mz->head;
mz->head = hdr->s.next; /* unlink it */
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ RTMemFree(hdr);
+#else
free(hdr);
+#endif
mz->elements--;
}
}
@@ -280,7 +284,11 @@ pr_ZoneMalloc(PRUint32 size)
mz->locked = 0;
pthread_mutex_unlock(&mz->lock);
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ mb = (MemBlockHdr *)RTMemAlloc(blockSize + 2 * (sizeof *mb));
+#else
mb = (MemBlockHdr *)malloc(blockSize + 2 * (sizeof *mb));
+#endif
if (!mb) {
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
return NULL;
@@ -300,7 +308,11 @@ pr_ZoneMalloc(PRUint32 size)
/* size was too big. Create a block with no zone */
blockSize = (size & 15) ? size + 16 - (size & 15) : size;
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ mb = (MemBlockHdr *)RTMemAlloc(blockSize + 2 * (sizeof *mb));
+#else
mb = (MemBlockHdr *)malloc(blockSize + 2 * (sizeof *mb));
+#endif
if (!mb) {
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
return NULL;
@@ -350,7 +362,11 @@ pr_ZoneRealloc(void *oldptr, PRUint32 bytes)
oldptr);
#endif
/* We don't know how big it is. But we can fix that. */
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ oldptr = RTMemRealloc(oldptr, bytes);
+#else
oldptr = realloc(oldptr, bytes);
+#endif
if (!oldptr) {
if (bytes) {
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
@@ -383,7 +399,11 @@ pr_ZoneRealloc(void *oldptr, PRUint32 bytes)
if (ours)
pr_ZoneFree(oldptr);
else if (oldptr)
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ RTMemFree(oldptr);
+#else
free(oldptr);
+#endif
}
return rv;
}
@@ -407,7 +427,11 @@ pr_ZoneFree(void *ptr)
fprintf(stderr,
"Warning: freeing memory block %p from ordinary malloc\n", ptr);
#endif
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ RTMemFree(ptr);
+#else
free(ptr);
+#endif
return;
}
@@ -420,7 +444,11 @@ pr_ZoneFree(void *ptr)
if (!mz) {
PR_ASSERT(blockSize > 65536);
/* This block was not in any zone. Just free it. */
+#ifdef VBOX_USE_IPRT_IN_NSPR
+ RTMemFree(mb);
+#else
free(mb);
+#endif
return;
}
PR_ASSERT(mz->blockSize == blockSize);
@@ -440,7 +468,7 @@ PR_IMPLEMENT(void *) PR_Malloc(PRUint32 size)
{
if (!_pr_initialized) _PR_ImplicitInitialization();
-#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
+#ifdef VBOX_USE_IPRT_IN_NSPR
return use_zone_allocator ? pr_ZoneMalloc(size) : RTMemAlloc(size);
#else
return use_zone_allocator ? pr_ZoneMalloc(size) : malloc(size);
@@ -452,7 +480,7 @@ PR_IMPLEMENT(void *) PR_Calloc(PRUint32 nelem, PRUint32 elsize)
if (!_pr_initialized) _PR_ImplicitInitialization();
return use_zone_allocator ?
-#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
+#ifdef VBOX_USE_IPRT_IN_NSPR
pr_ZoneCalloc(nelem, elsize) : RTMemAllocZ(nelem * (size_t)elsize);
#else
pr_ZoneCalloc(nelem, elsize) : calloc(nelem, elsize);
@@ -463,7 +491,7 @@ PR_IMPLEMENT(void *) PR_Realloc(void *ptr, PRUint32 size)
{
if (!_pr_initialized) _PR_ImplicitInitialization();
-#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
+#ifdef VBOX_USE_IPRT_IN_NSPR
return use_zone_allocator ? pr_ZoneRealloc(ptr, size) : RTMemRealloc(ptr, size);
#else
return use_zone_allocator ? pr_ZoneRealloc(ptr, size) : realloc(ptr, size);
@@ -475,7 +503,7 @@ PR_IMPLEMENT(void) PR_Free(void *ptr)
if (use_zone_allocator)
pr_ZoneFree(ptr);
else
-#ifdef VBOX_USE_MORE_IPRT_IN_NSPR
+#ifdef VBOX_USE_IPRT_IN_NSPR
RTMemFree(ptr);
#else
free(ptr);
@@ -497,7 +525,7 @@ PR_IMPLEMENT(void *) PR_Malloc(PRUint32 size)
#if defined (WIN16)
return PR_MD_malloc( (size_t) size);
#else
-# ifdef VBOX_USE_MORE_IPRT_IN_NSPR
+# ifdef VBOX_USE_IPRT_IN_NSPR
return RTMemAlloc(size);
# else
return malloc(size);
@@ -511,7 +539,7 @@ PR_IMPLEMENT(void *) PR_Calloc(PRUint32 nelem, PRUint32 elsize)
return PR_MD_calloc( (size_t)nelem, (size_t)elsize );
#else
-# ifdef VBOX_USE_MORE_IPRT_IN_NSPR
+# ifdef VBOX_USE_IPRT_IN_NSPR
return RTMemAllocZ(nelem * (size_t)elsize);
# else
return calloc(nelem, elsize);
@@ -524,7 +552,7 @@ PR_IMPLEMENT(void *) PR_Realloc(void *ptr, PRUint32 size)
#if defined (WIN16)
return PR_MD_realloc( ptr, (size_t) size);
#else
-# ifdef VBOX_USE_MORE_IPRT_IN_NSPR
+# ifdef VBOX_USE_IPRT_IN_NSPR
return RTMemRealloc(ptr, size);
# else
return realloc(ptr, size);
@@ -537,7 +565,7 @@ PR_IMPLEMENT(void) PR_Free(void *ptr)
#if defined (WIN16)
PR_MD_free( ptr );
#else
-# ifdef VBOX_USE_MORE_IPRT_IN_NSPR
+# ifdef VBOX_USE_IPRT_IN_NSPR
RTMemFree(ptr);
# else
free(ptr);
diff --git a/src/libs/xpcom18a4/nsprpub/pr/src/misc/prdtoa.c b/src/libs/xpcom18a4/nsprpub/pr/src/misc/prdtoa.c
index 3f06feaf104..13e0385336e 100644
--- a/src/libs/xpcom18a4/nsprpub/pr/src/misc/prdtoa.c
+++ b/src/libs/xpcom18a4/nsprpub/pr/src/misc/prdtoa.c
@@ -266,7 +266,12 @@ extern char *MALLOC();
extern void *MALLOC(size_t);
#endif
#else
+# ifdef VBOX_USE_IPRT_IN_NSPR
+# include <iprt/mem.h>
+# define MALLOC RTMemAlloc
+# else
#define MALLOC malloc
+# endif
#endif
#ifndef Omit_Private_Memory
@@ -3418,7 +3423,7 @@ PR_dtoa(PRFloat64 d, PRIntn mode, PRIntn ndigits,
rv = PR_SUCCESS;
}
freedtoa(result);
- return rv;
+ return rv;
}
/*
@@ -3426,7 +3431,7 @@ PR_dtoa(PRFloat64 d, PRIntn mode, PRIntn ndigits,
** prcsn - number of digits of precision to generate floating
** point value.
** This should be reparameterized so that you can send in a
-** prcn for the positive and negative ranges. For now,
+** prcn for the positive and negative ranges. For now,
** conform to the ECMA JavaScript spec which says numbers
** less than 1e-6 are in scientific notation.
** Also, the ECMA spec says that there should always be a
diff --git a/src/libs/xpcom18a4/xpcom/components/xcDll.cpp b/src/libs/xpcom18a4/xpcom/components/xcDll.cpp
index 489cb8e1dc2..494cf174e60 100644
--- a/src/libs/xpcom18a4/xpcom/components/xcDll.cpp
+++ b/src/libs/xpcom18a4/xpcom/components/xcDll.cpp
@@ -73,10 +73,13 @@
#endif
#include "nsNativeComponentLoader.h"
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+# include "nsMemory.h"
+#endif
nsDll::nsDll(nsIFile *dllSpec, nsNativeComponentLoader *loader)
: m_dllSpec(do_QueryInterface(dllSpec)),
- m_instance(NULL),
+ m_instance(NULL),
m_moduleObject(NULL),
m_loader(loader),
m_markForUnload(PR_FALSE)
@@ -101,7 +104,7 @@ void
nsDll::GetDisplayPath(nsACString& aLeafName)
{
m_dllSpec->GetNativeLeafName(aLeafName);
-
+
if (aLeafName.IsEmpty())
aLeafName.AssignLiteral("unknown!");
}
@@ -119,7 +122,7 @@ nsDll::HasChanged()
if (NS_FAILED(rv))
return PR_TRUE;
PRBool changed = PR_TRUE;
- manager->HasFileChanged(m_dllSpec, nsnull, currentDate, &changed);
+ manager->HasFileChanged(m_dllSpec, nsnull, currentDate, &changed);
return changed;
}
@@ -136,15 +139,15 @@ PRBool nsDll::Load(void)
#ifdef NS_BUILD_REFCNT_LOGGING
nsTraceRefcntImpl::SetActivityIsLegal(PR_FALSE);
#endif
-
+
// Load any library dependencies
// The Component Loader Manager may hold onto some extra data
- // set by either the native component loader or the native
+ // set by either the native component loader or the native
// component. We assume that this data is a space delimited
// listing of dependent libraries which are required to be
// loaded prior to us loading the given component. Once, the
- // component is loaded into memory, we can release our hold
- // on the dependent libraries with the assumption that the
+ // component is loaded into memory, we can release our hold
+ // on the dependent libraries with the assumption that the
// component library holds a reference via the OS so loader.
#if defined(XP_UNIX)
@@ -154,22 +157,22 @@ PRBool nsDll::Load(void)
nsXPIDLCString extraData;
manager->GetOptionalData(m_dllSpec, nsnull, getter_Copies(extraData));
-
+
#ifdef UNLOAD_DEPENDENT_LIBS
nsVoidArray dependentLibArray;
#endif
// if there was any extra data, treat it as a listing of dependent libs
- if (extraData != nsnull)
+ if (extraData != nsnull)
{
// all dependent libraries are suppose to be in the "gre" directory.
- // note that the gre directory is the same as the "bin" directory,
+ // note that the gre directory is the same as the "bin" directory,
// when there isn't a real "gre" found.
nsXPIDLCString path;
nsCOMPtr<nsIFile> file;
NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(file));
-
+
if (!file)
return NS_ERROR_FAILURE;
@@ -177,7 +180,11 @@ PRBool nsDll::Load(void)
// stupid right now, so that later we can just set the leaf name.
file->AppendNative(NS_LITERAL_CSTRING("dummy"));
- char *buffer = strdup(extraData);
+# ifdef VBOX_USE_IPRT_IN_XPCOM
+ char *buffer = (char *)nsMemory::Clone(extraData, strlen(extraData) + 1);
+# else
+ char *buffer = strdup(extraData);
+# endif
if (!buffer)
return NS_ERROR_OUT_OF_MEMORY;
@@ -199,15 +206,15 @@ PRBool nsDll::Load(void)
if (!path)
return NS_ERROR_FAILURE;
- // Load this dependent library with the global flag and stash
+ // Load this dependent library with the global flag and stash
// the result for later so that we can unload it.
PRLibSpec libSpec;
libSpec.type = PR_LibSpec_Pathname;
- // if the depend library path starts with a / we are
+ // if the depend library path starts with a / we are
// going to assume that it is a full path and should
- // be loaded without prepending the gre diretory
- // location. We could have short circuited the
+ // be loaded without prepending the gre diretory
+ // location. We could have short circuited the
// SetNativeLeafName above, but this is clearer and
// the common case is a relative path.
@@ -215,31 +222,35 @@ PRBool nsDll::Load(void)
libSpec.value.pathname = token;
else
libSpec.value.pathname = path;
-
+
PRLibrary* lib = PR_LoadLibraryWithFlags(libSpec, PR_LD_LAZY|PR_LD_GLOBAL);
// if we couldn't load the dependent library. We did the best we
// can. Now just let us fail later if this really was a required
// dependency.
#ifdef UNLOAD_DEPENDENT_LIBS
- if (lib)
+ if (lib)
dependentLibArray.AppendElement((void*)lib);
#endif
-
+
token = nsCRT::strtok(newStr, " ", &newStr);
}
+# ifdef VBOX_USE_IPRT_IN_XPCOM
+ nsMemory::Free(buffer);
+# else
free(buffer);
+# endif
}
#endif
// load the component
nsCOMPtr<nsILocalFile> lf(do_QueryInterface(m_dllSpec));
- NS_ASSERTION(lf, "nsIFile here must implement a nsILocalFile");
+ NS_ASSERTION(lf, "nsIFile here must implement a nsILocalFile");
lf->Load(&m_instance);
#if defined(XP_UNIX)
- // Unload any of library dependencies we loaded earlier. The assumption
+ // Unload any of library dependencies we loaded earlier. The assumption
// here is that the component will have a "internal" reference count to
- // the dependency library we just loaded.
+ // the dependency library we just loaded.
// XXX should we unload later - or even at all?
#ifdef UNLOAD_DEPENDENT_LIBS
@@ -305,7 +316,7 @@ void * nsDll::FindSymbol(const char *symbol)
{
if (symbol == NULL)
return (NULL);
-
+
// If not already loaded, load it now.
if (Load() != PR_TRUE)
return (NULL);
diff --git a/src/libs/xpcom18a4/xpcom/ds/nsRecyclingAllocator.cpp b/src/libs/xpcom18a4/xpcom/ds/nsRecyclingAllocator.cpp
index 719f51f9acd..241f795c4b0 100644
--- a/src/libs/xpcom18a4/xpcom/ds/nsRecyclingAllocator.cpp
+++ b/src/libs/xpcom18a4/xpcom/ds/nsRecyclingAllocator.cpp
@@ -48,6 +48,9 @@
#include "nsAutoLock.h"
#include "prprf.h"
#include "nsITimer.h"
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+# include <iprt/mem.h>
+#endif
#define NS_SEC_TO_MS(s) ((s) * 1000)
@@ -102,11 +105,15 @@ nsRecyclingAllocator::Init(PRUint32 nbucket, PRUint32 recycleAfter, const char *
// Free all memory held, if any
while(mFreeList)
{
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(mFreeList->block);
+#else
free(mFreeList->block);
+#endif
mFreeList = mFreeList->next;
}
mFreeList = nsnull;
-
+
if (mBlocks)
delete [] mBlocks;
@@ -142,11 +149,15 @@ nsRecyclingAllocator::~nsRecyclingAllocator()
// Free all memory held, if any
while(mFreeList)
{
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(mFreeList->block);
+#else
free(mFreeList->block);
+#endif
mFreeList = mFreeList->next;
}
mFreeList = nsnull;
-
+
if (mBlocks)
delete [] mBlocks;
@@ -164,7 +175,7 @@ nsRecyclingAllocator::Malloc(PRSize bytes, PRBool zeroit)
// Mark that we are using. This will prevent any
// timer based release of unused memory.
Touch();
-
+
Block* freeBlock = FindFreeBlock(bytes);
if (freeBlock)
{
@@ -174,18 +185,22 @@ nsRecyclingAllocator::Malloc(PRSize bytes, PRBool zeroit)
memset(data, 0, bytes);
return data;
}
-
+
// We need to do an allocation
// Add 4 bytes to what we allocate to hold the bucket index
PRSize allocBytes = bytes + NS_ALLOCATOR_OVERHEAD_BYTES;
-
+
// We dont have that memory already. Allocate.
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ Block *ptr = (Block *) (zeroit ? RTMemAllocZ(allocBytes) : RTMemAlloc(allocBytes));
+#else
Block *ptr = (Block *) (zeroit ? calloc(1, allocBytes) : malloc(allocBytes));
-
+#endif
+
// Deal with no memory situation
if (!ptr)
return ptr;
-
+
// This is the first allocation we are holding.
// Setup timer for releasing memory
// If this fails, then we wont have a timer to release unused
@@ -193,20 +208,20 @@ nsRecyclingAllocator::Malloc(PRSize bytes, PRBool zeroit)
// will try again to set the timer.
if (mRecycleAfter && !mRecycleTimer)
{
- // known only to stuff in xpcom.
+ // known only to stuff in xpcom.
extern nsresult NS_NewTimer(nsITimer* *aResult, nsTimerCallbackFunc aCallback, void *aClosure,
PRUint32 aDelay, PRUint32 aType);
- (void) NS_NewTimer(&mRecycleTimer, nsRecycleTimerCallback, this,
+ (void) NS_NewTimer(&mRecycleTimer, nsRecycleTimerCallback, this,
NS_SEC_TO_MS(mRecycleAfter),
nsITimer::TYPE_REPEATING_SLACK);
NS_ASSERTION(mRecycleTimer, "nsRecyclingAllocator: Creating timer failed.\n");
}
-
+
#ifdef DEBUG
mNAllocated++;
#endif
-
+
// Store size and return data portion
ptr->bytes = bytes;
return DATA(ptr);
@@ -234,7 +249,11 @@ nsRecyclingAllocator::Free(void *ptr)
NS_WARNING(buf);
mNAllocated--;
#endif
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(block);
+#else
free(block);
+#endif
}
}
@@ -256,7 +275,11 @@ nsRecyclingAllocator::FreeUnusedBuckets()
while (node)
{
// Free the allocated block
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(node->block);
+#else
free(node->block);
+#endif
#ifdef DEBUG_dp
printf("%d ", node->bytes);
@@ -274,7 +297,7 @@ nsRecyclingAllocator::FreeUnusedBuckets()
mBlocks[mMaxBlocks-1].next = nsnull;
mFreeList = nsnull;
-#ifdef DEBUG
+#ifdef DEBUG
mNAllocated = 0;
#endif
#ifdef DEBUG_dp
diff --git a/src/libs/xpcom18a4/xpcom/ds/pldhash.c b/src/libs/xpcom18a4/xpcom/ds/pldhash.c
index 3ee511e5f3f..9e02268d622 100644
--- a/src/libs/xpcom18a4/xpcom/ds/pldhash.c
+++ b/src/libs/xpcom18a4/xpcom/ds/pldhash.c
@@ -56,17 +56,28 @@
#else
# define METER(x) /* nothing */
#endif
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+# include <iprt/mem.h>
+#endif
PR_IMPLEMENT(void *)
PL_DHashAllocTable(PLDHashTable *table, PRUint32 nbytes)
{
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ return RTMemAlloc(nbytes);
+#else
return malloc(nbytes);
+#endif
}
PR_IMPLEMENT(void)
PL_DHashFreeTable(PLDHashTable *table, void *ptr)
{
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(ptr);
+#else
free(ptr);
+#endif
}
PR_IMPLEMENT(PLDHashNumber)
@@ -136,7 +147,11 @@ PL_DHashFreeStringKey(PLDHashTable *table, PLDHashEntryHdr *entry)
{
const PLDHashEntryStub *stub = (const PLDHashEntryStub *)entry;
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree((void *) stub->key);
+#else
free((void *) stub->key);
+#endif
memset(entry, 0, table->entrySize);
}
@@ -169,11 +184,19 @@ PL_NewDHashTable(const PLDHashTableOps *ops, void *data, PRUint32 entrySize,
{
PLDHashTable *table;
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ table = (PLDHashTable *) RTMemAlloc(sizeof *table);
+#else
table = (PLDHashTable *) malloc(sizeof *table);
+#endif
if (!table)
return NULL;
if (!PL_DHashTableInit(table, ops, data, entrySize, capacity)) {
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(table);
+#else
free(table);
+#endif
return NULL;
}
return table;
@@ -183,7 +206,11 @@ PR_IMPLEMENT(void)
PL_DHashTableDestroy(PLDHashTable *table)
{
PL_DHashTableFinish(table);
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(table);
+#else
free(table);
+#endif
}
PR_IMPLEMENT(PRBool)
diff --git a/src/libs/xpcom18a4/xpcom/proxy/src/nsProxyEvent.cpp b/src/libs/xpcom18a4/xpcom/proxy/src/nsProxyEvent.cpp
index 3cbbde963d4..561c2fdb59e 100644
--- a/src/libs/xpcom18a4/xpcom/proxy/src/nsProxyEvent.cpp
+++ b/src/libs/xpcom18a4/xpcom/proxy/src/nsProxyEvent.cpp
@@ -75,7 +75,7 @@
#define nsUTF8String nsCString
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
-
+
static void* PR_CALLBACK EventHandler(PLEvent *self);
static void PR_CALLBACK DestroyHandler(PLEvent *self);
static void* PR_CALLBACK CompletedEventHandler(PLEvent *self);
@@ -85,15 +85,15 @@ static void PR_CALLBACK ProxyDestructorDestroyHandler(PLEvent *self) ;
nsProxyObjectCallInfo::nsProxyObjectCallInfo( nsProxyObject* owner,
nsXPTMethodInfo *methodInfo,
- PRUint32 methodIndex,
- nsXPTCVariant* parameterList,
- PRUint32 parameterCount,
+ PRUint32 methodIndex,
+ nsXPTCVariant* parameterList,
+ PRUint32 parameterCount,
PLEvent *event)
{
NS_ASSERTION(owner, "No nsProxyObject!");
NS_ASSERTION(methodInfo, "No nsXPTMethodInfo!");
NS_ASSERTION(event, "No PLEvent!");
-
+
mCompleted = 0;
mMethodIndex = methodIndex;
mParameterList = parameterList;
@@ -103,7 +103,7 @@ nsProxyObjectCallInfo::nsProxyObjectCallInfo( nsProxyObject* owner,
mCallersEventQ = nsnull;
mOwner = owner;
-
+
RefCountInInterfacePointers(PR_TRUE);
if (mOwner->GetProxyType() & PROXY_ASYNC)
CopyStrings(PR_TRUE);
@@ -117,11 +117,15 @@ nsProxyObjectCallInfo::~nsProxyObjectCallInfo()
CopyStrings(PR_FALSE);
mOwner = nsnull;
-
+
PR_FREEIF(mEvent);
-
- if (mParameterList)
+
+ if (mParameterList)
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ nsMemory::Free((void*) mParameterList);
+#else
free( (void*) mParameterList);
+#endif
}
void
@@ -138,14 +142,14 @@ nsProxyObjectCallInfo::RefCountInInterfacePointers(PRBool addRef)
if (paramInfo.IsIn())
{
anInterface = ((nsISupports*)mParameterList[i].val.p);
-
+
if (anInterface)
{
if(addRef)
anInterface->AddRef();
else
anInterface->Release();
-
+
}
}
}
@@ -169,10 +173,10 @@ nsProxyObjectCallInfo::CopyStrings(PRBool copy)
continue;
if (copy)
- {
- switch (type_tag)
+ {
+ switch (type_tag)
{
- case nsXPTType::T_CHAR_STR:
+ case nsXPTType::T_CHAR_STR:
mParameterList[i].val.p =
PL_strdup((const char *)ptr);
break;
@@ -182,25 +186,25 @@ nsProxyObjectCallInfo::CopyStrings(PRBool copy)
break;
case nsXPTType::T_DOMSTRING:
case nsXPTType::T_ASTRING:
- mParameterList[i].val.p =
+ mParameterList[i].val.p =
new nsString(*((nsAString*) ptr));
break;
case nsXPTType::T_CSTRING:
- mParameterList[i].val.p =
+ mParameterList[i].val.p =
new nsCString(*((nsACString*) ptr));
break;
- case nsXPTType::T_UTF8STRING:
- mParameterList[i].val.p =
+ case nsXPTType::T_UTF8STRING:
+ mParameterList[i].val.p =
new nsUTF8String(*((nsAUTF8String*) ptr));
break;
default:
// Other types are ignored
- break;
+ break;
}
}
else
{
- switch (type_tag)
+ switch (type_tag)
{
case nsXPTType::T_CHAR_STR:
case nsXPTType::T_WCHAR_STR:
@@ -225,7 +229,7 @@ nsProxyObjectCallInfo::CopyStrings(PRBool copy)
}
}
-PRBool
+PRBool
nsProxyObjectCallInfo::GetCompleted()
{
return (PRBool)mCompleted;
@@ -237,18 +241,18 @@ nsProxyObjectCallInfo::SetCompleted()
PR_AtomicSet(&mCompleted, 1);
}
-void
+void
nsProxyObjectCallInfo::PostCompleted()
{
if (mCallersEventQ)
{
PLEvent *event = PR_NEW(PLEvent);
-
- PL_InitEvent(event,
+
+ PL_InitEvent(event,
this,
CompletedEventHandler,
CompletedDestroyHandler);
-
+
mCallersEventQ->PostSynchronousEvent(event, nsnull);
PR_FREEIF(event);
}
@@ -258,17 +262,17 @@ nsProxyObjectCallInfo::PostCompleted()
SetCompleted();
}
}
-
-nsIEventQueue*
-nsProxyObjectCallInfo::GetCallersQueue()
-{
+
+nsIEventQueue*
+nsProxyObjectCallInfo::GetCallersQueue()
+{
return mCallersEventQ;
-}
+}
void
nsProxyObjectCallInfo::SetCallersQueue(nsIEventQueue* queue)
{
mCallersEventQ = queue;
-}
+}
nsProxyObject::nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, nsISupports *realObject)
@@ -285,7 +289,7 @@ nsProxyObject::nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, const
{
mEventQService = do_GetService(kEventQueueServiceCID);
- nsComponentManager::CreateInstance(aClass,
+ nsComponentManager::CreateInstance(aClass,
aDelegate,
aIID,
getter_AddRefs(mRealObject));
@@ -295,10 +299,10 @@ nsProxyObject::nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, const
}
nsProxyObject::~nsProxyObject()
-{
- // I am worried about order of destruction here.
+{
+ // I am worried about order of destruction here.
// do not remove assignments.
-
+
mRealObject = 0;
mDestQueue = 0;
}
@@ -314,7 +318,7 @@ nsProxyObject::AddRef()
void
nsProxyObject::Release(void)
{
- NS_PRECONDITION(0 != mRefCnt, "dup release");
+ NS_PRECONDITION(0 != mRefCnt, "dup release");
nsrefcnt count = PR_AtomicDecrement((PRInt32 *)&mRefCnt);
NS_LOG_RELEASE(this, count, "nsProxyObject");
@@ -342,25 +346,25 @@ nsProxyObject::Release(void)
NS_ASSERTION(0, "Could not create a plevent. Leaking nsProxyObject!");
return; // if this happens we are going to leak.
}
-
- PL_InitEvent(event,
+
+ PL_InitEvent(event,
this,
ProxyDestructorEventHandler,
- ProxyDestructorDestroyHandler);
+ ProxyDestructorDestroyHandler);
mDestQueue->PostEvent(event);
- }
-}
+ }
+}
nsresult
nsProxyObject::PostAndWait(nsProxyObjectCallInfo *proxyInfo)
{
- if (proxyInfo == nsnull || mEventQService == nsnull)
+ if (proxyInfo == nsnull || mEventQService == nsnull)
return NS_ERROR_NULL_POINTER;
-
+
PRBool eventLoopCreated = PR_FALSE;
- nsresult rv;
+ nsresult rv;
nsCOMPtr<nsIEventQueue> eventQ;
rv = mEventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eventQ));
@@ -370,19 +374,19 @@ nsProxyObject::PostAndWait(nsProxyObjectCallInfo *proxyInfo)
eventLoopCreated = PR_TRUE;
if (NS_FAILED(rv))
return rv;
-
+
rv = mEventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eventQ));
}
if (NS_FAILED(rv))
return rv;
-
+
proxyInfo->SetCallersQueue(eventQ);
PLEvent* event = proxyInfo->GetPLEvent();
if (!event)
return NS_ERROR_NULL_POINTER;
-
+
mDestQueue->PostEvent(event);
while (! proxyInfo->GetCompleted())
@@ -390,24 +394,24 @@ nsProxyObject::PostAndWait(nsProxyObjectCallInfo *proxyInfo)
PLEvent *nextEvent;
rv = eventQ->WaitForEvent(&nextEvent);
if (NS_FAILED(rv)) break;
-
+
eventQ->HandleEvent(nextEvent);
- }
+ }
if (eventLoopCreated)
{
mEventQService->DestroyThreadEventQueue();
eventQ = 0;
}
-
+
return rv;
}
-
-
+
+
nsresult
-nsProxyObject::convertMiniVariantToVariant(nsXPTMethodInfo *methodInfo,
- nsXPTCMiniVariant * params,
- nsXPTCVariant **fullParam,
+nsProxyObject::convertMiniVariantToVariant(nsXPTMethodInfo *methodInfo,
+ nsXPTCMiniVariant * params,
+ nsXPTCVariant **fullParam,
uint8 *outParamCount)
{
uint8 paramCount = methodInfo->GetParamCount();
@@ -415,45 +419,49 @@ nsProxyObject::convertMiniVariantToVariant(nsXPTMethodInfo *methodInfo,
*fullParam = nsnull;
if (!paramCount) return NS_OK;
-
+
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ *fullParam = (nsXPTCVariant*)nsMemory::Alloc(sizeof(nsXPTCVariant) * paramCount);
+#else
*fullParam = (nsXPTCVariant*)malloc(sizeof(nsXPTCVariant) * paramCount);
-
+#endif
+
if (*fullParam == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
-
+
for (int i = 0; i < paramCount; i++)
{
const nsXPTParamInfo& paramInfo = methodInfo->GetParam(i);
if ((mProxyType & PROXY_ASYNC) && paramInfo.IsDipper())
{
- NS_WARNING("Async proxying of out parameters is not supported");
+ NS_WARNING("Async proxying of out parameters is not supported");
return NS_ERROR_PROXY_INVALID_OUT_PARAMETER;
}
uint8 flags = paramInfo.IsOut() ? nsXPTCVariant::PTR_IS_DATA : 0;
(*fullParam)[i].Init(params[i], paramInfo.GetType(), flags);
}
-
+
return NS_OK;
}
-
+
nsresult
-nsProxyObject::Post( PRUint32 methodIndex,
- nsXPTMethodInfo *methodInfo,
- nsXPTCMiniVariant * params,
- nsIInterfaceInfo *interfaceInfo)
+nsProxyObject::Post( PRUint32 methodIndex,
+ nsXPTMethodInfo *methodInfo,
+ nsXPTCMiniVariant * params,
+ nsIInterfaceInfo *interfaceInfo)
{
- nsresult rv = NS_OK;
+ nsresult rv = NS_OK;
if (! mDestQueue || ! mRealObject)
return NS_ERROR_OUT_OF_MEMORY;
if (methodInfo->IsNotXPCOM())
return NS_ERROR_PROXY_INVALID_IN_PARAMETER;
-
+
nsXPTCVariant *fullParam;
- uint8 paramCount;
+ uint8 paramCount;
rv = convertMiniVariantToVariant(methodInfo, params, &fullParam, &paramCount);
-
+
if (NS_FAILED(rv))
return rv;
@@ -461,61 +469,73 @@ nsProxyObject::Post( PRUint32 methodIndex,
// see if we should call into the method directly. Either it is a QI function call
// (methodIndex == 0), or it is a sync proxy and this code is running on the same thread
- // as the destination event queue.
+ // as the destination event queue.
if ( (methodIndex == 0) ||
- (mProxyType & PROXY_SYNC &&
+ (mProxyType & PROXY_SYNC &&
NS_SUCCEEDED(mDestQueue->IsOnCurrentThread(&callDirectly)) &&
callDirectly))
{
// invoke the magic of xptc...
- nsresult rv = XPTC_InvokeByIndex( mRealObject,
+ nsresult rv = XPTC_InvokeByIndex( mRealObject,
methodIndex,
- paramCount,
+ paramCount,
fullParam);
-
- if (fullParam)
+
+ if (fullParam)
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ nsMemory::Free(fullParam);
+#else
free(fullParam);
+#endif
return rv;
}
PLEvent *event = PR_NEW(PLEvent);
-
+
if (event == nsnull) {
- if (fullParam)
+ if (fullParam)
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ nsMemory::Free(fullParam);
+#else
free(fullParam);
- return NS_ERROR_OUT_OF_MEMORY;
+#endif
+ return NS_ERROR_OUT_OF_MEMORY;
}
- nsProxyObjectCallInfo *proxyInfo = new nsProxyObjectCallInfo(this,
- methodInfo,
- methodIndex,
+ nsProxyObjectCallInfo *proxyInfo = new nsProxyObjectCallInfo(this,
+ methodInfo,
+ methodIndex,
fullParam, // will be deleted by ~()
- paramCount,
+ paramCount,
event); // will be deleted by ~()
-
+
if (proxyInfo == nsnull) {
PR_DELETE(event);
if (fullParam)
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ nsMemory::Free(fullParam);
+#else
free(fullParam);
- return NS_ERROR_OUT_OF_MEMORY;
+#endif
+ return NS_ERROR_OUT_OF_MEMORY;
}
- PL_InitEvent(event,
+ PL_InitEvent(event,
proxyInfo,
EventHandler,
DestroyHandler);
-
+
if (mProxyType & PROXY_SYNC)
{
rv = PostAndWait(proxyInfo);
-
+
if (NS_SUCCEEDED(rv))
rv = proxyInfo->GetResult();
delete proxyInfo;
return rv;
}
-
+
if (mProxyType & PROXY_ASYNC)
{
mDestQueue->PostEvent(event);
@@ -526,16 +546,16 @@ nsProxyObject::Post( PRUint32 methodIndex,
-static void DestroyHandler(PLEvent *self)
+static void DestroyHandler(PLEvent *self)
{
nsProxyObjectCallInfo* owner = (nsProxyObjectCallInfo*)PL_GetEventOwner(self);
nsProxyObject* proxyObject = owner->GetProxyObject();
-
+
if (proxyObject == nsnull)
return;
-
+
if (proxyObject->GetProxyType() & PROXY_ASYNC)
- {
+ {
delete owner;
}
else
@@ -545,19 +565,19 @@ static void DestroyHandler(PLEvent *self)
}
-static void* EventHandler(PLEvent *self)
+static void* EventHandler(PLEvent *self)
{
nsProxyObjectCallInfo *info = (nsProxyObjectCallInfo*)PL_GetEventOwner(self);
NS_ASSERTION(info, "No nsProxyObjectCallInfo!");
-
+
nsProxyObject *proxyObject = info->GetProxyObject();
-
+
if (proxyObject)
{
// invoke the magic of xptc...
- nsresult rv = XPTC_InvokeByIndex( proxyObject->GetRealObject(),
+ nsresult rv = XPTC_InvokeByIndex( proxyObject->GetRealObject(),
info->GetMethodIndex(),
- info->GetParameterCount(),
+ info->GetParameterCount(),
info->GetParameterList());
info->SetResult(rv);
}
@@ -568,11 +588,11 @@ static void* EventHandler(PLEvent *self)
return NULL;
}
-static void CompletedDestroyHandler(PLEvent *self)
+static void CompletedDestroyHandler(PLEvent *self)
{
}
-static void* CompletedEventHandler(PLEvent *self)
+static void* CompletedEventHandler(PLEvent *self)
{
nsProxyObjectCallInfo* owner = (nsProxyObjectCallInfo*)PL_GetEventOwner(self);
owner->SetCompleted();
@@ -580,10 +600,10 @@ static void* CompletedEventHandler(PLEvent *self)
}
static void* ProxyDestructorEventHandler(PLEvent *self)
-{
+{
nsProxyObject* owner = (nsProxyObject*) PL_GetEventOwner(self);
NS_DELETEXPCOM(owner);
- return nsnull;
+ return nsnull;
}
static void ProxyDestructorDestroyHandler(PLEvent *self)
diff --git a/src/libs/xpcom18a4/xpcom/string/src/nsStringObsolete.cpp b/src/libs/xpcom18a4/xpcom/string/src/nsStringObsolete.cpp
index 682cf936773..76106a27bd3 100644
--- a/src/libs/xpcom18a4/xpcom/string/src/nsStringObsolete.cpp
+++ b/src/libs/xpcom18a4/xpcom/string/src/nsStringObsolete.cpp
@@ -52,6 +52,9 @@
#include "nsUTF8Utils.h"
#include "prdtoa.h"
#include "prprf.h"
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+# include <iprt/mem.h>
+#endif
/* ***** BEGIN RICKG BLOCK *****
*
@@ -78,7 +81,7 @@ ascii_tolower(char aChar)
/**
* This methods cans the given buffer for the given char
- *
+ *
* @update gess 02/17/00
* @param aDest is the buffer to be searched
* @param aDestLength is the size (in char-units, not bytes) of the buffer
@@ -100,7 +103,7 @@ FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnicha
//We'll only search if the given aChar is within the normal ascii a range,
//(Since this string is definitely within the ascii range).
-
+
if(0<aCount) {
const char* left= aDest+anOffset;
@@ -110,13 +113,13 @@ FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnicha
PRInt32 theMax = end-left;
if(0<theMax) {
-
+
unsigned char theChar = (unsigned char) aChar;
const char* result=(const char*)memchr(left, (int)theChar, theMax);
-
+
if(result)
return result-aDest;
-
+
}
}
}
@@ -127,7 +130,7 @@ FindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnicha
/**
* This methods cans the given buffer for the given char
- *
+ *
* @update gess 3/25/98
* @param aDest is the buffer to be searched
* @param aDestLength is the size (in char-units, not bytes) of the buffer
@@ -146,7 +149,7 @@ FindChar2(const PRUnichar* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRU
aCount = (PRInt32)aDestLength;
if((0<aDestLength) && ((PRUint32)anOffset < aDestLength)) {
-
+
if(0<aCount) {
const PRUnichar* root = aDest;
@@ -156,10 +159,10 @@ FindChar2(const PRUnichar* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRU
const PRUnichar* end = (last<max) ? last : max;
while(left<end){
-
+
if(*left==aChar)
return (left-root);
-
+
++left;
}
}
@@ -171,7 +174,7 @@ FindChar2(const PRUnichar* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRU
/**
* This methods cans the given buffer (in reverse) for the given char
- *
+ *
* @update gess 02/17/00
* @param aDest is the buffer to be searched
* @param aDestLength is the size (in char-units, not bytes) of the buffer
@@ -194,19 +197,19 @@ RFindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnich
//We'll only search if the given aChar is within the normal ascii a range,
//(Since this string is definitely within the ascii range).
-
+
if(0 < aCount) {
- const char* rightmost = aDest + anOffset;
+ const char* rightmost = aDest + anOffset;
const char* min = rightmost - aCount + 1;
const char* leftmost = (min<aDest) ? aDest: min;
char theChar=(char)aChar;
while(leftmost <= rightmost){
-
+
if((*rightmost) == theChar)
return rightmost - aDest;
-
+
--rightmost;
}
}
@@ -218,7 +221,7 @@ RFindChar1(const char* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PRUnich
/**
* This methods cans the given buffer for the given char
- *
+ *
* @update gess 3/25/98
* @param aDest is the buffer to be searched
* @param aDestLength is the size (in char-units, not bytes) of the buffer
@@ -237,19 +240,19 @@ RFindChar2(const PRUnichar* aDest,PRUint32 aDestLength,PRInt32 anOffset,const PR
aCount = PRInt32(aDestLength);
if((0 < aDestLength) && ((PRUint32)anOffset < aDestLength)) {
-
+
if(0 < aCount) {
const PRUnichar* root = aDest;
- const PRUnichar* rightmost = root + anOffset;
+ const PRUnichar* rightmost = root + anOffset;
const PRUnichar* min = rightmost - aCount + 1;
const PRUnichar* leftmost = (min<root) ? root: min;
-
+
while(leftmost <= rightmost){
-
+
if((*rightmost) == aChar)
return rightmost - root;
-
+
--rightmost;
}
}
@@ -282,11 +285,11 @@ static
inline
#endif /* __SUNPRO_CC */
PRInt32
-Compare1To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
+Compare1To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
PRInt32 result=0;
if(aIgnoreCase)
result=PRInt32(PL_strncasecmp(aStr1, aStr2, aCount));
- else
+ else
result=nsCharTraits<char>::compare(aStr1,aStr2,aCount);
// alien comparisons may return out-of-bound answers
@@ -307,14 +310,14 @@ Compare1To1(const char* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCa
* @param aIgnoreCase tells us whether to use a case-sensitive comparison
* @return -1,0,1 depending on <,==,>
*/
-static
+static
#ifdef __SUNPRO_CC
inline
#endif /* __SUNPRO_CC */
PRInt32
Compare2To2(const PRUnichar* aStr1,const PRUnichar* aStr2,PRUint32 aCount){
PRInt32 result;
-
+
if ( aStr1 && aStr2 )
result = nsCharTraits<PRUnichar>::compare(aStr1, aStr2, aCount);
@@ -355,14 +358,14 @@ PRInt32
Compare2To1(const PRUnichar* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgnoreCase){
const PRUnichar* s1 = aStr1;
const char *s2 = aStr2;
-
+
if (aStr1 && aStr2) {
if (aCount != 0) {
do {
PRUnichar c1 = *s1++;
PRUnichar c2 = PRUnichar((unsigned char)*s2++);
-
+
if (c1 != c2) {
#ifdef NS_DEBUG
// we won't warn on c1>=128 (the 2-byte value) because often
@@ -378,7 +381,7 @@ Compare2To1(const PRUnichar* aStr1,const char* aStr2,PRUint32 aCount,PRBool aIgn
c1 = ascii_tolower(char(c1));
c2 = ascii_tolower(char(c2));
-
+
if (c1 == c2) continue;
}
@@ -414,7 +417,7 @@ Compare1To2(const char* aStr1,const PRUnichar* aStr2,PRUint32 aCount,PRBool aIgn
/**
- * This method compresses duplicate runs of a given char from the given buffer
+ * This method compresses duplicate runs of a given char from the given buffer
*
* @update rickg 03.23.2000
* @param aString is the buffer to be manipulated
@@ -425,7 +428,7 @@ Compare1To2(const char* aStr1,const PRUnichar* aStr2,PRUint32 aCount,PRBool aIgn
* @return the new length of the given buffer
*/
static PRInt32
-CompressChars1(char* aString,PRUint32 aLength,const char* aSet){
+CompressChars1(char* aString,PRUint32 aLength,const char* aSet){
char* from = aString;
char* end = aString + aLength;
@@ -438,7 +441,7 @@ CompressChars1(char* aString,PRUint32 aLength,const char* aSet){
while (from < end) {
char theChar = *from++;
-
+
*to++=theChar; //always copy this char...
if((kNotFound!=FindChar1(aSet,aSetLen,0,theChar,aSetLen))){
@@ -459,7 +462,7 @@ CompressChars1(char* aString,PRUint32 aLength,const char* aSet){
/**
- * This method compresses duplicate runs of a given char from the given buffer
+ * This method compresses duplicate runs of a given char from the given buffer
*
* @update rickg 03.23.2000
* @param aString is the buffer to be manipulated
@@ -470,7 +473,7 @@ CompressChars1(char* aString,PRUint32 aLength,const char* aSet){
* @return the new length of the given buffer
*/
static PRInt32
-CompressChars2(PRUnichar* aString,PRUint32 aLength,const char* aSet){
+CompressChars2(PRUnichar* aString,PRUint32 aLength,const char* aSet){
PRUnichar* from = aString;
PRUnichar* end = from + aLength;
@@ -483,7 +486,7 @@ CompressChars2(PRUnichar* aString,PRUint32 aLength,const char* aSet){
while (from < end) {
PRUnichar theChar = *from++;
-
+
*to++=theChar; //always copy this char...
if((theChar<256) && (kNotFound!=FindChar1(aSet,aSetLen,0,theChar,aSetLen))){
@@ -502,7 +505,7 @@ CompressChars2(PRUnichar* aString,PRUint32 aLength,const char* aSet){
}
/**
- * This method strips chars in a given set from the given buffer
+ * This method strips chars in a given set from the given buffer
*
* @update gess 01/04/99
* @param aString is the buffer to be manipulated
@@ -513,7 +516,7 @@ CompressChars2(PRUnichar* aString,PRUint32 aLength,const char* aSet){
* @return the new length of the given buffer
*/
static PRInt32
-StripChars1(char* aString,PRUint32 aLength,const char* aSet){
+StripChars1(char* aString,PRUint32 aLength,const char* aSet){
// XXXdarin this code should defer writing until necessary.
@@ -536,7 +539,7 @@ StripChars1(char* aString,PRUint32 aLength,const char* aSet){
/**
- * This method strips chars in a given set from the given buffer
+ * This method strips chars in a given set from the given buffer
*
* @update gess 01/04/99
* @param aString is the buffer to be manipulated
@@ -547,7 +550,7 @@ StripChars1(char* aString,PRUint32 aLength,const char* aSet){
* @return the new length of the given buffer
*/
static PRInt32
-StripChars2(PRUnichar* aString,PRUint32 aLength,const char* aSet){
+StripChars2(PRUnichar* aString,PRUint32 aLength,const char* aSet){
// XXXdarin this code should defer writing until necessary.
@@ -559,7 +562,7 @@ StripChars2(PRUnichar* aString,PRUint32 aLength,const char* aSet){
PRUint32 aSetLen=strlen(aSet);
while (++from < end) {
PRUnichar theChar = *from;
- //Note the test for ascii range below. If you have a real unicode char,
+ //Note the test for ascii range below. If you have a real unicode char,
//and you're searching for chars in the (given) ascii string, there's no
//point in doing the real search since it's out of the ascii range.
if((255<theChar) || (kNotFound==FindChar1(aSet,aSetLen,0,theChar,aSetLen))){
@@ -634,7 +637,7 @@ struct nsBufferRoutines<char>
}
static
- PRInt32 compress_chars( char* s, PRUint32 len, const char* set )
+ PRInt32 compress_chars( char* s, PRUint32 len, const char* set )
{
return CompressChars1(s, len, set);
}
@@ -687,7 +690,7 @@ struct nsBufferRoutines<PRUnichar>
}
static
- PRInt32 compress_chars( PRUnichar* s, PRUint32 len, const char* set )
+ PRInt32 compress_chars( PRUnichar* s, PRUint32 len, const char* set )
{
return CompressChars2(s, len, set);
}
@@ -750,7 +753,7 @@ FindCharInSet( const CharT* data, PRUint32 dataLen, const SetCharT* set )
{
CharT filter = nsBufferRoutines<CharT>::get_find_in_set_filter(set);
- const CharT* end = data + dataLen;
+ const CharT* end = data + dataLen;
for (const CharT* iter = data; iter < end; ++iter)
{
CharT currentChar = *iter;
@@ -806,7 +809,7 @@ RFindCharInSet( const CharT* data, PRUint32 dataLen, const SetCharT* set )
*
* XXXdarin if this is the right thing, then why wasn't it fixed in NSPR?!?
*/
-void
+void
Modified_cnvtf(char *buf, int bufsz, int prcsn, double fval)
{
PRIntn decpt, sign, numdigits;
@@ -815,7 +818,11 @@ Modified_cnvtf(char *buf, int bufsz, int prcsn, double fval)
char *endnum;
/* If anything fails, we store an empty string in 'buf' */
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ num = (char*)RTMemAlloc(bufsz);
+#else
num = (char*)malloc(bufsz);
+#endif
if (num == NULL) {
buf[0] = '\0';
return;
@@ -890,16 +897,20 @@ Modified_cnvtf(char *buf, int bufsz, int prcsn, double fval)
*bufp++ = '\0';
}
done:
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(num);
+#else
free(num);
+#endif
}
/**
* this method changes the meaning of |offset| and |count|:
- *
+ *
* upon return,
* |offset| specifies start of search range
* |count| specifies length of search range
- */
+ */
static void
Find_ComputeSearchRange( PRUint32 bigLen, PRUint32 littleLen, PRInt32& offset, PRInt32& count )
{
@@ -919,7 +930,7 @@ Find_ComputeSearchRange( PRUint32 bigLen, PRUint32 littleLen, PRInt32& offset, P
if (count < 0 || count > maxCount)
{
count = maxCount;
- }
+ }
else
{
count += littleLen;
@@ -934,14 +945,14 @@ Find_ComputeSearchRange( PRUint32 bigLen, PRUint32 littleLen, PRInt32& offset, P
* upon entry,
* |offset| specifies the end point from which to search backwards
* |count| specifies the number of iterations from |offset|
- *
+ *
* upon return,
* |offset| specifies start of search range
* |count| specifies length of search range
*
*
* EXAMPLE
- *
+ *
* + -- littleLen=4 -- +
* : :
* |____|____|____|____|____|____|____|____|____|____|____|____|
@@ -951,7 +962,7 @@ Find_ComputeSearchRange( PRUint32 bigLen, PRUint32 littleLen, PRInt32& offset, P
* if count = 4, then we expect this function to return offset = 2 and
* count = 7.
*
- */
+ */
static void
RFind_ComputeSearchRange( PRUint32 bigLen, PRUint32 littleLen, PRInt32& offset, PRInt32& count )
{
@@ -1034,7 +1045,7 @@ nsString::FindCharInSet( const PRUnichar* aSet, PRInt32 aOffset ) const
aOffset = 0;
else if (aOffset >= PRInt32(mLength))
return kNotFound;
-
+
PRInt32 result = ::FindCharInSet(mData + aOffset, mLength - aOffset, aSet);
if (result != kNotFound)
result += aOffset;
diff --git a/src/libs/xpcom18a4/xpcom/string/src/nsSubstring.cpp b/src/libs/xpcom18a4/xpcom/string/src/nsSubstring.cpp
index dc791c5e430..6ed0c5c82dc 100644
--- a/src/libs/xpcom18a4/xpcom/string/src/nsSubstring.cpp
+++ b/src/libs/xpcom18a4/xpcom/string/src/nsSubstring.cpp
@@ -50,6 +50,9 @@
#include "nsDependentString.h"
#include "nsMemory.h"
#include "pratom.h"
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+# include <iprt/mem.h>
+#endif
// ---------------------------------------------------------------------------
@@ -75,6 +78,7 @@ class nsStringStats
if (!mAllocCount && !mAdoptCount)
return;
+#ifndef VBOX
printf("nsStringStats\n");
printf(" => mAllocCount: % 10d\n", mAllocCount);
printf(" => mReallocCount: % 10d\n", mReallocCount);
@@ -90,6 +94,7 @@ class nsStringStats
printf(" -- LEAKED %d !!!\n", mAdoptCount - mAdoptFreeCount);
else
printf("\n");
+#endif
}
PRInt32 mAllocCount;
@@ -136,7 +141,11 @@ class nsStringHeader
if (PR_AtomicDecrement(&mRefCount) == 0)
{
STRING_STAT_INCREMENT(Free);
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(this); // we were allocated with |malloc|
+#else
free(this); // we were allocated with |malloc|
+#endif
}
}
@@ -146,11 +155,15 @@ class nsStringHeader
static nsStringHeader* Alloc(size_t size)
{
STRING_STAT_INCREMENT(Alloc);
-
+
NS_ASSERTION(size != 0, "zero capacity allocation not allowed");
nsStringHeader *hdr =
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ (nsStringHeader *) RTMemAlloc(sizeof(nsStringHeader) + size);
+#else
(nsStringHeader *) malloc(sizeof(nsStringHeader) + size);
+#endif
if (hdr)
{
hdr->mRefCount = 1;
@@ -168,7 +181,11 @@ class nsStringHeader
// no point in trying to save ourselves if we hit this assertion
NS_ASSERTION(!hdr->IsReadonly(), "|Realloc| attempted on readonly string");
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ hdr = (nsStringHeader*) RTMemRealloc(hdr, sizeof(nsStringHeader) + size);
+#else
hdr = (nsStringHeader*) realloc(hdr, sizeof(nsStringHeader) + size);
+#endif
if (hdr)
hdr->mStorageSize = size;
diff --git a/src/libs/xpcom18a4/xpcom/threads/nsProcessCommon.cpp b/src/libs/xpcom18a4/xpcom/threads/nsProcessCommon.cpp
index 96c958ad474..07087c2f682 100644
--- a/src/libs/xpcom18a4/xpcom/threads/nsProcessCommon.cpp
+++ b/src/libs/xpcom18a4/xpcom/threads/nsProcessCommon.cpp
@@ -38,7 +38,7 @@
* ***** END LICENSE BLOCK ***** */
/*****************************************************************************
- *
+ *
* nsProcess is used to execute new processes and specify if you want to
* wait (blocking) or continue (non-blocking).
*
@@ -88,7 +88,7 @@ nsProcess::Init(nsIFile* executable)
//Store the nsIFile in mExecutable
mExecutable = executable;
//Get the path because it is needed by the NSPR process creation
-#ifdef XP_WIN
+#ifdef XP_WIN
rv = mExecutable->GetNativeTarget(mTargetPath);
if (NS_FAILED(rv) || mTargetPath.IsEmpty() )
#endif
@@ -132,7 +132,7 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
for (arg = argv; *arg; arg++) {
/* Add a space to separates the arguments */
if (arg != argv) {
- *p++ = ' ';
+ *p++ = ' ';
}
q = *arg;
numBackslashes = 0;
@@ -195,7 +195,7 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
if (argNeedQuotes) {
*p++ = '"';
}
- }
+ }
*p = '\0';
return 0;
@@ -203,7 +203,7 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
#endif
// XXXldb |args| has the wrong const-ness
-NS_IMETHODIMP
+NS_IMETHODIMP
nsProcess::Run(PRBool blocking, const char **args, PRUint32 count, PRUint32 *pid)
{
nsresult rv = NS_OK;
@@ -212,7 +212,11 @@ nsProcess::Run(PRBool blocking, const char **args, PRUint32 count, PRUint32 *pid
// count since we need to null terminate the list for the argv to
// pass into PR_CreateProcess
char **my_argv = NULL;
+#ifdef VBOX
+ my_argv = (char **)nsMemory::Alloc(sizeof(char *) * (count + 2) );
+#else
my_argv = (char **)malloc(sizeof(char *) * (count + 2) );
+#endif
if (!my_argv) {
return NS_ERROR_OUT_OF_MEMORY;
}
@@ -235,7 +239,7 @@ nsProcess::Run(PRBool blocking, const char **args, PRUint32 count, PRUint32 *pid
if (assembleCmdLine(my_argv, &cmdLine) == -1) {
nsMemory::Free(my_argv);
- return NS_ERROR_FILE_EXECUTION_FAILED;
+ return NS_ERROR_FILE_EXECUTION_FAILED;
}
ZeroMemory(&startupInfo, sizeof(startupInfo));
@@ -257,9 +261,9 @@ nsProcess::Run(PRBool blocking, const char **args, PRUint32 count, PRUint32 *pid
);
PR_FREEIF( cmdLine );
if (blocking) {
-
+
// if success, wait for process termination. the early returns and such
- // are a bit ugly but preserving the logic of the nspr code I copied to
+ // are a bit ugly but preserving the logic of the nspr code I copied to
// minimize our risk abit.
if ( retVal == TRUE ) {
@@ -281,12 +285,12 @@ nsProcess::Run(PRBool blocking, const char **args, PRUint32 count, PRUint32 *pid
}
else
rv = PR_FAILURE;
- }
+ }
else {
// map return value into success code
- if ( retVal == TRUE )
+ if ( retVal == TRUE )
rv = PR_SUCCESS;
else
rv = PR_FAILURE;
@@ -346,7 +350,7 @@ nsProcess::Kill()
nsresult rv = NS_OK;
if (mProcess)
rv = PR_KillProcess(mProcess);
-
+
return rv;
}
@@ -354,6 +358,6 @@ NS_IMETHODIMP
nsProcess::GetExitValue(PRInt32 *aExitValue)
{
*aExitValue = mExitValue;
-
+
return NS_OK;
}
diff --git a/src/libs/xpcom18a4/xpcom/typelib/xpt/src/xpt_arena.c b/src/libs/xpcom18a4/xpcom/typelib/xpt/src/xpt_arena.c
index 738b647e4d5..a0813b8f5b4 100644
--- a/src/libs/xpcom18a4/xpcom/typelib/xpt/src/xpt_arena.c
+++ b/src/libs/xpcom18a4/xpcom/typelib/xpt/src/xpt_arena.c
@@ -39,7 +39,7 @@
/* XXX This exists because we don't want to drag in NSPR. It *seemed*
* to make more sense to write a quick and dirty arena than to clone
-* plarena (like js/src did). This is not optimal, but it works.
+* plarena (like js/src did). This is not optimal, but it works.
* Half of the code here is instrumentation.
*/
@@ -47,6 +47,10 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+# include <iprt/mem.h>
+#endif
+
/*************************/
/* logging stats support */
@@ -93,7 +97,7 @@ static void xpt_DebugPrintArenaStats(XPTArena *arena);
#define LOG_REAL_MALLOC(_a, _size) ((void)0)
#define LOG_FREE(_a) ((void)0)
-#define LOG_DONE_LOADING(_a) ((void)0)
+#define LOG_DONE_LOADING(_a) ((void)0)
#define PRINT_STATS(_a) ((void)0)
#endif /* XPT_ARENA_LOGGING */
@@ -136,7 +140,11 @@ struct XPTArena
XPT_PUBLIC_API(XPTArena *)
XPT_NewArena(PRUint32 block_size, size_t alignment, const char* name)
{
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ XPTArena *arena = RTMemAllocZ(sizeof(XPTArena));
+#else
XPTArena *arena = calloc(1, sizeof(XPTArena));
+#endif
if (arena) {
XPT_ASSERT(alignment);
if (alignment > sizeof(double))
@@ -148,12 +156,12 @@ XPT_NewArena(PRUint32 block_size, size_t alignment, const char* name)
arena->block_size = ALIGN_RND(block_size, alignment);
/* must have room for at least one item! */
- XPT_ASSERT(arena->block_size >=
+ XPT_ASSERT(arena->block_size >=
ALIGN_RND(sizeof(BLK_HDR), alignment) +
ALIGN_RND(1, alignment));
if (name) {
- arena->name = XPT_STRDUP(arena, name);
+ arena->name = XPT_STRDUP(arena, name);
#ifdef XPT_ARENA_LOGGING
/* fudge the stats since we are using space in the arena */
arena->LOG_MallocCallCount = 0;
@@ -162,7 +170,7 @@ XPT_NewArena(PRUint32 block_size, size_t alignment, const char* name)
#endif /* XPT_ARENA_LOGGING */
}
}
- return arena;
+ return arena;
}
XPT_PUBLIC_API(void)
@@ -170,25 +178,33 @@ XPT_DestroyArena(XPTArena *arena)
{
BLK_HDR* cur;
BLK_HDR* next;
-
+
cur = arena->first;
while (cur) {
next = cur->next;
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(cur);
+#else
free(cur);
+#endif
cur = next;
}
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ RTMemFree(arena);
+#else
free(arena);
+#endif
}
XPT_PUBLIC_API(void)
XPT_DumpStats(XPTArena *arena)
{
PRINT_STATS(arena);
-}
+}
-/*
-* Our alignment rule is that we always round up the size of each allocation
+/*
+* Our alignment rule is that we always round up the size of each allocation
* so that the 'arena->next' pointer one will point to properly aligned space.
*/
@@ -207,19 +223,23 @@ XPT_ArenaMalloc(XPTArena *arena, size_t size)
}
bytes = ALIGN_RND(size, arena->alignment);
-
+
LOG_MALLOC(arena, size, bytes);
if (bytes > arena->space) {
BLK_HDR* new_block;
size_t block_header_size = ALIGN_RND(sizeof(BLK_HDR), arena->alignment);
size_t new_space = arena->block_size;
-
+
if (bytes > new_space - block_header_size)
new_space += bytes;
- new_block = (BLK_HDR*) calloc(new_space/arena->alignment,
+#ifdef VBOX_USE_IPRT_IN_XPCOM
+ new_block = (BLK_HDR*) RTMemAllocZ(new_space/arena->alignment * (size_t)arena->alignment);
+#else
+ new_block = (BLK_HDR*) calloc(new_space/arena->alignment,
arena->alignment);
+#endif
if (!new_block) {
arena->next = NULL;
arena->space = 0;
@@ -243,25 +263,25 @@ XPT_ArenaMalloc(XPTArena *arena, size_t size)
/* mark block for corruption check */
memset(arena->next, 0xcd, arena->space);
#endif
- }
-
+ }
+
#ifdef DEBUG
{
/* do corruption check */
size_t i;
for (i = 0; i < bytes; ++i) {
- XPT_ASSERT(arena->next[i] == 0xcd);
+ XPT_ASSERT(arena->next[i] == 0xcd);
}
/* we guarantee that the block will be filled with zeros */
memset(arena->next, 0, bytes);
- }
+ }
#endif
cur = arena->next;
arena->next += bytes;
arena->space -= bytes;
-
- return cur;
+
+ return cur;
}
@@ -285,7 +305,7 @@ XPT_NotifyDoneLoading(XPTArena *arena)
{
#ifdef XPT_ARENA_LOGGING
if (arena) {
- LOG_DONE_LOADING(arena);
+ LOG_DONE_LOADING(arena);
}
#endif
}
@@ -300,29 +320,29 @@ XPT_ArenaFree(XPTArena *arena, void *block)
static void xpt_DebugPrintArenaStats(XPTArena *arena)
{
printf("()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()\n");
- printf("Start xpt arena stats for \"%s\"\n",
+ printf("Start xpt arena stats for \"%s\"\n",
arena->name ? arena->name : "unnamed arena");
printf("\n");
- printf("%d times arena malloc called\n", (int) arena->LOG_MallocCallCount);
- printf("%d total bytes requested from arena malloc\n", (int) arena->LOG_MallocTotalBytesRequested);
+ printf("%d times arena malloc called\n", (int) arena->LOG_MallocCallCount);
+ printf("%d total bytes requested from arena malloc\n", (int) arena->LOG_MallocTotalBytesRequested);
printf("%d average bytes requested per call to arena malloc\n", (int)arena->LOG_MallocCallCount ? (arena->LOG_MallocTotalBytesRequested/arena->LOG_MallocCallCount) : 0);
printf("%d average bytes used per call (accounts for alignment overhead)\n", (int)arena->LOG_MallocCallCount ? (arena->LOG_MallocTotalBytesUsed/arena->LOG_MallocCallCount) : 0);
printf("%d average bytes used per call (accounts for all overhead and waste)\n", (int)arena->LOG_MallocCallCount ? (arena->LOG_RealMallocTotalBytesRequested/arena->LOG_MallocCallCount) : 0);
printf("\n");
- printf("%d during loading times arena free called\n", (int) arena->LOG_LoadingFreeCallCount);
- printf("%d during loading approx total bytes not freed\n", (int) arena->LOG_LoadingFreeCallCount * (int) (arena->LOG_MallocCallCount ? (arena->LOG_MallocTotalBytesUsed/arena->LOG_MallocCallCount) : 0));
+ printf("%d during loading times arena free called\n", (int) arena->LOG_LoadingFreeCallCount);
+ printf("%d during loading approx total bytes not freed\n", (int) arena->LOG_LoadingFreeCallCount * (int) (arena->LOG_MallocCallCount ? (arena->LOG_MallocTotalBytesUsed/arena->LOG_MallocCallCount) : 0));
printf("\n");
- printf("%d total times arena free called\n", (int) arena->LOG_FreeCallCount);
- printf("%d approx total bytes not freed until arena destruction\n", (int) arena->LOG_FreeCallCount * (int) (arena->LOG_MallocCallCount ? (arena->LOG_MallocTotalBytesUsed/arena->LOG_MallocCallCount) : 0 ));
+ printf("%d total times arena free called\n", (int) arena->LOG_FreeCallCount);
+ printf("%d approx total bytes not freed until arena destruction\n", (int) arena->LOG_FreeCallCount * (int) (arena->LOG_MallocCallCount ? (arena->LOG_MallocTotalBytesUsed/arena->LOG_MallocCallCount) : 0 ));
printf("\n");
- printf("%d times arena called system malloc\n", (int) arena->LOG_RealMallocCallCount);
- printf("%d total bytes arena requested from system\n", (int) arena->LOG_RealMallocTotalBytesRequested);
- printf("%d byte block size specified at arena creation time\n", (int) arena->block_size);
- printf("%d byte block alignment specified at arena creation time\n", (int) arena->alignment);
+ printf("%d times arena called system malloc\n", (int) arena->LOG_RealMallocCallCount);
+ printf("%d total bytes arena requested from system\n", (int) arena->LOG_RealMallocTotalBytesRequested);
+ printf("%d byte block size specified at arena creation time\n", (int) arena->block_size);
+ printf("%d byte block alignment specified at arena creation time\n", (int) arena->alignment);
printf("\n");
printf("End xpt arena stats\n");
printf("()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()\n");
-}
+}
#endif
/***************************************************************************/
@@ -334,5 +354,5 @@ XPT_AssertFailed(const char *s, const char *file, PRUint32 lineno)
fprintf(stderr, "Assertion failed: %s, file %s, line %d\n",
s, file, lineno);
abort();
-}
+}
#endif