Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Deprecate xbt_dict_new()
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 4 Dec 2016 17:47:09 +0000 (18:47 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 4 Dec 2016 20:04:41 +0000 (21:04 +0100)
Please people, use xbt_dict_new_homogeneous(). Non-homogeneous dicts
were a very bad idea that could have only originated in Perl anyway.

ChangeLog
examples/msg/app-bittorrent/peer.c
src/msg/msg_vm.cpp
src/smpi/smpi_comm.cpp
src/smpi/smpi_mpi_dt.cpp
src/surf/network_ib.cpp
src/surf/sg_platf.cpp
src/surf/xml/surfxml_sax_cb.cpp
src/xbt/dict.cpp

index a3aeb1c..8eb197e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -42,7 +42,10 @@ SimGrid (3.14) UNRELEASED; urgency=low
    - MSG_storage_set_property_value()
  * VM properties. Since msg_vm_t are msg_host_t, just use
    MSG_host_get_property_value() and friends
-
+ * xbt heterogeneous dictionnaries (created with xbt_dict_new()). 
+   Well, they are still there for now, but deprecated with a warning. 
+   Please switch to xbt_dict_new_homogeneous() before this is removed
+   for real.
  * Task affinity. Its intended behavior (that was very badly tested
    and probably not really working) was deceiving what most users
    would have hoped here.
index e27520e..d297ba8 100644 (file)
@@ -206,8 +206,8 @@ void peer_init(peer_t peer, int id, int seed)
   peer->id = id;
   snprintf(peer->mailbox,MAILBOX_SIZE-1, "%d", id);
   snprintf(peer->mailbox_tracker,MAILBOX_SIZE-1, "tracker_%d", id);
-  peer->peers = xbt_dict_new();
-  peer->active_peers = xbt_dict_new();
+  peer->peers        = xbt_dict_new_homogeneous(NULL);
+  peer->active_peers = xbt_dict_new_homogeneous(NULL);
   peer->hostname = MSG_host_get_name(MSG_host_self());
 
   peer->bitfield = xbt_new(char, FILE_PIECES + 1);
index 12a577e..934858f 100644 (file)
@@ -467,7 +467,7 @@ void MSG_host_add_task(msg_host_t host, msg_task_t task)
     dp->prev_remaining = remaining;
   }
   if (!pimpl->dp_objs)
-    pimpl->dp_objs = xbt_dict_new();
+    pimpl->dp_objs = xbt_dict_new_homogeneous(nullptr);
   xbt_assert(xbt_dict_get_or_null(pimpl->dp_objs, key) == nullptr);
   xbt_dict_set(pimpl->dp_objs, key, dp, nullptr);
   XBT_DEBUG("add %s on %s (remaining %f, dp_enabled %d)", key, host->cname(), remaining, pimpl->dp_enabled);
index 99625ce..7b2cbe0 100644 (file)
@@ -97,26 +97,26 @@ int smpi_comm_dup(MPI_Comm comm, MPI_Comm* newcomm){
   int ret = MPI_SUCCESS;
 
   if(comm->attributes !=nullptr){
-      (*newcomm)->attributes=xbt_dict_new();
-      xbt_dict_cursor_t cursor = nullptr;
-      int *key;
-      int flag;
-      void* value_in;
-      void* value_out;
-      xbt_dict_foreach(comm->attributes, cursor, key, value_in){
-        smpi_comm_key_elem elem =
-           static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(key), sizeof(int)));
-        if(elem!=nullptr && elem->copy_fn!=MPI_NULL_COPY_FN){
-          ret = elem->copy_fn(comm, *key, nullptr, value_in, &value_out, &flag );
-          if(ret!=MPI_SUCCESS){
-            smpi_comm_destroy(*newcomm);
-            *newcomm=MPI_COMM_NULL;
-            xbt_dict_cursor_free(&cursor);
-            return ret;
-          }
-          if(flag)
-            xbt_dict_set_ext((*newcomm)->attributes, reinterpret_cast<const char*>(key), sizeof(int),value_out, nullptr);
+    (*newcomm)->attributes   = xbt_dict_new_homogeneous(nullptr);
+    xbt_dict_cursor_t cursor = nullptr;
+    int* key;
+    int flag;
+    void* value_in;
+    void* value_out;
+    xbt_dict_foreach (comm->attributes, cursor, key, value_in) {
+      smpi_comm_key_elem elem = static_cast<smpi_comm_key_elem>(
+          xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(key), sizeof(int)));
+      if (elem != nullptr && elem->copy_fn != MPI_NULL_COPY_FN) {
+        ret = elem->copy_fn(comm, *key, nullptr, value_in, &value_out, &flag);
+        if (ret != MPI_SUCCESS) {
+          smpi_comm_destroy(*newcomm);
+          *newcomm = MPI_COMM_NULL;
+          xbt_dict_cursor_free(&cursor);
+          return ret;
         }
+        if (flag)
+          xbt_dict_set_ext((*newcomm)->attributes, reinterpret_cast<const char*>(key), sizeof(int), value_out, nullptr);
+      }
       }
     }
   return ret;
