(svn r18047) [0.7] -Backport from trunk:

- Fix: GCC 4.5 compiling (r18045, r18040)
This commit is contained in:
rubidium 2009-11-11 22:09:34 +00:00
parent b4ba357017
commit 49ac7c9338
4 changed files with 62 additions and 39 deletions

View File

@ -163,20 +163,12 @@ public:
/**
* Memory release for a single class instance.
* @param ptr the memory to free.
* @param size the amount of allocated memory (unused).
*
* @warning The value of the \a size parameter can only be trusted for
* classes that have their own (virtual) destructor method.
*/
FORCEINLINE void operator delete(void *ptr, size_t size) { free(ptr); }
/**
* Memory release for an array of class instances.
* @param ptr the memory to free.
* @param size the amount of allocated memory (unused).
*
* @warning The value of the \a size parameter can only be trusted for
* classes that have their own (virtual) destructor method.
*/
FORCEINLINE void operator delete[](void *ptr, size_t size) { free(ptr); }
};

View File

@ -51,36 +51,51 @@ enum GRFExtendedLanguages {
* but according to a different lang.
*/
struct GRFText {
public:
static GRFText* New(byte langid, const char* text)
{
return new(strlen(text) + 1) GRFText(langid, text);
}
public:
static GRFText *New(byte langid, const char *text)
{
return new (strlen(text) + 1) GRFText(langid, text);
}
private:
GRFText(byte langid_, const char* text_) : next(NULL), langid(langid_)
{
strcpy(text, 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();
}
void *operator new(size_t size, size_t extra)
{
return ::operator new(size + extra);
}
/**
* 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 MallocT<byte>(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);
}
public:
GRFText *next;
byte langid;
char text[VARARRAY_SIZE];
GRFText *next;
byte langid;
char text[VARARRAY_SIZE];
};

View File

@ -173,6 +173,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

View File

@ -139,11 +139,26 @@ public:
Window(const WindowDesc *desc, WindowNumber number = 0);
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, size_t size) {}
/**
* 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