|
1 | 1 | use std::borrow::Cow; |
2 | | -use std::cell::UnsafeCell; |
3 | 2 | use std::ops::Deref; |
4 | 3 | #[cfg(not(feature = "luau"))] |
5 | 4 | use std::ops::{BitOr, BitOrAssign}; |
@@ -51,14 +50,18 @@ impl<'a> Debug<'a> { |
51 | 50 | pub(crate) fn new(lua: &'a RawLua, ar: *mut lua_Debug) -> Self { |
52 | 51 | Debug { |
53 | 52 | lua: EitherLua::Borrowed(lua), |
54 | | - ar: ActivationRecord::Borrowed(ar), |
| 53 | + ar: ActivationRecord(ar, false), |
55 | 54 | } |
56 | 55 | } |
57 | 56 |
|
58 | | - pub(crate) fn new_owned(guard: ReentrantMutexGuard<'a, RawLua>, _level: c_int, ar: lua_Debug) -> Self { |
| 57 | + pub(crate) fn new_owned( |
| 58 | + guard: ReentrantMutexGuard<'a, RawLua>, |
| 59 | + _level: c_int, |
| 60 | + ar: Box<lua_Debug>, |
| 61 | + ) -> Self { |
59 | 62 | Debug { |
60 | 63 | lua: EitherLua::Owned(guard), |
61 | | - ar: ActivationRecord::Owned(UnsafeCell::new(ar)), |
| 64 | + ar: ActivationRecord(Box::into_raw(ar), true), |
62 | 65 | #[cfg(feature = "luau")] |
63 | 66 | level: _level, |
64 | 67 | } |
@@ -207,19 +210,19 @@ impl<'a> Debug<'a> { |
207 | 210 | } |
208 | 211 | } |
209 | 212 |
|
210 | | -enum ActivationRecord { |
211 | | - #[cfg(not(feature = "luau"))] |
212 | | - Borrowed(*mut lua_Debug), |
213 | | - Owned(UnsafeCell<lua_Debug>), |
214 | | -} |
| 213 | +struct ActivationRecord(*mut lua_Debug, bool); |
215 | 214 |
|
216 | 215 | impl ActivationRecord { |
217 | 216 | #[inline] |
218 | 217 | fn get(&self) -> *mut lua_Debug { |
219 | | - match self { |
220 | | - #[cfg(not(feature = "luau"))] |
221 | | - ActivationRecord::Borrowed(x) => *x, |
222 | | - ActivationRecord::Owned(x) => x.get(), |
| 218 | + self.0 |
| 219 | + } |
| 220 | +} |
| 221 | + |
| 222 | +impl Drop for ActivationRecord { |
| 223 | + fn drop(&mut self) { |
| 224 | + if self.1 { |
| 225 | + drop(unsafe { Box::from_raw(self.0) }); |
223 | 226 | } |
224 | 227 | } |
225 | 228 | } |
|
0 commit comments