Skip to content

state: json() and ptree() key by paths relative to their node - #674

Merged
transfix merged 1 commit into
masterfrom
fix/state-json-relative
Oct 18, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/state-json-relative

Conversation

@transfix

Copy link
Copy Markdown
Owner

Why

json(), ptree() and save() keyed every node by its full path from the root. Their loaders json(j), ptree(pt) and restore() apply keys relative to the node they are called on, as operator() and every other path a node takes do. The two halves disagreed:

  • A subtree's document only went back right into the root. n.json(n.json()) re-rooted n's subtree under n.<n's full path>.
  • Copying between nodes put the copy in the wrong place. m.json(n.json()) wrote under m.<n's full path>. This is the bug state_list hit (fixed separately in state_list: shift an element's whole subtree and data on erase/insert #672).
  • Every caller had to know the asymmetry. ariadne's state_io.h and the xmlrpc help strings documented it, and its tests restored a doc subtree into the root.

What

  • ptree()/json()/save() key each node by its path relative to the node they're called on, with "" for that node itself. The format is otherwise unchanged from state: json, traverse and reset without recursing once per level #668: still one level, pre-order, "" values for childless empty nodes.
    • n.json(n.json()) gives n its subtree back, and m.json(n.json()) copies it under m.
    • A document of the root is unchanged, since relative paths there are full names. pycvc state_json/state_from_json work on the root and are unaffected.
  • The loader is unchanged. It still reads documents older versions wrote, both nested and full-path; load those into the root.
  • Callers:
    • ariadne save_state/restore_state follow cvc::state. state_io.h is updated, and its tests restore into the saved node, plus a new check that restoring into another node copies the subtree.
    • cvc state json <path> now prints paths relative to <path> (camera.x, not scene.camera.x). The CLI guide says so.
    • The xmlrpc cvcstate_get_json/cvcstate_set_json help strings now say both sides are relative to the named object, so set_json on the path get_json read restores it. Only strings changed there, and xmlrpc is off in the local build. Removing xmlrpc waits for the FoldHub/F2Dock work, since F2Dock's F2DockServer builds on cvc::xmlrpc.
  • children() and traverse() still report full names. They name nodes rather than describe a subtree, and nothing here changes them.

Tests

  • StateDeepTree.JsonIsOneLevelOfRelativePaths (was …OfFullPaths) checks:
    • relative keys for a subtree, and full names in the root's document;
    • a document going back into the same node of another app, and into a different node as a copy;
    • a legacy nested document loading into the root.
  • StateDeepTree.JsonRoundTripsADeepTree restores into the saved node, 1000 deep on a 64 KiB stack.
  • Locally on master + this commit (MSVC 14.38 Release, Windows): all 4068 ctest cases pass except the three ImageMagick ones that image: find ImageMagick's coders beside its own DLL; init it before every Magick++ use #673 fixes. That includes state_test, state_list_test, state_deep_tree_test and ariadne_loader_test.
  • pycvc: 20 of 22 scripts pass, including test_pycvc_state.py's state_json round trip. The other two fail as before: the rawiv lock (volume: close the file after a successful rawiv write #663) and test_pycvc_lod.py's crash at exit.
  • clang-format 18 is clean.

json()/ptree()/save() keyed each node by its full path from the root,
while json(j)/ptree(pt)/restore() apply keys relative to the node they
are called on, like operator() and every other path a node takes. So a
subtree's document only went back right into the root, and
m.json(n.json()) wrote n's subtree under m.<n's full path>.

They now key each node by its path relative to the node they are
called on ("" for that node itself), so n.json(n.json()) gives n its
subtree back and m.json(n.json()) copies it under m. A document of the
root is unchanged (relative paths there are full names), and the loader
still reads the nested and full-path documents older versions wrote
(load those into the root).

Callers: ariadne's save_state/restore_state follow (state_io.h says so;
its tests restore into the saved node and into a copy); cvc state json
<path> prints paths relative to <path> (CLI guide); the xmlrpc
get_json/set_json help strings say both sides are relative.
@transfix
transfix merged commit 401c5a4 into master Oct 18, 2026
15 checks passed
@transfix
transfix deleted the fix/state-json-relative branch October 18, 2026 04:25
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