From 29ef95a9b592d9530395d018079474e21d9dee95 Mon Sep 17 00:00:00 2001 From: "Zephaniah E. Hull" Date: Thu, 29 Jun 2000 05:46:15 +0000 Subject: [PATCH] The end of Z_*!! This after the Z_* stuff hit my profiling list as a top user.. --- include/client.h | 1 - include/sound.h | 2 +- include/zone.h | 8 -- source/cl_slist.c | 39 +++++---- source/cmd.c | 24 +++--- source/cvar.c | 13 ++- source/gl_draw.c | 1 - source/gl_mesh.c | 1 - source/gl_model.c | 1 - source/gl_ngraph.c | 1 - source/gl_part.c | 1 - source/gl_refrag.c | 1 - source/gl_rlight.c | 1 - source/gl_rmisc.c | 1 - source/gl_rsurf.c | 1 - source/gl_screen.c | 1 - source/gl_view.c | 1 - source/keys.c | 5 +- source/menu.c | 8 +- source/quakefs.c | 17 ++-- source/sv_ccmds.c | 2 +- source/vid_ggi.c | 1 - source/vid_svgalib.c | 2 +- source/zone.c | 199 ------------------------------------------- 24 files changed, 54 insertions(+), 278 deletions(-) diff --git a/include/client.h b/include/client.h index dce6da8..88b72f6 100644 --- a/include/client.h +++ b/include/client.h @@ -38,7 +38,6 @@ #include "info.h" #include "mathlib.h" #include "protocol.h" -#include "zone.h" #include "net.h" #include "model.h" #include "sound.h" diff --git a/include/sound.h b/include/sound.h index 98c358b..4b723b4 100644 --- a/include/sound.h +++ b/include/sound.h @@ -31,8 +31,8 @@ #define _SOUND_H #include "mathlib.h" -#include "zone.h" #include "cvar.h" +#include "zone.h" // !!! if this is changed, it much be changed in asm_i386.h too !!! typedef struct diff --git a/include/zone.h b/include/zone.h index 65a53e6..e93256a 100644 --- a/include/zone.h +++ b/include/zone.h @@ -95,14 +95,6 @@ Zone block void Memory_Init (void *buf, int size); -void Z_Free (void *ptr); -void *Z_Malloc (int size); // returns 0 filled memory -void *Z_TagMalloc (int size, int tag); - -void Z_DumpHeap (void); -void Z_CheckHeap (void); -int Z_FreeMemory (void); - void *Hunk_Alloc (int size); // returns 0 filled memory void *Hunk_AllocName (int size, char *name); diff --git a/source/cl_slist.c b/source/cl_slist.c index f1077f0..5ffbf01 100644 --- a/source/cl_slist.c +++ b/source/cl_slist.c @@ -36,7 +36,6 @@ #include "bothdefs.h" #include "console.h" #include "commdef.h" -#include "zone.h" #include "quakefs.h" #include @@ -46,11 +45,11 @@ server_entry_t *SL_Add (server_entry_t *start, char *ip, char *desc) { server_entry_t *p; p = start; if (!start) { //Nothing at beginning of list, create it - start = Z_Malloc(sizeof(server_entry_t)); + start = malloc(sizeof(server_entry_t)); start->prev = 0; start->next = 0; - start->server = Z_Malloc(strlen(ip) + 1); - start->desc = Z_Malloc(strlen(desc) + 1); + start->server = malloc(strlen(ip) + 1); + start->desc = malloc(strlen(desc) + 1); strcpy(start->server,ip); strcpy(start->desc,desc); return (start); @@ -58,10 +57,10 @@ server_entry_t *SL_Add (server_entry_t *start, char *ip, char *desc) { for(p=start;p->next;p=p->next); //Get to end of list - p->next = Z_Malloc(sizeof(server_entry_t)); + p->next = malloc(sizeof(server_entry_t)); p->next->prev = p; - p->next->server = Z_Malloc(strlen(ip) + 1); - p->next->desc = Z_Malloc(strlen(desc) + 1); + p->next->server = malloc(strlen(ip) + 1); + p->next->desc = malloc(strlen(desc) + 1); strcpy(p->next->server,ip); strcpy(p->next->desc,desc); @@ -73,22 +72,22 @@ server_entry_t *SL_Add (server_entry_t *start, char *ip, char *desc) { server_entry_t *SL_Del(server_entry_t *start, server_entry_t *del) { server_entry_t *n; if (del == start) { - Z_Free(start->server); - Z_Free(start->desc); + free(start->server); + free(start->desc); n = start->next; if (n) n->prev = 0; - Z_Free(start); + free(start); return (n); } - Z_Free(del->server); - Z_Free(del->desc); + free(del->server); + free(del->desc); if (del->prev) del->prev->next = del->next; if (del->next) del->next->prev = del->prev; - Z_Free(del); + free(del); return (start); } @@ -96,9 +95,9 @@ server_entry_t *SL_InsB (server_entry_t *start, server_entry_t *place, char *ip, server_entry_t *new; server_entry_t *other; - new = Z_Malloc(sizeof(server_entry_t)); - new->server = Z_Malloc(strlen(ip) + 1); - new->desc = Z_Malloc(strlen(desc) + 1); + new = malloc(sizeof(server_entry_t)); + new->server = malloc(strlen(ip) + 1); + new->desc = malloc(strlen(desc) + 1); strcpy(new->server,ip); strcpy(new->desc,desc); other = place->prev; @@ -160,7 +159,7 @@ server_entry_t *SL_LoadF (FILE *f,server_entry_t *start) { // This could get mes line[i - 1] = '\0'; // Now we can parse it if ((st = gettokstart(line,1,' ')) != NULL) { len = gettoklen(line,1,' '); - addr = Z_Malloc(len + 1); + addr = malloc(len + 1); strncpy(addr,&line[0],len); addr[len] = '\0'; if ((st = gettokstart(line,2,' '))) { @@ -201,9 +200,9 @@ server_entry_t *SL_LoadF (FILE *f,server_entry_t *start) { // This could get mes server_entry_t *n; while (start) { n = start->next; - Z_Free(start->server); - Z_Free(start->desc); - Z_Free(start); + free(start->server); + free(start->desc); + free(start); start = n; } } diff --git a/source/cmd.c b/source/cmd.c index 4f73326..8c0b9ff 100644 --- a/source/cmd.c +++ b/source/cmd.c @@ -33,11 +33,11 @@ #include "cmd.h" #include "cvar.h" #include "sizebuf.h" -#include "zone.h" #include "console.h" #include "qargs.h" #include "quakefs.h" #include "commdef.h" +#include "zone.h" #include #include @@ -139,7 +139,7 @@ void Cbuf_InsertText (char *text) templen = cmd_text.cursize; if (templen) { - temp = Z_Malloc (templen); + temp = malloc (templen); memcpy (temp, cmd_text.data, templen); SZ_Clear (&cmd_text); } @@ -153,7 +153,7 @@ void Cbuf_InsertText (char *text) if (templen) { SZ_Write (&cmd_text, temp, templen); - Z_Free (temp); + free (temp); } } @@ -264,7 +264,7 @@ void Cmd_StuffCmds_f (void) return; // pull out the commands - build = Z_Malloc (s+1); + build = malloc (s+1); build[0] = 0; for (i=0 ; iname)) { - Z_Free (a->value); + free (a->value); break; } } if (!a) { - a = Z_Malloc (sizeof(cmdalias_t)); + a = malloc (sizeof(cmdalias_t)); a->next = cmd_alias; cmd_alias = a; } @@ -468,11 +468,11 @@ void Cmd_UnAlias_f (void) { if (!strcmp(s, a->name)) { - Z_Free (a->value); + free (a->value); prev->next = a->next; if (a == cmd_alias) cmd_alias = a->next; - Z_Free (a); + free (a); return; } prev = a; @@ -557,7 +557,7 @@ void Cmd_TokenizeString (char *text) // clear the args from the last string for (i=0 ; iflags&CVAR_ROM) return; - Z_Free (var->string); // free the old value string + free (var->string); // free the old value string - var->string = Z_Malloc (strlen(value)+1); + var->string = malloc (strlen(value)+1); strcpy (var->string, value); var->value = atof (var->string); @@ -215,9 +214,9 @@ void Cvar_SetROM (cvar_t *var, char *value) if (!var) return; - Z_Free (var->string); // free the old value string + free (var->string); // free the old value string - var->string = Z_Malloc (strlen(value)+1); + var->string = malloc (strlen(value)+1); strcpy (var->string, value); var->value = atof (var->string); @@ -413,7 +412,7 @@ void Cvar_Shutdown (void) { next = var->next; free(var->description); - Z_Free(var->string); + free(var->string); free(var->name); free(var); var = next; @@ -448,7 +447,7 @@ cvar_t *Cvar_Get(char *name, char *string, int cvarflags, char *description) v->next = cvar_vars; cvar_vars = v; v->name = strdup(name); - v->string = Z_Malloc (strlen(string)+1); + v->string = malloc (strlen(string)+1); strcpy (v->string, string); v->flags = cvarflags; v->description = strdup(description); diff --git a/source/gl_draw.c b/source/gl_draw.c index 93398f2..6534eba 100644 --- a/source/gl_draw.c +++ b/source/gl_draw.c @@ -41,7 +41,6 @@ #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" -#include "zone.h" // needed by: client.h, gl_model.h #include "mathlib.h" // needed by: protocol.h, render.h, client.h, // modelgen.h, glmodel.h #include "wad.h" diff --git a/source/gl_mesh.c b/source/gl_mesh.c index 65a490d..b409478 100644 --- a/source/gl_mesh.c +++ b/source/gl_mesh.c @@ -38,7 +38,6 @@ #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" -#include "zone.h" // needed by: client.h, model.h #include "mathlib.h" // needed by: protocol.h, render.h, client.h, // modelgen.h, glmodel.h #include "wad.h" diff --git a/source/gl_model.c b/source/gl_model.c index 8e176c0..43089cc 100644 --- a/source/gl_model.c +++ b/source/gl_model.c @@ -42,7 +42,6 @@ #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" -#include "zone.h" // needed by: client.h, gl_model.h #include "mathlib.h" // needed by: protocol.h, render.h, client.h, // modelgen.h, glmodel.h #include "wad.h" diff --git a/source/gl_ngraph.c b/source/gl_ngraph.c index a88f0a4..55b0e38 100644 --- a/source/gl_ngraph.c +++ b/source/gl_ngraph.c @@ -37,7 +37,6 @@ #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" -#include "zone.h" // needed by: client.h, gl_model.h #include "mathlib.h" // needed by: protocol.h, render.h, client.h, // modelgen.h, glmodel.h #include "wad.h" diff --git a/source/gl_part.c b/source/gl_part.c index dbf7765..8128d19 100644 --- a/source/gl_part.c +++ b/source/gl_part.c @@ -35,7 +35,6 @@ #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" -#include "zone.h" // needed by: client.h, gl_model.h #include "mathlib.h" // needed by: protocol.h, render.h, client.h, // modelgen.h, glmodel.h #include "wad.h" diff --git a/source/gl_refrag.c b/source/gl_refrag.c index 0c101c8..adad505 100644 --- a/source/gl_refrag.c +++ b/source/gl_refrag.c @@ -37,7 +37,6 @@ #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" -#include "zone.h" // needed by: client.h, gl_model.h #include "mathlib.h" // needed by: protocol.h, render.h, client.h, // modelgen.h, glmodel.h #include "wad.h" diff --git a/source/gl_rlight.c b/source/gl_rlight.c index 37edb8c..2ab0b1a 100644 --- a/source/gl_rlight.c +++ b/source/gl_rlight.c @@ -39,7 +39,6 @@ #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" -#include "zone.h" // needed by: client.h, gl_model.h #include "mathlib.h" // needed by: protocol.h, render.h, client.h, // modelgen.h, glmodel.h #include "wad.h" diff --git a/source/gl_rmisc.c b/source/gl_rmisc.c index 40a0781..1a1eac1 100644 --- a/source/gl_rmisc.c +++ b/source/gl_rmisc.c @@ -40,7 +40,6 @@ #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" -#include "zone.h" // needed by: client.h, gl_model.h #include "mathlib.h" // needed by: protocol.h, render.h, client.h, // modelgen.h, glmodel.h #include "wad.h" diff --git a/source/gl_rsurf.c b/source/gl_rsurf.c index 701a36a..c2dd33a 100644 --- a/source/gl_rsurf.c +++ b/source/gl_rsurf.c @@ -40,7 +40,6 @@ #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" -#include "zone.h" // needed by: client.h, gl_model.h #include "mathlib.h" // needed by: protocol.h, render.h, client.h, // modelgen.h, glmodel.h #include "wad.h" diff --git a/source/gl_screen.c b/source/gl_screen.c index e21cdc2..24ca61b 100644 --- a/source/gl_screen.c +++ b/source/gl_screen.c @@ -42,7 +42,6 @@ #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" -#include "zone.h" // needed by: client.h, gl_model.h #include "mathlib.h" // needed by: protocol.h, render.h, client.h, // modelgen.h, glmodel.h #include "wad.h" diff --git a/source/gl_view.c b/source/gl_view.c index 6949e51..1bd96ce 100644 --- a/source/gl_view.c +++ b/source/gl_view.c @@ -37,7 +37,6 @@ #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" -#include "zone.h" // needed by: client.h, gl_model.h #include "mathlib.h" // needed by: protocol.h, render.h, client.h, // modelgen.h, glmodel.h #include "wad.h" diff --git a/source/keys.c b/source/keys.c index f9eb590..99a3857 100644 --- a/source/keys.c +++ b/source/keys.c @@ -44,7 +44,6 @@ #include "keys.h" #include "menu.h" #include "cmd.h" -#include "zone.h" #include "console.h" #include "cvar.h" #include "screen.h" @@ -572,13 +571,13 @@ void Key_SetBinding (int keynum, char *binding) // free old bindings if (keybindings[keynum]) { - Z_Free (keybindings[keynum]); + free (keybindings[keynum]); keybindings[keynum] = NULL; } // allocate memory for new binding l = strlen (binding); - new = Z_Malloc (l+1); + new = malloc (l+1); strcpy (new, binding); new[l] = 0; keybindings[keynum] = new; diff --git a/source/menu.c b/source/menu.c index e3456a8..09f0a45 100644 --- a/source/menu.c +++ b/source/menu.c @@ -1242,10 +1242,10 @@ void M_SEdit_Key (int key) { break; case K_ENTER: c = SL_Get_By_Num(slist,m_multip_cursor); - Z_Free(c->server); - Z_Free(c->desc); - c->server = Z_Malloc(strlen(serv) + 1); - c->desc = Z_Malloc(strlen(desc) + 1); + free(c->server); + free(c->desc); + c->server = malloc(strlen(serv) + 1); + c->desc = malloc(strlen(desc) + 1); strcpy(c->server,serv); strcpy(c->desc,desc); M_Menu_MultiPlayer_f (); diff --git a/source/quakefs.c b/source/quakefs.c index 2d7d765..46e58b6 100644 --- a/source/quakefs.c +++ b/source/quakefs.c @@ -33,7 +33,6 @@ #include "quakefs.h" #include "sys.h" #include "console.h" -#include "zone.h" #include "draw.h" #include "cmd.h" #include "cvar.h" @@ -510,7 +509,7 @@ COM_LoadFile (char *path, int usehunk) else if (usehunk == 2) buf = Hunk_TempAlloc (len+1); else if (usehunk == 0) - buf = Z_Malloc (len+1); + buf = malloc (len+1); else if (usehunk == 3) buf = Cache_Alloc (loadcache, len+1, base); else if (usehunk == 4) @@ -605,7 +604,7 @@ COM_LoadPackFile (char *packfile) if (numpackfiles > MAX_FILES_IN_PACK) Sys_Error ("%s has %i files", packfile, numpackfiles); - newfiles = Z_Malloc (numpackfiles * sizeof(packfile_t)); + newfiles = malloc (numpackfiles * sizeof(packfile_t)); fseek (packhandle, header.dirofs, SEEK_SET); fread (info, 1, header.dirlen, packhandle); @@ -619,7 +618,7 @@ COM_LoadPackFile (char *packfile) newfiles[i].filelen = LittleLong(info[i].filelen); } - pack = Z_Malloc (sizeof (pack_t)); + pack = malloc (sizeof (pack_t)); strcpy (pack->filename, packfile); pack->handle = packhandle; pack->numfiles = numpackfiles; @@ -721,7 +720,7 @@ COM_LoadGameDirectory(char *dir) if (!pak) { Sys_Error(va("Bad pakfile %s!!", pakfiles[i])); } else { - search = Z_Malloc (sizeof(searchpath_t)); + search = malloc (sizeof(searchpath_t)); search->pack = pak; search->next = com_searchpaths; com_searchpaths = search; @@ -761,7 +760,7 @@ COM_AddDirectory (char *dir) // // add the directory to the search path // - search = Z_Malloc (sizeof(searchpath_t)); + search = malloc (sizeof(searchpath_t)); strcpy (search->filename, dir); search->next = com_searchpaths; com_searchpaths = search; @@ -821,11 +820,11 @@ COM_Gamedir (char *dir) if (com_searchpaths->pack) { fclose (com_searchpaths->pack->handle); - Z_Free (com_searchpaths->pack->files); - Z_Free (com_searchpaths->pack); + free (com_searchpaths->pack->files); + free (com_searchpaths->pack); } next = com_searchpaths->next; - Z_Free (com_searchpaths); + free (com_searchpaths); com_searchpaths = next; } diff --git a/source/sv_ccmds.c b/source/sv_ccmds.c index 77ccd46..db58220 100644 --- a/source/sv_ccmds.c +++ b/source/sv_ccmds.c @@ -598,7 +598,7 @@ void SV_Serverinfo_f (void) var = Cvar_FindVar (Cmd_Argv(1)); if (var) { - Z_Free (var->string); // free the old value string + free (var->string); // free the old value string var->string = CopyString (Cmd_Argv(2)); var->value = atof (var->string); } diff --git a/source/vid_ggi.c b/source/vid_ggi.c index 03236f1..a7c24db 100644 --- a/source/vid_ggi.c +++ b/source/vid_ggi.c @@ -46,7 +46,6 @@ #include "bspfile.h" // needed by: glquake.h #include "vid.h" #include "sys.h" -#include "zone.h" // needed by: client.h, gl_model.h #include "mathlib.h" // needed by: protocol.h, render.h, client.h, // modelgen.h, glmodel.h #include "wad.h" diff --git a/source/vid_svgalib.c b/source/vid_svgalib.c index 0704428..b52b006 100644 --- a/source/vid_svgalib.c +++ b/source/vid_svgalib.c @@ -306,7 +306,7 @@ VID_InitModes(void) /* Get complete information on all modes */ num_modes = vga_lastmodenumber()+1; - modes = Z_Malloc(num_modes * sizeof(vga_modeinfo)); + modes = malloc(num_modes * sizeof(vga_modeinfo)); for (i=0 ; iblocklist.next = zone->blocklist.prev = block = - (memblock_t *)( (byte *)zone + sizeof(memzone_t) ); - zone->blocklist.tag = 1; // in use block - zone->blocklist.id = 0; - zone->blocklist.size = 0; - zone->rover = block; - - block->prev = block->next = &zone->blocklist; - block->tag = 0; // free block - block->id = ZONEID; - block->size = size - sizeof(memzone_t); -} - - -/* -======================== -Z_Free -======================== -*/ -void Z_Free (void *ptr) -{ - memblock_t *block, *other; - - if (!ptr) - Sys_Error ("Z_Free: NULL pointer"); - - block = (memblock_t *) ( (byte *)ptr - sizeof(memblock_t)); - if (block->id != ZONEID) - Sys_Error ("Z_Free: freed a pointer without ZONEID"); - if (block->tag == 0) - Sys_Error ("Z_Free: freed a freed pointer"); - - block->tag = 0; // mark as free - - other = block->prev; - if (!other->tag) - { // merge with previous free block - other->size += block->size; - other->next = block->next; - other->next->prev = other; - if (block == mainzone->rover) - mainzone->rover = other; - block = other; - } - - other = block->next; - if (!other->tag) - { // merge the next free block onto the end - block->size += other->size; - block->next = other->next; - block->next->prev = block; - if (other == mainzone->rover) - mainzone->rover = block; - } -} - - -/* -======================== -Z_Malloc -======================== -*/ -void *Z_Malloc (int size) -{ - void *buf; - -Z_CheckHeap (); // DEBUG - buf = Z_TagMalloc (size, 1); - if (!buf) - Sys_Error ("Z_Malloc: failed on allocation of %i bytes",size); - memset (buf, 0, size); - - return buf; -} - -void *Z_TagMalloc (int size, int tag) -{ - int extra; - memblock_t *start, *rover, *new, *base; - - if (!tag) - Sys_Error ("Z_TagMalloc: tried to use a 0 tag"); - -// -// scan through the block list looking for the first free block -// of sufficient size -// - size += sizeof(memblock_t); // account for size of block header - size += 4; // space for memory trash tester - size = (size + 7) & ~7; // align to 8-byte boundary - - base = rover = mainzone->rover; - start = base->prev; - - do - { - if (rover == start) // scaned all the way around the list - return NULL; - if (rover->tag) - base = rover = rover->next; - else - rover = rover->next; - } while (base->tag || base->size < size); - -// -// found a block big enough -// - extra = base->size - size; - if (extra > MINFRAGMENT) - { // there will be a free fragment after the allocated block - new = (memblock_t *) ((byte *)base + size ); - new->size = extra; - new->tag = 0; // free block - new->prev = base; - new->id = ZONEID; - new->next = base->next; - new->next->prev = new; - base->next = new; - base->size = size; - } - - base->tag = tag; // no longer a free block - - mainzone->rover = base->next; // next allocation will start looking here - - base->id = ZONEID; - -// marker for memory trash testing - *(int *)((byte *)base + base->size - 4) = ZONEID; - - return (void *) ((byte *)base + sizeof(memblock_t)); -} - - -/* -======================== -Z_Print -======================== -*/ -void Z_Print (memzone_t *zone) -{ - memblock_t *block; - - Con_Printf ("zone size: %i location: %p\n",mainzone->size,mainzone); - - for (block = zone->blocklist.next ; ; block = block->next) - { - Con_Printf ("block:%p size:%7i tag:%3i\n", - block, block->size, block->tag); - - if (block->next == &zone->blocklist) - break; // all blocks have been hit - if ( (byte *)block + block->size != (byte *)block->next) - Con_Printf ("ERROR: block size does not touch the next block\n"); - if ( block->next->prev != block) - Con_Printf ("ERROR: next block doesn't have proper back link\n"); - if (!block->tag && !block->next->tag) - Con_Printf ("ERROR: two consecutive free blocks\n"); - } -} - - -/* -======================== -Z_CheckHeap -======================== -*/ -void Z_CheckHeap (void) -{ - memblock_t *block; - - for (block = mainzone->blocklist.next ; ; block = block->next) - { - if (block->next == &mainzone->blocklist) - break; // all blocks have been hit - if ( (byte *)block + block->size != (byte *)block->next) - Sys_Error ("Z_CheckHeap: block size does not touch the next block\n"); - if ( block->next->prev != block) - Sys_Error ("Z_CheckHeap: next block doesn't have proper back link\n"); - if (!block->tag && !block->next->tag) - Sys_Error ("Z_CheckHeap: two consecutive free blocks\n"); - } -} - //============================================================================ #define HUNK_SENTINAL 0x1df001ed @@ -953,6 +755,5 @@ void Memory_Init (void *buf, int size) Sys_Error ("Memory_Init: you must specify a size in KB after -zone"); } mainzone = Hunk_AllocName ( zonesize, "zone" ); - Z_ClearZone (mainzone, zonesize); }