summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-11-19 03:05:16 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-11-19 03:05:16 +0000
commitaee3755b6d780c3261bdec2aef4d517bc7c7b148 (patch)
tree71dd1e301aab7780c23db9dd62de0ce7ce85a1d8 /src
parenta0a93b21ebfbf51e3926a6819b46632703c33d90 (diff)
downloadhercules-aee3755b6d780c3261bdec2aef4d517bc7c7b148.tar.gz
hercules-aee3755b6d780c3261bdec2aef4d517bc7c7b148.tar.bz2
hercules-aee3755b6d780c3261bdec2aef4d517bc7c7b148.tar.xz
hercules-aee3755b6d780c3261bdec2aef4d517bc7c7b148.zip
* Nullpo's disabled on release builds.
* Added timestamps to the log of memory leaks. * Moved definition of __func__ to cbasetypes.h. * Configure script updated: - added option to select the memory manager - added option to enable MAPREGSQL - added option to enable DEBUG * common's Makefile deleting svnversion.h on 'clean' target. (run ./configure again to update your Makefile) git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11760 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r--src/common/Makefile.in2
-rw-r--r--src/common/cbasetypes.h12
-rw-r--r--src/common/malloc.c22
-rw-r--r--src/common/malloc.h35
-rw-r--r--src/common/nullpo.h49
-rw-r--r--src/map/path.c4
6 files changed, 63 insertions, 61 deletions
diff --git a/src/common/Makefile.in b/src/common/Makefile.in
index c22cc721c..94f42a956 100644
--- a/src/common/Makefile.in
+++ b/src/common/Makefile.in
@@ -17,7 +17,7 @@ txt: obj common
sql: $(SQL_DEPENDS)
clean:
- rm -rf *.o obj obj_sql
+ rm -rf *.o obj obj_sql svnversion.h
help:
@echo "possible targets are 'txt' 'sql' 'all' 'clean' 'help'"
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h
index d31d515a8..557e263fb 100644
--- a/src/common/cbasetypes.h
+++ b/src/common/cbasetypes.h
@@ -52,6 +52,18 @@
#define DEBUG
#endif
+// debug function name
+#ifndef __NETBSD__
+#if __STDC_VERSION__ < 199901L
+# if __GNUC__ >= 2
+# define __func__ __FUNCTION__
+# else
+# define __func__ ""
+# endif
+#endif
+#endif
+
+
// disable attributed stuff on non-GNU
#if !defined(__GNUC__) && !defined(MINGW)
# define __attribute__(x)
diff --git a/src/common/malloc.c b/src/common/malloc.c
index 414770156..a65ee7eed 100644
--- a/src/common/malloc.c
+++ b/src/common/malloc.c
@@ -1,15 +1,18 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "../common/malloc.h"
#include "../common/core.h"
#include "../common/showmsg.h"
-#ifdef MINICORE
- #undef LOG_MEMMGR
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+// no logging for minicore
+#if defined(MINICORE) && defined(LOG_MEMMGR)
+#undef LOG_MEMMGR
#endif
void* aMalloc_(size_t size, const char *file, int line, const char *func)
@@ -553,12 +556,17 @@ static FILE *log_fp;
static void memmgr_log (char *buf)
{
- if (!log_fp) {
+ time_t raw;
+ struct tm* t;
+ if( !log_fp )
+ {
log_fp = fopen(memmer_logfile,"w");
if (!log_fp) log_fp = stdout;
fprintf(log_fp, "Memory manager: Memory leaks found (Revision %s).\n", get_svn_revision());
}
- fprintf(log_fp, buf);
+ time(&raw);
+ t = localtime(&raw);
+ fprintf(log_fp, "%04d%02d%02d%02d%02d%02d %s", (t->tm_year+1900), (t->tm_mon+1), t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, buf);
return;
}
#endif
diff --git a/src/common/malloc.h b/src/common/malloc.h
index 43eff40f1..1efc4686f 100644
--- a/src/common/malloc.h
+++ b/src/common/malloc.h
@@ -13,28 +13,28 @@
// and I have doubts our implementation works.
// -> They should NOT be used, period.
-#ifndef __NETBSD__
-#if __STDC_VERSION__ < 199901L
-# if __GNUC__ >= 2
-# define __func__ __FUNCTION__
-# else
-# define __func__ ""
-# endif
+#define ALC_MARK __FILE__, __LINE__, __func__
+
+// disable built-in memory manager when using another manager
+#if defined(MEMWATCH) || defined(DMALLOC) || defined(GCOLLECT) || defined(BCHECK)
+#if !defined(NO_MEMMGR)
+#define NO_MEMMGR
#endif
#endif
-#define ALC_MARK __FILE__, __LINE__, __func__
-//////////////////////////////////////////////////////////////////////
-// Whether to use Athena's built-in Memory Manager (enabled by default)
-// To disable just comment the following line
-#if !defined(DMALLOC) && !defined(BCHECK)
- #define USE_MEMMGR
+// Use built-in memory manager by default
+#if !defined(NO_MEMMGR) && !defined(USE_MEMMGR)
+#define USE_MEMMGR
#endif
-// Whether to enable Memory Manager's logging
-#define LOG_MEMMGR
+
+//////////////////////////////////////////////////////////////////////
+// Athena's built-in Memory Manager
#ifdef USE_MEMMGR
+// Enable memory manager logging by default
+#define LOG_MEMMGR
+
# define aMalloc(n) _mmalloc(n,ALC_MARK)
# define aMallocA(n) _mmalloc(n,ALC_MARK)
# define aCalloc(m,n) _mcalloc(m,n,ALC_MARK)
@@ -71,7 +71,7 @@
////////////// Memory Managers //////////////////
-#ifdef MEMWATCH
+#if defined(MEMWATCH)
# include "memwatch.h"
# define MALLOC(n,file,line,func) mwMalloc((n),(file),(line))
@@ -108,7 +108,6 @@
void * _bcallocA(size_t, size_t);
char * _bstrdup(const char *);
-/* FIXME Why is this the same as #else? [FlavioJS]
#elif defined(BCHECK)
# define MALLOC(n,file,line,func) malloc(n)
@@ -118,7 +117,7 @@
# define REALLOC(p,n,file,line,func) realloc((p),(n))
# define STRDUP(p,file,line,func) strdup(p)
# define FREE(p,file,line,func) free(p)
-*/
+
#else
# define MALLOC(n,file,line,func) malloc(n)
diff --git a/src/common/nullpo.h b/src/common/nullpo.h
index 0238d2b6d..8ee86a782 100644
--- a/src/common/nullpo.h
+++ b/src/common/nullpo.h
@@ -5,28 +5,15 @@
#define _NULLPO_H_
-#define NULLPO_CHECK 1
- // 全体のスイッチを宣言しているヘッダがあれば
- // そこに移動していただけると
-
-#ifndef __NETBSD__
-#if __STDC_VERSION__ < 199901L
-# if __GNUC__ >= 2
-# define __func__ __FUNCTION__
-# else
-# define __func__ ""
-# endif
-#endif
-#endif
+#include "../common/cbasetypes.h"
+#define NLP_MARK __FILE__, __LINE__, __func__
-#if !defined(__GNUC__) && !defined(MINGW)
-# define __attribute__(x) /* nothing */
+// enabled by default on debug builds
+#if defined(DEBUG) && !defined(NULLPO_CHECK)
+#define NULLPO_CHECK
#endif
-
-#define NLP_MARK __FILE__, __LINE__, __func__
-
/*----------------------------------------------------------------------------
* Macros
*----------------------------------------------------------------------------
@@ -81,7 +68,7 @@
*--------------------------------------
*/
-#if NULLPO_CHECK
+#if defined(NULLPO_CHECK)
#define nullpo_ret(t) \
if (nullpo_chk(NLP_MARK, (void *)(t))) {return(0);}
@@ -137,25 +124,25 @@
// 良い方法が思いつかなかったので・・・苦肉の策です。
// 一応ワーニングは出ないはず
-#define nullpo_ret(t) if((t)){;}
-#define nullpo_retv(t) if((t)){;}
-#define nullpo_retr(ret, t) if((t)){;}
-#define nullpo_retb(t) if((t)){;}
+#define nullpo_ret(t) (void)(t)
+#define nullpo_retv(t) (void)(t)
+#define nullpo_retr(ret, t) (void)(t)
+#define nullpo_retb(t) (void)(t)
// 可変引数マクロに関する条件コンパイル
#if __STDC_VERSION__ >= 199901L
/* C99に対応 */
-#define nullpo_ret_f(t, fmt, ...) if((t)){;}
-#define nullpo_retv_f(t, fmt, ...) if((t)){;}
-#define nullpo_retr_f(ret, t, fmt, ...) if((t)){;}
-#define nullpo_retb_f(t, fmt, ...) if((t)){;}
+#define nullpo_ret_f(t, fmt, ...) (void)(t)
+#define nullpo_retv_f(t, fmt, ...) (void)(t)
+#define nullpo_retr_f(ret, t, fmt, ...) (void)(t)
+#define nullpo_retb_f(t, fmt, ...) (void)(t)
#elif __GNUC__ >= 2
/* GCC用 */
-#define nullpo_ret_f(t, fmt, args...) if((t)){;}
-#define nullpo_retv_f(t, fmt, args...) if((t)){;}
-#define nullpo_retr_f(ret, t, fmt, args...) if((t)){;}
-#define nullpo_retb_f(t, fmt, args...) if((t)){;}
+#define nullpo_ret_f(t, fmt, args...) (void)(t)
+#define nullpo_retv_f(t, fmt, args...) (void)(t)
+#define nullpo_retr_f(ret, t, fmt, args...) (void)(t)
+#define nullpo_retb_f(t, fmt, args...) (void)(t)
#else
/* その他の場合・・・ orz */
diff --git a/src/map/path.c b/src/map/path.c
index 50c2f2192..3d4b99fc9 100644
--- a/src/map/path.c
+++ b/src/map/path.c
@@ -8,10 +8,6 @@
#include "map.h"
#include "battle.h"
-#ifdef MEMWATCH
-#include "memwatch.h"
-#endif
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>