Description
What is the feature you'd like to have?
In the Rust API, the functionality to convert between the Rust wrapper types and the underlying C FFI types is currently marked pub(crate)
. I am requesting that it be made public in some form. This functionality includes from_raw
, into_raw
, inc_ref
, the handle
property (could be changed to a function), etc.
Is your feature request related to a problem?
While writing a Rust plugin, I ran into three different use cases where I needed to convert between Rust API wrappers and raw pointers to the C FFI types:
- Using
binaryninjacore_sys
to call functions that don't have a Rust wrapper yet (in my case,BNParseTypeString
). - Communicating with Python code that is using BN's Python API (example - not the best code but it works).
- Using a raw pointer as a hash map key (so that I can keep a per-object cache, but without keeping the object alive as would happen if I just used the wrapper type as the key).
Currently I am accomplishing all three by transmuting between the Rust wrapper types and raw pointers, but that is an abstraction violation. It would be better if I could use the proper APIs for this.
Are any alternative solutions acceptable?
In theory, you could obviate the need to drop down to the C API by providing the functionality natively. Respectively:
- Wrap all the missing functions.
- Add some kind of built-in Python object conversion functionality.
- Add some kind of 'unique ID' method or weak reference type.
But even then I think there would be use cases here and there for dropping down to the C API, e.g. interop with C or C++ code.