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: else:
error('`mozglue` must be "program" or "library"') error('`mozglue` must be "program" or "library"')
if not CONFIG['JS_STANDALONE']:
USE_LIBS += [
'fallible',
]
@template @template
def GeckoProgram(name, linkage='standalone', **kwargs): def GeckoProgram(name, linkage='standalone', **kwargs):

View File

@ -109,7 +109,7 @@ DOMParser::ParseFromString(const nsAString& str,
nsAutoCString utf8str; nsAutoCString utf8str;
// Convert from UTF16 to UTF8 using fallible allocations // 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; return NS_ERROR_OUT_OF_MEMORY;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1074,9 +1074,10 @@ nsGenericDOMDataNode::AppendTextTo(nsAString& aResult)
} }
bool 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> 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 // copy the array - we don't know its lifetime, and ours is tied to xpcom
// refcounting. // refcounting.
if (argc) { if (argc) {
static const fallible_t fallible = fallible_t();
mArgv = new (fallible) JS::Heap<JS::Value>[argc]; mArgv = new (fallible) JS::Heap<JS::Value>[argc];
if (!mArgv) { if (!mArgv) {
*prv = NS_ERROR_OUT_OF_MEMORY; *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); size_t len = js::GetStringLength(s);
static_assert(js::MaxStringLength < (1 << 28), static_assert(js::MaxStringLength < (1 << 28),
"Shouldn't overflow here or in SetCapacity"); "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); JS_ReportOutOfMemory(cx);
return false; return false;
} }

View File

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

View File

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

View File

@ -670,7 +670,7 @@ nsXMLHttpRequest::AppendToResponseText(const char * aSrcBuffer,
&destBufferLen); &destBufferLen);
NS_ENSURE_SUCCESS(rv, rv); 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; return NS_ERROR_OUT_OF_MEMORY;
} }

View File

