diff --git a/source/cmd.c b/source/cmd.c index 9eec6e2..2c27d98 100644 --- a/source/cmd.c +++ b/source/cmd.c @@ -693,7 +693,7 @@ void Cmd_AddCommand(const char *cmd_name, xcommand_t function) } } - cmd = (cmd_function_t *) Hunk_Alloc(sizeof(cmd_function_t)); + cmd = Hunk_AllocName(sizeof(cmd_function_t), "cmd_functions"); cmd->name = cmd_name; cmd->function = function; diff --git a/source/console.c b/source/console.c index 4b5324f..c2be5a4 100644 --- a/source/console.c +++ b/source/console.c @@ -274,7 +274,7 @@ void Con_CheckResize(void) numchars = con_linewidth; mark = Hunk_LowMark(); //johnfitz - tbuf = (char *) Hunk_Alloc(con_buffersize); //johnfitz + tbuf = Hunk_AllocName(con_buffersize, __func__); //johnfitz Q_memcpy(tbuf, con_text, con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE Q_memset(con_text, ' ', con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE @@ -314,7 +314,7 @@ void Con_Init(void) con_buffersize = CON_TEXTSIZE; //johnfitz - con_text = (char *) Hunk_AllocName(con_buffersize, "context"); //johnfitz -- con_buffersize replaces CON_TEXTSIZE + con_text = (char *)Hunk_AllocName(con_buffersize, "con_text"); //johnfitz -- con_buffersize replaces CON_TEXTSIZE Q_memset(con_text, ' ', con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE con_linewidth = -1; @@ -771,7 +771,7 @@ void AddToTabList(const char *name, const char *type) *i_bash = 0; } - t = (tab_t *) Hunk_Alloc(sizeof(tab_t)); + t = Hunk_AllocName(sizeof(tab_t), __func__); t->name = name; t->type = type; diff --git a/source/gl_draw.c b/source/gl_draw.c index 05437da..4226f6d 100644 --- a/source/gl_draw.c +++ b/source/gl_draw.c @@ -326,7 +326,7 @@ qpic_t *Draw_MakePic(const char *name, int32_t width, int32_t height, byte *data qpic_t *pic; glpic_t gl; - pic = (qpic_t *) Hunk_Alloc(sizeof(qpic_t) - 4 + sizeof(glpic_t)); + pic = Hunk_AllocName(sizeof(qpic_t) - 4 + sizeof(glpic_t), __func__); pic->width = width; pic->height = height; diff --git a/source/gl_mesh.c b/source/gl_mesh.c index 5bcb882..34969ac 100644 --- a/source/gl_mesh.c +++ b/source/gl_mesh.c @@ -320,7 +320,7 @@ void GL_MakeAliasModelDisplayLists(qmodel_t *m, aliashdr_t *hdr) paliashdr->poseverts = numorder; - cmds = (int32_t *) Hunk_Alloc(numcommands * 4); + cmds = Hunk_AllocName(numcommands * 4, __func__); paliashdr->commands = (byte *)cmds - (byte *)paliashdr; //johnfitz -- precompute texcoords for padded skins @@ -344,7 +344,7 @@ void GL_MakeAliasModelDisplayLists(qmodel_t *m, aliashdr_t *hdr) } //johnfitz - verts = (trivertx_t *) Hunk_Alloc(paliashdr->numposes * paliashdr->poseverts * sizeof(trivertx_t)); + verts = Hunk_AllocName(paliashdr->numposes * paliashdr->poseverts * sizeof(trivertx_t), __func__); paliashdr->posedata = (byte *)verts - (byte *)paliashdr; for(i = 0 ; i < paliashdr->numposes ; i++) for(j = 0 ; j < numorder ; j++) @@ -379,7 +379,7 @@ void GL_MakeAliasModelDisplayLists_VBO(void) return; // first, copy the verts onto the hunk - verts = (trivertx_t *) Hunk_Alloc(paliashdr->numposes * paliashdr->numverts * sizeof(trivertx_t)); + verts = Hunk_AllocName(paliashdr->numposes * paliashdr->numverts * sizeof(trivertx_t), __func__); paliashdr->vertexes = (byte *)verts - (byte *)paliashdr; for(i = 0 ; i < paliashdr->numposes ; i++) for(j = 0 ; j < paliashdr->numverts ; j++) @@ -387,10 +387,10 @@ void GL_MakeAliasModelDisplayLists_VBO(void) // there can never be more than this number of verts and we just put them all on the hunk maxverts_vbo = pheader->numtris * 3; - desc = (aliasmesh_t *) Hunk_Alloc(sizeof(aliasmesh_t) * maxverts_vbo); + desc = Hunk_AllocName(sizeof(aliasmesh_t) * maxverts_vbo, __func__); // there will always be this number of indexes - indexes = (uint16_t *) Hunk_Alloc(sizeof(uint16_t) * maxverts_vbo); + indexes = Hunk_AllocName(sizeof(uint16_t) * maxverts_vbo, __func__); pheader->indexes = (intptr_t) indexes - (intptr_t) pheader; pheader->meshdesc = (intptr_t) desc - (intptr_t) pheader; diff --git a/source/gl_model.c b/source/gl_model.c index 1160be9..93fb81b 100644 --- a/source/gl_model.c +++ b/source/gl_model.c @@ -529,7 +529,7 @@ void Mod_LoadTextures(lump_t *l) } //now create the warpimage, using dummy data from the hunk to create the initial image - Hunk_Alloc(gl_warpimagesize * gl_warpimagesize * 4); //make sure hunk is big enough so we don't reach an illegal address + Hunk_AllocName(gl_warpimagesize * gl_warpimagesize * 4, "temporary check"); //make sure hunk is big enough so we don't reach an illegal address Hunk_FreeToLowMark(mark); q_snprintf(texturename, sizeof(texturename), "%s_warp", texturename); tx->warpimage = TexMgr_LoadImage(loadmodel, texturename, gl_warpimagesize, @@ -1083,7 +1083,7 @@ void Mod_PolyForUnlitSurface(msurface_t *fa) } //create the poly - poly = (glpoly_t *) Hunk_Alloc(sizeof(glpoly_t) + (numverts - 4) * VERTEXSIZE * sizeof(float)); + poly = Hunk_AllocName(sizeof(glpoly_t) + (numverts - 4) * VERTEXSIZE * sizeof(float), __func__); poly->next = NULL; fa->polys = poly; poly->numverts = numverts; diff --git a/source/gl_refrag.c b/source/gl_refrag.c index 0c01015..3a7caac 100644 --- a/source/gl_refrag.c +++ b/source/gl_refrag.c @@ -56,7 +56,7 @@ entity_t *r_addent; // based on RMQEngine static efrag_t *R_GetEfrag(void) { - // we could just Hunk_Alloc a single efrag_t and return it, but since + // we could just allocate a single efrag_t and return it, but since // the struct is so small (2 pointers) allocate groups of them // to avoid wasting too much space on the hunk allocation headers. diff --git a/source/gl_sky.c b/source/gl_sky.c index 96d8d41..41e79a9 100644 --- a/source/gl_sky.c +++ b/source/gl_sky.c @@ -98,8 +98,8 @@ void Sky_LoadTexture(texture_t *mt) char texturename[64]; int32_t i, j, p, r, g, b, count; byte *src; - static byte front_data[128 * 128]; //FIXME: Hunk_Alloc - static byte back_data[128 * 128]; //FIXME: Hunk_Alloc + static byte front_data[128 * 128]; //FIXME: dynamically allocate + static byte back_data[128 * 128]; //FIXME: dynamically allocate unsigned *rgba; src = (byte *)mt + mt->offsets[0]; @@ -609,7 +609,7 @@ void Sky_ProcessEntities(void) { //copy the polygon and translate manually, since Sky_ProcessPoly needs it to be in world space mark = Hunk_LowMark(); - p = (glpoly_t *) Hunk_Alloc(sizeof(*s->polys)); //FIXME: don't allocate for each poly + p = Hunk_AllocName(sizeof(*s->polys), __func__); //FIXME: don't allocate for each poly p->numverts = s->polys->numverts; for(k = 0; k < p->numverts; k++) { @@ -908,7 +908,7 @@ void Sky_DrawFace(int32_t axis) Sky_SetBoxVert(1.0, -1.0, axis, verts[3]); start = Hunk_LowMark(); - p = (glpoly_t *) Hunk_Alloc(sizeof(glpoly_t)); + p = Hunk_AllocName(sizeof(glpoly_t), __func__); VectorSubtract(verts[2], verts[3], vup); VectorSubtract(verts[2], verts[1], vright); diff --git a/source/gl_texmgr.c b/source/gl_texmgr.c index f482ed0..14ffcf5 100644 --- a/source/gl_texmgr.c +++ b/source/gl_texmgr.c @@ -474,7 +474,7 @@ void TexMgr_LoadPalette(void) Sys_Error("Couldn't load gfx/palette.lmp"); mark = Hunk_LowMark(); - pal = (byte *) Hunk_Alloc(768); + pal = Hunk_AllocName(768, __func__); fread(pal, 1, 768, f); fclose(f); @@ -576,7 +576,7 @@ void TexMgr_RecalcWarpImageSize(void) // resize the textures in opengl mark = Hunk_LowMark(); - dummy = (byte *) Hunk_Alloc(gl_warpimagesize * gl_warpimagesize * 4); + dummy = Hunk_AllocName(gl_warpimagesize * gl_warpimagesize * 4, __func__); for(glt = active_gltextures; glt; glt = glt->next) { @@ -760,7 +760,7 @@ static unsigned *TexMgr_ResampleTexture(unsigned *in, int32_t inwidth, int32_t i outwidth = TexMgr_Pad(inwidth); outheight = TexMgr_Pad(inheight); - out = (unsigned *) Hunk_Alloc(outwidth * outheight * 4); + out = Hunk_AllocName(outwidth * outheight * 4, __func__); xfrac = ((inwidth - 1) << 16) / (outwidth - 1); yfrac = ((inheight - 1) << 16) / (outheight - 1); @@ -998,7 +998,7 @@ static unsigned *TexMgr_8to32(byte *in, int32_t pixels, uint32_t *usepal) int32_t i; unsigned *out, *data; - out = data = (unsigned *) Hunk_Alloc(pixels * 4); + out = data = Hunk_AllocName(pixels * 4, __func__); for(i = 0; i < pixels; i++) *out++ = usepal[*in++]; @@ -1021,7 +1021,7 @@ static byte *TexMgr_PadImageW(byte *in, int32_t width, int32_t height, byte padb outwidth = TexMgr_Pad(width); - out = data = (byte *) Hunk_Alloc(outwidth * height); + out = data = Hunk_AllocName(outwidth * height, __func__); for(i = 0; i < height; i++) { @@ -1050,7 +1050,7 @@ static byte *TexMgr_PadImageH(byte *in, int32_t width, int32_t height, byte padb srcpix = width * height; dstpix = width * TexMgr_Pad(height); - out = data = (byte *) Hunk_Alloc(dstpix); + out = data = Hunk_AllocName(dstpix, __func__); for(i = 0; i < srcpix; i++) *out++ = *in++; @@ -1349,7 +1349,7 @@ void TexMgr_ReloadImage(gltexture_t *glt, int32_t shirt, int32_t pants) size *= 4; else if(glt->source_format == SRC_LIGHTMAP) size *= lightmap_bytes; - data = (byte *) Hunk_Alloc(size); + data = Hunk_AllocName(size, __func__); fread(data, 1, size, f); fclose(f); } @@ -1415,7 +1415,7 @@ invalid: //translate texture size = glt->width * glt->height; - dst = translated = (byte *) Hunk_Alloc(size); + dst = translated = Hunk_AllocName(size, __func__); src = data; for(i = 0; i < size; i++) diff --git a/source/gl_warp.c b/source/gl_warp.c index 1f4c40c..f0b31f4 100644 --- a/source/gl_warp.c +++ b/source/gl_warp.c @@ -138,7 +138,7 @@ void SubdividePolygon(int32_t numverts, float *verts) return; } - poly = (glpoly_t *) Hunk_Alloc(sizeof(glpoly_t) + (numverts - 4) * VERTEXSIZE * sizeof(float)); + poly = Hunk_AllocName(sizeof(glpoly_t) + (numverts - 4) * VERTEXSIZE * sizeof(float), __func__); poly->next = warpface->polys->next; warpface->polys->next = poly; poly->numverts = numverts; diff --git a/source/image.c b/source/image.c index 5d99f32..f0024ba 100644 --- a/source/image.c +++ b/source/image.c @@ -214,7 +214,7 @@ byte *Image_LoadTGA(FILE *fin, int32_t *width, int32_t *height) numPixels = columns * rows; upside_down = !(targa_header.attributes & 0x20); //johnfitz -- fix for upside-down targas - targa_rgba = (byte *) Hunk_Alloc(numPixels * 4); + targa_rgba = Hunk_AllocName(numPixels * 4, __func__); if(targa_header.id_length != 0) fseek(fin, targa_header.id_length, SEEK_CUR); // skip TARGA image comment @@ -424,7 +424,7 @@ byte *Image_LoadPCX(FILE *f, int32_t *width, int32_t *height) w = pcx.xmax - pcx.xmin + 1; h = pcx.ymax - pcx.ymin + 1; - data = (byte *) Hunk_Alloc((w * h + 1) * 4); //+1 to allow reading padding byte on last line + data = Hunk_AllocName((w * h + 1) * 4, __func__); //+1 to allow reading padding byte on last line //load palette fseek(f, start + com_filesize - 768, SEEK_SET); diff --git a/source/r_brush.c b/source/r_brush.c index 11f0726..297884c 100644 --- a/source/r_brush.c +++ b/source/r_brush.c @@ -444,7 +444,7 @@ void BuildSurfaceDisplayList(msurface_t *fa) // // draw texture // - poly = (glpoly_t *) Hunk_Alloc(sizeof(glpoly_t) + (lnumverts - 4) * VERTEXSIZE * sizeof(float)); + poly = Hunk_AllocName(sizeof(glpoly_t) + (lnumverts - 4) * VERTEXSIZE * sizeof(float), __func__); poly->next = fa->polys; fa->polys = poly; poly->numverts = lnumverts; diff --git a/source/sv_phys.c b/source/sv_phys.c index 803f451..96d1236 100644 --- a/source/sv_phys.c +++ b/source/sv_phys.c @@ -482,8 +482,8 @@ void SV_PushMove(edict_t *pusher, float movetime) //johnfitz -- dynamically allocate mark = Hunk_LowMark(); - moved_edict = (edict_t **) Hunk_Alloc(sv.num_edicts * sizeof(edict_t *)); - moved_from = (vec3_t *) Hunk_Alloc(sv.num_edicts * sizeof(vec3_t)); + moved_edict = Hunk_AllocName(sv.num_edicts * sizeof(edict_t *), "moved_edict"); + moved_from = Hunk_AllocName(sv.num_edicts * sizeof(vec3_t), "moved_from"); //johnfitz // see if any solid entities are inside the final position diff --git a/source/world.c b/source/world.c index 4102075..2b74fee 100644 --- a/source/world.c +++ b/source/world.c @@ -343,7 +343,7 @@ void SV_TouchLinks(edict_t *ent) int32_t mark; mark = Hunk_LowMark(); - list = (edict_t **) Hunk_Alloc(sv.num_edicts * sizeof(edict_t *)); + list = Hunk_AllocName(sv.num_edicts * sizeof(edict_t *), __func__); listcount = 0; SV_AreaTriggerEdicts(ent, sv_areanodes, list, &listcount, sv.num_edicts); diff --git a/source/zone.c b/source/zone.c index d8760c5..32ee7d7 100644 --- a/source/zone.c +++ b/source/zone.c @@ -438,12 +438,12 @@ void *Hunk_AllocName(int32_t size, const char *name) #endif if(size < 0) - Sys_Error("Hunk_Alloc: bad size: %" PRIi32 "", size); + Sys_Error("Hunk_AllocName: bad size: %" PRIi32 "", size); size = sizeof(hunk_t) + ((size + 15) & ~15); if(hunk_size - hunk_low_used - hunk_high_used < size) - Sys_Error("Hunk_Alloc: failed on %" PRIi32 " bytes", size); + Sys_Error("Hunk_AllocName: failed on %" PRIi32 " bytes", size); h = (hunk_t *)(hunk_base + hunk_low_used); hunk_low_used += size; @@ -459,16 +459,6 @@ void *Hunk_AllocName(int32_t size, const char *name) return h + 1; } -/* -=================== -Hunk_Alloc -=================== -*/ -void *Hunk_Alloc(int32_t size) -{ - return Hunk_AllocName(size, "unknown"); -} - int32_t Hunk_LowMark(void) { return hunk_low_used; diff --git a/source/zone.h b/source/zone.h index 8f0253e..ebd5838 100644 --- a/source/zone.h +++ b/source/zone.h @@ -96,7 +96,6 @@ void *Z_Malloc(int32_t size); // returns 0 filled memory void *Z_Realloc(void *ptr, int32_t size); char *Z_Strdup(const char *s); -void *Hunk_Alloc(int32_t size); // returns 0 filled memory void *Hunk_AllocName(int32_t size, const char *name); void *Hunk_HighAllocName(int32_t size, const char *name); void *Hunk_Strdup(void const *s, char const *name); @@ -111,6 +110,7 @@ void Hunk_FreeToHighMark(int32_t mark); void *Hunk_TempAlloc(int32_t size); void Hunk_Check(void); +void Hunk_Print(bool all); typedef struct cache_user_s {