static e_mc_comm_pattern_difference_t compare_comm_pattern(mc_comm_pattern_t comm1, mc_comm_pattern_t comm2) {
if(comm1->type != comm2->type)
return TYPE_DIFF;
- if (strcmp(comm1->rdv, comm2->rdv) != 0)
+ if (comm1->rdv != comm2->rdv)
return RDV_DIFF;
if (comm1->src_proc != comm2->src_proc)
return SRC_PROC_DIFF;
this->read_bytes(target, size, remote(var->address));
}
-char* Process::read_string(RemotePtr<void> address) const
+std::string Process::read_string(RemotePtr<void> address) const
{
if (!address)
- return nullptr;
+ return {};
- off_t len = 128;
- char* res = (char*) malloc(len);
+ std::vector<char> res(128);
off_t off = 0;
while (1) {
- ssize_t c = pread(this->memory_file, res + off, len - off, (off_t) address.address() + off);
+ ssize_t c = pread(this->memory_file, res.data() + off, res.size() - off, (off_t) address.address() + off);
if (c == -1) {
if (errno == EINTR)
continue;
if (c==0)
xbt_die("Could not read string from remote process");
- void* p = memchr(res + off, '\0', c);
+ void* p = memchr(res.data() + off, '\0', c);
if (p)
- return res;
+ return std::string(res.data());
off += c;
- if (off == len) {
- len *= 2;
- res = (char*) realloc(res, len);
- }
+ if (off == (off_t) res.size())
+ res.resize(res.size() * 2);
}
}
#include <type_traits>
#include <vector>
#include <memory>
+#include <string>
#include <sys/types.h>
read_variable(name, &res, sizeof(T));
return res;
}
- char* read_string(RemotePtr<void> address) const;
+ std::string read_string(RemotePtr<void> address) const;
// Write memory:
void write_bytes(const void* buffer, size_t len, RemotePtr<void> address);
res->index = comm->index;
res->type = comm->type;
res->comm_addr = comm->comm_addr;
- res->rdv = xbt_strdup(comm->rdv);
+ res->rdv = comm->rdv;
res->data_size = -1;
res->data = nullptr;
if (comm->type == SIMIX_COMM_SEND) {
#include <cstddef>
#include <cstring>
+#include <string>
+
#include <simgrid_config.h>
#include <xbt/dynar.h>
unsigned long dst_proc = 0;
const char *src_host = nullptr;
const char *dst_host = nullptr;
- char *rdv = nullptr;
+ std::string rdv;
ssize_t data_size = 0;
void *data = nullptr;
int tag = 0;
}
~s_mc_comm_pattern()
{
- xbt_free(this->rdv);
xbt_free(this->data);
}
return nullptr;
simgrid::mc::SimixProcessInformation* info = MC_smx_process_get_info(p);
- if (info->name.empty()) {
- char* name = process->read_string(p->name);
- info->name = name;
- free(name);
- }
+ if (info->name.empty())
+ info->name = process->read_string(p->name);
return info->name.c_str();
}