From 7164761a9bba82982c6fd045bd27ccccc0075b15 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sat, 14 Oct 2017 23:24:33 +0200 Subject: [PATCH] Use a C++ string instead of char* for mailbox name. --- src/kernel/activity/MailboxImpl.cpp | 4 ++-- src/kernel/activity/MailboxImpl.hpp | 7 +++---- src/mc/checker/CommunicationDeterminismChecker.cpp | 4 +++- src/s4u/s4u_mailbox.cpp | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/kernel/activity/MailboxImpl.cpp b/src/kernel/activity/MailboxImpl.cpp index 13e9870ee1..d2f181176f 100644 --- a/src/kernel/activity/MailboxImpl.cpp +++ b/src/kernel/activity/MailboxImpl.cpp @@ -73,14 +73,14 @@ void MailboxImpl::remove(smx_activity_t activity) boost::static_pointer_cast(activity); xbt_assert(comm->mbox == this, "Comm %p is in mailbox %s, not mailbox %s", comm.get(), - (comm->mbox ? comm->mbox->name_ : "(null)"), this->name_); + (comm->mbox ? comm->mbox->name_.c_str() : "(null)"), this->name_.c_str()); comm->mbox = nullptr; for (auto it = this->comm_queue.begin(); it != this->comm_queue.end(); it++) if (*it == comm) { this->comm_queue.erase(it); return; } - xbt_die("Comm %p not found in mailbox %s", comm.get(), this->name_); + xbt_die("Comm %p not found in mailbox %s", comm.get(), this->name_.c_str()); } } } diff --git a/src/kernel/activity/MailboxImpl.hpp b/src/kernel/activity/MailboxImpl.hpp index 8c4541d611..6c9ee329ed 100644 --- a/src/kernel/activity/MailboxImpl.hpp +++ b/src/kernel/activity/MailboxImpl.hpp @@ -7,6 +7,7 @@ #define SIMIX_MAILBOXIMPL_H #include +#include #include "simgrid/s4u/Mailbox.hpp" #include "src/kernel/activity/CommImpl.hpp" @@ -21,20 +22,18 @@ namespace activity { class MailboxImpl { explicit MailboxImpl(const char* name) - : piface_(this), name_(xbt_strdup(name)), comm_queue(MAX_MAILBOX_SIZE), done_comm_queue(MAX_MAILBOX_SIZE) + : piface_(this), name_(name), comm_queue(MAX_MAILBOX_SIZE), done_comm_queue(MAX_MAILBOX_SIZE) { } public: - ~MailboxImpl() { xbt_free(name_); } - static MailboxImpl* byNameOrNull(const char* name); static MailboxImpl* byNameOrCreate(const char* name); void setReceiver(s4u::ActorPtr actor); void push(activity::CommImplPtr comm); void remove(smx_activity_t activity); simgrid::s4u::Mailbox piface_; // Our interface - char* name_; + simgrid::xbt::string name_; simgrid::simix::ActorImplPtr permanent_receiver; // process which the mailbox is attached to boost::circular_buffer_space_optimized comm_queue; diff --git a/src/mc/checker/CommunicationDeterminismChecker.cpp b/src/mc/checker/CommunicationDeterminismChecker.cpp index 6c50eb7eea..7fb06e5f04 100644 --- a/src/mc/checker/CommunicationDeterminismChecker.cpp +++ b/src/mc/checker/CommunicationDeterminismChecker.cpp @@ -236,7 +236,9 @@ void CommunicationDeterminismChecker::get_comm_pattern(xbt_dynar_t list, smx_sim simgrid::kernel::activity::CommImpl* comm = temp_comm.getBuffer(); char* remote_name; - mc_model_checker->process().read(&remote_name, remote(comm->mbox ? &comm->mbox->name_ : &comm->mbox_cpy->name_)); + mc_model_checker->process().read( + &remote_name, remote(comm->mbox ? &simgrid::xbt::string::to_string_data(comm->mbox->name_).data + : &simgrid::xbt::string::to_string_data(comm->mbox_cpy->name_).data)); pattern->rdv = mc_model_checker->process().read_string(remote_name); pattern->dst_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->dst_proc))->pid; pattern->dst_host = MC_smx_actor_get_host_name(issuer); diff --git a/src/s4u/s4u_mailbox.cpp b/src/s4u/s4u_mailbox.cpp index 5a594bcbb7..a3dbf166c0 100644 --- a/src/s4u/s4u_mailbox.cpp +++ b/src/s4u/s4u_mailbox.cpp @@ -18,7 +18,7 @@ namespace s4u { const char* Mailbox::getName() { - return pimpl_->name_; + return pimpl_->name_.c_str(); } MailboxPtr Mailbox::byName(const char*name) -- 2.20.1