Remove resdataprototype - #1281
Conversation
a97c6ca to
fd621e9
Compare
fd621e9 to
dd2e71a
Compare
There was a problem hiding this comment.
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.openusage with built-inopen()+fileno()across multiple APIs/tests (GRDECL I/O, CSV dump). - Introduce
checked_fdopen()to validate fd access mode and update pybind bindings to acceptint fdinstead ofFILE*wrappers. - Replace
ResdataTypeEnum’s oldBaseCEnumimplementation with a pybind11 native enum; add a new_ctimepybind 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 multiplefseek_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.
dd2e71a to
b9104d7
Compare
b9104d7 to
237cc2a
Compare
237cc2a to
883631c
Compare
There was a problem hiding this comment.
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()usesos.path...butosis not imported in this module, so callingresdata.root()will raiseNameError: name 'os' is not defined.
import ctypes as ct
import pathlib
import warnings
from importlib.util import find_spec
883631c to
a31531c
Compare
ajaust
left a comment
There was a problem hiding this comment.
Good! Some small comments and suggestions for fixing the Windows build.
| @@ -1,3 +1,3 @@ | |||
| from __future__ import annotations | |||
|
|
|||
| import ctypes | |||
| class ResdataPrototype(Prototype): | ||
| lib = _dlopen_resdata() |
There was a problem hiding this comment.
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).
a31531c to
8499772
Compare
…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
No description provided.