diff --git a/src/lib/util/corealloc.h b/src/lib/util/corealloc.h index b5fc126cba5..12dea2fce67 100644 --- a/src/lib/util/corealloc.h +++ b/src/lib/util/corealloc.h @@ -31,12 +31,12 @@ //************************************************************************** // global allocation helpers -- use these instead of new and delete -#define global_alloc(_type) new _type -#define global_alloc_nothrow(_type) new (std::nothrow) _type -#define global_alloc_array(_type, _num) new _type[_num] -#define global_alloc_array_nothrow(_type, _num) new (std::nothrow) _type[_num] -#define global_free(_ptr) do { delete _ptr; } while (0) -#define global_free_array(_ptr) do { delete[] _ptr; } while (0) +#define global_alloc(Type) new Type +#define global_alloc_nothrow(Type) new (std::nothrow) Type +#define global_alloc_array(Type, Num) new Type[Num] +#define global_alloc_array_nothrow(Type, Num) new (std::nothrow) Type[Num] +#define global_free(Ptr) do { delete Ptr; } while (0) +#define global_free_array(Ptr) do { delete[] Ptr; } while (0) @@ -59,54 +59,42 @@ inline T* global_alloc_array_clear(std::size_t num) -template -struct _MakeUniqClear -{ - typedef std::unique_ptr<_Tp> __single_object; -}; +template struct MakeUniqClearT { typedef std::unique_ptr single_object; }; -template -struct _MakeUniqClear<_Tp[]> -{ - typedef std::unique_ptr<_Tp[]> __array; -}; +template struct MakeUniqClearT { typedef std::unique_ptr array; }; -template -struct _MakeUniqClear<_Tp[_Bound]> -{ - struct __invalid_type { }; -}; +template struct MakeUniqClearT { struct invalid_type { }; }; /// make_unique_clear for single objects -template -inline typename _MakeUniqClear<_Tp>::__single_object make_unique_clear(_Args&&... __args) +template +inline typename MakeUniqClearT::single_object make_unique_clear(Params&&... args) { - unsigned char* ptr = new unsigned char[sizeof(_Tp)]; // allocate memory - memset(ptr, 0, sizeof(_Tp)); - return std::unique_ptr<_Tp>(new(ptr) _Tp(std::forward<_Args>(__args)...)); + void *const ptr = ::operator new(sizeof(Tp)); // allocate memory + std::memset(ptr, 0, sizeof(Tp)); + return std::unique_ptr(new(ptr) Tp(std::forward(args)...)); } /// make_unique_clear for arrays of unknown bound -template -inline typename _MakeUniqClear<_Tp>::__array make_unique_clear(size_t __num) +template +inline typename MakeUniqClearT::array make_unique_clear(size_t num) { - auto size = sizeof(std::remove_extent_t<_Tp>) * __num; + auto size = sizeof(std::remove_extent_t) * num; unsigned char* ptr = new unsigned char[size]; // allocate memory - memset(ptr, 0, size); - return std::unique_ptr<_Tp>(new(ptr) std::remove_extent_t<_Tp>[__num]()); + std::memset(ptr, 0, size); + return std::unique_ptr(new(ptr) std::remove_extent_t[num]()); } -template -inline typename _MakeUniqClear<_Tp>::__array make_unique_clear(size_t __num) +template +inline typename MakeUniqClearT::array make_unique_clear(size_t num) { - auto size = sizeof(std::remove_extent_t<_Tp>) * __num; + auto size = sizeof(std::remove_extent_t) * num; unsigned char* ptr = new unsigned char[size]; // allocate memory - memset(ptr, _F, size); - return std::unique_ptr<_Tp>(new(ptr) std::remove_extent_t<_Tp>[__num]()); + std::memset(ptr, F, size); + return std::unique_ptr(new(ptr) std::remove_extent_t[num]()); } /// Disable make_unique_clear for arrays of known bound -template -inline typename _MakeUniqClear<_Tp>::__invalid_type make_unique_clear(_Args&&...) = delete; +template +inline typename MakeUniqClearT::invalid_type make_unique_clear(Params&&...) = delete; #endif // MAME_LIB_UTIL_COREALLOC_H diff --git a/src/osd/osdcomm.h b/src/osd/osdcomm.h index a376ee6b9bd..ff8ca667713 100644 --- a/src/osd/osdcomm.h +++ b/src/osd/osdcomm.h @@ -17,6 +17,8 @@ #include #include #include +#include + /*************************************************************************** COMPILER-SPECIFIC NASTINESS @@ -131,6 +133,15 @@ using FPTR = uintptr_t; // Highly useful template for compile-time knowledge of an array size template constexpr inline size_t ARRAY_LENGTH(T (&)[N]) { return N;} +// For declaring an array of the same dimensions as another array (including multi-dimensional arrays) +template struct equivalent_array_or_type { typedef T type; }; +template struct equivalent_array_or_type { typedef typename equivalent_array_or_type::type type[N]; }; +template using equivalent_array_or_type_t = typename equivalent_array_or_type::type; +template struct equivalent_array { }; +template struct equivalent_array { typedef equivalent_array_or_type_t type[N]; }; +template using equivalent_array_t = typename equivalent_array::type; +#define EQUIVALENT_ARRAY(a, T) equivalent_array_t > + /* Macros for normalizing data into big or little endian formats */ #define FLIPENDIAN_INT16(x) (((((UINT16) (x)) >> 8) | ((x) << 8)) & 0xffff) diff --git a/src/tools/chdman.cpp b/src/tools/chdman.cpp index addfe14a913..ee2bae66779 100644 --- a/src/tools/chdman.cpp +++ b/src/tools/chdman.cpp @@ -471,7 +471,7 @@ public: // loop over channels and read the samples int channels = MIN(m_info.channels, ARRAY_LENGTH(m_audio)); - INT16 *samplesptr[ARRAY_LENGTH(m_audio)]; + EQUIVALENT_ARRAY(m_audio, INT16 *) samplesptr; for (int chnum = 0; chnum < channels; chnum++) { // read the sound samples