summaryrefslogtreecommitdiff
path: root/src/newgrf_text.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-11-11 21:15:58 +0000
committerrubidium <rubidium@openttd.org>2009-11-11 21:15:58 +0000
commit485b5a9c2fc1840255a0fe2fe7a1dd3f4d0e0130 (patch)
tree7ad968ec694d6acaf54711b090f88c9973590be3 /src/newgrf_text.cpp
parent285d25e01bff95ce845f4b92efa9ce0253b66429 (diff)
downloadopenttd-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.
Diffstat (limited to 'src/newgrf_text.cpp')
-rw-r--r--src/newgrf_text.cpp35
1 files changed, 25 insertions, 10 deletions
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: