diff options
author | rubidium <rubidium@openttd.org> | 2009-11-11 21:15:58 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-11-11 21:15:58 +0000 |
commit | 485b5a9c2fc1840255a0fe2fe7a1dd3f4d0e0130 (patch) | |
tree | 7ad968ec694d6acaf54711b090f88c9973590be3 | |
parent | 285d25e01bff95ce845f4b92efa9ce0253b66429 (diff) | |
download | openttd-485b5a9c2fc1840255a0fe2fe7a1dd3f4d0e0130.tar.xz |
(svn r18045) -Fix: GCC 4.5@HEAD not compiling OpenTTD anymore because of a "non-placement deallocation function [is] selected for placement delete", or in other words delete(void *, size_t) is 'magic'.
We implemented these delete(void *, size_t) operator functions because MSVC warned that "no matching operator delete found; memory will not be freed if initialization throws an exception" for new(size_t, size_t).
This disables MSVC warning about this because we do not use exceptions in the (constructors that use the) overridden allocation functions, as such they will never be called; delete(void *) remains necessary though.
-rw-r--r-- | src/core/pool_type.hpp | 29 | ||||
-rw-r--r-- | src/newgrf_text.cpp | 35 | ||||
-rw-r--r-- | src/stdafx.h | 1 | ||||
-rw-r--r-- | src/window_gui.h | 25 |
4 files changed, 46 insertions, 44 deletions
diff --git a/src/core/pool_type.hpp b/src/core/pool_type.hpp index 58a58f6ac..9c32a81df 100644 --- a/src/core/pool_type.hpp +++ b/src/core/pool_type.hpp @@ -119,20 +119,6 @@ struct Pool { } /** - * Deletes item with given index. - * @param p Titem memory to release - * @param index index of item - * @note never use this! Only for internal use - * (called automatically when constructor of Titem uses throw()) - */ - FORCEINLINE void operator delete(void *p, size_t index) - { - assert(p == Tpool->Get(index)); - Tpool->FreeItem(index); - } - - - /** * Allocates space for new Titem at given memory address * @param size size of Titem * @param ptr where are we allocating the item? @@ -154,21 +140,6 @@ struct Pool { return ptr; } - /** - * Deletes item that was allocated by the function above - * @param p Titem memory to release - * @param ptr parameter given to operator new - * @note never use this! Only for internal use - * (called automatically when constructor of Titem uses throw()) - */ - FORCEINLINE void operator delete(void *p, void *ptr) - { - assert(p == ptr); - for (size_t i = 0; i < Tpool->first_unused; i++) { - assert(ptr != Tpool->data[i]); - } - } - /** Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() */ diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index 5b3e7d03c..59edbb22e 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -125,24 +125,39 @@ public: return new (strlen(text) + 1) GRFText(langid, text); } + /** + * Helper allocation function to disallow something. + * Don't allow simple 'news'; they wouldn't have enough memory. + * @param size the amount of space not to allocate + */ + void *operator new(size_t size) + { + NOT_REACHED(); + } + + /** + * Free the memory we allocated + * @param p memory to free + */ + void operator delete(void *p) + { + free(p); + } private: GRFText(byte langid_, const char *text_) : next(NULL), langid(langid_) { strcpy(text, text_); } + /** + * Allocate memory for this class. + * @param size the size of the instance + * @param extra the extra memory for the text + * @return the requested amount of memory for both the instance and the text + */ void *operator new(size_t size, size_t extra) { - return ::operator new(size + extra); - } - -public: - /* dummy operator delete to silence VC8: - * 'void *GRFText::operator new(size_t,size_t)' : no matching operator delete found; - * memory will not be freed if initialization throws an exception */ - void operator delete(void *p, size_t extra) - { - return ::operator delete(p); + return MallocT<byte>(size + extra); } public: diff --git a/src/stdafx.h b/src/stdafx.h index bac0a6c46..59601c6d6 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -162,6 +162,7 @@ #if (_MSC_VER < 1400) // MSVC 2005 safety checks #error "Only MSVC 2005 or higher are supported. MSVC 2003 and earlier are not! Upgrade your compiler." #endif /* (_MSC_VER < 1400) */ + #pragma warning(disable: 4291) // no matching operator delete found; memory will not be freed if initialization throws an exception (reason: our overloaded functions never throw an exception) #pragma warning(disable: 4996) // 'strdup' was declared deprecated #define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions #pragma warning(disable: 6308) // code analyzer: 'realloc' might return null pointer: assigning null pointer to 't_ptr', which is passed as an argument to 'realloc', will cause the original memory block to be leaked diff --git a/src/window_gui.h b/src/window_gui.h index 4cd4c990b..57fcd5a02 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -345,11 +345,26 @@ public: Window(); virtual ~Window(); - /* Don't allow arrays; arrays of Windows are pointless as you need - * to destruct them all at the same time too, which is kinda hard. */ - FORCEINLINE void *operator new[](size_t size) { NOT_REACHED(); } - /* Don't free the window directly; it corrupts the linked list when iterating */ - FORCEINLINE void operator delete(void *ptr) {} + + /** + * Helper allocation function to disallow something. + * Don't allow arrays; arrays of Windows are pointless as you need + * to destruct them all at the same time too, which is kinda hard. + * @param size the amount of space not to allocate + */ + FORCEINLINE void *operator new[](size_t size) + { + NOT_REACHED(); + } + + /** + * Helper allocation function to disallow something. + * Don't free the window directly; it corrupts the linked list when iterating + * @param ptr the pointer not to free + */ + FORCEINLINE void operator delete(void *ptr) + { + } uint16 flags4; ///< Window flags, @see WindowFlags WindowClass window_class; ///< Window class |