@ -102,9 +102,7 @@ public:
DataType* AddEntry(const nsAString& aKey) NS_WARN_UNUSED_RESULT DataType* AddEntry(const nsAString& aKey) NS_WARN_UNUSED_RESULT
{ {
// XXXbz can't just use fallible_t() because our superclass has a EntryType* ent = this->PutEntry(aKey, fallible);
// private typedef by that name.
EntryType* ent = this->PutEntry(aKey, mozilla::fallible_t());
if (!ent) { if (!ent) {
return nullptr; 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)) if (!dataSurface->Map(DataSourceSurface::MapType::READ, &map))
return; return;
static const fallible_t fallible = fallible_t();
uint8_t* imageBuffer = new (fallible) uint8_t[mWidth * mHeight * 4]; uint8_t* imageBuffer = new (fallible) uint8_t[mWidth * mHeight * 4];
if (!imageBuffer) { if (!imageBuffer) {
dataSurface->Unmap(); dataSurface->Unmap();

View File

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

View File

@ -48,7 +48,6 @@
#include "mozilla/dom/ImageData.h" #include "mozilla/dom/ImageData.h"
#include "mozilla/dom/ToJSValue.h" #include "mozilla/dom/ToJSValue.h"
#include "mozilla/Endian.h" #include "mozilla/Endian.h"
#include "mozilla/fallible.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom; 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; uint32_t subrect_byteLength = (subrect_height-1)*subrect_alignedRowSize + subrect_plainRowSize;
// create subrect buffer, call glReadPixels, copy pixels into destination buffer, delete subrect buffer // 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) if (!subrect_data)
return ErrorOutOfMemory("readPixels: subrect_data"); return ErrorOutOfMemory("readPixels: subrect_data");
@ -3203,7 +3202,7 @@ WebGLContext::TexImage2D_base(TexImageTarget texImageTarget, GLint level,
else else
{ {
size_t convertedDataSize = height * dstStride; size_t convertedDataSize = height * dstStride;
convertedData = new ((fallible_t())) uint8_t[convertedDataSize]; convertedData = new (fallible) uint8_t[convertedDataSize];
if (!convertedData) { if (!convertedData) {
ErrorOutOfMemory("texImage2D: Ran out of memory when allocating" ErrorOutOfMemory("texImage2D: Ran out of memory when allocating"
" a buffer for doing format conversion."); " a buffer for doing format conversion.");
@ -3404,7 +3403,7 @@ WebGLContext::TexSubImage2D_base(TexImageTarget texImageTarget, GLint level,
if (!noConversion) { if (!noConversion) {
size_t convertedDataSize = height * dstStride; size_t convertedDataSize = height * dstStride;
convertedData = new ((fallible_t())) uint8_t[convertedDataSize]; convertedData = new (fallible) uint8_t[convertedDataSize];
if (!convertedData) { if (!convertedData) {
ErrorOutOfMemory("texImage2D: Ran out of memory when allocating" ErrorOutOfMemory("texImage2D: Ran out of memory when allocating"
" a buffer for doing format conversion."); " 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 // Need a fallible allocator because the caller may be a content
// and the content can specify the length of the string. // 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]); nsAutoArrayPtr<char16_t> buf(new (fallible) char16_t[outLen + 1]);
if (!buf) { if (!buf) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY); 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 // Need a fallible allocator because the caller may be a content
// and the content can specify the length of the string. // 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]); nsAutoArrayPtr<char> buf(new (fallible) char[maxLen + 1]);
if (!buf) { if (!buf) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY); aRv.Throw(NS_ERROR_OUT_OF_MEMORY);

View File

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

View File

@ -26,7 +26,7 @@ MemoryOutputStream::Create(uint64_t aSize)
nsRefPtr<MemoryOutputStream> stream = new MemoryOutputStream(); nsRefPtr<MemoryOutputStream> stream = new MemoryOutputStream();
char* dummy; 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); NS_ENSURE_TRUE(length == aSize, nullptr);
return stream.forget(); return stream.forget();

View File

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

View File

@ -1873,8 +1873,6 @@ bool
nsTextEditorState::SetValue(const nsAString& aValue, bool aUserInput, nsTextEditorState::SetValue(const nsAString& aValue, bool aUserInput,
bool aSetValueChanged) bool aSetValueChanged)
{ {
mozilla::fallible_t fallible;
if (mEditor && mBoundFrame) { if (mEditor && mBoundFrame) {
// The InsertText call below might flush pending notifications, which // The InsertText call below might flush pending notifications, which
// could lead into a scheduled PrepareEditor to be called. That will // 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 char kSavepointClause[] = "SAVEPOINT sp;";
const fallible_t fallible = fallible_t();
const uint32_t kFileCopyBufferSize = 32768; const uint32_t kFileCopyBufferSize = 32768;
const char kJournalDirectoryName[] = "journals"; const char kJournalDirectoryName[] = "journals";

View File

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

View File

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

View File

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

View File

@ -333,7 +333,6 @@ MediaDecodeTask::FinishDecode()
// Allocate the channel buffers. Note that if we end up resampling, we may // Allocate the channel buffers. Note that if we end up resampling, we may
// write fewer bytes than mResampledFrames to the output buffer, in which // write fewer bytes than mResampledFrames to the output buffer, in which
// case mWriteIndex will tell us how many valid samples we have. // case mWriteIndex will tell us how many valid samples we have.
static const fallible_t fallible = fallible_t();
bool memoryAllocationSuccess = true; bool memoryAllocationSuccess = true;
if (!mDecodeJob.mChannelBuffers.SetLength(channelCount)) { if (!mDecodeJob.mChannelBuffers.SetLength(channelCount)) {
memoryAllocationSuccess = false; memoryAllocationSuccess = false;

View File

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

View File

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

View File

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

View File

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

View File

@ -179,7 +179,7 @@ void txDouble::toString(double aValue, nsAString& aDest)
++length; ++length;
// grow the string // grow the string
uint32_t oldlength = aDest.Length(); uint32_t oldlength = aDest.Length();
if (!aDest.SetLength(oldlength + length, mozilla::fallible_t())) if (!aDest.SetLength(oldlength + length, mozilla::fallible))
return; // out of memory return; // out of memory
nsAString::iterator dest; nsAString::iterator dest;
aDest.BeginWriting(dest).advance(int32_t(oldlength)); 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->IsElement() ||
aNode.mNode->IsNodeOfType(nsINode::eDOCUMENT_FRAGMENT)) { aNode.mNode->IsNodeOfType(nsINode::eDOCUMENT_FRAGMENT)) {
nsContentUtils::AppendNodeTextContent(aNode.mNode, true, aResult, nsContentUtils::AppendNodeTextContent(aNode.mNode, true, aResult,
mozilla::fallible_t()); mozilla::fallible);
return; return;
} }

View File

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

View File

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

View File

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

View File

@ -1096,7 +1096,6 @@ gfxFT2FontList::AppendFacesFromOmnijarEntry(nsZipArchive* aArchive,
uint32_t bufSize = item->RealSize(); uint32_t bufSize = item->RealSize();
// We use fallible allocation here; if there's not enough RAM, we'll simply // 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. // 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]); nsAutoArrayPtr<uint8_t> buf(new (fallible) uint8_t[bufSize]);
if (!buf) { if (!buf) {
return; return;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1009,7 +1009,6 @@ void MediaPipelineTransmit::PipelineListener::ProcessVideoChunk(
// Send a black image. // Send a black image.
nsAutoArrayPtr<uint8_t> pixelData; nsAutoArrayPtr<uint8_t> pixelData;
static const fallible_t fallible = fallible_t();
pixelData = new (fallible) uint8_t[length]; pixelData = new (fallible) uint8_t[length];
if (pixelData) { if (pixelData) {
// YCrCb black = 0x10 0x80 0x80 // 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, * 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/. */ * You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_fallible_h #include "fallible.h"
#define mozilla_fallible_h
namespace mozilla { 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 NO_VISIBILITY_FLAGS = True
EXPORTS.mozilla += [ EXPORTS.mozilla += [
'fallible.h',
'mozalloc.h', 'mozalloc.h',
'mozalloc_abort.h', 'mozalloc_abort.h',
'mozalloc_oom.h', 'mozalloc_oom.h',

View File

@ -1157,7 +1157,7 @@ nsZipItemPtr_base::nsZipItemPtr_base(nsZipArchive *aZip, const char * aEntryName
uint32_t size = 0; uint32_t size = 0;
if (item->Compression() == DEFLATED) { if (item->Compression() == DEFLATED) {
size = item->RealSize(); size = item->RealSize();
mAutoBuf = new ((fallible_t())) uint8_t[size]; mAutoBuf = new (fallible) uint8_t[size];
if (!mAutoBuf) { if (!mAutoBuf) {
return; 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 // Debugging to see why we end up with very long strings here with
// some addons, see bug 836263. // some addons, see bug 836263.
nsAutoString wdata; nsAutoString wdata;
if (!AppendUTF8toUTF16(utf8String, wdata, mozilla::fallible_t())) { if (!AppendUTF8toUTF16(utf8String, wdata, mozilla::fallible)) {
#ifdef MOZ_CRASHREPORTER #ifdef MOZ_CRASHREPORTER
nsCOMPtr<nsICrashReporter> cr = nsCOMPtr<nsICrashReporter> cr =
do_GetService("@mozilla.org/toolkit/crash-reporter;1"); do_GetService("@mozilla.org/toolkit/crash-reporter;1");

View File

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

View File

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

View File

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

View File

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

View File

@ -588,7 +588,7 @@ nsStandardURL::BuildNormalizedSpec(const char *spec)
// generate the normalized URL string // generate the normalized URL string
// //
// approxLen should be correct or 1 high // 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; return NS_ERROR_OUT_OF_MEMORY;
char *buf; char *buf;
mSpec.BeginWriting(buf); mSpec.BeginWriting(buf);

View File

@ -26,7 +26,7 @@ nsUnicharStreamLoader::Init(nsIUnicharStreamLoaderObserver *aObserver)
mObserver = 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_ERROR_OUT_OF_MEMORY;
return NS_OK; return NS_OK;
@ -214,7 +214,7 @@ nsUnicharStreamLoader::WriteSegmentFun(nsIInputStream *,
self->mDecoder->GetMaxLength(aSegment, srcLen, &dstLen); self->mDecoder->GetMaxLength(aSegment, srcLen, &dstLen);
uint32_t capacity = haveRead + 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; return NS_ERROR_OUT_OF_MEMORY;
} }

View File

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

View File

@ -966,7 +966,7 @@ nsOfflineCacheDevice::UpdateEntry(nsCacheEntry *entry)
nsCString metaDataBuf; nsCString metaDataBuf;
uint32_t mdSize = entry->MetaDataSize(); uint32_t mdSize = entry->MetaDataSize();
if (!metaDataBuf.SetLength(mdSize, fallible_t())) if (!metaDataBuf.SetLength(mdSize, fallible))
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
char *md = metaDataBuf.BeginWriting(); char *md = metaDataBuf.BeginWriting();
entry->FlattenMetaData(md, mdSize); 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 // known atoms (NUM_HTTP_ATOMS) because we expect to encounter a few random
// headers right off the bat. // headers right off the bat.
if (!PL_DHashTableInit(&sAtomTable, &ops, sizeof(PLDHashEntryStub), if (!PL_DHashTableInit(&sAtomTable, &ops, sizeof(PLDHashEntryStub),
fallible_t(), NUM_HTTP_ATOMS + 10)) { fallible, NUM_HTTP_ATOMS + 10)) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }

View File

@ -1609,7 +1609,7 @@ WebSocketChannel::ProcessInput(uint8_t *buffer, uint32_t count)
utf8Data.Length())); utf8Data.Length()));
} else { } else {
if (!utf8Data.Assign((const char *)payload, payloadLength, if (!utf8Data.Assign((const char *)payload, payloadLength,
mozilla::fallible_t())) { mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
} }
@ -1719,7 +1719,7 @@ WebSocketChannel::ProcessInput(uint8_t *buffer, uint32_t count)
binaryData.Length())); binaryData.Length()));
} else { } else {
if (!binaryData.Assign((const char *)payload, payloadLength, if (!binaryData.Assign((const char *)payload, payloadLength,
mozilla::fallible_t())) { mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY; 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 // Ensure that our mBuf has capacity to hold the data we're about to
// read. // read.
if (!mBuf.SetLength(len + aCount, fallible_t())) if (!mBuf.SetLength(len + aCount, fallible))
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
// Now read the data into our buffer. // Now read the data into our buffer.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@
#include <base64.h> #include <base64.h>
#include <nsString.h> #include <nsString.h>
using mozilla::fallible_t; using mozilla::fallible;
static bool static bool
hex_from_2char(const unsigned char *c2, unsigned char *byteval) 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) toHexString(const unsigned char * str, unsigned len, nsACString & out)
{ {
static const char digits[] = "0123456789ABCDEF"; static const char digits[] = "0123456789ABCDEF";
if (!out.SetCapacity(2 * len, fallible_t())) if (!out.SetCapacity(2 * len, fallible))
return false; return false;
out.SetLength(0); out.SetLength(0);
for (unsigned i = 0; i < len; ++i) { for (unsigned i = 0; i < len; ++i) {
@ -301,7 +301,7 @@ setBase64(const unsigned char * data, unsigned len, nsACString & out)
if (base64 != nullptr) { if (base64 != nullptr) {
size_t len = PORT_Strlen(base64); size_t len = PORT_Strlen(base64);
if (out.SetCapacity(len, fallible_t())) { if (out.SetCapacity(len, fallible)) {
out.SetLength(0); out.SetLength(0);
out.Append(base64, len); out.Append(base64, len);
PORT_Free((void*) base64); 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 // result, we set the capacity to be one greater than what we need, and the
// length to our desired length. // length to our desired length.
uint32_t length = (aNumBytes + 2) / 3 * 4; // +2 due to integer math. 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); NS_ERROR_OUT_OF_MEMORY);
_result.SetLength(length); _result.SetLength(length);
(void)PL_Base64Encode(reinterpret_cast<const char*>(aBytes), aNumBytes, (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 // result, we set the capacity to be one greater than what we need, and the
// length to our desired length. // length to our desired length.
uint32_t length = (aNumBytes + 2) / 3 * 4; // +2 due to integer math. 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); NS_ERROR_OUT_OF_MEMORY);
_result.SetLength(length); _result.SetLength(length);
(void)PL_Base64Encode(reinterpret_cast<const char*>(aBytes), aNumBytes, (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, KeyedHistogram* keyed = new KeyedHistogram(name, expiration, histogramType,
min, max, bucketCount); min, max, bucketCount);
if (MOZ_UNLIKELY(!mKeyedHistograms.Put(name, keyed, fallible_t()))) { if (MOZ_UNLIKELY(!mKeyedHistograms.Put(name, keyed, fallible))) {
delete keyed; delete keyed;
return NS_ERROR_OUT_OF_MEMORY; 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); long lRtn = ::ImmGetCompositionStringW(aIMEContext.get(), aIndex, nullptr, 0);
if (lRtn < 0 || if (lRtn < 0 ||
!aCompositionString.SetLength((lRtn / sizeof(WCHAR)) + 1, !aCompositionString.SetLength((lRtn / sizeof(WCHAR)) + 1,
mozilla::fallible_t())) { mozilla::fallible)) {
PR_LOG(gIMM32Log, PR_LOG_ALWAYS, PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
("IMM32: GetCompositionString, FAILED by OOM\n")); ("IMM32: GetCompositionString, FAILED by OOM\n"));
return; // Error or out of memory. return; // Error or out of memory.
@ -1756,7 +1756,7 @@ nsIMM32Handler::ConvertToANSIString(const nsAFlatString& aStr, UINT aCodePage,
nullptr, 0, nullptr, nullptr); nullptr, 0, nullptr, nullptr);
NS_ENSURE_TRUE(len >= 0, false); 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, PR_LOG(gIMM32Log, PR_LOG_ALWAYS,
("IMM32: ConvertToANSIString, FAILED by OOM\n")); ("IMM32: ConvertToANSIString, FAILED by OOM\n"));
return false; return false;

View File

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

View File

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

View File

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

View File

@ -114,3 +114,8 @@ if CONFIG['ENABLE_TESTS']:
DIRS += ['tests/gtest'] DIRS += ['tests/gtest']
FAIL_ON_WARNINGS = True 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 DISABLE_STL_WRAPPING = True
FAIL_ON_WARNINGS = 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) 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()); NS_ABORT_OOM(this->mTable.EntrySize() * this->mTable.EntryCount());
} }
} }

View File

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

View File

@ -147,7 +147,7 @@ void
nsRefPtrHashtable<KeyClass, RefPtr>::Put(KeyType aKey, nsRefPtrHashtable<KeyClass, RefPtr>::Put(KeyType aKey,
already_AddRefed<RefPtr> aData) 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()); NS_ABORT_OOM(this->mTable.EntrySize() * this->mTable.EntryCount());
} }
} }

View File

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

View File

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

View File

@ -44,3 +44,8 @@ LOCAL_INCLUDES += [
DISABLE_STL_WRAPPING = True DISABLE_STL_WRAPPING = True
FAIL_ON_WARNINGS = 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 DISABLE_STL_WRAPPING = True
FAIL_ON_WARNINGS = 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 DISABLE_STL_WRAPPING = True
FAIL_ON_WARNINGS = 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; char* buffer;
// Add one byte for null termination. // Add one byte for null termination.
if (aString.SetCapacity(stringLen + 1, fallible_t()) && if (aString.SetCapacity(stringLen + 1, fallible) &&
(buffer = aString.BeginWriting()) && (buffer = aString.BeginWriting()) &&
PL_Base64Encode(aBinaryData.BeginReading(), aBinaryData.Length(), buffer)) { PL_Base64Encode(aBinaryData.BeginReading(), aBinaryData.Length(), buffer)) {
// PL_Base64Encode doesn't null terminate the buffer for us when we pass // 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; char* buffer;
// Add one byte for null termination. // Add one byte for null termination.
if (aBinaryData.SetCapacity(binaryDataLen + 1, fallible_t()) && if (aBinaryData.SetCapacity(binaryDataLen + 1, fallible) &&
(buffer = aBinaryData.BeginWriting()) && (buffer = aBinaryData.BeginWriting()) &&
PL_Base64Decode(aString.BeginReading(), aString.Length(), buffer)) { PL_Base64Decode(aString.BeginReading(), aString.Length(), buffer)) {
// PL_Base64Decode doesn't null terminate the buffer for us when we pass // 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) { if (!mBuffer) {
mBuffer.reset(new ((fallible_t())) char[mBlockSize]); mBuffer.reset(new (fallible) char[mBlockSize]);
if (NS_WARN_IF(!mBuffer)) { if (NS_WARN_IF(!mBuffer)) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
@ -174,7 +174,7 @@ SnappyCompressOutputStream::FlushToBaseStream()
// will then get re-used until the stream is closed. // will then get re-used until the stream is closed.
if (!mCompressedBuffer) { if (!mCompressedBuffer) {
mCompressedBufferLength = MaxCompressedBufferLength(mBlockSize); mCompressedBufferLength = MaxCompressedBufferLength(mBlockSize);
mCompressedBuffer.reset(new ((fallible_t())) char[mCompressedBufferLength]); mCompressedBuffer.reset(new (fallible) char[mCompressedBufferLength]);
if (NS_WARN_IF(!mCompressedBuffer)) { if (NS_WARN_IF(!mCompressedBuffer)) {
return NS_ERROR_OUT_OF_MEMORY; 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 // operation. These allocations only happens once. The buffers are reused
// until the stream is closed. // until the stream is closed.
if (!mUncompressedBuffer) { if (!mUncompressedBuffer) {
mUncompressedBuffer.reset(new ((fallible_t())) char[snappy::kBlockSize]); mUncompressedBuffer.reset(new (fallible) char[snappy::kBlockSize]);
if (NS_WARN_IF(!mUncompressedBuffer)) { if (NS_WARN_IF(!mUncompressedBuffer)) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
} }
if (!mCompressedBuffer) { if (!mCompressedBuffer) {
mCompressedBuffer.reset(new ((fallible_t())) char[kCompressedBufferLength]); mCompressedBuffer.reset(new (fallible) char[kCompressedBufferLength]);
if (NS_WARN_IF(!mCompressedBuffer)) { if (NS_WARN_IF(!mCompressedBuffer)) {
return NS_ERROR_OUT_OF_MEMORY; 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... // 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; return NS_ERROR_OUT_OF_MEMORY;
} }

View File

@ -3654,7 +3654,7 @@ nsDriveEnumerator::Init()
* the length required for the string. */ * the length required for the string. */
DWORD length = GetLogicalDriveStringsW(0, 0); DWORD length = GetLogicalDriveStringsW(0, 0);
/* The string is null terminated */ /* The string is null terminated */
if (!mDrives.SetLength(length + 1, fallible_t())) { if (!mDrives.SetLength(length + 1, fallible)) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
if (!GetLogicalDriveStringsW(length, wwc(mDrives.BeginWriting()))) { 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 // this will generally result in a larger allocation, but that seems
// better than an extra buffer copy. // better than an extra buffer copy.
// //
if (!aOutput.SetLength(inputLen, fallible_t())) { if (!aOutput.SetLength(inputLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
nsAString::iterator out_iter; nsAString::iterator out_iter;
@ -925,7 +925,7 @@ NS_CopyNativeToUnicode(const nsACString& aInput, nsAString& aOutput)
} }
// allocate sufficient space // allocate sufficient space
if (!aOutput.SetLength(resultLen, fallible_t())) { if (!aOutput.SetLength(resultLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
if (resultLen > 0) { if (resultLen > 0) {
@ -959,7 +959,7 @@ NS_CopyUnicodeToNative(const nsAString& aInput, nsACString& aOutput)
} }
// allocate sufficient space // allocate sufficient space
if (!aOutput.SetLength(resultLen, fallible_t())) { if (!aOutput.SetLength(resultLen, fallible)) {
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
if (resultLen > 0) { if (resultLen > 0) {

View File

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

View File

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

View File

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

View File

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

View File

@ -176,9 +176,9 @@ public:
return aIter = BeginWriting(); 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) char_iterator& EndWriting(char_iterator& aIter)
@ -186,9 +186,9 @@ public:
return aIter = EndWriting(); 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)); 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) 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, 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 #endif
@ -407,11 +409,11 @@ public:
AssignASCII(aData, mozilla::AssertedCast<size_type, size_t>(strlen(aData))); AssignASCII(aData, mozilla::AssertedCast<size_type, size_t>(strlen(aData)));
} }
NS_WARN_UNUSED_RESULT bool NS_FASTCALL AssignASCII(const char* aData, NS_WARN_UNUSED_RESULT bool NS_FASTCALL AssignASCII(const char* aData,
const fallible_t&) const fallible_t& aFallible)
{ {
return AssignASCII(aData, return AssignASCII(aData,
mozilla::AssertedCast<size_type, size_t>(strlen(aData)), mozilla::AssertedCast<size_type, size_t>(strlen(aData)),
fallible_t()); aFallible);
} }
// AssignLiteral must ONLY be applied to an actual literal string, or // 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, NS_WARN_UNUSED_RESULT bool NS_FASTCALL Replace(index_type aCutStart,
size_type aCutLength, size_type aCutLength,
char_type aChar, char_type aChar,
const mozilla::fallible_t&); const fallible_t&);
void NS_FASTCALL Replace(index_type aCutStart, size_type aCutLength, void NS_FASTCALL Replace(index_type aCutStart, size_type aCutLength,
const char_type* aData, const char_type* aData,
size_type aLength = size_type(-1)); size_type aLength = size_type(-1));
@ -481,7 +483,7 @@ public:
size_type aCutLength, size_type aCutLength,
const char_type* aData, const char_type* aData,
size_type aLength, size_type aLength,
const mozilla::fallible_t&); const fallible_t&);
void Replace(index_type aCutStart, size_type aCutLength, void Replace(index_type aCutStart, size_type aCutLength,
const self_type& aStr) const self_type& aStr)
{ {
@ -490,10 +492,10 @@ public:
NS_WARN_UNUSED_RESULT bool Replace(index_type aCutStart, NS_WARN_UNUSED_RESULT bool Replace(index_type aCutStart,
size_type aCutLength, size_type aCutLength,
const self_type& aStr, const self_type& aStr,
const mozilla::fallible_t&) const fallible_t& aFallible)
{ {
return Replace(aCutStart, aCutLength, aStr.Data(), aStr.Length(), return Replace(aCutStart, aCutLength, aStr.Data(), aStr.Length(),
mozilla::fallible_t()); aFallible);
} }
void NS_FASTCALL Replace(index_type aCutStart, size_type aCutLength, void NS_FASTCALL Replace(index_type aCutStart, size_type aCutLength,
const substring_tuple_type& aTuple); const substring_tuple_type& aTuple);
@ -517,18 +519,18 @@ public:
Replace(mLength, 0, aChar); Replace(mLength, 0, aChar);
} }
NS_WARN_UNUSED_RESULT bool Append(char_type 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)) void Append(const char_type* aData, size_type aLength = size_type(-1))
{ {
Replace(mLength, 0, aData, aLength); Replace(mLength, 0, aData, aLength);
} }
NS_WARN_UNUSED_RESULT bool Append(const char_type* aData, size_type 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) #if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
@ -766,10 +768,11 @@ public:
return GetMutableData(reinterpret_cast<char16_t**>(aData), aNewLen); 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, return GetMutableData(reinterpret_cast<char16_t**>(aData), aNewLen,
fallible_t()); aFallible);
} }
#endif #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 // will allocate 0.5GB of entry store on 32-bit platforms and 1GB on 64-bit
// platforms. // platforms.
if (!PL_DHashTableInit(&t, PL_DHashGetStubOps(), sizeof(PLDHashEntryStub), 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; return false;
} }
@ -57,7 +57,7 @@ static bool test_pldhash_Init_capacity_too_large()
// Try the smallest too-large capacity. // Try the smallest too-large capacity.
if (PL_DHashTableInit(&t, PL_DHashGetStubOps(), if (PL_DHashTableInit(&t, PL_DHashGetStubOps(),
sizeof(PLDHashEntryStub), sizeof(PLDHashEntryStub),
mozilla::fallible_t(), mozilla::fallible,
PL_DHASH_MAX_INITIAL_LENGTH + 1)) { PL_DHASH_MAX_INITIAL_LENGTH + 1)) {
return false; // it succeeded!? return false; // it succeeded!?
} }
@ -93,7 +93,7 @@ static bool test_pldhash_Init_overflow()
}; };
if (PL_DHashTableInit(&t, PL_DHashGetStubOps(), sizeof(OneKBEntry), 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!? return false; // it succeeded!?
} }
// Don't call PL_DHashTableFinish() here; it's not safe after Init() failure. // Don't call PL_DHashTableFinish() here; it's not safe after Init() failure.

View File

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