From b795233e374987f4c427f59922f271810f937eef Mon Sep 17 00:00:00 2001 From: ultramage Date: Sun, 7 Jan 2007 16:49:03 +0000 Subject: Undid the memset->malloc_set replacement git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9626 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/graph.c | 2 +- src/common/grfio.c | 8 ++++---- src/common/malloc.c | 57 +++------------------------------------------------ src/common/malloc.h | 11 ---------- src/common/mapindex.c | 2 +- src/common/plugins.c | 2 +- src/common/socket.c | 4 ++-- src/common/strlib.c | 2 +- src/common/timer.c | 6 +++--- 9 files changed, 16 insertions(+), 78 deletions(-) (limited to 'src/common') diff --git a/src/common/graph.c b/src/common/graph.c index e56783816..a13379a6b 100644 --- a/src/common/graph.c +++ b/src/common/graph.c @@ -71,7 +71,7 @@ void graph_pallet(struct graph* g, int index,unsigned long c) { if(g == NULL || c >= 256) return; if(g->pallet_count <= index) { - malloc_set(g->png_data + 0x29 + 3 * g->pallet_count,0,(index - g->pallet_count) * 3); + memset(g->png_data + 0x29 + 3 * g->pallet_count,0,(index - g->pallet_count) * 3); g->pallet_count = index + 1; } g->png_data[0x29 + index * 3 ] = (unsigned char)((c >> 16) & 0xFF); // R diff --git a/src/common/grfio.c b/src/common/grfio.c index a821ee269..ba3b55bb3 100644 --- a/src/common/grfio.c +++ b/src/common/grfio.c @@ -169,7 +169,7 @@ static void BitConvert(BYTE *Src,char *BitSwapTable) int lop,prm; BYTE tmp[8]; // *(DWORD*)tmp=*(DWORD*)(tmp+4)=0; - malloc_tsetdword(tmp,0,8); + memset(tmp,0,8); for(lop=0;lop!=64;lop++) { prm = BitSwapTable[lop]-1; if (Src[(prm >> 3) & 7] & BitMaskTable[prm & 7]) { @@ -299,7 +299,7 @@ int decode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* int encode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen) { z_stream stream; int err; - malloc_tsetdword(&stream, 0, sizeof(stream)); + memset(&stream, 0, sizeof(stream)); stream.next_in = (Bytef*)source; stream.avail_in = (uInt)sourceLen; /* Check for source > 64K on 16-bit machine: */ @@ -479,7 +479,7 @@ static FILELIST* filelist_add(FILELIST *entry) if (filelist_entrys >= filelist_maxentry) { filelist = (FILELIST *)aRealloc(filelist, (filelist_maxentry + FILELIST_ADDS) * sizeof(FILELIST)); - malloc_tsetdword(filelist + filelist_maxentry, '\0', FILELIST_ADDS * sizeof(FILELIST)); + memset(filelist + filelist_maxentry, '\0', FILELIST_ADDS * sizeof(FILELIST)); filelist_maxentry += FILELIST_ADDS; } @@ -949,7 +949,7 @@ char *grfio_alloc_ptr(char *fname) if (gentry_entrys >= gentry_maxentry) { gentry_maxentry += GENTRY_ADDS; gentry_table = (char**)aRealloc(gentry_table, gentry_maxentry * sizeof(char*)); - malloc_tsetdword(gentry_table + (gentry_maxentry - GENTRY_ADDS), 0, sizeof(char*) * GENTRY_ADDS); + memset(gentry_table + (gentry_maxentry - GENTRY_ADDS), 0, sizeof(char*) * GENTRY_ADDS); } len = strlen( fname ); buf = (char*)aMallocA(len + 1); diff --git a/src/common/malloc.c b/src/common/malloc.c index d4dda5b4c..fe73057ad 100644 --- a/src/common/malloc.c +++ b/src/common/malloc.c @@ -88,15 +88,13 @@ 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); - if (ret) //malloc_set(ret, 0, size * cnt); - malloc_set(ret, 0, size*cnt); + if (ret) memset(ret, 0, size * cnt); return ret; } void* _bcalloc(size_t size, size_t cnt) { void *ret = MALLOC(size * cnt); - if (ret) //malloc_set(ret, 0, size * cnt); - malloc_set(ret, 0, size*cnt); + if (ret) memset(ret, 0, size * cnt); return ret; } char* _bstrdup(const char *chr) @@ -295,8 +293,7 @@ void* _mmalloc(size_t size, const char *file, int line, const char *func ) { void* _mcalloc(size_t num, size_t size, const char *file, int line, const char *func ) { void *p = _mmalloc(num * size,file,line,func); - //malloc_set(p,0,num * size); - malloc_set(p,0,num*size); + memset(p,0,num * size); return p; } @@ -654,54 +651,6 @@ static void memmgr_init (void) } #endif -#if defined(MEMSET_TURBO) && defined(_WIN32) - void malloc_set(void *dest, int value, int count){ - _asm - { - mov eax, value - mov ecx, count - mov ebx, ecx - mov edi, dest - shr ecx, 2 - test ecx, ecx - jz ByteOp - shl ecx, 2 - sub ebx, ecx - shr ecx, 2 - rep stosd - test ebx, ebx - jz Done - ByteOp: - mov ecx, ebx - rep stosb - Done: - } - } - // Sets 32-bit aligned memory. - void malloc_tsetdword(void *dest, int value, int count){ - _asm - { - mov edi, dest - mov ecx, count - shr ecx, 2 - mov eax, value - rep stosd - } - } - - // Sets 16-bit aligned memory. - void malloc_tsetword(void *dest, short value, int count){ - _asm - { - mov edi, dest - mov ecx, count - shr ecx, 1 - mov ax, value - rep stosw - } - } -#endif - /*====================================== * Initialise *-------------------------------------- diff --git a/src/common/malloc.h b/src/common/malloc.h index 503eba75b..d6f6adb3c 100644 --- a/src/common/malloc.h +++ b/src/common/malloc.h @@ -10,8 +10,6 @@ // and I have doubts our implementation works. // -> They should NOT be used, period. -#define MEMSET_TURBO - #ifndef __NETBSD__ #if __STDC_VERSION__ < 199901L # if __GNUC__ >= 2 @@ -163,15 +161,6 @@ unsigned int malloc_usage (void); #define INLINE inline #endif #endif -#if defined(MEMSET_TURBO) && defined(_WIN32) - INLINE void malloc_set(void *, int, int); - INLINE void malloc_tsetdword(void *, int, int); - INLINE void malloc_tsetword(void *, short, int); -#else - #define malloc_set(x,y,z) memset(x,y,z) - #define malloc_tsetdword(x,y,z) memset(x,y,z) - #define malloc_tsetword(x,y,z) memset(x,y,z) -#endif void malloc_init (void); void malloc_final (void); diff --git a/src/common/mapindex.c b/src/common/mapindex.c index d0843017e..070326463 100644 --- a/src/common/mapindex.c +++ b/src/common/mapindex.c @@ -106,7 +106,7 @@ void mapindex_init(void) { int index; char map_name[1024]; - malloc_tsetdword (&indexes, 0, sizeof (indexes)); + memset (&indexes, 0, sizeof (indexes)); fp=fopen(mapindex_cfgfile,"r"); if(fp==NULL){ ShowFatalError("Unable to read mapindex config file %s!\n", mapindex_cfgfile); diff --git a/src/common/plugins.c b/src/common/plugins.c index 5951885a1..3dcddcb3d 100644 --- a/src/common/plugins.c +++ b/src/common/plugins.c @@ -133,7 +133,7 @@ int export_symbol (void *var, int offset) plugin_call_table = (void**)aRealloc(plugin_call_table, max_call_table*sizeof(void*)); // clear the new alloced block - malloc_tsetdword(plugin_call_table + call_table_size, 0, (max_call_table-call_table_size)*sizeof(void*)); + memset(plugin_call_table + call_table_size, 0, (max_call_table-call_table_size)*sizeof(void*)); } // the new table size is delimited by the new element at the end diff --git a/src/common/socket.c b/src/common/socket.c index a230158c8..04793094c 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -434,7 +434,7 @@ int start_console(void) { if (!session[0]) { // dummy socket already uses fd 0 CREATE(session[0], struct socket_data, 1); } - malloc_set(session[0],0,sizeof(*session[0])); + memset(session[0],0,sizeof(*session[0])); session[0]->func_recv = console_recieve; session[0]->func_console = default_console_parse; @@ -1233,7 +1233,7 @@ void socket_init(void) session[0]->max_rdata = 2*rfifo_size; session[0]->max_wdata = 2*wfifo_size; - malloc_set(func_parse_table, 0, sizeof(func_parse_table)); + memset(func_parse_table, 0, sizeof(func_parse_table)); func_parse_table[SESSION_RAW].check = default_func_check; func_parse_table[SESSION_RAW].func = default_func_parse; diff --git a/src/common/strlib.c b/src/common/strlib.c index 92601f9b1..60ea266db 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -123,7 +123,7 @@ char *trim(char *str, const char *delim) char *strp = strtok(str,delim); char buf[1024]; char *bufp = buf; - malloc_tsetdword(buf,0,sizeof buf); + memset(buf,0,sizeof buf); while(strp) { strcpy(bufp, strp); diff --git a/src/common/timer.c b/src/common/timer.c index 3b4fb1db4..c7be0ab8f 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -153,7 +153,7 @@ static void push_timer_heap(int tid) } else { timer_heap_max += 256; RECREATE(timer_heap, int, timer_heap_max); - malloc_tsetdword(timer_heap + (timer_heap_max - 256), 0, sizeof(int) * 256); + memset(timer_heap + (timer_heap_max - 256), 0, sizeof(int) * 256); } } @@ -223,7 +223,7 @@ static int acquire_timer(void) {// add more timers timer_data_max += 256; RECREATE(timer_data, struct TimerData, timer_data_max); - malloc_tsetdword(timer_data + (timer_data_max - 256), 0, sizeof(struct TimerData) * 256); + memset(timer_data + (timer_data_max - 256), 0, sizeof(struct TimerData) * 256); } } @@ -412,7 +412,7 @@ int do_timer(unsigned int tick) if (free_timer_list_pos >= free_timer_list_max) { free_timer_list_max += 256; RECREATE(free_timer_list,int,free_timer_list_max); - malloc_tsetdword(free_timer_list + (free_timer_list_max - 256), 0, 256 * sizeof(int)); + memset(free_timer_list + (free_timer_list_max - 256), 0, 256 * sizeof(int)); } free_timer_list[free_timer_list_pos++] = i; break; -- cgit v1.2.3-60-g2f50