Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Clean and reorganize: move some frees to the right locations...
[simgrid.git] / src / surf / surfxml_parse.c
index e2170bac70e8e47f4172c476af4cb0f1e87ab1c2..c1dbedbb93642c5c5df53021021c03d8067586d1 100644 (file)
@@ -80,7 +80,7 @@ xbt_dict_t current_property_set = NULL;
 xbt_dict_t route_table = NULL;
 xbt_dict_t route_multi_table = NULL;
 xbt_dynar_t route_multi_elements = NULL;
-xbt_dynar_t route_link_list = NULL;
+static xbt_dynar_t route_link_list = NULL;
 xbt_dynar_t links = NULL;
 xbt_dynar_t keys = NULL;
 
@@ -95,6 +95,7 @@ YY_BUFFER_STATE surf_input_buffer;
 FILE *surf_file_to_parse = NULL;
 
 static void convert_route_multi_to_routes(void);
+static void parse_route_elem(void);
 
 void surf_parse_free_callbacks(void)
 {
@@ -231,7 +232,6 @@ void ETag_surfxml_platform(void)
 
   xbt_dict_free(&random_data_list);
   xbt_dict_free(&set_list);
-
 }
 
 void STag_surfxml_host(void)
@@ -480,11 +480,6 @@ void parse_properties(void)
    xbt_dict_set(current_property_set, A_surfxml_prop_id, value, free);
 }
 
-void free_string(void *d)
-{
-  free(*(void**)d);
-}
-
 void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
 {
   xbt_dynar_push(cb_list, &function);
@@ -500,7 +495,11 @@ static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list)
     }
 }
 
-void init_data(void)
+static void parse_route_set_endpoints(void) {
+  route_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
+}
+
+static void init_data(void)
 {
   xbt_dict_free(&route_table);
   xbt_dynar_free(&route_link_list);
@@ -517,12 +516,36 @@ void init_data(void)
   trace_connect_list_latency = xbt_dict_new();
 
   random_data_list = xbt_dict_new();
+  surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
+  surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
+}
+
+static void free_data(void) 
+{
+  char *key,*data;
+  xbt_dict_cursor_t cursor = NULL;
+
+  xbt_dict_foreach(route_table, cursor, key, data) {
+    xbt_dynar_t links = (xbt_dynar_t)data;
+    xbt_dynar_free(&links);
+  }
+  xbt_dict_free(&route_table);
+  route_link_list = NULL;
+
+  xbt_dict_free(&trace_connect_list_host_avail);
+  xbt_dict_free(&trace_connect_list_power);
+  xbt_dict_free(&trace_connect_list_link_avail);
+  xbt_dict_free(&trace_connect_list_bandwidth);
+  xbt_dict_free(&trace_connect_list_latency);
+  xbt_dict_free(&traces_set_list);
 }
 
 void parse_platform_file(const char* file)
 {
   surf_parse_open(file);
+  init_data();
   xbt_assert1((!(*surf_parse)()), "Parse error in %s", file);
+  free_data();
   surf_parse_close();
 }
 
@@ -738,7 +761,7 @@ static int route_multi_size=0;
 static char* src_name, *dst_name;
 static int is_symmetric_route;
 
-void parse_route_elem(void)
+static void parse_route_elem(void)
 {
   char *val;
 
@@ -755,7 +778,7 @@ void parse_route_multi_set_endpoints(void)
   is_symmetric_route = A_surfxml_route_c_multi_symmetric;
   route_multi_size++;
 
-  route_link_list = xbt_dynar_new(sizeof(char *), &free_string);
+  route_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
 }
 
 static int contains(xbt_dynar_t list, const char* value)
@@ -793,6 +816,7 @@ void manage_route(xbt_dict_t routing_table, const char *route_name, int action,
                                    xbt_dynar_foreach(route_link_list, cpt, value) {
                                        xbt_dynar_push(links,&value);
                                    }
+                                   xbt_dynar_free(&route_link_list);
                                     route_link_list = links;
                                    break;
         case A_surfxml_route_action_OVERRIDE:
@@ -890,14 +914,14 @@ static void convert_route_multi_to_routes(void)
     dst_names = (xbt_dynar_t)xbt_dict_get_or_null(set_list, dst);
     /* Add to dynar even if they are simple names */
     if (src_names == NULL) {
-       src_names = xbt_dynar_new(sizeof(char *), &free_string);
+       src_names = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
        val = xbt_strdup(src);
        xbt_dynar_push(src_names, &val);
        if (strcmp(val,"$*") != 0 && NULL == xbt_dict_get_or_null(set, val))
          THROW3(unknown_error,0,"(In route:multi (%s -> %s) source %s does not exist (not a set or a host)", src, dst, src);
     }
     if (dst_names == NULL) {
-       dst_names = xbt_dynar_new(sizeof(char *), &free_string);
+       dst_names = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
        val = xbt_strdup(dst);
        if (strcmp(val,"$*") != 0 && NULL == xbt_dict_get_or_null(set, val))
          THROW3(unknown_error,0,"(In route:multi (%s -> %s) destination %s does not exist (not a set or a host)", src, dst, dst);