Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
further prepare the elegant death of dynars
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 8 Mar 2017 11:21:34 +0000 (12:21 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 8 Mar 2017 11:21:34 +0000 (12:21 +0100)
include/simgrid/s4u/NetZone.hpp
src/bindings/java/jmsg_as.cpp
src/msg/msg_environment.cpp
src/s4u/s4u_netzone.cpp

index 6b738f1..d04ad90 100644 (file)
@@ -48,7 +48,7 @@ public:
   NetZone* father();
 
   xbt_dict_t children(); // Sub netzones
-  xbt_dynar_t hosts();   // my content as a dynar
+  std::vector<Host*> hosts(); // my content as a vector of hosts
 
   /** Get the properties assigned to a host */
   std::unordered_map<std::string, std::string>* properties();
index cac6920..57bc735 100644 (file)
@@ -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<sg_host_t> table = as->hosts();
   if (!cls)
     return nullptr;
 
-  jtable = env->NewObjectArray(static_cast<jsize>(count), cls, nullptr);
+  jtable = env->NewObjectArray(static_cast<jsize>(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<jobject>(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;
 }
 
index 122783e..733814c 100644 (file)
@@ -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()
index e2149e6..5377233 100644 (file)
@@ -72,14 +72,14 @@ NetZone* NetZone::father()
   return father_;
 }
 
-xbt_dynar_t NetZone::hosts()
+std::vector<s4u::Host*> NetZone::hosts()
 {
-  xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t), nullptr);
+  std::vector<s4u::Host*> 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;
 }