From 2b0623121b18bfe7c4f722fd64faef1c77ee303e Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 15 Jan 2024 11:00:18 +0100 Subject: [PATCH] docs(core/rust): improve safety comments in buffer.rs --- core/embed/rust/src/micropython/buffer.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/embed/rust/src/micropython/buffer.rs b/core/embed/rust/src/micropython/buffer.rs index 9cf330ad1c..f0365872b7 100644 --- a/core/embed/rust/src/micropython/buffer.rs +++ b/core/embed/rust/src/micropython/buffer.rs @@ -196,6 +196,8 @@ fn get_buffer_info(obj: Obj, flags: u32) -> Result /// (a) no mutable reference to the same buffer is held at the same time, /// (b) the buffer is not modified in MicroPython while the reference to it is /// being held. +/// The returned value is NOT guaranteed to be a head pointer, so the +/// destination might get GC'd. Do not store the reference. pub unsafe fn get_buffer<'a>(obj: Obj) -> Result<&'a [u8], Error> { let bufinfo = get_buffer_info(obj, ffi::MP_BUFFER_READ)?; @@ -221,6 +223,8 @@ pub unsafe fn get_buffer<'a>(obj: Obj) -> Result<&'a [u8], Error> { /// (a) no other reference to the same buffer is held at the same time, /// (b) the buffer is not modified in MicroPython while the reference to it is /// being held. +/// The returned value is NOT guaranteed to be a head pointer, so the +/// destination might get GC'd. Do not store the reference. pub unsafe fn get_buffer_mut<'a>(obj: Obj) -> Result<&'a mut [u8], Error> { let bufinfo = get_buffer_info(obj, ffi::MP_BUFFER_WRITE)?;