mirror of
https://github.com/cookiengineer/audacity
synced 2025-12-25 14:11:28 +01:00
Redo resource RAII without the dubious casts
This commit is contained in:
@@ -1114,12 +1114,12 @@ void VSTEffect::BundleDeleter::operator() (void* p) const
|
|||||||
CFRelease(static_cast<CFBundleRef>(p));
|
CFRelease(static_cast<CFBundleRef>(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VSTEffect::ResourceDeleter::operator() (void *p) const
|
void VSTEffect::ResourceHandle::reset()
|
||||||
{
|
{
|
||||||
if (mpHandle) {
|
if (mpHandle)
|
||||||
int resource = (int)p;
|
CFBundleCloseBundleResourceMap(mpHandle, mNum);
|
||||||
CFBundleCloseBundleResourceMap(mpHandle->get(), resource);
|
mpHandle = nullptr;
|
||||||
}
|
mNum = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -2061,10 +2061,8 @@ bool VSTEffect::Load()
|
|||||||
mBundleRef = std::move(bundleRef);
|
mBundleRef = std::move(bundleRef);
|
||||||
|
|
||||||
// Open the resource map ... some plugins (like GRM Tools) need this.
|
// Open the resource map ... some plugins (like GRM Tools) need this.
|
||||||
mResource = ResourceHandle {
|
mResource = ResourceHandle{
|
||||||
reinterpret_cast<char*>(
|
mBundleRef.get(), CFBundleOpenBundleResourceMap(mBundleRef.get())
|
||||||
CFBundleOpenBundleResourceMap(mBundleRef.get())),
|
|
||||||
ResourceDeleter{&mBundleRef}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#elif defined(__WXMSW__)
|
#elif defined(__WXMSW__)
|
||||||
@@ -2267,7 +2265,7 @@ void VSTEffect::Unload()
|
|||||||
if (mModule)
|
if (mModule)
|
||||||
{
|
{
|
||||||
#if defined(__WXMAC__)
|
#if defined(__WXMAC__)
|
||||||
mResource = ResourceHandle{};
|
mResource.reset();
|
||||||
mBundleRef.reset();
|
mBundleRef.reset();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -302,15 +302,27 @@ private:
|
|||||||
|
|
||||||
BundleHandle mBundleRef;
|
BundleHandle mBundleRef;
|
||||||
|
|
||||||
struct ResourceDeleter {
|
struct ResourceHandle {
|
||||||
const BundleHandle *mpHandle;
|
ResourceHandle(
|
||||||
ResourceDeleter(const BundleHandle *pHandle = nullptr)
|
CFBundleRef pHandle = nullptr, CFBundleRefNum num = 0)
|
||||||
: mpHandle(pHandle) {}
|
: mpHandle{ pHandle }, mNum{ num }
|
||||||
void operator() (void*) const;
|
{}
|
||||||
|
ResourceHandle& operator=( ResourceHandle &&other )
|
||||||
|
{
|
||||||
|
if (this != &other) {
|
||||||
|
mpHandle = other.mpHandle;
|
||||||
|
mNum = other.mNum;
|
||||||
|
other.mpHandle = nullptr;
|
||||||
|
other.mNum = 0;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
~ResourceHandle() { reset(); }
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
CFBundleRef mpHandle{};
|
||||||
|
CFBundleRefNum mNum{};
|
||||||
};
|
};
|
||||||
using ResourceHandle = std::unique_ptr<
|
|
||||||
char, ResourceDeleter
|
|
||||||
>;
|
|
||||||
ResourceHandle mResource;
|
ResourceHandle mResource;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user