summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/log.cc2
-rw-r--r--kernel/rtlil.cc2
-rw-r--r--kernel/yosys.h11
3 files changed, 13 insertions, 2 deletions
diff --git a/kernel/log.cc b/kernel/log.cc
index dbc94ce8..91d85772 100644
--- a/kernel/log.cc
+++ b/kernel/log.cc
@@ -52,7 +52,7 @@ string log_last_error;
vector<int> header_count;
pool<RTLIL::IdString> log_id_cache;
-vector<string> string_buf;
+vector<shared_str> string_buf;
int string_buf_index = -1;
static struct timeval initial_tv = { 0, 0 };
diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc
index 373a3a5e..5deef850 100644
--- a/kernel/rtlil.cc
+++ b/kernel/rtlil.cc
@@ -147,7 +147,7 @@ RTLIL::Const RTLIL::Const::from_string(std::string str)
std::string RTLIL::Const::decode_string() const
{
std::string string;
- std::vector <char> string_chars;
+ std::vector<char> string_chars;
for (int i = 0; i < int (bits.size()); i += 8) {
char ch = 0;
for (int j = 0; j < 8 && i + j < int (bits.size()); j++)
diff --git a/kernel/yosys.h b/kernel/yosys.h
index db8161c5..14277ade 100644
--- a/kernel/yosys.h
+++ b/kernel/yosys.h
@@ -140,6 +140,17 @@ using std::vector;
using std::string;
using std::pair;
+// A primitive shared string implementation that does not
+// move its .c_str() when the object is copied or moved.
+struct shared_str {
+ std::shared_ptr<string> content;
+ shared_str() { }
+ shared_str(string s) { content = std::shared_ptr<string>(new string(s)); }
+ shared_str(const char *s) { content = std::shared_ptr<string>(new string(s)); }
+ const char *c_str() { return content->c_str(); }
+ const string &str() { return *content; }
+};
+
using hashlib::mkhash;
using hashlib::mkhash_init;
using hashlib::mkhash_add;