fix crash

This commit is contained in:
chayleaf 2024-08-13 12:37:59 +07:00
parent 07e3e45579
commit 76ffd7af5b
Signed by: chayleaf
GPG key ID: 78171AD46227E68E
3 changed files with 24 additions and 12 deletions

View file

@ -29,16 +29,28 @@ macro_rules! impl_tuple {
&self, &self,
qstate: &mut crate::unbound::ModuleQstateMut<Self::QstateData>, qstate: &mut crate::unbound::ModuleQstateMut<Self::QstateData>,
event: crate::unbound::ModuleEvent, event: crate::unbound::ModuleEvent,
entry: &mut crate::unbound::OutboundEntryMut, entry: Option<&mut crate::unbound::OutboundEntryMut>,
) -> Option<ModuleExtState> { ) -> Option<ModuleExtState> {
// lol idk how to safely "clone" Option<&mut>
if let Some(entry) = entry {
#[allow(unused_mut)] #[allow(unused_mut)]
let mut ret = self.0.operate(qstate, event, entry); let mut ret = self.0.operate(qstate, event, Some(entry));
$(if let Some(state) = self.$i.operate(qstate, event, entry) { $(if let Some(state) = self.$i.operate(qstate, event, Some(entry)) {
if !matches!(ret, Some(ret) if ret.importance() >= state.importance()) { if !matches!(ret, Some(ret) if ret.importance() >= state.importance()) {
ret = Some(state); ret = Some(state);
} }
})* })*
ret ret
} else {
#[allow(unused_mut)]
let mut ret = self.0.operate(qstate, event, None);
$(if let Some(state) = self.$i.operate(qstate, event, None) {
if !matches!(ret, Some(ret) if ret.importance() >= state.importance()) {
ret = Some(state);
}
})*
ret
}
} }
fn get_mem(&self, env: &mut crate::unbound::ModuleEnvMut<Self::EnvData>) -> usize { fn get_mem(&self, env: &mut crate::unbound::ModuleEnvMut<Self::EnvData>) -> usize {
self.0.get_mem(env) $(* self.$i.get_mem(env))* self.0.get_mem(env) $(* self.$i.get_mem(env))*

View file

@ -716,7 +716,7 @@ impl UnboundMod for ExampleMod {
&self, &self,
qstate: &mut crate::unbound::ModuleQstateMut<Self::QstateData>, qstate: &mut crate::unbound::ModuleQstateMut<Self::QstateData>,
event: ModuleEvent, event: ModuleEvent,
_entry: &mut crate::unbound::OutboundEntryMut, _entry: Option<&mut crate::unbound::OutboundEntryMut>,
) -> Option<ModuleExtState> { ) -> Option<ModuleExtState> {
match event { match event {
ModuleEvent::New | ModuleEvent::Pass => { ModuleEvent::New | ModuleEvent::Pass => {

View file

@ -32,7 +32,7 @@ pub trait UnboundMod: Send + Sync + Sized + RefUnwindSafe + UnwindSafe {
&self, &self,
_qstate: &mut unbound::ModuleQstateMut<Self::QstateData>, _qstate: &mut unbound::ModuleQstateMut<Self::QstateData>,
_event: unbound::ModuleEvent, _event: unbound::ModuleEvent,
_entry: &mut unbound::OutboundEntryMut, _entry: Option<&mut unbound::OutboundEntryMut>,
) -> Option<ModuleExtState> { ) -> Option<ModuleExtState> {
Some(ModuleExtState::Finished) Some(ModuleExtState::Finished)
} }
@ -105,7 +105,7 @@ unsafe impl<T: UnboundMod> SealedUnboundMod for T {
if let Some(ext_state) = self.operate( if let Some(ext_state) = self.operate(
&mut unbound::ModuleQstateMut::from_raw(qstate, id).unwrap(), &mut unbound::ModuleQstateMut::from_raw(qstate, id).unwrap(),
event.into(), event.into(),
&mut unbound::OutboundEntryMut::from_raw(entry).unwrap(), unbound::OutboundEntryMut::from_raw(entry).as_mut(),
) { ) {
if let Some(id) = unbound::check_id(id) { if let Some(id) = unbound::check_id(id) {
(*qstate).ext_state[id] = ext_state as bindings::module_ext_state; (*qstate).ext_state[id] = ext_state as bindings::module_ext_state;