Repository navigation
state_list: shift an element's whole subtree and data on erase/insert - #672
Merged
Merged
Conversation
erase() and insert() moved each element with dst.ptree(src.ptree()). ptree() keys every node by its full path from the root and ptree(pt) applies the keys relative to dst, so an element's subtree was written under dst.<src's full path> (stray nodes) while dst's own children kept their old values. data() was never moved either: the isData<boost::any>() check before it is false for any data that is not itself a boost::any. copy_element() now writes src's value and data, and those of each node under it, at the same path under dst, and resets (with signals) the nodes under dst that src lacks. Nodes are kept, as pop_back() keeps the one it clears, so references into an element and observers of its nodes stay valid. The keys-are-absolute, applied-relative semantics of json()/ptree(pt) are documented in ariadne's state_io.h and stay; the xmlrpc cvcstate_get_json/cvcstate_set_json help strings now say so too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while doing #668.
Why
state_list::erase()andinsert()move each later element by one index. They copied an element withdst.ptree(src.ptree()), which breaks for any element that has children:The subtree landed in the wrong place.
ptree()keys every node by its full path from the root, andptree(pt)applies those keys relative todst. So erasing element 0 oflst, where element 1 has a childx, wrote:lst.000001tolst.000000.lst.000001;x's value tolst.000000.lst.000001.x.Meanwhile
lst.000000.xkept its old value. This was the same before and after state: json, traverse and reset without recursing once per level #668: the loader has always been key-based.data()was never moved. The guardsrc.isData<boost::any>()isany_cast<boost::any>(data()), which fails for anything that is not itself aboost::any. So an element's data stayed at its old index.The existing tests only use scalar elements, so nothing caught either problem.
What
copy_element(dst, src)(file-local instate_list.cpp):src's value and data, and those of every node under it, at the same relative path underdst, creating nodes as needed;dstthatsrclacks, with signals, so observers hear the clear.data()is written only when either side has some, so an element without data gets no extradataChanged.Nodes are kept, never dropped, the same way
pop_back()keeps the element it clears. Astate&into an element stays valid, and its connections (the sync adapter's included) keep working. Dropping nodes would leave the adapter holding connections for paths it never reattaches.ptree(pt)/json(j)keep their semantics. Keys are absolute and applied relative to the target node, as ariadne'sstate_io.hdocuments ("restoring into a different node re-roots the saved absolute paths beneath it"). Every in-repo restore targets the root. The xmlrpccvcstate_get_json/cvcstate_set_jsonhelp strings and a comment now say so, including that passing""toset_jsonrestores aget_jsondocument in place.CVC_USING_XMLRPC=OFF), so that file was not compiled here. The change there is only string literals and a comment.Tests
New
StateListTestcases (3). On master they fail, including abad_any_castfor the unshifted data; on this branch they pass:EraseShiftsSubtreesAndDataInsertShiftsSubtreesAndDataShiftingKeepsTheNodesAndSignalsBetween them they cover:
data();…test_list…nodes;Locally on master + this commit (MSVC 14.38 Release, Windows):
image_testCMYK,cvc_cli_testVol2Img/Img2Vol).state_list_test23/23,state_test164/164,state_deep_tree_test18/18,ariadne_loader_test178/178.test_pycvc.pyhits the rawiv lock that volume: close the file after a successful rawiv write #663 fixes, andtest_pycvc_lod.pycrashes at exit after all its checks pass.clang-format 18 is clean.
Not changed
A shift moves value and
data(), as the old code meant to. It does not move:valueTypeName.