From bba9e436393e3606bfe19a2a1d40c849a9242f4a Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Mon, 17 Jul 2017 16:16:05 -0700 Subject: Refactor ptrace_get_data The boxing and unboxing was unnecessary and instead the references to the type on the stack can just be cast. --- src/sys/ptrace.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs index 4c3d29b1..73ca9160 100644 --- a/src/sys/ptrace.rs +++ b/src/sys/ptrace.rs @@ -97,13 +97,10 @@ fn ptrace_peek(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data /// requests. fn ptrace_get_data(request: ptrace::PtraceRequest, pid: Pid) -> Result { // Creates an uninitialized pointer to store result in - let data: Box = Box::new(unsafe { mem::uninitialized() }); - let data: *mut c_void = unsafe { mem::transmute(data) }; - let res = unsafe { ffi::ptrace(request, pid.into(), ptr::null_mut(), data) }; + let data: T = unsafe { mem::uninitialized() }; + let res = unsafe { ffi::ptrace(request, pid.into(), ptr::null_mut(), &data as *const _ as *const c_void) }; Errno::result(res)?; - // Convert back into the original data format and return unboxed value - let data: Box = unsafe { mem::transmute(data) }; - Ok(*data) + Ok(data) } fn ptrace_other(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result { -- cgit v1.2.3