volatile-register icon indicating copy to clipboard operation
volatile-register copied to clipboard

#[repr(C)] and UnsafeCell

Open seeday opened this issue 8 years ago • 1 comments
trafficstars

In the WO struct you use an UnsafeCell to hold the value, but UnsafeCell isn't repr(C) compatible. This causes rust to throw a warning that some struct element isn't repr(C) and should be.

I'm unsure whether or not this breaks things in practice, so what's the fix here, if any? My fork just made it work like RW structs, but would require a minor change to svd2rust (all write functions use mutable borrows).

seeday avatar Dec 13 '16 06:12 seeday

This causes rust to throw a warning that some struct element isn't repr(C) and should be.

In what cases does it throw a warning? FFI boundary?

I'm unsure whether or not this breaks things in practice

Now that we don't have "drop flags", it doesn't.

what's the fix here, if any?

We could mark UnsafeCell, itself, as repr(C).

My fork just made it work like RW structs,

For now, I'd rather not change the API of only WO. I want to review the whole API in the (near?) future.

japaric avatar Dec 14 '16 21:12 japaric