From: Martin Quinson Date: Sun, 4 Dec 2016 17:47:09 +0000 (+0100) Subject: Deprecate xbt_dict_new() X-Git-Tag: v3_14~122 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/ffbe55360efde07c787741f05fe6410860c651fa Deprecate xbt_dict_new() Please people, use xbt_dict_new_homogeneous(). Non-homogeneous dicts were a very bad idea that could have only originated in Perl anyway. --- diff --git a/ChangeLog b/ChangeLog index a3aeb1ca5c..8eb197e607 100644 --- 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. diff --git a/examples/msg/app-bittorrent/peer.c b/examples/msg/app-bittorrent/peer.c index e27520e4a9..d297ba8e1d 100644 --- a/examples/msg/app-bittorrent/peer.c +++ b/examples/msg/app-bittorrent/peer.c @@ -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); diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index 12a577e081..934858f996 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -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); diff --git a/src/smpi/smpi_comm.cpp b/src/smpi/smpi_comm.cpp index 99625ce3f0..7b2cbe07d9 100644 --- a/src/smpi/smpi_comm.cpp +++ b/src/smpi/smpi_comm.cpp @@ -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(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast(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(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( + xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast(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(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(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast(&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(&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(xbt_new0(s_smpi_mpi_comm_key_elem_t,1)); diff --git a/src/smpi/smpi_mpi_dt.cpp b/src/smpi/smpi_mpi_dt.cpp index 5f66b310be..634ecf493f 100644 --- a/src/smpi/smpi_mpi_dt.cpp +++ b/src/smpi/smpi_mpi_dt.cpp @@ -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(xbt_dict_get_or_null_ext(smpi_type_keyvals, reinterpret_cast(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(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( + xbt_dict_get_or_null_ext(smpi_type_keyvals, reinterpret_cast(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(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(xbt_dict_get_or_null_ext(smpi_type_keyvals, reinterpret_cast(&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(&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); diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index 1d84616753..dce8789547 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -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); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index e1aecbce80..6d42adc875 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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); } } diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index b6d60750ce..c8c643a90a 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -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); } } diff --git a/src/xbt/dict.cpp b/src/xbt/dict.cpp index 744d388a1f..29f86bf779 100644 --- a/src/xbt/dict.cpp +++ b/src/xbt/dict.cpp @@ -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;