Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replace a combination of malloc+strcpy by xbt_strdup.
[simgrid.git] / src / bindings / lua / lua_console.c
index a1188a5..da12ba5 100644 (file)
@@ -32,16 +32,20 @@ static void create_AS(const char *id, const char *mode)
  */
 
 static void create_host(const char *id, double power_peak, double power_sc,
-                        const char *power_tr, int state_init,
+                        const char *power_tr,int core,int state_init,
                         const char *state_tr)
 {
 
   double power_scale = 1.0;
+  int core_nb = 1; //default value
   tmgr_trace_t power_trace = NULL;
   e_surf_resource_state_t state_initial;
   tmgr_trace_t state_trace;
   if (power_sc)                 // !=0
     power_scale = power_sc;
+  if (core)
+         core_nb = core; //default value
+  else
   if (state_init == -1)
     state_initial = SURF_RESOURCE_OFF;
   else
@@ -56,7 +60,7 @@ static void create_host(const char *id, double power_peak, double power_sc,
     state_trace = tmgr_trace_new("");
   current_property_set = xbt_dict_new();
   surf_host_create_resource(xbt_strdup(id), power_peak, power_scale,
-                            power_trace, state_initial, state_trace,
+                            power_trace, core_nb, state_initial, state_trace,
                             current_property_set);
 
 }
@@ -194,7 +198,7 @@ static int AS_new(lua_State * L)
     mode = lua_tostring(L, -1);
     lua_pop(L, 1);
   } else {
-    ERROR0
+    XBT_ERROR
         ("Bad Arguments to AS.new, Should be a table with named arguments");
     return -1;
   }
@@ -219,7 +223,7 @@ static int Host_new(lua_State * L)
   const char *power_trace;
   const char *state_trace;
   double power, power_scale;
-  int state_initial;
+  int state_initial,core;
   //get values from the table passed as argument
   if (lua_istable(L, -1)) {
 
@@ -247,6 +251,11 @@ static int Host_new(lua_State * L)
     power_trace = lua_tostring(L, -1);
     lua_pop(L, 1);
 
+    lua_pushstring(L, "core");
+    lua_gettable(L, -2);
+    core = lua_tonumber(L, -1);
+    lua_pop(L, 1);
+
     //get state initial
     lua_pushstring(L, "state_initial");
     lua_gettable(L, -2);
@@ -260,7 +269,7 @@ static int Host_new(lua_State * L)
     lua_pop(L, 1);
 
   } else {
-    ERROR0
+    XBT_ERROR
         ("Bad Arguments to create host, Should be a table with named arguments");
     return -1;
   }
@@ -270,6 +279,7 @@ static int Host_new(lua_State * L)
   host->power_peak = power;
   host->power_scale = power_scale;
   host->power_trace = power_trace;
+  host->core = core;
   host->state_initial = state_initial;
   host->state_trace = state_trace;
   host->function = NULL;
@@ -348,7 +358,7 @@ static int Link_new(lua_State * L)      // (id,bandwidth,latency)
     lua_pop(L, 1);
 
   } else {
-    ERROR0
+    XBT_ERROR
         ("Bad Arguments to create link, Should be a table with named arguments");
     return -1;
   }
@@ -401,8 +411,7 @@ static int Route_new(lua_State * L)     // (src_id,dest_id,links_number,link_tab
 
      route->links_id = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
 
-     char *tmp_links = malloc(sizeof(char)*strlen(links)+1);//use xbt
-     strcpy(tmp_links,links);
+     char *tmp_links = xbt_strdup(links);
      link_id = strtok(tmp_links,",");   //tmp_link = strtok((char*)links,",");
      while(link_id != NULL)
        {
@@ -423,7 +432,7 @@ static int Route_new(lua_State * L)     // (src_id,dest_id,links_number,link_tab
                {
         link_id = lua_tostring(L, -1);
         xbt_dynar_push(route->links_id, &link_id);
-        DEBUG2("index = %f , Link_id = %s \n", lua_tonumber(L, -2),
+         XBT_DEBUG("index = %f , Link_id = %s \n", lua_tonumber(L, -2),
         lua_tostring(L, -1));
         lua_pop(L, 1);
        }
@@ -465,7 +474,7 @@ static int Host_set_function(lua_State * L)     //(host,function,nb_args,list_ar
      lua_pop(L, 1);
    }
    else {
-          ERROR0("Bad Arguments to create link, Should be a table with named arguments");
+          XBT_ERROR("Bad Arguments to create link, Should be a table with named arguments");
           return -1;
    }
 
@@ -483,7 +492,7 @@ static int Host_set_function(lua_State * L)     //(host,function,nb_args,list_ar
       return 0;
           }
       }
-         ERROR1("Host : %s Not Found !!", host);
+         XBT_ERROR("Host : %s Not Found !!", host);
          return 1;
 
 }
@@ -505,7 +514,7 @@ static int surf_parse_bypass_platform()
   // Add Hosts
   xbt_dynar_foreach(host_list_d, i, p_host) {
     create_host(p_host->id, p_host->power_peak, p_host->power_scale,
-                p_host->power_trace, p_host->state_initial,
+                p_host->power_trace, p_host->core, p_host->state_initial,
                 p_host->state_trace);
     //add to routing model host list
     surf_route_add_host((char *) p_host->id);