Comments (7)
Yeah to be clear I meant to make __IncompleteArrayField
optionally a DST, with the same-ish API to consumers, and we'd keep the current version as default at least for a bit. But yeah I guess you'd need from_ptr and such for the new version anyways so maybe it's not such a great idea.
from rust-bindgen.
Prototype implementation in #2772
from rust-bindgen.
Hmm, this seems fine, but maybe we should just make the implementation of __IncompleteArrayField
use them or so? Would that not be feasible?
from rust-bindgen.
That's a possibility but there's a few downsides:
- It currently relies on nightly features, and I don't know what their stabilization path is
- It's a pretty large back-compat break
Specifically for the second, since these become DST types, it means it's no longer possible to directly reference them by value, so you wouldn't be able to do something like:
let hdr = msg { ... set up fields ...};
// (something to set up payload)
*ptr = hdr;
That's not the end of the world of course - that's why from_ptr_mut
exists.
The other problem is that all pointers and references to these objects will be fat, and so not C-ABI compatible. So something like:
struct controlblock {
struct msg *messagequeue;
};
could not be directly converted to:
#[repr(C)]
struct controlblock {
messagequeue: *mut msg,
}
Currently this proposed API is using *mut/const ()
as the thin placeholder, but we could define associated types for typed thin variants, eg:
#[repr(C)]
struct controlblock {
messagequeue: *mut msg::Thin,
}
Likewise you wouldn't be able to directly pass or return the fat pointers to/from C-ABI functions.
I don't think any of these are show-stoppers; structures with flex array have always been a bit awkward to deal with, and I think this API is an accurate reflection of that (ie, it would make it harder to get things wrong). If we could wave a magic wand to stabilize the features and update all existing code to the new API, then I think we could replace __IncompleteArrayField
entirely.
from rust-bindgen.
BTW I also experimented with this idea using a trait (https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=114e0ca2cbc10523037946a7d9c61a06) , since it's a fairly self-contained abstraction that you might want to generalize over.
But as far as I know bindgen doesn't have a support library crate where this could live, and it doesn't seem like it makes sense to emit a separate variant of this trait for each bindgenned module - that would be no better than the current proposal just using intrinsic methods.
from rust-bindgen.
I've published PR #2772 with a fairly complete implementation of this idea.
from rust-bindgen.
I think #2772 is ready for review.
from rust-bindgen.
Related Issues (20)
- `static mut` deprecation HOT 1
- Bindgen release
- Failed to generate `Default` impl for arrays larger than 32 entries HOT 8
- wrap-static-fns converts _Bool to bool, causing a compile error HOT 3
- Clippy warns of useless_transmute in bitfields' setters and getters HOT 2
- Blocklist/allowlist based on header HOT 2
- Simplify target conversion further
- UINTMAX64 can never be generated HOT 2
- can not get the non-type template arg?
- allowlist_item does not work for anonymous enums - allowlist_var does HOT 1
- --target=wasm32-unknown-unknown: 'stdio.h' file not found HOT 5
- Unable to generate bindings for Arduino library IRremote.hpp on MacOS HOT 1
- Thread panicking at bindgen .Err state unable to found libclang.dll but it available on the path variable HOT 2
- feature request: Enable deriving `Clone`, `Copy`, etc... for `__IncompleteArrayField` and containing structs. HOT 2
- Support for raw-dylib for Windows
- Support for one set of bindings depending on another (conflicting `__BindgenBitfieldUnit`) HOT 3
- Unable to run bindgen on ubuntu 22.04 HOT 2
- update requirements for OpenBSD HOT 10
- Building tests for LightGBM bindings failes with linker error
- Unable to prevent Clang headers from being used
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 rust-bindgen.