Bug 1126593 - Add a global fallible instance, so that using fallible works directly, everywhere. r=njn

--HG--
rename : memory/mozalloc/fallible.h => memory/fallible/fallible.h
This commit is contained in:
Mike Hommey 2015-01-28 18:00:40 +09:00
parent 25ec09169f
commit 824818ee98
97 changed files with 358 additions and 262 deletions

View File

@ -78,6 +78,11 @@ def GeckoBinary(linkage='dependent', msvcrt='dynamic', mozglue=None):
else:
error('`mozglue` must be "program" or "library"')
if not CONFIG['JS_STANDALONE']:
USE_LIBS += [
'fallible',
]
@template
def GeckoProgram(name, linkage='standalone', **kwargs):

View File

@ -109,7 +109,7 @@ DOMParser::ParseFromString(const nsAString& str,
nsAutoCString utf8str;
// Convert from UTF16 to UTF8 using fallible allocations
if (!AppendUTF16toUTF8(str, utf8str, mozilla::fallible_t())) {
if (!AppendUTF16toUTF8(str, utf8str, mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -2202,7 +2202,7 @@ public:
bool ToString(nsAString& aOut)
{
if (!aOut.SetCapacity(mLength, fallible_t())) {
if (!aOut.SetCapacity(mLength, fallible)) {
return false;
}

View File

@ -190,7 +190,7 @@ URLSearchParams::ConvertString(const nsACString& aInput, nsAString& aOutput)
return;
}
if (!aOutput.SetLength(outputLength, fallible_t())) {
if (!aOutput.SetLength(outputLength, fallible)) {
return;
}

View File

@ -732,7 +732,7 @@ nsContentUtils::Atob(const nsAString& aAsciiBase64String,
const char16_t* start = aAsciiBase64String.BeginReading();
const char16_t* end = aAsciiBase64String.EndReading();
nsString trimmedString;
if (!trimmedString.SetCapacity(aAsciiBase64String.Length(), fallible_t())) {
if (!trimmedString.SetCapacity(aAsciiBase64String.Length(), fallible)) {
return NS_ERROR_DOM_INVALID_CHARACTER_ERR;
}
while (start < end) {
@ -4425,20 +4425,20 @@ nsContentUtils::SetNodeTextContent(nsIContent* aContent,
static bool
AppendNodeTextContentsRecurse(nsINode* aNode, nsAString& aResult,
const mozilla::fallible_t&)
const fallible_t& aFallible)
{
for (nsIContent* child = aNode->GetFirstChild();
child;
child = child->GetNextSibling()) {
if (child->IsElement()) {
bool ok = AppendNodeTextContentsRecurse(child, aResult,
mozilla::fallible_t());
aFallible);
if (!ok) {
return false;
}
}
else if (child->IsNodeOfType(nsINode::eTEXT)) {
bool ok = child->AppendTextTo(aResult, mozilla::fallible_t());
bool ok = child->AppendTextTo(aResult, aFallible);
if (!ok) {
return false;
}
@ -4452,21 +4452,21 @@ AppendNodeTextContentsRecurse(nsINode* aNode, nsAString& aResult,
bool
nsContentUtils::AppendNodeTextContent(nsINode* aNode, bool aDeep,
nsAString& aResult,
const mozilla::fallible_t&)
const fallible_t& aFallible)
{
if (aNode->IsNodeOfType(nsINode::eTEXT)) {
return static_cast<nsIContent*>(aNode)->AppendTextTo(aResult,
mozilla::fallible_t());
aFallible);
}
else if (aDeep) {
return AppendNodeTextContentsRecurse(aNode, aResult, mozilla::fallible_t());
return AppendNodeTextContentsRecurse(aNode, aResult, aFallible);
}
else {
for (nsIContent* child = aNode->GetFirstChild();
child;
child = child->GetNextSibling()) {
if (child->IsNodeOfType(nsINode::eTEXT)) {
bool ok = child->AppendTextTo(aResult, mozilla::fallible_t());
bool ok = child->AppendTextTo(aResult, fallible);
if (!ok) {
return false;
}
@ -6242,7 +6242,7 @@ void nsContentUtils::RemoveNewlines(nsString &aString)
void
nsContentUtils::PlatformToDOMLineBreaks(nsString &aString)
{
if (!PlatformToDOMLineBreaks(aString, mozilla::fallible_t())) {
if (!PlatformToDOMLineBreaks(aString, fallible)) {
aString.AllocFailed(aString.Length());
}
}
@ -6962,7 +6962,7 @@ bool
nsContentUtils::GetNodeTextContent(nsINode* aNode, bool aDeep, nsAString& aResult)
{
aResult.Truncate();
return AppendNodeTextContent(aNode, aDeep, aResult, mozilla::fallible_t());
return AppendNodeTextContent(aNode, aDeep, aResult, fallible);
}
void

View File

@ -348,7 +348,7 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount)
if (uint64_t(oldLen) + aCount > UINT32_MAX)
return NS_ERROR_OUT_OF_MEMORY;
char16_t *buf = nullptr;
mResult.GetMutableData(&buf, oldLen + aCount, fallible_t());
mResult.GetMutableData(&buf, oldLen + aCount, fallible);
NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);
uint32_t bytesRead = 0;
@ -522,7 +522,7 @@ nsDOMFileReader::GetAsDataURL(nsIDOMBlob *aFile,
rv = Base64Encode(Substring(aFileData, aDataLen), encodedData);
NS_ENSURE_SUCCESS(rv, rv);
if (!AppendASCIItoUTF16(encodedData, aResult, fallible_t())) {
if (!AppendASCIItoUTF16(encodedData, aResult, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -572,7 +572,7 @@ ConvertAndWrite(const nsAString& aString,
}
nsAutoCString charXferString;
if (!charXferString.SetLength(charLength, fallible_t()))
if (!charXferString.SetLength(charLength, fallible))
return NS_ERROR_OUT_OF_MEMORY;
char* charXferBuf = charXferString.BeginWriting();

View File

@ -1074,9 +1074,10 @@ nsGenericDOMDataNode::AppendTextTo(nsAString& aResult)
}
bool
nsGenericDOMDataNode::AppendTextTo(nsAString& aResult, const mozilla::fallible_t&)
nsGenericDOMDataNode::AppendTextTo(nsAString& aResult,
const mozilla::fallible_t& aFallible)
{
return mText.AppendTo(aResult, mozilla::fallible_t());
return mText.AppendTo(aResult, aFallible);
}
already_AddRefed<nsIAtom>

View File

@ -2773,7 +2773,6 @@ nsJSArgArray::nsJSArgArray(JSContext *aContext, uint32_t argc, JS::Value *argv,
// copy the array - we don't know its lifetime, and ours is tied to xpcom
// refcounting.
if (argc) {
static const fallible_t fallible = fallible_t();
mArgv = new (fallible) JS::Heap<JS::Value>[argc];
if (!mArgv) {
*prv = NS_ERROR_OUT_OF_MEMORY;

View File

@ -161,7 +161,7 @@ AssignJSString(JSContext *cx, T &dest, JSString *s)
size_t len = js::GetStringLength(s);
static_assert(js::MaxStringLength < (1 << 28),
"Shouldn't overflow here or in SetCapacity");
if (MOZ_UNLIKELY(!dest.SetLength(len, mozilla::fallible_t()))) {
if (MOZ_UNLIKELY(!dest.SetLength(len, mozilla::fallible))) {
JS_ReportOutOfMemory(cx);
return false;
}

View File

@ -328,13 +328,13 @@ nsScriptNameSpaceManager::Init()
mIsInitialized = PL_DHashTableInit(&mGlobalNames, &hash_table_ops,
sizeof(GlobalNameMapEntry),
fallible_t(),
fallible,
GLOBALNAME_HASHTABLE_INITIAL_LENGTH);
NS_ENSURE_TRUE(mIsInitialized, NS_ERROR_OUT_OF_MEMORY);
mIsInitialized = PL_DHashTableInit(&mNavigatorNames, &hash_table_ops,
sizeof(GlobalNameMapEntry),
fallible_t(),
fallible,
GLOBALNAME_HASHTABLE_INITIAL_LENGTH);
if (!mIsInitialized) {
PL_DHashTableFinish(&mGlobalNames);

View File

@ -125,7 +125,7 @@ public:
* Append the contents of this string fragment to aString
*/
void AppendTo(nsAString& aString) const {
if (!AppendTo(aString, mozilla::fallible_t())) {
if (!AppendTo(aString, mozilla::fallible)) {
aString.AllocFailed(aString.Length() + GetLength());
}
}
@ -135,9 +135,9 @@ public:
* @return false if an out of memory condition is detected, true otherwise
*/
bool AppendTo(nsAString& aString,
const mozilla::fallible_t&) const NS_WARN_UNUSED_RESULT {
const mozilla::fallible_t& aFallible) const NS_WARN_UNUSED_RESULT {
if (mState.mIs2b) {
bool ok = aString.Append(m2b, mState.mLength, mozilla::fallible_t());
bool ok = aString.Append(m2b, mState.mLength, aFallible);
if (!ok) {
return false;
}
@ -145,7 +145,7 @@ public:
return true;
} else {
return AppendASCIItoUTF16(Substring(m1b, mState.mLength), aString,
mozilla::fallible_t());
aFallible);
}
}
@ -155,7 +155,7 @@ public:
* @param aLength the length of the substring
*/
void AppendTo(nsAString& aString, int32_t aOffset, int32_t aLength) const {
if (!AppendTo(aString, aOffset, aLength, mozilla::fallible_t())) {
if (!AppendTo(aString, aOffset, aLength, mozilla::fallible)) {
aString.AllocFailed(aString.Length() + aLength);
}
}
@ -168,10 +168,10 @@ public:
* @return false if an out of memory condition is detected, true otherwise
*/
bool AppendTo(nsAString& aString, int32_t aOffset, int32_t aLength,
const mozilla::fallible_t&) const NS_WARN_UNUSED_RESULT
const mozilla::fallible_t& aFallible) const NS_WARN_UNUSED_RESULT
{
if (mState.mIs2b) {
bool ok = aString.Append(m2b + aOffset, aLength, mozilla::fallible_t());
bool ok = aString.Append(m2b + aOffset, aLength, aFallible);
if (!ok) {
return false;
}
@ -179,7 +179,7 @@ public:
return true;
} else {
return AppendASCIItoUTF16(Substring(m1b + aOffset, aLength), aString,
mozilla::fallible_t());
aFallible);
}
}

View File

@ -670,7 +670,7 @@ nsXMLHttpRequest::AppendToResponseText(const char * aSrcBuffer,
&destBufferLen);
NS_ENSURE_SUCCESS(rv, rv);
if (!mResponseText.SetCapacity(mResponseText.Length() + destBufferLen, fallible_t())) {
if (!mResponseText.SetCapacity(mResponseText.Length() + destBufferLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -102,9 +102,7 @@ public:
DataType* AddEntry(const nsAString& aKey) NS_WARN_UNUSED_RESULT
{
// XXXbz can't just use fallible_t() because our superclass has a
// private typedef by that name.
EntryType* ent = this->PutEntry(aKey, mozilla::fallible_t());
EntryType* ent = this->PutEntry(aKey, fallible);
if (!ent) {
return nullptr;
}

View File

@ -1060,7 +1060,6 @@ WebGLContext::GetImageBuffer(uint8_t** out_imageBuffer, int32_t* out_format)
if (!dataSurface->Map(DataSourceSurface::MapType::READ, &map))
return;
static const fallible_t fallible = fallible_t();
uint8_t* imageBuffer = new (fallible) uint8_t[mWidth * mHeight * 4];
if (!imageBuffer) {
dataSurface->Unmap();

View File

@ -581,7 +581,7 @@ WebGLContext::DoFakeVertexAttrib0(GLuint vertexCount)
GetAndFlushUnderlyingGLErrors();
if (mFakeVertexAttrib0BufferStatus == WebGLVertexAttrib0Status::EmulatedInitializedArray) {
UniquePtr<GLfloat[]> array(new ((fallible_t())) GLfloat[4 * vertexCount]);
UniquePtr<GLfloat[]> array(new (fallible) GLfloat[4 * vertexCount]);
if (!array) {
ErrorOutOfMemory("Fake attrib0 array.");
return false;

View File

@ -48,7 +48,6 @@
#include "mozilla/dom/ImageData.h"
#include "mozilla/dom/ToJSValue.h"
#include "mozilla/Endian.h"
#include "mozilla/fallible.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -2086,7 +2085,7 @@ WebGLContext::ReadPixels(GLint x, GLint y, GLsizei width,
uint32_t subrect_byteLength = (subrect_height-1)*subrect_alignedRowSize + subrect_plainRowSize;
// create subrect buffer, call glReadPixels, copy pixels into destination buffer, delete subrect buffer
UniquePtr<GLubyte> subrect_data(new ((fallible_t())) GLubyte[subrect_byteLength]);
UniquePtr<GLubyte> subrect_data(new (fallible) GLubyte[subrect_byteLength]);
if (!subrect_data)
return ErrorOutOfMemory("readPixels: subrect_data");
@ -3203,7 +3202,7 @@ WebGLContext::TexImage2D_base(TexImageTarget texImageTarget, GLint level,
else
{
size_t convertedDataSize = height * dstStride;
convertedData = new ((fallible_t())) uint8_t[convertedDataSize];
convertedData = new (fallible) uint8_t[convertedDataSize];
if (!convertedData) {
ErrorOutOfMemory("texImage2D: Ran out of memory when allocating"
" a buffer for doing format conversion.");
@ -3404,7 +3403,7 @@ WebGLContext::TexSubImage2D_base(TexImageTarget texImageTarget, GLint level,
if (!noConversion) {
size_t convertedDataSize = height * dstStride;
convertedData = new ((fallible_t())) uint8_t[convertedDataSize];
convertedData = new (fallible) uint8_t[convertedDataSize];
if (!convertedData) {
ErrorOutOfMemory("texImage2D: Ran out of memory when allocating"
" a buffer for doing format conversion.");

View File

@ -63,7 +63,6 @@ TextDecoder::Decode(const char* aInput, const int32_t aLength,
}
// Need a fallible allocator because the caller may be a content
// and the content can specify the length of the string.
static const fallible_t fallible = fallible_t();
nsAutoArrayPtr<char16_t> buf(new (fallible) char16_t[outLen + 1]);
if (!buf) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);

View File

@ -53,7 +53,6 @@ TextEncoder::Encode(JSContext* aCx,
}
// Need a fallible allocator because the caller may be a content
// and the content can specify the length of the string.
static const fallible_t fallible = fallible_t();
nsAutoArrayPtr<char> buf(new (fallible) char[maxLen + 1]);
if (!buf) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);

View File

@ -470,7 +470,7 @@ ExtractFromUSVString(const nsString& aStr,
}
nsCString encoded;
if (!encoded.SetCapacity(destBufferLen, fallible_t())) {
if (!encoded.SetCapacity(destBufferLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -583,7 +583,7 @@ public:
return rv;
}
if (!mDecoded.SetCapacity(mDecoded.Length() + destBufferLen, fallible_t())) {
if (!mDecoded.SetCapacity(mDecoded.Length() + destBufferLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -26,7 +26,7 @@ MemoryOutputStream::Create(uint64_t aSize)
nsRefPtr<MemoryOutputStream> stream = new MemoryOutputStream();
char* dummy;
uint32_t length = stream->mData.GetMutableData(&dummy, aSize, fallible_t());
uint32_t length = stream->mData.GetMutableData(&dummy, aSize, fallible);
NS_ENSURE_TRUE(length == aSize, nullptr);
return stream.forget();

View File

@ -232,7 +232,6 @@ HTMLFrameSetElement::ParseRowCol(const nsAString & aValue,
commaX = spec.FindChar(sComma, commaX + 1);
}
static const fallible_t fallible = fallible_t();
nsFramesetSpec* specs = new (fallible) nsFramesetSpec[count];
if (!specs) {
*aSpecs = nullptr;

View File

@ -1873,8 +1873,6 @@ bool
nsTextEditorState::SetValue(const nsAString& aValue, bool aUserInput,
bool aSetValueChanged)
{
mozilla::fallible_t fallible;
if (mEditor && mBoundFrame) {
// The InsertText call below might flush pending notifications, which
// could lead into a scheduled PrepareEditor to be called. That will

View File

@ -146,8 +146,6 @@ const int32_t kStorageProgressGranularity = 1000;
const char kSavepointClause[] = "SAVEPOINT sp;";
const fallible_t fallible = fallible_t();
const uint32_t kFileCopyBufferSize = 32768;
const char kJournalDirectoryName[] = "journals";

View File

@ -464,7 +464,7 @@ StructuredCloneReadString(JSStructuredCloneReader* aReader,
}
length = NativeEndian::swapFromLittleEndian(length);
if (!aString.SetLength(length, fallible_t())) {
if (!aString.SetLength(length, fallible)) {
NS_WARNING("Out of memory?");
return false;
}

View File

@ -11,7 +11,6 @@
#include "MediaResource.h"
#include "mozilla/fallible.h"
#include "mozilla/Maybe.h"
#include "mozilla/Monitor.h"
@ -77,7 +76,7 @@ private:
bool Init()
{
mBuffer = new ((fallible_t())) char[mCount];
mBuffer = new (fallible) char[mCount];
return !!mBuffer;
}

View File

@ -62,9 +62,8 @@ public:
// channels or size, but it's OK since we'll deal with the failure
// gracefully.
if (mInputChannels.SetLength(mNumberOfChannels)) {
static const fallible_t fallible = fallible_t();
for (uint32_t i = 0; i < mNumberOfChannels; ++i) {
mInputChannels[i] = new(fallible) float[mLength];
mInputChannels[i] = new (fallible) float[mLength];
if (!mInputChannels[i]) {
mInputChannels.Clear();
break;

View File

@ -333,13 +333,12 @@ MediaDecodeTask::FinishDecode()
// Allocate the channel buffers. Note that if we end up resampling, we may
// write fewer bytes than mResampledFrames to the output buffer, in which
// case mWriteIndex will tell us how many valid samples we have.
static const fallible_t fallible = fallible_t();
bool memoryAllocationSuccess = true;
if (!mDecodeJob.mChannelBuffers.SetLength(channelCount)) {
memoryAllocationSuccess = false;
} else {
for (uint32_t i = 0; i < channelCount; ++i) {
mDecodeJob.mChannelBuffers[i] = new(fallible) float[resampledFrames];
mDecodeJob.mChannelBuffers[i] = new (fallible) float[resampledFrames];
if (!mDecodeJob.mChannelBuffers[i]) {
memoryAllocationSuccess = false;
break;

View File

@ -259,7 +259,7 @@ static nsresult ConvertToUTF8(nsIUnicodeDecoder *aUnicodeDecoder,
nsresult rv = aUnicodeDecoder->GetMaxLength(aString.get(), numberOfBytes,
&outUnicodeLen);
NS_ENSURE_SUCCESS(rv, rv);
if (!buffer.SetLength(outUnicodeLen, fallible_t()))
if (!buffer.SetLength(outUnicodeLen, fallible))
return NS_ERROR_OUT_OF_MEMORY;
rv = aUnicodeDecoder->Convert(aString.get(), &numberOfBytes,
buffer.BeginWriting(), &outUnicodeLen);

View File

@ -117,7 +117,7 @@ DOMStorage::SetItem(const nsAString& aKey, const nsAString& aData,
: Telemetry::SESSIONDOMSTORAGE_VALUE_SIZE_BYTES, aData.Length());
nsString data;
bool ok = data.Assign(aData, fallible_t());
bool ok = data.Assign(aData, fallible);
if (!ok) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;

View File

@ -10,7 +10,6 @@
#define _USE_MATH_DEFINES
#include <math.h>
#include "mozilla/fallible.h"
#include "mozilla/gfx/2D.h" // for StrokeOptions
#include "mozilla/gfx/Matrix.h"
#include "mozilla/RangedPtr.h"
@ -111,8 +110,7 @@ public:
mDashPattern = mSmallArray;
return mSmallArray;
}
static const mozilla::fallible_t fallible = mozilla::fallible_t();
Float* nonConstArray = new (fallible) Float[aDashCount];
Float* nonConstArray = new (mozilla::fallible) Float[aDashCount];
mDashPattern = nonConstArray;
return nonConstArray;
}

View File

@ -202,7 +202,6 @@ SVGFEConvolveMatrixElement::GetPrimitiveDescription(nsSVGFilterInstance* aInstan
if (orderX > NS_SVG_OFFSCREEN_MAX_DIMENSION ||
orderY > NS_SVG_OFFSCREEN_MAX_DIMENSION)
return failureDescription;
const fallible_t fallible = fallible_t();
nsAutoArrayPtr<float> kernel(new (fallible) float[orderX * orderY]);
if (!kernel)
return failureDescription;

View File

@ -179,7 +179,7 @@ void txDouble::toString(double aValue, nsAString& aDest)
++length;
// grow the string
uint32_t oldlength = aDest.Length();
if (!aDest.SetLength(oldlength + length, mozilla::fallible_t()))
if (!aDest.SetLength(oldlength + length, mozilla::fallible))
return; // out of memory
nsAString::iterator dest;
aDest.BeginWriting(dest).advance(int32_t(oldlength));

View File

@ -514,7 +514,7 @@ txXPathNodeUtils::appendNodeValue(const txXPathNode& aNode, nsAString& aResult)
aNode.mNode->IsElement() ||
aNode.mNode->IsNodeOfType(nsINode::eDOCUMENT_FRAGMENT)) {
nsContentUtils::AppendNodeTextContent(aNode.mNode, true, aResult,
mozilla::fallible_t());
mozilla::fallible);
return;
}

View File

@ -1198,7 +1198,7 @@ nsTextEditRules::TruncateInsertionIfNeeded(Selection* aSelection,
if (!aSelection || !aInString || !aOutString) {return NS_ERROR_NULL_POINTER;}
nsresult res = NS_OK;
if (!aOutString->Assign(*aInString, mozilla::fallible_t())) {
if (!aOutString->Assign(*aInString, mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (aTruncated) {

View File

@ -576,7 +576,7 @@ mozInlineSpellWordUtil::BuildSoftText()
DOMTextMapping(NodeOffset(node, firstOffsetInNode), mSoftText.Length(), len));
bool ok = textFragment->AppendTo(mSoftText, firstOffsetInNode, len,
mozilla::fallible_t());
mozilla::fallible);
if (!ok) {
// probably out of memory, remove from mSoftTextDOMMapping
mSoftTextDOMMapping.RemoveElementAt(mSoftTextDOMMapping.Length() - 1);

View File

@ -674,8 +674,7 @@ bool
MemoryTextureClient::Allocate(uint32_t aSize)
{
MOZ_ASSERT(!mBuffer);
static const fallible_t fallible = fallible_t();
mBuffer = new(fallible) uint8_t[aSize];
mBuffer = new (fallible) uint8_t[aSize];
if (!mBuffer) {
NS_WARNING("Failed to allocate buffer");
return false;

View File

@ -1096,7 +1096,6 @@ gfxFT2FontList::AppendFacesFromOmnijarEntry(nsZipArchive* aArchive,
uint32_t bufSize = item->RealSize();
// We use fallible allocation here; if there's not enough RAM, we'll simply
// ignore the bundled fonts and fall back to the device's installed fonts.
static const fallible_t fallible = fallible_t();
nsAutoArrayPtr<uint8_t> buf(new (fallible) uint8_t[bufSize]);
if (!buf) {
return;

View File

@ -490,7 +490,7 @@ CreateBitmapInfo(BITMAPINFOHEADER* aHeader, size_t aColorTableSize)
{
BITMAPINFO* bmi = (BITMAPINFO*) ::operator new(sizeof(BITMAPINFOHEADER) +
aColorTableSize,
mozilla::fallible_t());
mozilla::fallible);
if (bmi) {
memcpy(bmi, aHeader, sizeof(BITMAPINFOHEADER));
memset(bmi->bmiColors, 0, aColorTableSize);

View File

@ -185,7 +185,6 @@ nsBMPEncoder::AddImageFrame(const uint8_t* aData,
return NS_ERROR_INVALID_ARG;
}
static fallible_t fallible = fallible_t();
nsAutoArrayPtr<uint8_t> row(new (fallible)
uint8_t[mBMPInfoHeader.width *
BytesPerPixel(mBMPInfoHeader.bpp)]);

View File

@ -272,7 +272,6 @@ private:
, mLength(0)
{
MOZ_ASSERT(aCapacity > 0, "Creating zero-capacity chunk");
static const fallible_t fallible = fallible_t();
mData = new (fallible) char[mCapacity];
}

View File

@ -65,7 +65,7 @@ nsScriptableUnicodeConverter::ConvertFromUnicode(const nsAString& aSrc,
nsresult rv = ConvertFromUnicodeWithLength(aSrc, &len, &str);
if (NS_SUCCEEDED(rv)) {
// No Adopt on nsACString :(
if (!_retval.Assign(str, len, mozilla::fallible_t())) {
if (!_retval.Assign(str, len, mozilla::fallible)) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
moz_free(str);
@ -114,7 +114,7 @@ nsScriptableUnicodeConverter::Finish(nsACString& _retval)
nsresult rv = FinishWithLength(&str, &len);
if (NS_SUCCEEDED(rv)) {
// No Adopt on nsACString :(
if (!_retval.Assign(str, len, mozilla::fallible_t())) {
if (!_retval.Assign(str, len, mozilla::fallible)) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
moz_free(str);
@ -160,7 +160,7 @@ nsScriptableUnicodeConverter::ConvertFromByteArray(const uint8_t* aData,
if (NS_SUCCEEDED(rv))
{
buf[outLength] = 0;
if (!_retval.Assign(buf, outLength, mozilla::fallible_t())) {
if (!_retval.Assign(buf, outLength, mozilla::fallible)) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
}

View File

@ -2220,7 +2220,7 @@ void nsBidiPresUtils::CopyLogicalToVisual(const nsAString& aSource,
uint32_t srcLength = aSource.Length();
if (srcLength == 0)
return;
if (!aDest.SetLength(srcLength, fallible_t())) {
if (!aDest.SetLength(srcLength, fallible)) {
return;
}
nsAString::const_iterator fromBegin, fromEnd;

View File

@ -1009,7 +1009,6 @@ void MediaPipelineTransmit::PipelineListener::ProcessVideoChunk(
// Send a black image.
nsAutoArrayPtr<uint8_t> pixelData;
static const fallible_t fallible = fallible_t();
pixelData = new (fallible) uint8_t[length];
if (pixelData) {
// YCrCb black = 0x10 0x80 0x80

View File

@ -2,13 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_fallible_h
#define mozilla_fallible_h
#include "fallible.h"
namespace mozilla {
struct fallible_t { };
const fallible_t fallible = {};
} // namespace mozilla
#endif // mozilla_fallible_h
}

View File

@ -0,0 +1,67 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_fallible_h
#define mozilla_fallible_h
#if defined(__cplusplus)
/* Explicit fallible allocation
*
* Memory allocation (normally) defaults to abort in case of failed
* allocation. That is, it never returns NULL, and crashes instead.
*
* Code can explicitely request for fallible memory allocation thanks
* to the declarations below.
*
* The typical use of the mozilla::fallible const is with placement new,
* like the following:
*
* foo = new (mozilla::fallible) Foo();
*
* The following forms, or derivatives, are also possible but deprecated:
*
* foo = new ((mozilla::fallible_t())) Foo();
*
* const mozilla::fallible_t fallible = mozilla::fallible_t();
* bar = new (f) Bar();
*
* It is also possible to declare method overloads with fallible allocation
* alternatives, like so:
*
* class Foo {
* public:
* void Method(void *);
* void Method(void *, const mozilla::fallible_t&);
* };
*
* Foo foo;
* foo.Method(nullptr, mozilla::fallible);
*
* If that last method call is in a method that itself takes a const
* fallible_t& argument, it is recommended to propagate that argument
* instead of using mozilla::fallible:
*
* void Func(Foo &foo, const mozilla::fallible_t& aFallible) {
* foo.Method(nullptr, aFallible);
* }
*
*/
namespace mozilla {
struct fallible_t { };
/* This symbol is kept unexported, such that in corner cases where the
* compiler can't remove its use (essentially, cross compilation-unit
* calls), the smallest machine code is used.
* Depending how the linker packs symbols, it will consume between 1 and
* 8 bytes of read-only data in each executable or shared library, but
* only in those where it's actually not optimized out by the compiler.
*/
extern const fallible_t fallible;
} // namespace mozilla
#endif
#endif // mozilla_fallible_h

30
memory/fallible/moz.build Normal file
View File

@ -0,0 +1,30 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXPORTS.mozilla += [
'fallible.h',
]
Library('fallible')
SOURCES += [
'fallible.cpp',
]
if CONFIG['_MSC_VER']:
# MSVC normally adds linker directives relative to the CRT in a .drectve
# section in .obj files. Then, when linking objects, it adds those
# directives as if they were given as command line arguments. This can
# lead to trying to include link CRTs because different objects are
# compiled with different CRT options (i.e. -MT vs. -MD), and failing.
# The only source in this directory doesn't expose anything that depends
# on a CRT, so it doesn't need to be bound to a specific one.
# Adding the -Zl option makes MSVC not store linker directives in the
# object. This allows to link fallible.obj to binaries independently of
# the CRT they use.
CXXFLAGS += [
'-Zl',
]

View File

@ -6,7 +6,6 @@
NO_VISIBILITY_FLAGS = True
EXPORTS.mozilla += [
'fallible.h',
'mozalloc.h',
'mozalloc_abort.h',
'mozalloc_oom.h',

View File

@ -1157,7 +1157,7 @@ nsZipItemPtr_base::nsZipItemPtr_base(nsZipArchive *aZip, const char * aEntryName
uint32_t size = 0;
if (item->Compression() == DEFLATED) {
size = item->RealSize();
mAutoBuf = new ((fallible_t())) uint8_t[size];
mAutoBuf = new (fallible) uint8_t[size];
if (!mAutoBuf) {
return;
}

View File

@ -330,7 +330,7 @@ NS_IMETHODIMP nsPrefBranch::GetComplexValue(const char *aPrefName, const nsIID &
// Debugging to see why we end up with very long strings here with
// some addons, see bug 836263.
nsAutoString wdata;
if (!AppendUTF8toUTF16(utf8String, wdata, mozilla::fallible_t())) {
if (!AppendUTF8toUTF16(utf8String, wdata, mozilla::fallible)) {
#ifdef MOZ_CRASHREPORTER
nsCOMPtr<nsICrashReporter> cr =
do_GetService("@mozilla.org/toolkit/crash-reporter;1");

View File

@ -147,7 +147,7 @@ nsresult PREF_Init()
{
if (!gHashTable.IsInitialized()) {
if (!PL_DHashTableInit(&gHashTable, &pref_HashTableOps,
sizeof(PrefHashEntry), fallible_t(),
sizeof(PrefHashEntry), fallible,
PREF_HASHTABLE_INITIAL_LENGTH)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -43,6 +43,7 @@ if not CONFIG['LIBXUL_SDK']:
DIRS += [
'mozglue',
'memory/fallible',
'memory/mozalloc',
'memory/volatile',
]

View File

@ -71,8 +71,7 @@ nsBufferedStream::Init(nsISupports* stream, uint32_t bufferSize)
mBufferSize = bufferSize;
mBufferStartOffset = 0;
mCursor = 0;
const mozilla::fallible_t fallible = mozilla::fallible_t();
mBuffer = new (fallible) char[bufferSize];
mBuffer = new (mozilla::fallible) char[bufferSize];
if (mBuffer == nullptr)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;

View File

@ -1546,7 +1546,7 @@ NS_ReadInputStreamToString(nsIInputStream *aInputStream,
nsACString &aDest,
uint32_t aCount)
{
if (!aDest.SetLength(aCount, mozilla::fallible_t()))
if (!aDest.SetLength(aCount, mozilla::fallible))
return NS_ERROR_OUT_OF_MEMORY;
void* dest = aDest.BeginWriting();
return NS_ReadInputStreamToBuffer(aInputStream, &dest, aCount);

View File

@ -588,7 +588,7 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
// generate the normalized URL string
//
// approxLen should be correct or 1 high
if (!mSpec.SetLength(approxLen+1, mozilla::fallible_t())) // buf needs a trailing '\0' below
if (!mSpec.SetLength(approxLen+1, mozilla::fallible)) // buf needs a trailing '\0' below
return NS_ERROR_OUT_OF_MEMORY;
char *buf;
mSpec.BeginWriting(buf);

View File

@ -26,7 +26,7 @@ nsUnicharStreamLoader::Init(nsIUnicharStreamLoaderObserver *aObserver)
mObserver = aObserver;
if (!mRawData.SetCapacity(SNIFFING_BUFFER_SIZE, fallible_t()))
if (!mRawData.SetCapacity(SNIFFING_BUFFER_SIZE, fallible))
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
@ -214,7 +214,7 @@ nsUnicharStreamLoader::WriteSegmentFun(nsIInputStream *,
self->mDecoder->GetMaxLength(aSegment, srcLen, &dstLen);
uint32_t capacity = haveRead + dstLen;
if (!self->mBuffer.SetCapacity(capacity, fallible_t())) {
if (!self->mBuffer.SetCapacity(capacity, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -405,7 +405,7 @@ nsCacheEntryHashTable::Init()
nsresult rv = NS_OK;
initialized = PL_DHashTableInit(&table, &ops,
sizeof(nsCacheEntryHashTableEntry),
fallible_t(), 256);
fallible, 256);
if (!initialized) rv = NS_ERROR_OUT_OF_MEMORY;

View File

@ -966,7 +966,7 @@ nsOfflineCacheDevice::UpdateEntry(nsCacheEntry *entry)
nsCString metaDataBuf;
uint32_t mdSize = entry->MetaDataSize();
if (!metaDataBuf.SetLength(mdSize, fallible_t()))
if (!metaDataBuf.SetLength(mdSize, fallible))
return NS_ERROR_OUT_OF_MEMORY;
char *md = metaDataBuf.BeginWriting();
entry->FlattenMetaData(md, mdSize);

View File

@ -106,7 +106,7 @@ nsHttp::CreateAtomTable()
// known atoms (NUM_HTTP_ATOMS) because we expect to encounter a few random
// headers right off the bat.
if (!PL_DHashTableInit(&sAtomTable, &ops, sizeof(PLDHashEntryStub),
fallible_t(), NUM_HTTP_ATOMS + 10)) {
fallible, NUM_HTTP_ATOMS + 10)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -1609,7 +1609,7 @@ WebSocketChannel::ProcessInput(uint8_t *buffer, uint32_t count)
utf8Data.Length()));
} else {
if (!utf8Data.Assign((const char *)payload, payloadLength,
mozilla::fallible_t())) {
mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
@ -1719,7 +1719,7 @@ WebSocketChannel::ProcessInput(uint8_t *buffer, uint32_t count)
binaryData.Length()));
} else {
if (!binaryData.Assign((const char *)payload, payloadLength,
mozilla::fallible_t())) {
mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}

View File

@ -333,7 +333,7 @@ nsDirIndexParser::OnDataAvailable(nsIRequest *aRequest, nsISupports *aCtxt,
// Ensure that our mBuf has capacity to hold the data we're about to
// read.
if (!mBuf.SetLength(len + aCount, fallible_t()))
if (!mBuf.SetLength(len + aCount, fallible))
return NS_ERROR_OUT_OF_MEMORY;
// Now read the data into our buffer.

View File

@ -39,13 +39,12 @@ nsHtml5OwningUTF16Buffer::~nsHtml5OwningUTF16Buffer()
already_AddRefed<nsHtml5OwningUTF16Buffer>
nsHtml5OwningUTF16Buffer::FalliblyCreate(int32_t aLength)
{
const mozilla::fallible_t fallible = mozilla::fallible_t();
char16_t* newBuf = new (fallible) char16_t[aLength];
char16_t* newBuf = new (mozilla::fallible) char16_t[aLength];
if (!newBuf) {
return nullptr;
}
nsRefPtr<nsHtml5OwningUTF16Buffer> newObj =
new (fallible) nsHtml5OwningUTF16Buffer(newBuf);
new (mozilla::fallible) nsHtml5OwningUTF16Buffer(newBuf);
if (!newObj) {
delete[] newBuf;
return nullptr;

View File

@ -771,8 +771,7 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
}
if (!mSniffingBuffer) {
const mozilla::fallible_t fallible = mozilla::fallible_t();
mSniffingBuffer = new (fallible)
mSniffingBuffer = new (mozilla::fallible)
uint8_t[NS_HTML5_STREAM_PARSER_SNIFFING_BUFFER_SIZE];
if (!mSniffingBuffer) {
return NS_ERROR_OUT_OF_MEMORY;
@ -1146,8 +1145,7 @@ nsHtml5StreamParser::OnDataAvailable(nsIRequest* aRequest,
uint32_t totalRead;
// Main thread to parser thread dispatch requires copying to buffer first.
if (NS_IsMainThread()) {
const mozilla::fallible_t fallible = mozilla::fallible_t();
nsAutoArrayPtr<uint8_t> data(new (fallible) uint8_t[aLength]);
nsAutoArrayPtr<uint8_t> data(new (mozilla::fallible) uint8_t[aLength]);
if (!data) {
return mExecutor->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY);
}

View File

@ -85,12 +85,12 @@ nsHTMLEntities::AddRefTable(void)
if (!gTableRefCnt) {
if (!PL_DHashTableInit(&gEntityToUnicode, &EntityToUnicodeOps,
sizeof(EntityNodeEntry),
fallible_t(), NS_HTML_ENTITY_COUNT)) {
fallible, NS_HTML_ENTITY_COUNT)) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (!PL_DHashTableInit(&gUnicodeToEntity, &UnicodeToEntityOps,
sizeof(EntityNodeEntry),
fallible_t(), NS_HTML_ENTITY_COUNT)) {
fallible, NS_HTML_ENTITY_COUNT)) {
PL_DHashTableFinish(&gEntityToUnicode);
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -472,7 +472,7 @@ CopyUnicodeTo( const nsScannerIterator& aSrcStart,
nsAString& aDest )
{
nsAString::iterator writer;
if (!aDest.SetLength(Distance(aSrcStart, aSrcEnd), mozilla::fallible_t())) {
if (!aDest.SetLength(Distance(aSrcStart, aSrcEnd), mozilla::fallible)) {
aDest.Truncate();
return; // out of memory
}
@ -505,7 +505,7 @@ AppendUnicodeTo( const nsScannerIterator& aSrcStart,
{
nsAString::iterator writer;
uint32_t oldLength = aDest.Length();
if (!aDest.SetLength(oldLength + Distance(aSrcStart, aSrcEnd), mozilla::fallible_t()))
if (!aDest.SetLength(oldLength + Distance(aSrcStart, aSrcEnd), mozilla::fallible))
return; // out of memory
aDest.BeginWriting(writer).advance(oldLength);
nsScannerIterator fromBegin(aSrcStart);

View File

@ -182,7 +182,7 @@ nsresult nsCertTree::InitCompareHash()
{
ClearCompareHash();
if (!PL_DHashTableInit(&mCompareCache, &gMapOps,
sizeof(CompareCacheHashEntryPtr), fallible_t(), 64)) {
sizeof(CompareCacheHashEntryPtr), fallible, 64)) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;

View File

@ -16,7 +16,7 @@
#include <base64.h>
#include <nsString.h>
using mozilla::fallible_t;
using mozilla::fallible;
static bool
hex_from_2char(const unsigned char *c2, unsigned char *byteval)
@ -73,7 +73,7 @@ static bool
toHexString(const unsigned char * str, unsigned len, nsACString & out)
{
static const char digits[] = "0123456789ABCDEF";
if (!out.SetCapacity(2 * len, fallible_t()))
if (!out.SetCapacity(2 * len, fallible))
return false;
out.SetLength(0);
for (unsigned i = 0; i < len; ++i) {
@ -301,7 +301,7 @@ setBase64(const unsigned char * data, unsigned len, nsACString & out)
if (base64 != nullptr) {
size_t len = PORT_Strlen(base64);
if (out.SetCapacity(len, fallible_t())) {
if (out.SetCapacity(len, fallible)) {
out.SetLength(0);
out.Append(base64, len);
PORT_Free((void*) base64);

View File

@ -61,7 +61,7 @@ Base64urlEncode(const uint8_t* aBytes,
// result, we set the capacity to be one greater than what we need, and the
// length to our desired length.
uint32_t length = (aNumBytes + 2) / 3 * 4; // +2 due to integer math.
NS_ENSURE_TRUE(_result.SetCapacity(length + 1, mozilla::fallible_t()),
NS_ENSURE_TRUE(_result.SetCapacity(length + 1, mozilla::fallible),
NS_ERROR_OUT_OF_MEMORY);
_result.SetLength(length);
(void)PL_Base64Encode(reinterpret_cast<const char*>(aBytes), aNumBytes,

View File

@ -212,7 +212,7 @@ Base64urlEncode(const uint8_t* aBytes,
// result, we set the capacity to be one greater than what we need, and the
// length to our desired length.
uint32_t length = (aNumBytes + 2) / 3 * 4; // +2 due to integer math.
NS_ENSURE_TRUE(_result.SetCapacity(length + 1, fallible_t()),
NS_ENSURE_TRUE(_result.SetCapacity(length + 1, fallible),
NS_ERROR_OUT_OF_MEMORY);
_result.SetLength(length);
(void)PL_Base64Encode(reinterpret_cast<const char*>(aBytes), aNumBytes,

View File

@ -1793,7 +1793,7 @@ TelemetryImpl::NewKeyedHistogram(const nsACString &name, const nsACString &expir
KeyedHistogram* keyed = new KeyedHistogram(name, expiration, histogramType,
min, max, bucketCount);
if (MOZ_UNLIKELY(!mKeyedHistograms.Put(name, keyed, fallible_t()))) {
if (MOZ_UNLIKELY(!mKeyedHistograms.Put(name, keyed, fallible))) {
delete keyed;
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -1689,7 +1689,7 @@ nsIMM32Handler::GetCompositionString(const nsIMEContext &aIMEContext,
long lRtn = ::ImmGetCompositionStringW(aIMEContext.get(), aIndex, nullptr, 0);
if (lRtn < 0 ||
!aCompositionString.SetLength((lRtn / sizeof(WCHAR)) + 1,
mozilla::fallible_t())) {
mozilla::fallible)) {
PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
("IMM32: GetCompositionString, FAILED by OOM\n"));
return; // Error or out of memory.
@ -1756,7 +1756,7 @@ nsIMM32Handler::ConvertToANSIString(const nsAFlatString& aStr, UINT aCodePage,
nullptr, 0, nullptr, nullptr);
NS_ENSURE_TRUE(len >= 0, false);
if (!aANSIStr.SetLength(len, mozilla::fallible_t())) {
if (!aANSIStr.SetLength(len, mozilla::fallible)) {
PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
("IMM32: ConvertToANSIString, FAILED by OOM\n"));
return false;

View File

@ -1357,7 +1357,7 @@ private:
if (!aPi) {
MOZ_CRASH();
}
if (!aQueue.Push(aPi, fallible_t())) {
if (!aQueue.Push(aPi, fallible)) {
mVisitor.Failed();
}
}

View File

@ -139,7 +139,7 @@ nsStaticCaseInsensitiveNameTable::Init(const char* const aNames[],
}
if (!PL_DHashTableInit(&mNameTable, &nametable_CaseInsensitiveHashTableOps,
sizeof(NameTableEntry), fallible_t(),
sizeof(NameTableEntry), fallible,
aLength)) {
return false;
}

View File

@ -7,8 +7,6 @@
#include "nsMemory.h"
#include "prprf.h"
using mozilla::fallible_t;
/***************************************************************************/
NS_IMPL_ISUPPORTS(nsSupportsIDImpl, nsISupportsID, nsISupportsPrimitive)
@ -107,7 +105,7 @@ nsSupportsCStringImpl::ToString(char** aResult)
NS_IMETHODIMP
nsSupportsCStringImpl::SetData(const nsACString& aData)
{
bool ok = mData.Assign(aData, fallible_t());
bool ok = mData.Assign(aData, mozilla::fallible);
if (!ok) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -152,7 +150,7 @@ nsSupportsStringImpl::ToString(char16_t** aResult)
NS_IMETHODIMP
nsSupportsStringImpl::SetData(const nsAString& aData)
{
bool ok = mData.Assign(aData, fallible_t());
bool ok = mData.Assign(aData, mozilla::fallible);
if (!ok) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -114,3 +114,8 @@ if CONFIG['ENABLE_TESTS']:
DIRS += ['tests/gtest']
FAIL_ON_WARNINGS = True
# Include fallible for third party code using the xpcom glue
USE_LIBS += [
'fallible',
]

View File

@ -42,3 +42,8 @@ USE_STATIC_LIBS = True
DISABLE_STL_WRAPPING = True
FAIL_ON_WARNINGS = True
# Include fallible for third party code using the xpcom glue
USE_LIBS += [
'fallible',
]

View File

@ -123,7 +123,7 @@ public:
*/
void Put(KeyType aKey, const UserDataType& aData)
{
if (!Put(aKey, aData, fallible_t())) {
if (!Put(aKey, aData, mozilla::fallible)) {
NS_ABORT_OOM(this->mTable.EntrySize() * this->mTable.EntryCount());
}
}

View File

@ -84,7 +84,7 @@ public:
*/
void Push(void* aItem)
{
if (!Push(aItem, fallible_t())) {
if (!Push(aItem, mozilla::fallible)) {
NS_ABORT_OOM(mSize * sizeof(void*));
}
}
@ -98,7 +98,7 @@ public:
*/
void PushFront(void* aItem)
{
if (!PushFront(aItem, fallible_t())) {
if (!PushFront(aItem, mozilla::fallible)) {
NS_ABORT_OOM(mSize * sizeof(void*));
}
}

View File

@ -147,7 +147,7 @@ void
nsRefPtrHashtable<KeyClass, RefPtr>::Put(KeyType aKey,
already_AddRefed<RefPtr> aData)
{
if (!Put(aKey, mozilla::Move(aData), mozilla::fallible_t())) {
if (!Put(aKey, mozilla::Move(aData), mozilla::fallible)) {
NS_ABORT_OOM(this->mTable.EntrySize() * this->mTable.EntryCount());
}
}

View File

@ -149,7 +149,7 @@ public:
*/
EntryType* PutEntry(KeyType aKey)
{
EntryType* e = PutEntry(aKey, fallible_t());
EntryType* e = PutEntry(aKey, mozilla::fallible);
if (!e) {
NS_ABORT_OOM(mTable.EntrySize() * mTable.EntryCount());
}

View File

@ -176,7 +176,7 @@ PL_NewDHashTable(const PLDHashTableOps* aOps, uint32_t aEntrySize,
if (!table) {
return nullptr;
}
if (!PL_DHashTableInit(table, aOps, aEntrySize, fallible_t(), aLength)) {
if (!PL_DHashTableInit(table, aOps, aEntrySize, fallible, aLength)) {
free(table);
return nullptr;
}
@ -276,7 +276,7 @@ void
PL_DHashTableInit(PLDHashTable* aTable, const PLDHashTableOps* aOps,
uint32_t aEntrySize, uint32_t aLength)
{
if (!PL_DHashTableInit(aTable, aOps, aEntrySize, fallible_t(), aLength)) {
if (!PL_DHashTableInit(aTable, aOps, aEntrySize, fallible, aLength)) {
if (aLength > PL_DHASH_MAX_INITIAL_LENGTH) {
MOZ_CRASH(); // the asked-for length was too big
}

View File

@ -44,3 +44,8 @@ LOCAL_INCLUDES += [
DISABLE_STL_WRAPPING = True
FAIL_ON_WARNINGS = True
# Include fallible for third party code using the xpcom glue
USE_LIBS += [
'fallible',
]

View File

@ -39,3 +39,8 @@ USE_STATIC_LIBS = True
DISABLE_STL_WRAPPING = True
FAIL_ON_WARNINGS = True
# Include fallible for third party code using the xpcom glue
USE_LIBS += [
'fallible',
]

View File

@ -37,3 +37,8 @@ USE_STATIC_LIBS = True
DISABLE_STL_WRAPPING = True
FAIL_ON_WARNINGS = True
# Include fallible for third party code using the xpcom glue
USE_LIBS += [
'fallible',
]

View File

@ -267,7 +267,7 @@ Base64Encode(const nsACString& aBinaryData, nsACString& aString)
char* buffer;
// Add one byte for null termination.
if (aString.SetCapacity(stringLen + 1, fallible_t()) &&
if (aString.SetCapacity(stringLen + 1, fallible) &&
(buffer = aString.BeginWriting()) &&
PL_Base64Encode(aBinaryData.BeginReading(), aBinaryData.Length(), buffer)) {
// PL_Base64Encode doesn't null terminate the buffer for us when we pass
@ -317,7 +317,7 @@ Base64Decode(const nsACString& aString, nsACString& aBinaryData)
char* buffer;
// Add one byte for null termination.
if (aBinaryData.SetCapacity(binaryDataLen + 1, fallible_t()) &&
if (aBinaryData.SetCapacity(binaryDataLen + 1, fallible) &&
(buffer = aBinaryData.BeginWriting()) &&
PL_Base64Decode(aString.BeginReading(), aString.Length(), buffer)) {
// PL_Base64Decode doesn't null terminate the buffer for us when we pass

View File

@ -107,7 +107,7 @@ SnappyCompressOutputStream::WriteSegments(nsReadSegmentFun aReader,
}
if (!mBuffer) {
mBuffer.reset(new ((fallible_t())) char[mBlockSize]);
mBuffer.reset(new (fallible) char[mBlockSize]);
if (NS_WARN_IF(!mBuffer)) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -174,7 +174,7 @@ SnappyCompressOutputStream::FlushToBaseStream()
// will then get re-used until the stream is closed.
if (!mCompressedBuffer) {
mCompressedBufferLength = MaxCompressedBufferLength(mBlockSize);
mCompressedBuffer.reset(new ((fallible_t())) char[mCompressedBufferLength]);
mCompressedBuffer.reset(new (fallible) char[mCompressedBufferLength]);
if (NS_WARN_IF(!mCompressedBuffer)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -188,14 +188,14 @@ SnappyUncompressInputStream::ParseNextChunk(uint32_t* aBytesReadOut)
// operation. These allocations only happens once. The buffers are reused
// until the stream is closed.
if (!mUncompressedBuffer) {
mUncompressedBuffer.reset(new ((fallible_t())) char[snappy::kBlockSize]);
mUncompressedBuffer.reset(new (fallible) char[snappy::kBlockSize]);
if (NS_WARN_IF(!mUncompressedBuffer)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
if (!mCompressedBuffer) {
mCompressedBuffer.reset(new ((fallible_t())) char[kCompressedBufferLength]);
mCompressedBuffer.reset(new (fallible) char[kCompressedBufferLength]);
if (NS_WARN_IF(!mCompressedBuffer)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -765,7 +765,7 @@ nsBinaryInputStream::ReadString(nsAString& aString)
}
// pre-allocate output buffer, and get direct access to buffer...
if (!aString.SetLength(length, mozilla::fallible_t())) {
if (!aString.SetLength(length, mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -3654,7 +3654,7 @@ nsDriveEnumerator::Init()
* the length required for the string. */
DWORD length = GetLogicalDriveStringsW(0, 0);
/* The string is null terminated */
if (!mDrives.SetLength(length + 1, fallible_t())) {
if (!mDrives.SetLength(length + 1, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (!GetLogicalDriveStringsW(length, wwc(mDrives.BeginWriting()))) {

View File

@ -814,7 +814,7 @@ NS_CopyNativeToUnicode(const nsACString& aInput, nsAString& aOutput)
// this will generally result in a larger allocation, but that seems
// better than an extra buffer copy.
//
if (!aOutput.SetLength(inputLen, fallible_t())) {
if (!aOutput.SetLength(inputLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsAString::iterator out_iter;
@ -925,7 +925,7 @@ NS_CopyNativeToUnicode(const nsACString& aInput, nsAString& aOutput)
}
// allocate sufficient space
if (!aOutput.SetLength(resultLen, fallible_t())) {
if (!aOutput.SetLength(resultLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (resultLen > 0) {
@ -959,7 +959,7 @@ NS_CopyUnicodeToNative(const nsAString& aInput, nsACString& aOutput)
}
// allocate sufficient space
if (!aOutput.SetLength(resultLen, fallible_t())) {
if (!aOutput.SetLength(resultLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
if (resultLen > 0) {

View File

@ -14,8 +14,6 @@
#include <string.h>
#include <stdarg.h>
#include "mozilla/fallible.h"
#define kNotFound -1
// declare nsAString

View File

@ -46,7 +46,7 @@ CopyASCIItoUTF16(const char* aSource, nsAString& aDest)
void
CopyUTF16toUTF8(const nsAString& aSource, nsACString& aDest)
{
if (!CopyUTF16toUTF8(aSource, aDest, mozilla::fallible_t())) {
if (!CopyUTF16toUTF8(aSource, aDest, mozilla::fallible)) {
// Note that this may wildly underestimate the allocation that failed, as
// we report the length of aSource as UTF-16 instead of UTF-8.
aDest.AllocFailed(aDest.Length() + aSource.Length());
@ -55,10 +55,10 @@ CopyUTF16toUTF8(const nsAString& aSource, nsACString& aDest)
bool
CopyUTF16toUTF8(const nsAString& aSource, nsACString& aDest,
const mozilla::fallible_t&)
const mozilla::fallible_t& aFallible)
{
aDest.Truncate();
if (!AppendUTF16toUTF8(aSource, aDest, mozilla::fallible_t())) {
if (!AppendUTF16toUTF8(aSource, aDest, aFallible)) {
return false;
}
return true;
@ -108,18 +108,18 @@ LossyAppendUTF16toASCII(const nsAString& aSource, nsACString& aDest)
void
AppendASCIItoUTF16(const nsACString& aSource, nsAString& aDest)
{
if (!AppendASCIItoUTF16(aSource, aDest, mozilla::fallible_t())) {
if (!AppendASCIItoUTF16(aSource, aDest, mozilla::fallible)) {
aDest.AllocFailed(aDest.Length() + aSource.Length());
}
}
bool
AppendASCIItoUTF16(const nsACString& aSource, nsAString& aDest,
const mozilla::fallible_t&)
const mozilla::fallible_t& aFallible)
{
uint32_t old_dest_length = aDest.Length();
if (!aDest.SetLength(old_dest_length + aSource.Length(),
mozilla::fallible_t())) {
aFallible)) {
return false;
}
@ -157,7 +157,7 @@ AppendASCIItoUTF16(const char* aSource, nsAString& aDest)
void
AppendUTF16toUTF8(const nsAString& aSource, nsACString& aDest)
{
if (!AppendUTF16toUTF8(aSource, aDest, mozilla::fallible_t())) {
if (!AppendUTF16toUTF8(aSource, aDest, mozilla::fallible)) {
// Note that this may wildly underestimate the allocation that failed, as
// we report the length of aSource as UTF-16 instead of UTF-8.
aDest.AllocFailed(aDest.Length() + aSource.Length());
@ -166,7 +166,7 @@ AppendUTF16toUTF8(const nsAString& aSource, nsACString& aDest)
bool
AppendUTF16toUTF8(const nsAString& aSource, nsACString& aDest,
const mozilla::fallible_t&)
const mozilla::fallible_t& aFallible)
{
nsAString::const_iterator source_start, source_end;
CalculateUTF8Size calculator;
@ -179,7 +179,7 @@ AppendUTF16toUTF8(const nsAString& aSource, nsACString& aDest,
uint32_t old_dest_length = aDest.Length();
// Grow the buffer if we need to.
if (!aDest.SetLength(old_dest_length + count, mozilla::fallible_t())) {
if (!aDest.SetLength(old_dest_length + count, aFallible)) {
return false;
}
@ -200,14 +200,14 @@ AppendUTF16toUTF8(const nsAString& aSource, nsACString& aDest,
void
AppendUTF8toUTF16(const nsACString& aSource, nsAString& aDest)
{
if (!AppendUTF8toUTF16(aSource, aDest, mozilla::fallible_t())) {
if (!AppendUTF8toUTF16(aSource, aDest, mozilla::fallible)) {
aDest.AllocFailed(aDest.Length() + aSource.Length());
}
}
bool
AppendUTF8toUTF16(const nsACString& aSource, nsAString& aDest,
const mozilla::fallible_t&)
const mozilla::fallible_t& aFallible)
{
nsACString::const_iterator source_start, source_end;
CalculateUTF8Length calculator;
@ -221,7 +221,7 @@ AppendUTF8toUTF16(const nsACString& aSource, nsAString& aDest,
uint32_t old_dest_length = aDest.Length();
// Grow the buffer if we need to.
if (!aDest.SetLength(old_dest_length + count, mozilla::fallible_t())) {
if (!aDest.SetLength(old_dest_length + count, aFallible)) {
return false;
}

View File

@ -464,18 +464,18 @@ nsTString_CharT::ReplaceSubstring(const char_type* aTarget,
bool
nsTString_CharT::ReplaceSubstring(const char_type* aTarget,
const char_type* aNewValue,
const fallible_t& fallible)
const fallible_t& aFallible)
{
return ReplaceSubstring(nsTDependentString_CharT(aTarget),
nsTDependentString_CharT(aNewValue),
fallible);
aFallible);
}
void
nsTString_CharT::ReplaceSubstring(const self_type& aTarget,
const self_type& aNewValue)
{
if (!ReplaceSubstring(aTarget, aNewValue, fallible_t())) {
if (!ReplaceSubstring(aTarget, aNewValue, mozilla::fallible)) {
// Note that this may wildly underestimate the allocation that failed, as
// we could have been replacing multiple copies of aTarget.
AllocFailed(mLength + (aNewValue.Length() - aTarget.Length()));

View File

@ -253,7 +253,7 @@ nsTSubstring_CharT::EnsureMutable(size_type aNewLen)
aNewLen = mLength;
}
return SetLength(aNewLen, fallible_t());
return SetLength(aNewLen, mozilla::fallible);
}
// ---------------------------------------------------------------------------
@ -283,7 +283,7 @@ nsTSubstring_CharT::Assign(char_type aChar, const fallible_t&)
void
nsTSubstring_CharT::Assign(const char_type* aData)
{
if (!Assign(aData, size_type(-1), fallible_t())) {
if (!Assign(aData, size_type(-1), mozilla::fallible)) {
AllocFailed(char_traits::length(aData));
}
}
@ -291,7 +291,7 @@ nsTSubstring_CharT::Assign(const char_type* aData)
void
nsTSubstring_CharT::Assign(const char_type* aData, size_type aLength)
{
if (!Assign(aData, aLength, fallible_t())) {
if (!Assign(aData, aLength, mozilla::fallible)) {
AllocFailed(aLength == size_type(-1) ? char_traits::length(aData)
: aLength);
}
@ -299,7 +299,7 @@ nsTSubstring_CharT::Assign(const char_type* aData, size_type aLength)
bool
nsTSubstring_CharT::Assign(const char_type* aData, size_type aLength,
const fallible_t&)
const fallible_t& aFallible)
{
if (!aData || aLength == 0) {
Truncate();
@ -311,7 +311,7 @@ nsTSubstring_CharT::Assign(const char_type* aData, size_type aLength,
}
if (IsDependentOn(aData, aData + aLength)) {
return Assign(string_type(aData, aLength), fallible_t());
return Assign(string_type(aData, aLength), aFallible);
}
if (!ReplacePrep(0, mLength, aLength)) {
@ -325,20 +325,20 @@ nsTSubstring_CharT::Assign(const char_type* aData, size_type aLength,
void
nsTSubstring_CharT::AssignASCII(const char* aData, size_type aLength)
{
if (!AssignASCII(aData, aLength, fallible_t())) {
if (!AssignASCII(aData, aLength, mozilla::fallible)) {
AllocFailed(aLength);
}
}
bool
nsTSubstring_CharT::AssignASCII(const char* aData, size_type aLength,
const fallible_t&)
const fallible_t& aFallible)
{
// A Unicode string can't depend on an ASCII string buffer,
// so this dependence check only applies to CStrings.
#ifdef CharT_is_char
if (IsDependentOn(aData, aData + aLength)) {
return Assign(string_type(aData, aLength), fallible_t());
return Assign(string_type(aData, aLength), aFallible);
}
#endif
@ -362,13 +362,13 @@ nsTSubstring_CharT::AssignLiteral(const char_type* aData, size_type aLength)
void
nsTSubstring_CharT::Assign(const self_type& aStr)
{
if (!Assign(aStr, fallible_t())) {
if (!Assign(aStr, mozilla::fallible)) {
AllocFailed(aStr.Length());
}
}
bool
nsTSubstring_CharT::Assign(const self_type& aStr, const fallible_t&)
nsTSubstring_CharT::Assign(const self_type& aStr, const fallible_t& aFallible)
{
// |aStr| could be sharable. We need to check its flags to know how to
// deal with it.
@ -406,24 +406,24 @@ nsTSubstring_CharT::Assign(const self_type& aStr, const fallible_t&)
}
// else, treat this like an ordinary assignment.
return Assign(aStr.Data(), aStr.Length(), fallible_t());
return Assign(aStr.Data(), aStr.Length(), aFallible);
}
void
nsTSubstring_CharT::Assign(const substring_tuple_type& aTuple)
{
if (!Assign(aTuple, fallible_t())) {
if (!Assign(aTuple, mozilla::fallible)) {
AllocFailed(aTuple.Length());
}
}
bool
nsTSubstring_CharT::Assign(const substring_tuple_type& aTuple,
const fallible_t&)
const fallible_t& aFallible)
{
if (aTuple.IsDependentOn(mData, mData + mLength)) {
// take advantage of sharing here...
return Assign(string_type(aTuple), fallible_t());
return Assign(string_type(aTuple), aFallible);
}
size_type length = aTuple.Length();
@ -486,7 +486,7 @@ nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
bool
nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
char_type aChar,
const mozilla::fallible_t&)
const fallible_t&)
{
aCutStart = XPCOM_MIN(aCutStart, Length());
@ -504,7 +504,7 @@ nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
const char_type* aData, size_type aLength)
{
if (!Replace(aCutStart, aCutLength, aData, aLength,
mozilla::fallible_t())) {
mozilla::fallible)) {
AllocFailed(Length() - aCutLength + 1);
}
}
@ -512,7 +512,7 @@ nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
bool
nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
const char_type* aData, size_type aLength,
const mozilla::fallible_t&)
const fallible_t& aFallible)
{
// unfortunately, some callers pass null :-(
if (!aData) {
@ -524,7 +524,7 @@ nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
if (IsDependentOn(aData, aData + aLength)) {
nsTAutoString_CharT temp(aData, aLength);
return Replace(aCutStart, aCutLength, temp, mozilla::fallible_t());
return Replace(aCutStart, aCutLength, temp, aFallible);
}
}
@ -602,7 +602,7 @@ nsTSubstring_CharT::ReplaceLiteral(index_type aCutStart, size_type aCutLength,
void
nsTSubstring_CharT::SetCapacity(size_type aCapacity)
{
if (!SetCapacity(aCapacity, fallible_t())) {
if (!SetCapacity(aCapacity, mozilla::fallible)) {
AllocFailed(aCapacity);
}
}
@ -659,9 +659,9 @@ nsTSubstring_CharT::SetLength(size_type aLength)
}
bool
nsTSubstring_CharT::SetLength(size_type aLength, const fallible_t&)
nsTSubstring_CharT::SetLength(size_type aLength, const fallible_t& aFallible)
{
if (!SetCapacity(aLength, fallible_t())) {
if (!SetCapacity(aLength, aFallible)) {
return false;
}

View File

@ -176,9 +176,9 @@ public:
return aIter = BeginWriting();
}
char_iterator& BeginWriting(char_iterator& aIter, const fallible_t&)
char_iterator& BeginWriting(char_iterator& aIter, const fallible_t& aFallible)
{
return aIter = BeginWriting(fallible_t());
return aIter = BeginWriting(aFallible);
}
char_iterator& EndWriting(char_iterator& aIter)
@ -186,9 +186,9 @@ public:
return aIter = EndWriting();
}
char_iterator& EndWriting(char_iterator& aIter, const fallible_t&)
char_iterator& EndWriting(char_iterator& aIter, const fallible_t& aFallible)
{
return aIter = EndWriting(fallible_t());
return aIter = EndWriting(aFallible);
}
/**
@ -380,9 +380,10 @@ public:
Assign(static_cast<const char16_t*>(aData));
}
NS_WARN_UNUSED_RESULT bool Assign(char16ptr_t aData, const fallible_t&)
NS_WARN_UNUSED_RESULT bool Assign(char16ptr_t aData,
const fallible_t& aFallible)
{
return Assign(static_cast<const char16_t*>(aData), fallible_t());
return Assign(static_cast<const char16_t*>(aData), aFallible);
}
void Assign(char16ptr_t aData, size_type aLength)
@ -391,9 +392,10 @@ public:
}
NS_WARN_UNUSED_RESULT bool Assign(char16ptr_t aData, size_type aLength,
const fallible_t&)
const fallible_t& aFallible)
{
return Assign(static_cast<const char16_t*>(aData), aLength, fallible_t());
return Assign(static_cast<const char16_t*>(aData), aLength,
aFallible);
}
#endif
@ -407,11 +409,11 @@ public:
AssignASCII(aData, mozilla::AssertedCast<size_type, size_t>(strlen(aData)));
}
NS_WARN_UNUSED_RESULT bool NS_FASTCALL AssignASCII(const char* aData,
const fallible_t&)
const fallible_t& aFallible)
{
return AssignASCII(aData,
mozilla::AssertedCast<size_type, size_t>(strlen(aData)),
fallible_t());
aFallible);
}
// AssignLiteral must ONLY be applied to an actual literal string, or
@ -473,7 +475,7 @@ public:
NS_WARN_UNUSED_RESULT bool NS_FASTCALL Replace(index_type aCutStart,
size_type aCutLength,
char_type aChar,
const mozilla::fallible_t&);
const fallible_t&);
void NS_FASTCALL Replace(index_type aCutStart, size_type aCutLength,
const char_type* aData,
size_type aLength = size_type(-1));
@ -481,7 +483,7 @@ public:
size_type aCutLength,
const char_type* aData,
size_type aLength,
const mozilla::fallible_t&);
const fallible_t&);
void Replace(index_type aCutStart, size_type aCutLength,
const self_type& aStr)
{
@ -490,10 +492,10 @@ public:
NS_WARN_UNUSED_RESULT bool Replace(index_type aCutStart,
size_type aCutLength,
const self_type& aStr,
const mozilla::fallible_t&)
const fallible_t& aFallible)
{
return Replace(aCutStart, aCutLength, aStr.Data(), aStr.Length(),
mozilla::fallible_t());
aFallible);
}
void NS_FASTCALL Replace(index_type aCutStart, size_type aCutLength,
const substring_tuple_type& aTuple);
@ -517,18 +519,18 @@ public:
Replace(mLength, 0, aChar);
}
NS_WARN_UNUSED_RESULT bool Append(char_type aChar,
const mozilla::fallible_t&)
const fallible_t& aFallible)
{
return Replace(mLength, 0, aChar, mozilla::fallible_t());
return Replace(mLength, 0, aChar, aFallible);
}
void Append(const char_type* aData, size_type aLength = size_type(-1))
{
Replace(mLength, 0, aData, aLength);
}
NS_WARN_UNUSED_RESULT bool Append(const char_type* aData, size_type aLength,
const mozilla::fallible_t&)
const fallible_t& aFallible)
{
return Replace(mLength, 0, aData, aLength, mozilla::fallible_t());
return Replace(mLength, 0, aData, aLength, aFallible);
}
#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
@ -766,10 +768,11 @@ public:
return GetMutableData(reinterpret_cast<char16_t**>(aData), aNewLen);
}
size_type GetMutableData(wchar_t** aData, size_type aNewLen, const fallible_t&)
size_type GetMutableData(wchar_t** aData, size_type aNewLen,
const fallible_t& aFallible)
{
return GetMutableData(reinterpret_cast<char16_t**>(aData), aNewLen,
fallible_t());
aFallible);
}
#endif

View File

@ -27,7 +27,7 @@ static bool test_pldhash_Init_capacity_ok()
// will allocate 0.5GB of entry store on 32-bit platforms and 1GB on 64-bit
// platforms.
if (!PL_DHashTableInit(&t, PL_DHashGetStubOps(), sizeof(PLDHashEntryStub),
mozilla::fallible_t(), PL_DHASH_MAX_INITIAL_LENGTH)) {
mozilla::fallible, PL_DHASH_MAX_INITIAL_LENGTH)) {
return false;
}
@ -57,7 +57,7 @@ static bool test_pldhash_Init_capacity_too_large()
// Try the smallest too-large capacity.
if (PL_DHashTableInit(&t, PL_DHashGetStubOps(),
sizeof(PLDHashEntryStub),
mozilla::fallible_t(),
mozilla::fallible,
PL_DHASH_MAX_INITIAL_LENGTH + 1)) {
return false; // it succeeded!?
}
@ -93,7 +93,7 @@ static bool test_pldhash_Init_overflow()
};
if (PL_DHashTableInit(&t, PL_DHashGetStubOps(), sizeof(OneKBEntry),
mozilla::fallible_t(), PL_DHASH_MAX_INITIAL_LENGTH)) {
mozilla::fallible, PL_DHASH_MAX_INITIAL_LENGTH)) {
return false; // it succeeded!?
}
// Don't call PL_DHashTableFinish() here; it's not safe after Init() failure.

View File

@ -11,12 +11,11 @@
#include "nsCRTGlue.h"
#include "nsRefPtr.h"
#include "nsTArray.h"
#include "mozilla/fallible.h"
#include "gtest/gtest.h"
namespace TestStrings {
using mozilla::fallible_t;
using mozilla::fallible;
void test_assign_helper(const nsACString& in, nsACString &_retval)
{
@ -851,75 +850,75 @@ TEST(Strings, huge_capacity)
// Ignore the result if the address space is less than 64-bit because
// some of the allocations above will exhaust the address space.
if (sizeof(void*) >= 8) {
EXPECT_TRUE(a.SetCapacity(1, fallible_t()));
EXPECT_FALSE(a.SetCapacity(nsString::size_type(-1)/2, fallible_t()));
EXPECT_TRUE(a.SetCapacity(0, fallible_t())); // free the allocated memory
EXPECT_TRUE(a.SetCapacity(1, fallible));
EXPECT_FALSE(a.SetCapacity(nsString::size_type(-1)/2, fallible));
EXPECT_TRUE(a.SetCapacity(0, fallible)); // free the allocated memory
EXPECT_TRUE(b.SetCapacity(1, fallible_t()));
EXPECT_FALSE(b.SetCapacity(nsString::size_type(-1)/2 - 1, fallible_t()));
EXPECT_TRUE(b.SetCapacity(0, fallible_t()));
EXPECT_TRUE(b.SetCapacity(1, fallible));
EXPECT_FALSE(b.SetCapacity(nsString::size_type(-1)/2 - 1, fallible));
EXPECT_TRUE(b.SetCapacity(0, fallible));
EXPECT_TRUE(c.SetCapacity(1, fallible_t()));
EXPECT_FALSE(c.SetCapacity(nsString::size_type(-1)/2, fallible_t()));
EXPECT_TRUE(c.SetCapacity(0, fallible_t()));
EXPECT_TRUE(c.SetCapacity(1, fallible));
EXPECT_FALSE(c.SetCapacity(nsString::size_type(-1)/2, fallible));
EXPECT_TRUE(c.SetCapacity(0, fallible));
EXPECT_FALSE(d.SetCapacity(nsString::size_type(-1)/2 - 1, fallible_t()));
EXPECT_FALSE(d.SetCapacity(nsString::size_type(-1)/2, fallible_t()));
EXPECT_TRUE(d.SetCapacity(0, fallible_t()));
EXPECT_FALSE(d.SetCapacity(nsString::size_type(-1)/2 - 1, fallible));
EXPECT_FALSE(d.SetCapacity(nsString::size_type(-1)/2, fallible));
EXPECT_TRUE(d.SetCapacity(0, fallible));
EXPECT_FALSE(e.SetCapacity(nsString::size_type(-1)/4, fallible_t()));
EXPECT_FALSE(e.SetCapacity(nsString::size_type(-1)/4 + 1, fallible_t()));
EXPECT_TRUE(e.SetCapacity(0, fallible_t()));
EXPECT_FALSE(e.SetCapacity(nsString::size_type(-1)/4, fallible));
EXPECT_FALSE(e.SetCapacity(nsString::size_type(-1)/4 + 1, fallible));
EXPECT_TRUE(e.SetCapacity(0, fallible));
EXPECT_FALSE(f.SetCapacity(nsString::size_type(-1)/2, fallible_t()));
EXPECT_TRUE(f.SetCapacity(0, fallible_t()));
EXPECT_FALSE(f.SetCapacity(nsString::size_type(-1)/2, fallible));
EXPECT_TRUE(f.SetCapacity(0, fallible));
EXPECT_FALSE(g.SetCapacity(nsString::size_type(-1)/4 + 1000, fallible_t()));
EXPECT_FALSE(g.SetCapacity(nsString::size_type(-1)/4 + 1001, fallible_t()));
EXPECT_TRUE(g.SetCapacity(0, fallible_t()));
EXPECT_FALSE(g.SetCapacity(nsString::size_type(-1)/4 + 1000, fallible));
EXPECT_FALSE(g.SetCapacity(nsString::size_type(-1)/4 + 1001, fallible));
EXPECT_TRUE(g.SetCapacity(0, fallible));
EXPECT_FALSE(h.SetCapacity(nsString::size_type(-1)/4+1, fallible_t()));
EXPECT_FALSE(h.SetCapacity(nsString::size_type(-1)/2, fallible_t()));
EXPECT_TRUE(h.SetCapacity(0, fallible_t()));
EXPECT_FALSE(h.SetCapacity(nsString::size_type(-1)/4+1, fallible));
EXPECT_FALSE(h.SetCapacity(nsString::size_type(-1)/2, fallible));
EXPECT_TRUE(h.SetCapacity(0, fallible));
EXPECT_TRUE(i.SetCapacity(1, fallible_t()));
EXPECT_TRUE(i.SetCapacity(nsString::size_type(-1)/4 - 1000, fallible_t()));
EXPECT_FALSE(i.SetCapacity(nsString::size_type(-1)/4 + 1, fallible_t()));
EXPECT_TRUE(i.SetCapacity(0, fallible_t()));
EXPECT_TRUE(i.SetCapacity(1, fallible));
EXPECT_TRUE(i.SetCapacity(nsString::size_type(-1)/4 - 1000, fallible));
EXPECT_FALSE(i.SetCapacity(nsString::size_type(-1)/4 + 1, fallible));
EXPECT_TRUE(i.SetCapacity(0, fallible));
EXPECT_TRUE(j.SetCapacity(nsString::size_type(-1)/4 - 1000, fallible_t()));
EXPECT_FALSE(j.SetCapacity(nsString::size_type(-1)/4 + 1, fallible_t()));
EXPECT_TRUE(j.SetCapacity(0, fallible_t()));
EXPECT_TRUE(j.SetCapacity(nsString::size_type(-1)/4 - 1000, fallible));
EXPECT_FALSE(j.SetCapacity(nsString::size_type(-1)/4 + 1, fallible));
EXPECT_TRUE(j.SetCapacity(0, fallible));
EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/8 - 1000, fallible_t()));
EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/4 - 1001, fallible_t()));
EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/4 - 998, fallible_t()));
EXPECT_FALSE(k.SetCapacity(nsString::size_type(-1)/4 + 1, fallible_t()));
EXPECT_TRUE(k.SetCapacity(0, fallible_t()));
EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/8 - 1000, fallible));
EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/4 - 1001, fallible));
EXPECT_TRUE(k.SetCapacity(nsString::size_type(-1)/4 - 998, fallible));
EXPECT_FALSE(k.SetCapacity(nsString::size_type(-1)/4 + 1, fallible));
EXPECT_TRUE(k.SetCapacity(0, fallible));
EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8, fallible_t()));
EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8 + 1, fallible_t()));
EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8 + 2, fallible_t()));
EXPECT_TRUE(l.SetCapacity(0, fallible_t()));
EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8, fallible));
EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8 + 1, fallible));
EXPECT_TRUE(l.SetCapacity(nsString::size_type(-1)/8 + 2, fallible));
EXPECT_TRUE(l.SetCapacity(0, fallible));
EXPECT_TRUE(m.SetCapacity(nsString::size_type(-1)/8 + 1000, fallible_t()));
EXPECT_TRUE(m.SetCapacity(nsString::size_type(-1)/8 + 1001, fallible_t()));
EXPECT_TRUE(m.SetCapacity(0, fallible_t()));
EXPECT_TRUE(m.SetCapacity(nsString::size_type(-1)/8 + 1000, fallible));
EXPECT_TRUE(m.SetCapacity(nsString::size_type(-1)/8 + 1001, fallible));
EXPECT_TRUE(m.SetCapacity(0, fallible));
EXPECT_TRUE(n.SetCapacity(nsString::size_type(-1)/8+1, fallible_t()));
EXPECT_FALSE(n.SetCapacity(nsString::size_type(-1)/4, fallible_t()));
EXPECT_TRUE(n.SetCapacity(0, fallible_t()));
EXPECT_TRUE(n.SetCapacity(nsString::size_type(-1)/8+1, fallible));
EXPECT_FALSE(n.SetCapacity(nsString::size_type(-1)/4, fallible));
EXPECT_TRUE(n.SetCapacity(0, fallible));
EXPECT_TRUE(n.SetCapacity(0, fallible_t()));
EXPECT_TRUE(n.SetCapacity((nsString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 2 - 2, fallible_t()));
EXPECT_TRUE(n.SetCapacity(0, fallible_t()));
EXPECT_FALSE(n.SetCapacity((nsString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 2 - 1, fallible_t()));
EXPECT_TRUE(n.SetCapacity(0, fallible_t()));
EXPECT_TRUE(n1.SetCapacity(0, fallible_t()));
EXPECT_TRUE(n1.SetCapacity((nsCString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 1 - 2, fallible_t()));
EXPECT_TRUE(n1.SetCapacity(0, fallible_t()));
EXPECT_FALSE(n1.SetCapacity((nsCString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 1 - 1, fallible_t()));
EXPECT_TRUE(n1.SetCapacity(0, fallible_t()));
EXPECT_TRUE(n.SetCapacity(0, fallible));
EXPECT_TRUE(n.SetCapacity((nsString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 2 - 2, fallible));
EXPECT_TRUE(n.SetCapacity(0, fallible));
EXPECT_FALSE(n.SetCapacity((nsString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 2 - 1, fallible));
EXPECT_TRUE(n.SetCapacity(0, fallible));
EXPECT_TRUE(n1.SetCapacity(0, fallible));
EXPECT_TRUE(n1.SetCapacity((nsCString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 1 - 2, fallible));
EXPECT_TRUE(n1.SetCapacity(0, fallible));
EXPECT_FALSE(n1.SetCapacity((nsCString::size_type(-1)/2 - sizeof(nsStringBuffer)) / 1 - 1, fallible));
EXPECT_TRUE(n1.SetCapacity(0, fallible));
}
}