Skip to content

Remove resdataprototype - #1281

Merged
eivindjahren merged 4 commits into
mainfrom
remove_resdataprototype
Aug 28, 2026
Merged

Remove resdataprototype#1281
eivindjahren merged 4 commits into
mainfrom
remove_resdataprototype

Conversation

@eivindjahren

Copy link
Copy Markdown
Collaborator

No description provided.

@eivindjahren
eivindjahren changed the base branch from main to fix_several_bugs August 26, 2026 13:26
@eivindjahren
eivindjahren force-pushed the remove_resdataprototype branch 5 times, most recently from a97c6ca to fd621e9 Compare August 27, 2026 07:13
@eivindjahren
eivindjahren requested a lite review from Copilot August 27, 2026 07:14
@eivindjahren
eivindjahren force-pushed the remove_resdataprototype branch from fd621e9 to dd2e71a Compare August 27, 2026 07:15

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 removes the remaining ResdataPrototype/CFILE-style ctypes plumbing and migrates several Python↔C++ bindings to a pybind11-first approach, including passing raw file descriptors (fileno()) into the bindings. Tests are updated accordingly, and new bindings are added for time helpers and native enums.

Changes:

  • Replace CFILE/cwrap.open usage with built-in open() + fileno() across multiple APIs/tests (GRDECL I/O, CSV dump).
  • Introduce checked_fdopen() to validate fd access mode and update pybind bindings to accept int fd instead of FILE* wrappers.
  • Replace ResdataTypeEnum’s old BaseCEnum implementation with a pybind11 native enum; add a new _ctime pybind module and remove abort-signal prototype wiring.

Reviewed changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/util/extended_testcase.py Removes abort-signal installation hook from test base class.
tests/test_fd_conversions.py Adds coverage ensuring fd-based bindings reject wrong read/write modes.
tests/rd_tests/test_sum.py Switches CSV dump tests from cwrap.open to built-in open().
tests/rd_tests/test_rd_type.py Updates enum iteration logic for new native ResdataTypeEnum.
tests/rd_tests/test_rd_sum.py Replaces cwrap.open usage with open() and context managers.
tests/rd_tests/test_rd_kw.py Updates keyword GRDECL tests to use built-in open() and context managers.
tests/rd_tests/test_rd_grid_misc.py Updates GRDECL write/read tests; passes fileno() into _grid._fwrite_grdecl.
tests/rd_tests/test_rd_3dkw.py Replaces cwrap.open with built-in open() for GRDECL reads.
tests/rd_tests/test_grid.py Migrates GRDECL save/write tests to built-in open().
tests/rd_tests/test_grid_equinor.py Refactors GRDECL reads/writes to use context-managed open().
tests/rd_tests/test_grdrd_equinor.py Migrates GRDECL read/write/fseek tests to context-managed open().
tests/rd_tests/test_grdecl.py Switches GRDECL read test to built-in open().
tests/rd_tests/test_fortio.py Removes cwrap.open in favor of built-in open() for text output.
tests/rd_tests/test_fault_blocks.py Updates GRDECL reads to built-in open().
tests/rd_tests/test_fault_blocks_equinor.py Updates setup to use context-managed open() for GRDECL.
tests/rd_tests/test_equinor_faults.py Updates GRDECL read path to use context-managed open().
python/resdata/util/util/install_abort_signals.py Removes abort-signal prototype module (deleted).
python/resdata/util/util/ctime.py Replaces BaseCValue/ResdataPrototype usage with new _ctime pybind helpers.
python/resdata/util/util/init.py Removes Prototype/abort-signal exports.
python/resdata/summary/rd_sum.py Changes dump_csv_line to pass fileno() into _rd_sum binding.
python/resdata/resfile/rd_kw.py Changes GRDECL read/write helpers to pass fileno() into _kw binding.
python/resdata/rd_util.py Removes ctypes/prototype-based enum extraction in favor of _rd_util binding exports.
python/resdata/rd_type.py Re-exports pybind-native ResdataTypeEnum and adjusts .type return value.
python/resdata/grid/rd_grid.py Switches GRDECL read/write helpers to pass fileno() into _grid binding.
python/resdata/geometry/init.py Removes unused Prototype import.
python/resdata/init.py Removes ResdataPrototype + abort handler wiring and abort-signal update call.
lib/resdata/rd_type_pybind.cpp Adds pybind11 native_enum for ResdataTypeEnum; updates function signatures.
lib/resdata/rd_sum_pybind.cpp Updates _dump_csv_line binding to accept fd and uses checked_fdopen.
lib/resdata/rd_kw_pybind.cpp Updates GRDECL read/write bindings to accept fd and uses checked_fdopen.
lib/resdata/rd_grid_pybind.cpp Updates GRDECL write bindings to accept fd and uses checked_fdopen.
lib/resdata/cwrap_pybind.cpp Adds checked_fdopen() and removes old CFILE conversion glue.
lib/resdata/ctime_pybind.cpp Adds new _ctime module providing timezone/timegm helpers via pybind.
lib/private-include/detail/resdata/cwrap_pybind.hpp Declares checked_fdopen() for use across pybind modules.
lib/CMakeLists.txt Registers new _ctime pybind module.
Suppressed comments (1)

