From 080ae2ced0dbf290eaaf7c56813dd2191c573a6d Mon Sep 17 00:00:00 2001 From: Thomas van Doornmalen Date: Sat, 13 Feb 2021 21:40:44 +0100 Subject: [PATCH] Backport AsMut fix --- jlrs/Cargo.toml | 2 +- jlrs/src/julia_future.rs | 2 +- jlrs/src/value.rs | 43 +++++++++++++++++++------------------- jlrs/src/value/datatype.rs | 4 ++-- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/jlrs/Cargo.toml b/jlrs/Cargo.toml index 330ff595..d87283ef 100644 --- a/jlrs/Cargo.toml +++ b/jlrs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jlrs" -version = "0.8.0" +version = "0.8.1" authors = ["Thomas van Doornmalen "] description = """ jlrs is a library built around bindings to the Julia C API that enables Julia code to be called diff --git a/jlrs/src/julia_future.rs b/jlrs/src/julia_future.rs index aa559569..bc79e218 100644 --- a/jlrs/src/julia_future.rs +++ b/jlrs/src/julia_future.rs @@ -40,7 +40,7 @@ impl<'frame, 'data> JuliaFuture<'frame, 'data> { pub(crate) fn new<'value, V>( frame: &mut AsyncFrame<'frame>, func: Value, - values: &mut V, + mut values: V, ) -> JlrsResult where V: AsMut<[Value<'value, 'data>]>, diff --git a/jlrs/src/value.rs b/jlrs/src/value.rs index 5ef9689f..e43c88e0 100644 --- a/jlrs/src/value.rs +++ b/jlrs/src/value.rs @@ -112,7 +112,6 @@ use jl_sys::{ jl_type_unionall, jl_typeof, jl_typeof_str, jl_undefref_exception, jl_value_t, }; use smallvec::SmallVec; -use std::borrow::BorrowMut; use std::cell::UnsafeCell; use std::ffi::{CStr, CString}; use std::fmt::{Debug, Formatter, Result as FmtResult}; @@ -371,7 +370,7 @@ impl<'frame, 'data> Value<'frame, 'data> { pub fn instantiate<'value, 'borrow, F, V>( frame: &mut F, ty: DataType, - values: &mut V, + values: V, ) -> JlrsResult> where F: Frame<'frame>, @@ -390,7 +389,7 @@ impl<'frame, 'data> Value<'frame, 'data> { frame: &mut F, output: Output<'output>, ty: DataType, - values: &mut V, + mut values: V, ) -> JlrsResult> where F: Frame<'frame>, @@ -458,13 +457,13 @@ impl<'frame, 'data> Value<'frame, 'data> { /// This function returns an error if there are not enough slots available. pub fn borrow_array( frame: &mut F, - data: &'data mut V, + data: V, dimensions: D, ) -> JlrsResult> where T: IntoJulia + JuliaType, D: Into, - V: BorrowMut<[T]>, + V: AsMut<[T]> + 'data, F: Frame<'frame>, { unsafe { @@ -483,14 +482,14 @@ impl<'frame, 'data> Value<'frame, 'data> { pub fn borrow_array_output<'output, 'borrow, T, D, V, F>( frame: &mut F, output: Output<'output>, - data: &'borrow mut V, + data: V, dimensions: D, ) -> JlrsResult> where 'borrow: 'output, T: IntoJulia + JuliaType, D: Into, - V: BorrowMut<[T]>, + V: AsMut<[T]> + 'borrow, F: Frame<'frame>, { unsafe { @@ -612,8 +611,8 @@ impl<'frame, 'data> Value<'frame, 'data> { /// Create a new named tuple, you can use the `named_tuple` macro instead of this method. pub fn new_named_tuple<'value, 'borrow, F, S, T, V>( frame: &mut F, - field_names: &mut S, - values: &mut V, + mut field_names: S, + mut values: V, ) -> JlrsResult> where F: Frame<'frame>, @@ -685,7 +684,7 @@ impl<'frame, 'data> Value<'frame, 'data> { pub fn apply_type<'fr, 'value, 'borrow, F, V>( self, frame: &mut F, - types: &mut V, + mut types: V, ) -> JlrsResult> where F: Frame<'fr>, @@ -1329,7 +1328,7 @@ impl<'fr, 'data> Value<'fr, 'data> { pub fn call<'frame, 'value, 'borrow, V, F>( self, frame: &mut F, - args: &mut V, + mut args: V, ) -> JlrsResult> where V: AsMut<[Value<'value, 'borrow>]>, @@ -1349,7 +1348,7 @@ impl<'fr, 'data> Value<'fr, 'data> { pub unsafe fn call_unprotected<'base, 'value, 'borrow, V, F>( self, _: Global<'base>, - args: &mut V, + mut args: V, ) -> CallResult<'base, 'borrow> where V: AsMut<[Value<'value, 'borrow>]>, @@ -1373,7 +1372,7 @@ impl<'fr, 'data> Value<'fr, 'data> { pub unsafe fn call_keywords_unprotected<'base, 'value, 'borrow, V, F>( self, _: Global<'base>, - args: &mut V, + mut args: V, ) -> CallResult<'base, 'borrow> where V: AsMut<[Value<'value, 'borrow>]>, @@ -1403,7 +1402,7 @@ impl<'fr, 'data> Value<'fr, 'data> { pub async fn call_async<'frame, 'value, 'borrow, V>( self, frame: &mut crate::frame::AsyncFrame<'frame>, - args: &mut V, + args: V, ) -> JlrsResult> where V: AsMut<[Value<'value, 'borrow>]>, @@ -1804,7 +1803,7 @@ impl<'func, 'funcdata, 'kw, 'kwdata> WithKeywords<'func, 'funcdata, 'kw, 'kwdata pub fn call<'frame, 'value, 'borrow, V, F>( self, frame: &mut F, - args: &mut V, + mut args: V, ) -> JlrsResult> where V: AsMut<[Value<'value, 'borrow>]>, @@ -1833,7 +1832,7 @@ impl<'func, 'funcdata, 'kw, 'kwdata> WithKeywords<'func, 'funcdata, 'kw, 'kwdata pub unsafe fn call_unprotected<'base, 'value, 'borrow, V, F>( self, _: Global<'base>, - args: &mut V, + mut args: V, ) -> CallResult<'base, 'borrow> where V: AsMut<[Value<'value, 'borrow>]>, @@ -1950,7 +1949,7 @@ impl<'output, 'frame, 'data> WithOutput<'output, Value<'frame, 'data>> { pub fn call<'value, 'borrow, 'fr, V, F>( self, frame: &mut F, - args: &mut V, + mut args: V, ) -> CallResult<'output, 'borrow> where 'borrow: 'output, @@ -2048,13 +2047,13 @@ where unsafe fn borrow_array<'data, 'frame, T, D, V, F>( frame: &mut F, - data: &'data mut V, + mut data: V, dimensions: D, ) -> JlrsResult<*mut jl_value_t> where T: IntoJulia + JuliaType, D: Into, - V: BorrowMut<[T]>, + V: AsMut<[T]> + 'data, F: Frame<'frame>, { let dims = dimensions.into(); @@ -2063,7 +2062,7 @@ where match dims.n_dimensions() { 1 => Ok(jl_ptr_to_array_1d( array_type, - data.borrow_mut().as_mut_ptr().cast(), + data.as_mut().as_mut_ptr().cast(), dims.n_elements(0), 0, ) @@ -2073,7 +2072,7 @@ where Ok(jl_ptr_to_array( array_type, - data.borrow_mut().as_mut_ptr().cast(), + data.as_mut().as_mut_ptr().cast(), tuple.ptr(), 0, ) @@ -2084,7 +2083,7 @@ where Ok(jl_ptr_to_array( array_type, - data.borrow_mut().as_mut_ptr().cast(), + data.as_mut().as_mut_ptr().cast(), tuple.ptr(), 0, ) diff --git a/jlrs/src/value/datatype.rs b/jlrs/src/value/datatype.rs index 9b3491d0..8edbbd73 100644 --- a/jlrs/src/value/datatype.rs +++ b/jlrs/src/value/datatype.rs @@ -272,7 +272,7 @@ impl<'frame> DataType<'frame> { pub fn instantiate<'fr, 'value, 'borrow, F, V>( self, frame: &mut F, - values: &mut V, + mut values: V, ) -> JlrsResult> where F: Frame<'fr>, @@ -295,7 +295,7 @@ impl<'frame> DataType<'frame> { self, frame: &mut F, output: Output<'output>, - values: &mut V, + values: V, ) -> JlrsResult> where F: Frame<'fr>,