Skip to content

make XPath dummy root local to XPath::evaluate in C++ runtime - #5001

Open
abdul7056 wants to merge 1 commit into
antlr:devfrom
abdul7056:cpp-xpath-local-dummy-root
Open

abdul7056 wants to merge 1 commit into
antlr:devfrom
abdul7056:cpp-xpath-local-dummy-root

Conversation

@abdul7056

Copy link
Copy Markdown
  1. XPath::evaluate() in the C++ runtime stores its dummy root in a file-scope static ParserRuleContext and assigns dummyRoot.children = { t } on every call. Two threads calling XPath::findAll() with their own parser and tree therefore reassign the same std::vector while the other thread iterates it, which frees the buffer under a live iterator and can return nodes from the other thread's tree. The Java runtime creates this root as a local in evaluate().
  2. The dummy root is now a local, as in Java, and is removed from the result before returning. Trees::getDescendants() includes the root it is given, so //* (and the empty path) previously returned the shared static as a match.

The new XPathTest runs findAll from 8 threads on separate parsers and trees. On the current dev it aborted in 10 of 10 runs with MSVC's "can't increment invalidated vector iterator" debug check; with the change it passed 30 of 30. A second test confirms //* returns only nodes of the input tree. The full C++ test suite (66 tests) passes, and the Release unity build used by CI compiles cleanly.

Signed-off-by: obsidian_nomad <abdul@sproutxp.com>
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