Backed out changeset 110e44b996f8 (bug 1034627) for Valgrind Testfailures on a CLOSED TREE

This commit is contained in:
Carsten "Tomcat" Book 2014-07-11 11:00:21 +02:00
parent dcc8c1b538
commit eb71d8cf86
3 changed files with 17 additions and 25 deletions

View File

@ -6,8 +6,6 @@
/* nsIVariant implementation for xpconnect. */
#include "mozilla/Range.h"
#include "xpcprivate.h"
#include "nsCxPusher.h"
@ -98,6 +96,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(XPCVariant)
JS::Value val = tmp->GetJSValPreserveColor();
// We're sharing val's buffer, clear the pointer to it so Cleanup() won't
// try to delete it
if (val.isString())
tmp->mData.u.wstr.mWStringValue = nullptr;
nsVariant::Cleanup(&tmp->mData);
if (val.isMarkable()) {
@ -286,18 +288,25 @@ bool XPCVariant::InitializeData(JSContext* cx)
if (!str)
return false;
// Don't use nsVariant::SetFromWStringWithSize, because that will copy
// the data. Just handle this ourselves. Note that it's ok to not
// copy because we added mJSVal as a GC root.
MOZ_ASSERT(mData.mType == nsIDataType::VTYPE_EMPTY,
"Why do we already have data?");
size_t length = JS_GetStringLength(str);
if (!NS_SUCCEEDED(nsVariant::AllocateWStringWithSize(&mData, length)))
// Despite the fact that the variant holds the length, there are
// implicit assumptions that mWStringValue[mWStringLength] == 0
size_t length;
const jschar *chars = JS_GetStringCharsZAndLength(cx, str, &length);
if (!chars)
return false;
mozilla::Range<jschar> destChars(mData.u.wstr.mWStringValue, length);
if (!JS_CopyStringChars(cx, destChars, str))
return false;
mData.u.wstr.mWStringValue = const_cast<jschar *>(chars);
// Use C-style cast, because reinterpret cast from size_t to
// uint32_t is not valid on some platforms.
mData.u.wstr.mWStringLength = (uint32_t)length;
mData.mType = nsIDataType::VTYPE_WSTRING_SIZE_IS;
MOZ_ASSERT(mData.u.wstr.mWStringValue[length] == '\0');
return true;
}

View File

@ -1557,18 +1557,6 @@ nsVariant::SetFromWStringWithSize(nsDiscriminatedUnion* aData, uint32_t aSize,
DATA_SETTER_EPILOGUE(aData, VTYPE_WSTRING_SIZE_IS);
}
/* static */ nsresult
nsVariant::AllocateWStringWithSize(nsDiscriminatedUnion* aData, uint32_t aSize)
{
DATA_SETTER_PROLOGUE(aData);
if (!(aData->u.wstr.mWStringValue =
(char16_t*)NS_Alloc((aSize + 1) * sizeof(char16_t)))) {
return NS_ERROR_OUT_OF_MEMORY;
}
aData->u.wstr.mWStringValue[aSize] = '\0';
aData->u.wstr.mWStringLength = aSize;
DATA_SETTER_EPILOGUE(aData, VTYPE_WSTRING_SIZE_IS);
}
/* static */ nsresult
nsVariant::SetToVoid(nsDiscriminatedUnion* aData)
{
DATA_SETTER_PROLOGUE(aData);

View File

@ -190,11 +190,6 @@ public:
uint32_t aSize,
const char16_t* aValue);
// Like SetFromWStringWithSize, but leaves the string uninitialized. It does
// does write the null-terminator.
static nsresult AllocateWStringWithSize(nsDiscriminatedUnion* aData,
uint32_t aSize);
static nsresult SetToVoid(nsDiscriminatedUnion* aData);
static nsresult SetToEmpty(nsDiscriminatedUnion* aData);
static nsresult SetToEmptyArray(nsDiscriminatedUnion* aData);