contextfree / winrt-rust

Use and (eventually) make Windows Runtime APIs with Rust
Apache License 2.0
142 stars 10 forks source link

Get rid of drop flags in wrappers #12

Closed Boddlnagg closed 7 years ago

Boddlnagg commented 7 years ago

Both HString and ComPtr<T> should be pointer sized, since they are wrapping a pointer, but actually are bigger because of drop flags. This is a problem for arrays/slices, because an array of HSTRINGs should be transmutable to an array of HStrings, and the same for ComPtr (element-wise conversion would be too expensive). This is why we currently expose raw types for arrays.

One possibility is #[unsafe_no_drop_flag], but this would not work on stable. Waiting for https://github.com/rust-lang/rust/issues/34398 should also resolve the issue.

chris-morgan commented 7 years ago

Nightly (0.12) has MIR turned on by default now and doesn’t add a drop flag to the type any more; hopefully there won’t be any major issues, and it’ll all stay with MIR enabled and no drop flags added when we get to 0.12 being released as stable.

I reckon only supporting nightly for the next few months is perfectly reasonable.

Boddlnagg commented 7 years ago

Thanks for your comment, @chris-morgan! However, the current nightly still has the embedded drop flag even if it's not used (https://is.gd/VsLXeK). I think this is because https://github.com/rust-lang/rust/issues/34398 is not yet resolved.

I agree that the way to go is to just wait until this is done and then require nightly until it hits stable.

Boddlnagg commented 7 years ago

https://github.com/rust-lang/rust/pull/35764 will finally remove the drop flags.

Boddlnagg commented 7 years ago

:tada: https://github.com/rust-lang/rust/pull/35764 was merged! So we just need to wait for the next nightlies.

Boddlnagg commented 7 years ago

This now works correctly on recent nightlies, #23 adds tests for it which fail in the presence of dropflags.