From 5318fcda33aa25dc5f0b3ce3a9e06d3aa3c0be07 Mon Sep 17 00:00:00 2001 From: Mark Giraud Date: Mon, 14 Aug 2023 13:38:13 +0200 Subject: [PATCH] fix: Make from handle function unsafe --- bindings/rust/src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bindings/rust/src/lib.rs b/bindings/rust/src/lib.rs index 9e424e2d..4de93722 100644 --- a/bindings/rust/src/lib.rs +++ b/bindings/rust/src/lib.rs @@ -54,7 +54,6 @@ pub use crate::{ use alloc::{boxed::Box, rc::Rc, vec::Vec}; use core::{cell::UnsafeCell, ptr}; -use bitflags::Flags; use ffi::uc_handle; use libc::c_void; @@ -166,13 +165,14 @@ impl<'a> Unicorn<'a, ()> { pub fn new(arch: Arch, mode: Mode) -> Result, uc_error> { Self::new_with_data(arch, mode, ()) } -} -impl<'a> TryFrom for Unicorn<'a, ()> { - type Error = uc_error; - - #[allow(clippy::not_unsafe_ptr_arg_deref)] - fn try_from(handle: uc_handle) -> Result, uc_error> { + /// # Safety + /// The function has to be called with a valid uc_handle pointer + /// that was previously allocated by a call to uc_open. + /// Calling the function with a non null pointer value that + /// does not point to a unicorn instance will cause undefined + /// behavior. + pub unsafe fn from_handle(handle: uc_handle) -> Result, uc_error> { if handle.is_null() { return Err(uc_error::HANDLE); }