From d7cc9b912b71b17d6cd1bb9726673b79a4c0173a Mon Sep 17 00:00:00 2001
From: Chris Robinson <chris.kcat@gmail.com>
Date: Sun, 18 Nov 2018 00:38:31 -0800
Subject: Use new/delete for ALCcontext objects

---
 common/almalloc.cpp |  6 +++---
 common/almalloc.h   | 23 ++++++++++++-----------
 2 files changed, 15 insertions(+), 14 deletions(-)

(limited to 'common')

diff --git a/common/almalloc.cpp b/common/almalloc.cpp
index 1b90d1c0..6dcb6cfc 100644
--- a/common/almalloc.cpp
+++ b/common/almalloc.cpp
@@ -55,7 +55,7 @@ void *al_calloc(size_t alignment, size_t size)
     return ret;
 }
 
-void al_free(void *ptr)
+void al_free(void *ptr) noexcept
 {
 #if defined(HAVE_ALIGNED_ALLOC) || defined(HAVE_POSIX_MEMALIGN)
     free(ptr);
@@ -73,7 +73,7 @@ void al_free(void *ptr)
 #endif
 }
 
-size_t al_get_page_size(void)
+size_t al_get_page_size(void) noexcept
 {
     static size_t psize = 0;
     if(UNLIKELY(!psize))
@@ -100,7 +100,7 @@ size_t al_get_page_size(void)
     return psize;
 }
 
-int al_is_sane_alignment_allocator(void)
+int al_is_sane_alignment_allocator(void) noexcept
 {
 #if defined(HAVE_ALIGNED_ALLOC) || defined(HAVE_POSIX_MEMALIGN) || defined(HAVE__ALIGNED_MALLOC)
     return 1;
diff --git a/common/almalloc.h b/common/almalloc.h
index a4297cf5..ad48db8b 100644
--- a/common/almalloc.h
+++ b/common/almalloc.h
@@ -3,28 +3,29 @@
 
 #include <stddef.h>
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /* Minimum alignment required by posix_memalign. */
 #define DEF_ALIGN sizeof(void*)
 
 void *al_malloc(size_t alignment, size_t size);
 void *al_calloc(size_t alignment, size_t size);
-void al_free(void *ptr);
+void al_free(void *ptr) noexcept;
 
-size_t al_get_page_size(void);
+size_t al_get_page_size(void) noexcept;
 
 /**
  * Returns non-0 if the allocation function has direct alignment handling.
  * Otherwise, the standard malloc is used with an over-allocation and pointer
  * offset strategy.
  */
-int al_is_sane_alignment_allocator(void);
-
-#ifdef __cplusplus
-}
-#endif
+int al_is_sane_alignment_allocator(void) noexcept;
+
+#define DEF_NEWDEL(T)                                                         \
+    void *operator new(size_t size)                                           \
+    {                                                                         \
+        void *ret = al_malloc(alignof(T), size);                              \
+        if(!ret) throw std::bad_alloc();                                      \
+        return ret;                                                           \
+    }                                                                         \
+    void operator delete(void *block) noexcept { al_free(block); }
 
 #endif /* AL_MALLOC_H */
-- 
cgit v1.2.3