From 0f0098d4733db10e384aef8030ca082574cc9299 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F." Date: Wed, 25 Dec 2024 10:38:07 +0100 Subject: [PATCH] Finished change around of wrapping SUNContext in a NonNull --- src/cvode_sens.rs | 2 +- src/lib.rs | 8 ++++---- src/nvector.rs | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cvode_sens.rs b/src/cvode_sens.rs index 8e868c9..19de823 100644 --- a/src/cvode_sens.rs +++ b/src/cvode_sens.rs @@ -184,7 +184,7 @@ where atol_sens, user_data, sensi_out_buffer: array_init::array_init(|_| { - NVectorSerialHeapAllocated::new(context.as_ptr()) + NVectorSerialHeapAllocated::new(context) }), }; { diff --git a/src/lib.rs b/src/lib.rs index d195750..7334814 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -105,7 +105,7 @@ //! ``` use std::{ffi::c_void, os::raw::c_int, ptr::NonNull}; -use sundials_sys::{realtype, SUNComm, SUNContext, _SUNContext}; +use sundials_sys::{realtype, SUNComm, SUNContext, SUNContext_}; mod nvector; pub use nvector::{NVectorSerial, NVectorSerialHeapAllocated}; @@ -226,12 +226,12 @@ fn check_flag_is_succes(flag: c_int, func_id: &'static str) -> Result<()> { } } -pub type SunContext = std::ptr::NonNull<_SUNContext>; +pub type SunContext = std::ptr::NonNull; fn sundials_create_context() -> Result { let context = unsafe { let mut context: SUNContext = std::ptr::null_mut(); - let ompi_communicator_t: SUNComm = std::ptr::null_mut(); + let ompi_communicator_t: SUNComm = 0; sundials_sys::SUNContext_Create(ompi_communicator_t, &mut context); check_non_null(context, "SUNContext_Create")?; std::ptr::NonNull::new(context).unwrap() @@ -240,7 +240,7 @@ fn sundials_create_context() -> Result { } fn sundials_free_context(context: SunContext) -> Result<()> { let mut ptr = context.as_ptr(); - let ptr_ptr: *mut *mut _SUNContext = &mut ptr; + let ptr_ptr: *mut *mut SUNContext_ = &mut ptr; unsafe { sundials_sys::SUNContext_Free(ptr_ptr) }; Ok(()) } diff --git a/src/nvector.rs b/src/nvector.rs index 24d0989..64e34b9 100644 --- a/src/nvector.rs +++ b/src/nvector.rs @@ -3,8 +3,8 @@ use std::{ ops::{Deref, DerefMut}, ptr::NonNull, }; - -use sundials_sys::{realtype, SUNContext, _SUNContext}; +use sundials_sys::realtype; +use crate::SunContext; /// A sundials `N_Vector_Serial`. #[repr(transparent)] @@ -53,13 +53,13 @@ impl DerefMut for NVectorSerialHeapAllocated { } impl NVectorSerialHeapAllocated { - unsafe fn new_inner_uninitialized(context: SUNContext) -> NonNull> { - let raw_c = sundials_sys::N_VNew_Serial(SIZE.try_into().unwrap(), context); + unsafe fn new_inner_uninitialized(context: SunContext) -> NonNull> { + let raw_c = sundials_sys::N_VNew_Serial(SIZE.try_into().unwrap(), context.as_ptr()); NonNull::new(raw_c as *mut NVectorSerial).unwrap() } /// Creates a new vector, filled with 0. - pub fn new(context: SUNContext) -> Self { + pub fn new(context: SunContext) -> Self { let inner = unsafe { let x = Self::new_inner_uninitialized(context); let ptr = sundials_sys::N_VGetArrayPointer_Serial(x.as_ref().as_raw()); @@ -72,9 +72,9 @@ impl NVectorSerialHeapAllocated { } /// Creates a new vector, filled with data from `data`. - pub fn new_from(data: &[realtype; SIZE], context: std::ptr::NonNull<_SUNContext>) -> Self { + pub fn new_from(data: &[realtype; SIZE], context: SunContext) -> Self { let inner = unsafe { - let x = Self::new_inner_uninitialized(context.as_ptr()); + let x = Self::new_inner_uninitialized(context); let ptr = sundials_sys::N_VGetArrayPointer_Serial(x.as_ref().as_raw()); std::ptr::copy_nonoverlapping(data.as_ptr(), ptr, SIZE); x