Comments (5)
Here's my plan here.
- bindgen needs to indicate the difference between reference and pointer in the generated bindings. Currently it does not.
- bindgen currently generates (almost) identical bindings for
uint32_t take_bob(const Bob& a)
asuint32_t take_bob(const Bob* a)
. At some point, we'll need to upstream a patch to bindgen to indicate the difference, if they're amenable, and re-fork bindgen meanwhile to add extra metadata. - Meanwhile there is one exception: the
#[link_name]
attribute added to such functions. As a world-class dreadful hack, we can demangle that name to work out whether a given parameter is a reference or a pointer. Perhaps. This might be a hack too far even for me, but I'm still at the stage of figuring out whetherautocxx
is ergonomic. - Another option is to allow this to be specified in a directive within
include_cpp!
. - Mangled names don't include the return type, so we can't know if a function returns a pointer or a reference. Returning a reference is pretty unusual so I think we'll assume a pointer unless a directive says it's a reference. Probably.
- A final option is to move away from bindgen to libclang directly, which has been proposed by a couple of people, but I tend to assume that autocxx currently relies on a large mountain of subtleties within bindgen which would be incredibly complex to replicate.
- bindgen currently generates (almost) identical bindings for
- We will assume that C++ references can't be null.
- We will assume that C++ pointers can be null.
- For pointers, we will use
UniquePtr
in Rust bindings, just as we do for non-POD value parameters. This means we'll need to generate wrapper functions for a higher percentage of bindings, which will package and unpackage thestd::unique_ptr
into a raw pointer and vice-versa. - When calling functions that take a raw pointer parameter, I believe it is safe to call them using a
UniquePtr
from Rust. - When calling functions which return a raw pointer, we have no guarantees about the uniqueness of the return value. As such I think such functions need to be tagged as
unsafe
in order to indicate that the caller needs to take special care to ensure the uniqueness of the pointer.
from autocxx.
See also dtolnay/cxx#115
from autocxx.
Possibly more relevant upstream issue: dtolnay/cxx#164.
from autocxx.
In progress at dtolnay/cxx#689
from autocxx.
This landed!
from autocxx.
Related Issues (20)
- Feature request: be able to implement functions declared in C++ headers HOT 1
- Missing `iterator` definition HOT 5
- "`*const u8` cannot be shared between threads safely" HOT 3
- Cannot pass UniquePtr from Rust to c++ std::unique_ptr HOT 6
- binding generation fails with 16bit floats HOT 2
- Codegen results in function call with incorrect number of arguments HOT 2
- Unable to generate bindings for std::array<unsigned char, 6> HOT 1
- Question: How to "export" (i.e. make `pub`) modules generated by `generate_ns!()`? HOT 1
- Usage of system frameworks (macOS)? HOT 3
- cannot bind rvalue reference of type .. to lvalue of type .. / pointer argument requires that the function be marked unsafe
- Calling protected functions from a Rust subclass
- Generated Binding fails to compile due to due to `redefinition as different kind of symbol` Error HOT 1
- New method of POD-Types not creating a POD rust type
- Unable to find CXX header for C++ HOT 1
- Unable to Call Base Class Functions When Base is a Template Class in autocxx
- autocxx-bindgen upgrade suggestions
- Cannot instantiate C++ `std::vec` of a simple C++ type due to lack of `cxx` `VectorElement` trait implementation. HOT 3
- Workarounds for Pointer to another pointer?
- Do all required include paths have to be included in Builder::new()
- Couldn’t generate binding for opencv cv::OutputArray HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autocxx.