Skip to content

P0a: the file handler tables are each app's own (volume, geometry, model, image) [4.0, breaking] - #1119

Merged
transfix merged 12 commits into
masterfrom
p0a/file-io-registries
Nov 10, 2026
Merged

transfix merged 12 commits into
masterfrom
p0a/file-io-registries

Conversation

@transfix

@transfix transfix commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

P0a's first subsystem (docs/roadmap/VOLROVER-LIBRARY-PORTS-ROADMAP.md §1.3, §7 P0a (1), §9 item 3). Breaking: part of the 4.0 break. Do not merge until a last 3.x is tagged.

Builds on #1107 (the writable-data scan, merged as a2d1607): this PR shrinks its allowlist.

The bug it fixes (§1.3, bug 1)

Every cvc::app constructor added a fresh set of handler objects to one process-wide volume map and one geometry map, with no lock and no de-duplication. The geometry map also filled itself with the same handlers on first use, so it held two sets after the first app. Each app made, including the per-thread apps in state_volume_codec.cpp, added another set that every other app then saw. A handler one app registered was every app's.

What moved

Each app now owns four handler tables, cvc::file_handler_registry<Handler> (new, inc/cvc/core/file_handler_registry.h: header-only, locked, no statics):

Table Was Readers and writers that use it
app.volume_handlers() volume_file_io::handlerMap() (function-static map) readVolumeFile, writeVolumeFile, createVolumeFile, volume_file_info (their API already took the app)
app.geometry_handlers() geometry_file_io::get_handlers() (function-static map, self-filling) read_geometry(app, file), write_geometry(app, geo, file), geometry::read / write (through the geometry's own app)
app.model_handlers() model_file_io::get_handlers() (function-static map, self-filling) read_model(app, file), write_model(app, model, file)
app.image_handlers() image.cpp's static vector, mutex and once_flag read_image(app, file), write_image(app, img, file), image::load(app, file), image.save(app, file)

app::registerDefaultHandlers() registers each kind's built-in handlers once, into that app: register_default_volume_handlers, ..._geometry_..., ..._model_..., ..._image_handlers(app&). app(no_init) starts with empty tables. insert() adds a handler only if no handler with its id() is there yet.

Public API changes (the old forms are gone; no app-free wrapper)

  • read_geometry(app&, file), write_geometry(app&, geo, file); geometry(const std::string&) is gone (use geometry(app, file)); geometry::read / write throw read_error / write_error for a geometry made without an app.
  • read_model(app&, file), write_model(app&, m, file), read_model_from_memory(app&, ...) (its embedded textures go through the app's image handlers).
  • read_image(app&, path), write_image(app&, img, path, q), image::load(app&, path), image::save(app&, path[, q]); image_file_io::for_read / for_write_ext / known_extensions take the app; image_file_io::add is gone (app.image_handlers().insert).
  • The static registry members are gone: volume_file_io::handlerMap/insertHandler/removeHandler/getExtensions, geometry_file_io::get_handlers/insert_handler/remove_handler/get_extensions, the same on model_file_io, and the app-free register_bunny_io() / register_off_io() / register_cvcraw_io() / register_default_geometry_handlers() / register_default_model_handlers() / register_assimp_geometry_io().
  • The geometry and model handler interfaces take the app, as volume_file_io's already did: read(app&, file), write(app&, ..., file), extents(app&, file) (the Assimp model handler reads its textures with it).
  • Functions that read through these tables take the app too: is_geometry_filename / is_volume_filename, world::load_city_bundle (both forms), world::load_building_library, world::write_bundle, nav::segment_scene_material, nav::land_cover_provider (keeps a reference to the app), physics::drive_plant_log_scene, ariadne::read_scene_node_geometry, ariadne::generated_world_library.
  • volume_file_io::FILE_EXTENSION_EXPR, CVC_VOLUME_GROUP, DEFAULT_VOLUME_NAME and the geometry and model FILE_EXTENSION_EXPR are const char *const.
  • pycvc: pycvc.load_model(app, path), pycvc.image.load(app, path), img.save(app, path[, quality]), pycvc.load_city_bundle(app, dir, ...), pycvc.generate_world(..., app=) (required with a building_library); geometry.save / load use the geometry's own app. pycvc_gl: scenes.load_terrain(app, path), terrain_sampler(..., app=), VehicleModel(app, path, ...), cars.generate(params, app=).

libcvc's own callers are updated in this PR: cvcGL, ari, arigl, the CLI, the worldgen tool, pycvc and pycvc_gl, the examples (C++ and Python) and the tests. arisrv needed nothing. Downstream (§9 item 3): CVC-DBG/cvcdbg's 3 read_model and 2 read_image calls and volrover3's 3 read_geometry calls take the app at 4.0.

What the allowlist lost: 19 lines

  • volume_file_io.cpp: handlerMap()::p and its guard; CVC_VOLUME_GROUP, DEFAULT_VOLUME_NAME, FILE_EXTENSION_EXPR.
  • geometry_file_io.cpp: get_handlers()::p, its guard, _registering_defaults, _defaults_registered; FILE_EXTENSION_EXPR.
  • model_file_io.cpp: the same five.
  • image.cpp: registry()::r, its guard, registry_mutex()::m, ensure_defaults()::once.

Six lines are renamed, not removed, because their function's signature gained the app: scene_generated_world.cpp's library_at(cvc::app&, ...) cache (5; it moves in the world-generators step, §7 P0a (4)) and assimp_io.cpp's decode_embedded_compressed(cvc::app&, ...)::counter. libcvc's lane: 449 entries for cvc (was 468).

The allowlist also takes in what commits that reached master after the scan's starting list added (from CI run 42763989853's libcvc list): per-thread scratch buffers (algo/distance_transform.cpp edt_scratch, nav/grid_nav.cpp sdf_scratch, replacing grid_nav's edt_scratch) and SlicedCall's function-static body in ariadne/script_engine.cpp. Master's own scan lane fails on these until this merges.

Left for later steps, as §7 orders them: state_volume_codec.cpp's per-thread app (group 3; its apps now fill only their own tables), the CLI's own cvc_app() static, and the building-library cache.

Tests

file_io_registry_test (new):

  • Two apps (TwoAppsSeeOnlyTheirOwnHandlers): a fake handler of each of the four kinds registered in one app is found and used there, and the other app's tables are unchanged and cannot read the format; removing a handler from one leaves the other's.
  • Making apps (MakingAnAppChangesNoOtherApp): two more apps, an app(no_init), an app destroyed, and four apps made on other threads at once leave the first app's tables exactly as they were; every app has each built-in handler once.
  • Order (ReadsGiveTheSameAnswersInAnyOrder): a volume and a mesh read alone, A then B, B then A, and with apps made and destroyed between the reads give the same results.
  • EveryAppStartsWithTheBuiltInHandlersOnce, NoInitAppGetsTheDefaultsWhenAsked, ATableHoldsOneHandlerPerId, AGeometryWithoutAnAppHasNoHandlersToUse.

Locally (Windows, MSVC 2022, Release, cvcGL + pycvc + examples, master merged in): the whole tree builds, and the 368 tests of the suites this touches pass: FileIoRegistry 7/7, the image, model, geometry, volume I/O, HDF5, utility, world, nav material and Ariadne data/scene suites, cvcgl_ariadne_realize, cvcgl_lod_cache, cvcgl_imgui_media, and pycvc's image, model, texture, world_geometry, gl_world_geometry, gl_ariadne_host and gl_cars. A loaded full run (-j 8 on a shared box) failed seven AsyncCalls time-limit cases; all seven pass run alone.

CI's first full run caught what my local run had skipped: 21 CvcCliTest cases. The CLI wrote its algorithm results with geometry::write(), and those geometries carry no app, so it threw. The CLI now writes through write_geometry(app, ...), cvc bunny reads into a geometry made with the CLI's app, and cvc::save() writes through the app it is given. All 182 CvcCliTest cases pass locally.

A master fix this PR carries (macOS)

ScriptLane::take_queue (from #1129) moved on_done out of a queued hook's options and then started the activation with those options. libc++ leaves a small callable in a moved-from std::function, so on macOS the activation reported again when it ended. ScriptEngineTest.AKeyHookTakesEveryKeyInOrder and AFailedEventLetsTheNextOneGo failed on both macOS lanes that had run; #1129's own CI was cancelled when it merged, so master hasn't run them on macOS yet. The fix (cf9a5d5) clears o.on_done after the move.

tools/singleton_scan/scan.py lists every writable data symbol in the objects
of the scanned CMake targets (nm's .data and .bss, thread-locals,
function-local statics and their guards) and fails on any symbol not on
tools/singleton_scan/allowlist.txt, and on any allowlist line the build no
longer has, so the list only shrinks as P0a moves state onto the app.

Each line names its target, its source file (or <header> for vague-linkage
statics) and the object. Read-only data (.rodata, .data.rel.ro) and the
toolchain's per-TU artifacts (std::__ioinit, coverage counters, the EH
personality reference, nvcc's registration stubs) are left out.

package-linux / libcvc-release-grpc scans cvc, cvc_igl, cvc_physics_jolt,
cvcGL, cvcMedia and cvc-cli; pycvc-linux scans pycvc and pycvc_gl. Both run
after the tests even when one failed, write the per-subsystem table to the
job summary and upload the allowlist their build needs.

test_scan.py covers the parser, the classification and the allowlist
matching on canned nm output, and compiles fixture.cpp into a real ELF object
for an end-to-end run (required in CI).
The allowlist is the list the two scan lanes' first run uploaded
(singleton-scan-libcvc, singleton-scan-pycvc), 815 objects:
cvc 468, cvcGL 221, cvc-cli 31, cvc_igl 14, cvcMedia 8,
cvc_physics_jolt 2, pycvc 52 and pycvc_gl 19.

Code generators' own tables are left out by rule, as the toolchain's
per-TU artifacts are, and the summary counts them: SWIG's module
runtime in the *PYTHON_wrap.cxx wrappers (the _swigt__/_swigc__ type
and cast tables, swig:: templates, NumPy's PyArray_API; 998 symbols)
and protoc's message tables in *.pb.cc (63). pycvc's own code that
SWIG copies into a wrapper is still scanned.
…del, image)

Fixes roadmap 1.3's bug 1: every cvc::app constructor added a fresh set of
handlers to one process-wide volume map and one geometry map (which also
filled itself on first use), with no lock and no de-duplication, so every
app made, the state volume codec's per-thread apps too, added duplicates
every other app saw, and a handler one app registered was every app's.

Each app now owns four tables, cvc::file_handler_registry<Handler>
(inc/cvc/core/file_handler_registry.h: header-only, locked, no statics):
app.volume_handlers(), geometry_handlers(), model_handlers() and
image_handlers(). The constructor registers each kind's built-in handlers
once, into that app (register_default_{volume,geometry,model,image}_handlers);
app(no_init) starts empty. insert() skips a handler whose id is there.

Breaking (the 4.0 break, roadmap 9 item 3); the old forms are gone and no
app-free wrapper keeps a table alive:
- read_geometry, write_geometry, read_model, write_model,
  read_model_from_memory, read_image, write_image, image::load and
  image::save take the app; geometry(const std::string&) is gone, and
  geometry::read/write use the geometry's own app;
- the static registry members (handlerMap/insertHandler/..., get_handlers/
  insert_handler/..., image_file_io::add) and the app-free register_*
  functions are gone;
- geometry_file_io's and model_file_io's read/write/extents take the app,
  as volume_file_io's do (the Assimp handler reads textures with it);
- what reads through the tables takes the app: is_geometry_filename,
  is_volume_filename, world::load_city_bundle, load_building_library,
  write_bundle, nav::segment_scene_material, land_cover_provider,
  physics::drive_plant_log_scene, ariadne::read_scene_node_geometry and
  generated_world_library;
- the I/O modules' FILE_EXTENSION_EXPR and volume names are const char *const.

libcvc's callers are updated: cvcGL, ari, arigl, the CLI, the worldgen tool,
pycvc and pycvc_gl (load_model, image.load/save, load_city_bundle and
VehicleModel take the app; generate_world takes app= with a library), the
C++ and Python examples, the tests and the docs.

file_io_registry_test: two apps see only their own handlers of all four
kinds; making apps (on other threads, app(no_init), destroyed ones) changes
no other app's tables; reads give the same answers in any order.

The allowlist loses 19 lines (the four modules' registry statics and
constants) and renames 6 whose function gained the app.
# Conflicts:
#	src/cvc/ariadne/scene_generated_world.cpp
@transfix
transfix marked this pull request as ready for review November 10, 2026 04:57
…p with master

The CLI's iso, tetrahedralize, hexahedralize, tetrahedralize2 and layer-mesh
commands wrote their result with geometry::write(), but an algorithm's
geometry comes back with no app, so the write threw and 21 CvcCliTest cases
failed. They now call write_geometry(app, result, path). `cvc bunny` reads into
a geometry made with the CLI's app, and cvc::save() writes a stored geometry
through the app it is given. cvc_cli_test's hexahedralize check reads its mesh
with the test's app.

The allowlist takes the libcvc lane's list from CI (run 42763989853). Commits
that reached master after the scan's starting list was taken added per-thread
scratch buffers (algo/distance_transform.cpp edt_scratch, nav/grid_nav.cpp
sdf_scratch, replacing grid_nav's edt_scratch) and SlicedCall's function-static
`body` in ariadne/script_engine.cpp.
ScriptLane::take_queue moved on_done out of the activation's options and
then started the activation with those options. A moved-from std::function
is not guaranteed empty, and libc++ leaves a small callable in place, so on
macOS the activation reported again when it ended: on_done ran once per
event plus once more. ScriptEngineTest.AKeyHookTakesEveryKeyInOrder and
AFailedEventLetsTheNextOneGo (from #1129) failed on every macOS lane.
Clear it after the move.
@transfix
transfix merged commit b9de118 into master Nov 10, 2026
33 checks passed
@transfix
transfix deleted the p0a/file-io-registries branch November 10, 2026 19:33
transfix added a commit that referenced this pull request Nov 10, 2026
Two conflicts, both resolved to keep both sides:

- script_engine.cpp, ScriptLane::take_queue: master made the same fix as
  afcfc49 (the delivery's options' on_done emptied after it is taken, as
  libc++ leaves a moved-from std::function set). Master's form is kept.
- tools/singleton_scan/allowlist.txt: only the cvc header's count. The
  merged list is base plus both sides' changes, 805 lines: master drops the
  handler tables' statics, and both sides list #1105/#1126's parsed
  programs and #1109's EDT/SDF scratch the same way. cvc is 457; the list
  parses and is in scan.py's own order.

No line this branch adds uses an API #1119 changed. Rebuilt cvc, pycvc and
the Ariadne, state_exec, exec_pool, net, stream and lifetime suites; all
pass, and ariadne_runtime_test (291) and ariadne_host_test (48) pass with
CVC_EXEC_THREADS=auto.
transfix added a commit that referenced this pull request Nov 10, 2026
Picks up #1119's refresh of the writable-data scan's allowlist (the
objects from #1109 and #1126), which package-linux / libcvc-release-grpc
failed on.
transfix added a commit that referenced this pull request Nov 10, 2026
…ument

package-linux's writable-data scan failed on 8 symbols this branch never touched
(algo/distance_transform.cpp, ariadne/script_engine.cpp, nav/grid_nav.cpp) and 2 stale grid_nav
entries: master's allowlist has had them since. #1119 gave drive_plant_log_scene an app first;
PlantLogScene.CityStartsAreTheSameOnEveryStandardLibrary passes one, as its neighbours do.
transfix added a commit that referenced this pull request Nov 15, 2026
P0a's breaking changes (#1119, #1137) are on master, and v3.7.13 was the last 3.x release, so
the next release is 4.0.0. CMakeLists.txt and every cvcpkg recipe's upstream_version move to
4.0.0 (cvc_revision is already 1 everywhere).

cvcGL's SOVERSION follows the major version, as libcvc's does: libcvcGL.so.4 beside
libcvc.so.4. It was hardcoded to 3, which would have let a 4.x cvcGL load where a 3.x one was
linked.
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