fix(gsc): use vector for rawfile (#64)
This commit is contained in:
parent
817c07dabf
commit
f99a56542a
@ -605,23 +605,22 @@ auto context::make_token(std::string_view str) const -> std::string
|
||||
|
||||
auto context::load_header(std::string const& name) -> std::tuple<std::string const*, char const*, usize>
|
||||
{
|
||||
// todo: remove cache to prevent use after free if files are read from fs by the game
|
||||
auto const itr = header_files_.find(name);
|
||||
|
||||
if (itr != header_files_.end())
|
||||
{
|
||||
return { &itr->first, reinterpret_cast<char const*>(itr->second.data), itr->second.size };
|
||||
return { &itr->first, reinterpret_cast<char const*>(itr->second.data()), itr->second.size() };
|
||||
}
|
||||
|
||||
auto data = fs_callback_(name);
|
||||
|
||||
if (data.first.data != nullptr && data.first.size != 0 && data.second.size() == 0)
|
||||
if (data.first.data == nullptr && data.first.size == 0 && !data.second.empty())
|
||||
{
|
||||
auto const res = header_files_.insert({ name, data.first });
|
||||
auto const res = header_files_.insert({ name, std::move(data.second) });
|
||||
|
||||
if (res.second)
|
||||
{
|
||||
return { &res.first->first, reinterpret_cast<char const*>(res.first->second.data), res.first->second.size };
|
||||
return { &res.first->first, reinterpret_cast<char const*>(res.first->second.data()), res.first->second.size() };
|
||||
}
|
||||
}
|
||||
|
||||
@ -644,13 +643,13 @@ auto context::load_include(std::string const& name) -> bool
|
||||
|
||||
auto file = fs_callback_(name);
|
||||
|
||||
if (file.first.data == nullptr && file.first.size == 0)
|
||||
if ((file.first.data == nullptr || file.first.size == 0) && file.second.empty())
|
||||
throw std::runtime_error("empty file");
|
||||
|
||||
if (file.second.size() == 0)
|
||||
if (file.first.data == nullptr && file.first.size == 0 && !file.second.empty())
|
||||
{
|
||||
// process RawFile
|
||||
auto prog = source_.parse_program(name, file.first);
|
||||
auto prog = source_.parse_program(name, file.second);
|
||||
|
||||
auto funcs = std::vector<std::string>{};
|
||||
|
||||
|
@ -126,7 +126,7 @@ protected:
|
||||
std::unordered_map<std::string_view, u32> token_map_rev_;
|
||||
std::unordered_map<u64, std::string_view> path_map_;
|
||||
std::unordered_map<u64, std::string_view> hash_map_;
|
||||
std::unordered_map<std::string, buffer> header_files_;
|
||||
std::unordered_map<std::string, std::vector<u8>> header_files_;
|
||||
std::unordered_set<std::string_view> includes_;
|
||||
std::unordered_map<std::string, std::vector<std::string>> include_cache_;
|
||||
std::unordered_set<std::string> new_func_map_;
|
||||
|
@ -457,12 +457,7 @@ auto fs_callback(std::string const& name) -> std::pair<buffer, std::vector<u8>>
|
||||
}
|
||||
else
|
||||
{
|
||||
auto res = files.insert({ name, std::move(data) });
|
||||
|
||||
if(res.second)
|
||||
{
|
||||
return { {res.first->second.data(), res.first->second.size() }, {} };
|
||||
}
|
||||
return { {}, std::move(data) };
|
||||
}
|
||||
|
||||
throw std::runtime_error("file read error");
|
||||
|
Loading…
Reference in New Issue
Block a user