1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-14 03:30:02 +00:00

docs(core/rust): improve safety comments in buffer.rs

This commit is contained in:
matejcik 2024-01-15 11:00:18 +01:00 committed by Jiří Musil
parent 0c793084f8
commit 03298ca80f

View File

@ -196,6 +196,8 @@ fn get_buffer_info(obj: Obj, flags: u32) -> Result<ffi::mp_buffer_info_t, Error>
/// (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)?;