lib/resdata/rd_kw_pybind.cpp:54

  • Same issue here: checked_fdopen() creates a new buffered stdio stream on the fd and the code returns without synchronizing/closing it. If the caller does multiple fseek_grdecl()/read_grdecl() operations on the same file handle, stdio buffering can advance the OS offset beyond the logical position, causing later reads to skip content. Ensure the stream is synced (fseek(stream, 0, SEEK_CUR)) and closed on a duplicated fd.
    m.def("_fseek_grdecl", [](std::string name, bool rewind, int fd) {
        auto *stream = checked_fdopen(fd, "r");
        return rd_kw_grdecl_fseek_kw(name.c_str(), rewind, stream);
    });

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/resdata/cwrap_pybind.cpp Outdated
Comment thread lib/resdata/cwrap_pybind.cpp Outdated
Comment thread lib/resdata/rd_kw_pybind.cpp Outdated
Comment thread lib/resdata/rd_grid_pybind.cpp
Comment thread lib/resdata/rd_sum_pybind.cpp
@eivindjahren
eivindjahren force-pushed the remove_resdataprototype branch from dd2e71a to b9104d7 Compare August 27, 2026 08:27
@eivindjahren
eivindjahren force-pushed the remove_resdataprototype branch from b9104d7 to 237cc2a Compare August 27, 2026 11:40
Base automatically changed from fix_several_bugs to main August 27, 2026 11:41

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 12 out of 12 changed files in this pull request and generated no new comments.

Suppressed comments (1)

python/resdata/init.py:4

  • root() uses os.path... but os is not imported in this module, so calling resdata.root() will raise NameError: name 'os' is not defined.
import ctypes as ct
import pathlib
import warnings
from importlib.util import find_spec

@eivindjahren
eivindjahren force-pushed the remove_resdataprototype branch from 883631c to a31531c Compare August 27, 2026 12:16

@ajaust ajaust left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good! Some small comments and suggestions for fixing the Windows build.

@@ -1,3 +1,3 @@
from __future__ import annotations

import ctypes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Seems to be unused now.

Comment on lines -95 to -96
class ResdataPrototype(Prototype):
lib = _dlopen_resdata()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I assume that this did some magic w.r.t. loading the library. After removing it, this became an issue for the Windows build.

It looks like we can fix it by updating our cibuildwheel config for window, see ajaust@fa4fc64. By telling delvewheel where libresdata.dll is instead of skipping it (since we could not locate it earlier), delvewheel seems to be able to do some magic and stuff works, see https://github.com/ajaust/resdata/actions/runs/33078634167/job/98539535465?pr=1 (I wrote the message when py311 @ windows passed successfully assuming that the rest will work).

@eivindjahren
eivindjahren force-pushed the remove_resdataprototype branch from a31531c to 8499772 Compare August 28, 2026 05:23
@eivindjahren
eivindjahren merged commit dabe48f into main Aug 28, 2026
11 checks passed
@eivindjahren
eivindjahren deleted the remove_resdataprototype branch August 28, 2026 10:44
ajaust added a commit to ajaust/resdata that referenced this pull request Sep 1, 2026
…quinor#1283 (Polygon lifetime fix)

- python-bindings.md: document removal of ResdataPrototype/_dlopen_resdata/
  abort-signal machinery; CTime and ResdataTypeEnum now native pybind
  (native_enum); note the Windows DLL-loading regression this caused
- build-packaging.md: document the delvewheel --add-path fix that replaced
  --no-dll libresdata.dll and restored Windows wheel builds
- geometry.md: document geo_polygon's C struct -> rd::Polygon C++ class
  migration, shared_ptr-based collection ownership fixing a use-after-free
  risk, the Polygon::length() empty-polygon UB fix, and the gc.collect()
  regression-test pattern for shared-ownership lifetime bugs
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