Comments (4)
Right, the problem here is that I (stupidly) hadn't realized field access was even possible via UniquePtr
. Oops. I was expecting field access to opaque types solely to be possible only via accessor methods in C++ which I have yet to generate.
(The solution is probably for autocxx
to generate a blank struct for things which are opaque, such that there are no fields to have the wrong offsets.)
from autocxx.
The solution is probably for
autocxx
to generate a blank struct for things which are opaque, such that there are no fields to have the wrong offsets.
Public fields should be fine as long as there is a way to find out the presence of padding from bindgen. (I have never looked into what information bindgen has; you might already have considered this and it's not possible or would be too platform-specific.)
The Rust struct I would expect generated for that input would be something like:
#[repr(C)]
pub struct S {
pub i: u32,
_padding0: [u8; 4],
pub s: ::cxx::CxxString,
_actual_s: [u64; 3],
}
Notice not all fields are pub which makes the struct not constructible from Rust with an S { ... }
struct literal expression, but that is fine because it shouldn't be constructible by value in Rust anyway.
This way we're still able to take references to s
for passing to C++ or calling e.g. the Debug impl of CxxString.
from autocxx.
Oh here is a way that would only use information that the current implementation is already using:
#[repr(C)]
pub struct S {
pub i: u32,
_align_s: [[u64; 3]; 0], // [T; 0] where T is the type of _actual_s determined through bindgen
pub s: ::cxx::CxxString,
_actual_s: [u64; 3],
}
from autocxx.
as long as there is a way to find out the presence of padding from bindgen. (I have never looked into what information bindgen has; you might already have considered this and it's not possible or would be too platform-specific.)
Unfortunately, there be doom here.
The relevant limitation on bindgen is lack of support for template specialization. It seems from my explorations that any real STL type except std::unique_ptr
involves partial template specialization and therefore the layout cannot be accurately calculated by bindgen. In fact, in autocxx
, we replace std::string
with a nonsense fictional type as it simply failed to deal with the real std::string
at all. (I can't remember the exact symptoms, but they seemed definitively doomed, and expected).
This leads to an interesting and worrying question though.
In cxx, we have:
- Opaque
- Trivial - no non-trivial move constructor, no destructor
For the purposes of field access, we need something slightly different:
- "Plain old data" - bindgen can calculate field offsets correctly
- Not POD - bindgen can't due to
std::string
or other type that might involve template specialization.
These things have been 100% correlated so far, but they're not the same and I'll need to be aware of this. #17 is therefore possibly just wrong.
from autocxx.
Related Issues (20)
- Github CI fails because of panic in autocxx-bindgen HOT 5
- Support cxx opaque types for subclassing HOT 2
- Can't recognize std::vector<int> HOT 1
- 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
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.