Skip to content

Avoid manual memory management of rd_file_kw#1243

Merged
eivindjahren merged 15 commits into
mainfrom
fix_manual_memory_in_rd_file_view
Jul 9, 2026
Merged

Avoid manual memory management of rd_file_kw#1243
eivindjahren merged 15 commits into
mainfrom
fix_manual_memory_in_rd_file_view

Conversation

@eivindjahren

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with FileKW and a new rd_file_view_clear()-based unloading approach.
  • Update rd_file_view to store keywords as std::shared_ptr<FileKW> and children as std::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.

Comment thread lib/resdata/rd_file.cpp
Comment thread lib/resdata/rd_file_view.cpp
Comment thread lib/resdata/rd_file_view.cpp
Comment thread lib/resdata/rd_file_view.cpp
Comment thread lib/resdata/rd_file_view.cpp
Comment thread lib/resdata/tests/rd_file_view.cpp Outdated
Comment thread lib/include/resdata/rd_file_kw.hpp Outdated
Comment thread lib/tests/test_well_info.cpp
@eivindjahren eivindjahren force-pushed the fix_manual_memory_in_rd_file_view branch 4 times, most recently from 1841d8f to 2d27fc2 Compare July 8, 2026 12:20
@eivindjahren eivindjahren requested a review from Copilot July 8, 2026 12:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Comment thread lib/include/resdata/rd_file_kw.hpp Outdated
Comment thread lib/resdata/rd_file_view.cpp Outdated
@eivindjahren eivindjahren force-pushed the fix_manual_memory_in_rd_file_view branch 2 times, most recently from a98657e to fcf70db Compare July 8, 2026 12:32
@eivindjahren eivindjahren requested a review from Copilot July 8, 2026 12:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.

Comment thread lib/resdata/rd_file_view.cpp Outdated
Comment thread lib/resdata/rd_file_view.cpp Outdated
Comment thread lib/include/resdata/rd_file_kw.hpp Outdated
Comment thread lib/resdata/rd_file_kw.cpp Outdated
Comment thread lib/resdata/rd_file_kw.cpp Outdated
Comment thread lib/resdata/rd_file_kw.cpp Outdated
@eivindjahren eivindjahren changed the title Avoid manual memory of rd_file_kw Avoid manual memory management of rd_file_kw Jul 9, 2026
@eivindjahren eivindjahren force-pushed the fix_manual_memory_in_rd_file_view branch from fcf70db to bb9da9e Compare July 9, 2026 04:53
@eivindjahren eivindjahren requested a review from Copilot July 9, 2026 04:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Comment thread lib/include/resdata/rd_file_kw.hpp Outdated
@eivindjahren eivindjahren force-pushed the fix_manual_memory_in_rd_file_view branch from 3175e70 to 39e15d3 Compare July 9, 2026 05:29
@eivindjahren eivindjahren requested a review from Copilot July 9, 2026 05:29
@eivindjahren eivindjahren force-pushed the fix_manual_memory_in_rd_file_view branch from 39e15d3 to 591cd9f Compare July 9, 2026 05:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Comment thread lib/resdata/rd_file_kw.cpp Outdated
Comment thread lib/resdata/rd_file.cpp
@eivindjahren eivindjahren force-pushed the fix_manual_memory_in_rd_file_view branch from 591cd9f to 010b4fc Compare July 9, 2026 05:51
@eivindjahren eivindjahren requested a review from Copilot July 9, 2026 05:51
@eivindjahren eivindjahren force-pushed the fix_manual_memory_in_rd_file_view branch from 010b4fc to 2080575 Compare July 9, 2026 05:55
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.
@eivindjahren eivindjahren force-pushed the fix_manual_memory_in_rd_file_view branch 2 times, most recently from fb673fb to 444b773 Compare July 9, 2026 08:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Comment thread lib/include/resdata/rd_util.hpp
Comment thread lib/include/resdata/rd_util.hpp
@eivindjahren eivindjahren force-pushed the fix_manual_memory_in_rd_file_view branch 3 times, most recently from 3e171dd to 9974cf4 Compare July 9, 2026 09:33
@eivindjahren eivindjahren requested a review from Copilot July 9, 2026 09:33
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.
@eivindjahren eivindjahren force-pushed the fix_manual_memory_in_rd_file_view branch from 9974cf4 to c5ca1e4 Compare July 9, 2026 09:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Comment thread lib/include/resdata/rd_file_view.hpp
Comment thread lib/include/resdata/rd_file_kw.hpp

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.

@eivindjahren eivindjahren merged commit fa7f6fb into main Jul 9, 2026
11 checks passed
@eivindjahren eivindjahren deleted the fix_manual_memory_in_rd_file_view branch July 9, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants