| @@ -737,9 +737,7 @@ bool File::appendText (const String& text, | |||||
| const bool writeUnicodeHeaderBytes) const | const bool writeUnicodeHeaderBytes) const | ||||
| { | { | ||||
| FileOutputStream out (*this); | FileOutputStream out (*this); | ||||
| if (out.failedToOpen()) | |||||
| return false; | |||||
| CARLA_SAFE_ASSERT_RETURN(out.failedToOpen(), false); | |||||
| out.writeText (text, asUnicode, writeUnicodeHeaderBytes); | out.writeText (text, asUnicode, writeUnicodeHeaderBytes); | ||||
| return true; | return true; | ||||
| @@ -766,7 +764,10 @@ bool File::hasIdenticalContentTo (const File& other) const | |||||
| if (in1.openedOk() && in2.openedOk()) | if (in1.openedOk() && in2.openedOk()) | ||||
| { | { | ||||
| const int bufferSize = 4096; | const int bufferSize = 4096; | ||||
| HeapBlock<char> buffer1 (bufferSize), buffer2 (bufferSize); | |||||
| HeapBlock<char> buffer1, buffer2; | |||||
| CARLA_SAFE_ASSERT_RETURN(buffer1.malloc (bufferSize), false); | |||||
| CARLA_SAFE_ASSERT_RETURN(buffer2.malloc (bufferSize), false); | |||||
| for (;;) | for (;;) | ||||
| { | { | ||||
| @@ -1545,7 +1546,9 @@ private: | |||||
| #else | #else | ||||
| static String getLinkedFile (const String& file) | static String getLinkedFile (const String& file) | ||||
| { | { | ||||
| HeapBlock<char> buffer (8194); | |||||
| HeapBlock<char> buffer; | |||||
| CARLA_SAFE_ASSERT_RETURN(buffer.malloc(8194), String()); | |||||
| const int numBytes = (int) readlink (file.toRawUTF8(), buffer, 8192); | const int numBytes = (int) readlink (file.toRawUTF8(), buffer, 8192); | ||||
| return String::fromUTF8 (buffer, jmax (0, numBytes)); | return String::fromUTF8 (buffer, jmax (0, numBytes)); | ||||
| } | } | ||||
| @@ -36,10 +36,12 @@ FileOutputStream::FileOutputStream (const File& f, const size_t bufferSizeToUse) | |||||
| status (Result::ok()), | status (Result::ok()), | ||||
| currentPosition (0), | currentPosition (0), | ||||
| bufferSize (bufferSizeToUse), | bufferSize (bufferSizeToUse), | ||||
| bytesInBuffer (0), | |||||
| buffer (jmax (bufferSizeToUse, (size_t) 16)) | |||||
| bytesInBuffer (0) | |||||
| { | { | ||||
| openHandle(); | |||||
| if (buffer.malloc(jmax (bufferSizeToUse, (size_t) 16))) | |||||
| openHandle(); | |||||
| else | |||||
| status = Result::fail ("Allocation failure"); | |||||
| } | } | ||||
| FileOutputStream::~FileOutputStream() | FileOutputStream::~FileOutputStream() | ||||
| @@ -31,17 +31,6 @@ | |||||
| namespace water { | namespace water { | ||||
| #if ! JUCE_EXCEPTIONS_DISABLED | |||||
| namespace HeapBlockHelper | |||||
| { | |||||
| template <bool shouldThrow> | |||||
| struct ThrowOnFail { static void checkPointer (void*) {} }; | |||||
| template<> | |||||
| struct ThrowOnFail<true> { static void checkPointer (void* data) { if (data == nullptr) throw std::bad_alloc(); } }; | |||||
| } | |||||
| #endif | |||||
| //============================================================================== | //============================================================================== | ||||
| /** | /** | ||||
| Very simple container class to hold a pointer to some data on the heap. | Very simple container class to hold a pointer to some data on the heap. | ||||
| @@ -102,33 +91,6 @@ public: | |||||
| { | { | ||||
| } | } | ||||
| /** Creates a HeapBlock containing a number of elements. | |||||
| The contents of the block are undefined, as it will have been created by a | |||||
| malloc call. | |||||
| If you want an array of zero values, you can use the calloc() method or the | |||||
| other constructor that takes an InitialisationState parameter. | |||||
| */ | |||||
| explicit HeapBlock (const size_t numElements) | |||||
| : data (static_cast<ElementType*> (std::malloc (numElements * sizeof (ElementType)))) | |||||
| { | |||||
| throwOnAllocationFailure(); | |||||
| } | |||||
| /** Creates a HeapBlock containing a number of elements. | |||||
| The initialiseToZero parameter determines whether the new memory should be cleared, | |||||
| or left uninitialised. | |||||
| */ | |||||
| HeapBlock (const size_t numElements, const bool initialiseToZero) | |||||
| : data (static_cast<ElementType*> (initialiseToZero | |||||
| ? std::calloc (numElements, sizeof (ElementType)) | |||||
| : std::malloc (numElements * sizeof (ElementType)))) | |||||
| { | |||||
| throwOnAllocationFailure(); | |||||
| } | |||||
| /** Destructor. | /** Destructor. | ||||
| This will free the data, if any has been allocated. | This will free the data, if any has been allocated. | ||||
| */ | */ | ||||
| @@ -297,15 +259,6 @@ public: | |||||
| private: | private: | ||||
| //============================================================================== | //============================================================================== | ||||
| ElementType* data; | ElementType* data; | ||||
| void throwOnAllocationFailure() const | |||||
| { | |||||
| #if JUCE_EXCEPTIONS_DISABLED | |||||
| jassert (data != nullptr); // without exceptions, you'll need to find a better way to handle this failure case. | |||||
| #else | |||||
| HeapBlockHelper::ThrowOnFail<throwOnFailure>::checkPointer (data); | |||||
| #endif | |||||
| } | |||||
| }; | }; | ||||
| } | } | ||||
| @@ -648,7 +648,8 @@ bool MidiMessage::isSysEx() const noexcept | |||||
| MidiMessage MidiMessage::createSysExMessage (const void* sysexData, const int dataSize) | MidiMessage MidiMessage::createSysExMessage (const void* sysexData, const int dataSize) | ||||
| { | { | ||||
| HeapBlock<uint8> m ((size_t) dataSize + 2); | |||||
| HeapBlock<uint8> m; | |||||
| CARLA_SAFE_ASSERT_RETURN(m.malloc((size_t) dataSize + 2U), MidiMessage()); | |||||
| m[0] = 0xf0; | m[0] = 0xf0; | ||||
| memcpy (m + 1, sysexData, (size_t) dataSize); | memcpy (m + 1, sysexData, (size_t) dataSize); | ||||
| @@ -226,17 +226,4 @@ String InputStream::readEntireStreamAsString() | |||||
| return mo.toString(); | return mo.toString(); | ||||
| } | } | ||||
| //============================================================================== | |||||
| void InputStream::skipNextBytes (int64 numBytesToSkip) | |||||
| { | |||||
| if (numBytesToSkip > 0) | |||||
| { | |||||
| const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384); | |||||
| HeapBlock<char> temp ((size_t) skipBufferSize); | |||||
| while (numBytesToSkip > 0 && ! isExhausted()) | |||||
| numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize)); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -246,15 +246,6 @@ public: | |||||
| */ | */ | ||||
| virtual bool setPosition (int64 newPosition) = 0; | virtual bool setPosition (int64 newPosition) = 0; | ||||
| /** Reads and discards a number of bytes from the stream. | |||||
| Some input streams might implement this efficiently, but the base | |||||
| class will just keep reading data until the requisite number of bytes | |||||
| have been done. | |||||
| */ | |||||
| virtual void skipNextBytes (int64 numBytesToSkip); | |||||
| protected: | protected: | ||||
| //============================================================================== | //============================================================================== | ||||
| InputStream() noexcept {} | InputStream() noexcept {} | ||||
| @@ -1706,7 +1706,8 @@ bool String::containsNonWhitespaceChars() const noexcept | |||||
| //===================================================================================================================== | //===================================================================================================================== | ||||
| static String getStringFromWindows1252Codepage (const char* data, size_t num) | static String getStringFromWindows1252Codepage (const char* data, size_t num) | ||||
| { | { | ||||
| HeapBlock<char> unicode (num + 1); | |||||
| HeapBlock<char> unicode; | |||||
| CARLA_SAFE_ASSERT_RETURN(unicode.malloc(num + 1), String()); | |||||
| for (size_t i = 0; i < num; ++i) | for (size_t i = 0; i < num; ++i) | ||||
| unicode[i] = CharacterFunctions::getUnicodeCharFromWindows1252Codepage ((uint8) data[i]); | unicode[i] = CharacterFunctions::getUnicodeCharFromWindows1252Codepage ((uint8) data[i]); | ||||
| @@ -1745,12 +1746,17 @@ String String::formatted (const String pf, ... ) | |||||
| { | { | ||||
| size_t bufferSize = 256; | size_t bufferSize = 256; | ||||
| HeapBlock<char> temp; | |||||
| CARLA_SAFE_ASSERT_RETURN(temp.malloc(bufferSize), String()); | |||||
| for (;;) | for (;;) | ||||
| { | { | ||||
| va_list args; | va_list args; | ||||
| va_start (args, pf); | va_start (args, pf); | ||||
| HeapBlock<char> temp (bufferSize); | |||||
| // FIXME - needed? | |||||
| temp.clear (bufferSize); | |||||
| const int num = vsnprintf (temp.getData(), bufferSize - 1, pf.toRawUTF8(), args); | const int num = vsnprintf (temp.getData(), bufferSize - 1, pf.toRawUTF8(), args); | ||||
| va_end (args); | va_end (args); | ||||
| @@ -53,13 +53,6 @@ | |||||
| #if __has_feature (cxx_deleted_functions) | #if __has_feature (cxx_deleted_functions) | ||||
| #define JUCE_DELETED_FUNCTION = delete | #define JUCE_DELETED_FUNCTION = delete | ||||
| #endif | #endif | ||||
| #ifndef JUCE_EXCEPTIONS_DISABLED | |||||
| #if ! __has_feature (cxx_exceptions) | |||||
| #define JUCE_EXCEPTIONS_DISABLED 1 | |||||
| #endif | |||||
| #endif | |||||
| #endif | #endif | ||||
| //============================================================================== | //============================================================================== | ||||