edef1c / libfringe

a Rust library implementing safe, lightweight context switches, without relying on kernel services
https://edef1c.github.io/libfringe
Apache License 2.0
512 stars 31 forks source link

Panic and leak the stack if it's unsafe to drop it #66

Closed edef1c closed 7 years ago

edef1c commented 7 years ago

We can't free the stack before the generator has returned, or been unwound. Without unwinding, the only safe course of action is to leak it.

We could additionally panic, since users can mem::forget the generator if they do intend to leak. Leaking in the destructor is not avoidable even if we panic, since we can't free the stack.

edef1c commented 7 years ago

An additional complication with panicking is that this turns any panic that drops the generator into a panic-in-panic, and we can't find out whether we're currently unwinding without help from the platform library (eg std::thread::panicking).

edef1c commented 7 years ago

@Amanieu raised a rather important concern: leaking the Stack impl doesn't do us any good if it doesn't own the underlying memory (ie if it isn't 'static) For example, if we have a SliceStack using an array on the parent's stack, returning or panicking will free it even if we leak the SliceStack value we hold. Either we have to restrict ourselves to Stack + 'static or we have to ensure unwinding.

edef1c commented 7 years ago

I should probably document the guarantee unsafe_new expects you to provide but I'll have to work on wording for that.