From b14ce328eaf0c82dff32ba156ec440ff1a07ac0d Mon Sep 17 00:00:00 2001 From: amber Date: Mon, 27 Dec 2004 16:29:44 +0000 Subject: update git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@821 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/grfio.c | 7 ++++--- src/common/malloc.c | 6 ++++++ src/common/malloc.h | 16 ++++++++++++++++ src/common/utils.c | 5 +++-- 4 files changed, 29 insertions(+), 5 deletions(-) (limited to 'src/common') diff --git a/src/common/grfio.c b/src/common/grfio.c index f9d99bd70..ea5bba6ab 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -31,6 +31,7 @@ #include "grfio.h" #include "mmo.h" #include "showmsg.h" +#include "malloc.h" #ifdef MEMWATCH #include "memwatch.h" @@ -350,7 +351,7 @@ static FILELIST* filelist_add(FILELIST *entry) } if (filelist_entrys>=filelist_maxentry) { - FILELIST *new_filelist = (FILELIST*)realloc( + FILELIST *new_filelist = (FILELIST*)aRealloc( (void*)filelist, (filelist_maxentry+FILELIST_ADDS)*sizeof(FILELIST) ); if (new_filelist != NULL) { filelist = new_filelist; @@ -395,7 +396,7 @@ static void filelist_adjust(void) { if (filelist!=NULL) { if (filelist_maxentry>filelist_entrys) { - FILELIST *new_filelist = (FILELIST*)realloc( + FILELIST *new_filelist = (FILELIST*)aRealloc( (void*)filelist,filelist_entrys*sizeof(FILELIST) ); if (new_filelist != NULL) { filelist = new_filelist; @@ -857,7 +858,7 @@ int grfio_add(char *fname) // ShowStatus(tmp_output); if (gentry_entrys>=gentry_maxentry) { - char **new_gentry = (char**)realloc( + char **new_gentry = (char**)aRealloc( (void*)gentry_table,(gentry_maxentry+GENTRY_ADDS)*sizeof(char*) ); if (new_gentry!=NULL) { int lop; diff --git a/src/common/malloc.c b/src/common/malloc.c index eda9bc218..dd1be030f 100644 --- a/src/common/malloc.c +++ b/src/common/malloc.c @@ -42,3 +42,9 @@ void* aRealloc_( void *p, size_t size, const char *file, int line, const char *f } return ret; } + +void * _bcalloc(size_t size, size_t cnt) { + void *ret = malloc(size * cnt); + memset(ret, 0, size * cnt); + return ret; +} diff --git a/src/common/malloc.h b/src/common/malloc.h index 3733a5e55..7b09d7074 100644 --- a/src/common/malloc.h +++ b/src/common/malloc.h @@ -3,6 +3,21 @@ #include +#if defined(GCOLLECT) + +#include "gc.h" +#define aMalloc(n) GC_MALLOC(n) +#define aCalloc(m,n) _bcalloc(m,n) +#define aRealloc(p,n) GC_REALLOC(p,n) + +extern void * _bcalloc(size_t, size_t); + +#elif defined(BCHECK) +#define aMalloc(n) malloc(n) +#define aCalloc(m,n) calloc(m,n) +#define aRealloc(p,n) realloc(p,n) +#else + #if __STDC_VERSION__ < 199901L # if __GNUC__ >= 2 # define __func__ __FUNCTION__ @@ -21,5 +36,6 @@ void* aRealloc_( void *p, size_t size, const char *file, int line, const char *f #define aCalloc(m,n) aCalloc_(m,n,ALC_MARK) #define aRealloc(p,n) aRealloc_(p,n,ALC_MARK) +#endif #endif diff --git a/src/common/utils.c b/src/common/utils.c index ccc81c1c5..9a7722478 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -3,6 +3,7 @@ #include #include #include +#include "malloc.h" void dump(unsigned char *buffer, int num) { @@ -142,7 +143,7 @@ int StringBuf_Printf(struct StringBuf *sbuf,const char *fmt,...) /* Else try again with more space. */ sbuf->max_ *= 2; // twice the old size off = sbuf->ptr_ - sbuf->buf_; - sbuf->buf_ = (char *) realloc(sbuf->buf_, sbuf->max_ + 1); + sbuf->buf_ = (char *) aRealloc(sbuf->buf_, sbuf->max_ + 1); sbuf->ptr_ = sbuf->buf_ + off; } } @@ -156,7 +157,7 @@ int StringBuf_Append(struct StringBuf *buf1,const struct StringBuf *buf2) if (size2 >= buf1_avail) { int off = buf1->ptr_ - buf1->buf_; buf1->max_ += size2; - buf1->buf_ = (char *) realloc(buf1->buf_, buf1->max_ + 1); + buf1->buf_ = (char *) aRealloc(buf1->buf_, buf1->max_ + 1); buf1->ptr_ = buf1->buf_ + off; } -- cgit v1.2.3-70-g09d2