feat: expose Core.SimplifyNameToQualifiedName (Python parity, sret)#37
Merged
Conversation
Closes HIGH missing-capi gap #24. The binding declared the BNRustSimplifyStrToFQN P/Invoke (which returns a BNQualifiedName by value) but declined to expose it: two TODO notes warned the struct-return (sret) ABI made the binding "non-trivial" and redirected callers to the string-only RustSimplifyStrToStr, so Python's demangle.simplify_name_to_qualified_name (demangle.py:253) had no managed equivalent. The sret concern was unfounded: BNQualifiedName is blittable (two IntPtrs plus a ulong), so the P/Invoke marshaller handles the struct-return ABI directly -- the same pattern as BNTypeBuilderGetStructureName. Verified end-to-end: a templated C++ name collapses identically to Python. Add Core.SimplifyNameToQualifiedName with a string overload (simplify flag, defaults true) and a QualifiedName overload (Python forces simplify=true for qualified-name input). Both wrap via QualifiedName.TakeNative (reads components eagerly, then frees the native array) and return null when the simplifier yields no components. Removes the two stale TODO notes.
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.
Summary
Closes HIGH-severity missing-capi gap #24.
BNRustSimplifyStrToFQN(returnsBNQualifiedNameby value) was declared but never exposed — two TODO notes warned the struct-return (sret) ABI made the binding "non-trivial" and redirected callers to the string-onlyRustSimplifyStrToStr. Python'sdemangle.simplify_name_to_qualified_name(demangle.py:253) had no managed equivalent.The sret concern was unfounded
BNQualifiedNameis blittable (twoIntPtr+ aulong,[StructLayout(Sequential)]), so the P/Invoke marshaller handles the struct-return ABI directly — the same proven pattern asBNTypeBuilderGetStructureName. No manual sret /IntPtr retBufworkaround needed.API
Core.SimplifyNameToQualifiedName(string, bool simplify = true)simplify_name_to_qualified_name(str, simplify)(demangle.py:253)Core.SimplifyNameToQualifiedName(QualifiedName)simplify_name_to_qualified_name(QualifiedName)— forcessimplify=true(demangle.py:267)Both wrap via
QualifiedName.TakeNative(reads components eagerly, then frees the native array) and returnnullwhen the simplifier yields no components (matching Python'sif len(result) == 0: return None).E2E tests (harness repo)
SimplifyNameToQualifiedNameTests(6 tests), each asserting components + join + rendered string match Python exactly:SimplifiesTemplatedCppName— the Python doc example →std::basic_string<wchar>.TokenizesWithoutSimplifying—simplify=falsekeeps default args.TokenizesPlainScopedName—a::b::cunaffected by the flag.SingleComponentNameRoundTrips— one-element list.EmptyInputReturnsNull—Noneparity.QualifiedNameOverloadForcesSimplification.Full harness regression 64/64.