mirror of
https://github.com/ModOrganizer2/mob.git
synced 2026-07-27 14:07:05 -07:00
fixed env::copy_for_write() not clearing sys_, would contain old variables
This commit is contained in:
+16
-5
@@ -268,6 +268,15 @@ std::string env::get(std::string_view k) const
|
||||
return utf16_to_utf8(*current);
|
||||
}
|
||||
|
||||
env::map env::get_map() const
|
||||
{
|
||||
if (!data_)
|
||||
return {};
|
||||
|
||||
std::scoped_lock lock(data_->m);
|
||||
return data_->vars;
|
||||
}
|
||||
|
||||
void env::set_from(const env& e)
|
||||
{
|
||||
copy_for_write();
|
||||
@@ -337,18 +346,20 @@ void* env::get_unicode_pointers() const
|
||||
void env::copy_for_write()
|
||||
{
|
||||
if (own_)
|
||||
{
|
||||
if (data_)
|
||||
data_->sys.clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (data_)
|
||||
{
|
||||
auto shared = data_;
|
||||
data_.reset(new data);
|
||||
data_->vars = shared->vars;
|
||||
|
||||
{
|
||||
std::scoped_lock lock(shared->m);
|
||||
data_->sys = shared->sys;
|
||||
}
|
||||
std::scoped_lock lock(shared->m);
|
||||
data_->vars = shared->vars;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace mob
|
||||
class env
|
||||
{
|
||||
public:
|
||||
using map = std::map<std::wstring, std::wstring>;
|
||||
|
||||
enum flags
|
||||
{
|
||||
replace = 1,
|
||||
@@ -36,12 +38,11 @@ public:
|
||||
void set_from(const env& e);
|
||||
|
||||
std::string get(std::string_view k) const;
|
||||
map get_map() const;
|
||||
|
||||
void* get_unicode_pointers() const;
|
||||
|
||||
private:
|
||||
using map = std::map<std::wstring, std::wstring>;
|
||||
|
||||
struct data
|
||||
{
|
||||
std::mutex m;
|
||||
|
||||
Reference in New Issue
Block a user