From: Martin Quinson Date: Sat, 6 May 2017 21:24:01 +0000 (+0200) Subject: let's use a sensible API for the MSG_zone functions X-Git-Tag: v3.16~274^2~54 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/6fef6bba4e2855d338f4cc57f7d24e7dae90280c?hp=6636687a97c0b9be68be6b9b78fc070917fcf2a0;ds=sidebyside let's use a sensible API for the MSG_zone functions --- diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index bb2c594940..a96060d6c2 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -180,10 +180,10 @@ XBT_PUBLIC(unsigned long int) MSG_get_sent_msg(); XBT_PUBLIC(msg_netzone_t) MSG_zone_get_root(); XBT_PUBLIC(const char*) MSG_zone_get_name(msg_netzone_t zone); XBT_PUBLIC(msg_netzone_t) MSG_zone_get_by_name(const char* name); -XBT_PUBLIC(xbt_dict_t) MSG_zone_get_sons(msg_netzone_t zone); +XBT_PUBLIC(void) MSG_zone_get_sons(msg_netzone_t zone, xbt_dict_t whereto); XBT_PUBLIC(const char*) MSG_zone_get_property_value(msg_netzone_t as, const char* name); XBT_PUBLIC(void) MSG_zone_set_property_value(msg_netzone_t netzone, const char* name, char* value); -XBT_PUBLIC(xbt_dynar_t) MSG_zone_get_hosts(msg_netzone_t zone); +XBT_PUBLIC(void) MSG_zone_get_hosts(msg_netzone_t zone, xbt_dynar_t whereto); /* Deprecated forms of the previous functions */ static inline XBT_ATTRIB_DEPRECATED("Please use MSG_zone_get_root since v3.16") @@ -200,7 +200,9 @@ static inline XBT_ATTRIB_DEPRECATED("Please use MSG_zone_get_by_name since v3.16 } static inline XBT_ATTRIB_DEPRECATED("Please use MSG_zone_get_sons since v3.16") xbt_dict_t MSG_environment_as_get_routing_sons(msg_netzone_t zone) { - return MSG_zone_get_sons(zone); + xbt_dict_t res = xbt_dict_new_homogeneous(NULL); + MSG_zone_get_sons(zone, res); + return res; } static inline XBT_ATTRIB_DEPRECATED("Please use MSG_zone_get_property_value since v3.16") const char* MSG_environment_as_get_property_value(msg_netzone_t zone, const char* name) { @@ -212,7 +214,9 @@ static inline XBT_ATTRIB_DEPRECATED("Please use MSG_zone_set_property_value sinc } static inline XBT_ATTRIB_DEPRECATED("Please use MSG_zone_get_hosts since v3.16") xbt_dynar_t MSG_environment_as_get_hosts(msg_netzone_t zone) { - return MSG_zone_get_hosts(zone); + xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t), NULL); + MSG_zone_get_hosts(zone, res); + return res; } /************************** File handling ***********************************/ diff --git a/src/msg/msg_environment.cpp b/src/msg/msg_environment.cpp index 68c2a1c371..fb2c8ad742 100644 --- a/src/msg/msg_environment.cpp +++ b/src/msg/msg_environment.cpp @@ -63,13 +63,11 @@ msg_netzone_t MSG_zone_get_by_name(const char* name) return simgrid::s4u::Engine::instance()->netzoneByNameOrNull(name); } -xbt_dict_t MSG_zone_get_sons(msg_netzone_t netzone) +void MSG_zone_get_sons(msg_netzone_t netzone, xbt_dict_t whereto) { - xbt_dict_t res = xbt_dict_new_homogeneous(nullptr); for (auto elem : *netzone->children()) { - xbt_dict_set(res, elem->name(), static_cast(elem), nullptr); + xbt_dict_set(whereto, elem->name(), static_cast(elem), nullptr); } - return res; } const char* MSG_zone_get_property_value(msg_netzone_t netzone, const char* name) @@ -82,15 +80,11 @@ void MSG_zone_set_property_value(msg_netzone_t netzone, const char* name, char* netzone->setProperty(name, value); } -xbt_dynar_t MSG_zone_get_hosts(msg_netzone_t netzone) +void MSG_zone_get_hosts(msg_netzone_t netzone, xbt_dynar_t whereto) { - xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t), nullptr); - for (auto host : *netzone->hosts()) { - xbt_dynar_push(res, &host); + xbt_dynar_push(whereto, &host); } - - return res; } SG_END_DECL()