| @@ -241,6 +241,7 @@ struct EngineOptions { | |||
| #ifndef DOXYGEN | |||
| EngineOptions() noexcept; | |||
| ~EngineOptions() noexcept; | |||
| CARLA_DECLARE_NON_COPY_STRUCT(EngineOptions) | |||
| #endif | |||
| }; | |||
| @@ -137,6 +137,7 @@ typedef struct _CarlaPluginInfo { | |||
| */ | |||
| _CarlaPluginInfo() noexcept; | |||
| ~_CarlaPluginInfo() noexcept; | |||
| CARLA_DECLARE_NON_COPY_STRUCT(_CarlaPluginInfo) | |||
| #endif | |||
| } CarlaPluginInfo; | |||
| @@ -212,6 +213,7 @@ typedef struct _CarlaNativePluginInfo { | |||
| * C++ constructor. | |||
| */ | |||
| _CarlaNativePluginInfo() noexcept; | |||
| CARLA_DECLARE_NON_COPY_STRUCT(_CarlaNativePluginInfo) | |||
| #endif | |||
| } CarlaNativePluginInfo; | |||
| @@ -267,6 +269,7 @@ typedef struct _CarlaParameterInfo { | |||
| */ | |||
| _CarlaParameterInfo() noexcept; | |||
| ~_CarlaParameterInfo() noexcept; | |||
| CARLA_DECLARE_NON_COPY_STRUCT(_CarlaParameterInfo) | |||
| #endif | |||
| } CarlaParameterInfo; | |||
| @@ -292,6 +295,7 @@ typedef struct _CarlaScalePointInfo { | |||
| */ | |||
| _CarlaScalePointInfo() noexcept; | |||
| ~_CarlaScalePointInfo() noexcept; | |||
| CARLA_DECLARE_NON_COPY_STRUCT(_CarlaScalePointInfo) | |||
| #endif | |||
| } CarlaScalePointInfo; | |||
| @@ -57,8 +57,10 @@ struct CarlaBackendStandalone { | |||
| : engine(nullptr), | |||
| engineCallback(nullptr), | |||
| engineCallbackPtr(nullptr), | |||
| engineOptions(), | |||
| fileCallback(nullptr), | |||
| fileCallbackPtr(nullptr) | |||
| fileCallbackPtr(nullptr), | |||
| lastError() | |||
| { | |||
| #ifdef BUILD_BRIDGE | |||
| engineOptions.processMode = CB::ENGINE_PROCESS_MODE_BRIDGE; | |||
| @@ -102,6 +104,8 @@ class CarlaNSM | |||
| public: | |||
| CarlaNSM() noexcept | |||
| : fOscServer(nullptr), | |||
| fClientId(), | |||
| fProjectPath(), | |||
| fHasBroadcast(false), | |||
| fHasShowHideUI(false) {} | |||
| @@ -376,7 +376,7 @@ bool CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, cons | |||
| # ifndef CARLA_OS_WIN | |||
| if (btype == BINARY_NATIVE) | |||
| { | |||
| bridgeBinary += OS_SEP_STR "carla-bridge-native"; | |||
| bridgeBinary += CARLA_OS_SEP_STR "carla-bridge-native"; | |||
| } | |||
| else | |||
| # endif | |||
| @@ -384,16 +384,16 @@ bool CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, cons | |||
| switch (btype) | |||
| { | |||
| case BINARY_POSIX32: | |||
| bridgeBinary += OS_SEP_STR "carla-bridge-posix32"; | |||
| bridgeBinary += CARLA_OS_SEP_STR "carla-bridge-posix32"; | |||
| break; | |||
| case BINARY_POSIX64: | |||
| bridgeBinary += OS_SEP_STR "carla-bridge-posix64"; | |||
| bridgeBinary += CARLA_OS_SEP_STR "carla-bridge-posix64"; | |||
| break; | |||
| case BINARY_WIN32: | |||
| bridgeBinary += OS_SEP_STR "carla-bridge-win32.exe"; | |||
| bridgeBinary += CARLA_OS_SEP_STR "carla-bridge-win32.exe"; | |||
| break; | |||
| case BINARY_WIN64: | |||
| bridgeBinary += OS_SEP_STR "carla-bridge-win64.exe"; | |||
| bridgeBinary += CARLA_OS_SEP_STR "carla-bridge-win64.exe"; | |||
| break; | |||
| default: | |||
| bridgeBinary.clear(); | |||
| @@ -245,7 +245,8 @@ EngineTimeInfo::EngineTimeInfo() noexcept | |||
| : playing(false), | |||
| frame(0), | |||
| usecs(0), | |||
| valid(0x0) {} | |||
| valid(0x0), | |||
| bbt() {} | |||
| void EngineTimeInfo::clear() noexcept | |||
| { | |||
| @@ -85,9 +85,26 @@ const char* getCarlaRackFullPortNameFromId(const /*RackGraphCarlaPortIds*/ uint | |||
| return nullptr; | |||
| } | |||
| // ----------------------------------------------------------------------- | |||
| // RackGraph Audio | |||
| RackGraph::Audio::Audio() noexcept | |||
| : mutex(), | |||
| connectedIn1(), | |||
| connectedIn2(), | |||
| connectedOut1(), | |||
| connectedOut2(), | |||
| inBuf{0, 0}, | |||
| inBufTmp{0, 0}, | |||
| outBuf{0, 0} {} | |||
| // ----------------------------------------------------------------------- | |||
| // RackGraph MIDI | |||
| RackGraph::MIDI::MIDI() noexcept | |||
| : ins(), | |||
| outs() {} | |||
| const char* RackGraph::MIDI::getName(const bool isInput, const uint portId) const noexcept | |||
| { | |||
| for (LinkedList<PortNameToId>::Itenerator it = isInput ? ins.begin() : outs.begin(); it.valid(); it.next()) | |||
| @@ -124,9 +141,13 @@ uint RackGraph::MIDI::getPortId(const bool isInput, const char portName[], bool* | |||
| // RackGraph | |||
| RackGraph::RackGraph(const uint32_t bufferSize, const uint32_t ins, const uint32_t outs) noexcept | |||
| : inputs(ins), | |||
| : connections(), | |||
| inputs(ins), | |||
| outputs(outs), | |||
| isOffline(false) | |||
| isOffline(false), | |||
| retCon(), | |||
| audio(), | |||
| midi() | |||
| { | |||
| audio.inBuf[0] = audio.inBuf[1] = nullptr; | |||
| audio.inBufTmp[0] = audio.inBufTmp[1] = nullptr; | |||
| @@ -76,6 +76,10 @@ struct RackGraph { | |||
| float* inBuf[2]; | |||
| float* inBufTmp[2]; | |||
| float* outBuf[2]; | |||
| // c++ compat stuff | |||
| Audio() noexcept; | |||
| CARLA_PREVENT_HEAP_ALLOCATION | |||
| CARLA_DECLARE_NON_COPY_CLASS(Audio) | |||
| } audio; | |||
| struct MIDI { | |||
| @@ -83,6 +87,10 @@ struct RackGraph { | |||
| LinkedList<PortNameToId> outs; | |||
| const char* getName(const bool isInput, const uint portId) const noexcept; | |||
| uint getPortId(const bool isInput, const char portName[], bool* const ok = nullptr) const noexcept; | |||
| // c++ compat stuff | |||
| MIDI() noexcept; | |||
| CARLA_PREVENT_HEAP_ALLOCATION | |||
| CARLA_DECLARE_NON_COPY_CLASS(MIDI) | |||
| } midi; | |||
| RackGraph(const uint32_t bufferSize, const uint32_t inputs, const uint32_t outputs) noexcept; | |||
| @@ -67,7 +67,8 @@ EngineInternalTime::EngineInternalTime() noexcept | |||
| EngineNextAction::EngineNextAction() noexcept | |||
| : opcode(kEnginePostActionNull), | |||
| pluginId(0), | |||
| value(0) {} | |||
| value(0), | |||
| waitEvent() {} | |||
| EngineNextAction::~EngineNextAction() noexcept | |||
| { | |||
| @@ -105,15 +106,25 @@ CarlaEngine::ProtectedData::ProtectedData(CarlaEngine* const engine) noexcept | |||
| isIdling(0), | |||
| curPluginCount(0), | |||
| maxPluginNumber(0), | |||
| #ifndef BUILD_BRIDGE | |||
| nextPluginId(0), | |||
| plugins(nullptr) {} | |||
| #else | |||
| nextPluginId(0) | |||
| lastError(), | |||
| name(), | |||
| options(), | |||
| timeInfo(), | |||
| #ifndef BUILD_BRIDGE | |||
| plugins(nullptr), | |||
| #endif | |||
| events(), | |||
| #ifndef BUILD_BRIDGE | |||
| graph(), | |||
| #endif | |||
| time(), | |||
| nextAction() | |||
| { | |||
| #ifdef BUILD_BRIDGE | |||
| carla_zeroStruct(plugins, 1); | |||
| } | |||
| #endif | |||
| } | |||
| CarlaEngine::ProtectedData::~ProtectedData() noexcept | |||
| { | |||
| @@ -26,6 +26,9 @@ | |||
| using juce::Atomic; | |||
| using juce::WaitableEvent; | |||
| // FIXME only use CARLA_PREVENT_HEAP_ALLOCATION for structs | |||
| // maybe separate macro | |||
| CARLA_BACKEND_START_NAMESPACE | |||
| // ----------------------------------------------------------------------- | |||
| @@ -87,6 +90,7 @@ private: | |||
| PatchbayGraph* fPatchbay; | |||
| }; | |||
| CARLA_PREVENT_HEAP_ALLOCATION | |||
| CARLA_DECLARE_NON_COPY_STRUCT(EngineInternalGraph) | |||
| }; | |||
| #endif | |||
| @@ -73,7 +73,8 @@ public: | |||
| : CarlaEngineAudioPort(client, isInputPort), | |||
| fJackClient(jackClient), | |||
| fJackPort(jackPort), | |||
| kDeletionCallback(delCallback) | |||
| kDeletionCallback(delCallback), | |||
| leakDetector_CarlaEngineJackAudioPort() | |||
| { | |||
| carla_debug("CarlaEngineJackAudioPort::CarlaEngineJackAudioPort(%s, %p, %p)", bool2str(isInputPort), jackClient, jackPort); | |||
| @@ -163,7 +164,8 @@ public: | |||
| : CarlaEngineCVPort(client, isInputPort), | |||
| fJackClient(jackClient), | |||
| fJackPort(jackPort), | |||
| kDeletionCallback(delCallback) | |||
| kDeletionCallback(delCallback), | |||
| leakDetector_CarlaEngineJackCVPort() | |||
| { | |||
| carla_debug("CarlaEngineJackCVPort::CarlaEngineJackCVPort(%s, %p, %p)", bool2str(isInputPort), jackClient, jackPort); | |||
| @@ -252,7 +254,9 @@ public: | |||
| fJackClient(jackClient), | |||
| fJackPort(jackPort), | |||
| fJackBuffer(nullptr), | |||
| kDeletionCallback(delCallback) | |||
| fRetEvent(kFallbackJackEngineEvent), | |||
| kDeletionCallback(delCallback), | |||
| leakDetector_CarlaEngineJackEventPort() | |||
| { | |||
| carla_debug("CarlaEngineJackEventPort::CarlaEngineJackEventPort(%s, %p, %p)", bool2str(isInputPort), jackClient, jackPort); | |||
| @@ -429,7 +433,11 @@ public: | |||
| CarlaEngineJackClient(const CarlaEngine& engine, jack_client_t* const jackClient) | |||
| : CarlaEngineClient(engine), | |||
| fJackClient(jackClient), | |||
| fUseClient(engine.getProccessMode() == ENGINE_PROCESS_MODE_SINGLE_CLIENT || engine.getProccessMode() == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS) | |||
| fUseClient(engine.getProccessMode() == ENGINE_PROCESS_MODE_SINGLE_CLIENT || engine.getProccessMode() == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS), | |||
| fAudioPorts(), | |||
| fCVPorts(), | |||
| fEventPorts(), | |||
| leakDetector_CarlaEngineJackClient() | |||
| { | |||
| carla_debug("CarlaEngineJackClient::CarlaEngineJackClient(%p)", jackClient); | |||
| @@ -619,11 +627,18 @@ public: | |||
| CarlaEngineJack() | |||
| : CarlaEngine(), | |||
| fClient(nullptr), | |||
| fTransportPos(), | |||
| fTransportState(JackTransportStopped), | |||
| fFreewheel(false) | |||
| fFreewheel(false), | |||
| #ifdef BUILD_BRIDGE | |||
| , fIsRunning(false) | |||
| fIsRunning(false), | |||
| #else | |||
| fUsedGroups(), | |||
| fUsedPorts(), | |||
| fUsedConnections(), | |||
| fNewGroups(), | |||
| #endif | |||
| leakDetector_CarlaEngineJack() | |||
| { | |||
| carla_debug("CarlaEngineJack::CarlaEngineJack()"); | |||
| @@ -54,7 +54,8 @@ class CarlaEngineNativeUI : public CarlaExternalUI | |||
| { | |||
| public: | |||
| CarlaEngineNativeUI(CarlaEngine* const engine) | |||
| : fEngine(engine) | |||
| : fEngine(engine), | |||
| leakDetector_CarlaEngineNativeUI() | |||
| { | |||
| carla_debug("CarlaEngineNativeUI::CarlaEngineNativeUI(%p)", engine); | |||
| } | |||
| @@ -555,7 +556,8 @@ public: | |||
| fIsPatchbay(isPatchbay), | |||
| fIsActive(false), | |||
| fIsRunning(false), | |||
| fUiServer(this) | |||
| fUiServer(this), | |||
| leakDetector_CarlaEngineNative() | |||
| { | |||
| carla_debug("CarlaEngineNative::CarlaEngineNative()"); | |||
| @@ -41,8 +41,15 @@ extern int CarlaPluginSetOscBridgeInfo(CarlaPlugin* const plugin, const PluginBr | |||
| CarlaEngineOsc::CarlaEngineOsc(CarlaEngine* const engine) noexcept | |||
| : fEngine(engine), | |||
| #ifndef BUILD_BRIDGE | |||
| fControlData(), | |||
| #endif | |||
| fName(), | |||
| fServerPathTCP(), | |||
| fServerPathUDP(), | |||
| fServerTCP(nullptr), | |||
| fServerUDP(nullptr) | |||
| fServerUDP(nullptr), | |||
| leakDetector_CarlaEngineOsc() | |||
| { | |||
| CARLA_SAFE_ASSERT(engine != nullptr); | |||
| carla_debug("CarlaEngineOsc::CarlaEngineOsc(%p)", engine); | |||
| @@ -93,6 +93,10 @@ public: | |||
| private: | |||
| CarlaEngine* const fEngine; | |||
| #ifndef BUILD_BRIDGE | |||
| CarlaOscData fControlData; // for carla-control | |||
| #endif | |||
| CarlaString fName; | |||
| CarlaString fServerPathTCP; | |||
| @@ -100,10 +104,6 @@ private: | |||
| lo_server fServerTCP; | |||
| lo_server fServerUDP; | |||
| #ifndef BUILD_BRIDGE | |||
| CarlaOscData fControlData; // for carla-control | |||
| #endif | |||
| // ------------------------------------------------------------------- | |||
| int handleMessage(const bool isTCP, const char* const path, const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg); | |||
| @@ -157,7 +157,13 @@ public: | |||
| fAudioInCount(0), | |||
| fAudioOutCount(0), | |||
| fLastEventTime(0), | |||
| fMidiOutVector(3) | |||
| fDeviceName(), | |||
| fMidiIns(), | |||
| fMidiInEvents(), | |||
| fMidiOuts(), | |||
| fMidiOutMutex(), | |||
| fMidiOutVector(3), | |||
| leakDetector_CarlaEngineRtAudio() | |||
| { | |||
| carla_debug("CarlaEngineRtAudio::CarlaEngineRtAudio(%i)", api); | |||
| @@ -949,7 +955,8 @@ private: | |||
| RtLinkedList<RtMidiEvent> dataPending; | |||
| RtMidiEvents() | |||
| : dataPool(512, 512), | |||
| : mutex(), | |||
| dataPool(512, 512), | |||
| data(dataPool), | |||
| dataPending(dataPool) {} | |||
| @@ -25,7 +25,8 @@ CARLA_BACKEND_START_NAMESPACE | |||
| CarlaEngineThread::CarlaEngineThread(CarlaEngine* const engine) noexcept | |||
| : CarlaThread("CarlaEngineThread"), | |||
| kEngine(engine) | |||
| kEngine(engine), | |||
| leakDetector_CarlaEngineThread() | |||
| { | |||
| CARLA_SAFE_ASSERT(engine != nullptr); | |||
| carla_debug("CarlaEngineThread::CarlaEngineThread(%p)", engine); | |||
| @@ -200,40 +200,51 @@ private: \ | |||
| #ifdef CARLA_PROPER_CPP11_SUPPORT | |||
| # define CARLA_PREVENT_HEAP_ALLOCATION \ | |||
| private: \ | |||
| static void* operator new(size_t) = delete; \ | |||
| static void* operator new(std::size_t) = delete; \ | |||
| static void operator delete(void*) = delete; | |||
| #else | |||
| # define CARLA_PREVENT_HEAP_ALLOCATION \ | |||
| private: \ | |||
| static void* operator new(size_t); \ | |||
| static void* operator new(std::size_t); \ | |||
| static void operator delete(void*); | |||
| #endif | |||
| /* Define EXTERN_C */ | |||
| /* Define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION */ | |||
| #ifdef CARLA_PROPER_CPP11_SUPPORT | |||
| # define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \ | |||
| private: \ | |||
| static void* operator new(std::size_t) = delete; | |||
| #else | |||
| # define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \ | |||
| private: \ | |||
| static void* operator new(std::size_t); | |||
| #endif | |||
| /* Define CARLA_EXTERN_C */ | |||
| #ifdef __cplusplus | |||
| # define EXTERN_C extern "C" | |||
| # define CARLA_EXTERN_C extern "C" | |||
| #else | |||
| # define EXTERN_C | |||
| # define CARLA_EXTERN_C | |||
| #endif | |||
| /* Define CARLA_EXPORT */ | |||
| #ifdef BUILD_BRIDGE | |||
| # define CARLA_EXPORT EXTERN_C | |||
| # define CARLA_EXPORT CARLA_EXTERN_C | |||
| #else | |||
| # if defined(CARLA_OS_WIN) && ! defined(__WINE__) | |||
| # define CARLA_EXPORT EXTERN_C __declspec (dllexport) | |||
| # define CARLA_EXPORT CARLA_EXTERN_C __declspec (dllexport) | |||
| # else | |||
| # define CARLA_EXPORT EXTERN_C __attribute__ ((visibility("default"))) | |||
| # define CARLA_EXPORT CARLA_EXTERN_C __attribute__ ((visibility("default"))) | |||
| # endif | |||
| #endif | |||
| /* Define OS_SEP */ | |||
| #ifdef CARLA_OS_WIN | |||
| # define OS_SEP '\\' | |||
| # define OS_SEP_STR "\\" | |||
| # define CARLA_OS_SEP '\\' | |||
| # define CARLA_OS_SEP_STR "\\" | |||
| #else | |||
| # define OS_SEP '/' | |||
| # define OS_SEP_STR "/" | |||
| # define CARLA_OS_SEP '/' | |||
| # define CARLA_OS_SEP_STR "/" | |||
| #endif | |||
| /* Useful typedefs */ | |||
| @@ -121,6 +121,8 @@ static void test_CarlaUtils() | |||
| str4 = nullptr; | |||
| } | |||
| } | |||
| CARLA_DECLARE_NON_COPY_STRUCT(TestStruct) | |||
| }; | |||
| TestStruct a, b, c; | |||
| @@ -30,8 +30,9 @@ | |||
| class LeakTestClass | |||
| { | |||
| public: | |||
| LeakTestClass()noexcept | |||
| : i(0) {} | |||
| LeakTestClass() noexcept | |||
| : i(0), | |||
| leakDetector_LeakTestClass() {} | |||
| private: | |||
| int i; | |||
| @@ -56,6 +56,9 @@ public: | |||
| private: | |||
| const magic_t fMagic; | |||
| CARLA_PREVENT_HEAP_ALLOCATION | |||
| CARLA_DECLARE_NON_COPY_STRUCT(CarlaMagic) | |||
| }; | |||
| static const CarlaMagic& getCarlaMagicInstance() | |||
| @@ -33,9 +33,11 @@ public: | |||
| }; | |||
| CarlaExternalUI() | |||
| : fUiState(UiNone) | |||
| { | |||
| } | |||
| : fFilename(), | |||
| fSampleRate(), | |||
| fUiTitle(), | |||
| fUiState(UiNone), | |||
| leakDetector_CarlaExternalUI() {} | |||
| ~CarlaExternalUI() override | |||
| { | |||
| @@ -45,7 +45,7 @@ | |||
| #define CARLA_LEAK_DETECTOR(ClassName) \ | |||
| friend class ::LeakedObjectDetector<ClassName>; \ | |||
| static const char* getLeakedObjectClassName() noexcept { return #ClassName; } \ | |||
| ::LeakedObjectDetector<ClassName> CARLA_JOIN_MACRO(leakDetector, __LINE__); | |||
| ::LeakedObjectDetector<ClassName> CARLA_JOIN_MACRO(leakDetector_, ClassName); | |||
| #define CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ClassName) \ | |||
| CARLA_DECLARE_NON_COPY_CLASS(ClassName) \ | |||
| @@ -96,9 +96,7 @@ private: | |||
| { | |||
| public: | |||
| LeakCounter() noexcept | |||
| { | |||
| numObjects = 0; | |||
| } | |||
| : numObjects(0) {} | |||
| ~LeakCounter() noexcept | |||
| { | |||
| @@ -27,7 +27,9 @@ | |||
| class LibCounter | |||
| { | |||
| public: | |||
| LibCounter() noexcept {} | |||
| LibCounter() noexcept | |||
| : fMutex(), | |||
| fLibs() {} | |||
| ~LibCounter() noexcept | |||
| { | |||
| @@ -429,7 +429,7 @@ public: | |||
| return cState; | |||
| } | |||
| CARLA_PREVENT_HEAP_ALLOCATION | |||
| CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION | |||
| }; | |||
| // ----------------------------------------------------------------------- | |||
| @@ -32,7 +32,8 @@ public: | |||
| * Constructor. | |||
| */ | |||
| CarlaMutex() noexcept | |||
| : fTryLockWasCalled(false) | |||
| : fMutex(), | |||
| fTryLockWasCalled(false) | |||
| { | |||
| pthread_mutex_init(&fMutex, nullptr); | |||
| } | |||
| @@ -103,6 +104,11 @@ public: | |||
| * Constructor. | |||
| */ | |||
| CarlaRecursiveMutex() noexcept | |||
| #ifdef CARLA_OS_WIN | |||
| : fSection() | |||
| #else | |||
| : fMutex() | |||
| #endif | |||
| { | |||
| #ifdef CARLA_OS_WIN | |||
| InitializeCriticalSection(&fSection); | |||
| @@ -66,7 +66,8 @@ struct PatchbayGroupList { | |||
| LinkedList<GroupNameToId> list; | |||
| PatchbayGroupList() noexcept | |||
| : lastId(0) {} | |||
| : lastId(0), | |||
| list() {} | |||
| void clear() noexcept | |||
| { | |||
| @@ -159,7 +160,8 @@ struct PatchbayPortList { | |||
| LinkedList<PortNameToId> list; | |||
| PatchbayPortList() noexcept | |||
| : lastId(0) {} | |||
| : lastId(0), | |||
| list() {} | |||
| void clear() noexcept | |||
| { | |||
| @@ -247,7 +249,8 @@ struct PatchbayConnectionList { | |||
| LinkedList<ConnectionToId> list; | |||
| PatchbayConnectionList() noexcept | |||
| : lastId(0) {} | |||
| : lastId(0), | |||
| list() {} | |||
| void clear() noexcept | |||
| { | |||
| @@ -39,10 +39,12 @@ class CarlaPipeServer | |||
| { | |||
| protected: | |||
| CarlaPipeServer() | |||
| : fPipeRecv(-1), | |||
| : fWriteLock(), | |||
| fPipeRecv(-1), | |||
| fPipeSend(-1), | |||
| fIsReading(false), | |||
| fPid(-1) | |||
| fPid(-1), | |||
| fTmpStr() | |||
| { | |||
| carla_debug("CarlaPipeServer::CarlaPipeServer()"); | |||
| @@ -41,10 +41,10 @@ static int temporaryErrorHandler(Display*, XErrorEvent*) | |||
| return 0; | |||
| } | |||
| class X11PluginUi : public CarlaPluginUI | |||
| class X11PluginUI : public CarlaPluginUI | |||
| { | |||
| public: | |||
| X11PluginUi(CloseCallback* const cb, const uintptr_t parentId) noexcept | |||
| X11PluginUI(CloseCallback* const cb, const uintptr_t parentId) noexcept | |||
| : CarlaPluginUI(cb), | |||
| fDisplay(nullptr), | |||
| fWindow(0), | |||
| @@ -88,7 +88,7 @@ public: | |||
| setTransientWinId(parentId); | |||
| } | |||
| ~X11PluginUi() override | |||
| ~X11PluginUI() override | |||
| { | |||
| CARLA_SAFE_ASSERT(! fIsVisible); | |||
| @@ -293,6 +293,8 @@ private: | |||
| bool fIsVisible; | |||
| bool fFirstShow; | |||
| EventProcPtr fEventProc; | |||
| CARLA_DECLARE_NON_COPY_CLASS(X11PluginUI) | |||
| }; | |||
| #endif | |||
| @@ -314,6 +316,9 @@ bool CarlaPluginUI::tryTransientWinIdMatch(const uintptr_t pid, const char* cons | |||
| Display* display; | |||
| ScopedDisplay() : display(XOpenDisplay(nullptr)) {} | |||
| ~ScopedDisplay() { if (display!=nullptr) XCloseDisplay(display); } | |||
| // c++ compat stuff | |||
| CARLA_PREVENT_HEAP_ALLOCATION | |||
| CARLA_DECLARE_NON_COPY_CLASS(ScopedDisplay) | |||
| }; | |||
| struct ScopedFreeData { | |||
| union { | |||
| @@ -323,6 +328,9 @@ bool CarlaPluginUI::tryTransientWinIdMatch(const uintptr_t pid, const char* cons | |||
| ScopedFreeData(char* d) : data(d) {} | |||
| ScopedFreeData(uchar* d) : udata(d) {} | |||
| ~ScopedFreeData() { XFree(data); } | |||
| // c++ compat stuff | |||
| CARLA_PREVENT_HEAP_ALLOCATION | |||
| CARLA_DECLARE_NON_COPY_CLASS(ScopedFreeData) | |||
| }; | |||
| const ScopedDisplay sd; | |||
| @@ -502,7 +510,7 @@ CarlaPluginUI* CarlaPluginUI::newWindows(CloseCallback*, uintptr_t) | |||
| #ifdef HAVE_X11 | |||
| CarlaPluginUI* CarlaPluginUI::newX11(CloseCallback* cb, uintptr_t parentId) | |||
| { | |||
| return new X11PluginUi(cb, parentId); | |||
| return new X11PluginUI(cb, parentId); | |||
| } | |||
| #endif | |||
| @@ -60,6 +60,8 @@ protected: | |||
| bool fIsIdling; | |||
| CloseCallback* fCallback; | |||
| CarlaPluginUI(CloseCallback* const cb) noexcept : fIsIdling(false), fCallback(cb) {} | |||
| CARLA_DECLARE_NON_COPY_CLASS(CarlaPluginUI) | |||
| }; | |||
| // ----------------------------------------------------- | |||
| @@ -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<HeapBuffer> | |||
| { | |||
| public: | |||
| CarlaHeapRingBuffer() noexcept | |||
| : CarlaRingBuffer<HeapBuffer>() | |||
| { | |||
| 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<StackBuffer> | |||
| { | |||
| public: | |||
| CarlaStackRingBuffer() noexcept | |||
| : CarlaRingBuffer<StackBuffer>(&fStackBuffer) {} | |||
| : fStackBuffer(StackBuffer_INIT) | |||
| { | |||
| setRingBuffer(&fStackBuffer, false); | |||
| } | |||
| private: | |||
| StackBuffer fStackBuffer; | |||
| CARLA_PREVENT_HEAP_ALLOCATION | |||
| CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION | |||
| CARLA_DECLARE_NON_COPY_CLASS(CarlaStackRingBuffer) | |||
| }; | |||
| @@ -152,7 +152,9 @@ StateSave::StateSave() noexcept | |||
| currentProgramName(nullptr), | |||
| currentMidiBank(-1), | |||
| currentMidiProgram(-1), | |||
| chunk(nullptr) {} | |||
| chunk(nullptr), | |||
| parameters(), | |||
| customData() {} | |||
| StateSave::~StateSave() noexcept | |||
| { | |||
| @@ -40,20 +40,20 @@ public: | |||
| * Empty string. | |||
| */ | |||
| explicit CarlaString() noexcept | |||
| { | |||
| _init(); | |||
| } | |||
| : fBuffer(_null()), | |||
| fBufferLen(0) {} | |||
| /* | |||
| * Simple character. | |||
| */ | |||
| explicit CarlaString(const char c) noexcept | |||
| : fBuffer(_null()), | |||
| fBufferLen(0) | |||
| { | |||
| char ch[2]; | |||
| ch[0] = c; | |||
| ch[1] = '\0'; | |||
| _init(); | |||
| _dup(ch); | |||
| } | |||
| @@ -61,8 +61,9 @@ public: | |||
| * Simple char string. | |||
| */ | |||
| explicit CarlaString(char* const strBuf) noexcept | |||
| : fBuffer(_null()), | |||
| fBufferLen(0) | |||
| { | |||
| _init(); | |||
| _dup(strBuf); | |||
| } | |||
| @@ -70,8 +71,9 @@ public: | |||
| * Simple const char string. | |||
| */ | |||
| explicit CarlaString(const char* const strBuf) noexcept | |||
| : fBuffer(_null()), | |||
| fBufferLen(0) | |||
| { | |||
| _init(); | |||
| _dup(strBuf); | |||
| } | |||
| @@ -79,12 +81,13 @@ public: | |||
| * Integer. | |||
| */ | |||
| explicit CarlaString(const int value) noexcept | |||
| : fBuffer(_null()), | |||
| fBufferLen(0) | |||
| { | |||
| char strBuf[0xff+1]; | |||
| std::snprintf(strBuf, 0xff, "%d", value); | |||
| strBuf[0xff] = '\0'; | |||
| _init(); | |||
| _dup(strBuf); | |||
| } | |||
| @@ -92,12 +95,13 @@ public: | |||
| * Unsigned integer, possibly in hexadecimal. | |||
| */ | |||
| explicit CarlaString(const unsigned int value, const bool hexadecimal = false) noexcept | |||
| : fBuffer(_null()), | |||
| fBufferLen(0) | |||
| { | |||
| char strBuf[0xff+1]; | |||
| std::snprintf(strBuf, 0xff, hexadecimal ? "0x%x" : "%u", value); | |||
| strBuf[0xff] = '\0'; | |||
| _init(); | |||
| _dup(strBuf); | |||
| } | |||
| @@ -105,12 +109,13 @@ public: | |||
| * Long integer. | |||
| */ | |||
| explicit CarlaString(const long value) noexcept | |||
| : fBuffer(_null()), | |||
| fBufferLen(0) | |||
| { | |||
| char strBuf[0xff+1]; | |||
| std::snprintf(strBuf, 0xff, "%ld", value); | |||
| strBuf[0xff] = '\0'; | |||
| _init(); | |||
| _dup(strBuf); | |||
| } | |||
| @@ -118,12 +123,13 @@ public: | |||
| * Long unsigned integer, possibly hexadecimal. | |||
| */ | |||
| explicit CarlaString(const unsigned long value, const bool hexadecimal = false) noexcept | |||
| : fBuffer(_null()), | |||
| fBufferLen(0) | |||
| { | |||
| char strBuf[0xff+1]; | |||
| std::snprintf(strBuf, 0xff, hexadecimal ? "0x%lx" : "%lu", value); | |||
| strBuf[0xff] = '\0'; | |||
| _init(); | |||
| _dup(strBuf); | |||
| } | |||
| @@ -131,12 +137,13 @@ public: | |||
| * Long long integer. | |||
| */ | |||
| explicit CarlaString(const long long value) noexcept | |||
| : fBuffer(_null()), | |||
| fBufferLen(0) | |||
| { | |||
| char strBuf[0xff+1]; | |||
| std::snprintf(strBuf, 0xff, "%lld", value); | |||
| strBuf[0xff] = '\0'; | |||
| _init(); | |||
| _dup(strBuf); | |||
| } | |||
| @@ -144,12 +151,13 @@ public: | |||
| * Long long unsigned integer, possibly hexadecimal. | |||
| */ | |||
| explicit CarlaString(const unsigned long long value, const bool hexadecimal = false) noexcept | |||
| : fBuffer(_null()), | |||
| fBufferLen(0) | |||
| { | |||
| char strBuf[0xff+1]; | |||
| std::snprintf(strBuf, 0xff, hexadecimal ? "0x%llx" : "%llu", value); | |||
| strBuf[0xff] = '\0'; | |||
| _init(); | |||
| _dup(strBuf); | |||
| } | |||
| @@ -157,12 +165,13 @@ public: | |||
| * Single-precision floating point number. | |||
| */ | |||
| explicit CarlaString(const float value) noexcept | |||
| : fBuffer(_null()), | |||
| fBufferLen(0) | |||
| { | |||
| char strBuf[0xff+1]; | |||
| std::snprintf(strBuf, 0xff, "%f", value); | |||
| strBuf[0xff] = '\0'; | |||
| _init(); | |||
| _dup(strBuf); | |||
| } | |||
| @@ -170,12 +179,13 @@ public: | |||
| * Double-precision floating point number. | |||
| */ | |||
| explicit CarlaString(const double value) noexcept | |||
| : fBuffer(_null()), | |||
| fBufferLen(0) | |||
| { | |||
| char strBuf[0xff+1]; | |||
| std::snprintf(strBuf, 0xff, "%g", value); | |||
| strBuf[0xff] = '\0'; | |||
| _init(); | |||
| _dup(strBuf); | |||
| } | |||
| @@ -186,8 +196,9 @@ public: | |||
| * Create string from another string. | |||
| */ | |||
| CarlaString(const CarlaString& str) noexcept | |||
| : fBuffer(_null()), | |||
| fBufferLen(0) | |||
| { | |||
| _init(); | |||
| _dup(str.fBuffer); | |||
| } | |||
| @@ -750,16 +761,6 @@ private: | |||
| return &sNull; | |||
| } | |||
| /* | |||
| * Shared init function. | |||
| * Called on all constructors. | |||
| */ | |||
| void _init() noexcept | |||
| { | |||
| fBuffer = _null(); | |||
| fBufferLen = 0; | |||
| } | |||
| /* | |||
| * Helper function. | |||
| * Called whenever the string needs to be allocated. | |||
| @@ -783,7 +784,11 @@ private: | |||
| fBuffer = (char*)std::malloc(fBufferLen+1); | |||
| if (fBuffer == nullptr) | |||
| return _init(); | |||
| { | |||
| fBuffer = _null(); | |||
| fBufferLen = 0; | |||
| return; | |||
| } | |||
| std::strcpy(fBuffer, strBuf); | |||
| @@ -800,7 +805,8 @@ private: | |||
| CARLA_SAFE_ASSERT(fBuffer != nullptr); | |||
| std::free(fBuffer); | |||
| _init(); | |||
| fBuffer = _null(); | |||
| fBufferLen = 0; | |||
| } | |||
| } | |||
| @@ -18,7 +18,6 @@ | |||
| #ifndef CARLA_STRING_LIST_HPP_INCLUDED | |||
| #define CARLA_STRING_LIST_HPP_INCLUDED | |||
| #include "CarlaString.hpp" | |||
| #include "LinkedList.hpp" | |||
| // ----------------------------------------------------------------------- | |||
| @@ -39,7 +38,7 @@ public: | |||
| copy(ptr.fCharList); | |||
| } | |||
| CharStringListPtr(const LinkedList<CarlaString>& list) noexcept | |||
| CharStringListPtr(const LinkedList<const char*>& list) noexcept | |||
| : fCharList(nullptr) | |||
| { | |||
| copy(list); | |||
| @@ -50,6 +49,8 @@ public: | |||
| clear(); | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| operator const char* const*() const noexcept | |||
| { | |||
| return fCharList; | |||
| @@ -69,13 +70,15 @@ public: | |||
| return *this; | |||
| } | |||
| CharStringListPtr& operator=(const LinkedList<CarlaString>& list) noexcept | |||
| CharStringListPtr& operator=(const LinkedList<const char*>& list) noexcept | |||
| { | |||
| clear(); | |||
| copy(list); | |||
| return *this; | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| protected: | |||
| void clear() noexcept | |||
| { | |||
| @@ -119,7 +122,7 @@ protected: | |||
| fCharList = tmpList; | |||
| } | |||
| void copy(const LinkedList<CarlaString>& list) noexcept | |||
| void copy(const LinkedList<const char*>& list) noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(fCharList == nullptr,); | |||
| @@ -133,23 +136,18 @@ protected: | |||
| } CARLA_SAFE_EXCEPTION_RETURN("CharStringListPtr::copy",); | |||
| size_t i=0; | |||
| for (LinkedList<CarlaString>::Itenerator it = list.begin(); it.valid(); it.next(), ++i) | |||
| for (LinkedList<const char*>::Itenerator it = list.begin(); it.valid(); it.next(), ++i) | |||
| { | |||
| const CarlaString& string(it.getValue()); | |||
| try { | |||
| tmpList[i] = string.dup(); | |||
| } | |||
| catch(...) { | |||
| tmpList[i] = nullptr; | |||
| break; | |||
| } | |||
| tmpList[i] = carla_strdup_safe(it.getValue()); | |||
| CARLA_SAFE_ASSERT_BREAK(tmpList[i] != nullptr); | |||
| } | |||
| tmpList[count] = nullptr; | |||
| fCharList = tmpList; | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| private: | |||
| const char* const* fCharList; | |||
| }; | |||
| @@ -157,50 +155,144 @@ private: | |||
| // ----------------------------------------------------------------------- | |||
| // CarlaStringList | |||
| class CarlaStringList : public LinkedList<CarlaString> | |||
| class CarlaStringList : public LinkedList<const char*> | |||
| { | |||
| public: | |||
| CarlaStringList() noexcept | |||
| : LinkedList<CarlaString>(true) {} | |||
| : LinkedList<const char*>() {} | |||
| #if 0 | |||
| CarlaStringList(const CarlaStringList& list) noexcept | |||
| : LinkedList<CarlaString>(true) | |||
| : LinkedList<const char*>() | |||
| { | |||
| for (Itenerator it = list.begin(); it.valid(); it.next()) | |||
| LinkedList<CarlaString>::append(it.getValue()); | |||
| LinkedList<const char*>::append(carla_strdup_safe(it.getValue())); | |||
| } | |||
| #endif | |||
| ~CarlaStringList() noexcept | |||
| ~CarlaStringList() noexcept override | |||
| { | |||
| clear(); | |||
| } | |||
| bool append(const char* const strBuf) noexcept | |||
| // ------------------------------------------------------------------- | |||
| void clear() noexcept | |||
| { | |||
| for (Itenerator it = begin(); it.valid(); it.next()) | |||
| { | |||
| if (const char* const string = it.getValue()) | |||
| delete[] string; | |||
| } | |||
| LinkedList<const char*>::clear(); | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| bool append(const char* const string) noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(string != nullptr, false); | |||
| if (const char* const stringDup = carla_strdup_safe(string)) | |||
| { | |||
| if (LinkedList<const char*>::append(stringDup)) | |||
| return true; | |||
| delete[] stringDup; | |||
| } | |||
| return false; | |||
| } | |||
| bool appendAt(const char* const string, const Itenerator& it) noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(string != nullptr, false); | |||
| if (const char* const stringDup = carla_strdup_safe(string)) | |||
| { | |||
| if (LinkedList<const char*>::appendAt(stringDup, it)) | |||
| return true; | |||
| delete[] stringDup; | |||
| } | |||
| return false; | |||
| } | |||
| bool insert(const char* const string) noexcept | |||
| { | |||
| CARLA_SAFE_ASSERT_RETURN(string != nullptr, false); | |||
| if (const char* const stringDup = carla_strdup_safe(string)) | |||
| { | |||
| if (LinkedList<const char*>::insert(stringDup)) | |||
| return true; | |||
| delete[] stringDup; | |||
| } | |||
| return false; | |||
| } | |||
| bool insertAt(const char* const string, const Itenerator& it) noexcept | |||
| { | |||
| const CarlaString string(strBuf); | |||
| return LinkedList<CarlaString>::append(string); | |||
| CARLA_SAFE_ASSERT_RETURN(string != nullptr, false); | |||
| if (const char* const stringDup = carla_strdup_safe(string)) | |||
| { | |||
| if (LinkedList<const char*>::insertAt(stringDup, it)) | |||
| return true; | |||
| delete[] stringDup; | |||
| } | |||
| return false; | |||
| } | |||
| bool appendAt(const char* const strBuf, const Itenerator& it) noexcept | |||
| // ------------------------------------------------------------------- | |||
| void remove(Itenerator& it) noexcept | |||
| { | |||
| const CarlaString string(strBuf); | |||
| return LinkedList<CarlaString>::appendAt(string, it); | |||
| if (const char* const string = it.getValue()) | |||
| delete[] string; | |||
| LinkedList<const char*>::remove(it); | |||
| } | |||
| bool insert(const char* const strBuf) noexcept | |||
| bool removeOne(const char* const string) noexcept | |||
| { | |||
| const CarlaString string(strBuf); | |||
| return LinkedList<CarlaString>::insert(string); | |||
| CARLA_SAFE_ASSERT_RETURN(string != nullptr, false); | |||
| for (Itenerator it = begin(); it.valid(); it.next()) | |||
| { | |||
| const char* const stringComp(it.getValue()); | |||
| CARLA_SAFE_ASSERT_CONTINUE(stringComp != nullptr); | |||
| if (std::strcmp(string, stringComp) != 0) | |||
| continue; | |||
| delete[] stringComp; | |||
| LinkedList<const char*>::remove(it); | |||
| return true; | |||
| } | |||
| return false; | |||
| } | |||
| bool insertAt(const char* const strBuf, const Itenerator& it) noexcept | |||
| void removeAll(const char* const string) noexcept | |||
| { | |||
| const CarlaString string(strBuf); | |||
| return LinkedList<CarlaString>::insertAt(string, it); | |||
| CARLA_SAFE_ASSERT_RETURN(string != nullptr,); | |||
| for (Itenerator it = begin(); it.valid(); it.next()) | |||
| { | |||
| const char* const stringComp(it.getValue()); | |||
| CARLA_SAFE_ASSERT_CONTINUE(stringComp != nullptr); | |||
| if (std::strcmp(string, stringComp) != 0) | |||
| continue; | |||
| delete[] stringComp; | |||
| LinkedList<const char*>::remove(it); | |||
| } | |||
| } | |||
| // ------------------------------------------------------------------- | |||
| CharStringListPtr toCharStringListPtr() const noexcept | |||
| { | |||
| return CharStringListPtr(*this); | |||
| @@ -210,8 +302,13 @@ public: | |||
| { | |||
| clear(); | |||
| CARLA_SAFE_ASSERT_RETURN(charStringList != nullptr, *this); | |||
| for (int i=0; charStringList[i] != nullptr; ++i) | |||
| append(charStringList[i]); | |||
| { | |||
| if (const char* const string = carla_strdup_safe(charStringList[i])) | |||
| LinkedList<const char*>::append(string); | |||
| } | |||
| return *this; | |||
| } | |||
| @@ -221,13 +318,15 @@ public: | |||
| clear(); | |||
| for (Itenerator it = list.begin(); it.valid(); it.next()) | |||
| LinkedList<CarlaString>::append(it.getValue()); | |||
| { | |||
| if (const char* const string = carla_strdup_safe(it.getValue())) | |||
| LinkedList<const char*>::append(string); | |||
| } | |||
| return *this; | |||
| } | |||
| private: | |||
| LinkedList<CarlaString> fList; | |||
| CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION | |||
| }; | |||
| // ----------------------------------------------------------------------- | |||
| @@ -37,11 +37,14 @@ protected: | |||
| * Constructor. | |||
| */ | |||
| CarlaThread(const char* const threadName = nullptr) noexcept | |||
| : fName(threadName), | |||
| fShouldExit(false) | |||
| { | |||
| _init(); | |||
| } | |||
| : fLock(), | |||
| fName(threadName), | |||
| #ifdef PTW32_DLLPORT | |||
| fHandle({nullptr, 0}), | |||
| #else | |||
| fHandle(0), | |||
| #endif | |||
| fShouldExit(false) {} | |||
| /* | |||
| * Destructor. | |||
| @@ -20,8 +20,6 @@ | |||
| #include "CarlaUtils.hpp" | |||
| #include <new> | |||
| // ----------------------------------------------------------------------- | |||
| // Define list_entry and list_entry_const | |||
| @@ -47,27 +45,11 @@ | |||
| ((const type *)((const char *)(ptr)-offsetof(type, member))) | |||
| #endif | |||
| // ----------------------------------------------------------------------- | |||
| // Declare non copyable and prevent heap allocation | |||
| #ifdef CARLA_PROPER_CPP11_SUPPORT | |||
| # define LINKED_LIST_DECLARATIONS(ClassName) \ | |||
| ClassName(ClassName&) = delete; \ | |||
| ClassName(const ClassName&) = delete; \ | |||
| ClassName& operator=(const ClassName&) = delete; \ | |||
| static void* operator new(size_t) = delete; | |||
| #else | |||
| # define LINKED_LIST_DECLARATIONS(ClassName) \ | |||
| ClassName(ClassName&); \ | |||
| ClassName(const ClassName&); \ | |||
| ClassName& operator=(const ClassName&); | |||
| #endif | |||
| // ----------------------------------------------------------------------- | |||
| // Abstract Linked List class | |||
| // _allocate() and _deallocate are virtual calls provided by subclasses | |||
| // NOTE: data-type classes are not allowed to throw | |||
| // NOTE: this class is meant for non-polymorphic data types only! | |||
| template<typename T> | |||
| class AbstractLinkedList | |||
| @@ -83,12 +65,10 @@ protected: | |||
| ListHead siblings; | |||
| }; | |||
| AbstractLinkedList(const bool isClass) noexcept | |||
| : kIsClass(isClass), | |||
| kDataSize(sizeof(Data)) | |||
| { | |||
| _init(); | |||
| } | |||
| AbstractLinkedList() noexcept | |||
| : kDataSize(sizeof(Data)), | |||
| fCount(0), | |||
| fQueue({&fQueue, &fQueue}) {} | |||
| public: | |||
| virtual ~AbstractLinkedList() noexcept | |||
| @@ -158,8 +138,6 @@ public: | |||
| Data* const data = list_entry(entry, Data, siblings); | |||
| CARLA_SAFE_ASSERT_CONTINUE(data != nullptr); | |||
| if (kIsClass) | |||
| data->~Data(); | |||
| _deallocate(data); | |||
| } | |||
| @@ -364,7 +342,6 @@ public: | |||
| } | |||
| protected: | |||
| const bool kIsClass; | |||
| const size_t kDataSize; | |||
| size_t fCount; | |||
| @@ -383,11 +360,9 @@ private: | |||
| void _createData(Data* const data, const T& value) noexcept | |||
| { | |||
| if (kIsClass) | |||
| new(data)Data(); | |||
| data->value = value; | |||
| ++fCount; | |||
| data->value = value; | |||
| //std::memcpy(data->value, value, kDataSize); | |||
| } | |||
| bool _add(const T& value, const bool inTail, ListHead* const queue) noexcept | |||
| @@ -397,9 +372,9 @@ private: | |||
| _createData(data, value); | |||
| if (inTail) | |||
| __list_add(&data->siblings, queue->prev, queue); | |||
| __list_add(data->siblings, queue->prev, queue); | |||
| else | |||
| __list_add(&data->siblings, queue, queue->next); | |||
| __list_add(data->siblings, queue, queue->next); | |||
| return true; | |||
| } | |||
| @@ -413,11 +388,8 @@ private: | |||
| entry->next = nullptr; | |||
| entry->prev = nullptr; | |||
| --fCount; | |||
| if (kIsClass) | |||
| data->~Data(); | |||
| _deallocate(data); | |||
| --fCount; | |||
| } | |||
| const T& _get(ListHead* const entry, const T& fallback) const noexcept | |||
| @@ -454,12 +426,12 @@ private: | |||
| /* | |||
| * Insert a new entry between two known consecutive entries. | |||
| */ | |||
| static void __list_add(ListHead* const new_, ListHead* const prev, ListHead* const next) noexcept | |||
| static void __list_add(ListHead& newl, ListHead* const prev, ListHead* const next) noexcept | |||
| { | |||
| next->prev = new_; | |||
| new_->next = next; | |||
| new_->prev = prev; | |||
| prev->next = new_; | |||
| next->prev = &newl; | |||
| newl.next = next; | |||
| newl.prev = prev; | |||
| prev->next = &newl; | |||
| } | |||
| /* | |||
| @@ -479,10 +451,10 @@ private: | |||
| ListHead* const at = head->next; | |||
| first->prev = head; | |||
| head->next = first; | |||
| head->next = first; | |||
| last->next = at; | |||
| at->prev = last; | |||
| at->prev = last; | |||
| } | |||
| static void __list_splice_tail(ListHead* const list, ListHead* const head) noexcept | |||
| @@ -492,7 +464,7 @@ private: | |||
| ListHead* const at = head->prev; | |||
| first->prev = at; | |||
| at->next = first; | |||
| at->next = first; | |||
| last->next = head; | |||
| head->prev = last; | |||
| @@ -500,7 +472,8 @@ private: | |||
| template<typename> friend class RtLinkedList; | |||
| LINKED_LIST_DECLARATIONS(AbstractLinkedList) | |||
| CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION | |||
| CARLA_DECLARE_NON_COPY_CLASS(AbstractLinkedList) | |||
| }; | |||
| // ----------------------------------------------------------------------- | |||
| @@ -510,8 +483,7 @@ template<typename T> | |||
| class LinkedList : public AbstractLinkedList<T> | |||
| { | |||
| public: | |||
| LinkedList(const bool isClass = false) noexcept | |||
| : AbstractLinkedList<T>(isClass) {} | |||
| LinkedList() noexcept {} | |||
| protected: | |||
| typename AbstractLinkedList<T>::Data* _allocate() noexcept override | |||
| @@ -526,7 +498,8 @@ protected: | |||
| std::free(dataPtr); | |||
| } | |||
| LINKED_LIST_DECLARATIONS(LinkedList) | |||
| CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION | |||
| CARLA_DECLARE_NON_COPY_CLASS(LinkedList) | |||
| }; | |||
| // ----------------------------------------------------------------------- | |||
| @@ -93,14 +93,16 @@ public: | |||
| private: | |||
| mutable RtMemPool_Handle fHandle; | |||
| const size_t kDataSize; | |||
| CARLA_PREVENT_HEAP_ALLOCATION | |||
| CARLA_DECLARE_NON_COPY_CLASS(Pool) | |||
| }; | |||
| // ------------------------------------------------------------------- | |||
| // Now the actual rt-linkedlist code | |||
| RtLinkedList(Pool& memPool, const bool isClass = false) noexcept | |||
| : AbstractLinkedList<T>(isClass), | |||
| fMemPool(memPool) {} | |||
| RtLinkedList(Pool& memPool) noexcept | |||
| : fMemPool(memPool) {} | |||
| bool append_sleepy(const T& value) noexcept | |||
| { | |||
| @@ -161,9 +163,9 @@ private: | |||
| this->_createData(data, value); | |||
| if (inTail) | |||
| this->__list_add(&data->siblings, this->fQueue.prev, &this->fQueue); | |||
| this->__list_add(data->siblings, this->fQueue.prev, &(this->fQueue)); | |||
| else | |||
| this->__list_add(&data->siblings, &this->fQueue, this->fQueue.next); | |||
| this->__list_add(data->siblings, &(this->fQueue), this->fQueue.next); | |||
| return true; | |||
| } | |||
| @@ -171,7 +173,8 @@ private: | |||
| return false; | |||
| } | |||
| LINKED_LIST_DECLARATIONS(RtLinkedList) | |||
| CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION | |||
| CARLA_DECLARE_NON_COPY_CLASS(RtLinkedList) | |||
| }; | |||
| // ----------------------------------------------------------------------- | |||