Skip to content

Use native filesystem paths across API boundaries#8231

Draft
plafosse wants to merge 1 commit into
devfrom
test_native_path_roundtrip
Draft

Use native filesystem paths across API boundaries#8231
plafosse wants to merge 1 commit into
devfrom
test_native_path_roundtrip

Conversation

@plafosse
Copy link
Copy Markdown
Member

@plafosse plafosse commented Jun 1, 2026

Summary

This is the API-side portion of a major refactor of how filesystem paths are handled throughout Binary Ninja. Before this change, several path flows round-tripped paths through UTF-8 or narrow strings, which was especially lossy on Windows. This changeset keeps filesystem paths as path objects until an explicit boundary requires text or byte-oriented data.

Within core, filesystem paths should not be handled as std::string except at explicit boundaries:

  1. Creating printable diagnostic/display strings through PrintablePath.
  2. Treating the path as data through PathToUtf8String.

Although this touches a lot of code, most changes are mechanical replacements of string path plumbing with native path types, or replacing C-style path handling with idiomatic C++. The main new API-side code is in pathhelpers.h, the public API wrappers, the binding generator, and the new tests.

API Changes

  1. Path-handling APIs now use path objects instead of char*, str, or equivalent string types:
    • C++: std::filesystem::path
    • C: BNPath
    • Python: pathlib.Path
    • Rust: std::path::Path
  2. BNPath is now the opaque C ABI representation for filesystem paths and wraps std::filesystem::path on the core side.
    • Adds BNAllocPath, BNFreePath, and plural forms.
    • This also lets the Python binding generator avoid hard-coded API lists for BNAllocPath/BNFreePath.
  3. Adds a C++ RAII wrapper around BNAllocPath/BNFreePath to simplify C++ API wrappers.
  4. Adds compiler attributes used by binding generation:
    • BN_OWNED
    • BN_BORROWED
    • BN_NULLABLE
    • BN_FREED_BY
    • BN_OUT_COUNT
    • BN_PATH_ELEMENT_COUNT

Review Notes

I have not done as much focused review of the Python and Rust API surfaces as the core/C++ changes. Please pay particular attention to those areas, especially Rust path ownership and conversion behavior. The main goal of this draft PR is to get the full changeset into CI and make it easier to discuss and review.

Validation

  • git -C api diff --check origin/dev
  • cmake --build cmake-build-relwithdebinfo --target binaryninjaapi binaryninjaui cpp_unit -j 8
  • cmake --build cmake-build-relwithdebinfo --target sharedcachecore -j 8
  • cmake --build cmake-build-relwithdebinfo --target debuggercore debuggerui -j 8

Companion core PR: https://github.com/Vector35/binaryninja/pull/1554

Carry paths through the C ABI as BNPath objects containing native platform code units instead of forcing UTF-8 or active-code-page strings.

Update the C++, Python, and Rust APIs to preserve filesystem path types until explicit display or interchange boundaries. Centralize printable path formatting, add a C++ IsDatabase path wrapper, and reuse shared path conversion helpers.

Add path round-trip coverage for Python FFI and Rust/C++ path-facing APIs, including Windows wide paths and POSIX byte paths.
@plafosse plafosse force-pushed the test_native_path_roundtrip branch from 9332000 to f359cae Compare June 1, 2026 02:04
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