Avoid manual memory management of rd_file_kw#1243
Merged
Merged
Conversation
f939881 to
7133723
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors the rd_file_kw/rd_file_view internals to avoid manual lifetime management of keyword wrappers by introducing a C++ FileKW class (smart-pointer based) and updating call sites to use it, while removing the old transaction-based unloading mechanism.
Changes:
- Replace
rd_file_kw_type+ transaction ref-counting withFileKWand a newrd_file_view_clear()-based unloading approach. - Update
rd_file_viewto store keywords asstd::shared_ptr<FileKW>and children asstd::unique_ptr, and adjust loaders/users accordingly. - Update/trim tests and CMake targets to reflect the new API (including removing the legacy
test_transactions).
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/tests/test_well_info.cpp | Removes a lazy-loading test (suggest re-adding coverage for new clear-based unloading). |
| lib/tests/test_rd_file_kw.cpp | Updates test to use FileKW wrapper and method-based write path. |
| lib/resdata/well_info.cpp | Replaces transaction guard with rd_file_view_clear() guard between UNRST blocks. |
| lib/resdata/tests/test_transactions.cpp | Removes legacy transaction test executable. |
| lib/resdata/tests/rd_file_view.cpp | Updates tests to FileKW but drops read/round-trip coverage (should be restored). |
| lib/resdata/rd_unsmry_loader.cpp | Updates keyword header comparisons to use FileKW::get_header(). |
| lib/resdata/rd_file.cpp | Switches to inv_map_type allocation via new/delete, uses FileKW and shared_ptr in scan/save flows. |
| lib/resdata/rd_file_view.cpp | Migrates view storage to shared_ptr<FileKW>, removes transactions, adds rd_file_view_clear(), updates indexing/IO. |
| lib/resdata/rd_file_kw.cpp | Introduces FileKW implementation including serialization and lazy loading. |
| lib/include/resdata/rd_file_view.hpp | Updates public API: adds rd_file_view_clear, moves iget_file_kw/add_kw to C++-only section, defines inv_map_type. |
| lib/include/resdata/rd_file_kw.hpp | Adds FileKW class declaration; removes legacy C-style API. |
| lib/CMakeLists.txt | Removes test_transactions from the build. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1841d8f to
2d27fc2
Compare
a98657e to
fcf70db
Compare
fcf70db to
bb9da9e
Compare
3175e70 to
39e15d3
Compare
39e15d3 to
591cd9f
Compare
591cd9f to
010b4fc
Compare
010b4fc to
2080575
Compare
This moves the responsibility of updating inv_map to file_view, which enables us to drop cleared keywords from inv_map. It also changes the memory management of file_list to use shared_ptr. Before the memory management would be done by choosing one file_view to own the references while other might get a non-owning reference. This avoids this brittle pattern by just using a shared_ptr.
fb673fb to
444b773
Compare
444b773 to
20c39ef
Compare
3e171dd to
9974cf4
Compare
This also changes the checked_alloc so that it correctly handles the num==0 case which where std::(re|m|c)alloc has implementation-defined behavior: either return nullptr or a memory segment that cannot be accessed but must be freed. By returning nullptr, if the caller handled the num==0 correctly, they can used the checked version.
9974cf4 to
c5ca1e4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.