Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
commit f00F8da2 broke the binding between SD and jedule
[simgrid.git] / src / instr / jedule / jedule_platform.c
index 9b21d5c..54fdb74 100644 (file)
@@ -10,7 +10,9 @@
 #include "xbt/asserts.h"
 #include "xbt/dynar.h"
 
-#include "jedule_platform.h"
+#include "instr/jedule/jedule_platform.h"
+
+#ifdef HAVE_JEDULE
 
 /********************************************************************/
 
@@ -30,7 +32,9 @@ static void jed_free_container(jed_simgrid_container_t container);
 /********************************************************************/
 
 static int compare_hostnames(const void *host1, const void *host2) {
-       return strcmp ((char*)host1, (char*)host2);
+       const char *hp1 = *((const char**) host1);
+       const char *hp2 = *((const char**) host2);
+       return strcmp (hp1, hp2);
 }
 
 static int compare_ids(const void *num1, const void *num2) {
@@ -42,9 +46,7 @@ static int compare_ids(const void *num1, const void *num2) {
 static void jed_free_container(jed_simgrid_container_t container) {
 
        xbt_dict_free(&container->name2id);
-       if( container->resource_list != NULL ) {
-               xbt_dynar_free(&container->resource_list);
-       }
+       xbt_dynar_free(&container->resource_list);
 
        if( container->container_children != NULL ) {
                unsigned int iter;
@@ -62,8 +64,7 @@ void jed_simgrid_create_container(jed_simgrid_container_t *container, char *name
        xbt_assert( name != NULL );
 
        *container = (jed_simgrid_container_t)calloc(1,sizeof(s_jed_simgrid_container_t));
-       (*container)->name = (char*)calloc((strlen(name)+1), sizeof(char));
-       strcpy((*container)->name, name);
+       (*container)->name = xbt_strdup(name);
        (*container)->is_lowest = 0;
        (*container)->container_children = xbt_dynar_new(sizeof(jed_simgrid_container_t), NULL);
        (*container)->parent = NULL;
@@ -85,24 +86,21 @@ void jed_simgrid_add_resources(jed_simgrid_container_t parent,
 
        unsigned int iter;
        char *host_name;
-       char buf[16];
-       char *buf_copy;
+       char *buf;
 
        parent->is_lowest = 1;
        xbt_dynar_free(&parent->container_children);
        parent->container_children = NULL;
-       parent->name2id = xbt_dict_new();
+       parent->name2id = xbt_dict_new_homogeneous(xbt_free);
        parent->last_id = 0;
        parent->resource_list = xbt_dynar_new(sizeof(char *), NULL);
 
-
        xbt_dynar_sort (host_names,     &compare_hostnames);
 
        xbt_dynar_foreach(host_names, iter, host_name) {
-               buf_copy = strdup(buf);
-               sprintf(buf_copy, "%d", parent->last_id);
+               buf = bprintf("%d", parent->last_id);
                (parent->last_id)++;
-               xbt_dict_set(parent->name2id, host_name, buf_copy, NULL);
+               xbt_dict_set(parent->name2id, host_name, buf, NULL);
                xbt_dict_set(host2_simgrid_parent_container, host_name, parent, NULL);
                xbt_dynar_push(parent->resource_list, &host_name);
        }
@@ -206,7 +204,7 @@ void jed_simgrid_get_resource_selection_by_hosts(xbt_dynar_t subset_list,
        unsigned int iter;
        xbt_dict_t parent2hostgroup;  // group hosts by parent
 
-       parent2hostgroup = xbt_dict_new();
+       parent2hostgroup = xbt_dict_new_homogeneous(NULL);
 
        xbt_assert( host_names != NULL );
 
@@ -264,9 +262,9 @@ void jedule_add_meta_info(jedule_t jedule, char *key, char *value) {
 
 void jed_create_jedule(jedule_t *jedule) {
        *jedule = (jedule_t)calloc(1,sizeof(s_jedule_t));
-       host2_simgrid_parent_container = xbt_dict_new();
-       container_name2container       = xbt_dict_new();
-       (*jedule)->jedule_meta_info    = xbt_dict_new();
+       host2_simgrid_parent_container = xbt_dict_new_homogeneous(NULL);
+       container_name2container       = xbt_dict_new_homogeneous(NULL);
+       (*jedule)->jedule_meta_info    = xbt_dict_new_homogeneous(NULL);
 }
 
 void jed_free_jedule(jedule_t jedule) {
@@ -280,4 +278,4 @@ void jed_free_jedule(jedule_t jedule) {
        xbt_dict_free(&container_name2container);
 }
 
-
+#endif