From 824818ee9899ed2600ef20e60c1bfdf511f78622 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Wed, 28 Jan 2015 18:00:40 +0900 Subject: [PATCH] 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 --- build/gecko_templates.mozbuild | 5 + dom/base/DOMParser.cpp | 2 +- dom/base/FragmentOrElement.cpp | 2 +- dom/base/URLSearchParams.cpp | 2 +- dom/base/nsContentUtils.cpp | 20 ++-- dom/base/nsDOMFileReader.cpp | 4 +- dom/base/nsDocumentEncoder.cpp | 2 +- dom/base/nsGenericDOMDataNode.cpp | 5 +- dom/base/nsJSEnvironment.cpp | 1 - dom/base/nsJSUtils.h | 2 +- dom/base/nsScriptNameSpaceManager.cpp | 4 +- dom/base/nsTextFragment.h | 16 +-- dom/base/nsXMLHttpRequest.cpp | 2 +- dom/bindings/MozMap.h | 4 +- dom/canvas/WebGLContext.cpp | 1 - dom/canvas/WebGLContextDraw.cpp | 2 +- dom/canvas/WebGLContextGL.cpp | 7 +- dom/encoding/TextDecoder.cpp | 1 - dom/encoding/TextEncoder.cpp | 1 - dom/fetch/Fetch.cpp | 4 +- dom/filehandle/MemoryStreams.cpp | 2 +- dom/html/HTMLFrameSetElement.cpp | 1 - dom/html/nsTextEditorState.cpp | 2 - dom/indexedDB/ActorsParent.cpp | 2 - dom/indexedDB/IDBObjectStore.cpp | 2 +- dom/media/fmp4/MP4Stream.h | 3 +- dom/media/webaudio/AudioDestinationNode.cpp | 3 +- dom/media/webaudio/MediaBufferDecoder.cpp | 3 +- dom/plugins/base/nsPluginTags.cpp | 2 +- dom/storage/DOMStorage.cpp | 2 +- dom/svg/SVGContentUtils.h | 4 +- dom/svg/SVGFEConvolveMatrixElement.cpp | 1 - dom/xslt/base/txDouble.cpp | 2 +- dom/xslt/xpath/txMozillaXPathTreeWalker.cpp | 2 +- editor/libeditor/nsTextEditRules.cpp | 2 +- .../spellcheck/src/mozInlineSpellWordUtil.cpp | 2 +- gfx/layers/client/TextureClient.cpp | 3 +- gfx/thebes/gfxFT2FontList.cpp | 1 - image/decoders/icon/win/nsIconChannel.cpp | 2 +- image/encoders/bmp/nsBMPEncoder.cpp | 1 - image/src/SourceBuffer.h | 1 - intl/uconv/nsScriptableUConv.cpp | 6 +- layout/base/nsBidiPresUtils.cpp | 2 +- .../src/mediapipeline/MediaPipeline.cpp | 1 - .../fallible.h => fallible/fallible.cpp} | 9 +- memory/fallible/fallible.h | 67 +++++++++++ memory/fallible/moz.build | 30 +++++ memory/mozalloc/moz.build | 1 - modules/libjar/nsZipArchive.cpp | 2 +- modules/libpref/nsPrefBranch.cpp | 2 +- modules/libpref/prefapi.cpp | 2 +- moz.build | 1 + netwerk/base/nsBufferedStreams.cpp | 3 +- netwerk/base/nsNetUtil.h | 2 +- netwerk/base/nsStandardURL.cpp | 2 +- netwerk/base/nsUnicharStreamLoader.cpp | 4 +- netwerk/cache/nsCacheEntry.cpp | 2 +- netwerk/cache/nsDiskCacheDeviceSQL.cpp | 2 +- netwerk/protocol/http/nsHttp.cpp | 2 +- .../protocol/websocket/WebSocketChannel.cpp | 4 +- .../converters/nsDirIndexParser.cpp | 2 +- parser/html/nsHtml5OwningUTF16Buffer.cpp | 5 +- parser/html/nsHtml5StreamParser.cpp | 6 +- parser/htmlparser/nsHTMLEntities.cpp | 4 +- parser/htmlparser/nsScannerString.cpp | 4 +- security/manager/ssl/src/nsCertTree.cpp | 2 +- services/crypto/component/nsSyncJPAKE.cpp | 6 +- toolkit/components/downloads/SQLFunctions.cpp | 2 +- toolkit/components/places/Helpers.cpp | 2 +- toolkit/components/telemetry/Telemetry.cpp | 2 +- widget/windows/nsIMM32Handler.cpp | 4 +- xpcom/base/nsCycleCollector.cpp | 2 +- xpcom/ds/nsStaticNameTable.cpp | 2 +- xpcom/ds/nsSupportsPrimitives.cpp | 6 +- xpcom/glue/moz.build | 5 + xpcom/glue/nomozalloc/moz.build | 5 + xpcom/glue/nsBaseHashtable.h | 2 +- xpcom/glue/nsDeque.h | 4 +- xpcom/glue/nsRefPtrHashtable.h | 2 +- xpcom/glue/nsTHashtable.h | 2 +- xpcom/glue/pldhash.cpp | 4 +- xpcom/glue/standalone/moz.build | 5 + xpcom/glue/standalone/staticruntime/moz.build | 5 + xpcom/glue/staticruntime/moz.build | 5 + xpcom/io/Base64.cpp | 4 +- xpcom/io/SnappyCompressOutputStream.cpp | 4 +- xpcom/io/SnappyUncompressInputStream.cpp | 4 +- xpcom/io/nsBinaryStream.cpp | 2 +- xpcom/io/nsLocalFileWin.cpp | 2 +- xpcom/io/nsNativeCharsetUtils.cpp | 6 +- xpcom/string/nsAString.h | 2 - xpcom/string/nsReadableUtils.cpp | 24 ++-- xpcom/string/nsTStringObsolete.cpp | 6 +- xpcom/string/nsTSubstring.cpp | 42 +++---- xpcom/string/nsTSubstring.h | 43 +++---- xpcom/tests/TestPLDHash.cpp | 6 +- xpcom/tests/gtest/TestStrings.cpp | 113 +++++++++--------- 97 files changed, 358 insertions(+), 262 deletions(-) rename memory/{mozalloc/fallible.h => fallible/fallible.cpp} (63%) create mode 100644 memory/fallible/fallible.h create mode 100644 memory/fallible/moz.build diff --git a/build/gecko_templates.mozbuild b/build/gecko_templates.mozbuild index 9d07947ce41..46ff7d2b456 100644 --- a/build/gecko_templates.mozbuild +++ b/build/gecko_templates.mozbuild @@ -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): diff --git a/dom/base/DOMParser.cpp b/dom/base/DOMParser.cpp index b9bec3e69b6..6d5e06f8851 100644 --- a/dom/base/DOMParser.cpp +++ b/dom/base/DOMParser.cpp @@ -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; } diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp index de073444108..f29289c81e1 100644 --- a/dom/base/FragmentOrElement.cpp +++ b/dom/base/FragmentOrElement.cpp @@ -2202,7 +2202,7 @@ public: bool ToString(nsAString& aOut) { - if (!aOut.SetCapacity(mLength, fallible_t())) { + if (!aOut.SetCapacity(mLength, fallible)) { return false; } diff --git a/dom/base/URLSearchParams.cpp b/dom/base/URLSearchParams.cpp index 0b9cd4cf03c..c2d5a89f54f 100644 --- a/dom/base/URLSearchParams.cpp +++ b/dom/base/URLSearchParams.cpp @@ -190,7 +190,7 @@ URLSearchParams::ConvertString(const nsACString& aInput, nsAString& aOutput) return; } - if (!aOutput.SetLength(outputLength, fallible_t())) { + if (!aOutput.SetLength(outputLength, fallible)) { return; } diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index b84e3c655d0..63dacabbb11 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -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(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 diff --git a/dom/base/nsDOMFileReader.cpp b/dom/base/nsDOMFileReader.cpp index fbeac9e9885..6267e0e985d 100644 --- a/dom/base/nsDOMFileReader.cpp +++ b/dom/base/nsDOMFileReader.cpp @@ -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; } diff --git a/dom/base/nsDocumentEncoder.cpp b/dom/base/nsDocumentEncoder.cpp index 44b3df67776..152add2180a 100644 --- a/dom/base/nsDocumentEncoder.cpp +++ b/dom/base/nsDocumentEncoder.cpp @@ -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(); diff --git a/dom/base/nsGenericDOMDataNode.cpp b/dom/base/nsGenericDOMDataNode.cpp index 81a28839c3e..d4057ecbc5a 100644 --- a/dom/base/nsGenericDOMDataNode.cpp +++ b/dom/base/nsGenericDOMDataNode.cpp @@ -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 diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 7c1ca0c7dd5..7043ffd4bae 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -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[argc]; if (!mArgv) { *prv = NS_ERROR_OUT_OF_MEMORY; diff --git a/dom/base/nsJSUtils.h b/dom/base/nsJSUtils.h index d696698d8c6..82d3488a420 100644 --- a/dom/base/nsJSUtils.h +++ b/dom/base/nsJSUtils.h @@ -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; } diff --git a/dom/base/nsScriptNameSpaceManager.cpp b/dom/base/nsScriptNameSpaceManager.cpp index b5e10aa8a14..d4b935fda17 100644 --- a/dom/base/nsScriptNameSpaceManager.cpp +++ b/dom/base/nsScriptNameSpaceManager.cpp @@ -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); diff --git a/dom/base/nsTextFragment.h b/dom/base/nsTextFragment.h index c7c587dc807..84597dd1862 100644 --- a/dom/base/nsTextFragment.h +++ b/dom/base/nsTextFragment.h @@ -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); } } diff --git a/dom/base/nsXMLHttpRequest.cpp b/dom/base/nsXMLHttpRequest.cpp index b4cf0604122..8f0aa506b2e 100644 --- a/dom/base/nsXMLHttpRequest.cpp +++ b/dom/base/nsXMLHttpRequest.cpp @@ -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; } diff --git a/dom/bindings/MozMap.h b/dom/bindings/MozMap.h index 22605aac166..d303c664f37 100644 --- a/dom/bindings/MozMap.h +++ b/dom/bindings/MozMap.h @@ -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; } diff --git a/dom/canvas/WebGLContext.cpp b/dom/canvas/WebGLContext.cpp index 29c45bde703..749621074af 100644 --- a/dom/canvas/WebGLContext.cpp +++ b/dom/canvas/WebGLContext.cpp @@ -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(); diff --git a/dom/canvas/WebGLContextDraw.cpp b/dom/canvas/WebGLContextDraw.cpp index 8ba46d457e7..2c725ae82ff 100644 --- a/dom/canvas/WebGLContextDraw.cpp +++ b/dom/canvas/WebGLContextDraw.cpp @@ -581,7 +581,7 @@ WebGLContext::DoFakeVertexAttrib0(GLuint vertexCount) GetAndFlushUnderlyingGLErrors(); if (mFakeVertexAttrib0BufferStatus == WebGLVertexAttrib0Status::EmulatedInitializedArray) { - UniquePtr array(new ((fallible_t())) GLfloat[4 * vertexCount]); + UniquePtr array(new (fallible) GLfloat[4 * vertexCount]); if (!array) { ErrorOutOfMemory("Fake attrib0 array."); return false; diff --git a/dom/canvas/WebGLContextGL.cpp b/dom/canvas/WebGLContextGL.cpp index 532e5ce60a2..999b71b67e4 100644 --- a/dom/canvas/WebGLContextGL.cpp +++ b/dom/canvas/WebGLContextGL.cpp @@ -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 subrect_data(new ((fallible_t())) GLubyte[subrect_byteLength]); + UniquePtr 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."); diff --git a/dom/encoding/TextDecoder.cpp b/dom/encoding/TextDecoder.cpp index 963dcac1333..25a5ea97d88 100644 --- a/dom/encoding/TextDecoder.cpp +++ b/dom/encoding/TextDecoder.cpp @@ -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 buf(new (fallible) char16_t[outLen + 1]); if (!buf) { aRv.Throw(NS_ERROR_OUT_OF_MEMORY); diff --git a/dom/encoding/TextEncoder.cpp b/dom/encoding/TextEncoder.cpp index 023f9b16c85..ae7ff4b7706 100644 --- a/dom/encoding/TextEncoder.cpp +++ b/dom/encoding/TextEncoder.cpp @@ -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 buf(new (fallible) char[maxLen + 1]); if (!buf) { aRv.Throw(NS_ERROR_OUT_OF_MEMORY); diff --git a/dom/fetch/Fetch.cpp b/dom/fetch/Fetch.cpp index 44cecf0fd81..9abbd7824c3 100644 --- a/dom/fetch/Fetch.cpp +++ b/dom/fetch/Fetch.cpp @@ -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; } diff --git a/dom/filehandle/MemoryStreams.cpp b/dom/filehandle/MemoryStreams.cpp index 67400631159..13d8001beac 100644 --- a/dom/filehandle/MemoryStreams.cpp +++ b/dom/filehandle/MemoryStreams.cpp @@ -26,7 +26,7 @@ MemoryOutputStream::Create(uint64_t aSize) nsRefPtr 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(); diff --git a/dom/html/HTMLFrameSetElement.cpp b/dom/html/HTMLFrameSetElement.cpp index a292f061f55..76ae4a9027e 100644 --- a/dom/html/HTMLFrameSetElement.cpp +++ b/dom/html/HTMLFrameSetElement.cpp @@ -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; diff --git a/dom/html/nsTextEditorState.cpp b/dom/html/nsTextEditorState.cpp index 92f748c46b8..68ff1a25d04 100644 --- a/dom/html/nsTextEditorState.cpp +++ b/dom/html/nsTextEditorState.cpp @@ -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 diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index 5e41ba09b53..690e8f61de2 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -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"; diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index d3f89fff649..db4014cb217 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -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; } diff --git a/dom/media/fmp4/MP4Stream.h b/dom/media/fmp4/MP4Stream.h index 912d4f00fe9..f45989e5fe4 100644 --- a/dom/media/fmp4/MP4Stream.h +++ b/dom/media/fmp4/MP4Stream.h @@ -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; } diff --git a/dom/media/webaudio/AudioDestinationNode.cpp b/dom/media/webaudio/AudioDestinationNode.cpp index c0dd1d31f74..4d476614737 100644 --- a/dom/media/webaudio/AudioDestinationNode.cpp +++ b/dom/media/webaudio/AudioDestinationNode.cpp @@ -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; diff --git a/dom/media/webaudio/MediaBufferDecoder.cpp b/dom/media/webaudio/MediaBufferDecoder.cpp index 938d4089f04..e4fb265f422 100644 --- a/dom/media/webaudio/MediaBufferDecoder.cpp +++ b/dom/media/webaudio/MediaBufferDecoder.cpp @@ -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; diff --git a/dom/plugins/base/nsPluginTags.cpp b/dom/plugins/base/nsPluginTags.cpp index a89f1e4009f..d93c05e4f22 100644 --- a/dom/plugins/base/nsPluginTags.cpp +++ b/dom/plugins/base/nsPluginTags.cpp @@ -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); diff --git a/dom/storage/DOMStorage.cpp b/dom/storage/DOMStorage.cpp index 121ed5486da..a147fedebaf 100644 --- a/dom/storage/DOMStorage.cpp +++ b/dom/storage/DOMStorage.cpp @@ -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; diff --git a/dom/svg/SVGContentUtils.h b/dom/svg/SVGContentUtils.h index 9c4e71afa82..be709df33db 100644 --- a/dom/svg/SVGContentUtils.h +++ b/dom/svg/SVGContentUtils.h @@ -10,7 +10,6 @@ #define _USE_MATH_DEFINES #include -#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; } diff --git a/dom/svg/SVGFEConvolveMatrixElement.cpp b/dom/svg/SVGFEConvolveMatrixElement.cpp index 72b8e7c6c7f..328220d1186 100644 --- a/dom/svg/SVGFEConvolveMatrixElement.cpp +++ b/dom/svg/SVGFEConvolveMatrixElement.cpp @@ -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 kernel(new (fallible) float[orderX * orderY]); if (!kernel) return failureDescription; diff --git a/dom/xslt/base/txDouble.cpp b/dom/xslt/base/txDouble.cpp index 1153a12a2f7..f52d1b88516 100644 --- a/dom/xslt/base/txDouble.cpp +++ b/dom/xslt/base/txDouble.cpp @@ -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)); diff --git a/dom/xslt/xpath/txMozillaXPathTreeWalker.cpp b/dom/xslt/xpath/txMozillaXPathTreeWalker.cpp index ce23e208f26..ad18c4fb2de 100644 --- a/dom/xslt/xpath/txMozillaXPathTreeWalker.cpp +++ b/dom/xslt/xpath/txMozillaXPathTreeWalker.cpp @@ -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; } diff --git a/editor/libeditor/nsTextEditRules.cpp b/editor/libeditor/nsTextEditRules.cpp index 2da4bc29c68..21eee05a76b 100644 --- a/editor/libeditor/nsTextEditRules.cpp +++ b/editor/libeditor/nsTextEditRules.cpp @@ -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) { diff --git a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp index dbc0ae1e1ce..967de5da408 100644 --- a/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp +++ b/extensions/spellcheck/src/mozInlineSpellWordUtil.cpp @@ -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); diff --git a/gfx/layers/client/TextureClient.cpp b/gfx/layers/client/TextureClient.cpp index 7ab4ff74aed..65fff190eda 100644 --- a/gfx/layers/client/TextureClient.cpp +++ b/gfx/layers/client/TextureClient.cpp @@ -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; diff --git a/gfx/thebes/gfxFT2FontList.cpp b/gfx/thebes/gfxFT2FontList.cpp index b2ecec736b6..471cdb5900c 100644 --- a/gfx/thebes/gfxFT2FontList.cpp +++ b/gfx/thebes/gfxFT2FontList.cpp @@ -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 buf(new (fallible) uint8_t[bufSize]); if (!buf) { return; diff --git a/image/decoders/icon/win/nsIconChannel.cpp b/image/decoders/icon/win/nsIconChannel.cpp index 4ce126de06a..4f1fb717501 100644 --- a/image/decoders/icon/win/nsIconChannel.cpp +++ b/image/decoders/icon/win/nsIconChannel.cpp @@ -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); diff --git a/image/encoders/bmp/nsBMPEncoder.cpp b/image/encoders/bmp/nsBMPEncoder.cpp index 91ec88375c6..7fd00e59168 100644 --- a/image/encoders/bmp/nsBMPEncoder.cpp +++ b/image/encoders/bmp/nsBMPEncoder.cpp @@ -185,7 +185,6 @@ nsBMPEncoder::AddImageFrame(const uint8_t* aData, return NS_ERROR_INVALID_ARG; } - static fallible_t fallible = fallible_t(); nsAutoArrayPtr row(new (fallible) uint8_t[mBMPInfoHeader.width * BytesPerPixel(mBMPInfoHeader.bpp)]); diff --git a/image/src/SourceBuffer.h b/image/src/SourceBuffer.h index 0383d5c0240..34c9b0ed93e 100644 --- a/image/src/SourceBuffer.h +++ b/image/src/SourceBuffer.h @@ -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]; } diff --git a/intl/uconv/nsScriptableUConv.cpp b/intl/uconv/nsScriptableUConv.cpp index 49a8221a3b9..8bca5060544 100644 --- a/intl/uconv/nsScriptableUConv.cpp +++ b/intl/uconv/nsScriptableUConv.cpp @@ -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; } } diff --git a/layout/base/nsBidiPresUtils.cpp b/layout/base/nsBidiPresUtils.cpp index a9587a7ed2f..b812028b982 100644 --- a/layout/base/nsBidiPresUtils.cpp +++ b/layout/base/nsBidiPresUtils.cpp @@ -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; diff --git a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp index 8450f51308e..25bd478c9bc 100644 --- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp +++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp @@ -1009,7 +1009,6 @@ void MediaPipelineTransmit::PipelineListener::ProcessVideoChunk( // Send a black image. nsAutoArrayPtr pixelData; - static const fallible_t fallible = fallible_t(); pixelData = new (fallible) uint8_t[length]; if (pixelData) { // YCrCb black = 0x10 0x80 0x80 diff --git a/memory/mozalloc/fallible.h b/memory/fallible/fallible.cpp similarity index 63% rename from memory/mozalloc/fallible.h rename to memory/fallible/fallible.cpp index 0eedd11aca9..f083fe674d5 100644 --- a/memory/mozalloc/fallible.h +++ b/memory/fallible/fallible.cpp @@ -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 +} diff --git a/memory/fallible/fallible.h b/memory/fallible/fallible.h new file mode 100644 index 00000000000..0ae5d56dcf2 --- /dev/null +++ b/memory/fallible/fallible.h @@ -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 diff --git a/memory/fallible/moz.build b/memory/fallible/moz.build new file mode 100644 index 00000000000..5ef8fe0bbad --- /dev/null +++ b/memory/fallible/moz.build @@ -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', + ] diff --git a/memory/mozalloc/moz.build b/memory/mozalloc/moz.build index 72640496c41..3f952879959 100644 --- a/memory/mozalloc/moz.build +++ b/memory/mozalloc/moz.build @@ -6,7 +6,6 @@ NO_VISIBILITY_FLAGS = True EXPORTS.mozilla += [ - 'fallible.h', 'mozalloc.h', 'mozalloc_abort.h', 'mozalloc_oom.h', diff --git a/modules/libjar/nsZipArchive.cpp b/modules/libjar/nsZipArchive.cpp index 28f8d8f2f2f..c0228d92f92 100644 --- a/modules/libjar/nsZipArchive.cpp +++ b/modules/libjar/nsZipArchive.cpp @@ -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; } diff --git a/modules/libpref/nsPrefBranch.cpp b/modules/libpref/nsPrefBranch.cpp index 5135fe46137..3c2fd845c0c 100644 --- a/modules/libpref/nsPrefBranch.cpp +++ b/modules/libpref/nsPrefBranch.cpp @@ -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 cr = do_GetService("@mozilla.org/toolkit/crash-reporter;1"); diff --git a/modules/libpref/prefapi.cpp b/modules/libpref/prefapi.cpp index 467663e3646..d0ce8bef0e5 100644 --- a/modules/libpref/prefapi.cpp +++ b/modules/libpref/prefapi.cpp @@ -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; } diff --git a/moz.build b/moz.build index 1c97f6f9b5c..abd2f5ebf1f 100644 --- a/moz.build +++ b/moz.build @@ -43,6 +43,7 @@ if not CONFIG['LIBXUL_SDK']: DIRS += [ 'mozglue', + 'memory/fallible', 'memory/mozalloc', 'memory/volatile', ] diff --git a/netwerk/base/nsBufferedStreams.cpp b/netwerk/base/nsBufferedStreams.cpp index 4c44e7f1207..36041d63fbd 100644 --- a/netwerk/base/nsBufferedStreams.cpp +++ b/netwerk/base/nsBufferedStreams.cpp @@ -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; diff --git a/netwerk/base/nsNetUtil.h b/netwerk/base/nsNetUtil.h index d4a5d5dbad7..218f91d73d5 100644 --- a/netwerk/base/nsNetUtil.h +++ b/netwerk/base/nsNetUtil.h @@ -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); diff --git a/netwerk/base/nsStandardURL.cpp b/netwerk/base/nsStandardURL.cpp index 47015ed16bf..d21e25e8c35 100644 --- a/netwerk/base/nsStandardURL.cpp +++ b/netwerk/base/nsStandardURL.cpp @@ -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); diff --git a/netwerk/base/nsUnicharStreamLoader.cpp b/netwerk/base/nsUnicharStreamLoader.cpp index 9c9dc963c62..383bed9d0df 100644 --- a/netwerk/base/nsUnicharStreamLoader.cpp +++ b/netwerk/base/nsUnicharStreamLoader.cpp @@ -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; } diff --git a/netwerk/cache/nsCacheEntry.cpp b/netwerk/cache/nsCacheEntry.cpp index 60c4e51bc76..7149bbfab68 100644 --- a/netwerk/cache/nsCacheEntry.cpp +++ b/netwerk/cache/nsCacheEntry.cpp @@ -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; diff --git a/netwerk/cache/nsDiskCacheDeviceSQL.cpp b/netwerk/cache/nsDiskCacheDeviceSQL.cpp index 3e44aa7d539..dd1774c9b0f 100644 --- a/netwerk/cache/nsDiskCacheDeviceSQL.cpp +++ b/netwerk/cache/nsDiskCacheDeviceSQL.cpp @@ -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); diff --git a/netwerk/protocol/http/nsHttp.cpp b/netwerk/protocol/http/nsHttp.cpp index 8cc0162cec3..5f10195744e 100644 --- a/netwerk/protocol/http/nsHttp.cpp +++ b/netwerk/protocol/http/nsHttp.cpp @@ -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; } diff --git a/netwerk/protocol/websocket/WebSocketChannel.cpp b/netwerk/protocol/websocket/WebSocketChannel.cpp index e7ea9f2032a..0187ffbb2a5 100644 --- a/netwerk/protocol/websocket/WebSocketChannel.cpp +++ b/netwerk/protocol/websocket/WebSocketChannel.cpp @@ -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; } } diff --git a/netwerk/streamconv/converters/nsDirIndexParser.cpp b/netwerk/streamconv/converters/nsDirIndexParser.cpp index f68d3df3b89..abfce2f1d0b 100644 --- a/netwerk/streamconv/converters/nsDirIndexParser.cpp +++ b/netwerk/streamconv/converters/nsDirIndexParser.cpp @@ -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. diff --git a/parser/html/nsHtml5OwningUTF16Buffer.cpp b/parser/html/nsHtml5OwningUTF16Buffer.cpp index dcd2aec196a..45bbb70dc5f 100644 --- a/parser/html/nsHtml5OwningUTF16Buffer.cpp +++ b/parser/html/nsHtml5OwningUTF16Buffer.cpp @@ -39,13 +39,12 @@ nsHtml5OwningUTF16Buffer::~nsHtml5OwningUTF16Buffer() already_AddRefed 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 newObj = - new (fallible) nsHtml5OwningUTF16Buffer(newBuf); + new (mozilla::fallible) nsHtml5OwningUTF16Buffer(newBuf); if (!newObj) { delete[] newBuf; return nullptr; diff --git a/parser/html/nsHtml5StreamParser.cpp b/parser/html/nsHtml5StreamParser.cpp index 9c58ef10e02..536f139ab8c 100644 --- a/parser/html/nsHtml5StreamParser.cpp +++ b/parser/html/nsHtml5StreamParser.cpp @@ -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 data(new (fallible) uint8_t[aLength]); + nsAutoArrayPtr data(new (mozilla::fallible) uint8_t[aLength]); if (!data) { return mExecutor->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY); } diff --git a/parser/htmlparser/nsHTMLEntities.cpp b/parser/htmlparser/nsHTMLEntities.cpp index b69c8ddf444..ad2cdf3123b 100644 --- a/parser/htmlparser/nsHTMLEntities.cpp +++ b/parser/htmlparser/nsHTMLEntities.cpp @@ -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; } diff --git a/parser/htmlparser/nsScannerString.cpp b/parser/htmlparser/nsScannerString.cpp index a596498e9bf..45e3d7f16c7 100644 --- a/parser/htmlparser/nsScannerString.cpp +++ b/parser/htmlparser/nsScannerString.cpp @@ -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); diff --git a/security/manager/ssl/src/nsCertTree.cpp b/security/manager/ssl/src/nsCertTree.cpp index f7d82d9876b..c041079629b 100644 --- a/security/manager/ssl/src/nsCertTree.cpp +++ b/security/manager/ssl/src/nsCertTree.cpp @@ -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; diff --git a/services/crypto/component/nsSyncJPAKE.cpp b/services/crypto/component/nsSyncJPAKE.cpp index 5c3a3b1265c..e72e908193a 100644 --- a/services/crypto/component/nsSyncJPAKE.cpp +++ b/services/crypto/component/nsSyncJPAKE.cpp @@ -16,7 +16,7 @@ #include #include -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); diff --git a/toolkit/components/downloads/SQLFunctions.cpp b/toolkit/components/downloads/SQLFunctions.cpp index 883c993b089..7540d39b7a4 100644 --- a/toolkit/components/downloads/SQLFunctions.cpp +++ b/toolkit/components/downloads/SQLFunctions.cpp @@ -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(aBytes), aNumBytes, diff --git a/toolkit/components/places/Helpers.cpp b/toolkit/components/places/Helpers.cpp index 27298f87102..5688b73d8ed 100644 --- a/toolkit/components/places/Helpers.cpp +++ b/toolkit/components/places/Helpers.cpp @@ -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(aBytes), aNumBytes, diff --git a/toolkit/components/telemetry/Telemetry.cpp b/toolkit/components/telemetry/Telemetry.cpp index e48056ac221..a1c03008b9c 100644 --- a/toolkit/components/telemetry/Telemetry.cpp +++ b/toolkit/components/telemetry/Telemetry.cpp @@ -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; } diff --git a/widget/windows/nsIMM32Handler.cpp b/widget/windows/nsIMM32Handler.cpp index 6aaae7bc45a..e5a922d0fbb 100644 --- a/widget/windows/nsIMM32Handler.cpp +++ b/widget/windows/nsIMM32Handler.cpp @@ -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; diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index 71ea2d6cce1..30077dd8ed3 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -1357,7 +1357,7 @@ private: if (!aPi) { MOZ_CRASH(); } - if (!aQueue.Push(aPi, fallible_t())) { + if (!aQueue.Push(aPi, fallible)) { mVisitor.Failed(); } } diff --git a/xpcom/ds/nsStaticNameTable.cpp b/xpcom/ds/nsStaticNameTable.cpp index 50a39645c0e..6d8950cf15e 100644 --- a/xpcom/ds/nsStaticNameTable.cpp +++ b/xpcom/ds/nsStaticNameTable.cpp @@ -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; } diff --git a/xpcom/ds/nsSupportsPrimitives.cpp b/xpcom/ds/nsSupportsPrimitives.cpp index 6fd41bb8a09..34235ce8f47 100644 --- a/xpcom/ds/nsSupportsPrimitives.cpp +++ b/xpcom/ds/nsSupportsPrimitives.cpp @@ -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; } diff --git a/xpcom/glue/moz.build b/xpcom/glue/moz.build index 0b296745023..27c6d1473b2 100644 --- a/xpcom/glue/moz.build +++ b/xpcom/glue/moz.build @@ -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', +] diff --git a/xpcom/glue/nomozalloc/moz.build b/xpcom/glue/nomozalloc/moz.build index d7418549736..df53bca9bb7 100644 --- a/xpcom/glue/nomozalloc/moz.build +++ b/xpcom/glue/nomozalloc/moz.build @@ -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', +] diff --git a/xpcom/glue/nsBaseHashtable.h b/xpcom/glue/nsBaseHashtable.h index 031048cc223..7a701b8c35b 100644 --- a/xpcom/glue/nsBaseHashtable.h +++ b/xpcom/glue/nsBaseHashtable.h @@ -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()); } } diff --git a/xpcom/glue/nsDeque.h b/xpcom/glue/nsDeque.h index 279af93b6dd..2f162d1ee9a 100644 --- a/xpcom/glue/nsDeque.h +++ b/xpcom/glue/nsDeque.h @@ -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*)); } } diff --git a/xpcom/glue/nsRefPtrHashtable.h b/xpcom/glue/nsRefPtrHashtable.h index df9227893fd..be9777d9065 100644 --- a/xpcom/glue/nsRefPtrHashtable.h +++ b/xpcom/glue/nsRefPtrHashtable.h @@ -147,7 +147,7 @@ void nsRefPtrHashtable::Put(KeyType aKey, already_AddRefed 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()); } } diff --git a/xpcom/glue/nsTHashtable.h b/xpcom/glue/nsTHashtable.h index 967df230be2..2a0d5dc5e0d 100644 --- a/xpcom/glue/nsTHashtable.h +++ b/xpcom/glue/nsTHashtable.h @@ -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()); } diff --git a/xpcom/glue/pldhash.cpp b/xpcom/glue/pldhash.cpp index 6c8a1c86484..3d95df38695 100644 --- a/xpcom/glue/pldhash.cpp +++ b/xpcom/glue/pldhash.cpp @@ -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 } diff --git a/xpcom/glue/standalone/moz.build b/xpcom/glue/standalone/moz.build index 9942a3be49f..a979e6b7fb9 100644 --- a/xpcom/glue/standalone/moz.build +++ b/xpcom/glue/standalone/moz.build @@ -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', +] diff --git a/xpcom/glue/standalone/staticruntime/moz.build b/xpcom/glue/standalone/staticruntime/moz.build index a4c84e56787..cb9c2445989 100644 --- a/xpcom/glue/standalone/staticruntime/moz.build +++ b/xpcom/glue/standalone/staticruntime/moz.build @@ -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', +] diff --git a/xpcom/glue/staticruntime/moz.build b/xpcom/glue/staticruntime/moz.build index 86b17efd1b3..aa4960825e7 100644 --- a/xpcom/glue/staticruntime/moz.build +++ b/xpcom/glue/staticruntime/moz.build @@ -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', +] diff --git a/xpcom/io/Base64.cpp b/xpcom/io/Base64.cpp index 34e69bf3e81..91f1d54710e 100644 --- a/xpcom/io/Base64.cpp +++ b/xpcom/io/Base64.cpp @@ -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 diff --git a/xpcom/io/SnappyCompressOutputStream.cpp b/xpcom/io/SnappyCompressOutputStream.cpp index a7485581d52..89b8a08081e 100644 --- a/xpcom/io/SnappyCompressOutputStream.cpp +++ b/xpcom/io/SnappyCompressOutputStream.cpp @@ -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; } diff --git a/xpcom/io/SnappyUncompressInputStream.cpp b/xpcom/io/SnappyUncompressInputStream.cpp index 10fca0e8560..119b1af8e84 100644 --- a/xpcom/io/SnappyUncompressInputStream.cpp +++ b/xpcom/io/SnappyUncompressInputStream.cpp @@ -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; } diff --git a/xpcom/io/nsBinaryStream.cpp b/xpcom/io/nsBinaryStream.cpp index fee287a4e12..289730f076c 100644 --- a/xpcom/io/nsBinaryStream.cpp +++ b/xpcom/io/nsBinaryStream.cpp @@ -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; } diff --git a/xpcom/io/nsLocalFileWin.cpp b/xpcom/io/nsLocalFileWin.cpp index cacde9ae096..e647e82112c 100644 --- a/xpcom/io/nsLocalFileWin.cpp +++ b/xpcom/io/nsLocalFileWin.cpp @@ -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()))) { diff --git a/xpcom/io/nsNativeCharsetUtils.cpp b/xpcom/io/nsNativeCharsetUtils.cpp index 8f7b500e45a..447963e9663 100644 --- a/xpcom/io/nsNativeCharsetUtils.cpp +++ b/xpcom/io/nsNativeCharsetUtils.cpp @@ -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) { diff --git a/xpcom/string/nsAString.h b/xpcom/string/nsAString.h index 5ad82735d3f..1925a4a8ecb 100644 --- a/xpcom/string/nsAString.h +++ b/xpcom/string/nsAString.h @@ -14,8 +14,6 @@ #include #include -#include "mozilla/fallible.h" - #define kNotFound -1 // declare nsAString diff --git a/xpcom/string/nsReadableUtils.cpp b/xpcom/string/nsReadableUtils.cpp index 81b740e91e2..9de9fe71de4 100644 --- a/xpcom/string/nsReadableUtils.cpp +++ b/xpcom/string/nsReadableUtils.cpp @@ -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; } diff --git a/xpcom/string/nsTStringObsolete.cpp b/xpcom/string/nsTStringObsolete.cpp index fc3e790da70..df4dec29644 100644 --- a/xpcom/string/nsTStringObsolete.cpp +++ b/xpcom/string/nsTStringObsolete.cpp @@ -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())); diff --git a/xpcom/string/nsTSubstring.cpp b/xpcom/string/nsTSubstring.cpp index ee1088c9109..29f36dd57c7 100644 --- a/xpcom/string/nsTSubstring.cpp +++ b/xpcom/string/nsTSubstring.cpp @@ -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; } diff --git a/xpcom/string/nsTSubstring.h b/xpcom/string/nsTSubstring.h index 313bc9523ee..a967988e473 100644 --- a/xpcom/string/nsTSubstring.h +++ b/xpcom/string/nsTSubstring.h @@ -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(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(aData), fallible_t()); + return Assign(static_cast(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(aData), aLength, fallible_t()); + return Assign(static_cast(aData), aLength, + aFallible); } #endif @@ -407,11 +409,11 @@ public: AssignASCII(aData, mozilla::AssertedCast(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(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(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(aData), aNewLen, - fallible_t()); + aFallible); } #endif diff --git a/xpcom/tests/TestPLDHash.cpp b/xpcom/tests/TestPLDHash.cpp index 8609c3f5195..fdb6ea5bbfe 100644 --- a/xpcom/tests/TestPLDHash.cpp +++ b/xpcom/tests/TestPLDHash.cpp @@ -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. diff --git a/xpcom/tests/gtest/TestStrings.cpp b/xpcom/tests/gtest/TestStrings.cpp index f38e868ee7e..dc5fd6fbfb4 100644 --- a/xpcom/tests/gtest/TestStrings.cpp +++ b/xpcom/tests/gtest/TestStrings.cpp @@ -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)); } }