diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-05-24 00:38:44 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-05-24 00:38:44 +0300 |
commit | d2c42029b98c665725768b891aa877eb3267664f (patch) | |
tree | b232b9a20e45ecb4e7ec2133d7806669054708a6 | |
parent | fe39570810969993f51a0ff6045d0a5d4397a5e5 (diff) | |
download | plus-d2c42029b98c665725768b891aa877eb3267664f.tar.gz plus-d2c42029b98c665725768b891aa877eb3267664f.tar.bz2 plus-d2c42029b98c665725768b891aa877eb3267664f.tar.xz plus-d2c42029b98c665725768b891aa877eb3267664f.zip |
Add simple memory leak detector.
Can be enabled by configure option -enable-memdebug=yes.
Known issue: not all memory allocations hooked with it.
246 files changed, 1931 insertions, 7 deletions
@@ -38,7 +38,8 @@ autoreconf -i ./configure --prefix=$dir/run \ --datadir=$dir/run/share/games \ --bindir=$dir/run/bin \ ---mandir=$dir/run/share/man +--mandir=$dir/run/share/man \ +--enable-memdebug=no cd po #make -j5 update-po 2>../make1.log diff --git a/configure.ac b/configure.ac index f79cecb1d..d76f687ca 100755 --- a/configure.ac +++ b/configure.ac @@ -156,6 +156,17 @@ esac],[portable_enabled=false]) AM_CONDITIONAL(ENABLE_PORTABLE, test x$portable_enabled = xtrue) +# Enable debug +AC_ARG_ENABLE(memdebug, +[ --enable-memdebug Turn on memory debug mode], +[case "${enableval}" in + yes) memdebug_enabled=true ;; + no) memdebug_enabled=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-memdebug) ;; +esac],[memdebug_enabled=false]) + +AM_CONDITIONAL(ENABLE_MEM_DEBUG, test x$memdebug_enabled = xtrue) + AC_CONFIG_FILES([ Makefile src/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 31674723d..aa361ab87 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,7 +10,18 @@ if ENABLE_PORTABLE manaplus_CXXFLAGS += -DENABLE_PORTABLE endif -manaplus_SOURCES = gui/widgets/avatarlistbox.cpp \ +if ENABLE_MEM_DEBUG +manaplus_CXXFLAGS += -DENABLE_MEM_DEBUG + +manaplus_SOURCES = debug/debug_new.cpp \ + debug/debug_new.h \ + debug/fast_mutex.h \ + debug/static_assert.h +else +manaplus_SOURCES = +endif + +manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/avatarlistbox.h \ gui/widgets/battletab.cpp \ gui/widgets/battletab.h \ @@ -374,6 +385,7 @@ manaplus_SOURCES = gui/widgets/avatarlistbox.cpp \ configlistener.h \ configuration.cpp \ configuration.h \ + debug.h \ defaults.cpp \ defaults.h \ effectmanager.cpp \ @@ -601,6 +613,7 @@ manaplus_SOURCES += \ mumblemanager.cpp \ mumblemanager.h + EXTRA_DIST = CMakeLists.txt \ winver.h.in diff --git a/src/actor.cpp b/src/actor.cpp index 77ad0e4de..147b01cb6 100644 --- a/src/actor.cpp +++ b/src/actor.cpp @@ -26,6 +26,8 @@ #include "resources/image.h" #include "resources/resourcemanager.h" +#include "debug.h" + Actor::Actor(): mMap(0) {} diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index 23f229217..a3c0f2e93 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -39,6 +39,8 @@ #include "resources/imageset.h" #include "resources/resourcemanager.h" +#include "debug.h" + #define EFFECTS_FILE "effects.xml" ImageSet *ActorSprite::targetCursorImages[2][NUM_TC]; diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 9be75e0db..1b2e0c2e8 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -49,6 +49,8 @@ #include <list> #include <vector> +#include "debug.h" + #define for_actors ActorSpritesConstIterator it, it_end; \ for (it = mActors.begin(), it_end = mActors.end() ; it != it_end; ++it) diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 5d5c1ee18..80a2014eb 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -34,6 +34,8 @@ #include <cassert> +#include "debug.h" + AnimatedSprite::AnimatedSprite(SpriteDef *sprite): mDirection(DIRECTION_DOWN), mLastTime(0), diff --git a/src/animationparticle.cpp b/src/animationparticle.cpp index de8fb68fb..fbe0e29df 100644 --- a/src/animationparticle.cpp +++ b/src/animationparticle.cpp @@ -25,6 +25,8 @@ #include "graphics.h" #include "simpleanimation.h" +#include "debug.h" + AnimationParticle::AnimationParticle(Map *map, Animation *animation): ImageParticle(map, 0), mAnimation(new SimpleAnimation(animation)) diff --git a/src/avatar.cpp b/src/avatar.cpp index b3d40e259..9a4831f18 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -24,6 +24,8 @@ #include <sstream> +#include "debug.h" + Avatar::Avatar(const std::string &name): mId(0), mCharId(0), diff --git a/src/being.cpp b/src/being.cpp index b995338a4..5230edeae 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -82,6 +82,8 @@ #include <cassert> #include <cmath> +#include "debug.h" + #define CACHE_SIZE 50 #define HAIR_FILE "hair.xml" diff --git a/src/channel.cpp b/src/channel.cpp index 74ecbeada..c9194ec6f 100644 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -24,6 +24,8 @@ #include "gui/widgets/channeltab.h" +#include "debug.h" + Channel::Channel(short id, const std::string &name, const std::string &announcement) : diff --git a/src/channelmanager.cpp b/src/channelmanager.cpp index 6bdc90468..23c68c1f7 100644 --- a/src/channelmanager.cpp +++ b/src/channelmanager.cpp @@ -26,6 +26,8 @@ #include "utils/dtor.h" +#include "debug.h" + ChannelManager::ChannelManager() { } diff --git a/src/chatlog.cpp b/src/chatlog.cpp index 8d3e43f50..b0ff14479 100644 --- a/src/chatlog.cpp +++ b/src/chatlog.cpp @@ -42,6 +42,8 @@ #include "utils/stringutils.h" +#include "debug.h" + ChatLogger::ChatLogger() { } diff --git a/src/client.cpp b/src/client.cpp index a5028f790..96d21c96c 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -113,6 +113,8 @@ #include "mumblemanager.h" +#include "debug.h" + /** * Tells the max tick value, * setting it back to zero (and start again). diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 14a1a3044..ece2ccb44 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -61,6 +61,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + extern std::string tradePartnerName; CommandHandler::CommandHandler() diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp index 4f8333525..8f6f1f60a 100644 --- a/src/compoundsprite.cpp +++ b/src/compoundsprite.cpp @@ -35,6 +35,8 @@ #include <SDL.h> +#include "debug.h" + #define BUFFER_WIDTH 100 #define BUFFER_HEIGHT 100 diff --git a/src/configuration.cpp b/src/configuration.cpp index 04acbce28..ffb80ad13 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -30,6 +30,8 @@ #include <libxml/encoding.h> +#include "debug.h" + #ifdef DEBUG_CONFIG #define GETLOG() if (logger) {logger->log("config get: " + key); } #else diff --git a/src/debug.h b/src/debug.h new file mode 100644 index 000000000..0e8e19961 --- /dev/null +++ b/src/debug.h @@ -0,0 +1,25 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifdef ENABLE_MEM_DEBUG +#define _DEBUG_NEW_EMULATE_MALLOC 1 + +#include "debug/debug_new.h" +#endif diff --git a/src/debug/debug_new.cpp b/src/debug/debug_new.cpp new file mode 100644 index 000000000..73b56bc7e --- /dev/null +++ b/src/debug/debug_new.cpp @@ -0,0 +1,844 @@ +// -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- +// vim:tabstop=4:shiftwidth=4:expandtab: + +/* + * Copyright (C) 2004-2008 Wu Yongwei <adah at users dot sourceforge dot net> + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any + * damages arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute + * it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must + * not claim that you wrote the original software. If you use this + * software in a product, an acknowledgement in the product + * documentation would be appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must + * not be misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source + * distribution. + * + * This file is part of Stones of Nvwa: + * http://sourceforge.net/projects/nvwa + * + * original version changed for ManaPlus + * + * Copyright (C) 2011 ManaPlus developers + */ + +/** + * @file debug_new.cpp + * + * Implementation of debug versions of new and delete to check leakage. + * + * @version 4.14, 2008/10/20 + * @author Wu Yongwei + * + */ + +#include <new> +#include <assert.h> +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#ifdef __unix__ +#include <alloca.h> +#endif +#ifdef _WIN32 +#include <malloc.h> +#endif +#include "debug/fast_mutex.h" +#include "debug/static_assert.h" + +#if !_FAST_MUTEX_CHECK_INITIALIZATION && !defined(_NOTHREADS) +#error "_FAST_MUTEX_CHECK_INITIALIZATION not set: check_leaks may not work" +#endif + +/** + * @def _DEBUG_NEW_ALIGNMENT + * + * The alignment requirement of allocated memory blocks. It must be a + * power of two. + */ +#ifndef _DEBUG_NEW_ALIGNMENT +#define _DEBUG_NEW_ALIGNMENT 16 +#endif + +/** + * @def _DEBUG_NEW_CALLER_ADDRESS + * + * The expression to return the caller address. #print_position will + * later on use this address to print the position information of memory + * operation points. + */ +#ifndef _DEBUG_NEW_CALLER_ADDRESS +#ifdef __GNUC__ +#define _DEBUG_NEW_CALLER_ADDRESS __builtin_return_address(0) +#else +#define _DEBUG_NEW_CALLER_ADDRESS NULL +#endif +#endif + +/** + * @def _DEBUG_NEW_ERROR_ACTION + * + * The action to take when an error occurs. The default behaviour is to + * call \e abort, unless \c _DEBUG_NEW_ERROR_CRASH is defined, in which + * case a segmentation fault will be triggered instead (which can be + * useful on platforms like Windows that do not generate a core dump + * when \e abort is called). + */ +#ifndef _DEBUG_NEW_ERROR_ACTION +#ifndef _DEBUG_NEW_ERROR_CRASH +#define _DEBUG_NEW_ERROR_ACTION abort() +#else +#define _DEBUG_NEW_ERROR_ACTION do { *((char*)0) = 0; abort(); } while (0) +#endif +#endif + +/** + * @def _DEBUG_NEW_FILENAME_LEN + * + * The length of file name stored if greater than zero. If it is zero, + * only a const char pointer will be stored. Currently the default + * behaviour is to copy the file name, because I found that the exit + * leakage check cannot access the address of the file name sometimes + * (in my case, a core dump will occur when trying to access the file + * name in a shared library after a \c SIGINT). The current default + * value makes the size of new_ptr_list_t 64 on 32-bit platforms. + */ +#ifndef _DEBUG_NEW_FILENAME_LEN +#define _DEBUG_NEW_FILENAME_LEN 44 +#endif + +/** + * @def _DEBUG_NEW_PROGNAME + * + * The program (executable) name to be set at compile time. It is + * better to assign the full program path to #new_progname in \e main + * (at run time) than to use this (compile-time) macro, but this macro + * serves well as a quick hack. Note also that double quotation marks + * need to be used around the program name, i.e., one should specify a + * command-line option like <code>-D_DEBUG_NEW_PROGNAME=\"a.out\"</code> + * in \e bash, or <code>-D_DEBUG_NEW_PROGNAME=\"a.exe\"</code> in the + * Windows command prompt. + */ +#ifndef _DEBUG_NEW_PROGNAME +#define _DEBUG_NEW_PROGNAME NULL +#endif + +/** + * @def _DEBUG_NEW_STD_OPER_NEW + * + * Macro to indicate whether the standard-conformant behaviour of + * <code>operator new</code> is wanted. It is on by default now, but + * the user may set it to \c 0 to revert to the old behaviour. + */ +#ifndef _DEBUG_NEW_STD_OPER_NEW +#define _DEBUG_NEW_STD_OPER_NEW 1 +#endif + +/** + * @def _DEBUG_NEW_TAILCHECK + * + * Macro to indicate whether a writing-past-end check will be performed. + * Define it to a positive integer as the number of padding bytes at the + * end of a memory block for checking. + */ +#ifndef _DEBUG_NEW_TAILCHECK +#define _DEBUG_NEW_TAILCHECK 0 +#endif + +/** + * @def _DEBUG_NEW_TAILCHECK_CHAR + * + * Value of the padding bytes at the end of a memory block. + */ +#ifndef _DEBUG_NEW_TAILCHECK_CHAR +#define _DEBUG_NEW_TAILCHECK_CHAR 0xCC +#endif + +/** + * @def _DEBUG_NEW_USE_ADDR2LINE + * + * Whether to use \e addr2line to convert a caller address to file/line + * information. Defining it to a non-zero value will enable the + * conversion (automatically done if GCC is detected). Defining it to + * zero will disable the conversion. + */ +#ifndef _DEBUG_NEW_USE_ADDR2LINE +#ifdef __GNUC__ +#define _DEBUG_NEW_USE_ADDR2LINE 1 +#else +#define _DEBUG_NEW_USE_ADDR2LINE 0 +#endif +#endif + +#ifdef _MSC_VER +#pragma warning(disable: 4073) // #pragma init_seg(lib) used +#pragma warning(disable: 4290) // C++ exception specification ignored +#pragma init_seg(lib) +#endif + +#undef _DEBUG_NEW_EMULATE_MALLOC +#undef _DEBUG_NEW_REDEFINE_NEW +/** + * Macro to indicate whether redefinition of \c new is wanted. Here it + * is defined to \c 0 to disable the redefinition of \c new. + */ +#define _DEBUG_NEW_REDEFINE_NEW 0 +#include "debug_new.h" + +/** + * Gets the aligned value of memory block size. + */ +#define align(s) \ + (((s) + _DEBUG_NEW_ALIGNMENT - 1) & ~(_DEBUG_NEW_ALIGNMENT - 1)) + +/** + * Structure to store the position information where \c new occurs. + */ +struct new_ptr_list_t +{ + new_ptr_list_t* next; + new_ptr_list_t* prev; + size_t size; + union + { +#if _DEBUG_NEW_FILENAME_LEN == 0 + const char* file; +#else + char file[_DEBUG_NEW_FILENAME_LEN]; +#endif + void* addr; + }; + unsigned line :31; + unsigned is_array :1; + unsigned magic; +}; + +/** + * Magic number for error detection. + */ +const unsigned MAGIC = 0x4442474E; + +/** + * The extra memory allocated by <code>operator new</code>. + */ +const int ALIGNED_LIST_ITEM_SIZE = align(sizeof(new_ptr_list_t)); + +/** + * List of all new'd pointers. + */ +static new_ptr_list_t new_ptr_list = { + &new_ptr_list, + &new_ptr_list, + 0, + { +#if _DEBUG_NEW_FILENAME_LEN == 0 + NULL +#else + "" +#endif + }, + 0, + 0, + MAGIC +}; + +/** + * The mutex guard to protect simultaneous access to the pointer list. + */ +static fast_mutex new_ptr_lock; + +/** + * The mutex guard to protect simultaneous output to #new_output_fp. + */ +static fast_mutex new_output_lock; + +/** + * Total memory allocated in bytes. + */ +static size_t total_mem_alloc = 0; + +/** + * Flag to control whether #check_leaks will be automatically called on + * program exit. + */ +bool new_autocheck_flag = true; + +/** + * Flag to control whether verbose messages are output. + */ +bool new_verbose_flag = false; + +/** + * Pointer to the output stream. The default output is \e stderr, and + * one may change it to a user stream if needed (say, #new_verbose_flag + * is \c true and there are a lot of (de)allocations). + */ +FILE* new_output_fp = stderr; + +/** + * Pointer to the program name. Its initial value is the macro + * #_DEBUG_NEW_PROGNAME. You should try to assign the program path to + * it early in your application. Assigning <code>argv[0]</code> to it + * in \e main is one way. If you use \e bash or \e ksh (or similar), + * the following statement is probably what you want: + * `<code>new_progname = getenv("_");</code>'. + */ +const char* new_progname = _DEBUG_NEW_PROGNAME; + +#if _DEBUG_NEW_USE_ADDR2LINE +/** + * Tries printing the position information from an instruction address. + * This is the version that uses \e addr2line. + * + * @param addr the instruction address to convert and print + * @return \c true if the address is converted successfully (and + * the result is printed); \c false if no useful + * information is got (and nothing is printed) + */ +static bool print_position_from_addr(const void* addr) +{ + static const void* last_addr = NULL; + static char last_info[256] = ""; + if (addr == last_addr) + { + if (last_info[0] == '\0') + return false; + fprintf(new_output_fp, "%s", last_info); + return true; + } + if (new_progname) + { + const char addr2line_cmd[] = "addr2line -e "; +#if defined(__CYGWIN__) || defined(_WIN32) + const int exeext_len = 4; +#else + const int exeext_len = 0; +#endif +#if !defined(__CYGWIN__) && defined(__unix__) + const char ignore_err[] = " 2>/dev/null"; +#elif defined(__CYGWIN__) || \ + (defined(_WIN32) && defined(WINVER) && WINVER >= 0x0500) + const char ignore_err[] = " 2>nul"; +#else + const char ignore_err[] = ""; +#endif + char* cmd = (char*)alloca(strlen(new_progname) + + exeext_len + + sizeof addr2line_cmd - 1 + + sizeof ignore_err - 1 + + sizeof(void*) * 2 + + 4 /* SP + "0x" + null */); + strcpy(cmd, addr2line_cmd); + strcpy(cmd + sizeof addr2line_cmd - 1, new_progname); + size_t len = strlen(cmd); +#if defined(__CYGWIN__) || defined(_WIN32) + if (len <= 4 + || (strcmp(cmd + len - 4, ".exe") != 0 && + strcmp(cmd + len - 4, ".EXE") != 0)) + { + strcpy(cmd + len, ".exe"); + len += 4; + } +#endif + sprintf(cmd + len, " %p%s", addr, ignore_err); + FILE* fp = popen(cmd, "r"); + if (fp) + { + char buffer[sizeof last_info] = ""; + len = 0; + if (fgets(buffer, sizeof buffer, fp)) + { + len = strlen(buffer); + if (buffer[len - 1] == '\n') + buffer[--len] = '\0'; + } + int res = pclose(fp); + // Display the file/line information only if the command + // is executed successfully and the output points to a + // valid position, but the result will be cached if only + // the command is executed successfully. + if (res == 0 && len > 0) + { + last_addr = addr; + if (buffer[len - 1] == '0' && buffer[len - 2] == ':') + last_info[0] = '\0'; + else + { + fprintf(new_output_fp, "%s", buffer); + strcpy(last_info, buffer); + return true; + } + } + } + } + return false; +} +#else +/** + * Tries printing the position information from an instruction address. + * This is the stub version that does nothing at all. + * + * @return \c false always + */ +static bool print_position_from_addr(const void*) +{ + return false; +} +#endif // _DEBUG_NEW_USE_ADDR2LINE + +/** + * Prints the position information of a memory operation point. When \c + * _DEBUG_NEW_USE_ADDR2LINE is defined to a non-zero value, this + * function will try to convert a given caller address to file/line + * information with \e addr2line. + * + * @param ptr source file name if \e line is non-zero; caller address + * otherwise + * @param line source line number if non-zero; indication that \e ptr + * is the caller address otherwise + */ +static void print_position(const void* ptr, int line) +{ + if (line != 0) // Is file/line information present? + { + fprintf(new_output_fp, "%s:%d", (const char*)ptr, line); + } + else if (ptr != NULL) // Is caller address present? + { + if (!print_position_from_addr(ptr)) // Fail to get source position? + fprintf(new_output_fp, "%p", ptr); + } + else // No information is present + { + fprintf(new_output_fp, "<Unknown>"); + } +} + +#if _DEBUG_NEW_TAILCHECK +/** + * Checks whether the padding bytes at the end of a memory block is + * tampered with. + * + * @param ptr pointer to a new_ptr_list_t struct + * @return \c true if the padding bytes are untouched; \c false + * otherwise + */ +static bool check_tail(new_ptr_list_t* ptr) +{ + const unsigned char* const pointer = (unsigned char*)ptr + + ALIGNED_LIST_ITEM_SIZE + ptr->size; + for (int i = 0; i < _DEBUG_NEW_TAILCHECK; ++i) + if (pointer[i] != _DEBUG_NEW_TAILCHECK_CHAR) + return false; + return true; +} +#endif + +/** + * Allocates memory and initializes control data. + * + * @param size size of the required memory block + * @param file null-terminated string of the file name + * @param line line number + * @param is_array boolean value whether this is an array operation + * @return pointer to the user-requested memory area; \c NULL + * if memory allocation is not successful + */ +static void* alloc_mem(size_t size, const char* file, int line, bool is_array) +{ + assert(line >= 0); + STATIC_ASSERT((_DEBUG_NEW_ALIGNMENT & (_DEBUG_NEW_ALIGNMENT - 1)) == 0, + Alignment_must_be_power_of_two); + STATIC_ASSERT(_DEBUG_NEW_TAILCHECK >= 0, Invalid_tail_check_length); + size_t s = size + ALIGNED_LIST_ITEM_SIZE + _DEBUG_NEW_TAILCHECK; + new_ptr_list_t* ptr = (new_ptr_list_t*)malloc(s); + if (ptr == NULL) + { +#if _DEBUG_NEW_STD_OPER_NEW + return NULL; +#else + fast_mutex_autolock lock(new_output_lock); + fprintf(new_output_fp, + "Out of memory when allocating %u bytes\n", + size); + fflush(new_output_fp); + _DEBUG_NEW_ERROR_ACTION; +#endif + } + void* pointer = (char*)ptr + ALIGNED_LIST_ITEM_SIZE; +#if _DEBUG_NEW_FILENAME_LEN == 0 + ptr->file = file; +#else + if (line) + strncpy(ptr->file, file, _DEBUG_NEW_FILENAME_LEN - 1) + [_DEBUG_NEW_FILENAME_LEN - 1] = '\0'; + else + ptr->addr = (void*)file; +#endif + ptr->line = line; + ptr->is_array = is_array; + ptr->size = size; + ptr->magic = MAGIC; + { + fast_mutex_autolock lock(new_ptr_lock); + ptr->prev = new_ptr_list.prev; + ptr->next = &new_ptr_list; + new_ptr_list.prev->next = ptr; + new_ptr_list.prev = ptr; + } +#if _DEBUG_NEW_TAILCHECK + memset((char*)pointer + size, _DEBUG_NEW_TAILCHECK_CHAR, + _DEBUG_NEW_TAILCHECK); +#endif + if (new_verbose_flag) + { + fast_mutex_autolock lock(new_output_lock); + fprintf(new_output_fp, + "new%s: allocated %p (size %u, ", + is_array ? "[]" : "", + pointer, (unsigned)size); + if (line != 0) + print_position(ptr->file, ptr->line); + else + print_position(ptr->addr, ptr->line); + fprintf(new_output_fp, ")\n"); + } + total_mem_alloc += size; + return pointer; +} + +/** + * Frees memory and adjusts pointers. + * + * @param pointer pointer to delete + * @param addr pointer to the caller + * @param is_array flag indicating whether it is invoked by a + * <code>delete[]</code> call + */ +static void free_pointer(void* pointer, void* addr, bool is_array) +{ + if (pointer == NULL) + return; + new_ptr_list_t* ptr = + (new_ptr_list_t*)((char*)pointer - ALIGNED_LIST_ITEM_SIZE); + if (ptr->magic != MAGIC) + { + { + fast_mutex_autolock lock(new_output_lock); + fprintf(new_output_fp, "delete%s: invalid pointer %p (", + is_array ? "[]" : "", pointer); + print_position(addr, 0); + fprintf(new_output_fp, ")\n"); + } + check_mem_corruption(); + fflush(new_output_fp); + _DEBUG_NEW_ERROR_ACTION; + } + if (is_array != ptr->is_array) + { + const char* msg; + if (is_array) + msg = "delete[] after new"; + else + msg = "delete after new[]"; + fast_mutex_autolock lock(new_output_lock); + fprintf(new_output_fp, + "%s: pointer %p (size %u)\n\tat ", + msg, + (char*)ptr + ALIGNED_LIST_ITEM_SIZE, + (unsigned)ptr->size); + print_position(addr, 0); + fprintf(new_output_fp, "\n\toriginally allocated at "); + if (ptr->line != 0) + print_position(ptr->file, ptr->line); + else + print_position(ptr->addr, ptr->line); + fprintf(new_output_fp, "\n"); + fflush(new_output_fp); + _DEBUG_NEW_ERROR_ACTION; + } +#if _DEBUG_NEW_TAILCHECK + if (!check_tail(ptr)) + { + check_mem_corruption(); + fflush(new_output_fp); + _DEBUG_NEW_ERROR_ACTION; + } +#endif + { + fast_mutex_autolock lock(new_ptr_lock); + total_mem_alloc -= ptr->size; + ptr->magic = 0; + ptr->prev->next = ptr->next; + ptr->next->prev = ptr->prev; + } + if (new_verbose_flag) + { + fast_mutex_autolock lock(new_output_lock); + fprintf(new_output_fp, + "delete%s: freed %p (size %u, %u bytes still allocated)\n", + is_array ? "[]" : "", + (char*)ptr + ALIGNED_LIST_ITEM_SIZE, + (unsigned)ptr->size, (unsigned)total_mem_alloc); + } + free(ptr); + return; +} + +/** + * Checks for memory leaks. + * + * @return zero if no leakage is found; the number of leaks otherwise + */ +int check_leaks() +{ + int leak_cnt = 0; + fast_mutex_autolock lock_ptr(new_ptr_lock); + fast_mutex_autolock lock_output(new_output_lock); + new_ptr_list_t* ptr = new_ptr_list.next; + while (ptr != &new_ptr_list) + { + const char* const pointer = (char*)ptr + ALIGNED_LIST_ITEM_SIZE; + if (ptr->magic != MAGIC) + { + fprintf(new_output_fp, + "warning: heap data corrupt near %p\n", + pointer); + } +#if _DEBUG_NEW_TAILCHECK + if (!check_tail(ptr)) + { + fprintf(new_output_fp, + "warning: overwritten past end of object at %p\n", + pointer); + } +#endif + fprintf(new_output_fp, + "Leaked object at %p (size %u, ", + pointer, + (unsigned)ptr->size); + if (ptr->line != 0) + print_position(ptr->file, ptr->line); + else + print_position(ptr->addr, ptr->line); + fprintf(new_output_fp, ")\n"); + ptr = ptr->next; + ++leak_cnt; + } + if (new_verbose_flag || leak_cnt) + fprintf(new_output_fp, "*** %d leaks found\n", leak_cnt); + return leak_cnt; +} + +/** + * Checks for heap corruption. + * + * @return zero if no problem is found; the number of found memory + * corruptions otherwise + */ +int check_mem_corruption() +{ + int corrupt_cnt = 0; + fast_mutex_autolock lock_ptr(new_ptr_lock); + fast_mutex_autolock lock_output(new_output_lock); + fprintf(new_output_fp, "*** Checking for memory corruption: START\n"); + for (new_ptr_list_t* ptr = new_ptr_list.next; + ptr != &new_ptr_list; + ptr = ptr->next) + { + const char* const pointer = (char*)ptr + ALIGNED_LIST_ITEM_SIZE; + if (ptr->magic == MAGIC +#if _DEBUG_NEW_TAILCHECK + && check_tail(ptr) +#endif + ) + continue; +#if _DEBUG_NEW_TAILCHECK + if (ptr->magic != MAGIC) + { +#endif + fprintf(new_output_fp, + "Heap data corrupt near %p (size %u, ", + pointer, + (unsigned)ptr->size); +#if _DEBUG_NEW_TAILCHECK + } + else + { + fprintf(new_output_fp, + "Overwritten past end of object at %p (size %u, ", + pointer, + ptr->size); + } +#endif + if (ptr->line != 0) + print_position(ptr->file, ptr->line); + else + print_position(ptr->addr, ptr->line); + fprintf(new_output_fp, ")\n"); + ++corrupt_cnt; + } + fprintf(new_output_fp, "*** Checking for memory corruption: %d FOUND\n", + corrupt_cnt); + return corrupt_cnt; +} + +void __debug_new_recorder::_M_process(void* pointer) +{ + if (pointer == NULL) + return; + new_ptr_list_t* ptr = + (new_ptr_list_t*)((char*)pointer - ALIGNED_LIST_ITEM_SIZE); + if (ptr->magic != MAGIC || ptr->line != 0) + { + fast_mutex_autolock lock(new_output_lock); + fprintf(new_output_fp, + "warning: debug_new used with placement new (%s:%d)\n", + _M_file, _M_line); + return; + } +#if _DEBUG_NEW_FILENAME_LEN == 0 + ptr->file = _M_file; +#else + strncpy(ptr->file, _M_file, _DEBUG_NEW_FILENAME_LEN - 1) + [_DEBUG_NEW_FILENAME_LEN - 1] = '\0'; +#endif + ptr->line = _M_line; +} + +void* operator new(size_t size, const char* file, int line) +{ + void* ptr = alloc_mem(size, file, line, false); +#if _DEBUG_NEW_STD_OPER_NEW + if (ptr) + return ptr; + else + throw std::bad_alloc(); +#else + return ptr; +#endif +} + +void* operator new[](size_t size, const char* file, int line) +{ + void* ptr = alloc_mem(size, file, line, true); +#if _DEBUG_NEW_STD_OPER_NEW + if (ptr) + return ptr; + else + throw std::bad_alloc(); +#else + return ptr; +#endif +} + +void* operator new(size_t size) throw(std::bad_alloc) +{ + return operator new(size, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0); +} + +void* operator new[](size_t size) throw(std::bad_alloc) +{ + return operator new[](size, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0); +} + +#if !defined(__BORLANDC__) || __BORLANDC__ > 0x551 +void* operator new(size_t size, const std::nothrow_t&) throw() +{ + return alloc_mem(size, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0, false); +} + +void* operator new[](size_t size, const std::nothrow_t&) throw() +{ + return alloc_mem(size, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0, true); +} +#endif + +void operator delete(void* pointer) throw() +{ + free_pointer(pointer, _DEBUG_NEW_CALLER_ADDRESS, false); +} + +void operator delete[](void* pointer) throw() +{ + free_pointer(pointer, _DEBUG_NEW_CALLER_ADDRESS, true); +} + +#if HAVE_PLACEMENT_DELETE +void operator delete(void* pointer, const char* file, int line) throw() +{ + if (new_verbose_flag) + { + fast_mutex_autolock lock(new_output_lock); + fprintf(new_output_fp, + "info: exception thrown on initializing object at %p (", + pointer); + print_position(file, line); + fprintf(new_output_fp, ")\n"); + } + operator delete(pointer); +} + +void operator delete[](void* pointer, const char* file, int line) throw() +{ + if (new_verbose_flag) + { + fast_mutex_autolock lock(new_output_lock); + fprintf(new_output_fp, + "info: exception thrown on initializing objects at %p (", + pointer); + print_position(file, line); + fprintf(new_output_fp, ")\n"); + } + operator delete[](pointer); +} + +void operator delete(void* pointer, const std::nothrow_t&) throw() +{ + operator delete(pointer, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0); +} + +void operator delete[](void* pointer, const std::nothrow_t&) throw() +{ + operator delete[](pointer, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0); +} +#endif // HAVE_PLACEMENT_DELETE + +int __debug_new_counter::_S_count = 0; + +/** + * Constructor to increment the count. + */ +__debug_new_counter::__debug_new_counter() +{ + ++_S_count; +} + +/** + * Destructor to decrement the count. When the count is zero, + * #check_leaks will be called. + */ +__debug_new_counter::~__debug_new_counter() +{ + if (--_S_count == 0 && new_autocheck_flag) + if (check_leaks()) + { + new_verbose_flag = true; +#if defined(__GNUC__) && __GNUC__ >= 3 + if (!getenv("GLIBCPP_FORCE_NEW") && !getenv("GLIBCXX_FORCE_NEW")) + fprintf(new_output_fp, +"*** WARNING: GCC 3 or later is detected, please make sure the\n" +" environment variable GLIBCPP_FORCE_NEW (GCC 3.2 and 3.3) or\n" +" GLIBCXX_FORCE_NEW (GCC 3.4 and later) is defined. Check the\n" +" README file for details.\n"); +#endif + } +} diff --git a/src/debug/debug_new.h b/src/debug/debug_new.h new file mode 100644 index 000000000..5bcd06eb0 --- /dev/null +++ b/src/debug/debug_new.h @@ -0,0 +1,183 @@ +// -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- +// vim:tabstop=4:shiftwidth=4:expandtab: + +/* + * Copyright (C) 2004-2008 Wu Yongwei <adah at users dot sourceforge dot net> + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any + * damages arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute + * it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must + * not claim that you wrote the original software. If you use this + * software in a product, an acknowledgement in the product + * documentation would be appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must + * not be misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source + * distribution. + * + * This file is part of Stones of Nvwa: + * http://sourceforge.net/projects/nvwa + * + * original version changed for ManaPlus + * + * Copyright (C) 2011 ManaPlus developers + */ + +/** + * @file debug_new.h + * + * Header file for checking leaks caused by unmatched new/delete. + * + * @version 4.4, 2007/12/31 + * @author Wu Yongwei + * + */ + +#ifndef _DEBUG_NEW_H +#define _DEBUG_NEW_H + +#include <new> +#include <stdio.h> + +/** + * @def HAVE_PLACEMENT_DELETE + * + * Macro to indicate whether placement delete operators are supported on + * a certain compiler. Some compilers, like Borland C++ Compiler 5.5.1 + * and Digital Mars Compiler 8.42, do not support them, and the user + * must define this macro to \c 0 to make the program compile. Also + * note that in that case memory leakage will occur if an exception is + * thrown in the initialization (constructor) of a dynamically created + * object. + */ +#ifndef HAVE_PLACEMENT_DELETE +#define HAVE_PLACEMENT_DELETE 1 +#endif + +/** + * @def _DEBUG_NEW_REDEFINE_NEW + * + * Macro to indicate whether redefinition of \c new is wanted. If one + * wants to define one's own <code>operator new</code>, to call + * <code>operator new</code> directly, or to call placement \c new, it + * should be defined to \c 0 to alter the default behaviour. Unless, of + * course, one is willing to take the trouble to write something like: + * @code + * # ifdef new + * # define _NEW_REDEFINED + * # undef new + * # endif + * + * // Code that uses new is here + * + * # ifdef _NEW_REDEFINED + * # ifdef DEBUG_NEW + * # define new DEBUG_NEW + * # endif + * # undef _NEW_REDEFINED + * # endif + * @endcode + */ +#ifndef _DEBUG_NEW_REDEFINE_NEW +#define _DEBUG_NEW_REDEFINE_NEW 1 +#endif + +/* Prototypes */ +int check_leaks(); +int check_mem_corruption(); +void* operator new(size_t size, const char* file, int line); +void* operator new[](size_t size, const char* file, int line); +#if HAVE_PLACEMENT_DELETE +void operator delete(void* pointer, const char* file, int line) throw(); +void operator delete[](void* pointer, const char* file, int line) throw(); +#endif +#if defined(_MSC_VER) && _MSC_VER < 1300 +// MSVC 6 requires the following declarations; or the non-placement +// new[]/delete[] will not compile. +void* operator new[](size_t) throw(std::bad_alloc); +void operator delete[](void*) throw(); +#endif + +/* Control variables */ +extern bool new_autocheck_flag; // default to true: call check_leaks() on exit +extern bool new_verbose_flag; // default to false: no verbose information +extern FILE* new_output_fp; // default to stderr: output to console +extern const char* new_progname;// default to NULL; should be assigned argv[0] + +/** + * @def DEBUG_NEW + * + * Macro to catch file/line information on allocation. If + * #_DEBUG_NEW_REDEFINE_NEW is \c 0, one can use this macro directly; + * otherwise \c new will be defined to it, and one must use \c new + * instead. + */ +#define DEBUG_NEW __debug_new_recorder(__FILE__, __LINE__) ->* new + +# if _DEBUG_NEW_REDEFINE_NEW +# define new DEBUG_NEW +# endif +# ifdef _DEBUG_NEW_EMULATE_MALLOC +# include <stdlib.h> +# ifdef new +# define malloc(s) ((void*)(new char[s])) +# else +# define malloc(s) ((void*)(DEBUG_NEW char[s])) +# endif +# define free(p) delete[] (char*)(p) +# define default_free free +# endif + +/** + * Recorder class to remember the call context. + * + * The idea comes from <a href="http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/7089382e3bc1c489/85f9107a1dc79ee9?#85f9107a1dc79ee9">Greg Herlihy's post</a> in comp.lang.c++.moderated. + */ +class __debug_new_recorder +{ + const char* _M_file; + const int _M_line; + void _M_process(void* pointer); +public: + /** + * Constructor to remember the call context. The information will + * be used in __debug_new_recorder::operator->*. + */ + __debug_new_recorder(const char* file, int line) + : _M_file(file), _M_line(line) {} + /** + * Operator to write the context information to memory. + * <code>operator->*</code> is chosen because it has the right + * precedence, it is rarely used, and it looks good: so people can + * tell the special usage more quickly. + */ + template <class _Tp> _Tp* operator->*(_Tp* pointer) + { _M_process(pointer); return pointer; } +private: + __debug_new_recorder(const __debug_new_recorder&); + __debug_new_recorder& operator=(const __debug_new_recorder&); +}; + +/** + * Counter class for on-exit leakage check. + * + * This technique is learnt from <em>The C++ Programming Language</em> by + * Bjarne Stroustup. + */ +class __debug_new_counter +{ + static int _S_count; +public: + __debug_new_counter(); + ~__debug_new_counter(); +}; +/** Counting object for each file including debug_new.h. */ +static __debug_new_counter __debug_new_count; + +#endif // _DEBUG_NEW_H diff --git a/src/debug/fast_mutex.h b/src/debug/fast_mutex.h new file mode 100644 index 000000000..a6adb2db3 --- /dev/null +++ b/src/debug/fast_mutex.h @@ -0,0 +1,314 @@ +// -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- +// vim:tabstop=4:shiftwidth=4:expandtab: + +/* + * Copyright (C) 2004-2008 Wu Yongwei <adah at users dot sourceforge dot net> + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any + * damages arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute + * it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must + * not claim that you wrote the original software. If you use this + * software in a product, an acknowledgement in the product + * documentation would be appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must + * not be misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source + * distribution. + * + * This file is part of Stones of Nvwa: + * http://sourceforge.net/projects/nvwa + * + * original version changed for ManaPlus + * + * Copyright (C) 2011 ManaPlus developers + */ + +/** + * @file fast_mutex.h + * + * A fast mutex implementation for POSIX and Win32. + * + * @version 1.18, 2005/05/06 + * @author Wu Yongwei + * + */ + +#ifndef _FAST_MUTEX_H +#define _FAST_MUTEX_H + +# if !defined(_NOTHREADS) +# if !defined(_WIN32THREADS) && \ + (defined(_WIN32) && defined(_MT)) +// Automatically use _WIN32THREADS when specifying -MT/-MD in MSVC, +// or -mthreads in MinGW GCC. +# define _WIN32THREADS +# elif !defined(_PTHREADS) && \ + defined(_REENTRANT) +// Automatically use _PTHREADS when specifying -pthread in GCC. +// N.B. I do not detect on _PTHREAD_H since libstdc++-v3 under +// Linux will silently include <pthread.h> anyway. +# define _PTHREADS +# endif +# endif + +# if !defined(_PTHREADS) && !defined(_WIN32THREADS) && !defined(_NOTHREADS) +# define _NOTHREADS +# endif + +# if defined(_NOTHREADS) +# if defined(_PTHREADS) || defined(_WIN32THREADS) +# undef _NOTHREADS +# error "Cannot define multi-threaded mode with -D_NOTHREADS" +# if defined(__MINGW32__) && defined(_WIN32THREADS) && !defined(_MT) +# error "Be sure to specify -mthreads with -D_WIN32THREADS" +# endif +# endif +# endif + +# ifndef _FAST_MUTEX_CHECK_INITIALIZATION +/** + * Macro to control whether to check for initialization status for each + * lock/unlock operation. Defining it to a non-zero value will enable + * the check, so that the construction/destruction of a static object + * using a static fast_mutex not yet constructed or already destroyed + * will work (with lock/unlock operations ignored). Defining it to zero + * will disable to check. + */ +# define _FAST_MUTEX_CHECK_INITIALIZATION 1 +# endif + +# if defined(_PTHREADS) && defined(_WIN32THREADS) +// Some C++ libraries have _PTHREADS defined even on Win32 platforms. +// Thus this hack. +# undef _PTHREADS +# endif + +# ifdef _DEBUG +# include <stdio.h> +# include <stdlib.h> +/** Macro for fast_mutex assertions. Real version (for debug mode). */ +# define _FAST_MUTEX_ASSERT(_Expr, _Msg) \ + if (!(_Expr)) { \ + fprintf(stderr, "fast_mutex::%s\n", _Msg); \ + abort(); \ + } +# else +/** Macro for fast_mutex assertions. Fake version (for release mode). */ +# define _FAST_MUTEX_ASSERT(_Expr, _Msg) \ + ((void)0) +# endif + +# ifdef _PTHREADS +# include <pthread.h> +/** + * Macro alias to `volatile' semantics. Here it is truly volatile since + * it is in a multi-threaded (POSIX threads) environment. + */ +# define __VOLATILE volatile + /** + * Class for non-reentrant fast mutexes. This is the implementation + * for POSIX threads. + */ + class fast_mutex + { + pthread_mutex_t _M_mtx_impl; +# if _FAST_MUTEX_CHECK_INITIALIZATION + bool _M_initialized; +# endif +# ifdef _DEBUG + bool _M_locked; +# endif + public: + fast_mutex() +# ifdef _DEBUG + : _M_locked(false) +# endif + { + ::pthread_mutex_init(&_M_mtx_impl, NULL); +# if _FAST_MUTEX_CHECK_INITIALIZATION + _M_initialized = true; +# endif + } + ~fast_mutex() + { + _FAST_MUTEX_ASSERT(!_M_locked, "~fast_mutex(): still locked"); +# if _FAST_MUTEX_CHECK_INITIALIZATION + _M_initialized = false; +# endif + ::pthread_mutex_destroy(&_M_mtx_impl); + } + void lock() + { +# if _FAST_MUTEX_CHECK_INITIALIZATION + if (!_M_initialized) + return; +# endif + ::pthread_mutex_lock(&_M_mtx_impl); +# ifdef _DEBUG + // The following assertion should _always_ be true for a + // real `fast' pthread_mutex. However, this assertion can + // help sometimes, when people forget to use `-lpthread' and + // glibc provides an empty implementation. Having this + // assertion is also more consistent. + _FAST_MUTEX_ASSERT(!_M_locked, "lock(): already locked"); + _M_locked = true; +# endif + } + void unlock() + { +# if _FAST_MUTEX_CHECK_INITIALIZATION + if (!_M_initialized) + return; +# endif +# ifdef _DEBUG + _FAST_MUTEX_ASSERT(_M_locked, "unlock(): not locked"); + _M_locked = false; +# endif + ::pthread_mutex_unlock(&_M_mtx_impl); + } + private: + fast_mutex(const fast_mutex&); + fast_mutex& operator=(const fast_mutex&); + }; +# endif // _PTHREADS + +# ifdef _WIN32THREADS +# include <windows.h> +/** + * Macro alias to `volatile' semantics. Here it is truly volatile since + * it is in a multi-threaded (Win32 threads) environment. + */ +# define __VOLATILE volatile + /** + * Class for non-reentrant fast mutexes. This is the implementation + * for Win32 threads. + */ + class fast_mutex + { + CRITICAL_SECTION _M_mtx_impl; +# if _FAST_MUTEX_CHECK_INITIALIZATION + bool _M_initialized; +# endif +# ifdef _DEBUG + bool _M_locked; +# endif + public: + fast_mutex() +# ifdef _DEBUG + : _M_locked(false) +# endif + { + ::InitializeCriticalSection(&_M_mtx_impl); +# if _FAST_MUTEX_CHECK_INITIALIZATION + _M_initialized = true; +# endif + } + ~fast_mutex() + { + _FAST_MUTEX_ASSERT(!_M_locked, "~fast_mutex(): still locked"); +# if _FAST_MUTEX_CHECK_INITIALIZATION + _M_initialized = false; +# endif + ::DeleteCriticalSection(&_M_mtx_impl); + } + void lock() + { +# if _FAST_MUTEX_CHECK_INITIALIZATION + if (!_M_initialized) + return; +# endif + ::EnterCriticalSection(&_M_mtx_impl); +# ifdef _DEBUG + _FAST_MUTEX_ASSERT(!_M_locked, "lock(): already locked"); + _M_locked = true; +# endif + } + void unlock() + { +# if _FAST_MUTEX_CHECK_INITIALIZATION + if (!_M_initialized) + return; +# endif +# ifdef _DEBUG + _FAST_MUTEX_ASSERT(_M_locked, "unlock(): not locked"); + _M_locked = false; +# endif + ::LeaveCriticalSection(&_M_mtx_impl); + } + private: + fast_mutex(const fast_mutex&); + fast_mutex& operator=(const fast_mutex&); + }; +# endif // _WIN32THREADS + +# ifdef _NOTHREADS +/** + * Macro alias to `volatile' semantics. Here it is not truly volatile + * since it is in a single-threaded environment. + */ +# define __VOLATILE + /** + * Class for non-reentrant fast mutexes. This is the null + * implementation for single-threaded environments. + */ + class fast_mutex + { +# ifdef _DEBUG + bool _M_locked; +# endif + public: + fast_mutex() +# ifdef _DEBUG + : _M_locked(false) +# endif + { + } + ~fast_mutex() + { + _FAST_MUTEX_ASSERT(!_M_locked, "~fast_mutex(): still locked"); + } + void lock() + { +# ifdef _DEBUG + _FAST_MUTEX_ASSERT(!_M_locked, "lock(): already locked"); + _M_locked = true; +# endif + } + void unlock() + { +# ifdef _DEBUG + _FAST_MUTEX_ASSERT(_M_locked, "unlock(): not locked"); + _M_locked = false; +# endif + } + private: + fast_mutex(const fast_mutex&); + fast_mutex& operator=(const fast_mutex&); + }; +# endif // _NOTHREADS + +/** An acquistion-on-initialization lock class based on fast_mutex. */ +class fast_mutex_autolock +{ + fast_mutex& _M_mtx; +public: + explicit fast_mutex_autolock(fast_mutex& __mtx) : _M_mtx(__mtx) + { + _M_mtx.lock(); + } + ~fast_mutex_autolock() + { + _M_mtx.unlock(); + } +private: + fast_mutex_autolock(const fast_mutex_autolock&); + fast_mutex_autolock& operator=(const fast_mutex_autolock&); +}; + +#endif // _FAST_MUTEX_H diff --git a/src/debug/static_assert.h b/src/debug/static_assert.h new file mode 100644 index 000000000..17be7a5f3 --- /dev/null +++ b/src/debug/static_assert.h @@ -0,0 +1,53 @@ +// -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- +// vim:tabstop=4:shiftwidth=4:expandtab: + +/* + * Copyright (C) 2004-2008 Wu Yongwei <adah at users dot sourceforge dot net> + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any + * damages arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute + * it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must + * not claim that you wrote the original software. If you use this + * software in a product, an acknowledgement in the product + * documentation would be appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must + * not be misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source + * distribution. + * + * This file is part of Stones of Nvwa: + * http://sourceforge.net/projects/nvwa + * + * original version changed for ManaPlus + * + * Copyright (C) 2011 ManaPlus developers + */ + +/** + * @file static_assert.h + * + * Template class to check validity duing compile time (adapted from Loki). + * + * @version 1.2, 2005/11/22 + * @author Wu Yongwei + * + */ + +#ifndef STATIC_ASSERT + +template <bool> struct __nvwa_compile_time_error; +template <> struct __nvwa_compile_time_error<true> {}; + +#define STATIC_ASSERT(_Expr, _Msg) \ + { \ + __nvwa_compile_time_error<((_Expr) != 0)> ERROR_##_Msg; \ + (void)ERROR_##_Msg; \ + } + +#endif // STATIC_ASSERT diff --git a/src/defaults.cpp b/src/defaults.cpp index b3efd4cb8..48c650f6c 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -29,6 +29,8 @@ #include <stdlib.h> +#include "debug.h" + using namespace Mana; VariableData* createData(int defData) diff --git a/src/dropshortcut.cpp b/src/dropshortcut.cpp index ca68ffbc9..189d76b96 100644 --- a/src/dropshortcut.cpp +++ b/src/dropshortcut.cpp @@ -36,6 +36,8 @@ #include "utils/stringutils.h" +#include "debug.h" + DropShortcut *dropShortcut; DropShortcut::DropShortcut(): diff --git a/src/effectmanager.cpp b/src/effectmanager.cpp index b6e95d7a6..4e2f3b249 100644 --- a/src/effectmanager.cpp +++ b/src/effectmanager.cpp @@ -27,6 +27,8 @@ #include "utils/xml.h" +#include "debug.h" + EffectManager::EffectManager() { XML::Document doc("effects.xml"); diff --git a/src/emoteshortcut.cpp b/src/emoteshortcut.cpp index 238ae75f5..00d7264a4 100644 --- a/src/emoteshortcut.cpp +++ b/src/emoteshortcut.cpp @@ -27,6 +27,8 @@ #include "resources/emotedb.h" +#include "debug.h" + EmoteShortcut *emoteShortcut; EmoteShortcut::EmoteShortcut(): diff --git a/src/event.cpp b/src/event.cpp index 548045225..8660f6b94 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -24,6 +24,8 @@ #include "listener.h" #include "variabledata.h" +#include "debug.h" + namespace Mana { diff --git a/src/flooritem.cpp b/src/flooritem.cpp index 150e020a9..952e8eebb 100644 --- a/src/flooritem.cpp +++ b/src/flooritem.cpp @@ -36,6 +36,8 @@ #include "resources/itemdb.h" #include "resources/iteminfo.h" +#include "debug.h" + FloorItem::FloorItem(int id, int itemId, int x, diff --git a/src/game.cpp b/src/game.cpp index 82a77c0bb..d4c26d6e8 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -110,6 +110,8 @@ #include "mumblemanager.h" +#include "debug.h" + Joystick *joystick = NULL; OkDialog *weightNotice = NULL; diff --git a/src/graphics.cpp b/src/graphics.cpp index 48d4104d1..41dae2d9c 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -35,6 +35,8 @@ //<SDL_gfxBlitFunc.h> #include "SDL_gfxBlitFunc.h" +#include "debug.h" + Graphics::Graphics(): mWidth(0), mHeight(0), diff --git a/src/graphicsvertexes.cpp b/src/graphicsvertexes.cpp index 8b03368fd..0cadfedc2 100644 --- a/src/graphicsvertexes.cpp +++ b/src/graphicsvertexes.cpp @@ -24,6 +24,8 @@ #include "utils/dtor.h" +#include "debug.h" + #ifdef USE_OPENGL int GraphicsVertexes::mUseOpenGL = 0; const unsigned int vertexBufSize = 500; diff --git a/src/gui/beingpopup.cpp b/src/gui/beingpopup.cpp index b6c01758f..20d2c5c1e 100644 --- a/src/gui/beingpopup.cpp +++ b/src/gui/beingpopup.cpp @@ -35,6 +35,7 @@ #include <guichan/font.hpp> +#include "debug.h" BeingPopup::BeingPopup(): Popup("BeingPopup") diff --git a/src/gui/botcheckerwindow.cpp b/src/gui/botcheckerwindow.cpp index 5d2fe2781..a15a7ed56 100644 --- a/src/gui/botcheckerwindow.cpp +++ b/src/gui/botcheckerwindow.cpp @@ -45,6 +45,7 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" #define COLUMNS_NR 5 // name plus listbox #define NAME_COLUMN 0 diff --git a/src/gui/buydialog.cpp b/src/gui/buydialog.cpp index 00602e6f2..530c4020b 100644 --- a/src/gui/buydialog.cpp +++ b/src/gui/buydialog.cpp @@ -48,6 +48,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + BuyDialog::DialogList BuyDialog::instances; BuyDialog::BuyDialog(int npcId): diff --git a/src/gui/buyselldialog.cpp b/src/gui/buyselldialog.cpp index 961e744c0..14dcb0bc1 100644 --- a/src/gui/buyselldialog.cpp +++ b/src/gui/buyselldialog.cpp @@ -32,6 +32,8 @@ #include "utils/gettext.h" +#include "debug.h" + BuySellDialog::DialogList BuySellDialog::instances; BuySellDialog::BuySellDialog(int npcId): diff --git a/src/gui/changeemaildialog.cpp b/src/gui/changeemaildialog.cpp index a8f016c9b..d424fff91 100644 --- a/src/gui/changeemaildialog.cpp +++ b/src/gui/changeemaildialog.cpp @@ -42,6 +42,8 @@ #include <string> #include <sstream> +#include "debug.h" + ChangeEmailDialog::ChangeEmailDialog(LoginData *loginData): Window(_("Change Email Address"), true), mWrongDataNoticeListener(new WrongDataNoticeListener), diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp index 1ea4662c4..dc640841a 100644 --- a/src/gui/changepassworddialog.cpp +++ b/src/gui/changepassworddialog.cpp @@ -44,6 +44,8 @@ #include <string> #include <sstream> +#include "debug.h" + ChangePasswordDialog::ChangePasswordDialog(LoginData *loginData): Window(_("Change Password"), true), mWrongDataNoticeListener(new WrongDataNoticeListener), diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 914e29f3c..91c284985 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -52,6 +52,8 @@ #include <guichan/font.hpp> +#include "debug.h" + CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): Window(_("Create Character"), true, parent), mCharSelectDialog(parent), diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index bf4225df9..264df06e3 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -62,6 +62,8 @@ #include <string> #include <cassert> +#include "debug.h" + // Character slots per row in the dialog static const int SLOTS_PER_ROW = 5; diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index b2048eb0a..1712a3f16 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -65,6 +65,8 @@ #include <sys/stat.h> +#include "debug.h" + /** * The chat input hides when it loses focus. It is also invisible by default. */ diff --git a/src/gui/confirmdialog.cpp b/src/gui/confirmdialog.cpp index a9186a2ed..661168dd9 100644 --- a/src/gui/confirmdialog.cpp +++ b/src/gui/confirmdialog.cpp @@ -33,6 +33,8 @@ #include <guichan/font.hpp> +#include "debug.h" + ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, bool ignore, bool modal, Window *parent): Window(title, modal, parent) diff --git a/src/gui/connectiondialog.cpp b/src/gui/connectiondialog.cpp index 05f4ef177..157398297 100644 --- a/src/gui/connectiondialog.cpp +++ b/src/gui/connectiondialog.cpp @@ -31,6 +31,8 @@ #include "utils/gettext.h" +#include "debug.h" + ConnectionDialog::ConnectionDialog(const std::string &text, State cancelState): Window(""), diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index b3e19e3e5..ecc3ada54 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -48,6 +48,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + DebugWindow::DebugWindow(): Window(_("Debug")) { diff --git a/src/gui/editdialog.cpp b/src/gui/editdialog.cpp index b8d999ce7..bb80f07ed 100644 --- a/src/gui/editdialog.cpp +++ b/src/gui/editdialog.cpp @@ -31,6 +31,8 @@ #include <guichan/font.hpp> +#include "debug.h" + EditDialog::EditDialog(const std::string &title, const std::string &msg, std::string eventOk, int width, Window *parent, bool modal): diff --git a/src/gui/emotepopup.cpp b/src/gui/emotepopup.cpp index bd7e857f9..d23443a2f 100644 --- a/src/gui/emotepopup.cpp +++ b/src/gui/emotepopup.cpp @@ -41,6 +41,8 @@ #include <guichan/mouseinput.hpp> #include <guichan/selectionlistener.hpp> +#include "debug.h" + const int EmotePopup::gridWidth = 34; // emote icon width + 4 const int EmotePopup::gridHeight = 36; // emote icon height + 4 diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index bb1fc325b..edad33623 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -50,6 +50,8 @@ #include <guichan/font.hpp> +#include "debug.h" + static const int BOX_WIDTH = 36; static const int BOX_HEIGHT = 36; diff --git a/src/gui/focushandler.cpp b/src/gui/focushandler.cpp index 2a3ed9f4a..ec854cf87 100644 --- a/src/gui/focushandler.cpp +++ b/src/gui/focushandler.cpp @@ -24,6 +24,8 @@ #include "gui/widgets/window.h" +#include "debug.h" + void FocusHandler::requestModalFocus(gcn::Widget *widget) { /* If there is another widget with modal focus, remove its modal focus diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index aecb6a6f8..9df692515 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -45,6 +45,8 @@ #include <guichan/exception.hpp> #include <guichan/image.hpp> +#include "debug.h" + // Guichan stuff Gui *gui = 0; SDLInput *guiInput = 0; diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp index c6afb0fd1..e0e42c0bb 100644 --- a/src/gui/helpwindow.cpp +++ b/src/gui/helpwindow.cpp @@ -37,6 +37,8 @@ #include "utils/gettext.h" +#include "debug.h" + HelpWindow::HelpWindow(): Window(_("Help")) { diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index a12f4cf61..056afee92 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -59,6 +59,8 @@ #include <string> +#include "debug.h" + InventoryWindow::WindowList InventoryWindow::instances; InventoryWindow::InventoryWindow(Inventory *inventory): diff --git a/src/gui/itemamountwindow.cpp b/src/gui/itemamountwindow.cpp index 5506f1690..908a861dd 100644 --- a/src/gui/itemamountwindow.cpp +++ b/src/gui/itemamountwindow.cpp @@ -46,6 +46,8 @@ #include <math.h> +#include "debug.h" + class ItemsModal : public gcn::ListModel { public: diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index 5e50e2e55..e7def2234 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -45,6 +45,8 @@ #include <guichan/widgets/label.hpp> #include <guichan/widgets/container.hpp> +#include "debug.h" + ItemPopup::ItemPopup(): Popup("ItemPopup"), mIcon(0), diff --git a/src/gui/killstats.cpp b/src/gui/killstats.cpp index 4b20d5270..610e76208 100644 --- a/src/gui/killstats.cpp +++ b/src/gui/killstats.cpp @@ -39,6 +39,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + KillStats::KillStats(): Window(_("Kill stats")), mKillCounter(0), mExpCounter(0), mKillTCounter(0), mExpTCounter(0), mKillTimer(0), diff --git a/src/gui/logindialog.cpp b/src/gui/logindialog.cpp index e32caeb13..436e401a8 100644 --- a/src/gui/logindialog.cpp +++ b/src/gui/logindialog.cpp @@ -43,6 +43,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + static const int MAX_SERVER_LIST_SIZE = 15; static const int LOGIN_DIALOG_WIDTH = 300; static const int LOGIN_DIALOG_HEIGHT = 140; diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 93f84bcf7..b85826679 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -41,6 +41,8 @@ #include <guichan/font.hpp> +#include "debug.h" + bool Minimap::mShow = true; Minimap::Minimap(): diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 213693e0a..6809a5149 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -46,6 +46,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + extern volatile int tick_time; MiniStatusWindow::MiniStatusWindow(): diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index a6a3f085e..d8dc68fd1 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -46,6 +46,8 @@ #include <guichan/font.hpp> +#include "debug.h" + #define CAPTION_WAITING _("Waiting for server") #define CAPTION_NEXT _("Next") #define CAPTION_CLOSE _("Close") diff --git a/src/gui/npcpostdialog.cpp b/src/gui/npcpostdialog.cpp index 7ba8d301a..0ba4e44b6 100644 --- a/src/gui/npcpostdialog.cpp +++ b/src/gui/npcpostdialog.cpp @@ -34,6 +34,8 @@ #include "utils/gettext.h" +#include "debug.h" + NpcPostDialog::DialogList NpcPostDialog::instances; NpcPostDialog::NpcPostDialog(int npcId): diff --git a/src/gui/okdialog.cpp b/src/gui/okdialog.cpp index fde7d6670..122d7176f 100644 --- a/src/gui/okdialog.cpp +++ b/src/gui/okdialog.cpp @@ -31,6 +31,8 @@ #include <guichan/font.hpp> +#include "debug.h" + OkDialog::OkDialog(const std::string &title, const std::string &msg, bool modal, bool showCenter, Window *parent): Window(title, modal, parent) diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 57ad6ab21..6f2c35921 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -51,6 +51,8 @@ #include <vector> +#include "debug.h" + float OutfitWindow::mAlpha = 1.0; OutfitWindow::OutfitWindow(): diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 5a61c332a..f5c074f6c 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -34,6 +34,8 @@ #include <math.h> +#include "debug.h" + const gcn::Color Palette::BLACK = gcn::Color(0, 0, 0); Palette::Palettes Palette::mInstances; diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 88ae0e376..f84088cc1 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -78,6 +78,8 @@ #include <cassert> +#include "debug.h" + std::string tradePartnerName(""); PopupMenu::PopupMenu(): diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp index 423e2404d..28a3332bf 100644 --- a/src/gui/quitdialog.cpp +++ b/src/gui/quitdialog.cpp @@ -43,6 +43,8 @@ #include <assert.h> +#include "debug.h" + QuitDialog::QuitDialog(QuitDialog** pointerToMe): Window(_("Quit"), true, NULL), mMyPointer(pointerToMe) { diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 4bce1b8b8..b7bbc4ab2 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -44,6 +44,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + WrongDataNoticeListener::WrongDataNoticeListener(): mTarget(0) { diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp index 655a00f05..9cbee4e89 100644 --- a/src/gui/sdlfont.cpp +++ b/src/gui/sdlfont.cpp @@ -35,6 +35,8 @@ #include <guichan/exception.hpp> +#include "debug.h" + const unsigned int CACHE_SIZE = 256; const unsigned int CACHE_SIZE_SMALL1 = 2; const unsigned int CACHE_SIZE_SMALL2 = 50; diff --git a/src/gui/selldialog.cpp b/src/gui/selldialog.cpp index e1ed7c1b0..fdbc53ea8 100644 --- a/src/gui/selldialog.cpp +++ b/src/gui/selldialog.cpp @@ -45,6 +45,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + SellDialog::DialogList SellDialog::instances; SellDialog::SellDialog(int npcId): diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 76dada241..0dc817646 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -55,6 +55,8 @@ #include <iostream> #include <string> +#include "debug.h" + static const int MAX_SERVERLIST = 15; static std::string serverTypeToString(ServerInfo::Type type) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 5db19b97d..76588a860 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -42,6 +42,8 @@ #include "utils/dtor.h" #include "utils/gettext.h" +#include "debug.h" + extern Window *statusWindow; Setup::Setup(): diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index 92acdaabe..28e6d8cfa 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -36,6 +36,8 @@ #include "utils/gettext.h" +#include "debug.h" + Setup_Audio::Setup_Audio(): mMusicVolume(config.getIntValue("musicVolume")), mSfxVolume(config.getIntValue("sfxVolume")), diff --git a/src/gui/setup_chat.cpp b/src/gui/setup_chat.cpp index a5b211d8f..4d9bc9876 100644 --- a/src/gui/setup_chat.cpp +++ b/src/gui/setup_chat.cpp @@ -37,6 +37,8 @@ #include "utils/gettext.h" +#include "debug.h" + #define ACTION_REMOVE_COLORS "remove colors" #define ACTION_MAGIC_IN_DEBUG "magic in debug" #define ACTION_ALLOW_COMMANDS_IN_CHATTABS "allow commands" diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 0b30aa08e..c3bda11bc 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -42,6 +42,8 @@ #include <string> #include <cmath> +#include "debug.h" + const std::string Setup_Colors::rawmsg = _("This is what the color looks like"); diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp index 2f45319a8..aadfc11e3 100644 --- a/src/gui/setup_joystick.cpp +++ b/src/gui/setup_joystick.cpp @@ -32,6 +32,8 @@ #include "utils/gettext.h" +#include "debug.h" + extern Joystick *joystick; Setup_Joystick::Setup_Joystick(): diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index 0fc23cac7..5125541cf 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -39,6 +39,8 @@ #include <SDL_keyboard.h> +#include "debug.h" + /** * The list model for key function list. * diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index bc1a07ed3..311a06bb5 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -35,6 +35,8 @@ #include "utils/gettext.h" +#include "debug.h" + #define ACTION_SHOW_TAKEDDAMAGE "taked damage" #define ACTION_ONLY_REACHABLE "only reachable" #define ACTION_ERRORS_IN_DEBUG "errors in debug" diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index 0290c24d5..e071eee73 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -55,6 +55,8 @@ #define WIDGET_AT(row, column) (((row) * COLUMNS_NR) + column) +#include "debug.h" + static const char *table_titles[COLUMNS_NR] = { N_("Name"), diff --git a/src/gui/setup_theme.cpp b/src/gui/setup_theme.cpp index faaeeb00f..b9ba8e3dc 100644 --- a/src/gui/setup_theme.cpp +++ b/src/gui/setup_theme.cpp @@ -42,6 +42,8 @@ #include "resources/resourcemanager.h" +#include "debug.h" + const char* ACTION_THEME = "theme"; const char* ACTION_FONT = "font"; const char* ACTION_BOLD_FONT = "bold font"; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 9c84dd9d7..59f3ccf34 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -56,6 +56,8 @@ #include <string> #include <vector> +#include "debug.h" + extern Graphics *graphics; /** diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index 81710dda3..549979905 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -65,6 +65,8 @@ #include <sys/stat.h> +#include "debug.h" + extern std::string tradePartnerName; ShopWindow::DialogList ShopWindow::instances; diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp index dce04d150..f9db35ff6 100644 --- a/src/gui/shortcutwindow.cpp +++ b/src/gui/shortcutwindow.cpp @@ -32,6 +32,8 @@ #include "gui/widgets/tab.h" #include "gui/widgets/tabbedarea.h" +#include "debug.h" + static const int SCROLL_PADDING = 0; int ShortcutWindow::mBoxesWidth = 0; diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index a58a3e169..ee1803604 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -56,10 +56,11 @@ #include <set> #include <string> +#include "debug.h" + class SkillModel; class SkillEntry; - struct SkillInfo { unsigned short id; diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index e943d7286..0be9dd70f 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -57,6 +57,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + class SocialTab : public Tab { protected: diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp index d3583e0f5..1c41752f3 100644 --- a/src/gui/specialswindow.cpp +++ b/src/gui/specialswindow.cpp @@ -51,6 +51,8 @@ #include <string> +#include "debug.h" + #define SPECIALS_WIDTH 200 #define SPECIALS_HEIGHT 32 diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 877af76a1..7356cc633 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -34,6 +34,8 @@ #include <guichan/widgets/label.hpp> +#include "debug.h" + SpeechBubble::SpeechBubble(): Popup("Speech", "speechbubble.xml") { diff --git a/src/gui/spellpopup.cpp b/src/gui/spellpopup.cpp index 80fa9f378..3c6d17599 100644 --- a/src/gui/spellpopup.cpp +++ b/src/gui/spellpopup.cpp @@ -37,6 +37,8 @@ #include <guichan/font.hpp> #include <guichan/widgets/label.hpp> +#include "debug.h" + SpellPopup::SpellPopup(): Popup("SpellPopup") { diff --git a/src/gui/statuspopup.cpp b/src/gui/statuspopup.cpp index f098ff9eb..9ac2cfad0 100644 --- a/src/gui/statuspopup.cpp +++ b/src/gui/statuspopup.cpp @@ -41,6 +41,8 @@ #include <guichan/font.hpp> #include <guichan/widgets/label.hpp> +#include "debug.h" + StatusPopup::StatusPopup(): Popup("StatusPopup") { diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index ef2ce78ed..bfd18c40f 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -52,6 +52,8 @@ #include "utils/mathutils.h" #include "utils/stringutils.h" +#include "debug.h" + class AttrDisplay : public Container { public: diff --git a/src/gui/textcommandeditor.cpp b/src/gui/textcommandeditor.cpp index e169e9303..b3a1440e1 100644 --- a/src/gui/textcommandeditor.cpp +++ b/src/gui/textcommandeditor.cpp @@ -53,6 +53,8 @@ #include "resources/itemdb.h" #include "resources/iteminfo.h" +#include "debug.h" + class IconsModal : public gcn::ListModel { public: diff --git a/src/gui/textdialog.cpp b/src/gui/textdialog.cpp index f8d3588fb..a80e25260 100644 --- a/src/gui/textdialog.cpp +++ b/src/gui/textdialog.cpp @@ -33,6 +33,8 @@ #include <guichan/font.hpp> +#include "debug.h" + int TextDialog::instances = 0; TextDialog::TextDialog(const std::string &title, const std::string &msg, diff --git a/src/gui/textpopup.cpp b/src/gui/textpopup.cpp index 77bd4bae6..049f86d76 100644 --- a/src/gui/textpopup.cpp +++ b/src/gui/textpopup.cpp @@ -36,6 +36,8 @@ #include <guichan/font.hpp> #include <guichan/widgets/label.hpp> +#include "debug.h" + TextPopup::TextPopup(): Popup("TextPopup") { diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 98251948f..0817df564 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -42,6 +42,8 @@ #include <algorithm> #include <physfs.h> +#include "debug.h" + static std::string defaultThemePath; std::string Theme::mThemePath; diff --git a/src/gui/tradewindow.cpp b/src/gui/tradewindow.cpp index 25c478c21..6ed09669a 100644 --- a/src/gui/tradewindow.cpp +++ b/src/gui/tradewindow.cpp @@ -53,6 +53,8 @@ #include <sstream> +#include "debug.h" + #define CAPTION_PROPOSE _("Propose trade") #define CAPTION_CONFIRMED _("Confirmed. Waiting...") #define CAPTION_ACCEPT _("Agree trade") diff --git a/src/gui/unregisterdialog.cpp b/src/gui/unregisterdialog.cpp index 4d3483a30..8f845e746 100644 --- a/src/gui/unregisterdialog.cpp +++ b/src/gui/unregisterdialog.cpp @@ -44,6 +44,8 @@ #include <string> #include <sstream> +#include "debug.h" + UnRegisterDialog::UnRegisterDialog(LoginData *loginData): Window(_("Unregister"), true), mWrongDataNoticeListener(new WrongDataNoticeListener), diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index bc74aeb58..42ed1c289 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -50,6 +50,8 @@ #include <sys/stat.h> +#include "debug.h" + const std::string xmlUpdateFile = "resources.xml"; const std::string txtUpdateFile = "resources2.txt"; diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp index bc5576469..40dddc4f1 100644 --- a/src/gui/userpalette.cpp +++ b/src/gui/userpalette.cpp @@ -34,6 +34,8 @@ #include <math.h> +#include "debug.h" + const std::string ColorTypeNames[] = { "ColorBeing", diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 09fc7d24c..3c13fcb7e 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -51,6 +51,8 @@ #include "utils/stringutils.h" +#include "debug.h" + extern volatile int tick_time; Viewport::Viewport(): diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index c1b7f03d1..dfb896778 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -48,6 +48,16 @@ // Curl should be included after Guichan to avoid Windows redefinitions #include <curl/curl.h> +#include "debug.h" + +#ifdef free +#undef free +#endif + +#ifdef malloc +#undef malloc +#endif + bool stringCompare(const std::string &left, const std::string &right); bool stringCompare(const std::string &left, const std::string &right ) diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index c1025e66d..c4737160b 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -40,6 +40,8 @@ #include <guichan/font.hpp> +#include "debug.h" + int AvatarListBox::instances = 0; Image *AvatarListBox::onlineIcon = 0; Image *AvatarListBox::offlineIcon = 0; diff --git a/src/gui/widgets/battletab.cpp b/src/gui/widgets/battletab.cpp index e5f8c0f77..e72c78ee0 100644 --- a/src/gui/widgets/battletab.cpp +++ b/src/gui/widgets/battletab.cpp @@ -39,6 +39,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + BattleTab::BattleTab() : ChatTab(_("Battle")) { diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 5d144c5a9..f3ee7270b 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -44,6 +44,8 @@ #include <algorithm> +#include "debug.h" + BrowserBox::BrowserBox(unsigned int mode, bool opaque): gcn::Widget(), mLinkHandler(0), diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index c0f174b2c..ba3ac5f36 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -38,6 +38,8 @@ #include <guichan/exception.hpp> #include <guichan/font.hpp> +#include "debug.h" + int Button::mInstances = 0; float Button::mAlpha = 1.0; diff --git a/src/gui/widgets/channeltab.cpp b/src/gui/widgets/channeltab.cpp index df2df2790..87d87f7d1 100644 --- a/src/gui/widgets/channeltab.cpp +++ b/src/gui/widgets/channeltab.cpp @@ -29,6 +29,8 @@ #include "utils/gettext.h" +#include "debug.h" + ChannelTab::ChannelTab(Channel *channel) : ChatTab(channel->getName()), mChannel(channel) diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 3c277fc8d..76f74dec8 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -46,6 +46,8 @@ #include <guichan/widgets/tabbedarea.hpp> +#include "debug.h" + #define MAX_WORD_SIZE 50 ChatTab::ChatTab(const std::string &name) : diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index 9832c0cbd..0422345f7 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -33,6 +33,8 @@ #include <guichan/actionlistener.hpp> +#include "debug.h" + int CheckBox::instances = 0; float CheckBox::mAlpha = 1.0; Image *CheckBox::checkBoxNormal; diff --git a/src/gui/widgets/container.cpp b/src/gui/widgets/container.cpp index 136dedb97..96cea7119 100644 --- a/src/gui/widgets/container.cpp +++ b/src/gui/widgets/container.cpp @@ -22,6 +22,8 @@ #include "gui/widgets/container.h" +#include "debug.h" + Container::Container() { setOpaque(false); diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index 09c106632..8b6217da2 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -36,6 +36,8 @@ #include "utils/stringutils.h" +#include "debug.h" + Desktop::Desktop() : mWallpaper(0) { diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 3fe015e2f..681d7736e 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -39,6 +39,8 @@ #include <algorithm> +#include "debug.h" + int DropDown::instances = 0; Image *DropDown::buttons[2][2]; ImageRect DropDown::skin; diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp index c3aaed829..0125558dc 100644 --- a/src/gui/widgets/dropshortcutcontainer.cpp +++ b/src/gui/widgets/dropshortcutcontainer.cpp @@ -43,6 +43,8 @@ #include "utils/stringutils.h" +#include "debug.h" + DropShortcutContainer::DropShortcutContainer(): ShortcutContainer(), mItemClicked(false), diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index 6e15d4bf9..c45c0a44c 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -41,6 +41,8 @@ #include "utils/dtor.h" +#include "debug.h" + static const int MAX_ITEMS = 44; EmoteShortcutContainer::EmoteShortcutContainer(): diff --git a/src/gui/widgets/flowcontainer.cpp b/src/gui/widgets/flowcontainer.cpp index cf7c76d68..98b90cdc7 100644 --- a/src/gui/widgets/flowcontainer.cpp +++ b/src/gui/widgets/flowcontainer.cpp @@ -21,6 +21,8 @@ #include "flowcontainer.h" +#include "debug.h" + FlowContainer::FlowContainer(int boxWidth, int boxHeight): mBoxWidth(boxWidth), mBoxHeight(boxHeight), mGridWidth(1), mGridHeight(1) diff --git a/src/gui/widgets/horizontcontainer.cpp b/src/gui/widgets/horizontcontainer.cpp index 7863408b2..a04230871 100644 --- a/src/gui/widgets/horizontcontainer.cpp +++ b/src/gui/widgets/horizontcontainer.cpp @@ -21,6 +21,8 @@ #include "gui/widgets/horizontcontainer.h" +#include "debug.h" + HorizontContainer::HorizontContainer(int height, int spacing): mSpacing(spacing), mCount(0), diff --git a/src/gui/widgets/icon.cpp b/src/gui/widgets/icon.cpp index ba1fa7e26..2799080b6 100644 --- a/src/gui/widgets/icon.cpp +++ b/src/gui/widgets/icon.cpp @@ -27,6 +27,8 @@ #include "resources/image.h" #include "resources/resourcemanager.h" +#include "debug.h" + Icon::Icon(const std::string &file) : mImage(0) { diff --git a/src/gui/widgets/inttextfield.cpp b/src/gui/widgets/inttextfield.cpp index 1feedd503..021340fbe 100644 --- a/src/gui/widgets/inttextfield.cpp +++ b/src/gui/widgets/inttextfield.cpp @@ -26,6 +26,8 @@ #include "utils/stringutils.h" +#include "debug.h" + IntTextField::IntTextField(int def, int min, int max, bool enabled, int width): TextField(toString(def)), diff --git a/src/gui/widgets/inventoryfilter.cpp b/src/gui/widgets/inventoryfilter.cpp index 8c62849a1..a220fdb98 100644 --- a/src/gui/widgets/inventoryfilter.cpp +++ b/src/gui/widgets/inventoryfilter.cpp @@ -25,6 +25,8 @@ #include "log.h" +#include "debug.h" + InventoryFilter::InventoryFilter(std::string group, int height, int spacing): HorizontContainer(height, spacing), mGroup(group) diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 509c7b218..d4cecced2 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -50,6 +50,8 @@ #include <guichan/mouseinput.hpp> #include <guichan/selectionlistener.hpp> +#include "debug.h" + // TODO: Add support for adding items to the item shortcut window (global // itemShortcut). diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp index 87d708cd0..0d6ef9990 100644 --- a/src/gui/widgets/itemlinkhandler.cpp +++ b/src/gui/widgets/itemlinkhandler.cpp @@ -32,6 +32,8 @@ #include "resources/itemdb.h" +#include "debug.h" + ItemLinkHandler::ItemLinkHandler() { mItemPopup = new ItemPopup; diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index 513b7cb51..4d0758e3d 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -46,6 +46,8 @@ #include "utils/stringutils.h" +#include "debug.h" + ItemShortcutContainer::ItemShortcutContainer(unsigned number): ShortcutContainer(), mItemClicked(false), diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp index 56c604e64..16b813dd5 100644 --- a/src/gui/widgets/label.cpp +++ b/src/gui/widgets/label.cpp @@ -22,6 +22,8 @@ #include "gui/theme.h" +#include "debug.h" + Label::Label() { } diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 3dc4eb038..274c17d61 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -26,6 +26,8 @@ #include <cassert> +#include "debug.h" + ContainerPlacer ContainerPlacer::at(int x, int y) { return ContainerPlacer(mContainer, &mCell->at(x, y)); diff --git a/src/gui/widgets/layouthelper.cpp b/src/gui/widgets/layouthelper.cpp index 17d4cb651..cded6313a 100644 --- a/src/gui/widgets/layouthelper.cpp +++ b/src/gui/widgets/layouthelper.cpp @@ -22,6 +22,8 @@ #include "gui/widgets/layouthelper.h" +#include "debug.h" + LayoutHelper::LayoutHelper(gcn::Container *container): mContainer(container) { diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index 574cadf94..ae75d469e 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -34,6 +34,8 @@ #include <guichan/key.hpp> #include <guichan/listmodel.hpp> +#include "debug.h" + float ListBox::mAlpha = 1.0; ListBox::ListBox(gcn::ListModel *listModel): diff --git a/src/gui/widgets/passwordfield.cpp b/src/gui/widgets/passwordfield.cpp index 57ba6f695..34639b063 100644 --- a/src/gui/widgets/passwordfield.cpp +++ b/src/gui/widgets/passwordfield.cpp @@ -22,6 +22,8 @@ #include "passwordfield.h" +#include "debug.h" + PasswordField::PasswordField(const std::string &text): TextField(text) { diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp index e3905e523..2efaa2088 100644 --- a/src/gui/widgets/playerbox.cpp +++ b/src/gui/widgets/playerbox.cpp @@ -34,6 +34,8 @@ #include "utils/dtor.h" +#include "debug.h" + int PlayerBox::instances = 0; float PlayerBox::mAlpha = 1.0; ImageRect PlayerBox::background; diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp index bc15a4c2c..444d147ff 100644 --- a/src/gui/widgets/popup.cpp +++ b/src/gui/widgets/popup.cpp @@ -38,6 +38,8 @@ #include <guichan/exception.hpp> +#include "debug.h" + Popup::Popup(const std::string &name, const std::string &skin): mPopupName(name), mMinWidth(100), diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp index bbde65207..363bab319 100644 --- a/src/gui/widgets/progressbar.cpp +++ b/src/gui/widgets/progressbar.cpp @@ -38,6 +38,8 @@ #include <guichan/font.hpp> +#include "debug.h" + ImageRect ProgressBar::mBorder; int ProgressBar::mInstances = 0; float ProgressBar::mAlpha = 1.0; diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp index 9ca6fe3b8..e885aa0ec 100644 --- a/src/gui/widgets/progressindicator.cpp +++ b/src/gui/widgets/progressindicator.cpp @@ -32,6 +32,8 @@ #include <guichan/widgets/label.hpp> +#include "debug.h" + ProgressIndicator::ProgressIndicator() { ImageSet *images = Theme::getImageSetFromTheme("progress-indicator.png", diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp index ffea0f372..8e3fdb9bb 100644 --- a/src/gui/widgets/radiobutton.cpp +++ b/src/gui/widgets/radiobutton.cpp @@ -30,6 +30,8 @@ #include "resources/image.h" +#include "debug.h" + int RadioButton::instances = 0; float RadioButton::mAlpha = 1.0; Image *RadioButton::radioNormal; diff --git a/src/gui/widgets/resizegrip.cpp b/src/gui/widgets/resizegrip.cpp index 3350adc6a..cf017b9ec 100644 --- a/src/gui/widgets/resizegrip.cpp +++ b/src/gui/widgets/resizegrip.cpp @@ -32,6 +32,8 @@ #include <guichan/graphics.hpp> +#include "debug.h" + Image *ResizeGrip::gripImage = 0; int ResizeGrip::mInstances = 0; float ResizeGrip::mAlpha = 1.0; diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 59e323e94..e290be21a 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -34,6 +34,8 @@ #include "utils/dtor.h" +#include "debug.h" + int ScrollArea::instances = 0; float ScrollArea::mAlpha = 1.0; ImageRect ScrollArea::background; diff --git a/src/gui/widgets/setuptab.cpp b/src/gui/widgets/setuptab.cpp index 127cd0f96..e98e9c3ac 100644 --- a/src/gui/widgets/setuptab.cpp +++ b/src/gui/widgets/setuptab.cpp @@ -22,6 +22,8 @@ #include "gui/widgets/setuptab.h" +#include "debug.h" + SetupTab::SetupTab() { setOpaque(false); diff --git a/src/gui/widgets/shopitems.cpp b/src/gui/widgets/shopitems.cpp index 764f22a57..85ee0a181 100644 --- a/src/gui/widgets/shopitems.cpp +++ b/src/gui/widgets/shopitems.cpp @@ -26,6 +26,8 @@ #include "utils/dtor.h" +#include "debug.h" + ShopItems::ShopItems(bool mergeDuplicates) : mMergeDuplicates(mergeDuplicates) { diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp index 2965cba5d..81a3b7b58 100644 --- a/src/gui/widgets/shoplistbox.cpp +++ b/src/gui/widgets/shoplistbox.cpp @@ -38,6 +38,8 @@ #include <guichan/font.hpp> #include <guichan/listmodel.hpp> +#include "debug.h" + const int ITEM_ICON_SIZE = 32; float ShopListBox::mAlpha = 1.0; diff --git a/src/gui/widgets/shortcutcontainer.cpp b/src/gui/widgets/shortcutcontainer.cpp index a804f2658..d4065677a 100644 --- a/src/gui/widgets/shortcutcontainer.cpp +++ b/src/gui/widgets/shortcutcontainer.cpp @@ -28,6 +28,8 @@ #include "utils/stringutils.h" +#include "debug.h" + float ShortcutContainer::mAlpha = 1.0; ShortcutContainer::ShortcutContainer(): diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index 8d452dfbf..7950f6a24 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -30,6 +30,8 @@ #include "resources/image.h" +#include "debug.h" + Image *Slider::hStart, *Slider::hMid, *Slider::hEnd, *Slider::hGrip; Image *Slider::vStart, *Slider::vMid, *Slider::vEnd, *Slider::vGrip; Image *Slider::hStartHi, *Slider::hMidHi, *Slider::hEndHi, *Slider::hGripHi; diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp index 8f4cee1ac..bfeecbfa0 100644 --- a/src/gui/widgets/spellshortcutcontainer.cpp +++ b/src/gui/widgets/spellshortcutcontainer.cpp @@ -48,6 +48,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + SpellShortcutContainer::SpellShortcutContainer(unsigned number): ShortcutContainer(), mSpellClicked(false), diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index 5e4a147c0..7287d6a8e 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -39,6 +39,8 @@ #include <guichan/widgets/label.hpp> +#include "debug.h" + int Tab::mInstances = 0; float Tab::mAlpha = 1.0; diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index e76ac6d57..da6dfb64c 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -29,6 +29,8 @@ #include <guichan/widgets/container.hpp> +#include "debug.h" + TabbedArea::TabbedArea() : gcn::TabbedArea(), mTabsWidth(0), diff --git a/src/gui/widgets/table.cpp b/src/gui/widgets/table.cpp index ab8b3a339..d5325679f 100644 --- a/src/gui/widgets/table.cpp +++ b/src/gui/widgets/table.cpp @@ -34,6 +34,8 @@ #include <guichan/graphics.hpp> #include <guichan/key.hpp> +#include "debug.h" + float GuiTable::mAlpha = 1.0; class GuiTableActionListener : public gcn::ActionListener diff --git a/src/gui/widgets/tablemodel.cpp b/src/gui/widgets/tablemodel.cpp index f1bfd0832..6c932a411 100644 --- a/src/gui/widgets/tablemodel.cpp +++ b/src/gui/widgets/tablemodel.cpp @@ -26,6 +26,8 @@ #include <guichan/widget.hpp> +#include "debug.h" + void TableModel::installListener(TableModelListener *listener) { if (listener) diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index 8c8804b67..f31c8d129 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -28,6 +28,8 @@ #include <sstream> +#include "debug.h" + TextBox::TextBox() : mTextColor(&Theme::getThemeColor(Theme::TEXT)) { diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 8e61bce3c..fd50ee4d5 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -40,6 +40,8 @@ #undef DELETE //Win32 compatibility hack +#include "debug.h" + int TextField::instances = 0; float TextField::mAlpha = 1.0; ImageRect TextField::skin; diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index 6d41bef06..07cf19b61 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -32,6 +32,8 @@ #include <typeinfo> +#include "debug.h" + float TextPreview::mAlpha = 1.0; TextPreview::TextPreview(const std::string &text): diff --git a/src/gui/widgets/tradetab.cpp b/src/gui/widgets/tradetab.cpp index 0767dc5fe..99a145d86 100644 --- a/src/gui/widgets/tradetab.cpp +++ b/src/gui/widgets/tradetab.cpp @@ -38,6 +38,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + TradeTab::TradeTab() : ChatTab(_("Trade")) { diff --git a/src/gui/widgets/vertcontainer.cpp b/src/gui/widgets/vertcontainer.cpp index ad5199f7c..d4cf0a13f 100644 --- a/src/gui/widgets/vertcontainer.cpp +++ b/src/gui/widgets/vertcontainer.cpp @@ -21,6 +21,8 @@ #include "gui/widgets/vertcontainer.h" +#include "debug.h" + VertContainer::VertContainer(int spacing): mSpacing(spacing), mCount(0) diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp index 0cfd41bcb..bee30b969 100644 --- a/src/gui/widgets/whispertab.cpp +++ b/src/gui/widgets/whispertab.cpp @@ -35,6 +35,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + WhisperTab::WhisperTab(const std::string &nick) : ChatTab(nick), mNick(nick) diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index df8599b95..2b6c4ef58 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -41,6 +41,8 @@ #include <guichan/exception.hpp> #include <guichan/focushandler.hpp> +#include "debug.h" + int Window::instances = 0; int Window::mouseResize = 0; diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp index f68eb0220..5a3c16037 100644 --- a/src/gui/widgets/windowcontainer.cpp +++ b/src/gui/widgets/windowcontainer.cpp @@ -24,6 +24,8 @@ #include "utils/dtor.h" +#include "debug.h" + WindowContainer *windowContainer = NULL; void WindowContainer::logic() diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp index 5e93d5c69..719b67829 100644 --- a/src/gui/windowmenu.cpp +++ b/src/gui/windowmenu.cpp @@ -42,6 +42,8 @@ #include <string> +#include "debug.h" + extern Window *equipmentWindow; extern Window *inventoryWindow; extern Window *itemShortcutWindow; diff --git a/src/gui/worldselectdialog.cpp b/src/gui/worldselectdialog.cpp index 3a35e3396..7e2afbaa3 100644 --- a/src/gui/worldselectdialog.cpp +++ b/src/gui/worldselectdialog.cpp @@ -39,6 +39,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + extern WorldInfo **server_info; /** diff --git a/src/guild.cpp b/src/guild.cpp index 2e1b3d78c..ec8baee03 100644 --- a/src/guild.cpp +++ b/src/guild.cpp @@ -24,6 +24,8 @@ #include "actorspritemanager.h" +#include "debug.h" + class SortGuildFunctor { public: diff --git a/src/imageparticle.cpp b/src/imageparticle.cpp index 2d4f21337..00ede704b 100644 --- a/src/imageparticle.cpp +++ b/src/imageparticle.cpp @@ -26,6 +26,8 @@ #include "resources/image.h" +#include "debug.h" + std::map<std::string, int> ImageParticle::imageParticleCountByName; ImageParticle::ImageParticle(Map *map, Image *image): diff --git a/src/imagesprite.cpp b/src/imagesprite.cpp index 43ff3267e..e0c27e3d7 100644 --- a/src/imagesprite.cpp +++ b/src/imagesprite.cpp @@ -23,6 +23,8 @@ #include "graphics.h" +#include "debug.h" + ImageSprite::ImageSprite(Image *image): mImage(image) { diff --git a/src/inventory.cpp b/src/inventory.cpp index e410a36ed..9c3e16666 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -34,6 +34,8 @@ #include <algorithm> #include <string> +#include "debug.h" + struct SlotUsed : public std::unary_function<Item*, bool> { bool operator()(const Item *item) const diff --git a/src/item.cpp b/src/item.cpp index e6fa5cb1a..e59d0c334 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -29,6 +29,8 @@ #include "resources/resourcemanager.h" #include "configuration.h" +#include "debug.h" + Item::Item(int id, int quantity, int refine, unsigned char color, bool equipment, bool equipped): mImage(0), diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp index 7f8f8ddc0..0d2aee6de 100644 --- a/src/itemshortcut.cpp +++ b/src/itemshortcut.cpp @@ -33,6 +33,8 @@ #include "utils/stringutils.h" +#include "debug.h" + ItemShortcut *itemShortcut[SHORTCUT_TABS]; ItemShortcut::ItemShortcut(int number): diff --git a/src/joystick.cpp b/src/joystick.cpp index 7db6117ab..f1255c4c0 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -26,6 +26,8 @@ #include <cassert> +#include "debug.h" + int Joystick::joystickCount = 0; void Joystick::init() diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index a07fbc574..1ad6fb582 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -28,6 +28,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + struct KeyData { const char *configField; diff --git a/src/listener.cpp b/src/listener.cpp index b26a6e6df..cf7c209d6 100644 --- a/src/listener.cpp +++ b/src/listener.cpp @@ -23,6 +23,8 @@ #include "event.h" +#include "debug.h" + namespace Mana { diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 5759c7dc4..fc0e17a6f 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -81,6 +81,8 @@ #include "mumblemanager.h" +#include "debug.h" + // This is the minimal delay between to permitted // setDestination() calls using the keyboard. // TODO: This can fine tuned later on when running is added... diff --git a/src/log.cpp b/src/log.cpp index abd6beb76..cd0814f54 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -39,6 +39,8 @@ #include <sys/time.h> +#include "debug.h" + Logger::Logger(): mLogToStandardOut(true), mChatWindow(NULL), diff --git a/src/main.cpp b/src/main.cpp index a170cf513..0f9b0f217 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,6 +37,8 @@ #include <windows.h> #endif +#include "debug.h" + static void printHelp() { using std::endl; diff --git a/src/map.cpp b/src/map.cpp index 87e0ccbc6..93e2acd1a 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -51,6 +51,8 @@ #include <sys/stat.h> +#include "debug.h" + bool actorCompare(const Actor *a, const Actor *b); /** diff --git a/src/mumblemanager.cpp b/src/mumblemanager.cpp index aecb28bc0..feef64727 100644 --- a/src/mumblemanager.cpp +++ b/src/mumblemanager.cpp @@ -22,7 +22,9 @@ #ifndef WIN32 #include <sys/mman.h> -#endif +#endif + +#include "debug.h" MumbleManager::MumbleManager() : mLinkedMem(0) diff --git a/src/net/charhandler.cpp b/src/net/charhandler.cpp index c7474c7f3..f3a02fc3b 100644 --- a/src/net/charhandler.cpp +++ b/src/net/charhandler.cpp @@ -23,6 +23,8 @@ #include "gui/charselectdialog.h" +#include "debug.h" + using namespace Net; void CharHandler::updateCharSelectDialog() diff --git a/src/net/download.cpp b/src/net/download.cpp index 1badf1763..1da792c52 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -34,10 +34,11 @@ #include <zlib.h> +#include "debug.h" + const char *DOWNLOAD_ERROR_MESSAGE_THREAD = "Could not create download thread!"; - enum { OPTIONS_NONE = 0, diff --git a/src/net/ea/adminhandler.cpp b/src/net/ea/adminhandler.cpp index 9dd525ae9..3554a9d9e 100644 --- a/src/net/ea/adminhandler.cpp +++ b/src/net/ea/adminhandler.cpp @@ -27,6 +27,8 @@ #include <string> +#include "debug.h" + namespace Ea { diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index f59283e23..6875a067e 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -51,6 +51,8 @@ #include <iostream> +#include "debug.h" + namespace Ea { const int EMOTION_TIME = 500; /**< Duration of emotion icon */ diff --git a/src/net/ea/buysellhandler.cpp b/src/net/ea/buysellhandler.cpp index 2ee586c92..685562d6f 100644 --- a/src/net/ea/buysellhandler.cpp +++ b/src/net/ea/buysellhandler.cpp @@ -44,6 +44,8 @@ #include "utils/gettext.h" +#include "debug.h" + namespace Ea { diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 9b76c76fa..8b5f2eee3 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -29,6 +29,8 @@ #include "utils/stringutils.h" +#include "debug.h" + #define MAKEWORD(low, high) \ (static_cast<unsigned short>((static_cast<unsigned char>(low)) | \ (static_cast<unsigned short>(static_cast<unsigned char>(high))) << 8)) diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index db7f4842e..24edb4079 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -31,6 +31,8 @@ #include <cstring> #include <string> +#include "debug.h" + namespace Net { diff --git a/src/net/net.cpp b/src/net/net.cpp index ca26415a6..49bb58903 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -46,6 +46,8 @@ #include "net/manaserv/generalhandler.h" #endif +#include "debug.h" + Net::AdminHandler *adminHandler = NULL; Net::CharHandler *charHandler = NULL; Net::ChatHandler *chatHandler = NULL; diff --git a/src/net/packetcounters.cpp b/src/net/packetcounters.cpp index f6a1dfec3..8cd2e4627 100644 --- a/src/net/packetcounters.cpp +++ b/src/net/packetcounters.cpp @@ -22,6 +22,8 @@ #include "net/packetcounters.h" +#include "debug.h" + extern volatile int cur_time; extern volatile bool runCounters; diff --git a/src/net/tmwa/adminhandler.cpp b/src/net/tmwa/adminhandler.cpp index 45a285d02..cbd16bd39 100644 --- a/src/net/tmwa/adminhandler.cpp +++ b/src/net/tmwa/adminhandler.cpp @@ -41,6 +41,8 @@ #include <string> +#include "debug.h" + extern Net::AdminHandler *adminHandler; namespace TmwAthena diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index ff458b31b..7589553ff 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -51,6 +51,8 @@ #include <iostream> +#include "debug.h" + extern Net::BeingHandler *beingHandler; namespace TmwAthena diff --git a/src/net/tmwa/buysellhandler.cpp b/src/net/tmwa/buysellhandler.cpp index 0b839a3f5..fa509ffec 100644 --- a/src/net/tmwa/buysellhandler.cpp +++ b/src/net/tmwa/buysellhandler.cpp @@ -47,6 +47,8 @@ #include "utils/gettext.h" +#include "debug.h" + extern Net::BuySellHandler *buySellHandler; namespace TmwAthena diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp index 7f091bc67..defe7925a 100644 --- a/src/net/tmwa/charserverhandler.cpp +++ b/src/net/tmwa/charserverhandler.cpp @@ -46,6 +46,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + extern Net::CharHandler *charHandler; namespace TmwAthena diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index 3a3b45a3c..b4ae395c3 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -46,6 +46,8 @@ #include <string> +#include "debug.h" + extern Net::ChatHandler *chatHandler; namespace TmwAthena diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp index b1f72a834..99d4841b2 100644 --- a/src/net/tmwa/gamehandler.cpp +++ b/src/net/tmwa/gamehandler.cpp @@ -40,6 +40,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + extern Net::GameHandler *gameHandler; namespace TmwAthena diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index 26f6983d7..2e9070eb7 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -65,6 +65,8 @@ #include <assert.h> #include <list> +#include "debug.h" + extern Net::GeneralHandler *generalHandler; namespace TmwAthena diff --git a/src/net/tmwa/gui/guildtab.cpp b/src/net/tmwa/gui/guildtab.cpp index 714f08b46..ce828b338 100644 --- a/src/net/tmwa/gui/guildtab.cpp +++ b/src/net/tmwa/gui/guildtab.cpp @@ -39,6 +39,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + namespace TmwAthena { diff --git a/src/net/tmwa/gui/partytab.cpp b/src/net/tmwa/gui/partytab.cpp index 84d846c7f..fc8ec138d 100644 --- a/src/net/tmwa/gui/partytab.cpp +++ b/src/net/tmwa/gui/partytab.cpp @@ -41,6 +41,8 @@ #include "net/chathandler.h" +#include "debug.h" + namespace TmwAthena { diff --git a/src/net/tmwa/guildhandler.cpp b/src/net/tmwa/guildhandler.cpp index f2552d4c8..b70059baa 100644 --- a/src/net/tmwa/guildhandler.cpp +++ b/src/net/tmwa/guildhandler.cpp @@ -37,6 +37,8 @@ #include "utils/gettext.h" +#include "debug.h" + extern Net::GuildHandler *guildHandler; namespace TmwAthena diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 3e8e89703..ecf875b78 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -47,6 +47,8 @@ #include <SDL_types.h> +#include "debug.h" + extern Net::InventoryHandler *inventoryHandler; const Equipment::Slot EQUIP_POINTS[Equipment::EQUIP_VECTOREND] = diff --git a/src/net/tmwa/itemhandler.cpp b/src/net/tmwa/itemhandler.cpp index 897ed1fb5..d9595c846 100644 --- a/src/net/tmwa/itemhandler.cpp +++ b/src/net/tmwa/itemhandler.cpp @@ -28,6 +28,8 @@ #include "net/tmwa/protocol.h" +#include "debug.h" + namespace TmwAthena { diff --git a/src/net/tmwa/loginhandler.cpp b/src/net/tmwa/loginhandler.cpp index 7f73057b4..b1af0900d 100644 --- a/src/net/tmwa/loginhandler.cpp +++ b/src/net/tmwa/loginhandler.cpp @@ -37,6 +37,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + extern Net::LoginHandler *loginHandler; namespace TmwAthena diff --git a/src/net/tmwa/messagehandler.cpp b/src/net/tmwa/messagehandler.cpp index fc3d9f752..843339718 100644 --- a/src/net/tmwa/messagehandler.cpp +++ b/src/net/tmwa/messagehandler.cpp @@ -26,6 +26,8 @@ #include <cassert> +#include "debug.h" + namespace TmwAthena { diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index ca32b1df4..6e2fcc187 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -31,6 +31,8 @@ #include <SDL.h> #include <SDL_endian.h> +#include "debug.h" + #define MAKEWORD(low, high) \ ((unsigned short)(((unsigned char)(low)) | \ ((unsigned short)((unsigned char)(high))) << 8)) diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp index b6fcc09a1..a904b6bbb 100644 --- a/src/net/tmwa/messageout.cpp +++ b/src/net/tmwa/messageout.cpp @@ -36,6 +36,8 @@ #include <cstring> #include <string> +#include "debug.h" + namespace TmwAthena { diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index 5beb05c20..9207522e1 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -35,6 +35,8 @@ #include <assert.h> #include <sstream> +#include "debug.h" + /** Warning: buffers and other variables are shared, so there can be only one connection active at a time */ diff --git a/src/net/tmwa/npchandler.cpp b/src/net/tmwa/npchandler.cpp index f70e8cd03..688635942 100644 --- a/src/net/tmwa/npchandler.cpp +++ b/src/net/tmwa/npchandler.cpp @@ -36,6 +36,8 @@ #include <SDL_types.h> +#include "debug.h" + extern Net::NpcHandler *npcHandler; namespace TmwAthena diff --git a/src/net/tmwa/partyhandler.cpp b/src/net/tmwa/partyhandler.cpp index 4ce77fbf4..152348d78 100644 --- a/src/net/tmwa/partyhandler.cpp +++ b/src/net/tmwa/partyhandler.cpp @@ -37,6 +37,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + #define PARTY_ID 1 extern Net::PartyHandler *partyHandler; diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index 385c7ca15..e0f3e5c29 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -46,6 +46,8 @@ #include "utils/stringutils.h" #include "utils/gettext.h" +#include "debug.h" + extern OkDialog *weightNotice; extern OkDialog *deathNotice; extern int weightNoticeTime; diff --git a/src/net/tmwa/specialhandler.cpp b/src/net/tmwa/specialhandler.cpp index 586f5fe00..19713a0bf 100644 --- a/src/net/tmwa/specialhandler.cpp +++ b/src/net/tmwa/specialhandler.cpp @@ -36,6 +36,8 @@ #include "utils/gettext.h" +#include "debug.h" + /** job dependend identifiers (?) */ #define SKILL_BASIC 0x0001 #define SKILL_WARP 0x001b diff --git a/src/net/tmwa/tradehandler.cpp b/src/net/tmwa/tradehandler.cpp index 19c32bd71..f7d6787d0 100644 --- a/src/net/tmwa/tradehandler.cpp +++ b/src/net/tmwa/tradehandler.cpp @@ -42,6 +42,8 @@ #include "utils/gettext.h" #include "utils/stringutils.h" +#include "debug.h" + extern std::string tradePartnerName; ConfirmDialog *confirmDlg; diff --git a/src/opengl1graphics.cpp b/src/opengl1graphics.cpp index ad488d3cd..5f22171d0 100644 --- a/src/opengl1graphics.cpp +++ b/src/opengl1graphics.cpp @@ -36,6 +36,8 @@ #include <SDL.h> +#include "debug.h" + #ifndef GL_TEXTURE_RECTANGLE_ARB #define GL_TEXTURE_RECTANGLE_ARB 0x84F5 #define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 0cfda2445..ea5d11c27 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -38,6 +38,8 @@ #include <SDL.h> +#include "debug.h" + #ifndef GL_TEXTURE_RECTANGLE_ARB #define GL_TEXTURE_RECTANGLE_ARB 0x84F5 #define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 diff --git a/src/particle.cpp b/src/particle.cpp index 807bca084..ecc68e6cc 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -44,6 +44,8 @@ #include <algorithm> #include <cmath> +#include "debug.h" + #define SIN45 0.707106781f class Graphics; diff --git a/src/particlecontainer.cpp b/src/particlecontainer.cpp index 72aed5df2..d00c68a63 100644 --- a/src/particlecontainer.cpp +++ b/src/particlecontainer.cpp @@ -25,6 +25,8 @@ #include "particle.h" #include "particlecontainer.h" +#include "debug.h" + ParticleContainer::ParticleContainer(ParticleContainer *parent, bool delParent): mDelParent(delParent), diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index 1c3e63f30..33c2f1d92 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -33,6 +33,8 @@ #include <cmath> +#include "debug.h" + #define SIN45 0.707106781f #define DEG_RAD_FACTOR 0.017453293f diff --git a/src/party.cpp b/src/party.cpp index 2b491edb9..9f0541224 100644 --- a/src/party.cpp +++ b/src/party.cpp @@ -23,6 +23,8 @@ #include "actorspritemanager.h" +#include "debug.h" + class SortPartyFunctor { public: diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp index ab2596f32..fb78e0ae8 100644 --- a/src/playerinfo.cpp +++ b/src/playerinfo.cpp @@ -31,6 +31,8 @@ #include "resources/itemdb.h" #include "resources/iteminfo.h" +#include "debug.h" + namespace PlayerInfo { diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp index 4b40eff33..f41ea5e4d 100644 --- a/src/playerrelations.cpp +++ b/src/playerrelations.cpp @@ -31,6 +31,8 @@ #include "utils/dtor.h" #include "utils/gettext.h" +#include "debug.h" + #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 diff --git a/src/position.cpp b/src/position.cpp index 18e05f701..8e9baf272 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -22,6 +22,8 @@ #include "position.h" +#include "debug.h" + std::ostream& operator <<(std::ostream &os, const Position &p) { os << "(" << p.x << ", " << p.y << ")"; diff --git a/src/resources/action.cpp b/src/resources/action.cpp index 23941f955..a95ebc5e3 100644 --- a/src/resources/action.cpp +++ b/src/resources/action.cpp @@ -27,6 +27,8 @@ #include "utils/dtor.h" +#include "debug.h" + Action::Action() { } diff --git a/src/resources/ambientlayer.cpp b/src/resources/ambientlayer.cpp index 145de8e79..92d9eb43e 100644 --- a/src/resources/ambientlayer.cpp +++ b/src/resources/ambientlayer.cpp @@ -26,6 +26,8 @@ #include "resources/image.h" #include "resources/resourcemanager.h" +#include "debug.h" + AmbientLayer::AmbientLayer(Image *img, float parallax, float speedX, float speedY, bool keepRatio): mImage(img), mParallax(parallax), diff --git a/src/resources/animation.cpp b/src/resources/animation.cpp index 10b017cd1..915d7ef30 100644 --- a/src/resources/animation.cpp +++ b/src/resources/animation.cpp @@ -24,6 +24,8 @@ #include "utils/dtor.h" +#include "debug.h" + Animation::Animation(): mDuration(0) { diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 438de46dd..7114290ca 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -27,6 +27,8 @@ #include "utils/dtor.h" #include "utils/gettext.h" +#include "debug.h" + BeingInfo *BeingInfo::Unknown = new BeingInfo; BeingInfo::BeingInfo(): diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp index 30d7c4f0c..2d4e9687e 100644 --- a/src/resources/colordb.cpp +++ b/src/resources/colordb.cpp @@ -27,6 +27,8 @@ #include <libxml/tree.h> +#include "debug.h" + namespace { ColorDB::Colors mHairColors; diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 2d621127b..fe7d4bcac 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -27,6 +27,8 @@ #include <math.h> #include <sstream> +#include "debug.h" + DyePalette::DyePalette(const std::string &description) { int size = static_cast<int>(description.length()); diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp index d0cb84b90..85a2993dd 100644 --- a/src/resources/emotedb.cpp +++ b/src/resources/emotedb.cpp @@ -26,6 +26,8 @@ #include "utils/xml.h" #include "configuration.h" +#include "debug.h" + namespace { EmoteInfos mEmoteInfos; diff --git a/src/resources/image.cpp b/src/resources/image.cpp index be7bb7f47..aa5c33488 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -39,6 +39,8 @@ #include <SDL_image.h> #include <SDL_rotozoom.h> +#include "debug.h" + #ifdef USE_OPENGL int Image::mUseOpenGL = 0; int Image::mTextureType = 0; diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp index d0c82c09f..fa5d0eea1 100644 --- a/src/resources/imageloader.cpp +++ b/src/resources/imageloader.cpp @@ -31,6 +31,12 @@ #include <cassert> +#include "debug.h" + +#ifdef free +#undef free +#endif + ProxyImage::ProxyImage(SDL_Surface *s): mImage(NULL), mSDLImage(s) { diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp index af180b0eb..1d41c6e63 100644 --- a/src/resources/imageset.cpp +++ b/src/resources/imageset.cpp @@ -28,6 +28,8 @@ #include "utils/dtor.h" +#include "debug.h" + ImageSet::ImageSet(Image *img, int width, int height, int margin, int spacing) : mOffsetX(0), diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp index d5d3de898..d068b9c02 100644 --- a/src/resources/imagewriter.cpp +++ b/src/resources/imagewriter.cpp @@ -28,6 +28,8 @@ #include <SDL.h> #include <string> +#include "debug.h" + bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename) { if (!surface) diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 234394cbe..b4e33dfa7 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -38,6 +38,8 @@ #include <cassert> +#include "debug.h" + namespace { ItemDB::ItemInfos mItemInfos; diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 09813c43f..3eea45360 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -28,6 +28,8 @@ #include <set> #include <map> +#include "debug.h" + const std::string &ItemInfo::getSprite(Gender gender) const { if (mView) diff --git a/src/resources/mapdb.cpp b/src/resources/mapdb.cpp index 0b553e35d..e8aeaf168 100644 --- a/src/resources/mapdb.cpp +++ b/src/resources/mapdb.cpp @@ -29,6 +29,8 @@ #include <libxml/tree.h> +#include "debug.h" + namespace { bool mLoaded = false; diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 6d0a6fa4f..c5e52ae7c 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -41,6 +41,8 @@ #include <iostream> #include <zlib.h> +#include "debug.h" + int inflateMemory(unsigned char *in, unsigned int inLength, unsigned char *&out, unsigned int &outLength); diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index ac5b2c7f9..f0739296a 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -34,6 +34,8 @@ #include "configuration.h" +#include "debug.h" + #define OLD_TMWATHENA_OFFSET 1002 namespace diff --git a/src/resources/music.cpp b/src/resources/music.cpp index 2fb296db9..ccd1d9280 100644 --- a/src/resources/music.cpp +++ b/src/resources/music.cpp @@ -24,6 +24,8 @@ #include "log.h" +#include "debug.h" + Music::Music(Mix_Chunk *music): mChunk(music), mChannel(-1) diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp index 5c8c0e8c8..6f539e17b 100644 --- a/src/resources/npcdb.cpp +++ b/src/resources/npcdb.cpp @@ -30,6 +30,8 @@ #include "utils/xml.h" #include "configuration.h" +#include "debug.h" + namespace { BeingInfos mNPCInfos; diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp index 550a2ea32..6e986272a 100644 --- a/src/resources/resource.cpp +++ b/src/resources/resource.cpp @@ -29,6 +29,8 @@ #include <cassert> +#include "debug.h" + Resource::~Resource() { } diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 0c1dafe4b..79231a744 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -41,6 +41,8 @@ #include <sys/time.h> +#include "debug.h" + #define THEMES_FOLDER "themes" ResourceManager *ResourceManager::instance = NULL; diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp index 7219ab624..a01bf21a0 100644 --- a/src/resources/soundeffect.cpp +++ b/src/resources/soundeffect.cpp @@ -24,6 +24,8 @@ #include "log.h" +#include "debug.h" + SoundEffect::~SoundEffect() { Mix_FreeChunk(mChunk); diff --git a/src/resources/specialdb.cpp b/src/resources/specialdb.cpp index 1115a693d..4ab5e2a91 100644 --- a/src/resources/specialdb.cpp +++ b/src/resources/specialdb.cpp @@ -26,6 +26,7 @@ #include "utils/dtor.h" #include "utils/xml.h" +#include "debug.h" namespace { diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 1eea6547d..2cd59ee29 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -37,6 +37,8 @@ #include <set> +#include "debug.h" + SpriteReference *SpriteReference::Empty = new SpriteReference( paths.getStringValue("spriteErrorFile"), 0); diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp index a2e3861e9..397b87993 100644 --- a/src/resources/wallpaper.cpp +++ b/src/resources/wallpaper.cpp @@ -35,8 +35,7 @@ #include <time.h> #include <vector> -//define WALLPAPER_FOLDER "graphics/images/" -//define WALLPAPER_BASE "login_wallpaper.png" +#include "debug.h" struct WallpaperData { diff --git a/src/rotationalparticle.cpp b/src/rotationalparticle.cpp index adb78668f..8be11ee10 100644 --- a/src/rotationalparticle.cpp +++ b/src/rotationalparticle.cpp @@ -24,6 +24,8 @@ #include "graphics.h" #include "simpleanimation.h" +#include "debug.h" + #define PI 3.14159265 RotationalParticle::RotationalParticle(Map *map, Animation *animation): diff --git a/src/shopitem.cpp b/src/shopitem.cpp index a87c1f3f9..5000ceb4d 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -29,6 +29,8 @@ #include "resources/iteminfo.h" +#include "debug.h" + ShopItem::ShopItem(int inventoryIndex, int id, unsigned char color, int quantity, int price) : Item(id, 0, 0, color), diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp index 8d86583eb..a952d792b 100644 --- a/src/simpleanimation.cpp +++ b/src/simpleanimation.cpp @@ -32,6 +32,8 @@ #include "resources/imageset.h" #include "resources/resourcemanager.h" +#include "debug.h" + SimpleAnimation::SimpleAnimation(Animation *animation): mAnimation(animation), mAnimationTime(0), diff --git a/src/sound.cpp b/src/sound.cpp index 5a0959804..a9157af1b 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -30,6 +30,8 @@ #include "resources/resourcemanager.h" #include "resources/soundeffect.h" +#include "debug.h" + /** * This will be set to true, when a music can be freed after a fade out * Currently used by fadeOutCallBack() diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp index f4462c732..29b99a9a0 100644 --- a/src/spellmanager.cpp +++ b/src/spellmanager.cpp @@ -36,6 +36,8 @@ #include "utils/dtor.h" #include "utils/stringutils.h" +#include "debug.h" + SpellManager::SpellManager() { //fillSpells(); diff --git a/src/spellshortcut.cpp b/src/spellshortcut.cpp index 1559cfa47..8a8e55c21 100644 --- a/src/spellshortcut.cpp +++ b/src/spellshortcut.cpp @@ -34,6 +34,8 @@ #include "utils/stringutils.h" +#include "debug.h" + SpellShortcut *spellShortcut; SpellShortcut::SpellShortcut() diff --git a/src/statuseffect.cpp b/src/statuseffect.cpp index e35018908..d875a2f57 100644 --- a/src/statuseffect.cpp +++ b/src/statuseffect.cpp @@ -33,6 +33,8 @@ #include <map> +#include "debug.h" + #define STATUS_EFFECTS_FILE "status-effects.xml" void unloadMap(std::map<int, StatusEffect *> map); diff --git a/src/text.cpp b/src/text.cpp index e1217978d..8d930f4e2 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -36,6 +36,8 @@ #include <guichan/font.hpp> +#include "debug.h" + int Text::mInstances = 0; ImageRect Text::mBubble; Image *Text::mBubbleArrow; diff --git a/src/textcommand.cpp b/src/textcommand.cpp index 402aef5c5..836b3c653 100644 --- a/src/textcommand.cpp +++ b/src/textcommand.cpp @@ -28,6 +28,8 @@ #include "resources/iteminfo.h" #include "resources/resourcemanager.h" +#include "debug.h" + TextCommand::TextCommand(unsigned int id, std::string symbol, std::string command, SpellTarget type, std::string icon, unsigned int basicLvl, diff --git a/src/textmanager.cpp b/src/textmanager.cpp index a57ed1b44..a8b62bcf2 100644 --- a/src/textmanager.cpp +++ b/src/textmanager.cpp @@ -24,6 +24,8 @@ #include <cstring> +#include "debug.h" + TextManager *textManager = 0; TextManager::TextManager() diff --git a/src/textparticle.cpp b/src/textparticle.cpp index 3b28e5e05..02cc97459 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -26,6 +26,8 @@ #include <guichan/color.hpp> +#include "debug.h" + TextParticle::TextParticle(Map *map, const std::string &text, const gcn::Color *color, gcn::Font *font, bool outline): diff --git a/src/units.cpp b/src/units.cpp index 6971a5445..ee0647e2e 100644 --- a/src/units.cpp +++ b/src/units.cpp @@ -31,6 +31,8 @@ #include <climits> #include <vector> +#include "debug.h" + struct UnitLevel { std::string symbol; diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp index cdd928105..d3563fb78 100644 --- a/src/utils/base64.cpp +++ b/src/utils/base64.cpp @@ -32,6 +32,8 @@ #include <stdlib.h> #include <string.h> +#include "debug.h" + static char base64_table[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', diff --git a/src/utils/copynpaste.cpp b/src/utils/copynpaste.cpp index 06c959017..58740a243 100644 --- a/src/utils/copynpaste.cpp +++ b/src/utils/copynpaste.cpp @@ -35,6 +35,8 @@ #include <SDL_syswm.h> #include "copynpaste.h" +#include "debug.h" + #ifdef WIN32 bool retrieveBuffer(std::string& text, std::string::size_type& pos) { diff --git a/src/utils/mkdir.cpp b/src/utils/mkdir.cpp index d8962f0cd..a031fe717 100644 --- a/src/utils/mkdir.cpp +++ b/src/utils/mkdir.cpp @@ -37,6 +37,8 @@ #include "utils/mkdir.h" +#include "debug.h" + #if defined WIN32 int mkdir_r(const char *pathname) { diff --git a/src/utils/sha256.cpp b/src/utils/sha256.cpp index b38bbb7db..6bad8c5e4 100644 --- a/src/utils/sha256.cpp +++ b/src/utils/sha256.cpp @@ -83,6 +83,8 @@ typedef unsigned char uint8_t; typedef unsigned int uint32_t; #endif +#include "debug.h" + #define SHA256_BLOCK_SIZE (512 / 8) /** An sha 256 context, used by original m_opersha256 */ diff --git a/src/utils/specialfolder.cpp b/src/utils/specialfolder.cpp index 864615181..5ac06848f 100644 --- a/src/utils/specialfolder.cpp +++ b/src/utils/specialfolder.cpp @@ -29,6 +29,8 @@ #include <iostream> #endif +#include "debug.h" + /* * Retrieve the pathname of special folders on win32, or an empty string * on error / if the folder does not exist. diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index d9eca557d..5e45b6168 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -28,6 +28,8 @@ #include <cstdio> #include <list> +#include "debug.h" + static int UTF8_MAX_SIZE = 10; std::string &trim(std::string &str) diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 0ffd2acfc..b31b60ee1 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -30,6 +30,8 @@ #include <fstream> #include <cstring> +#include "debug.h" + namespace XML { Document::Document(const std::string &filename, bool useResman): diff --git a/src/vector.cpp b/src/vector.cpp index f98cc7025..c234dea4c 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -22,6 +22,8 @@ #include "vector.h" +#include "debug.h" + std::ostream& operator <<(std::ostream &os, const Vector &v) { os << "Vector(" << v.x << ", " << v.y << ", " << v.z << ")"; |