Skip to content

fix(pycvc): save() must create the volume file before writing - #110

Merged
transfix merged 1 commit into
masterfrom
fix/pycvc-volume-save
Jul 20, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/pycvc-volume-save

Conversation

@transfix

Copy link
Copy Markdown
Owner

Problem

pycvc.Volume.save('x.rawiv') failed with unsupported_volume_file_type, even though .rawiv is the canonical CVC format. This blocked volume file I/O for external SDK consumers built on the new pycvc Volume binding.

Root cause (not what it looked like)

The symptom suggested the .rawiv handler was missing — the theory being that libcvc's format-handler TUs get stripped by the linker in a shared build. That is not what's happening. Handler registration was already refactored away from static initializers to explicit register_*_io(app&) calls invoked by app::registerDefaultHandlers(); because app.cpp references those symbols, the TUs are always linked into libcvc.so. A tiny consumer linked against the shared cvc::cvc confirms the map is fully populated across the library boundary:

handler extensions (13): '.cvc' '.h5' '.hdf' '.hdf5' '.map' '.mrc' '.nothing' '.rawiv' '.rawv' '.spi' '.vol' '.vtk' '.xmp'

The real bug is in the facade. Volume::save() called the free-function writeVolumeFile(app, vol, filename) overload, which writes into an already-existing file (the chunk/offset write path) and does not create it. For a fresh path the .rawiv handler throws while trying to read the not-yet-existent file, and writeVolumeFile re-wraps that as unsupported_volume_file_type — hence the misleading symptom. The failure is actually a read_error: No such file or directory raised inside volume_file_info::read, i.e. a registered handler ran.

Fix

Delegate save()/load() to the canonical members cvc::volume::write()/read(). write() does createVolumeFile() and then writeVolumeFile() — the same idiom the library uses internally. No change to libcvc itself is needed (no whole-archive / --no-as-needed / attribute((used))).

Also drops the test's soft-skip that assumed the handler might be unregistered and asserts the .rawiv round-trip unconditionally (register_rawiv_io is never conditionally compiled).

Verification

  • Tiny C++ consumer against the installed shared SDK: single-volume overload fails with read_error: No such file, vector/write() path round-trips cleanly.
  • Rebuilt _pycvc.so; test_pycvc.py passes end-to-end including the now-unconditional .rawiv round-trip.
  • Original repro (v.save('field.rawiv')) now writes a valid 100-byte .rawiv (68-byte header + 8×4-byte floats) and loads back with correct dims/values.

Volume::save() called the free-function writeVolumeFile(app, vol, filename)
overload, which writes into an *already-existing* file (the chunk/offset
write path) and does not create it. For a fresh path the format handler
threw while trying to read the missing file, which writeVolumeFile re-wraps
as unsupported_volume_file_type — misleadingly suggesting the .rawiv handler
was unregistered. It is not: the handler map is fully populated across the
shared-library boundary via app::registerDefaultHandlers().

Delegate save()/load() to cvc::volume::write()/read(), the canonical members
that createVolumeFile() the target first and then fill it in.

Drop the test's soft-skip that assumed the handler might be unregistered and
assert the .rawiv round-trip unconditionally (register_rawiv_io is never
conditionally compiled).
@transfix
transfix merged commit c8d735f into master Jul 20, 2026
4 of 8 checks passed
@transfix
transfix deleted the fix/pycvc-volume-save branch July 20, 2026 22:12
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.

1 participant