Hpmason / retour-rs

A cross-platform detour library written in Rust
Other
99 stars 18 forks source link

Detours are disabled on drop only in debug builds #43

Closed Kyuuhachi closed 2 months ago

Kyuuhachi commented 8 months ago

This drop impl has a side effect inside a debug_assert!(), which is generally not a good idea.

I personally don't like the disable-on-drop behavior at all since in most cases I want to set a detour at load and then forget about it, but that's a separate issue.

Hpmason commented 8 months ago

I agree, I don't like the debug_assert!() that has a side effect depending on build profile, that should definitely be fixed. Though I think the disable-on-drop is preferred, as follows typical RAII.

If you want to load a detour and forget about it, I'd recommend mem::leak if you want to completely forget about a detour or Box::leak if you need to access it again as a static resource.

So, I definitely want to fix the debug_assert!() side effect, but keep the automatic disable-on-drop since it's easier to explicitly opt-out of it than to opt-in.