-
Notifications
You must be signed in to change notification settings - Fork 152
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
Remove debug assert from Peripherals::steal #238
Conversation
So, not the final word, but my $0.02, This could maaaaaaybe be considered a breaking change, if someone was relying on this assert to trigger in debug mode (it's a long shot, I know). I would say that either of the following would be a no-brainer approve from me:
I don't have strong feelings either way, but I would appreciate more feedback from anyone on @rust-embedded/tools |
@jamesmunns Back when @japaric introduced the I still see this as an ergonomics only issue since it is possible to access the peripherals anyway and a crippled |
@therealprof there are some things you cannot do, I actually ran in to it recently. For example, you can use This means you cannot easily call a member function of I will admit I have done this before, and it seems to work, but seems incredibly unsound: // AJM - unsure if this is sound
let cpuid = &mut *(CPUID::ptr() as *mut CPUID);
let scb = &mut *(SCB::ptr() as *mut SCB);
// Disable icache
scb.disable_icache();
// Disable dcache
scb.disable_dcache(cpuid); |
For context, this was in a Though, it might be nice to be able to "give back" the peripherals to allow them to be taken later, but that really would only help in the case of pre-init, not in an interrupt context or anything, so probably not really worth it. |
One of the most useful aspects of |
I've pushed and published a manual update to the crates relevant to me, but only because I was able to take ownership of them. So while I've got a workaround, it's not ideal. :) I'd love to get this merged in so I can de-monkey-ify things. |
I think, considering I'd argue that removing this assert makes sense and it should be up to user to control the usage of |
@DoumanAsh I'm not sure I understand what you're saying in your second paragraph. Are you suggesting to leave the |
@thenewwazoo No, what I'm saying is that any sort of assertion to prevent calling this method twice, makes it safe. UPD: Actually noticed I made mistake in my original comment 😄 |
I would go further and in addition to removing the dbg_assert!() do the following:
|
To move things forward I'm going out on a limb here and will approve this on the basis that it never made sense to me and @DoumanAsh has quite a point in saying that this function is marked |
bors r+ |
238: Remove debug assert from Peripherals::steal r=therealprof a=thenewwazoo Very simple PR! :) This permits actually-unsafe use of the steal method, and avoids divergent behavior between debug and release modes. Co-authored-by: Brandon Matthews <[email protected]>
Build succeeded |
147: Remove debug_assert from Peripherals::steal r=thejpster a=mvirkkunen This is the same change as rust-embedded/svd2rust#238, except for the one bit that isn't generated by svd2rust. There was a decent amount of discussion about this over at that issue, and to me it makes sense to change this here as well. It's `unsafe`, so let the user decide if they want to use it. Co-authored-by: Matti Virkkunen <[email protected]>
Very simple PR! :)
This permits actually-unsafe use of the steal method, and avoids divergent behavior between debug and release modes.