Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Create current_property_set only if it is required.
[simgrid.git] / src / bindings / lua / lua_console.c
index c3d576b..e4a523a 100644 (file)
@@ -55,11 +55,13 @@ static void create_host(const char *id, double power_peak, double power_sc,
     state_trace = tmgr_trace_new(state_tr);
   else
     state_trace = tmgr_trace_new("");
-  current_property_set = xbt_dict_new();
+
   surf_host_create_resource(xbt_strdup(id), power_peak, power_scale,
                             power_trace, core_nb, state_initial, state_trace,
                             current_property_set);
 
+  current_property_set = NULL;
+
 }
 
 /**
@@ -127,11 +129,11 @@ static void create_host_wsL07(const char *id, double power_peak,
     state_trace = tmgr_trace_new(state_tr);
   else
     state_trace = tmgr_trace_new("");
-  current_property_set = xbt_dict_new();
+
   surf_wsL07_host_create_resource(xbt_strdup(id), power_peak, power_scale,
                                   power_trace, state_initial, state_trace,
                                   current_property_set);
-
+  current_property_set = NULL;
 }
 
 /**
@@ -222,7 +224,7 @@ static int Host_new(lua_State * L)
 {
   p_host_attr host;
   unsigned int i;
-  p_AS_attr p_as,current_as;
+  p_AS_attr p_as,current_as = NULL;
   const char *AS_id;
   const char *id;
   const char *power_trace;
@@ -317,7 +319,7 @@ static int Link_new(lua_State * L)      // (id,bandwidth,latency)
 {
   const char *AS_id;
   unsigned int i;
-  p_AS_attr p_as,current_as;
+  p_AS_attr p_as,current_as = NULL;
   const char* id;
   double bandwidth, latency;
   const char *bandwidth_trace;
@@ -428,7 +430,7 @@ static int Route_new(lua_State * L)     // (src_id,dest_id,links_number,link_tab
   p_route_attr route = malloc(sizeof(route_attr));
 
 
-  if (!lua_istable(L, 3)) { // if Route.new is declared as an indexed table (FIXME : we check the third arg if it's not a table)
+  if (!lua_istable(L, 4)) { // if Route.new is declared as an indexed table (FIXME : we check the third arg if it's not a table)
 
         //get AS_id
         lua_pushstring(L, "AS");
@@ -476,18 +478,27 @@ static int Route_new(lua_State * L)     // (src_id,dest_id,links_number,link_tab
           link_id = strtok(NULL,","); //Alternatively, a null pointer may be specified, in which case the function continues scanning where a previous successful call to the function ended.
         }
      xbt_dynar_push(current_as->route_list_d, &route);
-
-
      return 0;
-
       }
   else { // Route.new is declared as a function
-     //const char* link_id;
-     route->src_id = luaL_checkstring(L, 1);
-     route->dest_id = luaL_checkstring(L, 2);
+        AS_id = luaL_checkstring(L, 1);
+        xbt_dynar_foreach(as_list_d, i, p_as){
+                 if (p_as->id == AS_id){
+                         current_as = p_as;
+                         break;
+                 }
+                }
+
+        if (!current_as)
+        {
+               XBT_ERROR("addRoute: No AS_id :%s found",AS_id);
+               return -2;
+        }
+     route->src_id = luaL_checkstring(L, 2);
+     route->dest_id = luaL_checkstring(L, 3);
      route->links_id = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
      lua_pushnil(L);
-     while (lua_next(L, 3) != 0)
+     while (lua_next(L, 4) != 0)
                {
         link_id = lua_tostring(L, -1);
         xbt_dynar_push(route->links_id, &link_id);
@@ -495,11 +506,10 @@ static int Route_new(lua_State * L)     // (src_id,dest_id,links_number,link_tab
         lua_tostring(L, -1));
         lua_pop(L, 1);
        }
-        lua_pop(L, 1);
-
-         //add route to platform's route list
-         xbt_dynar_push(current_as->route_list_d, &route);
-         return 0;
+    lua_pop(L, 1);
+    //add route to platform's route list
+    xbt_dynar_push(current_as->route_list_d, &route);
+    return 0;
     }
 
   return -1;