From: Frederic Suter Date: Wed, 8 Mar 2017 11:21:34 +0000 (+0100) Subject: further prepare the elegant death of dynars X-Git-Tag: v3_15~184 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/14262a27cd78687e6a762eff0e58166fd35e5625 further prepare the elegant death of dynars --- diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index 6b738f1756..d04ad90fa9 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -48,7 +48,7 @@ public: NetZone* father(); xbt_dict_t children(); // Sub netzones - xbt_dynar_t hosts(); // my content as a dynar + std::vector hosts(); // my content as a vector of hosts /** Get the properties assigned to a host */ std::unordered_map* properties(); diff --git a/src/bindings/java/jmsg_as.cpp b/src/bindings/java/jmsg_as.cpp index cac6920004..57bc73518a 100644 --- a/src/bindings/java/jmsg_as.cpp +++ b/src/bindings/java/jmsg_as.cpp @@ -129,27 +129,22 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jo jobjectArray jtable; jobject jhost; jstring jname; - msg_host_t host; simgrid::s4u::NetZone* as = jnetzone_get_native(env, jas); - xbt_dynar_t table = as->hosts(); - int count = xbt_dynar_length(table); - jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host"); - + std::vector table = as->hosts(); if (!cls) return nullptr; - jtable = env->NewObjectArray(static_cast(count), cls, nullptr); + jtable = env->NewObjectArray(static_cast(table.size()), cls, nullptr); if (!jtable) { jxbt_throw_jni(env, "Hosts table allocation failed"); return nullptr; } - for (int index = 0; index < count; index++) { - host = xbt_dynar_get_as(table,index,msg_host_t); - + int index = 0; + for (auto host : table) { jhost = static_cast(host->extension(JAVA_HOST_LEVEL)); if (!jhost) { jname = env->NewStringUTF(host->cname()); @@ -160,8 +155,8 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jo } env->SetObjectArrayElement(jtable, index, jhost); + index++; } - xbt_dynar_free(&table); return jtable; } diff --git a/src/msg/msg_environment.cpp b/src/msg/msg_environment.cpp index 122783e9e5..733814c377 100644 --- a/src/msg/msg_environment.cpp +++ b/src/msg/msg_environment.cpp @@ -80,7 +80,13 @@ void MSG_environment_as_set_property_value(msg_netzone_t netzone, const char* na xbt_dynar_t MSG_environment_as_get_hosts(msg_netzone_t netzone) { - return netzone->hosts(); + xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t), nullptr); + + for (auto host : netzone->hosts()) { + xbt_dynar_push(res, &host); + } + + return res; } SG_END_DECL() diff --git a/src/s4u/s4u_netzone.cpp b/src/s4u/s4u_netzone.cpp index e2149e69aa..5377233560 100644 --- a/src/s4u/s4u_netzone.cpp +++ b/src/s4u/s4u_netzone.cpp @@ -72,14 +72,14 @@ NetZone* NetZone::father() return father_; } -xbt_dynar_t NetZone::hosts() +std::vector NetZone::hosts() { - xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t), nullptr); + std::vector res; for (auto card : vertices_) { s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->name()); if (host != nullptr) - xbt_dynar_push(res, &host); + res.push_back(host); } return res; }