]> granicus.if.org Git - gc/commitdiff
Fix delete operator redirection if gc_cpp is built as .dll (Cygwin, MinGW)
authorIvan Maidanski <ivmai@mail.ru>
Wed, 15 Aug 2018 07:23:33 +0000 (10:23 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 15 Aug 2018 07:24:56 +0000 (10:24 +0300)
Issue #229 (bdwgc).

* include/gc_cpp.h [(__CYGWIN32__ || __CYGWIN__ || __MINGW32__)
&& !GC_BUILD && !GC_NOT_DLL && GC_OPERATOR_NEW_ARRAY] (operator new[],
operator delete[]): Define inline function.
* include/gc_cpp.h [(__CYGWIN32__ || __CYGWIN__ || __MINGW32__)
&& !GC_BUILD && !GC_NOT_DLL] (operator new, operator delete): Likewise.
* include/gc_cpp.h [_MSC_VER || __DMC__ || (__CYGWIN32__ || __CYGWIN__
|| __MINGW32__) && !GC_BUILD && !GC_NOT_DLL && __cplusplus>201103L]
(operator delete(void*,size_t)): Likewise.
* include/gc_cpp.h [_MSC_VER || __DMC__ || (__CYGWIN32__ || __CYGWIN__
|| __MINGW32__) && !GC_BUILD && !GC_NOT_DLL && __cplusplus>201103L
&& GC_OPERATOR_NEW_ARRAY && !CPPCHECK]
(operator delete[](void*,size_t)): Likewise.
* include/gc_cpp.h (operator new(size_t, int, const char*, int),
operator new[](size_t, int, const char*, int)): Do not define
for __DMC__.

include/gc_cpp.h

index 81a748deb774dafdb30c6c60a04a41f02fc22e00..a5f5e79ba12ab8e10ca6aee98d5695cc542b11a8 100644 (file)
@@ -306,7 +306,9 @@ inline void* operator new(size_t size, GC_NS_QUALIFY(GCPlacement) gcp,
                               void*) GC_NOEXCEPT;
 #endif
 
-#if defined(_MSC_VER) || defined(__DMC__)
+#if defined(_MSC_VER) || defined(__DMC__) \
+    || ((defined(__CYGWIN32__) || defined(__CYGWIN__) \
+        || defined(__MINGW32__)) && !defined(GC_BUILD) && !defined(GC_NOT_DLL))
   // The following ensures that the system default operator new[] does not
   // get undefined, which is what seems to happen on VC++ 6 for some reason
   // if we define a multi-argument operator new[].
@@ -341,6 +343,23 @@ inline void* operator new(size_t size, GC_NS_QUALIFY(GCPlacement) gcp,
     GC_FREE(obj);
   }
 
+# if __cplusplus > 201103L // C++14
+    inline void operator delete(void* obj, size_t size) GC_NOEXCEPT {
+      (void)size; // size is ignored
+      GC_FREE(obj);
+    }
+
+#   if defined(GC_OPERATOR_NEW_ARRAY) && !defined(CPPCHECK)
+      inline void operator delete[](void* obj, size_t size) GC_NOEXCEPT {
+        (void)size;
+        GC_FREE(obj);
+      }
+#   endif
+# endif // C++14
+#endif
+
+#ifdef _MSC_VER
+
   // This new operator is used by VC++ in case of Debug builds:
 # ifdef GC_DEBUG
     inline void* operator new(size_t size, int /* nBlockUse */,