mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-31 21:20:33 +00:00
Fix up the definitely lost memory blocks.
qfcc isn't meant to be long running, so I'm not super worried about memory usage, but definitely lost memory blocks when compiling just a single function seems a tad sloppy.
This commit is contained in:
parent
b0c08bf24b
commit
4c65d9f2a4
2 changed files with 53 additions and 26 deletions
|
@ -136,6 +136,10 @@ InitData (void)
|
||||||
codespace_delete (pr.code);
|
codespace_delete (pr.code);
|
||||||
strpool_delete (pr.strings);
|
strpool_delete (pr.strings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pr.linenos)
|
||||||
|
free (pr.linenos);
|
||||||
|
|
||||||
memset (&pr, 0, sizeof (pr));
|
memset (&pr, 0, sizeof (pr));
|
||||||
pr.source_line = 1;
|
pr.source_line = 1;
|
||||||
pr.error_count = 0;
|
pr.error_count = 0;
|
||||||
|
@ -463,8 +467,8 @@ separate_compile (void)
|
||||||
const char **file, *ext;
|
const char **file, *ext;
|
||||||
const char **temp_files;
|
const char **temp_files;
|
||||||
lang_t lang;
|
lang_t lang;
|
||||||
dstring_t *output_file = dstring_newstr ();
|
dstring_t *output_file;
|
||||||
dstring_t *extension = dstring_newstr ();
|
dstring_t *extension;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -479,6 +483,9 @@ separate_compile (void)
|
||||||
i++;
|
i++;
|
||||||
temp_files = calloc (i + 1, sizeof (const char*));
|
temp_files = calloc (i + 1, sizeof (const char*));
|
||||||
|
|
||||||
|
output_file = dstring_newstr ();
|
||||||
|
extension = dstring_newstr ();
|
||||||
|
|
||||||
for (file = source_files, i = 0; *file; file++) {
|
for (file = source_files, i = 0; *file; file++) {
|
||||||
ext = QFS_FileExtension (*file);
|
ext = QFS_FileExtension (*file);
|
||||||
dstring_copysubstr (output_file, *file, ext - *file);
|
dstring_copysubstr (output_file, *file, ext - *file);
|
||||||
|
@ -503,6 +510,8 @@ separate_compile (void)
|
||||||
"not done\n", this_program, *file);
|
"not done\n", this_program, *file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dstring_delete (output_file);
|
||||||
|
dstring_delete (extension);
|
||||||
if (!err && !options.compile) {
|
if (!err && !options.compile) {
|
||||||
InitData ();
|
InitData ();
|
||||||
linker_begin ();
|
linker_begin ();
|
||||||
|
@ -517,14 +526,17 @@ separate_compile (void)
|
||||||
} else {
|
} else {
|
||||||
err = linker_add_lib (*file);
|
err = linker_add_lib (*file);
|
||||||
}
|
}
|
||||||
if (err)
|
if (err) {
|
||||||
|
free (temp_files);
|
||||||
return err;
|
return err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
err = finish_link ();
|
err = finish_link ();
|
||||||
if (!options.save_temps)
|
if (!options.save_temps)
|
||||||
for (file = temp_files; *file; file++)
|
for (file = temp_files; *file; file++)
|
||||||
unlink (*file);
|
unlink (*file);
|
||||||
}
|
}
|
||||||
|
free (temp_files);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -252,6 +252,12 @@ static hashtab_t *pointer_imm_defs;
|
||||||
static hashtab_t *quaternion_imm_defs;
|
static hashtab_t *quaternion_imm_defs;
|
||||||
static hashtab_t *integer_imm_defs;
|
static hashtab_t *integer_imm_defs;
|
||||||
|
|
||||||
|
static void
|
||||||
|
imm_free (void *_imm, void *unused)
|
||||||
|
{
|
||||||
|
free (_imm);
|
||||||
|
}
|
||||||
|
|
||||||
static uintptr_t
|
static uintptr_t
|
||||||
imm_get_hash (const void *_imm, void *_tab)
|
imm_get_hash (const void *_imm, void *_tab)
|
||||||
{
|
{
|
||||||
|
@ -394,6 +400,19 @@ convert_value (ex_value_t *value, type_t *type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static immediate_t *
|
||||||
|
make_def_imm (def_t *def, hashtab_t *tab)
|
||||||
|
{
|
||||||
|
immediate_t *imm;
|
||||||
|
|
||||||
|
imm = calloc (1, sizeof (immediate_t));
|
||||||
|
imm->def = def;
|
||||||
|
|
||||||
|
Hash_AddElement (tab, imm);
|
||||||
|
|
||||||
|
return imm;
|
||||||
|
}
|
||||||
|
|
||||||
def_t *
|
def_t *
|
||||||
emit_value (ex_value_t *value, def_t *def)
|
emit_value (ex_value_t *value, def_t *def)
|
||||||
{
|
{
|
||||||
|
@ -527,19 +546,16 @@ emit_value (ex_value_t *value, def_t *def)
|
||||||
|
|
||||||
memcpy (D_POINTER (void, cn), &val.v, 4 * type_size (type));
|
memcpy (D_POINTER (void, cn), &val.v, 4 * type_size (type));
|
||||||
|
|
||||||
imm = malloc (sizeof (immediate_t));
|
imm = make_def_imm (cn, tab);
|
||||||
imm->def = cn;
|
|
||||||
memcpy (&imm->i, &val.v, sizeof (imm->i));
|
memcpy (&imm->i, &val.v, sizeof (imm->i));
|
||||||
|
|
||||||
Hash_AddElement (tab, imm);
|
|
||||||
|
|
||||||
return cn;
|
return cn;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
clear_immediates (void)
|
clear_immediates (void)
|
||||||
{
|
{
|
||||||
immediate_t *imm;
|
def_t *def;
|
||||||
|
|
||||||
if (value_table) {
|
if (value_table) {
|
||||||
Hash_FlushTable (value_table);
|
Hash_FlushTable (value_table);
|
||||||
|
@ -556,43 +572,42 @@ clear_immediates (void)
|
||||||
value_table = Hash_NewTable (16381, 0, 0, 0);
|
value_table = Hash_NewTable (16381, 0, 0, 0);
|
||||||
Hash_SetHashCompare (value_table, value_get_hash, value_compare);
|
Hash_SetHashCompare (value_table, value_get_hash, value_compare);
|
||||||
|
|
||||||
string_imm_defs = Hash_NewTable (16381, 0, 0, &string_imm_defs);
|
string_imm_defs = Hash_NewTable (16381, 0, imm_free, &string_imm_defs);
|
||||||
Hash_SetHashCompare (string_imm_defs, imm_get_hash, imm_compare);
|
Hash_SetHashCompare (string_imm_defs, imm_get_hash, imm_compare);
|
||||||
|
|
||||||
float_imm_defs = Hash_NewTable (16381, 0, 0, &float_imm_defs);
|
float_imm_defs = Hash_NewTable (16381, 0, imm_free, &float_imm_defs);
|
||||||
Hash_SetHashCompare (float_imm_defs, imm_get_hash, imm_compare);
|
Hash_SetHashCompare (float_imm_defs, imm_get_hash, imm_compare);
|
||||||
|
|
||||||
vector_imm_defs = Hash_NewTable (16381, 0, 0, &vector_imm_defs);
|
vector_imm_defs = Hash_NewTable (16381, 0, imm_free, &vector_imm_defs);
|
||||||
Hash_SetHashCompare (vector_imm_defs, imm_get_hash, imm_compare);
|
Hash_SetHashCompare (vector_imm_defs, imm_get_hash, imm_compare);
|
||||||
|
|
||||||
entity_imm_defs = Hash_NewTable (16381, 0, 0, &entity_imm_defs);
|
entity_imm_defs = Hash_NewTable (16381, 0, imm_free, &entity_imm_defs);
|
||||||
Hash_SetHashCompare (entity_imm_defs, imm_get_hash, imm_compare);
|
Hash_SetHashCompare (entity_imm_defs, imm_get_hash, imm_compare);
|
||||||
|
|
||||||
field_imm_defs = Hash_NewTable (16381, 0, 0, &field_imm_defs);
|
field_imm_defs = Hash_NewTable (16381, 0, imm_free, &field_imm_defs);
|
||||||
Hash_SetHashCompare (field_imm_defs, imm_get_hash, imm_compare);
|
Hash_SetHashCompare (field_imm_defs, imm_get_hash, imm_compare);
|
||||||
|
|
||||||
func_imm_defs = Hash_NewTable (16381, 0, 0, &func_imm_defs);
|
func_imm_defs = Hash_NewTable (16381, 0, imm_free, &func_imm_defs);
|
||||||
Hash_SetHashCompare (func_imm_defs, imm_get_hash, imm_compare);
|
Hash_SetHashCompare (func_imm_defs, imm_get_hash, imm_compare);
|
||||||
|
|
||||||
pointer_imm_defs = Hash_NewTable (16381, 0, 0, &pointer_imm_defs);
|
pointer_imm_defs =
|
||||||
|
Hash_NewTable (16381, 0, imm_free, &pointer_imm_defs);
|
||||||
Hash_SetHashCompare (pointer_imm_defs, imm_get_hash, imm_compare);
|
Hash_SetHashCompare (pointer_imm_defs, imm_get_hash, imm_compare);
|
||||||
|
|
||||||
quaternion_imm_defs =
|
quaternion_imm_defs =
|
||||||
Hash_NewTable (16381, 0, 0, &quaternion_imm_defs);
|
Hash_NewTable (16381, 0, imm_free, &quaternion_imm_defs);
|
||||||
Hash_SetHashCompare (quaternion_imm_defs, imm_get_hash, imm_compare);
|
Hash_SetHashCompare (quaternion_imm_defs, imm_get_hash, imm_compare);
|
||||||
|
|
||||||
integer_imm_defs = Hash_NewTable (16381, 0, 0, &integer_imm_defs);
|
integer_imm_defs =
|
||||||
|
Hash_NewTable (16381, 0, imm_free, &integer_imm_defs);
|
||||||
Hash_SetHashCompare (integer_imm_defs, imm_get_hash, imm_compare);
|
Hash_SetHashCompare (integer_imm_defs, imm_get_hash, imm_compare);
|
||||||
}
|
}
|
||||||
|
|
||||||
imm = calloc (1, sizeof (immediate_t));
|
def = make_symbol (".zero", &type_zero, 0, st_extern)->s.def;
|
||||||
imm->def = make_symbol (".zero", &type_zero, 0, st_extern)->s.def;
|
|
||||||
imm->def->initialized = imm->def->constant = 1;
|
|
||||||
imm->def->nosave = 1;
|
|
||||||
|
|
||||||
Hash_AddElement (string_imm_defs, imm);
|
make_def_imm (def, string_imm_defs);
|
||||||
Hash_AddElement (float_imm_defs, imm);
|
make_def_imm (def, float_imm_defs);
|
||||||
Hash_AddElement (entity_imm_defs, imm);
|
make_def_imm (def, entity_imm_defs);
|
||||||
Hash_AddElement (pointer_imm_defs, imm);
|
make_def_imm (def, pointer_imm_defs);
|
||||||
Hash_AddElement (integer_imm_defs, imm);
|
make_def_imm (def, integer_imm_defs);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue