Skip to content

Commit f6f432a

Browse files
authored
Merge pull request #224 from tetengo/search_dict_c
Correct the file mapping lifetime #223
2 parents de1f634 + 7e2969e commit f6f432a

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

library/trie/c/src/tetengo_trie_storage.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
struct tetengo_trie_storage_tag
2020
{
21-
private:
21+
public:
2222
std::unique_ptr<boost::interprocess::file_mapping> p_cpp_file_mapping;
2323

24+
private:
2425
const tetengo::trie::storage* p_cpp_storage_referred;
2526

2627
public:

library/trie/c/src/tetengo_trie_trie.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ tetengo_trie_trie_t* tetengo_trie_trie_createWithStorage(tetengo_trie_storage_t*
113113
}
114114

115115
auto p_cpp_trie = std::make_unique<cpp_trie_type>(std::move(p_storage->p_cpp_storage_owned));
116+
auto p_cpp_file_mapping = std::move(p_storage->p_cpp_file_mapping);
116117
tetengo_trie_storage_destroy(p_storage);
117118

118-
auto p_instance = std::make_unique<tetengo_trie_trie_t>(std::move(p_cpp_trie));
119+
auto p_instance = std::make_unique<tetengo_trie_trie_t>(std::move(p_cpp_trie), std::move(p_cpp_file_mapping));
119120
return p_instance.release();
120121
}
121122
catch (...)

library/trie/c/src/tetengo_trie_trie.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,21 @@ struct tetengo_trie_trie_tag
2424
{
2525
std::unique_ptr<cpp_trie_type> p_cpp_trie;
2626

27+
std::unique_ptr<boost::interprocess::file_mapping> p_cpp_file_mapping;
28+
2729
std::unique_ptr<tetengo_trie_storage_t> p_storage;
2830

2931
tetengo_trie_trie_tag(std::unique_ptr<cpp_trie_type>&& p_cpp_trie) :
3032
p_cpp_trie{ std::move(p_cpp_trie) },
33+
p_cpp_file_mapping{},
34+
p_storage{}
35+
{}
36+
37+
tetengo_trie_trie_tag(
38+
std::unique_ptr<cpp_trie_type>&& p_cpp_trie,
39+
std::unique_ptr<boost::interprocess::file_mapping> p_cpp_file_mapping) :
40+
p_cpp_trie{ std::move(p_cpp_trie) },
41+
p_cpp_file_mapping{ std::move(p_cpp_file_mapping) },
3142
p_storage{}
3243
{}
3344

0 commit comments

Comments
 (0)