diff options
author | Er_Maqui <er_maqui@darkbolt.net> | 2015-10-21 14:54:40 +0200 |
---|---|---|
committer | Er_Maqui <er_maqui@darkbolt.net> | 2015-10-21 14:54:40 +0200 |
commit | 198aef7133713b47a4c4fadaac6811c9d3812d19 (patch) | |
tree | 84df335dd0ad350c20f8c2a018b2a7096907b636 /src/common | |
parent | 6977d6d31b58afc5095c0a59e754f21ea1080054 (diff) | |
parent | 8b198db1e0ccc8209b7bcf54b4df62d4747f75b2 (diff) | |
download | hercules-198aef7133713b47a4c4fadaac6811c9d3812d19.tar.gz hercules-198aef7133713b47a4c4fadaac6811c9d3812d19.tar.bz2 hercules-198aef7133713b47a4c4fadaac6811c9d3812d19.tar.xz hercules-198aef7133713b47a4c4fadaac6811c9d3812d19.zip |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/HPM.c | 2 | ||||
-rw-r--r-- | src/common/HPMDataCheck.h | 10 | ||||
-rw-r--r-- | src/common/HPMSymbols.inc.h | 8 | ||||
-rw-r--r-- | src/common/Makefile.in | 8 | ||||
-rw-r--r-- | src/common/console.c | 27 | ||||
-rw-r--r-- | src/common/core.c | 2 | ||||
-rw-r--r-- | src/common/db.c | 2 | ||||
-rw-r--r-- | src/common/ers.c | 2 | ||||
-rw-r--r-- | src/common/grfio.c | 2 | ||||
-rw-r--r-- | src/common/memmgr.c (renamed from src/common/malloc.c) | 52 | ||||
-rw-r--r-- | src/common/memmgr.h (renamed from src/common/malloc.h) | 6 | ||||
-rw-r--r-- | src/common/mutex.c | 2 | ||||
-rw-r--r-- | src/common/socket.c | 2 | ||||
-rw-r--r-- | src/common/sql.c | 2 | ||||
-rw-r--r-- | src/common/strlib.c | 2 | ||||
-rw-r--r-- | src/common/sysinfo.c | 2 | ||||
-rw-r--r-- | src/common/thread.c | 2 | ||||
-rw-r--r-- | src/common/timer.c | 2 |
18 files changed, 88 insertions, 47 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c index 5373c8b6a..7d9a0b104 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -11,7 +11,7 @@ #include "common/console.h" #include "common/core.h" #include "common/db.h" -#include "common/malloc.h" +#include "common/memmgr.h" #include "common/mapindex.h" #include "common/mmo.h" #include "common/showmsg.h" diff --git a/src/common/HPMDataCheck.h b/src/common/HPMDataCheck.h index 510ea9d4e..923b6ccbf 100644 --- a/src/common/HPMDataCheck.h +++ b/src/common/HPMDataCheck.h @@ -144,16 +144,16 @@ HPExport const struct s_HPMDataCheck HPMDataCheck[] = { #else #define COMMON_HPMI_H #endif // COMMON_HPMI_H - #ifdef COMMON_MALLOC_H - { "malloc_interface", sizeof(struct malloc_interface), SERVER_TYPE_ALL }, - #else - #define COMMON_MALLOC_H - #endif // COMMON_MALLOC_H #ifdef COMMON_MAPINDEX_H { "mapindex_interface", sizeof(struct mapindex_interface), SERVER_TYPE_CHAR|SERVER_TYPE_MAP }, #else #define COMMON_MAPINDEX_H #endif // COMMON_MAPINDEX_H + #ifdef COMMON_MEMMGR_H + { "malloc_interface", sizeof(struct malloc_interface), SERVER_TYPE_ALL }, + #else + #define COMMON_MEMMGR_H + #endif // COMMON_MEMMGR_H #ifdef COMMON_MMO_H { "auction_data", sizeof(struct auction_data), SERVER_TYPE_ALL }, { "fame_list", sizeof(struct fame_list), SERVER_TYPE_ALL }, diff --git a/src/common/HPMSymbols.inc.h b/src/common/HPMSymbols.inc.h index 3a4c5852c..4c3722b69 100644 --- a/src/common/HPMSymbols.inc.h +++ b/src/common/HPMSymbols.inc.h @@ -125,9 +125,9 @@ struct loginif_interface *loginif; #ifdef MAP_MAIL_H /* mail */ struct mail_interface *mail; #endif // MAP_MAIL_H -#ifdef COMMON_MALLOC_H /* iMalloc */ +#ifdef COMMON_MEMMGR_H /* iMalloc */ struct malloc_interface *iMalloc; -#endif // COMMON_MALLOC_H +#endif // COMMON_MEMMGR_H #ifdef MAP_MAP_H /* map */ struct map_interface *map; #endif // MAP_MAP_H @@ -348,9 +348,9 @@ if ((server_type&(SERVER_TYPE_CHAR)) && !HPM_SYMBOL("loginif", loginif)) return #ifdef MAP_MAIL_H /* mail */ if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("mail", mail)) return "mail"; #endif // MAP_MAIL_H -#ifdef COMMON_MALLOC_H /* iMalloc */ +#ifdef COMMON_MEMMGR_H /* iMalloc */ if ((server_type&(SERVER_TYPE_ALL)) && !HPM_SYMBOL("iMalloc", iMalloc)) return "iMalloc"; -#endif // COMMON_MALLOC_H +#endif // COMMON_MEMMGR_H #ifdef MAP_MAP_H /* map */ if ((server_type&(SERVER_TYPE_MAP)) && !HPM_SYMBOL("map", map)) return "map"; #endif // MAP_MAP_H diff --git a/src/common/Makefile.in b/src/common/Makefile.in index 208d3b111..88e991651 100644 --- a/src/common/Makefile.in +++ b/src/common/Makefile.in @@ -27,12 +27,12 @@ COMMON_SHARED_C = conf.c db.c des.c ers.c grfio.c HPM.c mapindex.c md5calc.c \ COMMON_C = $(COMMON_SHARED_C) COMMON_SHARED_OBJ = $(patsubst %.c,%.o,$(COMMON_SHARED_C)) COMMON_OBJ = $(addprefix obj_all/, $(COMMON_SHARED_OBJ) \ - console.o core.o malloc.o socket.o) + console.o core.o memmgr.o socket.o) COMMON_MINI_OBJ = $(addprefix obj_all/, $(COMMON_SHARED_OBJ) \ - miniconsole.o minicore.o minimalloc.o minisocket.o) -COMMON_C += console.c core.c malloc.c socket.c + miniconsole.o minicore.o minimemmgr.o minisocket.o) +COMMON_C += console.c core.c memmgr.c socket.c COMMON_H = atomic.h cbasetypes.h conf.h console.h core.h db.h des.h ers.h \ - grfio.h hercules.h HPM.h HPMi.h malloc.h mapindex.h md5calc.h \ + grfio.h hercules.h HPM.h HPMi.h memmgr.h mapindex.h md5calc.h \ mmo.h mutex.h nullpo.h random.h showmsg.h socket.h spinlock.h \ sql.h strlib.h sysinfo.h thread.h timer.h utils.h winapi.h diff --git a/src/common/console.c b/src/common/console.c index c8ca4ae87..477141b48 100644 --- a/src/common/console.c +++ b/src/common/console.c @@ -16,7 +16,7 @@ #ifndef MINICORE # include "common/atomic.h" # include "common/ers.h" -# include "common/malloc.h" +# include "common/memmgr.h" # include "common/mutex.h" # include "common/spinlock.h" # include "common/sql.h" @@ -362,7 +362,6 @@ void console_parse_sub(char *line) char *tok; char sublist[CP_CMD_LENGTH * 5]; int i; - unsigned int len = 0; memcpy(bline, line, 200); tok = strtok(line, " "); @@ -375,19 +374,15 @@ void console_parse_sub(char *line) cmd = VECTOR_INDEX(console->input->command_list, i); - len += snprintf(sublist,CP_CMD_LENGTH * 5,"%s", cmd->cmd); + snprintf(sublist, sizeof(sublist), "%s", cmd->cmd); if (cmd->type == CPET_FUNCTION) { - char *r = NULL; - if( (tok = strtok(NULL, " ")) ) { - r = bline; - r += len + 1; - } - cmd->u.func(r); + tok = strtok(NULL, ""); + cmd->u.func(tok); return; } - while (( tok = strtok(NULL, " ") ) != NULL) { + while ((tok = strtok(NULL, " ")) != NULL) { struct CParseEntry *entry = NULL; Assert_retv(cmd->type == CPET_CATEGORY); @@ -409,17 +404,15 @@ void console_parse_sub(char *line) } entry = VECTOR_INDEX(cmd->u.children, i); if (entry->type == CPET_FUNCTION) { - char *r = NULL; - if ((tok = strtok(NULL, " "))) { - r = bline; - r += len + strlen(entry->cmd) + 1; - } - entry->u.func(r); + tok = strtok(NULL, ""); + entry->u.func(tok); return; } cmd = entry; - len += snprintf(sublist + len,(CP_CMD_LENGTH * 5) - len," %s", cmd->cmd); + + if (strlen(sublist) < sizeof(sublist)-1) + snprintf(sublist+strlen(sublist), sizeof(sublist), " %s", cmd->cmd); } ShowError("Is only a category, type '"CL_WHITE"%s help"CL_RESET"' to list its subcommands\n",sublist); } diff --git a/src/common/core.c b/src/common/core.c index 8564b8acc..6f21f526b 100644 --- a/src/common/core.c +++ b/src/common/core.c @@ -10,7 +10,7 @@ #include "common/cbasetypes.h" #include "common/console.h" #include "common/db.h" -#include "common/malloc.h" +#include "common/memmgr.h" #include "common/mmo.h" #include "common/random.h" #include "common/showmsg.h" diff --git a/src/common/db.c b/src/common/db.c index 4df5c08db..0600be2e8 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -73,7 +73,7 @@ #include "db.h" #include "common/ers.h" -#include "common/malloc.h" +#include "common/memmgr.h" #include "common/mmo.h" #include "common/showmsg.h" #include "common/strlib.h" diff --git a/src/common/ers.c b/src/common/ers.c index 91fc6ccfb..bf17e087d 100644 --- a/src/common/ers.c +++ b/src/common/ers.c @@ -45,7 +45,7 @@ #include "ers.h" #include "common/cbasetypes.h" -#include "common/malloc.h" // CREATE, RECREATE, aMalloc, aFree +#include "common/memmgr.h" // CREATE, RECREATE, aMalloc, aFree #include "common/nullpo.h" #include "common/showmsg.h" // ShowMessage, ShowError, ShowFatalError, CL_BOLD, CL_NORMAL diff --git a/src/common/grfio.c b/src/common/grfio.c index b59c2b63d..46804ea08 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -8,7 +8,7 @@ #include "common/cbasetypes.h" #include "common/des.h" -#include "common/malloc.h" +#include "common/memmgr.h" #include "common/nullpo.h" #include "common/showmsg.h" #include "common/strlib.h" diff --git a/src/common/malloc.c b/src/common/memmgr.c index 63de90cb3..0d9305b06 100644 --- a/src/common/malloc.c +++ b/src/common/memmgr.c @@ -4,7 +4,7 @@ #define HERCULES_CORE -#include "malloc.h" +#include "memmgr.h" #include "common/cbasetypes.h" #include "common/core.h" @@ -79,6 +79,26 @@ struct malloc_interface *iMalloc; #endif +#ifndef USE_MEMMGR + +#ifdef __APPLE__ +#include <malloc/malloc.h> +#define BUFFER_SIZE(ptr) malloc_size(ptr) +#elif __FreeBSD__ +#include <malloc_np.h> +#define BUFFER_SIZE(ptr) malloc_usable_size(ptr) +#elif defined __linux__ || defined __linux || defined CYGWIN +#include <malloc.h> +#define BUFFER_SIZE(ptr) malloc_usable_size(ptr) +#elif defined WIN32 +#include <malloc.h> +#define BUFFER_SIZE(ptr) _msize(ptr) +#else +#error Unsupported OS +#endif + +#endif + void* aMalloc_(size_t size, const char *file, int line, const char *func) { void *ret = MALLOC(size, file, line, func); @@ -110,6 +130,34 @@ void* aRealloc_(void *p, size_t size, const char *file, int line, const char *fu } return ret; } + +void* aReallocz_(void *p, size_t size, const char *file, int line, const char *func) +{ + void *ret; + // ShowMessage("%s:%d: in func %s: aReallocz %p %ld\n",file,line,func,p,size); +#ifdef USE_MEMMGR + ret = REALLOC(p, size, file, line, func); +#else + size_t newSize; + if (p) { + size_t oldSize = malloc_usable_size(p); + ret = REALLOC(p, size, file, line, func); + newSize = BUFFER_SIZE(ret); + if (ret && newSize > oldSize) + memset(ret + oldSize, 0, newSize - oldSize); + } else { + ret = REALLOC(p, size, file, line, func); + if (ret) + memset(ret, 0, BUFFER_SIZE(ret)); + } +#endif + if (ret == NULL){ + ShowFatalError("%s:%d: in func %s: aRealloc error out of memory!\n",file,line,func); + exit(EXIT_FAILURE); + } + return ret; +} + char* aStrdup_(const char *p, const char *file, int line, const char *func) { char *ret = STRDUP(p, file, line, func); @@ -888,7 +936,7 @@ void malloc_defaults(void) { iMalloc->malloc = aMalloc_; iMalloc->calloc = aCalloc_; iMalloc->realloc = aRealloc_; - iMalloc->reallocz = aRealloc_;/* not using memory manager huhum o.o perhaps we could still do something about */ + iMalloc->reallocz = aReallocz_;/* not using memory manager huhum o.o perhaps we could still do something about */ iMalloc->astrdup = aStrdup_; iMalloc->free = aFree_; #endif diff --git a/src/common/malloc.h b/src/common/memmgr.h index b194c7cf3..c5a3358db 100644 --- a/src/common/malloc.h +++ b/src/common/memmgr.h @@ -1,8 +1,8 @@ // Copyright (c) Athena Dev Teams - Licensed under GNU GPL // For more information, see LICENCE in the main folder -#ifndef COMMON_MALLOC_H -#define COMMON_MALLOC_H +#ifndef COMMON_MEMMGR_H +#define COMMON_MEMMGR_H #include "common/hercules.h" @@ -86,4 +86,4 @@ void memmgr_report(int extra); HPShared struct malloc_interface *iMalloc; -#endif /* COMMON_MALLOC_H */ +#endif /* COMMON_MEMMGR_H */ diff --git a/src/common/mutex.c b/src/common/mutex.c index 715609628..af1a6d155 100644 --- a/src/common/mutex.c +++ b/src/common/mutex.c @@ -6,7 +6,7 @@ #include "mutex.h" #include "common/cbasetypes.h" // for WIN32 -#include "common/malloc.h" +#include "common/memmgr.h" #include "common/showmsg.h" #include "common/timer.h" diff --git a/src/common/socket.c b/src/common/socket.c index b4b67da40..b418a468f 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -10,7 +10,7 @@ #include "common/HPM.h" #include "common/cbasetypes.h" #include "common/db.h" -#include "common/malloc.h" +#include "common/memmgr.h" #include "common/mmo.h" #include "common/nullpo.h" #include "common/showmsg.h" diff --git a/src/common/sql.c b/src/common/sql.c index ee759eb61..4262a10a1 100644 --- a/src/common/sql.c +++ b/src/common/sql.c @@ -7,7 +7,7 @@ #include "sql.h" #include "common/cbasetypes.h" -#include "common/malloc.h" +#include "common/memmgr.h" #include "common/showmsg.h" #include "common/strlib.h" #include "common/timer.h" diff --git a/src/common/strlib.c b/src/common/strlib.c index fcd1b483b..fefabe52b 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -7,7 +7,7 @@ #include "strlib.h" #include "common/cbasetypes.h" -#include "common/malloc.h" +#include "common/memmgr.h" #include "common/showmsg.h" #include <errno.h> diff --git a/src/common/sysinfo.c b/src/common/sysinfo.c index d218e6e99..1baf33086 100644 --- a/src/common/sysinfo.c +++ b/src/common/sysinfo.c @@ -10,7 +10,7 @@ #include "common/cbasetypes.h" #include "common/core.h" -#include "common/malloc.h" +#include "common/memmgr.h" #include "common/strlib.h" #include <stdio.h> // fopen diff --git a/src/common/thread.c b/src/common/thread.c index d5bbd7f97..d9cd42aa6 100644 --- a/src/common/thread.c +++ b/src/common/thread.c @@ -11,7 +11,7 @@ #include "thread.h" #include "common/cbasetypes.h" -#include "common/malloc.h" +#include "common/memmgr.h" #include "common/showmsg.h" #include "common/sysinfo.h" // sysinfo->getpagesize() diff --git a/src/common/timer.c b/src/common/timer.c index f6ce00d54..f31ae0ffe 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -8,7 +8,7 @@ #include "common/cbasetypes.h" #include "common/db.h" -#include "common/malloc.h" +#include "common/memmgr.h" #include "common/showmsg.h" #include "common/utils.h" |