Repository navigation
Conversation
BNProjectQueryMetadata returns null when nothing is stored under the key, and wrapping that in a Ref made any later use of the metadata dereference null. Return an Option, as BinaryView, Function, TypeLibrary and TypeArchive already do.
This branch has not been deployed
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.
Problem
Project::query_metadatapasses the result ofBNProjectQueryMetadatastraight toMetadata::ref_from_raw. The core returns null when nothing is stored under the key, so the caller gets aRef<Metadata>with a null handle. That trips thedebug_assertin debug builds, and in release builds any use of the value dereferences null. The Rust bindings give no way to ask whether a key exists, so reading a key that may not be set can't be done safely. The Python binding handles this case:query_metadataraisesKeyErrorandget_metadatareturns its default.Change
Project::query_metadatanow returnsOption<Ref<Metadata>>, andNonewhen the core returns null. That matchesBinaryView,Function,TypeLibraryandTypeArchive, whosequery_metadataalready returnOption. This changes the method's signature, so callers need to handle theOption. Nothing else in this repository calls it exceptrust/tests/project.rs, which is updated.Testing
rust/tests/project.rsnow unwraps the result where the key is set. It also checks thatquery_metadatareturnsNoneright afterremove_metadata, which would have crashed before.cargo test --test projectpasses (3 tests), andcargo fmtis clean on the changed files.