From: Gabriel Corona Date: Fri, 15 Jan 2016 11:07:38 +0000 (+0100) Subject: [s4u] Do not use containers of references X-Git-Tag: v3_13~1237^2~5 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/2bdebbaf8391c3b5dc1cd193491504f83bb2ea3e?hp=c257b6f70c01d5107ea6e9d9ebd858f99d42b31a [s4u] Do not use containers of references Containers are not allowes to hold references. --- diff --git a/examples/s4u/io/s4u_io_test.cpp b/examples/s4u/io/s4u_io_test.cpp index 846ac4c735..4f2e993d06 100644 --- a/examples/s4u/io/s4u_io_test.cpp +++ b/examples/s4u/io/s4u_io_test.cpp @@ -16,13 +16,13 @@ public: myHost(const char*procname, simgrid::s4u::Host *host,int argc, char **argv) : simgrid::s4u::Actor(procname,host,argc,argv){} - void show_info(boost::unordered_map &mounts) { + void show_info(boost::unordered_map &mounts) { XBT_INFO("Storage info on %s:", simgrid::s4u::Host::current()->name().c_str()); for (const auto&kv : mounts) { const char* mountpoint = kv.first.c_str(); - simgrid::s4u::Storage &storage = kv.second; + simgrid::s4u::Storage &storage = *kv.second; // Retrieve disk's information sg_size_t free_size = storage.size_free(); @@ -35,7 +35,7 @@ public: } int main(int argc, char **argv) { - boost::unordered_map &mounts = + boost::unordered_map & mounts = simgrid::s4u::Host::current()->mountedStorages(); show_info(mounts); diff --git a/include/simgrid/s4u/host.hpp b/include/simgrid/s4u/host.hpp index d5c48344e0..3d32534415 100644 --- a/include/simgrid/s4u/host.hpp +++ b/include/simgrid/s4u/host.hpp @@ -94,11 +94,11 @@ public: * Do not change the returned value in any way. */ // TODO, do not use Storage&, this looks dangerous! - boost::unordered_map &mountedStorages(); + boost::unordered_map &mountedStorages(); private: simgrid::xbt::string name_ = "noname"; - boost::unordered_map *mounts = NULL; // caching + boost::unordered_map *mounts = NULL; // caching void* p_userdata = NULL; public: diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index 9c7ceba0e1..8701353b5d 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -76,9 +76,9 @@ int Host::getNbPStates() const { return this->pimpl_cpu->getNbPStates(); } -boost::unordered_map &Host::mountedStorages() { +boost::unordered_map &Host::mountedStorages() { if (mounts == NULL) { - mounts = new boost::unordered_map (); + mounts = new boost::unordered_map (); xbt_dict_t dict = this->getMountedStorageList(); @@ -86,7 +86,7 @@ boost::unordered_map &Host::mountedStorages() { char *mountname; char *storagename; xbt_dict_foreach(dict, cursor, mountname, storagename) { - mounts->insert({mountname, Storage::byName(storagename)}); + mounts->insert({mountname, &Storage::byName(storagename)}); } xbt_dict_free(&dict); }