@@ -557,7 +557,7 @@ int smpi_comm_attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag){
 
 int smpi_comm_attr_put(MPI_Comm comm, int keyval, void* attr_value){
   if(smpi_comm_keyvals==nullptr)
-    smpi_comm_keyvals = xbt_dict_new();
+    smpi_comm_keyvals = xbt_dict_new_homogeneous(nullptr);
   smpi_comm_key_elem elem =
     static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals,  reinterpret_cast<const char*>(&keyval), sizeof(int)));
   if(elem==nullptr)
@@ -571,7 +571,7 @@ int smpi_comm_attr_put(MPI_Comm comm, int keyval, void* attr_value){
       return ret;
   }
   if(comm->attributes==nullptr)
-    comm->attributes=xbt_dict_new();
+    comm->attributes = xbt_dict_new_homogeneous(nullptr);
 
   xbt_dict_set_ext(comm->attributes,  reinterpret_cast<const char*>(&keyval), sizeof(int), attr_value, nullptr);
   return MPI_SUCCESS;
@@ -580,7 +580,7 @@ int smpi_comm_attr_put(MPI_Comm comm, int keyval, void* attr_value){
 int smpi_comm_keyval_create(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
                             void* extra_state){
   if(smpi_comm_keyvals==nullptr)
-    smpi_comm_keyvals = xbt_dict_new();
+    smpi_comm_keyvals = xbt_dict_new_homogeneous(nullptr);
 
   smpi_comm_key_elem value = static_cast<smpi_comm_key_elem>(xbt_new0(s_smpi_mpi_comm_key_elem_t,1));
 
index 5f66b31..634ecf4 100644 (file)
@@ -186,26 +186,26 @@ int smpi_datatype_dup(MPI_Datatype datatype, MPI_Datatype* new_t)
   if(datatype->name)
     (*new_t)->name = xbt_strdup(datatype->name);
   if(datatype->attributes !=nullptr){
-      (*new_t)->attributes=xbt_dict_new();
-      xbt_dict_cursor_t cursor = nullptr;
-      int *key;
-      int flag;
-      void* value_in;
-      void* value_out;
-      xbt_dict_foreach(datatype->attributes, cursor, key, value_in){
-        smpi_type_key_elem elem =
-          static_cast<smpi_type_key_elem>(xbt_dict_get_or_null_ext(smpi_type_keyvals,  reinterpret_cast<const char*>(key), sizeof(int)));
-        if(elem != nullptr && elem->copy_fn!=MPI_NULL_COPY_FN){
-          ret = elem->copy_fn(datatype, *key, nullptr, value_in, &value_out, &flag );
-          if(ret!=MPI_SUCCESS){
-            smpi_datatype_unuse(*new_t);
-            *new_t=MPI_DATATYPE_NULL;
-            xbt_dict_cursor_free(&cursor);
-            return ret;
-          }
-          if(flag)
-            xbt_dict_set_ext((*new_t)->attributes, reinterpret_cast<const char*>(key), sizeof(int),value_out, nullptr);
+    (*new_t)->attributes     = xbt_dict_new_homogeneous(nullptr);
+    xbt_dict_cursor_t cursor = nullptr;
+    int* key;
+    int flag;
+    void* value_in;
+    void* value_out;
+    xbt_dict_foreach (datatype->attributes, cursor, key, value_in) {
+      smpi_type_key_elem elem = static_cast<smpi_type_key_elem>(
+          xbt_dict_get_or_null_ext(smpi_type_keyvals, reinterpret_cast<const char*>(key), sizeof(int)));
+      if (elem != nullptr && elem->copy_fn != MPI_NULL_COPY_FN) {
+        ret = elem->copy_fn(datatype, *key, nullptr, value_in, &value_out, &flag);
+        if (ret != MPI_SUCCESS) {
+          smpi_datatype_unuse(*new_t);
+          *new_t = MPI_DATATYPE_NULL;
+          xbt_dict_cursor_free(&cursor);
+          return ret;
         }
+        if (flag)
+          xbt_dict_set_ext((*new_t)->attributes, reinterpret_cast<const char*>(key), sizeof(int), value_out, nullptr);
+      }
       }
     }
   return ret;
@@ -1606,7 +1606,7 @@ int smpi_type_attr_get(MPI_Datatype type, int keyval, void* attr_value, int* fla
 
 int smpi_type_attr_put(MPI_Datatype type, int keyval, void* attr_value){
   if(smpi_type_keyvals==nullptr)
-    smpi_type_keyvals = xbt_dict_new();
+    smpi_type_keyvals = xbt_dict_new_homogeneous(nullptr);
   smpi_type_key_elem elem =
      static_cast<smpi_type_key_elem>(xbt_dict_get_or_null_ext(smpi_type_keyvals, reinterpret_cast<const char*>(&keyval), sizeof(int)));
   if(elem==nullptr)
@@ -1620,7 +1620,7 @@ int smpi_type_attr_put(MPI_Datatype type, int keyval, void* attr_value){
       return ret;
   }
   if(type->attributes==nullptr)
-    type->attributes=xbt_dict_new();
+    type->attributes = xbt_dict_new_homogeneous(nullptr);
 
   xbt_dict_set_ext(type->attributes, reinterpret_cast<const char*>(&keyval), sizeof(int), attr_value, nullptr);
   return MPI_SUCCESS;
@@ -1629,7 +1629,7 @@ int smpi_type_attr_put(MPI_Datatype type, int keyval, void* attr_value){
 int smpi_type_keyval_create(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
                             void* extra_state){
   if(smpi_type_keyvals==nullptr)
-    smpi_type_keyvals = xbt_dict_new();
+    smpi_type_keyvals = xbt_dict_new_homogeneous(nullptr);
 
   smpi_type_key_elem value = (smpi_type_key_elem) xbt_new0(s_smpi_mpi_type_key_elem_t,1);
 
index 1d84616..dce8789 100644 (file)
@@ -21,7 +21,7 @@ static void IB_create_host_callback(simgrid::s4u::Host& host){
   static int id=0;
   // pour t->id -> rajouter une nouvelle struct dans le dict, pour stocker les comms actives
   if(((NetworkIBModel*)surf_network_model)->active_nodes==nullptr)
-    ((NetworkIBModel*)surf_network_model)->active_nodes=xbt_dict_new();
+    ((NetworkIBModel*)surf_network_model)->active_nodes = xbt_dict_new_homogeneous(nullptr);
 
   IBNode* act = new IBNode(id);
 
index e1aecbc..6d42adc 100644 (file)
@@ -235,10 +235,10 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
     if ((cluster->properties != nullptr) && (!xbt_dict_is_empty(cluster->properties))) {
       xbt_dict_cursor_t cursor=nullptr;
       char *key,*data;
-      host.properties = xbt_dict_new();
+      host.properties = xbt_dict_new_homogeneous(free);
 
       xbt_dict_foreach(cluster->properties,cursor,key,data) {
-        xbt_dict_set(host.properties, key, xbt_strdup(data),free);
+        xbt_dict_set(host.properties, key, xbt_strdup(data), nullptr);
       }
     }
 
index b6d6075..c8c643a 100644 (file)
@@ -473,8 +473,8 @@ void STag_surfxml_prop()
   }
   else{
     if (!current_property_set)
-       current_property_set = xbt_dict_new(); // Maybe, it should raise an error
-    xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), xbt_free_f);
+      current_property_set = xbt_dict_new_homogeneous(&xbt_free_f); // Maybe, it should raise an error
+    xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), nullptr);
     XBT_DEBUG("add prop %s=%s into current property set", A_surfxml_prop_id, A_surfxml_prop_value);
   }
 }
index 744d388..29f86bf 100644 (file)
@@ -31,6 +31,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dict, xbt, "Dictionaries provide the same fu
  */
 xbt_dict_t xbt_dict_new()
 {
+  XBT_WARN("Function xbt_dict_new() will soon be dropped. Please switch to xbt_dict_new_homogeneous()");
   xbt_dict_t dict = xbt_dict_new_homogeneous(nullptr);
   dict->homogeneous = 0;