diff --git a/source/includes/CarlaDefines.h b/source/includes/CarlaDefines.h index 6ae1f0217..13f34f7aa 100644 --- a/source/includes/CarlaDefines.h +++ b/source/includes/CarlaDefines.h @@ -209,6 +209,17 @@ private: \ static void operator delete(void*); #endif +/* Define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION */ +#ifdef CARLA_PROPER_CPP11_SUPPORT +# define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \ +private: \ + static void* operator new(size_t) = delete; +#else +# define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \ +private: \ + static void* operator new(size_t); +#endif + /* Define EXTERN_C */ #ifdef __cplusplus # define EXTERN_C extern "C" diff --git a/source/utils/CarlaRingBuffer.hpp b/source/utils/CarlaRingBuffer.hpp index 761103129..931838a5c 100644 --- a/source/utils/CarlaRingBuffer.hpp +++ b/source/utils/CarlaRingBuffer.hpp @@ -75,6 +75,9 @@ struct BigStackBuffer { uint8_t buf[size]; }; +#define HeapBuffer_INIT {0, 0, 0, 0, false, nullptr} +#define StackBuffer_INIT {0, 0, 0, false, {0}} + // ----------------------------------------------------------------------- // CarlaRingBuffer templated class @@ -85,12 +88,9 @@ public: CarlaRingBuffer() noexcept : fBuffer(nullptr) {} - CarlaRingBuffer(BufferStruct* const ringBuf) noexcept - : fBuffer(ringBuf) - { - if (ringBuf != nullptr) - clear(); - } + virtual ~CarlaRingBuffer() noexcept {} + + // ------------------------------------------------------------------- void clear() noexcept { @@ -376,7 +376,7 @@ protected: private: BufferStruct* fBuffer; - CARLA_PREVENT_HEAP_ALLOCATION + CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION CARLA_DECLARE_NON_COPY_CLASS(CarlaRingBuffer) }; @@ -387,12 +387,9 @@ class CarlaHeapRingBuffer : public CarlaRingBuffer { public: CarlaHeapRingBuffer() noexcept - : CarlaRingBuffer() - { - carla_zeroStruct(fHeapBuffer); - } + : fHeapBuffer(HeapBuffer_INIT) {} - ~CarlaHeapRingBuffer() noexcept + ~CarlaHeapRingBuffer() noexcept override { if (fHeapBuffer.buf == nullptr) return; @@ -430,7 +427,7 @@ public: private: HeapBuffer fHeapBuffer; - CARLA_PREVENT_HEAP_ALLOCATION + CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION CARLA_DECLARE_NON_COPY_CLASS(CarlaHeapRingBuffer) }; @@ -441,12 +438,15 @@ class CarlaStackRingBuffer : public CarlaRingBuffer { public: CarlaStackRingBuffer() noexcept - : CarlaRingBuffer(&fStackBuffer) {} + : fStackBuffer(StackBuffer_INIT) + { + setRingBuffer(&fStackBuffer, true); // FIXME + } private: StackBuffer fStackBuffer; - CARLA_PREVENT_HEAP_ALLOCATION + CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION CARLA_DECLARE_NON_COPY_CLASS(CarlaStackRingBuffer) };