From c633850c450067d7d5f6d4b6e1b93e14e76b29eb Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Mon, 19 Jun 2017 13:12:19 +0200 Subject: [PATCH] fix test (hate dict) and please sonar --- examples/msg/io-storage/io-storage.c | 2 +- include/simgrid/s4u/File.hpp | 2 +- src/msg/msg_io.cpp | 8 +++++--- src/s4u/s4u_file.cpp | 3 +-- src/s4u/s4u_storage.cpp | 3 +-- src/surf/StorageImpl.cpp | 6 ++---- src/surf/StorageImpl.hpp | 2 +- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/examples/msg/io-storage/io-storage.c b/examples/msg/io-storage/io-storage.c index e4075c12e4..4d5b34ff26 100644 --- a/examples/msg/io-storage/io-storage.c +++ b/examples/msg/io-storage/io-storage.c @@ -104,7 +104,7 @@ static int host(int argc, char *argv[]){ xbt_dict_foreach(contents, curs, mountname, content){ XBT_INFO("Print the content of mount point: %s",mountname); xbt_dict_foreach(content,curs2,path,size){ - XBT_INFO("%s size: %llu bytes", path, (sg_size_t)size); + XBT_INFO("%s size: %llu bytes", path, *(sg_size_t*)size); } xbt_dict_free(&content); } diff --git a/include/simgrid/s4u/File.hpp b/include/simgrid/s4u/File.hpp index 27dbf56a79..75050dd680 100644 --- a/include/simgrid/s4u/File.hpp +++ b/include/simgrid/s4u/File.hpp @@ -76,10 +76,10 @@ public: int desc_id = 0; private: - sg_host_t host_ = nullptr; smx_file_t pimpl_ = nullptr; const char* path_ = nullptr; void* userdata_ = nullptr; + sg_host_t host_ = nullptr; }; } } // namespace simgrid::s4u diff --git a/src/msg/msg_io.cpp b/src/msg/msg_io.cpp index 7aa6b09209..bfb2f3d979 100644 --- a/src/msg/msg_io.cpp +++ b/src/msg/msg_io.cpp @@ -295,7 +295,7 @@ msg_error_t MSG_file_rcopy (msg_file_t file, msg_host_t host, const char* fullpa } } - if (longest_prefix_length > 0) { + if (storage_dest != nullptr) { /* Mount point found, retrieve the host the storage is attached to */ dst_host = storage_dest->host(); }else{ @@ -472,10 +472,12 @@ void *MSG_storage_get_data(msg_storage_t storage) xbt_dict_t MSG_storage_get_content(msg_storage_t storage) { std::map* content = storage->content(); - xbt_dict_t content_dict = xbt_dict_new_homogeneous(nullptr); + xbt_dict_t content_dict = xbt_dict_new_homogeneous(&free); for (auto entry : *content) { - xbt_dict_set(content_dict, entry.first.c_str(), (void*)entry.second, nullptr); + sg_size_t* psize = new sg_size_t; + *psize = entry.second; + xbt_dict_set(content_dict, entry.first.c_str(), psize, nullptr); } return content_dict; } diff --git a/src/s4u/s4u_file.cpp b/src/s4u/s4u_file.cpp index ec8cd7cd48..3296ba1dd0 100644 --- a/src/s4u/s4u_file.cpp +++ b/src/s4u/s4u_file.cpp @@ -17,7 +17,7 @@ namespace s4u { File::File(const char* fullpath, void* userdata) : File(fullpath, Host::current(), userdata){}; -File::File(const char* fullpath, sg_host_t host, void* userdata) : path_(fullpath), userdata_(userdata) +File::File(const char* fullpath, sg_host_t host, void* userdata) : path_(fullpath), userdata_(userdata), host_(host) { // this cannot fail because we get a xbt_die if the mountpoint does not exist Storage* st = nullptr; @@ -42,7 +42,6 @@ File::File(const char* fullpath, sg_host_t host, void* userdata) : path_(fullpat xbt_die("Can't find mount point for '%s' on '%s'", fullpath, host->cname()); pimpl_ = simcall_file_open(mount_point.c_str(), path.c_str(), st); - host_ = host; storage_type = st->type(); storageId = st->name(); } diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index b1112a2c76..d10a19d886 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -12,7 +12,6 @@ namespace simgrid { namespace s4u { -// attached_to_ = Host::by_name_or_null(pimpl->attach_); std::map* allStorages() { std::unordered_map* map = surf::StorageImpl::storagesMap(); @@ -38,7 +37,7 @@ const char* Storage::name() const char* Storage::type() { - return pimpl_->typeId_; + return pimpl_->typeId_.c_str(); } Host* Storage::host() diff --git a/src/surf/StorageImpl.cpp b/src/surf/StorageImpl.cpp index a6b13179b0..95c0ffe301 100644 --- a/src/surf/StorageImpl.cpp +++ b/src/surf/StorageImpl.cpp @@ -64,11 +64,11 @@ StorageImpl::StorageImpl(Model* model, const char* name, lmm_system_t maxminSyst , piface_(this) , size_(size) , usedSize_(0) - , typeId_(xbt_strdup(type_id)) + , typeId_(type_id) + , attach_(attach) , writeActions_(std::vector()) { content_ = parseContent(content_name); - attach_ = attach; turnOn(); XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size); constraintRead_ = lmm_constraint_new(maxminSystem, this, bread); @@ -81,8 +81,6 @@ StorageImpl::~StorageImpl() storageDestructedCallbacks(this); if (content_ != nullptr) delete content_; - - free(typeId_); } std::map* StorageImpl::parseContent(const char* filename) diff --git a/src/surf/StorageImpl.hpp b/src/surf/StorageImpl.hpp index ac7a6025fa..fbb744956f 100644 --- a/src/surf/StorageImpl.hpp +++ b/src/surf/StorageImpl.hpp @@ -105,7 +105,7 @@ public: std::map* content_; sg_size_t size_; sg_size_t usedSize_; - char* typeId_; + std::string typeId_; std::string attach_; // Name of the host to which this storage is attached. // Only used until the platform is fully parsed only. // Then the interface stores the Host directly. -- 2.20.1