Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make Datatype::name_ and Win::name_ a std::string.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 23 Nov 2020 15:37:21 +0000 (16:37 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 23 Nov 2020 20:42:08 +0000 (21:42 +0100)
src/smpi/include/smpi_datatype.hpp
src/smpi/include/smpi_win.hpp
src/smpi/mpi/smpi_datatype.cpp
src/smpi/mpi/smpi_win.cpp

index f55d2a8..dace552 100644 (file)
@@ -89,7 +89,7 @@ class Datatype_contents {
 };
 
 class Datatype : public F2C, public Keyval{
-  char* name_ = nullptr;
+  std::string name_ = "";
   /* The id here is the (unique) datatype id used for this datastructure.
    * It's default value is set to -1 since some code expects this return value
    * when no other id has been assigned
@@ -115,7 +115,7 @@ public:
   Datatype& operator=(const Datatype&) = delete;
   ~Datatype() override;
 
-  char* name() const { return name_; }
+  const char* name() const { return name_.c_str(); }
   size_t size() const { return size_; }
   MPI_Aint lb() const { return lb_; }
   MPI_Aint ub() const { return ub_; }
index cb84e72..7e40d29 100644 (file)
@@ -29,7 +29,7 @@ class Win : public F2C, public Keyval {
   s4u::MutexPtr mut_;
   s4u::Barrier* bar_;
   MPI_Win* connected_wins_;
-  char* name_;
+  std::string name_;
   int opened_;
   MPI_Group group_;
   int count_; //for ordering the accs
index 3f770e9..85d16a6 100644 (file)
@@ -151,7 +151,6 @@ Datatype::~Datatype()
 
   cleanup_attr<Datatype>();
   delete contents_;
-  xbt_free(name_);
 }
 
 int Datatype::copy_attrs(Datatype* datatype){
@@ -261,18 +260,16 @@ int Datatype::extent(MPI_Aint* lb, MPI_Aint* extent) const
 
 void Datatype::get_name(char* name, int* length) const
 {
-  if(name_!=nullptr){
-    *length = strlen(name_);
-    strncpy(name, name_, *length+1);
-  }else{
-    *length = 0;
+  *length = name_.length();
+  if (not name_.empty()) {
+    name_.copy(name, *length);
+    name[*length] = '\0';
   }
 }
 
-void Datatype::set_name(const char* name){
-  if(name_!=nullptr &&  (flags_ & DT_FLAG_PREDEFINED) == 0)
-    xbt_free(name_);
-  name_ = xbt_strdup(name);
+void Datatype::set_name(const char* name)
+{
+  name_ = name;
 }
 
 int Datatype::pack(const void* inbuf, int incount, void* outbuf, int outcount, int* position, const Comm*)
index 6f1245e..73bd32d 100644 (file)
@@ -36,7 +36,6 @@ Win::Win(void* base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm,
   if(info!=MPI_INFO_NULL)
     info->ref();
   int comm_size          = comm->size();
-  name_                  = nullptr;
   opened_                = 0;
   group_                 = MPI_GROUP_NULL;
   requests_              = new std::vector<MPI_Request>();
@@ -72,9 +71,6 @@ Win::~Win(){
 
   delete requests_;
   delete[] connected_wins_;
-  if (name_ != nullptr){
-    xbt_free(name_);
-  }
   if (info_ != MPI_INFO_NULL)
     simgrid::smpi::Info::unref(info_);
   if (errhandler_ != MPI_ERRHANDLER_NULL)
@@ -112,13 +108,11 @@ int Win::detach(const void* /*base*/)
 
 void Win::get_name(char* name, int* length) const
 {
-  if(name_==nullptr){
-    *length=0;
-    name=nullptr;
-    return;
+  *length = name_.length();
+  if (not name_.empty()) {
+    name_.copy(name, *length);
+    name[*length] = '\0';
   }
-  *length = strlen(name_);
-  strncpy(name, name_, *length+1);
 }
 
 void Win::get_group(MPI_Group* group){
@@ -172,7 +166,7 @@ void Win::set_info(MPI_Info info)
 }
 
 void Win::set_name(const char* name){
-  name_ = xbt_strdup(name);
+  name_ = name;
 }
 
 int Win::fence(int assert)