commit 68cc20805049c11230b5338e280d8ae02a1540e4
parent 208ecdebacf094fb383c6e399e45db2be72c611b
Author: kyle <kyle@0x30.net>
Date: Fri, 16 Sep 2016 22:32:41 -0600
src: sync c++ with runtime changes
Diffstat:
5 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/src/process_file.cc b/src/process_file.cc
@@ -34,20 +34,17 @@ ProcessFile::ProcessFile(std::string const &path) :
m_shm.read_all(&m_pid);
m_shm.read_all(&m_ppid);
m_shm.read_all(&m_pgrp);
- m_shm.read_cstring(&m_progname);
- m_shm.read_cstring(&m_cwd);
+ m_shm.read_string(m_progname);
+ m_shm.read_string(m_cwd);
m_shm.next_page();
while (m_shm.at_end() == false) {
TranslationUnit t;
- uint8_t ready;
- m_shm.read_all(&ready);
-
m_shm.read_all(&t.num_lines);
- m_shm.read_cstring(&t.comp_file_path);
- m_shm.read_cstring(&t.abs_file_path);
+ m_shm.read_string(t.comp_file_path);
+ m_shm.read_string(t.abs_file_path);
t.exec_diffs = (uint64_t *)m_shm.get_block(t.num_lines * 8);
t.source.resize(t.num_lines);
@@ -75,7 +72,7 @@ ProcessFile::read_source(struct TranslationUnit &t)
std::ifstream file_stream(t.abs_file_path);
if (file_stream.is_open() == 0) {
- warnx("ifstream.open(%s)", t.abs_file_path);
+ warnx("ifstream.open(%s)", t.abs_file_path.c_str());
return;
}
diff --git a/src/process_file.h b/src/process_file.h
@@ -4,8 +4,8 @@
#include "shm.h"
struct TranslationUnit {
- const char *comp_file_path;
- const char *abs_file_path;
+ std::string comp_file_path;
+ std::string abs_file_path;
uint32_t num_lines;
uint8_t has_execs;
uint64_t *exec_diffs;
@@ -27,8 +27,8 @@ public:
uint8_t m_major;
uint8_t m_minor;
- const char *m_progname;
- const char *m_cwd;
+ std::string m_progname;
+ std::string m_cwd;
uint32_t m_pid;
uint32_t m_ppid;
uint32_t m_pgrp;
diff --git a/src/shm.cc b/src/shm.cc
@@ -32,14 +32,23 @@ Shm::Shm(std::string const &path) :
}
void
-Shm::read_cstring(const char **c_str)
+Shm::next_page()
{
- size_t sz = strlen((const char *)m_mem + m_pos) + 1;
- if (sz > 1025)
- errx(1, "read_string: %zu too long", sz);
+ int page_size = getpagesize();
+ m_pos += page_size - (m_pos % page_size);
+}
+
+void
+Shm::read_string(std::string &str)
+{
+ uint16_t len;
+
+ memcpy(&len, m_mem + m_pos, sizeof(len));
+ m_pos += sizeof(len);
- *c_str = (const char *)m_mem + m_pos;
- m_pos += sz;
+ str.resize(len);
+ memcpy(&str[0], m_mem + m_pos, len);
+ m_pos += len;
}
void *
diff --git a/src/shm.h b/src/shm.h
@@ -16,13 +16,8 @@ public:
m_pos += sizeof(T);
};
- void next_page()
- {
- int page_size = getpagesize();
- m_pos += page_size - (m_pos % page_size);
- }
-
- void read_cstring(const char **);
+ void next_page();
+ void read_string(std::string &);
void *get_block(size_t);
bool at_end();
diff --git a/src/term_main.cc b/src/term_main.cc
@@ -161,8 +161,8 @@ CursesViewer::print_statusbar()
}
printw(" [%s] [%s] [%i/%i] [%i fps] [%ik execs/s]",
- m_cur_pfile->m_progname,
- m_cur_tu.comp_file_path,
+ m_cur_pfile->m_progname.c_str(),
+ m_cur_tu.comp_file_path.c_str(),
m_tu + 1, m_cur_pfile->m_tus.size(),
m_fps,
m_eps / 1000);