mirror of
				https://github.com/cookiengineer/audacity
				synced 2025-11-03 23:53:55 +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));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void VSTEffect::ResourceDeleter::operator() (void *p) const
 | 
			
		||||
void VSTEffect::ResourceHandle::reset()
 | 
			
		||||
{
 | 
			
		||||
   if (mpHandle) {
 | 
			
		||||
      int resource = (int)p;
 | 
			
		||||
      CFBundleCloseBundleResourceMap(mpHandle->get(), resource);
 | 
			
		||||
   }
 | 
			
		||||
   if (mpHandle)
 | 
			
		||||
      CFBundleCloseBundleResourceMap(mpHandle, mNum);
 | 
			
		||||
   mpHandle = nullptr;
 | 
			
		||||
   mNum = 0;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@@ -2061,10 +2061,8 @@ bool VSTEffect::Load()
 | 
			
		||||
   mBundleRef = std::move(bundleRef);
 | 
			
		||||
 | 
			
		||||
   // Open the resource map ... some plugins (like GRM Tools) need this.
 | 
			
		||||
   mResource = ResourceHandle {
 | 
			
		||||
      reinterpret_cast<char*>(
 | 
			
		||||
         CFBundleOpenBundleResourceMap(mBundleRef.get())),
 | 
			
		||||
      ResourceDeleter{&mBundleRef}
 | 
			
		||||
   mResource = ResourceHandle{
 | 
			
		||||
      mBundleRef.get(), CFBundleOpenBundleResourceMap(mBundleRef.get())
 | 
			
		||||
   };
 | 
			
		||||
 | 
			
		||||
#elif defined(__WXMSW__)
 | 
			
		||||
@@ -2267,7 +2265,7 @@ void VSTEffect::Unload()
 | 
			
		||||
   if (mModule)
 | 
			
		||||
   {
 | 
			
		||||
#if defined(__WXMAC__)
 | 
			
		||||
      mResource = ResourceHandle{};
 | 
			
		||||
      mResource.reset();
 | 
			
		||||
      mBundleRef.reset();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -302,15 +302,27 @@ private:
 | 
			
		||||
 | 
			
		||||
   BundleHandle mBundleRef;
 | 
			
		||||
 | 
			
		||||
   struct ResourceDeleter {
 | 
			
		||||
      const BundleHandle *mpHandle;
 | 
			
		||||
      ResourceDeleter(const BundleHandle *pHandle = nullptr)
 | 
			
		||||
         : mpHandle(pHandle) {}
 | 
			
		||||
      void operator() (void*) const;
 | 
			
		||||
   struct ResourceHandle {
 | 
			
		||||
      ResourceHandle(
 | 
			
		||||
         CFBundleRef pHandle = nullptr, CFBundleRefNum num = 0)
 | 
			
		||||
      : mpHandle{ pHandle }, mNum{ num }
 | 
			
		||||
      {}
 | 
			
		||||
      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;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user