From 0739c739a67bf0be9eaa8b0a0847dfe59aeed34f Mon Sep 17 00:00:00 2001 From: TimeServ Date: Sun, 11 May 2008 12:55:53 +0000 Subject: [PATCH] BZ_* no longer clears, qclib no longer assumes memalloc clears git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2952 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/common/zone.c | 2 +- engine/qclib/initlib.c | 5 +-- engine/qclib/pr_edict.c | 70 ++++++++++++++++------------------------- engine/qclib/pr_multi.c | 2 +- 4 files changed, 32 insertions(+), 47 deletions(-) diff --git a/engine/common/zone.c b/engine/common/zone.c index a16f965e..29a42ba6 100644 --- a/engine/common/zone.c +++ b/engine/common/zone.c @@ -278,7 +278,7 @@ void *Z_Realloc(void *data, int newsize) void *BZF_Malloc(int size) //BZ_Malloc but allowed to fail - like straight malloc. { - return calloc(size, 1); // TODO: this should be malloc but some code still assumes this is an alias to Z_Malloc + return malloc(size, 1); } void *BZ_Malloc(int size) //Doesn't clear. The expectation is a large file, rather than sensative data structures. diff --git a/engine/qclib/initlib.c b/engine/qclib/initlib.c index 89a1a181..9dd5e4fa 100644 --- a/engine/qclib/initlib.c +++ b/engine/qclib/initlib.c @@ -10,7 +10,7 @@ void *PRHunkAlloc(progfuncs_t *progfuncs, int ammount) { prmemb_t *mem; ammount = sizeof(prmemb_t)+((ammount + 3)&~3); - mem = memalloc(ammount); + mem = memalloc(ammount); memset(mem, 0, ammount); mem->prev = memb; if (!memb) @@ -380,8 +380,9 @@ string_t PR_StringToProgs (progfuncs_t *progfuncs, char *str) } prinst->maxallocedstrings += 1024; - ntable = memalloc(sizeof(char*) * prinst->maxallocedstrings); + ntable = memalloc(sizeof(char*) * prinst->maxallocedstrings); memcpy(ntable, prinst->allocedstrings, sizeof(char*) * prinst->numallocedstrings); + memset(ntable + prinst->numallocedstrings, 0, sizeof(char*) * prinst->maxallocedstrings - prinst->numallocedstrings); prinst->numallocedstrings = prinst->maxallocedstrings; if (prinst->allocedstrings) memfree(prinst->allocedstrings); diff --git a/engine/qclib/pr_edict.c b/engine/qclib/pr_edict.c index eda18576..83562938 100644 --- a/engine/qclib/pr_edict.c +++ b/engine/qclib/pr_edict.c @@ -71,6 +71,19 @@ void ED_ClearEdict (progfuncs_t *progfuncs, edictrun_t *e) e->entnum = num; } +edictrun_t *ED_AllocIntoTable (progfuncs_t *progfuncs, int num) +{ + edictrun_t *e; + + prinst->edicttable[num] = *(struct edict_s **)&e = (void*)memalloc(externs->edictsize); + memset(e, 0, externs->edictsize); + e->fields = PRAddressableAlloc(progfuncs, fields_size); + e->entnum = num; + ED_ClearEdict(progfuncs, e); + + return e; +} + /* ================= ED_Alloc @@ -95,13 +108,9 @@ struct edict_s *ED_Alloc (progfuncs_t *progfuncs) if (!e || (e->isfree && ( e->freetime < 2 || *externs->gametime - e->freetime > 0.5 ) )) { if (!e) - { - prinst->edicttable[i] = *(struct edict_s **)&e = (void*)memalloc(externs->edictsize); - e->fields = PRAddressableAlloc(progfuncs, fields_size); - e->entnum = i; - } - - ED_ClearEdict (progfuncs, e); + e = ED_AllocIntoTable(progfuncs, i); + else + ED_ClearEdict (progfuncs, e); if (externs->entspawn) externs->entspawn((struct edict_s *) e); @@ -119,13 +128,9 @@ struct edict_s *ED_Alloc (progfuncs_t *progfuncs) if (!e || (e->isfree)) { if (!e) - { - prinst->edicttable[i] = *(struct edict_s **)&e = (void*)memalloc(externs->edictsize); - e->fields = PRAddressableAlloc(progfuncs, fields_size); - e->entnum = i; - } - - ED_ClearEdict (progfuncs, e); + e = ED_AllocIntoTable(progfuncs, i); + else + ED_ClearEdict (progfuncs, e); if (externs->entspawn) externs->entspawn((struct edict_s *) e); @@ -152,13 +157,9 @@ struct edict_s *ED_Alloc (progfuncs_t *progfuncs) e = (edictrun_t*)EDICT_NUM(progfuncs, i); if (!e) - { - prinst->edicttable[i] = *(struct edict_s **)&e = (void*)memalloc(externs->edictsize); - e->fields = PRAddressableAlloc(progfuncs, fields_size); - e->entnum = i; - } - - ED_ClearEdict (progfuncs, e); + e = ED_AllocIntoTable(progfuncs, i); + else + ED_ClearEdict (progfuncs, e); if (externs->entspawn) externs->entspawn((struct edict_s *) e); @@ -1676,9 +1677,7 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags) if (!ed) { - prinst->edicttable[num] = *(struct edict_s **)&ed = (void*)memalloc(externs->edictsize); - ed->fields = PRAddressableAlloc(progfuncs, fields_size); - ed->entnum = num; + ed = ED_AllocIntoTable(progfuncs, num); ed->isfree = true; } } @@ -1698,10 +1697,7 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags) if (!ed) { Sys_Error("Edict was not allocated\n"); - prinst->edicttable[num] = *(struct edict_s **)&ed = (void*)memalloc(externs->edictsize); - ed->fields = PRAddressableAlloc(progfuncs, fields_size); - ED_ClearEdict(progfuncs, ed); - ed->entnum = num; + ed = ED_AllocIntoTable(progfuncs, num); } } ed->isfree = false; @@ -1792,10 +1788,7 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags) if (!ed) { - prinst->edicttable[num] = *(struct edict_s **)&ed = (void*)memalloc(externs->edictsize); - ed->fields = PRAddressableAlloc(progfuncs, fields_size); - ED_ClearEdict(progfuncs, ed); - ed->entnum = num; + ed = ED_AllocIntoTable(progfuncs, num); ed->isfree = true; } } @@ -1951,13 +1944,7 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags) { ed = (edictrun_t *)EDICT_NUM(progfuncs, numents); if (!ed) - { - prinst->edicttable[numents] = *(struct edict_s **)&ed = (void*)memalloc(externs->edictsize); - ed->fields = PRAddressableAlloc(progfuncs, fields_size); - ED_ClearEdict(progfuncs, ed); - ed->entnum = numents; - ed->isfree = true; - } + ed = ED_AllocIntoTable(progfuncs, numents); sv_num_edicts = numents; ed->isfree = false; @@ -1978,10 +1965,7 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags) if (!ed) { - prinst->edicttable[num] = *(struct edict_s **)&ed = (void*)memalloc(externs->edictsize); - ed->fields = PRAddressableAlloc(progfuncs, fields_size); - ED_ClearEdict(progfuncs, ed); - ed->entnum = num; + ed = ED_AllocIntoTable(progfuncs, num); ed->isfree = true; } } diff --git a/engine/qclib/pr_multi.c b/engine/qclib/pr_multi.c index 88d04a66..f4b18143 100644 --- a/engine/qclib/pr_multi.c +++ b/engine/qclib/pr_multi.c @@ -173,7 +173,7 @@ void QC_InitShares(progfuncs_t *progfuncs) if (!field) //don't make it so we will just need to remalloc everything { maxfields = 64; - field = memalloc(sizeof(fdef_t) * maxfields); + field = memalloc(sizeof(fdef_t) * maxfields); } numfields = 0;