From d27bcbf19eae8cabf1ee9b3ad0243e3fa5bb6975 Mon Sep 17 00:00:00 2001 From: Lofty Date: Wed, 23 Nov 2022 03:47:04 +0000 Subject: [PATCH] awooter: fix an API soundness issue --- common/route/awooter/rust/src/npnr.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/route/awooter/rust/src/npnr.rs b/common/route/awooter/rust/src/npnr.rs index 90bd7fd0..1ceab4c4 100644 --- a/common/route/awooter/rust/src/npnr.rs +++ b/common/route/awooter/rust/src/npnr.rs @@ -54,7 +54,14 @@ pub struct PortRef { } impl PortRef { - pub fn cell(&self) -> Option<&mut CellInfo> { + pub fn cell(&self) -> Option<&CellInfo> { + // SAFETY: handing out &s is safe when we have &self. + unsafe { npnr_portref_cell(self).as_ref() } + } + + pub fn cell_mut(&mut self) -> Option<&mut CellInfo> { + // SAFETY: handing out &mut is safe when we have &mut self + // as getting multiple &mut CellInfo would require multiple &mut PortRef. unsafe { npnr_portref_cell(self).as_mut() } } }