From 7c382a3cc4f4f399ace7f70e08629723aff111a1 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 16 Nov 2011 19:50:16 -0800 Subject: I hate doing this, but, well. Maybe I should design a memory allocator class, but, meh. --- includes/Exceptions.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'includes/Exceptions.h') diff --git a/includes/Exceptions.h b/includes/Exceptions.h index e17e468..0563090 100644 --- a/includes/Exceptions.h +++ b/includes/Exceptions.h @@ -21,6 +21,33 @@ class GeneralException { char * m_msg; }; +static inline void * malloc(size_t size) throw (GeneralException) { + void * r = ::malloc(size); + + if (!r && size) + throw GeneralException("Failed to allocate memory."); + + return r; +} + +static inline void * calloc(size_t count, size_t size) throw (GeneralException) { + void * r = ::calloc(count, size); + + if (!r && ((count * size) != 0)) + throw GeneralException("Failed to allocate memory."); + + return r; +} + +static inline void * realloc(void * previous, size_t size) throw (GeneralException) { + void * r = ::realloc(previous, size); + + if (!r && size) + throw GeneralException("Failed to allocate memory."); + + return r; +} + static inline void AssertHelper(const String & msg) throw(GeneralException) { throw GeneralException(msg); } class ClassName { -- cgit v1.2.3