diff --git a/vvp/stop.cc b/vvp/stop.cc index af214d643..737fbedcf 100644 --- a/vvp/stop.cc +++ b/vvp/stop.cc @@ -81,8 +81,8 @@ static void cmd_call(unsigned argc, char*argv[]) vpip_make_root_iterator(table, ntable); } else { - table = stop_current_scope->intern; - ntable = stop_current_scope->nintern; + table = &stop_current_scope->intern[0]; + ntable = stop_current_scope->intern.size(); } /* This is an array of vpiHandles, for passing to the created @@ -221,8 +221,8 @@ static void cmd_list(unsigned, char*[]) vpip_make_root_iterator(table, ntable); } else { - table = stop_current_scope->intern; - ntable = stop_current_scope->nintern; + table = &stop_current_scope->intern[0]; + ntable = stop_current_scope->intern.size(); } printf("%u items in this scope:\n", ntable); @@ -327,8 +327,8 @@ static void cmd_push(unsigned argc, char* argv[]) struct __vpiScope*child = 0; if (stop_current_scope) { - table = stop_current_scope->intern; - ntable = stop_current_scope->nintern; + table = &stop_current_scope->intern[0]; + ntable = stop_current_scope->intern.size(); } else { vpip_make_root_iterator(table, ntable); } diff --git a/vvp/vpi_priv.cc b/vvp/vpi_priv.cc index 858286b9e..f9f48ef04 100644 --- a/vvp/vpi_priv.cc +++ b/vvp/vpi_priv.cc @@ -1260,7 +1260,7 @@ static vpiHandle find_name(const char *name, vpiHandle handle) rtn = handle; /* brute force search for the name in all objects in this scope */ - for (unsigned i = 0 ; i < ref->nintern ; i += 1) { + for (unsigned i = 0 ; i < ref->intern.size() ; i += 1) { /* The standard says that since a port does not have a full * name it cannot be found by name. Because of this we need * to skip ports here so the correct handle can be located. */ diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index df334a308..a6844c023 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -26,6 +26,7 @@ # include # include # include +# include /* * Added to use some "vvp_fun_modpath_src" @@ -265,8 +266,7 @@ class __vpiScope : public __vpiHandle { struct __vpiScopedSTime scoped_stime; struct __vpiScopedRealtime scoped_realtime; /* Keep an array of internal scope items. */ - class __vpiHandle**intern; - unsigned nintern; + std::vector intern; /* Set of types */ std::map classes; /* Keep an array of items to be automatically allocated */ diff --git a/vvp/vpi_scope.cc b/vvp/vpi_scope.cc index 037789d84..64305f170 100644 --- a/vvp/vpi_scope.cc +++ b/vvp/vpi_scope.cc @@ -25,27 +25,26 @@ #ifdef CHECK_WITH_VALGRIND # include "vvp_cleanup.h" #endif +# include # include # include # include # include "ivl_alloc.h" +using namespace std; -static vpiHandle *vpip_root_table_ptr = 0; -static unsigned vpip_root_table_cnt = 0; +static vector vpip_root_table; vpiHandle vpip_make_root_iterator(void) { - assert(vpip_root_table_ptr); - assert(vpip_root_table_cnt); - return vpip_make_iterator(vpip_root_table_cnt, - vpip_root_table_ptr, false); + return vpip_make_iterator(vpip_root_table.size(), + &vpip_root_table[0], false); } void vpip_make_root_iterator(__vpiHandle**&table, unsigned&ntable) { - table = vpip_root_table_ptr; - ntable = vpip_root_table_cnt; + table = &vpip_root_table[0]; + ntable = vpip_root_table.size(); } #ifdef CHECK_WITH_VALGRIND @@ -148,16 +147,14 @@ static void delete_sub_scopes(struct __vpiScope *scope) void root_table_delete(void) { - for (unsigned idx = 0; idx < vpip_root_table_cnt; idx += 1) { + for (unsigned idx = 0; idx < vpip_root_table.size(); idx += 1) { struct __vpiScope *scope = static_cast<__vpiScope *> - (vpip_root_table_ptr[idx]); + (vpip_root_table[idx]); vthreads_delete(scope); delete_sub_scopes(scope); delete scope; } - free(vpip_root_table_ptr); - vpip_root_table_ptr = 0; - vpip_root_table_cnt = 0; + vpip_root_table.clear(); /* Clean up all the class definitions. */ for (unsigned idx = 0; idx < class_list_count; idx += 1) { @@ -298,7 +295,7 @@ static vpiHandle module_iter_subset(int code, struct __vpiScope*ref) unsigned mcnt = 0, ncnt = 0; vpiHandle*args; - for (unsigned idx = 0 ; idx < ref->nintern ; idx += 1) + for (unsigned idx = 0 ; idx < ref->intern.size() ; idx += 1) if (compare_types(code, ref->intern[idx]->get_type_code())) mcnt += 1; @@ -306,7 +303,7 @@ static vpiHandle module_iter_subset(int code, struct __vpiScope*ref) return 0; args = (vpiHandle*)calloc(mcnt, sizeof(vpiHandle)); - for (unsigned idx = 0 ; idx < ref->nintern ; idx += 1) + for (unsigned idx = 0 ; idx < ref->intern.size() ; idx += 1) if (compare_types(code, ref->intern[idx]->get_type_code())) args[ncnt++] = ref->intern[idx]; @@ -463,16 +460,7 @@ static struct __vpiScope*current_scope = 0; void vpip_attach_to_scope(struct __vpiScope*scope, vpiHandle obj) { assert(scope); - unsigned idx = scope->nintern++; - - if (scope->intern == 0) - scope->intern = (vpiHandle*) - malloc(sizeof(vpiHandle)); - else - scope->intern = (vpiHandle*) - realloc(scope->intern, sizeof(vpiHandle)*scope->nintern); - - scope->intern[idx] = obj; + scope->intern.push_back(obj); } /* @@ -522,8 +510,6 @@ compile_scope_decl(char*label, char*type, char*name, char*tname, scope->lineno = (unsigned) lineno; scope->def_file_idx = (unsigned) def_file_idx; scope->def_lineno = (unsigned) def_lineno; - scope->intern = 0; - scope->nintern = 0; scope->item = 0; scope->nitem = 0; scope->live_contexts = 0; @@ -556,11 +542,7 @@ compile_scope_decl(char*label, char*type, char*name, char*tname, } else { scope->scope = 0x0; - unsigned cnt = vpip_root_table_cnt + 1; - vpip_root_table_ptr = (vpiHandle*) - realloc(vpip_root_table_ptr, cnt * sizeof(vpiHandle)); - vpip_root_table_ptr[vpip_root_table_cnt] = scope; - vpip_root_table_cnt = cnt; + vpip_root_table.push_back(scope); /* Root scopes inherit time_units and precision from the system precision. */