commit ce2958b118a3de0d3a91d138f23b628b7f58a64c
Author: R.J.V. Bertin <rjvbertin@gmail.com>
Date:   Wed Mar 21 15:18:48 2018 +0100

    port:audacity : address a libstdc++ build problem with VSTEffect and support C++11 everywhere on Mac.
    
diff --git a/audio/audacity/Portfile b/audio/audacity/Portfile
index 35216d9e..e9027002 100644
--- a/audio/audacity/Portfile
+++ b/audio/audacity/Portfile
@@ -133,7 +133,7 @@ platform darwin {
                     patch-python.diff                                       \
                     patch-vstcontrolosx.diff \
                     patch-libnyquist-symbol-visibility.diff \
-                    patch-fix-casts.diff \
+                    patch-fix-vsteffects.diff \
                     patch-add-MenusMac.diff \
                     patch-skip-gcc-version-test.diff \
                     patch-fix-audiounits.diff
@@ -210,6 +210,7 @@ post-patch {
                                 lib-src/lv2/configure
     reinplace -W ${worksrcpath} "s|/usr/local|${prefix}|g" \
                                 src/effects/ladspa/LadspaEffect.cpp \
+                                src/effects/VST/VSTEffect.cpp \
                                 src/export/ExportMP3.cpp \
                                 lib-src/lv2/lilv/wscript \
                                 lib-src/lv2/lilv/test/lilv_test.c
diff --git a/audio/audacity/files/patch-fix-casts.diff b/audio/audacity/files/patch-fix-casts.diff
deleted file mode 100644
index 7a165ddc..00000000
--- a/audio/audacity/files/patch-fix-casts.diff
+++ /dev/null
@@ -1,15 +0,0 @@
-diff --git a/src/effects/VST/VSTEffect.cpp b/src/effects/VST/VSTEffect.cpp
-index 3cd95bd1c339ea1a744849562f387161d8be3ea2..b69547e22e6444c676c3eca98754139743da7183 100644
---- a/src/effects/VST/VSTEffect.cpp
-+++ b/src/effects/VST/VSTEffect.cpp
-@@ -1110,7 +1110,9 @@ void VSTEffect::BundleDeleter::operator() (void* p) const
- void VSTEffect::ResourceDeleter::operator() (void *p) const
- {
-    if (mpHandle) {
--      int resource = (int)p;
-+      // take a detour to avoid a "fatal warning" about losing data downcasting a void* to int
-+      size_t dum = size_t(p);
-+      int resource = int(dum);
-       CFBundleCloseBundleResourceMap(mpHandle->get(), resource);
-    }
- }
diff --git a/audio/audacity/files/patch-fix-vsteffects.diff b/audio/audacity/files/patch-fix-vsteffects.diff
new file mode 100644
index 00000000..96ca3bce
--- /dev/null
+++ b/audio/audacity/files/patch-fix-vsteffects.diff
@@ -0,0 +1,79 @@
+diff --git a/src/effects/VST/VSTEffect.cpp b/src/effects/VST/VSTEffect.cpp
+index 3cd95bd1c339ea1a744849562f387161d8be3ea2..b48eb3d838f1bf6981e5aad3bb860b3eec00c165 100644
+--- a/src/effects/VST/VSTEffect.cpp
++++ b/src/effects/VST/VSTEffect.cpp
+@@ -1110,14 +1110,23 @@ void VSTEffect::BundleDeleter::operator() (void* p) const
+ void VSTEffect::ResourceDeleter::operator() (void *p) const
+ {
+    if (mpHandle) {
+-      int resource = (int)p;
+-      CFBundleCloseBundleResourceMap(mpHandle->get(), resource);
++      CFBundleRefNum *resource = reinterpret_cast<CFBundleRefNum*>(p);
++      if (resource)
++      {
++          CFBundleCloseBundleResourceMap(mpHandle->get(), *resource);
++          // resource is ours to free
++          free(resource);
++      }
+    }
+ }
+ #endif
+ 
+ VSTEffect::VSTEffect(const wxString & path, VSTEffect *master)
+ :  mPath(path),
++#ifdef __WXMAC__
++   // mResource must be initialised explicitly when building against libstdc++ instead of libc++
++   mResource(ResourceHandle{nullptr, nullptr}),
++#endif
+    mMaster(master)
+ {
+    mHost = NULL;
+@@ -1994,7 +2003,7 @@ bool VSTEffect::Load()
+    // Start clean
+    mBundleRef.reset();
+ 
+-   mResource = ResourceHandle{};
++   mResource = ResourceHandle{nullptr, nullptr};
+ 
+    // Convert the path to a CFSTring
+    wxCFStringRef path(realPath);
+@@ -2064,11 +2073,12 @@ 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}
+-   };
++   // CFBundleOpenBundleResourceMap() returns a CFBundleRefNum which is
++   // an int, so we use a cache variable to avoid having to upcast to a
++   // pointer (upcasting is easy, downcasting back to an int less so).
++   CFBundleRefNum *resource = new CFBundleRefNum;
++   *resource = CFBundleOpenBundleResourceMap(mBundleRef.get());
++   mResource = ResourceHandle {resource, ResourceDeleter{&mBundleRef}};
+ 
+ #elif defined(__WXMSW__)
+ 
+@@ -2270,7 +2280,7 @@ void VSTEffect::Unload()
+    if (mModule)
+    {
+ #if defined(__WXMAC__)
+-      mResource = ResourceHandle{};
++      mResource = ResourceHandle{nullptr, nullptr};
+       mBundleRef.reset();
+ #endif
+ 
+diff --git a/src/effects/VST/VSTEffect.h b/src/effects/VST/VSTEffect.h
+index ccf4e12b7ae0279c5900b8517c18a1a7e65aef51..4cad1618c87403a1cf4fa17023bcffe448c2f27f 100644
+--- a/src/effects/VST/VSTEffect.h
++++ b/src/effects/VST/VSTEffect.h
+@@ -308,7 +308,7 @@ private:
+       void operator() (void*) const;
+    };
+    using ResourceHandle = std::unique_ptr<
+-      char, ResourceDeleter
++      CFBundleRefNum, ResourceDeleter
+    >;
+    ResourceHandle mResource;
+ #endif
diff --git a/audio/audacity/files/patch-unordered_map-fixes.diff b/audio/audacity/files/patch-unordered_map-fixes.diff
index a386b6f7..f84a5c9d 100644
--- a/audio/audacity/files/patch-unordered_map-fixes.diff
+++ b/audio/audacity/files/patch-unordered_map-fixes.diff
@@ -2,6 +2,15 @@ diff --git a/src/MemoryX.h b/src/MemoryX.h
 index 56e99171a9eb87fe574291d0ec9d086efb0c1fbb..621afa3001ba354f36e80edb86c72a45dca426cb 100644
 --- a/src/MemoryX.h
 +++ b/src/MemoryX.h
+@@ -11,7 +13,7 @@
+ // std:: containers knowing about rvalue references
+ #undef __AUDACITY_OLD_STD__
+ 
+-#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED <= __MAC_10_6
++#if 0 //defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED <= __MAC_10_6
+ 
+ #define __AUDACITY_OLD_STD__
+ 
 @@ -1177,7 +1179,7 @@ namespace std
     namespace tr1
     {
