From: Frederic Suter Date: Wed, 8 Mar 2017 15:55:15 +0000 (+0100) Subject: moving dynar up in the stack X-Git-Tag: v3_15~182 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8f4c00936fdabbd005cbf15ca132ceb248f72dcd?ds=sidebyside moving dynar up in the stack --- diff --git a/include/simgrid/s4u/host.hpp b/include/simgrid/s4u/host.hpp index 77147d3346..7c48221eb8 100644 --- a/include/simgrid/s4u/host.hpp +++ b/include/simgrid/s4u/host.hpp @@ -94,7 +94,7 @@ public: void setPstate(int pstate_index); int pstate(); xbt_dict_t mountedStoragesAsDict(); // HACK - xbt_dynar_t attachedStorages(); + std::vector attachedStorages(); /** Get an associative list [mount point]->[Storage] of all local mount points. * diff --git a/src/bindings/java/jmsg_host.cpp b/src/bindings/java/jmsg_host.cpp index f3f0fc5f2b..6a095c5e2e 100644 --- a/src/bindings/java/jmsg_host.cpp +++ b/src/bindings/java/jmsg_host.cpp @@ -272,15 +272,13 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_getAttachedStorage(JNIE } jobjectArray jtable; - xbt_dynar_t dyn = MSG_host_get_attached_storage_list(host); - int count = xbt_dynar_length(dyn); - jclass cls = jxbt_get_class(env, "java/lang/String"); - jtable = env->NewObjectArray((jsize) count, cls, nullptr); - int index; - char *storage_name; + xbt_dynar_t dyn = sg_host_get_attached_storage_list(host); + jclass cls = jxbt_get_class(env, "java/lang/String"); + jtable = env->NewObjectArray(static_cast(xbt_dynar_length(dyn)), cls, nullptr); + unsigned int index; + const char* storage_name; jstring jstorage_name; - for (index = 0; index < count; index++) { - storage_name = xbt_dynar_get_as(dyn,index,char*); + xbt_dynar_foreach (dyn, index, storage_name) { jstorage_name = env->NewStringUTF(storage_name); env->SetObjectArrayElement(jtable, index, jstorage_name); } diff --git a/src/msg/msg_host.cpp b/src/msg/msg_host.cpp index e8f65182b5..3d68513d29 100644 --- a/src/msg/msg_host.cpp +++ b/src/msg/msg_host.cpp @@ -5,6 +5,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/s4u/host.hpp" +#include "simgrid/s4u/storage.hpp" #include "src/msg/msg_private.h" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg); @@ -255,8 +256,7 @@ xbt_dict_t MSG_host_get_mounted_storage_list(msg_host_t host) */ xbt_dynar_t MSG_host_get_attached_storage_list(msg_host_t host) { - xbt_assert((host != nullptr), "Invalid parameters"); - return host->attachedStorages(); + return sg_host_get_attached_storage_list(host); } /** \ingroup m_host_management diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index d821972504..dcfa890cd1 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -257,7 +257,7 @@ xbt_dict_t Host::mountedStoragesAsDict() * \brief Returns the list of storages attached to an host. * \return a dict containing all storages attached to the host */ -xbt_dynar_t Host::attachedStorages() +std::vector Host::attachedStorages() { return simgrid::simix::kernelImmediate([this] { return this->pimpl_->getAttachedStorageList(); diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 901e0bd5fe..51bc85ed23 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -121,10 +121,12 @@ xbt_dict_t sg_host_get_mounted_storage_list(sg_host_t host){ } xbt_dynar_t sg_host_get_attached_storage_list(sg_host_t host){ - return host->pimpl_->getAttachedStorageList(); + xbt_dynar_t storage_dynar = xbt_dynar_new(sizeof(const char*), nullptr); + for (auto name : host->attachedStorages()) + xbt_dynar_push(storage_dynar, &name); + return storage_dynar; } - // =========== user-level functions =============== // ================================================ /** @brief Returns the total speed of a host */ diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index d74dfd2f91..5366a5d6fb 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -138,19 +138,19 @@ xbt_dict_t HostImpl::getMountedStorageList() return storage_list; } -xbt_dynar_t HostImpl::getAttachedStorageList() +std::vector HostImpl::getAttachedStorageList() { xbt_lib_cursor_t cursor; char* key; void** data; - xbt_dynar_t result = xbt_dynar_new(sizeof(void*), nullptr); + std::vector result; xbt_lib_foreach(storage_lib, cursor, key, data) { if (xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL) != nullptr) { simgrid::surf::Storage* storage = static_cast( xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL)); if (!strcmp(static_cast(storage->attach_), piface_->cname())) { - xbt_dynar_push_as(result, void*, (void*)storage->cname()); + result.push_back(storage->cname()); } } } diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 70887a8b44..4c28215202 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -73,7 +73,7 @@ public: virtual xbt_dict_t getMountedStorageList(); /** @brief Get the xbt_dynar_t of storages attached to the Host */ - virtual xbt_dynar_t getAttachedStorageList(); + virtual std::vector getAttachedStorageList(); /** * @brief Open a file