More valgrind cleanup (local nets).

This patch adds code to cleanup local nets and changes a few of
memory cleanup messages.
This commit is contained in:
Cary R 2009-10-19 19:53:46 -07:00 committed by Stephen Williams
parent d098db0a06
commit c7d05eefb4
4 changed files with 32 additions and 4 deletions

View File

@ -953,8 +953,8 @@ void signal_pool_delete()
{
if (RUNNING_ON_VALGRIND && (signal_count != signal_dels)) {
fflush(NULL);
VALGRIND_PRINTF("Error: vvp missed deleting %lu signal(s).",
signal_count - signal_dels);
VALGRIND_PRINTF("Error: vvp missed deleting %ld of %lu signal(s).",
(long) signal_count - signal_dels, signal_count);
}
for (unsigned idx = 0; idx < signal_pool_count; idx += 1) {

View File

@ -55,4 +55,6 @@ extern void exec_ufunc_delete(vvp_code_t euf_code);
extern void vthreads_delete(vthread_t base);
extern void vvp_net_delete(vvp_net_t *item);
extern void pool_local_net(vvp_net_t *net);
#endif

View File

@ -84,6 +84,16 @@ void* vvp_net_t::operator new (size_t size)
#ifdef CHECK_WITH_VALGRIND
static map<vvp_net_t*, bool> vvp_net_map;
static map<sfunc_core*, bool> sfunc_map;
static vvp_net_t **local_net_pool = 0;
static unsigned local_net_pool_count = 0;
void pool_local_net(vvp_net_t*net)
{
local_net_pool_count += 1;
local_net_pool = (vvp_net_t **) realloc(local_net_pool,
local_net_pool_count*sizeof(vvp_net_t **));
local_net_pool[local_net_pool_count-1] = net;
}
void vvp_net_delete(vvp_net_t *item)
{
@ -97,21 +107,31 @@ void vvp_net_pool_delete()
{
unsigned long vvp_nets_del = 0;
for (unsigned idx = 0; idx < local_net_pool_count; idx += 1) {
vvp_net_delete(local_net_pool[idx]);
}
free(local_net_pool);
local_net_pool = 0;
local_net_pool_count = 0;
map<vvp_net_t*, bool>::iterator iter;
for (iter = vvp_net_map.begin(); iter != vvp_net_map.end(); iter++) {
vvp_nets_del += 1;
VALGRIND_MEMPOOL_FREE(iter->first->pool, iter->first);
}
vvp_net_map.clear();
map<sfunc_core*, bool>::iterator siter;
for (siter = sfunc_map.begin(); siter != sfunc_map.end(); siter++) {
delete siter->first;
}
sfunc_map.clear();
if (RUNNING_ON_VALGRIND && (vvp_nets_del != count_vvp_nets)) {
fflush(NULL);
VALGRIND_PRINTF("Error: vvp missed deleting %lu net(s).",
count_vvp_nets - vvp_nets_del);
VALGRIND_PRINTF("Error: vvp missed deleting %ld of %lu net(s).",
(long) count_vvp_nets - vvp_nets_del,
count_vvp_nets);
}
for (unsigned idx = 0; idx < vvp_net_pool_count; idx += 1) {

View File

@ -23,6 +23,9 @@
# include "vvp_net_sig.h"
# include "logic.h"
# include "schedule.h"
#ifdef CHECK_WITH_VALGRIND
# include "vvp_cleanup.h"
#endif
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
@ -261,6 +264,9 @@ static void __compile_net2(vvp_net_t*node, vvp_array_t array,
/* This attaches the label to the vpiHandle */
compile_vpi_symbol(my_label, obj);
}
#ifdef CHECK_WITH_VALGRIND
else pool_local_net(node);
#endif
// REMOVE ME! Giving the net a label is a legacy of the times
// when the .net was a functor of its own. In the long run, we