diff options
author | flaviojs <flaviojs@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2011-07-19 04:12:30 +0000 |
---|---|---|
committer | flaviojs <flaviojs@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2011-07-19 04:12:30 +0000 |
commit | 44ce1e507f08e4d808dbae8abeb355e01de1819f (patch) | |
tree | 970bba91385573c664f0267e51aaf846d7d6710b | |
parent | fcf74b22c8c1136a66c802e8067db74e25654f81 (diff) | |
download | hercules-44ce1e507f08e4d808dbae8abeb355e01de1819f.tar.gz hercules-44ce1e507f08e4d808dbae8abeb355e01de1819f.tar.bz2 hercules-44ce1e507f08e4d808dbae8abeb355e01de1819f.tar.xz hercules-44ce1e507f08e4d808dbae8abeb355e01de1819f.zip |
* Made NO_MEMMGR only be set as a default value, allowing for simultaneous use with the memory libraries.
* Moved memory library selection to malloc.c to avoid poisoning the namespace of the rest of the code.
* Removed BCHECK code since it's unneeded. (bcheck is an external batch tool that runs on top of the dbx debugger)
* Fixed GCOLLECT usage. (missing init and final memory leak check)
* Fixed DMALLOC usage. (missing options on CYGWIN and verify memory)
* Renamed malloc_verify to malloc_verify_ptr to avoid conflict with DMALLOC.
* Changed itemtype from inline to static inline to avoid error with the SunOS compiler.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14913 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r-- | Changelog-Trunk.txt | 8 | ||||
-rw-r--r-- | src/common/core.c | 4 | ||||
-rw-r--r-- | src/common/malloc.c | 76 | ||||
-rw-r--r-- | src/common/malloc.h | 82 | ||||
-rw-r--r-- | src/map/clif.c | 2 |
5 files changed, 91 insertions, 81 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index 82c2563d4..c39b7cf93 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -1,5 +1,13 @@ Date Added +2011/07/19 + * Made NO_MEMMGR only be set as a default value, allowing for simultaneous use with the memory libraries. [FlavioJS] + * Moved memory library selection to malloc.c to avoid poisoning the namespace of the rest of the code. + * Removed BCHECK code since it's uneeded. (bcheck is an external batch tool that runs on top of the dbx debugger) + * Fixed GCOLLECT usage. (missing init and final memory leak check) + * Fixed DMALLOC usage. (missing options on CYGWIN and verify memory) + * Renamed malloc_verify to malloc_verify_ptr to avoid conflict with DMALLOC. + * Changed itemtype from inline to static inline to avoid error with the SunOS compiler. 2011/07/15 * Changed the warning message of when setrlimit fails to be more explicit. [FlavioJS] * CMake: added tests for big endian, typecast to union and monotonic clock. diff --git a/src/common/core.c b/src/common/core.c index bfa563d8c..d528861c2 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -276,7 +276,3 @@ int main (int argc, char **argv) return 0; } - -#ifdef BCHECK -unsigned int __invalid_size_argument_for_IOC; -#endif diff --git a/src/common/malloc.c b/src/common/malloc.c index f80d11fb4..cf553fd73 100644 --- a/src/common/malloc.c +++ b/src/common/malloc.c @@ -10,9 +10,58 @@ #include <string.h> #include <time.h> -// no logging for minicore -#if defined(MINICORE) && defined(LOG_MEMMGR) -#undef LOG_MEMMGR +////////////// Memory Libraries ////////////////// + +#if defined(MEMWATCH) + +# include <string.h> +# include "memwatch.h" +# define MALLOC(n,file,line,func) mwMalloc((n),(file),(line)) +# define MALLOCA(n,file,line,func) mwMalloc((n),(file),(line)) +# define CALLOC(m,n,file,line,func) mwCalloc((m),(n),(file),(line)) +# define CALLOCA(m,n,file,line,func) mwCalloc((m),(n),(file),(line)) +# define REALLOC(p,n,file,line,func) mwRealloc((p),(n),(file),(line)) +# define STRDUP(p,file,line,func) mwStrdup((p),(file),(line)) +# define FREE(p,file,line,func) mwFree((p),(file),(line)) + +#elif defined(DMALLOC) + +# include <string.h> +# include <stdlib.h> +# include "dmalloc.h" +# define MALLOC(n,file,line,func) dmalloc_malloc((file),(line),(n),DMALLOC_FUNC_MALLOC,0,0) +# define MALLOCA(n,file,line,func) dmalloc_malloc((file),(line),(n),DMALLOC_FUNC_MALLOC,0,0) +# define CALLOC(m,n,file,line,func) dmalloc_malloc((file),(line),(m)*(n),DMALLOC_FUNC_CALLOC,0,0) +# define CALLOCA(m,n,file,line,func) dmalloc_malloc((file),(line),(m)*(n),DMALLOC_FUNC_CALLOC,0,0) +# define REALLOC(p,n,file,line,func) dmalloc_realloc((file),(line),(p),(n),DMALLOC_FUNC_REALLOC,0) +# define STRDUP(p,file,line,func) strdup(p) +# define FREE(p,file,line,func) free(p) + +#elif defined(GCOLLECT) + +# include "gc.h" +# define MALLOC(n,file,line,func) GC_MALLOC(n) +# define MALLOCA(n,file,line,func) GC_MALLOC_ATOMIC(n) +# define CALLOC(m,n,file,line,func) _bcalloc((m),(n)) +# define CALLOCA(m,n,file,line,func) _bcallocA((m),(n)) +# define REALLOC(p,n,file,line,func) GC_REALLOC((p),(n)) +# define STRDUP(p,file,line,func) _bstrdup(p) +# define FREE(p,file,line,func) GC_FREE(p) + + void * _bcalloc(size_t, size_t); + void * _bcallocA(size_t, size_t); + char * _bstrdup(const char *); + +#else + +# define MALLOC(n,file,line,func) malloc(n) +# define MALLOCA(n,file,line,func) malloc(n) +# define CALLOC(m,n,file,line,func) calloc((m),(n)) +# define CALLOCA(m,n,file,line,func) calloc((m),(n)) +# 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) + #endif void* aMalloc_(size_t size, const char *file, int line, const char *func) @@ -90,20 +139,20 @@ void aFree_(void *p, const char *file, int line, const char *func) void* _bcallocA(size_t size, size_t cnt) { - void *ret = MALLOCA(size * cnt); + void *ret = GC_MALLOC_ATOMIC(size * cnt); if (ret) memset(ret, 0, size * cnt); return ret; } void* _bcalloc(size_t size, size_t cnt) { - void *ret = MALLOC(size * cnt); + void *ret = GC_MALLOC(size * cnt); if (ret) memset(ret, 0, size * cnt); return ret; } char* _bstrdup(const char *chr) { int len = strlen(chr); - char *ret = (char*)MALLOC(len + 1); + char *ret = (char*)GC_MALLOC(len + 1); if (ret) memcpy(ret, chr, len + 1); return ret; } @@ -654,10 +703,12 @@ static void memmgr_init (void) *-------------------------------------- */ -bool malloc_verify(void* ptr) +bool malloc_verify_ptr(void* ptr) { #ifdef USE_MEMMGR return memmgr_verify(ptr); +#elif defined(DMALLOC) + return (dmalloc_verify(ptr) == DMALLOC_VERIFY_NOERROR); #else return true; #endif @@ -677,10 +728,21 @@ void malloc_final (void) #ifdef USE_MEMMGR memmgr_final (); #endif +#ifdef GCOLLECT + GC_find_leak = 1; + GC_gcollect(); +#endif } void malloc_init (void) { +#if defined(DMALLOC) && defined(CYGWIN) + // http://dmalloc.com/docs/latest/online/dmalloc_19.html + dmalloc_debug_setup(getenv("DMALLOC_OPTIONS")); +#endif +#ifdef GCOLLECT + GC_INIT(); +#endif #ifdef USE_MEMMGR memmgr_init (); #endif diff --git a/src/common/malloc.h b/src/common/malloc.h index aaf3e318d..4e0c603b4 100644 --- a/src/common/malloc.h +++ b/src/common/malloc.h @@ -15,17 +15,17 @@ #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 -// Use built-in memory manager by default +// default memory manager #if !defined(NO_MEMMGR) && !defined(USE_MEMMGR) +#if defined(MEMWATCH) || defined(DMALLOC) || defined(GCOLLECT) +// disable built-in memory manager when using another manager +#define NO_MEMMGR +#else +// use built-in memory manager by default #define USE_MEMMGR #endif +#endif ////////////////////////////////////////////////////////////////////// @@ -35,6 +35,11 @@ // Enable memory manager logging by default #define LOG_MEMMGR +// no logging for minicore +#if defined(MINICORE) && defined(LOG_MEMMGR) +#undef LOG_MEMMGR +#endif + # define aMalloc(n) _mmalloc(n,ALC_MARK) # define aMallocA(n) _mmalloc(n,ALC_MARK) # define aCalloc(m,n) _mcalloc(m,n,ALC_MARK) @@ -69,67 +74,6 @@ #endif -////////////// Memory Managers ////////////////// - -#if defined(MEMWATCH) - -# include "memwatch.h" -# define MALLOC(n,file,line,func) mwMalloc((n),(file),(line)) -# define MALLOCA(n,file,line,func) mwMalloc((n),(file),(line)) -# define CALLOC(m,n,file,line,func) mwCalloc((m),(n),(file),(line)) -# define CALLOCA(m,n,file,line,func) mwCalloc((m),(n),(file),(line)) -# define REALLOC(p,n,file,line,func) mwRealloc((p),(n),(file),(line)) -# define STRDUP(p,file,line,func) mwStrdup((p),(file),(line)) -# define FREE(p,file,line,func) mwFree((p),(file),(line)) - -#elif defined(DMALLOC) - -# include "dmalloc.h" -# define MALLOC(n,file,line,func) dmalloc_malloc((file),(line),(n),DMALLOC_FUNC_MALLOC,0,0) -# define MALLOCA(n,file,line,func) dmalloc_malloc((file),(line),(n),DMALLOC_FUNC_MALLOC,0,0) -# define CALLOC(m,n,file,line,func) dmalloc_malloc((file),(line),(m)*(n),DMALLOC_FUNC_CALLOC,0,0) -# define CALLOCA(m,n,file,line,func) dmalloc_malloc((file),(line),(m)*(n),DMALLOC_FUNC_CALLOC,0,0) -# define REALLOC(p,n,file,line,func) dmalloc_realloc((file),(line),(p),(n),DMALLOC_FUNC_REALLOC,0) -# define STRDUP(p,file,line,func) strdup(p) -# define FREE(p,file,line,func) free(p) - -#elif defined(GCOLLECT) - -# include "gc.h" -# define MALLOC(n,file,line,func) GC_MALLOC(n) -# define MALLOCA(n,file,line,func) GC_MALLOC_ATOMIC(n) -# define CALLOC(m,n,file,line,func) _bcalloc((m),(n)) -# define CALLOCA(m,n,file,line,func) _bcallocA((m),(n)) -# define REALLOC(p,n,file,line,func) GC_REALLOC((p),(n)) -# define STRDUP(p,file,line,func) _bstrdup(p) -# define FREE(p,file,line,func) GC_FREE(p) - - void * _bcalloc(size_t, size_t); - void * _bcallocA(size_t, size_t); - char * _bstrdup(const char *); - -#elif defined(BCHECK) - -# define MALLOC(n,file,line,func) malloc(n) -# define MALLOCA(n,file,line,func) malloc(n) -# define CALLOC(m,n,file,line,func) calloc((m),(n)) -# define CALLOCA(m,n,file,line,func) calloc((m),(n)) -# 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) -# define MALLOCA(n,file,line,func) malloc(n) -# define CALLOC(m,n,file,line,func) calloc((m),(n)) -# define CALLOCA(m,n,file,line,func) calloc((m),(n)) -# 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) - -#endif - /////////////// Buffer Creation ///////////////// // Full credit for this goes to Shinomori [Ajarn] @@ -155,7 +99,7 @@ //////////////////////////////////////////////// -bool malloc_verify(void* ptr); +bool malloc_verify_ptr(void* ptr); size_t malloc_usage (void); void malloc_init (void); void malloc_final (void); diff --git a/src/map/clif.c b/src/map/clif.c index 071401acf..e0fb480a9 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -57,7 +57,7 @@ struct Clif_Config { struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1]; //Converts item type in case of pet eggs. -inline int itemtype(int type) +static inline int itemtype(int type) { return ( type == IT_PETEGG ) ? IT_WEAPON : type; } |