Skip to content

Remove cvcapp singleton: thread cvc::app& through libcvc (Phase A, part 1)#11

Merged
transfix merged 7 commits into
masterfrom
remove-cvcapp-singleton
May 2, 2026
Merged

Remove cvcapp singleton: thread cvc::app& through libcvc (Phase A, part 1)#11
transfix merged 7 commits into
masterfrom
remove-cvcapp-singleton

Conversation

@transfix
Copy link
Copy Markdown
Owner

@transfix transfix commented May 1, 2026

Summary

First batch of work toward removing the cvcapp singleton (cvc::app::instance()) from libcvc, per cvc-singleton-removal-plan.md.

This PR contains 6 small, independent commits — each individually builds and passes ctest (590/590) on Linux Debug. They're stacked on one branch for CI efficiency; happy to split into separate PRs if reviewers prefer.

Commits (oldest → newest)

  1. dac67ed cvc-mesher: thread cvc::app through Mesher main() — eliminates the last external caller of the parameterless VolMagick::readVolumeFile shim.
  2. fab6789 rawv_io: pass app& through thread_info ctor — 4 virtual method bodies now forward the supplied ctx instead of falling back on the singleton.
  3. fe32a76 libcvc CLI: thread cvc::app& through dispatch table — dispatch now void(cvc::app&, args); main() owns one app cvc_ctx.
  4. 4c0c026 volume_file_io/utility: delete ctx-less free-function bridges — all callers in libcvc + downstream now pass app& explicitly.
  5. f325f71 volume_file_io subclasses: thread cvc::app& through virtual method bodies — mrc_io / rawiv_io / spider_io / hdf5_io / vtk_io / volume_file_info had app & /*ctx*/ parameters but constructed thread_info ti(BOOST_CURRENT_FUNCTION), silently falling back on the singleton. Restore the parameter name and pass it through.
  6. 5f65657 hdf5_utils: delete ctx-less inline overloads — block of ~100 lines of app::instance()-injecting forwarders. Sole caller (hdf5_test.cpp) migrated to fixture-local cvc::app.

What still uses app::instance() after this PR

  • algorithm.cpp (~30 free functions) — large mechanical signature change, separate PR
  • xmlrpc_server.cpp / xmlrpc_client.cpp — bundled with state work
  • volrover3 dialogs (MainWindow, GeometryDialog, SDFDialog, etc.) — separate PR
  • legacy delegating ctors at app.h:384/421/493 — deferred until after the above
  • test files (app_test.cpp, state_test.cpp, geometry_test.cpp, voxels_test.cpp) — large fixture rewrite, separate PR
  • app::instance() itself + cvcapp macro — gated on all of the above

See cvc-singleton-removal-plan.md for the full 17-PR sequencing plan.

Validation

  • cmake --build . clean (158/158 targets) on Linux Debug at every commit
  • ctest -j8 100% passed (590/590) at every commit
  • grep -n 'app::instance' libcvc/src/cvc/{volume_file_io,utility}.cpp returns 0 hits after PR

transfix added 6 commits May 1, 2026 12:45
Drop the last call site of the parameterless VolMagick::readVolumeFile
shim. Construct a local cvc::app at main() entry and invoke
CVC_NAMESPACE::readVolumeFile(ctx, vol, input_file) directly. This
unblocks deleting the ctx-less free-function overloads in
src/cvc/volume_file_io.cpp and the corresponding cvcapp singleton
references in upcoming Phase 5 commits.
Each virtual already takes app& ctx as a parameter (currently
unnamed because unused). Use it for the thread_info construction
instead of falling back to the legacy delegating ctor that calls
app::instance(). Pure mechanical change in 4 sites; no behavior
change. Removes 4 of the singleton-using call sites and unblocks
deletion of the cvc::thread_info(string) legacy ctor at app.h:384.
Change command_func signature from
    void(const std::vector<std::string>&)
to
    void(cvc::app&, const std::vector<std::string>&)
and construct one cvc::app at the top of main(), passing it into
each dispatched handler. Each command (copy/info/sdf/iso/server/client)
now uses ctx-aware overloads for thread_info, geometry/volume ctors,
volume_file_info::read, and the iso/sdf/save/load free functions.

cvcstate(...) and cvcapp.wait() are kept inside server() for now;
they will become ctx.state()(...) once the state singleton merge
(PR 11) lands. cvcapp.wait() in server() becomes ctx.wait().

This unblocks deletion of the ctx-less free-function bridges in
volume_file_io.cpp and utility.cpp, since libcvc.cpp:47 was the
last caller of the parameterless save/load overloads.
The mesher CLI commit eliminated the last external caller of the
parameterless VolMagick::readVolumeFile shim, and libcvc.cpp's command
handlers (PR 4) were the last libcvc-internal callers of save(load(...)).
All other call sites already pass cvc::app& explicitly, so the ctx-less
bridges in volume_file_io.{h,cpp} and utility.{h,cpp} are unreachable.

Deleted ctx-less overloads:
  volume_file_io.h/.cpp:
    readVolumeFile (5 forms), writeVolumeFile (3 forms),
    createVolumeFile, readBoundingBox, writeBoundingBox.
  utility.h/.cpp:
    calcGradient, sub, volconvert, load, save, plus the inline
    createVolumeFile(volume_file_info)/(volume,filename) shims.

Also fixed an internal save() that constructed a ctx-less geometry
during dispatch -- now uses the supplied app& context.

Full Linux Debug build (158 targets) and ctest (590/590 passing)
verified.

Part of the cvc::app singleton removal effort tracked in
cvc-singleton-removal-plan.md (PR 7).
…dies

Several volume_file_io subclasses had `app & /*ctx*/` parameters and
constructed `thread_info ti(BOOST_CURRENT_FUNCTION)` -- which silently
fell back on app::instance(). Restore the parameter name and pass the
provided ctx into thread_info so progress/info routing follows the
caller's app instance.

Files updated (mechanical s/app & \/\*ctx\*\//app \&ctx/ +
s/thread_info ti(BOOST_CURRENT_FUNCTION)/thread_info ti(ctx, ...)/):
  src/cvc/hdf5_io.cpp
  src/cvc/mrc_io.cpp
  src/cvc/rawiv_io.cpp
  src/cvc/spider_io.cpp
  src/cvc/vtk_io.cpp
  src/cvc/volume_file_info.cpp

Full Linux Debug build (158 targets) and ctest (590/590) green.

Part of cvc-singleton-removal-plan.md (PR 5, revised scope -- legacy
ctor deletion deferred until after algorithm.cpp / volrover3 callers
are migrated).
Lines 1338-1436 of inc/cvc/hdf5_utils.h were a block of inline
overloads that injected app::instance() and forwarded to the
ctx-aware primary versions. The only caller in the codebase is
src/cvc/tests/hdf5_test.cpp (8 objectExists calls); migrate that
to the test fixture's local cvc::app and delete the ctx-less
forwarders entirely.

Build (158 targets) + ctest (590/590) green.

Part of cvc-singleton-removal-plan.md (PR 6).
Apply clang-format-18 to files touched in this branch so the
clang-format (changed lines) CI check passes.
@transfix transfix merged commit f7d2df1 into master May 2, 2026
19 checks passed
@transfix transfix deleted the remove-cvcapp-singleton branch May 2, 2026 06:47
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