summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2025-01-20 21:28:25 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2025-01-22 08:12:57 +0100
commite0009216ee830e8da023047ed6fe187f48f612d1 (patch)
tree33961e665fda1e9a93c90385f7d65f01963e3398
parent3438b4d3eb272c301e28af7cb72c6d2adb0e6597 (diff)
Don't return const ref strings in ctor::configuration::get. Instead return std::string by copy.
-rw-r--r--src/bootstrap.cc17
-rw-r--r--src/configure.cc2
-rw-r--r--src/ctor.h2
-rw-r--r--test/tools_test.cc14
4 files changed, 12 insertions, 23 deletions
diff --git a/src/bootstrap.cc b/src/bootstrap.cc
index aa50561..0179f7b 100644
--- a/src/bootstrap.cc
+++ b/src/bootstrap.cc
@@ -41,41 +41,36 @@ bool ctor::configuration::has(const std::string& key) const
return false;
}
-const std::string& ctor::configuration::get(const std::string& key, const std::string& default_value) const
+std::string ctor::configuration::get(const std::string& key, const std::string& default_value) const
{
auto cxx_env = std::getenv("CXX");
if(key == ctor::cfg::build_cxx && cxx_env)
{
- static std::string s = cxx_env;
- return s;
+ return cxx_env;
}
auto cc_env = std::getenv("CC");
if(key == ctor::cfg::build_cc && cc_env)
{
- static std::string s = cc_env;
- return s;
+ return cc_env;
}
auto ld_env = std::getenv("LD");
if(key == ctor::cfg::build_ld && ld_env)
{
- static std::string s = ld_env;
- return s;
+ return ld_env;
}
auto ar_env = std::getenv("AR");
if(key == ctor::cfg::build_ar && ar_env)
{
- static std::string s = ar_env;
- return s;
+ return ar_env;
}
auto builddir_env = std::getenv("BUILDDIR");
if(key == ctor::cfg::builddir && builddir_env)
{
- static std::string s = builddir_env;
- return s;
+ return builddir_env;
}
return default_value;
diff --git a/src/configure.cc b/src/configure.cc
index 553e368..7a68f03 100644
--- a/src/configure.cc
+++ b/src/configure.cc
@@ -69,7 +69,7 @@ bool ctor::configuration::has(const std::string& key) const
return tools.find(key) != tools.end();
}
-const std::string& ctor::configuration::get(const std::string& key, const std::string& default_value) const
+std::string ctor::configuration::get(const std::string& key, const std::string& default_value) const
{
if(key == ctor::cfg::ctor_includedir && ctor::includedir)
{
diff --git a/src/ctor.h b/src/ctor.h
index 3c0b303..6f21aca 100644
--- a/src/ctor.h
+++ b/src/ctor.h
@@ -283,7 +283,7 @@ constexpr auto ctor_libdir = "ctor-libdir";
struct configuration
{
bool has(const std::string& key) const;
- const std::string& get(const std::string& key, const std::string& default_value = {}) const;
+ std::string get(const std::string& key, const std::string& default_value = {}) const;
ctor::toolchain host_toolchain{ctor::toolchain::none};
ctor::arch host_arch{ctor::arch::unknown};
diff --git a/test/tools_test.cc b/test/tools_test.cc
index a428ea1..46ab084 100644
--- a/test/tools_test.cc
+++ b/test/tools_test.cc
@@ -114,33 +114,27 @@ bool operator!=(const ctor::asm_flag& a, const ctor::asm_flag& b)
#include <uunit.h>
-namespace {
-std::string conf_host_cxx{};
-std::string conf_build_cxx{};
-}
-
const ctor::configuration& ctor::get_configuration()
{
static ctor::configuration cfg;
return cfg;
}
-const std::string& ctor::configuration::get(const std::string& key, const std::string& defval) const
+std::string ctor::configuration::get(const std::string& key, [[maybe_unused]]const std::string& default_value) const
{
if(key == ctor::cfg::host_cxx)
{
- return conf_host_cxx;
+ return {};
}
if(key == ctor::cfg::build_cxx)
{
- return conf_build_cxx;
+ return {};
}
assert(false); // bad key
- static std::string res{};
- return res;
+ return {};
}
class ToolsTest