-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Enable va_arg for raw pointers to unsized types #61126
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Good catch. Could you add a ui test for this? |
Would |
431c65a
to
29f4ad4
Compare
I added a "pointer to foreign type" test to |
Wouldn't this would make |
On Sat, May 25, 2019 at 02:34:33AM -0700, whataloadofwhat wrote:
Wouldn't this would make `ap.arg::<*const [u8]>()` legal? Isn't that bad?
That's fine; you're just taking a pointer from the VaArgs, and that
pointer can point to anything.
|
|
Right, Pointers-to-slices and pointers-to-traits are currently the only 2 kinds of fat pointers in Rust, afaik. |
My latest update is that I have an idea how to fix this using auto traits (basically making |
After looking into auto traits for a bit, I came to the conclusion that
The other kind of fat pointers in Rust are pointers-to-traits, i.e., |
29f4ad4
to
0fb85ef
Compare
It actually does, recursively (if all members of the aggregate implement the trait, then the aggregate does too). However, it still doesn't the original problem of allowing fat pointers. |
Adding a function to |
that seems reasonable
AFAIK I hit some strange errors on windows with aggregate types. If we use |
ping from triage... @ahomescu thank you for your time, can you please provide a status? |
@rholderfield This is blocked until I figure out a way to disable the The change from a regular trait to an auto trait also enables |
This RFC could help us, since it would let us implement |
ping from triage @joshtriplett and @dlrobertson, could you comment on the author's concern above? |
pinging agan from triage @joshtriplett and @dlrobertson @ahomescu
|
Yeah RFC 2580 would be perfect for resolving this issue. |
0fb85ef
to
138f3bb
Compare
I added a source code comment on RFC 2580. In the meantime, we could either wait for that to be implemented, or keep working on this PR as-is. |
138f3bb
to
74e1455
Compare
74e1455
to
0ff1661
Compare
I decided to submit a separate PR for the auto-trait along with more tests, so I removed it from this one. The fix for the @joshtriplett Do you want to approve this PR for now (and fix the issue later), or wait? |
@ahomescu So the current state is that you can't have pointers to unsized types at all (and thus can't accidentally treat a non-thin pointer as FFI-safe/ |
That basically covers it. The original motivation was to enable |
@ahomescu It's not clear to me that we need all of RFC 2580; don't we just want to say that thin pointers are FFI-safe and non-thin pointers aren't? Also, I don't think we should enable something that makes it easy for people to do the wrong thing here, if we have a means of distinguishing the cases instead and only allowing thin pointers. |
Do you mean for Edit: Alternatively, it would be great to somehow say " |
On Mon, Sep 09, 2019 at 01:33:26PM -0700, ahomescu wrote:
> don't we just want to say that thin pointers are FFI-safe and non-thin pointers aren't?
Do you mean for `improper_ctypes`? That's an interesting idea, I'm not sure how that interacts with `VaListImpl::arg()`. The context here is that we want to allow someone to do `ap.arg::<*const Foo>()` for an opaque type `Foo`. Would `improper_ctypes` even check this?
I'm not sure.
|
@joshtriplett I checked the implementation for What I could try to do is replace |
On Mon, Sep 09, 2019 at 02:47:29PM -0700, ahomescu wrote:
@joshtriplett I checked the implementation for `improper_ctypes`, and it's just a lint that checks that the input and output types for each foreign function are FFI-safe, but with its own [implementation](https://github.com/rust-lang/rust/blob/master/src/librustc_lint/types.rs#L600) of whether each type is FFI-safe.
What I could try to do is replace `VaArgSafe` with a `FfiSafe` trait that the compiler auto-magically implements for all FFI-safe types (kinda like `Sized`), using the implementation from the lint. `VaListImpl::arg()` would then be implemented for `FfiSafe`, which would cover the opaque type case and many more.
However, this would turn `FfiSafe` into a magic trait, is that desirable? Also, is this new trait something that would be useful for other users?
Seems like it'd be quite useful, yes. That probably needs some broader
discussion, but I'd like to use *exactly* the same list of types.
|
@joshtriplett @dlrobertson I discovered something interesting: some of the FFI-unsafe types are not supported by the backend anyway, I added a new UI test with the following: pub unsafe extern "C" fn vararg_unsafe_types(_: usize, mut ap: ...) {
let _ = ap.arg::<*const str>();
let _ = ap.arg::<*const [u8]>();
} and got an ICE when running the test:
I've also been looking into the implementation of the |
That is an interesting ICE. You should post an issue for it. I wonder what the values |
@dlrobertson It should be |
ping from triage @ahomescu, any update on this PR or the ICE above? |
@dlrobertson @bjorn3 That ICE only occurs if I enable @hdhoang I've looked into possible ways to implement |
Ping from triage: |
@JohnCSimon I'm fine with closing it for now. |
Closing this due to inactivity. Thanks for making the effort to contribute and when you want to work on this, you can make a new PR. |
This patch implements
VaArgSafe
for raw pointers to unsized types, which lets users callVaList::arg
for such pointers. Everything else inlibcore
usesT: ?Sized
for raw pointers, soVaList
should too, and we already ran into a case where we could use this for C2Rust.r? @joshtriplett
cc @dlrobertson