diff --git a/tgt-pcb/fp.y b/tgt-pcb/fp.y index d300def61..4f3484668 100644 --- a/tgt-pcb/fp.y +++ b/tgt-pcb/fp.y @@ -59,7 +59,7 @@ static fp_element_t cur_element; long integer; char*text; }; - + %token STRING %token INTEGER %token K_ELEMENT diff --git a/vvp/array.cc b/vvp/array.cc index b95b49a58..143ac3a7b 100644 --- a/vvp/array.cc +++ b/vvp/array.cc @@ -77,8 +77,8 @@ vvp_array_t array_find(const char*label) * an array of vvp_vector4_t vectors. * * - Array of real variables -* The valsr member points to a vvp_realarray_t objects that has an -* array of double variables. This is very much line the way the +* The vals member points to a dynamic array objects that has an +* array of double variables. This is very much like the way the * vector4 array works. */ struct __vpiArray : public __vpiHandle { @@ -1074,7 +1074,7 @@ vvp_vector4_t array_get_word(vvp_array_t arr, unsigned address) arr->vals->get_word(address, val); return val; } - + assert(arr->vals4 == 0); assert(arr->vals == 0); assert(arr->nets != 0); @@ -2038,10 +2038,10 @@ void memory_delete(vpiHandle item) // constant_delete(handle)? delete arr->vals4; -// if (arr->valsr) {} +// if (arr->vals) {} // Delete the individual words? // constant_delete(handle)? - delete arr->valsr; + delete arr->vals; if (arr->nets) { for (unsigned idx = 0; idx < arr->array_count; idx += 1) { diff --git a/vvp/main.cc b/vvp/main.cc index 323835fa2..ae2457155 100644 --- a/vvp/main.cc +++ b/vvp/main.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2012 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2013 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -31,6 +31,9 @@ # include # include # include +#ifdef CHECK_WITH_VALGRIND +# include +#endif #if defined(HAVE_SYS_RESOURCE_H) # include @@ -232,6 +235,14 @@ static void final_cleanup() * files are automatically closed. */ load_module_delete(); + +#ifdef CHECK_WITH_VALGRIND + simulator_cb_delete(); + /* This is needed to prevent valgrind from complaining about + * _dlerror_run() having a memory leak. */ +// HERE: Is this portable? Does it break anything? + pthread_exit(NULL); +#endif } unsigned module_cnt = 0; diff --git a/vvp/vpi_callback.cc b/vvp/vpi_callback.cc index 314a3bb79..c2accdd06 100644 --- a/vvp/vpi_callback.cc +++ b/vvp/vpi_callback.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2012 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2013 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -31,6 +31,9 @@ # include "event.h" # include "vvp_net_sig.h" # include "config.h" +#ifdef CHECK_WITH_VALGRIND +#include "vvp_cleanup.h" +#endif # include # include # include @@ -412,6 +415,36 @@ static simulator_callback*EndOfCompile = 0; static simulator_callback*StartOfSimulation = 0; static simulator_callback*EndOfSimulation = 0; +#ifdef CHECK_WITH_VALGRIND +/* This is really only needed if the simulator aborts before starting the + * main event loop. For that reason we can skip the next sim time queue. */ +void simulator_cb_delete(void) +{ + simulator_callback* cur; + + /* Delete all the end of compile callbacks. */ + while (EndOfCompile) { + cur = EndOfCompile; + EndOfCompile = dynamic_cast(cur->next); + delete cur; + } + + /* Delete all the start of simulation callbacks. */ + while (StartOfSimulation) { + cur = StartOfSimulation; + StartOfSimulation = dynamic_cast(cur->next); + delete cur; + } + + /* Delete all the end of simulation callbacks. */ + while (EndOfSimulation) { + cur = EndOfSimulation; + EndOfSimulation = dynamic_cast(cur->next); + delete cur; + } +} +#endif + void vpiEndOfCompile(void) { simulator_callback* cur; diff --git a/vvp/vpi_tasks.cc b/vvp/vpi_tasks.cc index d20951ce6..5060f648f 100644 --- a/vvp/vpi_tasks.cc +++ b/vvp/vpi_tasks.cc @@ -706,14 +706,14 @@ void print_vpi_call_errors() #ifdef CHECK_WITH_VALGRIND static void cleanup_vpi_call_args(unsigned argc, vpiHandle*argv) { -#if 0 if (argc) { - struct __vpiSysTaskCall*obj = new struct __vpiSysTaskCall; + /* Since this is just being used to cleanup the arguments a + * system task definition can be used. */ + struct __vpiSysTaskCall*obj = new systask_def; obj->nargs = argc; obj->args = argv; - vpi_call_delete(&obj->base); + vpi_call_delete(obj); } -#endif } #endif diff --git a/vvp/vvp_cleanup.h b/vvp/vvp_cleanup.h index c5de97967..c0464cf99 100644 --- a/vvp/vvp_cleanup.h +++ b/vvp/vvp_cleanup.h @@ -34,6 +34,7 @@ extern void load_module_delete(void); extern void modpath_delete(void); extern void root_table_delete(void); extern void signal_pool_delete(void); +extern void simulator_cb_delete(void); extern void udp_defns_delete(void); extern void vpi_handle_delete(void); extern void vpi_stack_delete(void);