diff --git a/CHANGELOG.md b/CHANGELOG.md index e12cb008..257cfbee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +#### v0.18 + - jlrs is compatible with Julia 1.7 again, but this version not actively tested or supported. Version features have been added to select a particular version of Julia. + + - Foreign types can be reinitialized with `reinit_foreign_type`, this is only available when Julia 1.10 (the current nightly version) is used. + + #### v0.17 - Atomic struct fields are now atomic in the generated bindings. diff --git a/examples/async_tasks.rs b/examples/async_tasks.rs index 5401e2ac..4c00452f 100644 --- a/examples/async_tasks.rs +++ b/examples/async_tasks.rs @@ -47,9 +47,9 @@ impl AsyncTask for MyTask { unsafe { Module::main(&frame) .submodule(&frame, "MyModule")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .call_async(&mut frame, &mut [dims, iters]) .await .into_jlrs_result()? diff --git a/examples/call_julia.rs b/examples/call_julia.rs index 65688999..196baa99 100644 --- a/examples/call_julia.rs +++ b/examples/call_julia.rs @@ -34,11 +34,11 @@ fn main() { Module::main(&frame) // the submodule doesn't have to be rooted because it's never reloaded. .submodule(&frame, "MyModule")? - .wrapper() + .as_managed() // the same holds true for the function: the module is never reloaded so it's // globally rooted .function(&frame, "complexfunc")? - .wrapper() + .as_managed() // Call the function with the two arguments it takes .call2(&mut frame, dim, iters) // If you don't want to use the exception, it can be converted to a `JlrsError` diff --git a/examples/ccall_throw_exception.rs b/examples/ccall_throw_exception.rs index e3cdaa96..21cf9c47 100644 --- a/examples/ccall_throw_exception.rs +++ b/examples/ccall_throw_exception.rs @@ -16,7 +16,7 @@ pub unsafe extern "C" fn assert_less_than(a: i32, b: i32) { Module::core(&frame) .global(&frame, "AssertionError") .expect("AssertionError does not exist in Core") - .value() + .as_value() .cast::() .expect("AssertionError is not a DataType") .instantiate_unchecked(frame.as_mut(), [msg]) diff --git a/examples/fully_async_async_std.rs b/examples/fully_async_async_std.rs index 7937848b..f27239ea 100644 --- a/examples/fully_async_async_std.rs +++ b/examples/fully_async_async_std.rs @@ -47,9 +47,9 @@ impl AsyncTask for MyTask { unsafe { Module::main(&frame) .submodule(&frame, "MyModule")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .call_async(&mut frame, &mut [dims, iters]) .await .into_jlrs_result()? diff --git a/examples/fully_async_tokio.rs b/examples/fully_async_tokio.rs index 43616884..35dfac34 100644 --- a/examples/fully_async_tokio.rs +++ b/examples/fully_async_tokio.rs @@ -47,9 +47,9 @@ impl AsyncTask for MyTask { unsafe { Module::main(&frame) .submodule(&frame, "MyModule")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .call_async(&mut frame, &mut [dims, iters]) .await .into_jlrs_result()? diff --git a/examples/nested_async_scopes.rs b/examples/nested_async_scopes.rs index 883011e7..c827ea28 100644 --- a/examples/nested_async_scopes.rs +++ b/examples/nested_async_scopes.rs @@ -52,9 +52,9 @@ impl AsyncTask for MyTask { let out = unsafe { Module::main(&frame) .submodule(&frame, "MyModule")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .call_async(&mut frame, &mut [dims, iters]) .await .into_jlrs_result()? diff --git a/examples/persistent_tasks.rs b/examples/persistent_tasks.rs index 19b631bd..0666883b 100644 --- a/examples/persistent_tasks.rs +++ b/examples/persistent_tasks.rs @@ -52,7 +52,9 @@ impl PersistentTask for AccumulatorTask { .scope(|mut frame| { // A nested scope is used to only root a single value in the frame provided to // init, rather than two. - let func = Module::main(&frame).global(&frame, "MutFloat64")?.value(); + let func = Module::main(&frame) + .global(&frame, "MutFloat64")? + .as_value(); let init_v = Value::new(&mut frame, self.init_value); Ok(func.call1(output, init_v)) diff --git a/examples/plot.rs b/examples/plot.rs index 7f28f8c2..46879945 100644 --- a/examples/plot.rs +++ b/examples/plot.rs @@ -30,7 +30,7 @@ impl PersistentTask for MyTask { ) -> JlrsResult> { unsafe { // Create the first plot with no data, but with a custom label for the y-axis. - let plot_fn = Module::plots(&frame).function(&frame, "plot")?.wrapper(); + let plot_fn = Module::plots(&frame).function(&frame, "plot")?.as_managed(); let ylabel_str = JuliaString::new(&mut frame, &self.ylabel); let ylabel = @@ -55,11 +55,11 @@ impl PersistentTask for MyTask { let n = Value::new(&mut frame, 100usize); let data = Module::base(&frame) .function(&frame, "randn")? - .wrapper() + .as_managed() .call1(&mut frame, n) .into_jlrs_result()?; - let plot_fn = Module::plots(&frame).function(&frame, "plot")?.wrapper(); + let plot_fn = Module::plots(&frame).function(&frame, "plot")?.as_managed(); state .0 diff --git a/jlrs/src/async_util/future.rs b/jlrs/src/async_util/future.rs index 832e4246..d6eef16e 100644 --- a/jlrs/src/async_util/future.rs +++ b/jlrs/src/async_util/future.rs @@ -15,16 +15,16 @@ use smallvec::SmallVec; use crate::{ call::{Call, ProvideKeywords, WithKeywords}, - error::{JuliaResult, CANNOT_DISPLAY_VALUE}, - memory::target::{frame::AsyncGcFrame, unrooted::Unrooted}, - private::Private, - wrappers::ptr::{ + data::managed::{ module::Module, - private::WrapperPriv, + private::ManagedPriv, task::Task, value::{Value, MAX_SIZE}, - Wrapper, + Managed, }, + error::{JuliaResult, CANNOT_DISPLAY_VALUE}, + memory::target::{frame::AsyncGcFrame, unrooted::Unrooted}, + private::Private, }; pub(crate) struct TaskState<'frame, 'data> { @@ -66,10 +66,10 @@ impl<'frame, 'data> JuliaFuture<'frame, 'data> { Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "asynccall") .expect("asynccall not available") - .wrapper() + .as_managed() .call(&mut *frame, &mut vals) .unwrap_or_else(|e| { let msg = e.display_string_or(CANNOT_DISPLAY_VALUE); @@ -121,10 +121,10 @@ impl<'frame, 'data> JuliaFuture<'frame, 'data> { Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "interactivecall") .expect("interactivecall not available") - .wrapper() + .as_managed() .call(&mut *frame, &mut vals) .unwrap_or_else(|e| { let msg = e.display_string_or(CANNOT_DISPLAY_VALUE); @@ -175,10 +175,10 @@ impl<'frame, 'data> JuliaFuture<'frame, 'data> { Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "scheduleasynclocal") .expect("scheduleasynclocal not available") - .wrapper() + .as_managed() .call(&mut *frame, &mut vals) .unwrap_or_else(|e| { let msg = e.display_string_or(CANNOT_DISPLAY_VALUE); @@ -229,10 +229,10 @@ impl<'frame, 'data> JuliaFuture<'frame, 'data> { Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "scheduleasync") .expect("scheduleasync not available") - .wrapper() + .as_managed() .call(&mut *frame, &mut vals) .unwrap_or_else(|e| { let msg = e.display_string_or(CANNOT_DISPLAY_VALUE); @@ -273,10 +273,10 @@ impl<'frame, 'data> JuliaFuture<'frame, 'data> { Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "postblocking") .expect("postblocking not available") - .wrapper() + .as_managed() .call3(&mut *frame, fn_ptr, task_ptr, state_ptr_boxed) .unwrap_or_else(|e| { let msg = e.display_string_or(CANNOT_DISPLAY_VALUE); @@ -326,10 +326,10 @@ impl<'frame, 'data> JuliaFuture<'frame, 'data> { Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "asynccall") .expect("asynccall not available") - .wrapper() + .as_managed() .provide_keywords(func.keywords()) .expect("Keywords invalid") .call(&mut *frame, &mut vals) @@ -382,10 +382,10 @@ impl<'frame, 'data> JuliaFuture<'frame, 'data> { Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "interactivecall") .expect("interactivecall not available") - .wrapper() + .as_managed() .provide_keywords(func.keywords()) .expect("Keywords invalid") .call(&mut *frame, &mut vals) @@ -438,10 +438,10 @@ impl<'frame, 'data> JuliaFuture<'frame, 'data> { let task = Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "scheduleasynclocal") .expect("scheduleasynclocal not available") - .wrapper() + .as_managed() .provide_keywords(func.keywords()) .expect("Keywords invalid") .call(&mut *frame, &mut vals) @@ -494,10 +494,10 @@ impl<'frame, 'data> JuliaFuture<'frame, 'data> { Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "scheduleasync") .expect("scheduleasync not available") - .wrapper() + .as_managed() .provide_keywords(func.keywords()) .expect("Keywords invalid") .call(&mut *frame, &mut vals) @@ -533,7 +533,7 @@ impl<'frame, 'data> Future for JuliaFuture<'frame, 'data> { let f = Module::base(&global) .function(&global, "fetch") .unwrap() - .wrapper(); + .as_managed(); let res = jl_call1(f.unwrap(Private), task.unwrap(Private).cast()); let exc = jl_exception_occurred(); diff --git a/jlrs/src/async_util/internal.rs b/jlrs/src/async_util/internal.rs index 206beaaf..a071e364 100644 --- a/jlrs/src/async_util/internal.rs +++ b/jlrs/src/async_util/internal.rs @@ -10,6 +10,7 @@ use crate::{ task::AsyncTask, }, call::Call, + data::managed::{module::Module, string::JuliaString, value::Value, Managed}, error::{JlrsError, JlrsResult}, memory::{ context::stack::Stack, @@ -17,7 +18,6 @@ use crate::{ target::frame::{AsyncGcFrame, GcFrame}, }, runtime::async_rt::{PersistentHandle, PersistentMessage}, - wrappers::ptr::{module::Module, string::JuliaString, value::Value, Wrapper}, }; pub(crate) type InnerPersistentMessage

= Box< @@ -468,9 +468,11 @@ where let path = JuliaString::new(&mut frame, path); Module::main(&frame) .function(&frame, "include")? - .wrapper() + .as_managed() .call1(&frame, path.as_value()) - .map_err(|e| JlrsError::exception(format!("Include error: {:?}", e.value())))?; + .map_err(|e| { + JlrsError::exception(format!("Include error: {:?}", e.as_value())) + })?; } None => {} } @@ -534,9 +536,9 @@ where Module::main(&unrooted) .submodule(&unrooted, "Jlrs")? - .wrapper() + .as_managed() .global(&unrooted, "color")? - .value() + .as_value() .set_nth_field_unchecked(0, enable); Ok(()) diff --git a/jlrs/src/async_util/task.rs b/jlrs/src/async_util/task.rs index 592dbd8c..c5acfa79 100644 --- a/jlrs/src/async_util/task.rs +++ b/jlrs/src/async_util/task.rs @@ -25,9 +25,9 @@ use crate::{ }; use crate::{ call::Call, + data::managed::{module::Module, value::Value}, error::JlrsResult, memory::target::{frame::AsyncGcFrame, Target}, - wrappers::ptr::{module::Module, value::Value}, }; /// A task that returns once. @@ -374,12 +374,12 @@ pub fn sleep<'scope, 'data, T: Target<'scope>>(target: &T, duration: Duration) { // Is rooted when sleep is called. let secs = duration.as_millis() as usize as f64 / 1000.; - let secs = Value::new(target, secs).value(); + let secs = Value::new(target, secs).as_value(); Module::base(target) .global(target, "sleep") .expect("sleep not found") - .value() + .as_value() .call1(target, secs) .expect("sleep threw an exception"); } diff --git a/jlrs/src/call.rs b/jlrs/src/call.rs index 49bea9f7..2a41b520 100644 --- a/jlrs/src/call.rs +++ b/jlrs/src/call.rs @@ -14,15 +14,15 @@ use jl_sys::{jl_call, jl_exception_occurred}; use smallvec::SmallVec; #[cfg(not(any(feature = "julia-1-10", feature = "julia-1-9")))] -use crate::wrappers::ptr::private::WrapperPriv as _; +use crate::data::managed::private::ManagedPriv as _; use crate::{ - error::{AccessError, JlrsResult, JuliaResult}, - memory::{context::ledger::Ledger, target::Target}, - private::Private, - wrappers::ptr::{ + data::managed::{ array::{tracked::ArrayWrapper, Array}, value::{Value, ValueResult, MAX_SIZE}, }, + error::{AccessError, JlrsResult, JuliaResult}, + memory::{context::ledger::Ledger, target::Target}, + private::Private, }; /// A function and its keyword arguments. @@ -60,8 +60,8 @@ impl<'scope, 'data> WithKeywords<'scope, 'data> { /// All of these methods are unsafe, arbitrary Julia functions can't be checked for correctness. /// More information can be found in the [`safety`] module. /// -/// [`Function`]: crate::wrappers::ptr::function::Function -/// [`OpaqueClosure`]: crate::wrappers::ptr::internal::opaque_closure::OpaqueClosure +/// [`Function`]: crate::data::managed::function::Function +/// [`OpaqueClosure`]: crate::data::managed::internal::opaque_closure::OpaqueClosure /// [`safety`]: crate::safety pub trait Call<'data>: private::CallPriv { /// Call a function with no arguments. @@ -375,8 +375,8 @@ cfg_if::cfg_if! { use async_trait::async_trait; use crate::{ memory::target::frame::AsyncGcFrame, - wrappers::ptr::{ - Wrapper, + data::managed::{ + Managed, task::Task, module::Module, function::Function @@ -968,10 +968,10 @@ cfg_if::cfg_if! { let task = Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "interactivecall") .expect("interactivecall not available") - .wrapper() + .as_managed() .call(&mut *frame, &mut vals); match task { @@ -997,10 +997,10 @@ cfg_if::cfg_if! { let task = Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "asynccall") .expect("asynccall not available") - .wrapper() + .as_managed() .call(&mut *frame, &mut vals); match task { @@ -1037,10 +1037,10 @@ cfg_if::cfg_if! { let task = Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "scheduleasynclocal") .expect("scheduleasynclocal not available") - .wrapper() + .as_managed() .call(&mut *frame, &mut vals); match task { @@ -1077,10 +1077,10 @@ cfg_if::cfg_if! { let task = Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "scheduleasync") .expect("scheduleasync not available") - .wrapper() + .as_managed() .call(&mut *frame, &mut vals); match task { @@ -1226,10 +1226,10 @@ cfg_if::cfg_if! { let task = Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "interactivecall") .expect("interactivecall not available") - .wrapper() + .as_managed() .provide_keywords(self.keywords()) .expect("Keywords invalid") .call(&mut *frame, &mut vals); @@ -1257,10 +1257,10 @@ cfg_if::cfg_if! { let task = Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "asynccall") .expect("asynccall not available") - .wrapper() + .as_managed() .provide_keywords(self.keywords()) .expect("Keywords invalid") .call(&mut *frame, &mut vals); @@ -1299,10 +1299,10 @@ cfg_if::cfg_if! { let task = Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "scheduleasynclocal") .expect("scheduleasynclocal not available") - .wrapper() + .as_managed() .provide_keywords(self.keywords()) .expect("Keywords invalid") .call(&mut *frame, &mut vals); @@ -1341,10 +1341,10 @@ cfg_if::cfg_if! { let task = Module::main(&frame) .submodule(&frame, "JlrsMultitask") .expect("JlrsMultitask not available") - .wrapper() + .as_managed() .function(&frame, "scheduleasync") .expect("scheduleasync not available") - .wrapper() + .as_managed() .provide_keywords(self.keywords()) .expect("Keywords invalid") .call(&mut *frame, &mut vals); @@ -1361,8 +1361,8 @@ cfg_if::cfg_if! { mod private { use super::WithKeywords; #[cfg(all(not(feature = "julia-1-6"), feature = "internal-types"))] - use crate::wrappers::ptr::internal::opaque_closure::OpaqueClosure; - use crate::wrappers::ptr::{function::Function, value::Value}; + use crate::data::managed::internal::opaque_closure::OpaqueClosure; + use crate::data::managed::{function::Function, value::Value}; pub trait CallPriv: Sized {} impl CallPriv for WithKeywords<'_, '_> {} impl CallPriv for Function<'_, '_> {} diff --git a/jlrs/src/catch.rs b/jlrs/src/catch.rs index abec91e9..f37fd473 100644 --- a/jlrs/src/catch.rs +++ b/jlrs/src/catch.rs @@ -7,18 +7,14 @@ use std::{ }; use jl_sys::{ - jlrs_catch_t, - jlrs_catch_tag_t_JLRS_CATCH_ERR, - jlrs_catch_tag_t_JLRS_CATCH_EXCECPTION, - jlrs_catch_tag_t_JLRS_CATCH_OK, - jlrs_catch_tag_t_JLRS_CATCH_PANIC, - jlrs_catch_wrapper, + jlrs_catch_t, jlrs_catch_tag_t_JLRS_CATCH_ERR, jlrs_catch_tag_t_JLRS_CATCH_EXCECPTION, + jlrs_catch_tag_t_JLRS_CATCH_OK, jlrs_catch_tag_t_JLRS_CATCH_PANIC, jlrs_catch_wrapper, }; use crate::{ + data::managed::value::ValueRef, error::{JlrsResult, JuliaResultRef}, memory::target::frame::GcFrame, - wrappers::ptr::value::ValueRef, }; unsafe extern "C" fn trampoline_with_slots<'frame, F, T>( diff --git a/jlrs/src/ccall.rs b/jlrs/src/ccall.rs index 2a1d467f..76474ab8 100644 --- a/jlrs/src/ccall.rs +++ b/jlrs/src/ccall.rs @@ -7,6 +7,10 @@ use jl_sys::jl_throw; use jl_sys::uv_async_send; use crate::{ + data::managed::{ + private::ManagedPriv, + value::{Value, ValueRef}, + }, error::JlrsResult, memory::{ context::stack::Stack, @@ -14,10 +18,6 @@ use crate::{ target::{frame::GcFrame, unrooted::Unrooted}, }, private::Private, - wrappers::ptr::{ - private::WrapperPriv, - value::{Value, ValueRef}, - }, }; /// Use Julia from a Rust function called through `ccall`. diff --git a/jlrs/src/convert/into_jlrs_result.rs b/jlrs/src/convert/into_jlrs_result.rs index ef02b448..474d6d61 100644 --- a/jlrs/src/convert/into_jlrs_result.rs +++ b/jlrs/src/convert/into_jlrs_result.rs @@ -5,8 +5,8 @@ //! defined in this module. use crate::{ + data::managed::Managed, error::{JlrsError, JlrsResult, JuliaResult, CANNOT_DISPLAY_VALUE}, - wrappers::ptr::Wrapper, }; /// Extension trait that lets you convert a `JuliaResult` to a `JlrsResult`. diff --git a/jlrs/src/convert/into_julia.rs b/jlrs/src/convert/into_julia.rs index 8dd3307b..4a639124 100644 --- a/jlrs/src/convert/into_julia.rs +++ b/jlrs/src/convert/into_julia.rs @@ -6,51 +6,29 @@ //! isbits-types, and should not be implemented manually. Rather, you should use JlrsReflect.jl to //! automatically derive it for compatible types. //! -//! [`Value::new`]: crate::wrappers::ptr::value::Value::new -//! [`Value`]: crate::wrappers::ptr::value::Value +//! [`Value::new`]: crate::data::managed::value::Value::new +//! [`Value`]: crate::data::managed::value::Value use std::{ffi::c_void, ptr::NonNull}; use jl_sys::{ - jl_apply_type, - jl_bool_type, - jl_box_bool, - jl_box_char, - jl_box_float32, - jl_box_float64, - jl_box_int16, - jl_box_int32, - jl_box_int64, - jl_box_int8, - jl_box_uint16, - jl_box_uint32, - jl_box_uint64, - jl_box_uint8, - jl_box_voidpointer, - jl_char_type, - jl_float32_type, - jl_float64_type, - jl_int16_type, - jl_int32_type, - jl_int64_type, - jl_int8_type, - jl_new_struct_uninit, - jl_uint16_type, - jl_uint32_type, - jl_uint64_type, - jl_uint8_type, + jl_apply_type, jl_bool_type, jl_box_bool, jl_box_char, jl_box_float32, jl_box_float64, + jl_box_int16, jl_box_int32, jl_box_int64, jl_box_int8, jl_box_uint16, jl_box_uint32, + jl_box_uint64, jl_box_uint8, jl_box_voidpointer, jl_char_type, jl_float32_type, + jl_float64_type, jl_int16_type, jl_int32_type, jl_int64_type, jl_int8_type, + jl_new_struct_uninit, jl_uint16_type, jl_uint32_type, jl_uint64_type, jl_uint8_type, jl_voidpointer_type, }; use crate::{ - memory::target::Target, - private::Private, - wrappers::ptr::{ + data::managed::{ datatype::{DataType, DataTypeData}, - private::WrapperPriv, + private::ManagedPriv, union_all::UnionAll, value::{Value, ValueData}, }, + memory::target::Target, + private::Private, }; /// Trait implemented by types that can be converted to a Julia value in combination with @@ -62,7 +40,7 @@ use crate::{ /// type and the type in Rust must match exactly. Incompatible layouts will cause undefined /// behavior. The type in Rust must always be `#[repr(C)]`. The `DataType` must be an isbits-type. /// -/// [`Value::new`]: crate::wrappers::ptr::value::Value::new +/// [`Value::new`]: crate::data::managed::value::Value::new pub unsafe trait IntoJulia: Sized + 'static { /// Returns the associated Julia type of the implementor. /// @@ -81,7 +59,7 @@ pub unsafe trait IntoJulia: Sized + 'static { // associated unsafe { // TODO: root this data until the data has been instantiated. - let ty = Self::julia_type(&target).wrapper(); + let ty = Self::julia_type(&target).as_managed(); debug_assert!(ty.is_bits()); let instance = ty.instance(); @@ -103,7 +81,7 @@ macro_rules! impl_into_julia { #[inline(always)] fn julia_type<'scope, T>( target: T, - ) -> $crate::wrappers::ptr::datatype::DataTypeData<'scope, T> + ) -> $crate::data::managed::datatype::DataTypeData<'scope, T> where T: $crate::memory::target::Target<'scope>, { @@ -119,7 +97,7 @@ macro_rules! impl_into_julia { fn into_julia<'scope, T>( self, target: T, - ) -> $crate::wrappers::ptr::value::ValueData<'scope, 'static, T> + ) -> $crate::data::managed::value::ValueData<'scope, 'static, T> where T: $crate::memory::target::Target<'scope>, { diff --git a/jlrs/src/convert/ndarray.rs b/jlrs/src/convert/ndarray.rs index 72933cd4..0c4316d3 100644 --- a/jlrs/src/convert/ndarray.rs +++ b/jlrs/src/convert/ndarray.rs @@ -2,7 +2,7 @@ use ndarray::{ArrayView, ArrayViewMut, Dim, IntoDimension, IxDynImpl, ShapeBuilder}; -use crate::wrappers::ptr::array::data::{ +use crate::data::managed::array::data::{ accessor::{BitsArrayAccessor, InlinePtrArrayAccessor, Mutability, Mutable}, copied::CopiedArray, }; @@ -68,7 +68,7 @@ impl<'view, T> NdArrayViewMut<'view, T> for CopiedArray { } mod private { - use crate::wrappers::ptr::array::data::{ + use crate::data::managed::array::data::{ accessor::{BitsArrayAccessor, InlinePtrArrayAccessor, Mutability}, copied::CopiedArray, }; diff --git a/jlrs/src/convert/to_symbol.rs b/jlrs/src/convert/to_symbol.rs index 88bf0e62..cea1bf30 100644 --- a/jlrs/src/convert/to_symbol.rs +++ b/jlrs/src/convert/to_symbol.rs @@ -4,9 +4,9 @@ //! strings to be used instead. use crate::{ + data::managed::{string::JuliaString, symbol::Symbol}, memory::target::Target, private::Private, - wrappers::ptr::{string::JuliaString, symbol::Symbol}, }; /// Trait implemented by types that can be converted to a [`Symbol`]. @@ -31,8 +31,8 @@ pub(crate) mod private { use jl_sys::{jl_symbol, jl_symbol_n}; use crate::{ + data::managed::{private::ManagedPriv, string::JuliaString, symbol::Symbol}, private::Private, - wrappers::ptr::{private::WrapperPriv, string::JuliaString, symbol::Symbol}, }; pub trait ToSymbolPriv { diff --git a/jlrs/src/convert/unbox.rs b/jlrs/src/convert/unbox.rs index ec32f019..27822b63 100644 --- a/jlrs/src/convert/unbox.rs +++ b/jlrs/src/convert/unbox.rs @@ -18,29 +18,21 @@ //! JlrsReflect.jl [`Unbox`] is always derived. //! //! [`Cast`]: crate::convert::cast::Cast -//! [`Bool`]: crate::wrappers::inline::bool::Bool -//! [`Char`]: crate::wrappers::inline::char::Char -//! [`DataType`]: crate::wrappers::ptr::datatype::DataType +//! [`Bool`]: crate::data::layout::bool::Bool +//! [`Char`]: crate::data::layout::char::Char +//! [`DataType`]: crate::data::managed::datatype::DataType //! [`IntoJulia`]: crate::convert::into_julia::IntoJulia use std::ffi::c_void; use jl_sys::{ - jl_unbox_float32, - jl_unbox_float64, - jl_unbox_int16, - jl_unbox_int32, - jl_unbox_int64, - jl_unbox_int8, - jl_unbox_uint16, - jl_unbox_uint32, - jl_unbox_uint64, - jl_unbox_uint8, + jl_unbox_float32, jl_unbox_float64, jl_unbox_int16, jl_unbox_int32, jl_unbox_int64, + jl_unbox_int8, jl_unbox_uint16, jl_unbox_uint32, jl_unbox_uint64, jl_unbox_uint8, jl_unbox_voidpointer, }; use super::into_julia::IntoJulia; -use crate::wrappers::ptr::value::Value; +use crate::data::managed::value::Value; /// A trait implemented by types that can be extracted from a Julia value with [`Value::unbox`]. /// @@ -54,7 +46,7 @@ use crate::wrappers::ptr::value::Value; /// `unbox` dereferences the value as `&Self::Output` and clones it. If this implementation is /// incorrect it must be overridden. /// -/// [`Value::unbox`]: crate::wrappers::ptr::value::Value::unbox +/// [`Value::unbox`]: crate::data::managed::value::Value::unbox /// [`ValidLayout`]: crate::layout::valid_layout::ValidLayout pub unsafe trait Unbox { /// The type of the unboxed data. Must be `#[repr(C)]`. @@ -77,7 +69,7 @@ macro_rules! impl_unboxer { #[inline(always)] unsafe fn unbox(value: Value) -> $type { $unboxer( - ::unwrap( + ::unwrap( value, $crate::private::Private, ), diff --git a/jlrs/src/wrappers/inline/bool.rs b/jlrs/src/data/layout/bool.rs similarity index 95% rename from jlrs/src/wrappers/inline/bool.rs rename to jlrs/src/data/layout/bool.rs index 8138ffa3..589e4f69 100644 --- a/jlrs/src/wrappers/inline/bool.rs +++ b/jlrs/src/data/layout/bool.rs @@ -1,4 +1,4 @@ -//! Wrapper for `Bool`. +//! Managed for `Bool`. //! //! In Rust it's unsound to create an invalid `bool`, while a `Bool` in Julia can be an arbitrary //! `i8` in some rare cases. Rather than treating all `Bool`s as `i8` or `bool`s jlrs provides @@ -9,8 +9,8 @@ use jl_sys::{jl_bool_type, jl_unbox_int8}; /// a wrapper for this type. use crate::{convert::unbox::Unbox, impl_julia_typecheck, impl_valid_layout}; use crate::{ + data::managed::{private::ManagedPriv, value::Value}, private::Private, - wrappers::ptr::{private::WrapperPriv, value::Value}, }; /// A Julia `Bool`. diff --git a/jlrs/src/wrappers/inline/char.rs b/jlrs/src/data/layout/char.rs similarity index 93% rename from jlrs/src/wrappers/inline/char.rs rename to jlrs/src/data/layout/char.rs index e3375060..df40dff1 100644 --- a/jlrs/src/wrappers/inline/char.rs +++ b/jlrs/src/data/layout/char.rs @@ -1,4 +1,4 @@ -//! Wrapper for `Char`. +//! Managed for `Char`. //! //! In Rust it's unsafe to create an invalid `char`, while a `Char` in Julia can be an arbitrary //! `u32` in some rare cases. Rather than treating all `Char`s as `u32` or `char`s, jlrs provides @@ -9,10 +9,9 @@ use jl_sys::{jl_char_type, jl_unbox_uint32}; use crate::{ convert::unbox::Unbox, - impl_julia_typecheck, - impl_valid_layout, + data::managed::{private::ManagedPriv, value::Value}, + impl_julia_typecheck, impl_valid_layout, private::Private, - wrappers::ptr::{private::WrapperPriv, value::Value}, }; /// A Julia `Char`. diff --git a/jlrs/src/wrappers/inline/f16.rs b/jlrs/src/data/layout/f16.rs similarity index 82% rename from jlrs/src/wrappers/inline/f16.rs rename to jlrs/src/data/layout/f16.rs index e39e183b..e2d3fcc3 100644 --- a/jlrs/src/wrappers/inline/f16.rs +++ b/jlrs/src/data/layout/f16.rs @@ -1,18 +1,17 @@ -//! Wrapper for `Float16`. +//! Managed for `Float16`. use half::f16; use jl_sys::jl_float16_type; use crate::{ convert::{into_julia::IntoJulia, unbox::Unbox}, - impl_julia_typecheck, - impl_valid_layout, - memory::target::Target, - private::Private, - wrappers::ptr::{ + data::managed::{ datatype::{DataType, DataTypeData}, - private::WrapperPriv, + private::ManagedPriv, }, + impl_julia_typecheck, impl_valid_layout, + memory::target::Target, + private::Private, }; impl_julia_typecheck!(f16, jl_float16_type); diff --git a/jlrs/src/wrappers/foreign.rs b/jlrs/src/data/layout/foreign.rs similarity index 96% rename from jlrs/src/wrappers/foreign.rs rename to jlrs/src/data/layout/foreign.rs index 52831c63..4bfd7a62 100644 --- a/jlrs/src/wrappers/foreign.rs +++ b/jlrs/src/data/layout/foreign.rs @@ -26,19 +26,21 @@ use std::{ #[cfg(feature = "julia-1-10")] use jl_sys::jl_reinit_foreign_type; use jl_sys::{ - jl_gc_alloc_typed, - jl_gc_schedule_foreign_sweepfunc, - jl_new_foreign_type, - jl_value_t, + jl_gc_alloc_typed, jl_gc_schedule_foreign_sweepfunc, jl_new_foreign_type, jl_value_t, }; -use super::ptr::{datatype::DataTypeData, private::WrapperPriv, value::ValueData}; use crate::{ convert::{into_julia::IntoJulia, unbox::Unbox}, + data::managed::{ + datatype::{DataType, DataTypeData}, + module::Module, + private::ManagedPriv, + symbol::Symbol, + value::{Value, ValueData}, + }, layout::valid_layout::ValidLayout, memory::{get_tls, target::Target, PTls}, private::Private, - wrappers::ptr::{datatype::DataType, module::Module, symbol::Symbol, value::Value}, }; static FOREIGN_TYPES: ForeignTypes = ForeignTypes { diff --git a/jlrs/src/wrappers/inline/mod.rs b/jlrs/src/data/layout/mod.rs similarity index 92% rename from jlrs/src/wrappers/inline/mod.rs rename to jlrs/src/data/layout/mod.rs index c8166861..4e817d80 100644 --- a/jlrs/src/wrappers/inline/mod.rs +++ b/jlrs/src/data/layout/mod.rs @@ -4,6 +4,7 @@ pub mod bool; pub mod char; #[cfg(feature = "f16")] pub mod f16; +pub mod foreign; pub mod nothing; #[cfg(feature = "internal-types")] pub mod ssa_value; diff --git a/jlrs/src/wrappers/inline/nothing.rs b/jlrs/src/data/layout/nothing.rs similarity index 84% rename from jlrs/src/wrappers/inline/nothing.rs rename to jlrs/src/data/layout/nothing.rs index d441139a..ec444914 100644 --- a/jlrs/src/wrappers/inline/nothing.rs +++ b/jlrs/src/data/layout/nothing.rs @@ -1,17 +1,16 @@ -//! Wrapper for `Nothing`. +//! Managed for `Nothing`. use jl_sys::jl_nothing_type; use crate::{ convert::{into_julia::IntoJulia, unbox::Unbox}, - impl_julia_typecheck, - impl_valid_layout, - memory::target::Target, - private::Private, - wrappers::ptr::{ + data::managed::{ datatype::{DataType, DataTypeData}, - private::WrapperPriv, + private::ManagedPriv, }, + impl_julia_typecheck, impl_valid_layout, + memory::target::Target, + private::Private, }; #[repr(C)] diff --git a/jlrs/src/wrappers/inline/ssa_value.rs b/jlrs/src/data/layout/ssa_value.rs similarity index 95% rename from jlrs/src/wrappers/inline/ssa_value.rs rename to jlrs/src/data/layout/ssa_value.rs index f8850354..c9cf780c 100644 --- a/jlrs/src/wrappers/inline/ssa_value.rs +++ b/jlrs/src/data/layout/ssa_value.rs @@ -1,4 +1,4 @@ -//! Wrapper for `SSAVAlue`. +//! Managed for `SSAVAlue`. use std::fmt::{Debug, Formatter, Result as FmtResult}; diff --git a/jlrs/src/wrappers/inline/tuple.rs b/jlrs/src/data/layout/tuple.rs similarity index 88% rename from jlrs/src/wrappers/inline/tuple.rs rename to jlrs/src/data/layout/tuple.rs index dd00f083..f4140473 100644 --- a/jlrs/src/wrappers/inline/tuple.rs +++ b/jlrs/src/data/layout/tuple.rs @@ -30,17 +30,17 @@ use jl_sys::jl_tuple_typename; #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] -use crate::wrappers::ptr::value::ValueResult; +use crate::data::managed::value::ValueResult; use crate::{ - layout::typecheck::Typecheck, - memory::target::{ExtendedTarget, Target}, - private::Private, - wrappers::ptr::{ + data::managed::{ datatype::DataType, - private::WrapperPriv as _, + private::ManagedPriv as _, value::{Value, ValueData, MAX_SIZE}, - Wrapper as _, + Managed as _, }, + layout::typecheck::Typecheck, + memory::target::{ExtendedTarget, Target}, + private::Private, }; /// A tuple that has an arbitrary number of fields. This type can be used as a typecheck to check @@ -144,10 +144,10 @@ macro_rules! count { macro_rules! check { ($fieldtypes:expr, $n:expr, $t:ident, $($x:ident),+) => { - <$t>::valid_field($fieldtypes[$n - 1 - count!($($x),+)].unwrap().wrapper()) && check!($fieldtypes, $n, $($x),+) + <$t>::valid_field($fieldtypes[$n - 1 - count!($($x),+)].unwrap().as_managed()) && check!($fieldtypes, $n, $($x),+) }; ($fieldtypes:expr, $n:expr, $t:ident) => { - <$t>::valid_field($fieldtypes[$n - 1].unwrap().wrapper()) + <$t>::valid_field($fieldtypes[$n - 1].unwrap().as_managed()) }; } @@ -168,7 +168,7 @@ macro_rules! impl_tuple { { fn julia_type<'scope, T>( target: T, - ) -> $crate::wrappers::ptr::datatype::DataTypeData<'scope, T> + ) -> $crate::data::managed::datatype::DataTypeData<'scope, T> where T: $crate::memory::target::Target<'scope> { @@ -189,18 +189,18 @@ macro_rules! impl_tuple { where $($types: $crate::layout::valid_layout::ValidField + Clone + ::std::fmt::Debug),+ { - fn valid_layout(v: $crate::wrappers::ptr::value::Value) -> bool { + fn valid_layout(v: $crate::data::managed::value::Value) -> bool { unsafe { - if let Ok(dt) = v.cast::<$crate::wrappers::ptr::datatype::DataType>() { + if let Ok(dt) = v.cast::<$crate::data::managed::datatype::DataType>() { let global = v.unrooted_target(); let fieldtypes = dt.field_types(global); let n = count!($($types),+); - if fieldtypes.wrapper().len() != n { + if fieldtypes.as_managed().len() != n { return false; } - let types = fieldtypes.wrapper(); + let types = fieldtypes.as_managed(); let types = types.data().as_slice(); if !check!(types, n, $($types),+) { return false @@ -220,18 +220,18 @@ macro_rules! impl_tuple { where $($types: $crate::layout::valid_layout::ValidField + Clone + ::std::fmt::Debug),+ { - fn valid_field(v: $crate::wrappers::ptr::value::Value) -> bool { + fn valid_field(v: $crate::data::managed::value::Value) -> bool { unsafe { - if let Ok(dt) = v.cast::<$crate::wrappers::ptr::datatype::DataType>() { + if let Ok(dt) = v.cast::<$crate::data::managed::datatype::DataType>() { let global = v.unrooted_target(); let fieldtypes = dt.field_types(global); let n = count!($($types),+); - if fieldtypes.wrapper().len() != n { + if fieldtypes.as_managed().len() != n { return false; } - let types = fieldtypes.wrapper(); + let types = fieldtypes.as_managed(); let types = types.data().as_slice(); if !check!(types, n, $($types),+) { return false @@ -256,7 +256,7 @@ macro_rules! impl_tuple { where $($types: $crate::layout::valid_layout::ValidField + Clone + ::std::fmt::Debug),+ { - fn typecheck(t: $crate::wrappers::ptr::datatype::DataType) -> bool { + fn typecheck(t: $crate::data::managed::datatype::DataType) -> bool { ::valid_layout(t.as_value()) } } @@ -270,32 +270,32 @@ macro_rules! impl_tuple { { fn julia_type<'scope, T>( target: T, - ) -> $crate::wrappers::ptr::datatype::DataTypeData<'scope, T> + ) -> $crate::data::managed::datatype::DataTypeData<'scope, T> where T: $crate::memory::target::Target<'scope> { unsafe { - let ptr = $crate::wrappers::ptr::datatype::DataType::emptytuple_type(&target).unwrap_non_null($crate::private::Private); + let ptr = $crate::data::managed::datatype::DataType::emptytuple_type(&target).unwrap_non_null($crate::private::Private); target.data_from_ptr(ptr, $crate::private::Private) } } - fn into_julia<'scope, T>(self, target: T) -> $crate::wrappers::ptr::value::ValueData<'scope, 'static, T> + fn into_julia<'scope, T>(self, target: T) -> $crate::data::managed::value::ValueData<'scope, 'static, T> where T: $crate::memory::target::Target<'scope>, { unsafe { - let ptr = $crate::wrappers::ptr::value::Value::emptytuple(&target).unwrap_non_null($crate::private::Private); + let ptr = $crate::data::managed::value::Value::emptytuple(&target).unwrap_non_null($crate::private::Private); target.data_from_ptr(ptr, $crate::private::Private) } } } unsafe impl $crate::layout::valid_layout::ValidLayout for $name { - fn valid_layout(v: $crate::wrappers::ptr::value::Value) -> bool { - if let Ok(dt) = v.cast::<$crate::wrappers::ptr::datatype::DataType>() { + fn valid_layout(v: $crate::data::managed::value::Value) -> bool { + if let Ok(dt) = v.cast::<$crate::data::managed::datatype::DataType>() { let global = unsafe {$crate::memory::target::unrooted::Unrooted::new()}; - return dt == $crate::wrappers::ptr::datatype::DataType::emptytuple_type(&global) + return dt == $crate::data::managed::datatype::DataType::emptytuple_type(&global) } false @@ -305,10 +305,10 @@ macro_rules! impl_tuple { } unsafe impl $crate::layout::valid_layout::ValidField for $name { - fn valid_field(v: $crate::wrappers::ptr::value::Value) -> bool { - if let Ok(dt) = v.cast::<$crate::wrappers::ptr::datatype::DataType>() { + fn valid_field(v: $crate::data::managed::value::Value) -> bool { + if let Ok(dt) = v.cast::<$crate::data::managed::datatype::DataType>() { let global = unsafe {$crate::memory::target::unrooted::Unrooted::new()}; - return dt == $crate::wrappers::ptr::datatype::DataType::emptytuple_type(&global) + return dt == $crate::data::managed::datatype::DataType::emptytuple_type(&global) } false @@ -318,13 +318,13 @@ macro_rules! impl_tuple { unsafe impl $crate::convert::unbox::Unbox for $name { type Output = Self; - unsafe fn unbox(_: $crate::wrappers::ptr::value::Value) -> Self::Output { + unsafe fn unbox(_: $crate::data::managed::value::Value) -> Self::Output { Tuple0() } } unsafe impl $crate::layout::typecheck::Typecheck for $name { - fn typecheck(t: $crate::wrappers::ptr::datatype::DataType) -> bool { + fn typecheck(t: $crate::data::managed::datatype::DataType) -> bool { ::valid_layout(t.as_value()) } } diff --git a/jlrs/src/wrappers/inline/union.rs b/jlrs/src/data/layout/union.rs similarity index 97% rename from jlrs/src/wrappers/inline/union.rs rename to jlrs/src/data/layout/union.rs index 14f29913..98ec5265 100644 --- a/jlrs/src/wrappers/inline/union.rs +++ b/jlrs/src/data/layout/union.rs @@ -9,19 +9,15 @@ use std::{ use jl_sys::jl_bottom_type; use crate::{ + data::managed::{ + datatype::DataType, private::ManagedPriv as _, union::Union, value::Value, Managed, + }, layout::{ bits_union::{Align, BitsUnionContainer, Flag}, typecheck::Typecheck, valid_layout::{ValidField, ValidLayout}, }, private::Private, - wrappers::ptr::{ - datatype::DataType, - private::WrapperPriv as _, - union::Union, - value::Value, - Wrapper, - }, }; /// Ensures the next field is aligned to 1 byte. diff --git a/jlrs/src/wrappers/ptr/array/data/accessor.rs b/jlrs/src/data/managed/array/data/accessor.rs similarity index 98% rename from jlrs/src/wrappers/ptr/array/data/accessor.rs rename to jlrs/src/data/managed/array/data/accessor.rs index e0ee5124..131b1dc6 100644 --- a/jlrs/src/wrappers/ptr/array/data/accessor.rs +++ b/jlrs/src/data/managed/array/data/accessor.rs @@ -10,25 +10,23 @@ use std::{ use jl_sys::{jl_array_ptr_set, jl_array_typetagdata, jl_arrayref, jl_arrayset}; #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] -use crate::wrappers::ptr::value::ValueResult; +use crate::data::managed::value::ValueResult; use crate::{ - error::{AccessError, JlrsResult, TypeError, CANNOT_DISPLAY_TYPE}, - layout::valid_layout::ValidField, - memory::target::Target, - private::Private, - wrappers::ptr::{ + data::managed::{ array::{ dimensions::{ArrayDimensions, Dims}, Array, }, datatype::DataType, - private::WrapperPriv, + private::ManagedPriv, union::{find_union_component, nth_union_component}, value::{Value, ValueData}, - Wrapper, - WrapperRef, - WrapperType, + Managed, ManagedRef, ManagedType, }, + error::{AccessError, JlrsResult, TypeError, CANNOT_DISPLAY_TYPE}, + layout::valid_layout::ValidField, + memory::target::Target, + private::Private, }; /// Trait used to indicate how the elements are laid out. @@ -103,7 +101,7 @@ impl<'borrow, T> Mutability for Mutable<'borrow, T> {} /// requirements on the layout, but as a result it can only access its contents with /// [`ArrayAccessor::get_value`] and mutate them with [`ArrayAccessor::set_value`]. /// -/// [`ValueRef`]: crate::wrappers::ptr::value::ValueRef +/// [`ValueRef`]: crate::data::managed::value::ValueRef #[repr(transparent)] pub struct ArrayAccessor<'borrow, 'array, 'data, T, L: ArrayLayout, M: Mutability> { pub(crate) array: Array<'array, 'data>, @@ -330,7 +328,7 @@ impl<'borrow, 'array, 'data, U, L: ArrayLayout> } } -impl<'borrow, 'array, 'data, W: WrapperRef<'array, 'data>, M: Mutability> +impl<'borrow, 'array, 'data, W: ManagedRef<'array, 'data>, M: Mutability> PtrArrayAccessor<'borrow, 'array, 'data, W, M> { /// Get a reference to the value at `index`, or `None` if the index is out of bounds. @@ -338,7 +336,7 @@ impl<'borrow, 'array, 'data, W: WrapperRef<'array, 'data>, M: Mutability> &self, target: T, index: D, - ) -> Option>> + ) -> Option>> where D: Dims, T: Target<'target>, @@ -349,7 +347,7 @@ impl<'borrow, 'array, 'data, W: WrapperRef<'array, 'data>, M: Mutability> let x = self .array .data_ptr() - .cast::() + .cast::() .add(idx) .as_ref() .cloned()?; @@ -375,7 +373,7 @@ impl<'borrow, 'array, 'data, W: WrapperRef<'array, 'data>, M: Mutability> } } -impl<'borrow, 'array, 'data, T: WrapperRef<'array, 'data>> +impl<'borrow, 'array, 'data, T: ManagedRef<'array, 'data>> PtrArrayAccessor<'borrow, 'array, 'data, T, Mutable<'borrow, T>> { /// Set the value at `index` to `value` if `value` has a type that's compatible with this array. @@ -412,7 +410,7 @@ impl<'borrow, 'array, 'data, T: WrapperRef<'array, 'data>> impl<'borrow, 'array, 'data, D, T, M> Index for PtrArrayAccessor<'borrow, 'array, 'data, T, M> where D: Dims, - T: WrapperRef<'array, 'data>, + T: ManagedRef<'array, 'data>, M: Mutability, { type Output = Option; diff --git a/jlrs/src/wrappers/ptr/array/data/copied.rs b/jlrs/src/data/managed/array/data/copied.rs similarity index 94% rename from jlrs/src/wrappers/ptr/array/data/copied.rs rename to jlrs/src/data/managed/array/data/copied.rs index ccaf5b87..11c95737 100644 --- a/jlrs/src/wrappers/ptr/array/data/copied.rs +++ b/jlrs/src/data/managed/array/data/copied.rs @@ -2,14 +2,14 @@ use std::ops::{Index, IndexMut}; -use crate::wrappers::ptr::array::dimensions::{Dimensions, Dims}; +use crate::data::managed::array::dimensions::{Dimensions, Dims}; /// An n-dimensional array whose contents have been copied from Julia to Rust. /// /// You can create this struct by calling [`Array::copy_inline_data`]. The data has a column-major /// order and can be indexed with anything that implements [`Dims`]. /// -/// [`Array::copy_inline_data`]: crate::wrappers::ptr::array::Array::copy_inline_data +/// [`Array::copy_inline_data`]: crate::data::managed::array::Array::copy_inline_data #[derive(Debug)] pub struct CopiedArray { data: Box<[T]>, diff --git a/jlrs/src/wrappers/ptr/array/data/mod.rs b/jlrs/src/data/managed/array/data/mod.rs similarity index 100% rename from jlrs/src/wrappers/ptr/array/data/mod.rs rename to jlrs/src/data/managed/array/data/mod.rs diff --git a/jlrs/src/wrappers/ptr/array/dimensions.rs b/jlrs/src/data/managed/array/dimensions.rs similarity index 99% rename from jlrs/src/wrappers/ptr/array/dimensions.rs rename to jlrs/src/data/managed/array/dimensions.rs index 8a0ae7af..631a5e30 100644 --- a/jlrs/src/wrappers/ptr/array/dimensions.rs +++ b/jlrs/src/data/managed/array/dimensions.rs @@ -15,9 +15,9 @@ use std::{ use jl_sys::{jl_array_dims_ptr, jl_array_ndims}; use crate::{ + data::managed::{array::Array, private::ManagedPriv as _}, error::{AccessError, JlrsResult}, private::Private, - wrappers::ptr::{array::Array, private::WrapperPriv as _}, }; /// Trait implemented by types that can be used as n-dimensional indices. diff --git a/jlrs/src/wrappers/ptr/array/mod.rs b/jlrs/src/data/managed/array/mod.rs similarity index 97% rename from jlrs/src/wrappers/ptr/array/mod.rs rename to jlrs/src/data/managed/array/mod.rs index 389d9926..f57cb517 100644 --- a/jlrs/src/wrappers/ptr/array/mod.rs +++ b/jlrs/src/data/managed/array/mod.rs @@ -32,48 +32,33 @@ use std::{ use cfg_if::cfg_if; use jl_sys::{ - jl_alloc_array_1d, - jl_alloc_array_2d, - jl_alloc_array_3d, - jl_apply_array_type, - jl_apply_tuple_type_v, - jl_array_data, - jl_array_del_beg, - jl_array_del_end, - jl_array_dims_ptr, - jl_array_eltype, - jl_array_grow_beg, - jl_array_grow_end, - jl_array_ndims, - jl_array_t, - jl_datatype_t, - jl_gc_add_ptr_finalizer, - jl_new_array, - jl_new_struct_uninit, - jl_pchar_to_array, - jl_ptr_to_array, - jl_ptr_to_array_1d, - jl_reshape_array, + jl_alloc_array_1d, jl_alloc_array_2d, jl_alloc_array_3d, jl_apply_array_type, + jl_apply_tuple_type_v, jl_array_data, jl_array_del_beg, jl_array_del_end, jl_array_dims_ptr, + jl_array_eltype, jl_array_grow_beg, jl_array_grow_end, jl_array_ndims, jl_array_t, + jl_datatype_t, jl_gc_add_ptr_finalizer, jl_new_array, jl_new_struct_uninit, jl_pchar_to_array, + jl_ptr_to_array, jl_ptr_to_array_1d, jl_reshape_array, }; use self::data::accessor::{ - ArrayAccessor, - BitsArrayAccessorI, - BitsArrayAccessorMut, - Immutable, - IndeterminateArrayAccessor, - IndeterminateArrayAccessorI, - InlinePtrArrayAccessorI, - InlinePtrArrayAccessorMut, - Mutable, - PtrArrayAccessorI, - PtrArrayAccessorMut, - UnionArrayAccessorI, - UnionArrayAccessorMut, + ArrayAccessor, BitsArrayAccessorI, BitsArrayAccessorMut, Immutable, IndeterminateArrayAccessor, + IndeterminateArrayAccessorI, InlinePtrArrayAccessorI, InlinePtrArrayAccessorMut, Mutable, + PtrArrayAccessorI, PtrArrayAccessorMut, UnionArrayAccessorI, UnionArrayAccessorMut, }; use super::{union_all::UnionAll, value::ValueRef, Ref}; use crate::{ convert::into_julia::IntoJulia, + data::managed::{ + array::{ + data::copied::CopiedArray, + dimensions::{ArrayDimensions, Dims}, + }, + datatype::DataType, + private::ManagedPriv, + type_name::TypeName, + union::Union, + value::Value, + Managed, ManagedRef, + }, error::{AccessError, ArrayLayoutError, InstantiationError, JlrsResult, CANNOT_DISPLAY_TYPE}, layout::{ typecheck::Typecheck, @@ -84,19 +69,6 @@ use crate::{ target::{frame::GcFrame, private::TargetPriv, unrooted::Unrooted, ExtendedTarget, Target}, }, private::Private, - wrappers::ptr::{ - array::{ - data::copied::CopiedArray, - dimensions::{ArrayDimensions, Dims}, - }, - datatype::DataType, - private::WrapperPriv, - type_name::TypeName, - union::Union, - value::Value, - Wrapper, - WrapperRef, - }, }; cfg_if! { @@ -917,11 +889,11 @@ impl<'scope, 'data> Array<'scope, 'data> { /// /// Returns `ArrayLayoutError::NotPointer` if the data is stored inline or `AccessError::InvalidLayout` if `T` /// is not a valid layout for the array elements. - pub unsafe fn wrapper_data<'borrow, T>( + pub unsafe fn managed_data<'borrow, T>( &'borrow self, ) -> JlrsResult> where - T: WrapperRef<'scope, 'data>, + T: ManagedRef<'scope, 'data>, Option: ValidField, { self.ensure_ptr_containing::()?; @@ -939,11 +911,11 @@ impl<'scope, 'data> Array<'scope, 'data> { /// /// Safety: Mutating Julia data is generally unsafe because it can't be guaranteed mutating /// this value is allowed. - pub unsafe fn wrapper_data_mut<'borrow, T>( + pub unsafe fn managed_data_mut<'borrow, T>( &'borrow mut self, ) -> JlrsResult> where - T: WrapperRef<'scope, 'data>, + T: ManagedRef<'scope, 'data>, Option: ValidField, { self.ensure_ptr_containing::()?; @@ -1188,7 +1160,7 @@ impl<'scope, 'data> Array<'scope, 'data> { fn ensure_ptr_containing<'fr, 'da, T>(self) -> JlrsResult<()> where - T: WrapperRef<'fr, 'da>, + T: ManagedRef<'fr, 'da>, Option: ValidField, { if !self.is_value_array() { @@ -1372,7 +1344,7 @@ unsafe impl<'scope, 'data> Typecheck for Array<'scope, 'data> { impl_debug!(Array<'_, '_>); -impl<'scope, 'data> WrapperPriv<'scope, 'data> for Array<'scope, 'data> { +impl<'scope, 'data> ManagedPriv<'scope, 'data> for Array<'scope, 'data> { type Wraps = jl_array_t; type TypeConstructorPriv<'target, 'da> = Array<'target, 'da>; const NAME: &'static str = "Array"; @@ -1441,10 +1413,10 @@ where let res = match x { Ok(arr) => Ok(arr - .wrapper() + .as_managed() .as_typed_unchecked::() .unwrap_non_null(Private)), - Err(e) => Err(e.wrapper().unwrap_non_null(Private)), + Err(e) => Err(e.as_managed().unwrap_non_null(Private)), }; Ok(output.result_from_ptr(res, Private)) @@ -1474,7 +1446,7 @@ where let target = frame.extended_target(inner_output); let res = Array::new_unchecked::(target, dims) - .wrapper() + .as_managed() .as_typed_unchecked::(); Ok(output.data_from_ptr(res.unwrap_non_null(Private), Private)) @@ -1509,10 +1481,10 @@ where let res = match Array::from_slice::(target, data, dims)? { Ok(arr) => Ok(arr - .wrapper() + .as_managed() .as_typed_unchecked::() .unwrap_non_null(Private)), - Err(e) => Err(e.wrapper().unwrap_non_null(Private)), + Err(e) => Err(e.as_managed().unwrap_non_null(Private)), }; Ok(output.result_from_ptr(res, Private)) @@ -1544,7 +1516,7 @@ where let target = frame.extended_target(inner_output); let res = Array::from_slice_unchecked::(target, data, dims)? - .wrapper() + .as_managed() .as_typed_unchecked::(); Ok(output.data_from_ptr(res.unwrap_non_null(Private), Private)) @@ -1579,10 +1551,10 @@ where let res = match Array::from_vec::(target, data, dims)? { Ok(arr) => Ok(arr - .wrapper() + .as_managed() .as_typed_unchecked::() .unwrap_non_null(Private)), - Err(e) => Err(e.wrapper().unwrap_non_null(Private)), + Err(e) => Err(e.as_managed().unwrap_non_null(Private)), }; Ok(output.result_from_ptr(res, Private)) @@ -1615,7 +1587,7 @@ where let target = frame.extended_target(inner_output); let res = Array::from_vec_unchecked::(target, data, dims)? - .wrapper() + .as_managed() .as_typed_unchecked::(); Ok(output.data_from_ptr(res.unwrap_non_null(Private), Private)) @@ -1656,10 +1628,10 @@ where let res = match Array::new_for(target, dims, ty) { Ok(arr) => Ok(arr - .wrapper() + .as_managed() .as_typed_unchecked::() .unwrap_non_null(Private)), - Err(e) => Err(e.wrapper().unwrap_non_null(Private)), + Err(e) => Err(e.as_managed().unwrap_non_null(Private)), }; Ok(output.result_from_ptr(res, Private)) @@ -1694,7 +1666,7 @@ where let target = frame.extended_target(inner_output); let res = Array::new_for_unchecked(target, dims, ty) - .wrapper() + .as_managed() .as_typed_unchecked::(); Ok(output.data_from_ptr(res.unwrap_non_null(Private), Private)) @@ -1903,10 +1875,10 @@ where let res = match self.as_array().reshape(target, dims) { Ok(arr) => Ok(arr - .wrapper() + .as_managed() .as_typed_unchecked::() .unwrap_non_null(Private)), - Err(e) => Err(e.wrapper().unwrap_non_null(Private)), + Err(e) => Err(e.as_managed().unwrap_non_null(Private)), }; Ok(output.result_from_ptr(res, Private)) @@ -1937,7 +1909,7 @@ where let res = self .as_array() .reshape_unchecked(target, dims) - .wrapper() + .as_managed() .as_typed_unchecked::() .unwrap_non_null(Private); Ok(output.data_from_ptr(res, Private)) @@ -1971,7 +1943,7 @@ where impl<'scope, 'data, T> TypedArray<'scope, 'data, Option> where - T: WrapperRef<'scope, 'data>, + T: ManagedRef<'scope, 'data>, Option: ValidField, { fn ensure_ptr(self) -> JlrsResult<()> { @@ -1990,7 +1962,7 @@ where /// /// Returns `ArrayLayoutError::NotPointer` if the data is stored inline or `AccessError::InvalidLayout` if `T` /// is not a valid layout for the array elements. - pub unsafe fn wrapper_data<'borrow>( + pub unsafe fn managed_data<'borrow>( &'borrow self, ) -> JlrsResult> { self.ensure_ptr()?; @@ -2009,7 +1981,7 @@ where /// /// Safety: Mutating Julia data is generally unsafe because it can't be guaranteed mutating /// this value is allowed. - pub unsafe fn wrapper_data_mut<'borrow>( + pub unsafe fn managed_data_mut<'borrow>( &'borrow mut self, ) -> JlrsResult> { self.ensure_ptr()?; @@ -2183,7 +2155,8 @@ unsafe impl<'scope, 'data, T: ValidField> Typecheck for TypedArray<'scope, 'data fn typecheck(t: DataType) -> bool { // Safety: borrow is only temporary unsafe { - t.is::() && T::valid_field(t.parameters().data().as_slice()[0].unwrap().value()) + t.is::() + && T::valid_field(t.parameters().data().as_slice()[0].unwrap().as_value()) } } } @@ -2197,7 +2170,7 @@ impl Debug for TypedArray<'_, '_, T> { } } -impl<'scope, 'data, T: ValidField> WrapperPriv<'scope, 'data> for TypedArray<'scope, 'data, T> { +impl<'scope, 'data, T: ValidField> ManagedPriv<'scope, 'data> for TypedArray<'scope, 'data, T> { type Wraps = jl_array_t; type TypeConstructorPriv<'target, 'da> = TypedArray<'target, 'da, T>; const NAME: &'static str = "Array"; diff --git a/jlrs/src/wrappers/ptr/array/tracked.rs b/jlrs/src/data/managed/array/tracked.rs similarity index 94% rename from jlrs/src/wrappers/ptr/array/tracked.rs rename to jlrs/src/data/managed/array/tracked.rs index a999bebc..15e03546 100644 --- a/jlrs/src/wrappers/ptr/array/tracked.rs +++ b/jlrs/src/data/managed/array/tracked.rs @@ -7,35 +7,25 @@ use std::{ use super::{ data::{ accessor::{ - BitsArrayAccessorI, - BitsArrayAccessorMut, - IndeterminateArrayAccessorI, - IndeterminateArrayAccessorMut, - InlinePtrArrayAccessorI, - InlinePtrArrayAccessorMut, - PtrArrayAccessorI, - PtrArrayAccessorMut, - UnionArrayAccessorI, - UnionArrayAccessorMut, + BitsArrayAccessorI, BitsArrayAccessorMut, IndeterminateArrayAccessorI, + IndeterminateArrayAccessorMut, InlinePtrArrayAccessorI, InlinePtrArrayAccessorMut, + PtrArrayAccessorI, PtrArrayAccessorMut, UnionArrayAccessorI, UnionArrayAccessorMut, }, copied::CopiedArray, }, dimensions::{ArrayDimensions, Dims}, - Array, - ArrayData, - TypedArray, - TypedArrayData, + Array, ArrayData, TypedArray, TypedArrayData, }; #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] use super::{ArrayResult, TypedArrayResult}; use crate::{ + data::managed::{value::ValueRef, ManagedRef}, error::JlrsResult, layout::valid_layout::ValidField, memory::{ context::ledger::Ledger, target::{ExtendedTarget, Target}, }, - wrappers::ptr::{value::ValueRef, WrapperRef}, }; pub trait ArrayWrapper<'scope, 'data>: Copy { @@ -198,14 +188,14 @@ impl<'tracked, 'scope, 'data> TrackedArray<'tracked, 'scope, 'data, Array<'scope unsafe { self.data.inline_data() } } - pub fn wrapper_data<'borrow, T>( + pub fn managed_data<'borrow, T>( &'borrow self, ) -> JlrsResult> where - T: WrapperRef<'scope, 'data>, + T: ManagedRef<'scope, 'data>, Option: ValidField, { - unsafe { self.data.wrapper_data() } + unsafe { self.data.managed_data() } } pub fn value_data<'borrow>( @@ -307,13 +297,13 @@ where impl<'tracked, 'scope, 'data, T> TrackedArray<'tracked, 'scope, 'data, TypedArray<'scope, 'data, Option>> where - T: WrapperRef<'scope, 'data>, + T: ManagedRef<'scope, 'data>, Option: ValidField, { - pub fn wrapper_data<'borrow>( + pub fn managed_data<'borrow>( &'borrow self, ) -> JlrsResult> { - unsafe { self.data.wrapper_data() } + unsafe { self.data.managed_data() } } pub fn value_data<'borrow>( @@ -375,14 +365,14 @@ impl<'tracked, 'scope, 'data> TrackedArrayMut<'tracked, 'scope, 'data, Array<'sc self.tracked.data.inline_data_mut() } - pub unsafe fn wrapper_data_mut<'borrow, T>( + pub unsafe fn managed_data_mut<'borrow, T>( &'borrow mut self, ) -> JlrsResult> where - T: WrapperRef<'scope, 'data>, + T: ManagedRef<'scope, 'data>, Option: ValidField, { - self.tracked.data.wrapper_data_mut() + self.tracked.data.managed_data_mut() } pub unsafe fn value_data_mut<'borrow>( @@ -497,13 +487,13 @@ where impl<'tracked, 'scope, 'data, T> TrackedArrayMut<'tracked, 'scope, 'data, TypedArray<'scope, 'data, Option>> where - T: WrapperRef<'scope, 'data>, + T: ManagedRef<'scope, 'data>, Option: ValidField, { - pub unsafe fn wrapper_data_mut<'borrow>( + pub unsafe fn managed_data_mut<'borrow>( &'borrow mut self, ) -> JlrsResult> { - self.tracked.data.wrapper_data_mut() + self.tracked.data.managed_data_mut() } pub unsafe fn value_data_mut<'borrow>( diff --git a/jlrs/src/wrappers/ptr/datatype.rs b/jlrs/src/data/managed/datatype.rs similarity index 95% rename from jlrs/src/wrappers/ptr/datatype.rs rename to jlrs/src/data/managed/datatype.rs index 66219db7..f24d7a0d 100644 --- a/jlrs/src/wrappers/ptr/datatype.rs +++ b/jlrs/src/data/managed/datatype.rs @@ -1,128 +1,60 @@ -//! Wrapper for `DataType`, which provides access to type properties. +//! Managed for `DataType`, which provides access to type properties. use std::{ffi::CStr, marker::PhantomData, ptr::NonNull}; use cfg_if::cfg_if; use jl_sys::{ - jl_abstractslot_type, - jl_abstractstring_type, - jl_any_type, - jl_anytuple_type, - jl_argument_type, - jl_argumenterror_type, - jl_bool_type, - jl_boundserror_type, - jl_builtin_type, - jl_char_type, - jl_code_info_type, - jl_code_instance_type, - jl_const_type, - jl_datatype_layout_t, - jl_datatype_t, - jl_datatype_type, - jl_emptytuple_type, - jl_errorexception_type, - jl_expr_type, - jl_field_index, - jl_field_isptr, - jl_field_offset, - jl_field_size, - jl_float16_type, - jl_float32_type, - jl_float64_type, - jl_floatingpoint_type, - jl_function_type, - jl_get_fieldtypes, - jl_globalref_type, - jl_gotoifnot_type, - jl_gotonode_type, - jl_initerror_type, - jl_int16_type, - jl_int32_type, - jl_int64_type, - jl_int8_type, - jl_intrinsic_type, - jl_lineinfonode_type, - jl_linenumbernode_type, - jl_loaderror_type, - jl_method_instance_type, - jl_method_match_type, - jl_method_type, - jl_methoderror_type, - jl_methtable_type, - jl_module_type, - jl_new_structv, - jl_newvarnode_type, - jl_nothing_type, - jl_number_type, - jl_partial_struct_type, - jl_phicnode_type, - jl_phinode_type, - jl_pinode_type, - jl_quotenode_type, - jl_returnnode_type, - jl_signed_type, - jl_simplevector_type, - jl_slotnumber_type, - jl_ssavalue_type, - jl_string_type, - jl_symbol_type, - jl_task_type, - jl_tvar_type, - jl_typedslot_type, - jl_typeerror_type, - jl_typemap_entry_type, - jl_typemap_level_type, - jl_typename_str, - jl_typename_type, - jl_typeofbottom_type, - jl_uint16_type, - jl_uint32_type, - jl_uint64_type, - jl_uint8_type, - jl_undefvarerror_type, - jl_unionall_type, - jl_uniontype_type, - jl_upsilonnode_type, - jl_voidpointer_type, - jl_weakref_type, + jl_abstractslot_type, jl_abstractstring_type, jl_any_type, jl_anytuple_type, jl_argument_type, + jl_argumenterror_type, jl_bool_type, jl_boundserror_type, jl_builtin_type, jl_char_type, + jl_code_info_type, jl_code_instance_type, jl_const_type, jl_datatype_layout_t, jl_datatype_t, + jl_datatype_type, jl_emptytuple_type, jl_errorexception_type, jl_expr_type, jl_field_index, + jl_field_isptr, jl_field_offset, jl_field_size, jl_float16_type, jl_float32_type, + jl_float64_type, jl_floatingpoint_type, jl_function_type, jl_get_fieldtypes, jl_globalref_type, + jl_gotoifnot_type, jl_gotonode_type, jl_initerror_type, jl_int16_type, jl_int32_type, + jl_int64_type, jl_int8_type, jl_intrinsic_type, jl_lineinfonode_type, jl_linenumbernode_type, + jl_loaderror_type, jl_method_instance_type, jl_method_match_type, jl_method_type, + jl_methoderror_type, jl_methtable_type, jl_module_type, jl_new_structv, jl_newvarnode_type, + jl_nothing_type, jl_number_type, jl_partial_struct_type, jl_phicnode_type, jl_phinode_type, + jl_pinode_type, jl_quotenode_type, jl_returnnode_type, jl_signed_type, jl_simplevector_type, + jl_slotnumber_type, jl_ssavalue_type, jl_string_type, jl_symbol_type, jl_task_type, + jl_tvar_type, jl_typedslot_type, jl_typeerror_type, jl_typemap_entry_type, + jl_typemap_level_type, jl_typename_str, jl_typename_type, jl_typeofbottom_type, jl_uint16_type, + jl_uint32_type, jl_uint64_type, jl_uint8_type, jl_undefvarerror_type, jl_unionall_type, + jl_uniontype_type, jl_upsilonnode_type, jl_voidpointer_type, jl_weakref_type, }; #[cfg(not(feature = "julia-1-6"))] use jl_sys::{ - jl_atomicerror_type, - jl_interconditional_type, - jl_partial_opaque_type, - jl_vararg_type, + jl_atomicerror_type, jl_interconditional_type, jl_partial_opaque_type, jl_vararg_type, }; use super::{simple_vector::SimpleVectorData, type_name::TypeName, value::ValueData, Ref}; use crate::{ convert::to_symbol::ToSymbol, + data::managed::{ + private::ManagedPriv, + simple_vector::{SimpleVector, SimpleVectorRef}, + symbol::{Symbol, SymbolRef}, + value::Value, + Managed, + }, error::{AccessError, JlrsResult, CANNOT_DISPLAY_TYPE}, impl_julia_typecheck, layout::typecheck::Typecheck, memory::target::Target, private::Private, - wrappers::ptr::{ - private::WrapperPriv, - simple_vector::{SimpleVector, SimpleVectorRef}, - symbol::{Symbol, SymbolRef}, - value::Value, - Wrapper, - }, }; cfg_if! { if #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] { - use super::array::Array; - use super::value::ValueResult; + use crate::data::managed::array::Array; + use crate::data::managed::value::ValueResult; } } /// Julia type information. You can acquire a [`Value`]'s datatype by by calling /// [`Value::datatype`]. If a `DataType` is concrete and not a subtype of `Array` a new instance /// can be created with [`DataType::instantiate`]. This can also be achieved by converting the -/// `DataType` to a `Value` with [`Wrapper::as_value`] and calling it as a Julia function. +/// `DataType` to a `Value` with [`Managed::as_value`] and calling it as a Julia function. #[derive(Copy, Clone)] #[repr(transparent)] pub struct DataType<'scope>(NonNull, PhantomData<&'scope ()>); @@ -227,7 +159,7 @@ impl<'scope> DataType<'scope> { unsafe { Some( self.field_types(&target) - .wrapper() + .as_managed() .data() .as_slice() .get(idx)? @@ -250,7 +182,7 @@ impl<'scope> DataType<'scope> { { Some( self.field_types(&target) - .wrapper() + .as_managed() .data() .as_slice() .get_unchecked(idx) @@ -273,7 +205,7 @@ impl<'scope> DataType<'scope> { unsafe { Some( self.field_types(&target) - .wrapper() + .as_managed() .data() .as_slice() .get(idx)? @@ -297,7 +229,7 @@ impl<'scope> DataType<'scope> { .typed_data_unchecked::() .as_slice() .get(idx)? - .map(|s| s.wrapper()) + .map(|s| s.as_managed()) } } @@ -1514,7 +1446,7 @@ impl<'scope> Eq for DataType<'scope> {} impl_debug!(DataType<'_>); impl_julia_typecheck!(DataType<'frame>, jl_datatype_type, 'frame); -impl<'scope> WrapperPriv<'scope, '_> for DataType<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for DataType<'scope> { type Wraps = jl_datatype_t; type TypeConstructorPriv<'target, 'da> = DataType<'target>; const NAME: &'static str = "DataType"; diff --git a/jlrs/src/wrappers/ptr/function.rs b/jlrs/src/data/managed/function.rs similarity index 95% rename from jlrs/src/wrappers/ptr/function.rs rename to jlrs/src/data/managed/function.rs index 4ce6b9d1..8f2bfe3e 100644 --- a/jlrs/src/wrappers/ptr/function.rs +++ b/jlrs/src/data/managed/function.rs @@ -1,4 +1,4 @@ -//! Wrapper for `Function`, the supertype of all Julia functions. +//! Managed for `Function`, the supertype of all Julia functions. //! //! All Julia functions are subtypes of `Function`, a function can be called with the methods //! of the [`Call`] trait. You don't need to cast a [`Value`] to a [`Function`] in order to call @@ -13,6 +13,7 @@ use jl_sys::jl_value_t; use super::{value::ValueResult, Ref}; use crate::{ call::{Call, ProvideKeywords, WithKeywords}, + data::managed::{datatype::DataType, private::ManagedPriv, value::Value, Managed}, error::JlrsResult, layout::{ typecheck::Typecheck, @@ -20,7 +21,6 @@ use crate::{ }, memory::target::{unrooted::Unrooted, Target}, private::Private, - wrappers::ptr::{datatype::DataType, private::WrapperPriv, value::Value, Wrapper}, }; /// A Julia function. @@ -49,7 +49,7 @@ unsafe impl Typecheck for Function<'_, '_> { impl_debug!(Function<'_, '_>); -impl<'scope, 'data> WrapperPriv<'scope, 'data> for Function<'scope, 'data> { +impl<'scope, 'data> ManagedPriv<'scope, 'data> for Function<'scope, 'data> { type Wraps = jl_value_t; type TypeConstructorPriv<'target, 'da> = Function<'target, 'da>; const NAME: &'static str = "Function"; diff --git a/jlrs/src/wrappers/ptr/internal/code_instance.rs b/jlrs/src/data/managed/internal/code_instance.rs similarity index 98% rename from jlrs/src/wrappers/ptr/internal/code_instance.rs rename to jlrs/src/data/managed/internal/code_instance.rs index 3e145120..7b00057e 100644 --- a/jlrs/src/wrappers/ptr/internal/code_instance.rs +++ b/jlrs/src/data/managed/internal/code_instance.rs @@ -1,4 +1,4 @@ -//! Wrapper for `CodeInstance`. +//! Managed for `CodeInstance`. //! //! The documentation for this module has been slightly adapted from the comments for this struct //! in [`julia.h`] @@ -11,14 +11,14 @@ use cfg_if::cfg_if; use jl_sys::{jl_code_instance_t, jl_code_instance_type}; use crate::{ - impl_julia_typecheck, - memory::target::Target, - private::Private, - wrappers::ptr::{ - private::WrapperPriv, + data::managed::{ + private::ManagedPriv, value::{Value, ValueData, ValueRef}, Ref, }, + impl_julia_typecheck, + memory::target::Target, + private::Private, }; cfg_if! { @@ -233,7 +233,7 @@ impl<'scope> CodeInstance<'scope> { impl_julia_typecheck!(CodeInstance<'scope>, jl_code_instance_type, 'scope); impl_debug!(CodeInstance<'_>); -impl<'scope> WrapperPriv<'scope, '_> for CodeInstance<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for CodeInstance<'scope> { type Wraps = jl_code_instance_t; type TypeConstructorPriv<'target, 'da> = CodeInstance<'target>; const NAME: &'static str = "CodeInstance"; diff --git a/jlrs/src/wrappers/ptr/internal/expr.rs b/jlrs/src/data/managed/internal/expr.rs similarity index 94% rename from jlrs/src/wrappers/ptr/internal/expr.rs rename to jlrs/src/data/managed/internal/expr.rs index 0c93b021..91f1a2b6 100644 --- a/jlrs/src/wrappers/ptr/internal/expr.rs +++ b/jlrs/src/data/managed/internal/expr.rs @@ -1,19 +1,19 @@ -//! Wrapper for `Expr`. +//! Managed for `Expr`. use std::{marker::PhantomData, ptr::NonNull}; use jl_sys::{jl_expr_t, jl_expr_type}; use crate::{ - impl_julia_typecheck, - memory::target::Target, - private::Private, - wrappers::ptr::{ + data::managed::{ array::{ArrayData, ArrayRef}, - private::WrapperPriv, + private::ManagedPriv, symbol::Symbol, Ref, }, + impl_julia_typecheck, + memory::target::Target, + private::Private, }; /// A compound expression in Julia ASTs. @@ -56,7 +56,7 @@ impl<'scope> Expr<'scope> { impl_julia_typecheck!(Expr<'scope>, jl_expr_type, 'scope); impl_debug!(Expr<'_>); -impl<'scope> WrapperPriv<'scope, '_> for Expr<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for Expr<'scope> { type Wraps = jl_expr_t; type TypeConstructorPriv<'target, 'da> = Expr<'target>; const NAME: &'static str = "Expr"; diff --git a/jlrs/src/wrappers/ptr/internal/method.rs b/jlrs/src/data/managed/internal/method.rs similarity index 98% rename from jlrs/src/wrappers/ptr/internal/method.rs rename to jlrs/src/data/managed/internal/method.rs index f127dbe2..e074372a 100644 --- a/jlrs/src/wrappers/ptr/internal/method.rs +++ b/jlrs/src/data/managed/internal/method.rs @@ -1,4 +1,4 @@ -//! Wrapper for `Method`. +//! Managed for `Method`. //! //! The documentation for this module has been slightly adapted from the comments for this struct //! in [`julia.h`] @@ -11,19 +11,19 @@ use cfg_if::cfg_if; use jl_sys::{jl_method_t, jl_method_type}; use crate::{ - impl_julia_typecheck, - memory::target::Target, - private::Private, - wrappers::ptr::{ + data::managed::{ array::{ArrayData, ArrayRef}, internal::method_instance::MethodInstanceRef, module::{ModuleData, ModuleRef}, - private::WrapperPriv, + private::ManagedPriv, simple_vector::{SimpleVectorData, SimpleVectorRef}, symbol::Symbol, value::{ValueData, ValueRef}, Ref, }, + impl_julia_typecheck, + memory::target::Target, + private::Private, }; cfg_if! { @@ -33,9 +33,9 @@ cfg_if! { } #[cfg(not(any(feature = "julia-1-6", feature = "julia-1-7")))] -use crate::wrappers::ptr::array::TypedArrayData; +use crate::data::managed::array::TypedArrayData; #[cfg(not(any(feature = "julia-1-6", feature = "julia-1-7")))] -use crate::wrappers::ptr::array::TypedArrayRef; +use crate::data::managed::array::TypedArrayRef; /// This type describes a single method definition, and stores data shared by the specializations /// of a function. @@ -404,7 +404,7 @@ impl<'scope> Method<'scope> { impl_julia_typecheck!(Method<'scope>, jl_method_type, 'scope); impl_debug!(Method<'_>); -impl<'scope> WrapperPriv<'scope, '_> for Method<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for Method<'scope> { type Wraps = jl_method_t; type TypeConstructorPriv<'target, 'da> = Method<'target>; const NAME: &'static str = "Method"; diff --git a/jlrs/src/wrappers/ptr/internal/method_instance.rs b/jlrs/src/data/managed/internal/method_instance.rs similarity index 97% rename from jlrs/src/wrappers/ptr/internal/method_instance.rs rename to jlrs/src/data/managed/internal/method_instance.rs index 994c7a22..c4f700a3 100644 --- a/jlrs/src/wrappers/ptr/internal/method_instance.rs +++ b/jlrs/src/data/managed/internal/method_instance.rs @@ -1,4 +1,4 @@ -//! Wrapper for `MethodInstance`. +//! Managed for `MethodInstance`. //! //! The documentation for this module has been slightly adapted from the comments for this struct //! in [`julia.h`] @@ -10,16 +10,16 @@ use cfg_if::cfg_if; use jl_sys::{jl_method_instance_t, jl_method_instance_type}; use crate::{ - impl_julia_typecheck, - memory::target::Target, - private::Private, - wrappers::ptr::{ + data::managed::{ internal::code_instance::CodeInstanceRef, - private::WrapperPriv, + private::ManagedPriv, simple_vector::{SimpleVectorData, SimpleVectorRef}, value::{ValueData, ValueRef}, Ref, }, + impl_julia_typecheck, + memory::target::Target, + private::Private, }; cfg_if! { @@ -169,7 +169,7 @@ impl<'scope> MethodInstance<'scope> { impl_julia_typecheck!(MethodInstance<'scope>, jl_method_instance_type, 'scope); impl_debug!(MethodInstance<'_>); -impl<'scope> WrapperPriv<'scope, '_> for MethodInstance<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for MethodInstance<'scope> { type Wraps = jl_method_instance_t; type TypeConstructorPriv<'target, 'da> = MethodInstance<'target>; const NAME: &'static str = "MethodInstance"; diff --git a/jlrs/src/wrappers/ptr/internal/method_match.rs b/jlrs/src/data/managed/internal/method_match.rs similarity index 94% rename from jlrs/src/wrappers/ptr/internal/method_match.rs rename to jlrs/src/data/managed/internal/method_match.rs index 7a4ee65d..3dc8c449 100644 --- a/jlrs/src/wrappers/ptr/internal/method_match.rs +++ b/jlrs/src/data/managed/internal/method_match.rs @@ -1,4 +1,4 @@ -//! Wrapper for `MethodMatch`. +//! Managed for `MethodMatch`. //! //! The documentation for this module has been slightly adapted from the comments for this struct //! in [`julia.h`] @@ -9,12 +9,12 @@ use std::{marker::PhantomData, ptr::NonNull}; use jl_sys::{jl_method_match_t, jl_method_match_type}; use crate::{ + data::managed::{private::ManagedPriv, simple_vector::SimpleVector, value::Value, Ref}, impl_julia_typecheck, private::Private, - wrappers::ptr::{private::WrapperPriv, simple_vector::SimpleVector, value::Value, Ref}, }; -/// Wrapper for `MethodMatch`. +/// Managed for `MethodMatch`. #[derive(Copy, Clone)] #[repr(transparent)] pub struct MethodMatch<'scope>(NonNull, PhantomData<&'scope ()>); @@ -70,7 +70,7 @@ impl<'scope> MethodMatch<'scope> { impl_julia_typecheck!(MethodMatch<'scope>, jl_method_match_type, 'scope); impl_debug!(MethodMatch<'_>); -impl<'scope> WrapperPriv<'scope, '_> for MethodMatch<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for MethodMatch<'scope> { type Wraps = jl_method_match_t; type TypeConstructorPriv<'target, 'da> = MethodMatch<'target>; const NAME: &'static str = "MethodMatch"; diff --git a/jlrs/src/wrappers/ptr/internal/method_table.rs b/jlrs/src/data/managed/internal/method_table.rs similarity index 98% rename from jlrs/src/wrappers/ptr/internal/method_table.rs rename to jlrs/src/data/managed/internal/method_table.rs index c7431271..996a07ec 100644 --- a/jlrs/src/wrappers/ptr/internal/method_table.rs +++ b/jlrs/src/data/managed/internal/method_table.rs @@ -1,4 +1,4 @@ -//! Wrapper for `MethodTable`. +//! Managed for `MethodTable`. //! //! The documentation for this module has been slightly adapted from the comments for this struct //! in [`julia.h`] @@ -11,17 +11,17 @@ use cfg_if::cfg_if; use jl_sys::{jl_methtable_t, jl_methtable_type}; use crate::{ - impl_julia_typecheck, - memory::target::Target, - private::Private, - wrappers::ptr::{ + data::managed::{ array::{ArrayData, ArrayRef}, module::Module, - private::WrapperPriv, + private::ManagedPriv, symbol::Symbol, value::{ValueData, ValueRef}, Ref, }, + impl_julia_typecheck, + memory::target::Target, + private::Private, }; cfg_if! { @@ -193,7 +193,7 @@ impl<'scope> MethodTable<'scope> { impl_julia_typecheck!(MethodTable<'scope>, jl_methtable_type, 'scope); impl_debug!(MethodTable<'_>); -impl<'scope> WrapperPriv<'scope, '_> for MethodTable<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for MethodTable<'scope> { type Wraps = jl_methtable_t; type TypeConstructorPriv<'target, 'da> = MethodTable<'target>; const NAME: &'static str = " { impl_debug!(OpaqueClosure<'_>); -impl<'scope, 'data> WrapperPriv<'scope, 'data> for OpaqueClosure<'scope> { +impl<'scope, 'data> ManagedPriv<'scope, 'data> for OpaqueClosure<'scope> { type Wraps = jl_opaque_closure_t; type TypeConstructorPriv<'target, 'da> = OpaqueClosure<'target>; const NAME: &'static str = "OpaqueClosure"; diff --git a/jlrs/src/wrappers/ptr/internal/typemap_entry.rs b/jlrs/src/data/managed/internal/typemap_entry.rs similarity index 97% rename from jlrs/src/wrappers/ptr/internal/typemap_entry.rs rename to jlrs/src/data/managed/internal/typemap_entry.rs index 11463ad6..2899fe94 100644 --- a/jlrs/src/wrappers/ptr/internal/typemap_entry.rs +++ b/jlrs/src/data/managed/internal/typemap_entry.rs @@ -1,4 +1,4 @@ -//! Wrapper for `TypeMapEntry`. +//! Managed for `TypeMapEntry`. //! //! The documentation for this module has been slightly adapted from the comments for this struct //! in [`julia.h`] @@ -11,14 +11,14 @@ use cfg_if::cfg_if; use jl_sys::{jl_typemap_entry_t, jl_typemap_entry_type}; use crate::{ - impl_julia_typecheck, - memory::target::Target, - private::Private, - wrappers::ptr::{ - private::WrapperPriv, + data::managed::{ + private::ManagedPriv, value::{Value, ValueData, ValueRef}, Ref, }, + impl_julia_typecheck, + memory::target::Target, + private::Private, }; cfg_if! { @@ -146,7 +146,7 @@ impl<'scope> TypeMapEntry<'scope> { impl_julia_typecheck!(TypeMapEntry<'scope>, jl_typemap_entry_type, 'scope); impl_debug!(TypeMapEntry<'_>); -impl<'scope> WrapperPriv<'scope, '_> for TypeMapEntry<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for TypeMapEntry<'scope> { type Wraps = jl_typemap_entry_t; type TypeConstructorPriv<'target, 'da> = TypeMapEntry<'target>; const NAME: &'static str = "TypeMapEntry"; diff --git a/jlrs/src/wrappers/ptr/internal/typemap_level.rs b/jlrs/src/data/managed/internal/typemap_level.rs similarity index 98% rename from jlrs/src/wrappers/ptr/internal/typemap_level.rs rename to jlrs/src/data/managed/internal/typemap_level.rs index 6e4be102..d55f2c3e 100644 --- a/jlrs/src/wrappers/ptr/internal/typemap_level.rs +++ b/jlrs/src/data/managed/internal/typemap_level.rs @@ -1,4 +1,4 @@ -//! Wrapper for `TypeMapLevel`. +//! Managed for `TypeMapLevel`. //! //! The documentation for this module has been slightly adapted from the comments for this struct //! in [`julia.h`] @@ -11,14 +11,14 @@ use cfg_if::cfg_if; use jl_sys::{jl_typemap_level_t, jl_typemap_level_type}; use crate::{ - impl_julia_typecheck, - memory::target::Target, - private::Private, - wrappers::ptr::{ - private::WrapperPriv, + data::managed::{ + private::ManagedPriv, value::{ValueData, ValueRef}, Ref, }, + impl_julia_typecheck, + memory::target::Target, + private::Private, }; cfg_if! { @@ -193,7 +193,7 @@ impl<'scope> TypeMapLevel<'scope> { impl_julia_typecheck!(TypeMapLevel<'scope>, jl_typemap_level_type, 'scope); impl_debug!(TypeMapLevel<'_>); -impl<'scope> WrapperPriv<'scope, '_> for TypeMapLevel<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for TypeMapLevel<'scope> { type Wraps = jl_typemap_level_t; type TypeConstructorPriv<'target, 'da> = TypeMapLevel<'target>; const NAME: &'static str = "TypeMapLevel"; diff --git a/jlrs/src/wrappers/ptr/internal/vararg.rs b/jlrs/src/data/managed/internal/vararg.rs similarity index 94% rename from jlrs/src/wrappers/ptr/internal/vararg.rs rename to jlrs/src/data/managed/internal/vararg.rs index 2f28997a..25ed27e2 100644 --- a/jlrs/src/wrappers/ptr/internal/vararg.rs +++ b/jlrs/src/data/managed/internal/vararg.rs @@ -1,18 +1,18 @@ -//! Wrapper for `Vararg`. +//! Managed for `Vararg`. use std::{marker::PhantomData, ptr::NonNull}; use jl_sys::{jl_vararg_t, jl_vararg_type}; use crate::{ - impl_julia_typecheck, - memory::target::Target, - private::Private, - wrappers::ptr::{ - private::WrapperPriv, + data::managed::{ + private::ManagedPriv, value::{ValueData, ValueRef}, Ref, }, + impl_julia_typecheck, + memory::target::Target, + private::Private, }; /// A wrapper for `Vararg`. @@ -49,7 +49,7 @@ impl<'scope> Vararg<'scope> { impl_julia_typecheck!(Vararg<'scope>, jl_vararg_type, 'scope); impl_debug!(Vararg<'_>); -impl<'scope, 'data> WrapperPriv<'scope, 'data> for Vararg<'scope> { +impl<'scope, 'data> ManagedPriv<'scope, 'data> for Vararg<'scope> { type Wraps = jl_vararg_t; type TypeConstructorPriv<'target, 'da> = Vararg<'target>; const NAME: &'static str = "Vararg"; diff --git a/jlrs/src/wrappers/ptr/internal/weak_ref.rs b/jlrs/src/data/managed/internal/weak_ref.rs similarity index 93% rename from jlrs/src/wrappers/ptr/internal/weak_ref.rs rename to jlrs/src/data/managed/internal/weak_ref.rs index 1b1a32b4..d3f33842 100644 --- a/jlrs/src/wrappers/ptr/internal/weak_ref.rs +++ b/jlrs/src/data/managed/internal/weak_ref.rs @@ -1,18 +1,18 @@ -//! Wrapper for `WeakRef`. +//! Managed for `WeakRef`. use std::{marker::PhantomData, ptr::NonNull}; use jl_sys::{jl_weakref_t, jl_weakref_type}; use crate::{ - impl_julia_typecheck, - memory::target::Target, - private::Private, - wrappers::ptr::{ - private::WrapperPriv, + data::managed::{ + private::ManagedPriv, value::{ValueData, ValueRef}, Ref, }, + impl_julia_typecheck, + memory::target::Target, + private::Private, }; /// A weak reference. @@ -44,7 +44,7 @@ impl<'scope> WeakRef<'scope> { impl_julia_typecheck!(WeakRef<'scope>, jl_weakref_type, 'scope); impl_debug!(WeakRef<'_>); -impl<'scope> WrapperPriv<'scope, '_> for WeakRef<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for WeakRef<'scope> { type Wraps = jl_weakref_t; type TypeConstructorPriv<'target, 'da> = WeakRef<'target>; const NAME: &'static str = "WeakRef"; diff --git a/jlrs/src/wrappers/ptr/mod.rs b/jlrs/src/data/managed/mod.rs similarity index 77% rename from jlrs/src/wrappers/ptr/mod.rs rename to jlrs/src/data/managed/mod.rs index e8af9e87..4ef5f404 100644 --- a/jlrs/src/wrappers/ptr/mod.rs +++ b/jlrs/src/data/managed/mod.rs @@ -16,8 +16,8 @@ //! about rooting see the documentation of the [`memory`] module. //! //! [`memory`]: crate::memory -//! [`DataType`]: crate::wrappers::ptr::datatype::DataType -//! [`Array`]: crate::wrappers::ptr::array::Array +//! [`DataType`]: crate::data::managed::datatype::DataType +//! [`Array`]: crate::data::managed::array::Array // NB: inspect layout of builtin types with: /* @@ -31,8 +31,8 @@ end macro_rules! impl_valid_layout { ($ref_type:ident, $type:ident) => { unsafe impl $crate::layout::valid_layout::ValidLayout for $ref_type<'_> { - fn valid_layout(ty: $crate::wrappers::ptr::value::Value) -> bool { - if let Ok(dt) = ty.cast::<$crate::wrappers::ptr::datatype::DataType>() { + fn valid_layout(ty: $crate::data::managed::value::Value) -> bool { + if let Ok(dt) = ty.cast::<$crate::data::managed::datatype::DataType>() { dt.is::<$type>() } else { false @@ -43,8 +43,8 @@ macro_rules! impl_valid_layout { } unsafe impl $crate::layout::valid_layout::ValidField for Option<$ref_type<'_>> { - fn valid_field(ty: $crate::wrappers::ptr::value::Value) -> bool { - if let Ok(dt) = ty.cast::<$crate::wrappers::ptr::datatype::DataType>() { + fn valid_field(ty: $crate::data::managed::value::Value) -> bool { + if let Ok(dt) = ty.cast::<$crate::data::managed::datatype::DataType>() { dt.is::<$type>() } else { false @@ -58,7 +58,7 @@ macro_rules! impl_debug { ($type:ty) => { impl ::std::fmt::Debug for $type { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - match ::display_string(*self) { + match ::display_string(*self) { Ok(s) => f.write_str(&s), Err(e) => f.write_fmt(format_args!("", e)), } @@ -92,35 +92,35 @@ use std::{ use crate::{ call::Call, + data::managed::{module::Module, private::ManagedPriv as _, string::JuliaString, value::Value}, error::{JlrsError, JlrsResult, CANNOT_DISPLAY_VALUE}, layout::valid_layout::{ValidField, ValidLayout}, memory::target::{unrooted::Unrooted, Target}, private::Private, - wrappers::ptr::{module::Module, private::WrapperPriv as _, string::JuliaString, value::Value}, }; /// Trait implemented by `Ref`. -pub trait WrapperRef<'scope, 'data>: - private::WrapperRef<'scope, 'data> + Copy + Debug + ValidLayout +pub trait ManagedRef<'scope, 'data>: + private::ManagedRef<'scope, 'data> + Copy + Debug + ValidLayout { /// The pointer wrapper type associated with this `Ref`. - type Wrapper: Wrapper<'scope, 'data>; + type Managed: Managed<'scope, 'data>; } -impl<'scope, 'data, T> WrapperRef<'scope, 'data> for Ref<'scope, 'data, T> +impl<'scope, 'data, T> ManagedRef<'scope, 'data> for Ref<'scope, 'data, T> where - T: Wrapper<'scope, 'data>, + T: Managed<'scope, 'data>, Self: Copy + ValidLayout, Option: ValidField, { - type Wrapper = T; + type Managed = T; } /// Trait implemented by all pointer wrapper types. -pub trait Wrapper<'scope, 'data>: private::WrapperPriv<'scope, 'data> { +pub trait Managed<'scope, 'data>: private::ManagedPriv<'scope, 'data> { /// `Self`, but with arbitrary lifetimes. Used to construct the appropriate type in generic /// contexts. - type TypeConstructor<'target, 'da>: Wrapper<'target, 'da>; + type TypeConstructor<'target, 'da>: Managed<'target, 'da>; /// Convert the wrapper to a `Ref`. fn as_ref(self) -> Ref<'scope, 'data, Self> { @@ -151,17 +151,18 @@ pub trait Wrapper<'scope, 'data>: private::WrapperPriv<'scope, 'data> { fn display_string(self) -> JlrsResult { // Safety: all Julia data that is accessed is globally rooted, the result is converted // to a String before the GC can free it. + let global = self.unrooted_target(); + let s = unsafe { - let global = Unrooted::new(); Module::main(&global) .submodule(&global, "Jlrs")? - .wrapper() + .as_managed() .function(&global, "valuestring")? - .wrapper() + .as_managed() .call1(&global, self.as_value()) - .map_err(|e| e.value().error_string_or(CANNOT_DISPLAY_VALUE)) + .map_err(|e| e.as_value().error_string_or(CANNOT_DISPLAY_VALUE)) .map_err(|e| JlrsError::exception(format!("Jlrs.valuestring failed: {}", e)))? - .value() + .as_value() .cast::()? .as_str()? .to_string() @@ -180,17 +181,18 @@ pub trait Wrapper<'scope, 'data>: private::WrapperPriv<'scope, 'data> { fn error_string(self) -> JlrsResult { // Safety: all Julia data that is accessed is globally rooted, the result is converted // to a String before the GC can free it. + let global = self.unrooted_target(); + let s = unsafe { - let global = Unrooted::new(); Module::main(&global) .submodule(&global, "Jlrs")? - .wrapper() + .as_managed() .function(&global, "errorstring")? - .wrapper() + .as_managed() .call1(&global, self.as_value()) - .map_err(|e| e.value().error_string_or(CANNOT_DISPLAY_VALUE)) + .map_err(|e| e.as_value().error_string_or(CANNOT_DISPLAY_VALUE)) .map_err(|e| JlrsError::exception(format!("Jlrs.errorstring failed: {}", e)))? - .value() + .as_value() .cast::()? .as_str()? .to_string() @@ -213,15 +215,15 @@ pub trait Wrapper<'scope, 'data>: private::WrapperPriv<'scope, 'data> { } /// The wrapper type W<'target, 'data> assocatiated with the reference type T<'scope, 'data>. -pub type WrapperType<'target, 'scope, 'data, T> = - <>::Wrapper as Wrapper<'scope, 'data>>::TypeConstructor< +pub type ManagedType<'target, 'scope, 'data, T> = + <>::Managed as Managed<'scope, 'data>>::TypeConstructor< 'target, 'data, >; -impl<'scope, 'data, W> Wrapper<'scope, 'data> for W +impl<'scope, 'data, W> Managed<'scope, 'data> for W where - W: private::WrapperPriv<'scope, 'data>, + W: private::ManagedPriv<'scope, 'data>, { type TypeConstructor<'target, 'da> = Self::TypeConstructorPriv<'target, 'da>; } @@ -234,7 +236,7 @@ where /// safe to use. Whenever data is not rooted jlrs returns a `Ref`. Because it's not rooted it's /// unsafe to use. #[repr(transparent)] -pub struct Ref<'scope, 'data, T: Wrapper<'scope, 'data>>( +pub struct Ref<'scope, 'data, T: Managed<'scope, 'data>>( NonNull, PhantomData<&'scope ()>, PhantomData<&'data ()>, @@ -242,22 +244,22 @@ pub struct Ref<'scope, 'data, T: Wrapper<'scope, 'data>>( impl<'scope, 'data, T> Clone for Ref<'scope, 'data, T> where - T: Wrapper<'scope, 'data>, + T: Managed<'scope, 'data>, { fn clone(&self) -> Self { Ref(self.0, PhantomData, PhantomData) } } -impl<'scope, 'data, T> Copy for Ref<'scope, 'data, T> where T: Wrapper<'scope, 'data> {} +impl<'scope, 'data, T> Copy for Ref<'scope, 'data, T> where T: Managed<'scope, 'data> {} -impl<'scope, 'data, T: Wrapper<'scope, 'data>> Debug for Ref<'scope, 'data, T> { +impl<'scope, 'data, T: Managed<'scope, 'data>> Debug for Ref<'scope, 'data, T> { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { write!(f, "Ref<{}>", T::NAME) } } -impl<'scope, 'data, W: Wrapper<'scope, 'data>> Ref<'scope, 'data, W> { +impl<'scope, 'data, W: Managed<'scope, 'data>> Ref<'scope, 'data, W> { /// Use `target` to root this data. /// /// Safety: The data pointed to by `self` must not have been freed by the GC yet. @@ -280,8 +282,8 @@ impl<'scope, 'data, W: Wrapper<'scope, 'data>> Ref<'scope, 'data, W> { /// Safety: a reference is only guaranteed to be valid as long as it's reachable from some /// GC root. If the reference is unreachable, the GC can free it. The GC can run whenever a /// safepoint is reached, this is typically the case when new Julia data is allocated. - pub unsafe fn wrapper(self) -> W { - W::wrapper(self, Private) + pub unsafe fn as_managed(self) -> W { + W::wrap_non_null(self.ptr(), Private) } /// Assume the reference still points to valid Julia data and convert it to a `Value`. @@ -289,8 +291,8 @@ impl<'scope, 'data, W: Wrapper<'scope, 'data>> Ref<'scope, 'data, W> { /// Safety: a reference is only guaranteed to be valid as long as it's reachable from some /// GC root. If the reference is unreachable, the GC can free it. The GC can run whenever a /// safepoint is reached, this is typically the case when new Julia data is allocated. - pub unsafe fn value(self) -> Value<'scope, 'data> { - W::value(self, Private) + pub unsafe fn as_value(self) -> Value<'scope, 'data> { + Value::wrap_non_null(self.data_ptr().cast(), Private) } /// Leaks `self` with a `'static` lifetime. This method is only available when the `ccall` @@ -319,13 +321,13 @@ pub(crate) mod private { use std::{fmt::Debug, ptr::NonNull}; use crate::{ + data::managed::{value::Value, Ref}, private::Private, - wrappers::ptr::{value::Value, Ref}, }; - pub trait WrapperPriv<'scope, 'data>: Copy + Debug { + pub trait ManagedPriv<'scope, 'data>: Copy + Debug { type Wraps; - type TypeConstructorPriv<'target, 'da>: WrapperPriv<'target, 'da>; + type TypeConstructorPriv<'target, 'da>: ManagedPriv<'target, 'da>; const NAME: &'static str; // Safety: `inner` must point to valid data. If it is not @@ -344,32 +346,12 @@ pub(crate) mod private { fn unwrap(self, _: Private) -> *mut Self::Wraps { self.unwrap_non_null(Private).as_ptr() } - - #[inline(always)] - // Safety: value_ref must not have been freed yet and not be undefined, the wrapper can't - // be used after the data becomes unreachable. - unsafe fn wrapper(value_ref: Ref<'scope, 'data, Self>, _: Private) -> Self - where - Self: Sized + super::Wrapper<'scope, 'data>, - { - Self::wrap_non_null(value_ref.ptr(), Private) - } - - #[inline(always)] - // Safety: value_ref must not have been freed yet, the wrapper can't - // be used after the data becomes unreachable. - unsafe fn value(value_ref: Ref<'scope, 'data, Self>, _: Private) -> Value<'scope, 'data> - where - Self: Sized + super::Wrapper<'scope, 'data>, - { - Value::wrap_non_null(value_ref.ptr().cast(), Private) - } } - pub trait WrapperRef<'scope, 'data> {} + pub trait ManagedRef<'scope, 'data> {} - impl<'scope, 'data, T> WrapperRef<'scope, 'data> for Ref<'scope, 'data, T> where - T: WrapperPriv<'scope, 'data> + impl<'scope, 'data, T> ManagedRef<'scope, 'data> for Ref<'scope, 'data, T> where + T: ManagedPriv<'scope, 'data> { } } diff --git a/jlrs/src/wrappers/ptr/module.rs b/jlrs/src/data/managed/module.rs similarity index 96% rename from jlrs/src/wrappers/ptr/module.rs rename to jlrs/src/data/managed/module.rs index 45492981..666a28b1 100644 --- a/jlrs/src/wrappers/ptr/module.rs +++ b/jlrs/src/data/managed/module.rs @@ -1,4 +1,4 @@ -//! Wrapper for `Module`, which provides access to Julia's modules and their contents. +//! Managed for `Module`, which provides access to Julia's modules and their contents. //! //! In Julia, each module introduces a separate global scope. There are three important "root" //! modules, `Main`, `Base` and `Core`. Any Julia code that you include in jlrs is made available @@ -7,15 +7,8 @@ use std::{marker::PhantomData, ptr::NonNull}; use jl_sys::{ - jl_base_module, - jl_core_module, - jl_get_global, - jl_is_imported, - jl_main_module, - jl_module_t, - jl_module_type, - jl_set_const, - jl_set_global, + jl_base_module, jl_core_module, jl_get_global, jl_is_imported, jl_main_module, jl_module_t, + jl_module_type, jl_set_const, jl_set_global, }; use super::{ @@ -26,17 +19,17 @@ use super::{ use crate::{ call::Call, convert::to_symbol::ToSymbol, + data::managed::{ + function::Function, + private::ManagedPriv, + symbol::Symbol, + value::{leaked::LeakedValue, Value}, + Managed as _, + }, error::{AccessError, JlrsResult, TypeError}, impl_julia_typecheck, memory::target::Target, private::Private, - wrappers::ptr::{ - function::Function, - private::WrapperPriv, - symbol::Symbol, - value::{LeakedValue, Value}, - Wrapper as _, - }, }; /// Functionality in Julia can be accessed through its module system. You can get a handle to the @@ -346,7 +339,7 @@ impl<'scope> Module<'scope> { // Safety: the pointer points to valid data, the result is checked. unsafe { let symbol = name.to_symbol_priv(Private); - let func = self.global(&target, symbol)?.wrapper(); + let func = self.global(&target, symbol)?.as_managed(); if !func.is::() { let name = symbol.as_str().unwrap_or("").into(); @@ -387,7 +380,7 @@ impl<'scope> Module<'scope> { Module::base(&target) .function(&target, "require") .unwrap() - .wrapper() + .as_managed() .call2( target, self.as_value(), @@ -399,7 +392,7 @@ impl<'scope> Module<'scope> { impl_julia_typecheck!(Module<'target>, jl_module_type, 'target); impl_debug!(Module<'_>); -impl<'scope> WrapperPriv<'scope, '_> for Module<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for Module<'scope> { type Wraps = jl_module_t; type TypeConstructorPriv<'target, 'da> = Module<'target>; const NAME: &'static str = "Module"; diff --git a/jlrs/src/wrappers/ptr/simple_vector.rs b/jlrs/src/data/managed/simple_vector.rs similarity index 91% rename from jlrs/src/wrappers/ptr/simple_vector.rs rename to jlrs/src/data/managed/simple_vector.rs index 476af511..bd1ec20c 100644 --- a/jlrs/src/wrappers/ptr/simple_vector.rs +++ b/jlrs/src/data/managed/simple_vector.rs @@ -1,4 +1,4 @@ -//! Wrapper for `SimpleVector`. +//! Managed for `SimpleVector`. use std::{ fmt::{Debug, Formatter, Result as FmtResult}, @@ -7,24 +7,15 @@ use std::{ }; use jl_sys::{ - jl_alloc_svec, - jl_alloc_svec_uninit, - jl_emptysvec, - jl_gc_wb, - jl_svec_data, - jl_svec_t, + jl_alloc_svec, jl_alloc_svec_uninit, jl_emptysvec, jl_gc_wb, jl_svec_data, jl_svec_t, }; use super::{ - datatype::DataType, - private::WrapperPriv, - value::ValueRef, + datatype::DataType, private::ManagedPriv, value::ValueRef, Managed, ManagedRef, ManagedType, Ref, - Wrapper, - WrapperRef, - WrapperType, }; use crate::{ + data::managed::value::Value, error::{AccessError, JlrsResult}, layout::{ typecheck::Typecheck, @@ -32,7 +23,6 @@ use crate::{ }, memory::target::{unrooted::Unrooted, Target}, private::Private, - wrappers::ptr::value::Value, }; /// Access @@ -43,7 +33,7 @@ pub struct SimpleVectorContent<'scope, 'borrow, T = ValueRef<'scope, 'static>>( PhantomData<&'borrow [Option]>, ); -impl<'scope, 'borrow, T: WrapperRef<'scope, 'static>> SimpleVectorContent<'scope, 'borrow, T> { +impl<'scope, 'borrow, T: ManagedRef<'scope, 'static>> SimpleVectorContent<'scope, 'borrow, T> { /// Returns the length of this `SimpleVector`. pub fn len(&self) -> usize { // Safety: the pointer points to valid data @@ -65,9 +55,9 @@ pub struct SimpleVectorContentMut<'scope, 'borrow, T = ValueRef<'scope, 'static> PhantomData<&'borrow mut [Option]>, ) where - T: WrapperRef<'scope, 'static>; + T: ManagedRef<'scope, 'static>; -impl<'scope, 'borrow, T: WrapperRef<'scope, 'static>> SimpleVectorContentMut<'scope, 'borrow, T> { +impl<'scope, 'borrow, T: ManagedRef<'scope, 'static>> SimpleVectorContentMut<'scope, 'borrow, T> { /// Returns the length of this `SimpleVector`. pub fn len(&self) -> usize { // Safety: the pointer points to valid data @@ -88,7 +78,7 @@ impl<'scope, 'borrow, T: WrapperRef<'scope, 'static>> SimpleVectorContentMut<'sc pub unsafe fn set( &mut self, index: usize, - value: Option>, + value: Option>, ) -> JlrsResult<()> { if index >= self.len() { Err(AccessError::OutOfBoundsSVec { @@ -98,7 +88,7 @@ impl<'scope, 'borrow, T: WrapperRef<'scope, 'static>> SimpleVectorContentMut<'sc } jl_svec_data(self.0.as_ptr()) - .cast::>>() + .cast::>>() .add(index) .write(value); @@ -159,7 +149,7 @@ impl<'scope> SimpleVector<'scope> { &'borrow self, ) -> JlrsResult> where - U: WrapperRef<'scope, 'static>, + U: ManagedRef<'scope, 'static>, Option: ValidField, { if !self.is_typed::() { @@ -182,7 +172,7 @@ impl<'scope> SimpleVector<'scope> { &'borrow mut self, ) -> JlrsResult> where - U: WrapperRef<'scope, 'static>, + U: ManagedRef<'scope, 'static>, Option: ValidField, { if !self.is_typed::() { @@ -205,7 +195,7 @@ impl<'scope> SimpleVector<'scope> { &'borrow self, ) -> SimpleVectorContent<'scope, 'borrow, U> where - U: WrapperRef<'scope, 'static>, + U: ManagedRef<'scope, 'static>, { SimpleVectorContent(self.unwrap_non_null(Private), PhantomData, PhantomData) } @@ -217,14 +207,14 @@ impl<'scope> SimpleVector<'scope> { &'borrow mut self, ) -> SimpleVectorContentMut<'scope, 'borrow, U> where - U: WrapperRef<'scope, 'static>, + U: ManagedRef<'scope, 'static>, { SimpleVectorContentMut(self.unwrap_non_null(Private), PhantomData, PhantomData) } fn is_typed(self) -> bool where - U: WrapperRef<'scope, 'static>, + U: ManagedRef<'scope, 'static>, Option: ValidField, { // Safety: the pointer points to valid data @@ -237,7 +227,7 @@ impl<'scope> SimpleVector<'scope> { for element in slice.iter().copied() { match element { Some(value) => { - let value = value.value(); + let value = value.as_value(); if !Option::::valid_field(value.datatype().as_value()) { return false; } @@ -282,7 +272,7 @@ impl<'scope> Debug for SimpleVector<'scope> { } } -impl<'scope> WrapperPriv<'scope, '_> for SimpleVector<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for SimpleVector<'scope> { type Wraps = jl_svec_t; type TypeConstructorPriv<'target, 'da> = SimpleVector<'target>; const NAME: &'static str = "SimpleVector"; diff --git a/jlrs/src/wrappers/ptr/string.rs b/jlrs/src/data/managed/string.rs similarity index 96% rename from jlrs/src/wrappers/ptr/string.rs rename to jlrs/src/data/managed/string.rs index 2e4cb74e..f4757227 100644 --- a/jlrs/src/wrappers/ptr/string.rs +++ b/jlrs/src/data/managed/string.rs @@ -1,4 +1,4 @@ -//! Wrapper for `String`. +//! Managed for `String`. use std::{ ffi::CStr, @@ -14,11 +14,11 @@ use jl_sys::{jl_pchar_to_string, jl_string_type}; use super::Ref; use crate::{ convert::unbox::Unbox, + data::managed::{private::ManagedPriv, value::Value}, error::{JlrsError, JlrsResult}, impl_julia_typecheck, memory::target::Target, private::Private, - wrappers::ptr::{private::WrapperPriv, value::Value}, }; /// A Julia string. @@ -115,7 +115,7 @@ impl Debug for JuliaString<'_> { } } -impl<'scope> WrapperPriv<'scope, '_> for JuliaString<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for JuliaString<'scope> { type Wraps = u8; type TypeConstructorPriv<'target, 'da> = JuliaString<'target>; const NAME: &'static str = "String"; diff --git a/jlrs/src/wrappers/ptr/symbol.rs b/jlrs/src/data/managed/symbol.rs similarity index 96% rename from jlrs/src/wrappers/ptr/symbol.rs rename to jlrs/src/data/managed/symbol.rs index b16c05f9..a36aee48 100644 --- a/jlrs/src/wrappers/ptr/symbol.rs +++ b/jlrs/src/data/managed/symbol.rs @@ -1,4 +1,4 @@ -//! Wrapper for `Symbol`. Symbols represent identifiers like module and function names. +//! Managed for `Symbol`. Symbols represent identifiers like module and function names. #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] use std::mem::MaybeUninit; @@ -15,11 +15,11 @@ use super::Ref; #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] use crate::catch::catch_exceptions; use crate::{ + data::managed::{private::ManagedPriv, value::leaked::LeakedValue}, error::{JlrsError, JlrsResult}, impl_julia_typecheck, memory::target::Target, private::Private, - wrappers::ptr::{private::WrapperPriv, value::LeakedValue}, }; /// `Symbol`s are used Julia to represent identifiers, `:x` represents the `Symbol` `x`. Things @@ -90,7 +90,7 @@ impl<'scope> Symbol<'scope> { /// Extend the `Symbol`'s lifetime. A `Symbol` is never freed by the garbage collector, its /// lifetime can be safely extended. /// - /// [`Value`]: crate::wrappers::ptr::value::Value + /// [`Value`]: crate::data::managed::value::Value pub fn extend<'target, T>(self, _: &T) -> Symbol<'target> where T: Target<'target>, @@ -155,7 +155,7 @@ impl Hash for Symbol<'_> { impl_julia_typecheck!(Symbol<'scope>, jl_symbol_type, 'scope); impl_debug!(Symbol<'_>); -impl<'scope> WrapperPriv<'scope, '_> for Symbol<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for Symbol<'scope> { type Wraps = jl_sym_t; type TypeConstructorPriv<'target, 'da> = Symbol<'target>; const NAME: &'static str = "Symbol"; diff --git a/jlrs/src/wrappers/ptr/task.rs b/jlrs/src/data/managed/task.rs similarity index 96% rename from jlrs/src/wrappers/ptr/task.rs rename to jlrs/src/data/managed/task.rs index b4235bda..d307d657 100644 --- a/jlrs/src/wrappers/ptr/task.rs +++ b/jlrs/src/data/managed/task.rs @@ -1,4 +1,4 @@ -//! Wrapper for `Task`. +//! Managed for `Task`. //! //! The documentation for this module has been slightly adapted from the comments for this struct //! in [`julia.h`] @@ -14,11 +14,11 @@ use cfg_if::cfg_if; use jl_sys::{jl_task_t, jl_task_type}; use super::Ref; -use crate::{impl_julia_typecheck, private::Private, wrappers::ptr::private::WrapperPriv}; +use crate::{data::managed::private::ManagedPriv, impl_julia_typecheck, private::Private}; #[cfg(feature = "extra-fields")] use crate::{ + data::managed::value::{ValueData, ValueRef}, memory::target::Target, - wrappers::ptr::value::{ValueData, ValueRef}, }; /// A Julia `Task` (coroutine). @@ -188,7 +188,7 @@ impl<'scope> Task<'scope> { impl_julia_typecheck!(Task<'scope>, jl_task_type, 'scope); impl_debug!(Task<'_>); -impl<'scope> WrapperPriv<'scope, '_> for Task<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for Task<'scope> { type Wraps = jl_task_t; type TypeConstructorPriv<'target, 'da> = Task<'target>; const NAME: &'static str = "Task"; diff --git a/jlrs/src/wrappers/ptr/type_name.rs b/jlrs/src/data/managed/type_name.rs similarity index 95% rename from jlrs/src/wrappers/ptr/type_name.rs rename to jlrs/src/data/managed/type_name.rs index 6b8b7451..59806a99 100644 --- a/jlrs/src/wrappers/ptr/type_name.rs +++ b/jlrs/src/data/managed/type_name.rs @@ -1,4 +1,4 @@ -//! Wrapper for `TypeName`. +//! Managed for `TypeName`. //! //! The documentation for this module has been slightly adapted from the comments for this struct //! in [`julia.h`] @@ -9,34 +9,23 @@ use std::{marker::PhantomData, ptr::NonNull}; use cfg_if::cfg_if; use jl_sys::{ - jl_array_typename, - jl_llvmpointer_typename, - jl_namedtuple_typename, - jl_pointer_typename, - jl_tuple_typename, - jl_type_typename, - jl_typename_t, - jl_typename_type, - jl_vecelement_typename, + jl_array_typename, jl_llvmpointer_typename, jl_namedtuple_typename, jl_pointer_typename, + jl_tuple_typename, jl_type_typename, jl_typename_t, jl_typename_type, jl_vecelement_typename, }; use super::Ref; use crate::{ + data::managed::{ + module::Module, private::ManagedPriv, simple_vector::SimpleVector, symbol::Symbol, + }, impl_julia_typecheck, memory::target::Target, private::Private, - wrappers::ptr::{ - module::Module, - private::WrapperPriv, - simple_vector::SimpleVector, - symbol::Symbol, - }, }; cfg_if! { if #[cfg(feature = "julia-1-6")] { use jl_sys::jl_vararg_typename; - } else { use jl_sys::{jl_opaque_closure_typename}; } @@ -44,14 +33,14 @@ cfg_if! { cfg_if! { if #[cfg(feature = "extra-fields")] { - use crate::wrappers::ptr::{value::Value, simple_vector::{SimpleVectorRef, SimpleVectorData}}; + use crate::data::managed::{value::Value, simple_vector::{SimpleVectorRef, SimpleVectorData}}; } } cfg_if! { if #[cfg(all(not(feature = "julia-1-6"), feature = "extra-fields"))] { use std::sync::atomic::Ordering; - use crate::wrappers::ptr::value::{ValueData, ValueRef}; + use crate::data::managed::value::{ValueData, ValueRef}; } } @@ -362,7 +351,7 @@ impl<'base> TypeName<'base> { impl_julia_typecheck!(TypeName<'scope>, jl_typename_type, 'scope); impl_debug!(TypeName<'_>); -impl<'scope> WrapperPriv<'scope, '_> for TypeName<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for TypeName<'scope> { type Wraps = jl_typename_t; type TypeConstructorPriv<'target, 'da> = TypeName<'target>; const NAME: &'static str = "TypeName"; diff --git a/jlrs/src/wrappers/ptr/type_var.rs b/jlrs/src/data/managed/type_var.rs similarity index 97% rename from jlrs/src/wrappers/ptr/type_var.rs rename to jlrs/src/data/managed/type_var.rs index 10874a6f..649acb93 100644 --- a/jlrs/src/wrappers/ptr/type_var.rs +++ b/jlrs/src/data/managed/type_var.rs @@ -1,4 +1,4 @@ -//! Wrapper for `TypeVar`. +//! Managed for `TypeVar`. use std::{marker::PhantomData, ptr::NonNull}; @@ -7,16 +7,16 @@ use jl_sys::{jl_new_typevar, jl_tvar_t, jl_tvar_type}; use super::{value::ValueData, Ref}; use crate::{ convert::to_symbol::ToSymbol, - impl_julia_typecheck, - memory::target::Target, - private::Private, - wrappers::ptr::{ + data::managed::{ datatype::DataType, - private::WrapperPriv, + private::ManagedPriv, symbol::Symbol, value::{Value, ValueRef}, - Wrapper, + Managed, }, + impl_julia_typecheck, + memory::target::Target, + private::Private, }; /// An unknown, but possibly restricted, type parameter. In `Array{T, N}`, `T` and `N` are @@ -138,7 +138,7 @@ impl<'scope> TypeVar<'scope> { impl_julia_typecheck!(TypeVar<'scope>, jl_tvar_type, 'scope); impl_debug!(TypeVar<'_>); -impl<'scope> WrapperPriv<'scope, '_> for TypeVar<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for TypeVar<'scope> { type Wraps = jl_tvar_t; type TypeConstructorPriv<'target, 'da> = TypeVar<'target>; const NAME: &'static str = "TypeVar"; diff --git a/jlrs/src/wrappers/ptr/union.rs b/jlrs/src/data/managed/union.rs similarity index 95% rename from jlrs/src/wrappers/ptr/union.rs rename to jlrs/src/data/managed/union.rs index 519be8bd..9ba1758a 100644 --- a/jlrs/src/wrappers/ptr/union.rs +++ b/jlrs/src/data/managed/union.rs @@ -1,4 +1,4 @@ -//! Wrapper for `Union`. +//! Managed for `Union`. use std::{marker::PhantomData, ptr::NonNull}; @@ -8,10 +8,10 @@ use jl_sys::{jl_islayout_inline, jl_type_union, jl_uniontype_t, jl_uniontype_typ use super::value::ValueResult; use super::{value::ValueData, Ref}; use crate::{ + data::managed::{private::ManagedPriv, value::Value, Managed}, impl_julia_typecheck, memory::target::Target, private::Private, - wrappers::ptr::{private::WrapperPriv, value::Value, Wrapper}, }; /// A struct field can have a type that's a union of several types. In this case, the type of this @@ -27,8 +27,8 @@ impl<'scope> Union<'scope> { /// /// If an exception is thrown, it's caught and returned. /// - /// [`Union`]: crate::wrappers::ptr::union::Union - /// [`DataType`]: crate::wrappers::ptr::datatype::DataType + /// [`Union`]: crate::data::managed::union::Union + /// [`DataType`]: crate::data::managed::datatype::DataType #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] pub fn new<'target, V, T>(target: T, types: V) -> ValueResult<'target, 'static, T> where @@ -69,8 +69,8 @@ impl<'scope> Union<'scope> { /// Safety: an exception must not be thrown if this method is called from a `ccall`ed /// function. /// - /// [`Union`]: crate::wrappers::ptr::union::Union - /// [`DataType`]: crate::wrappers::ptr::datatype::DataType + /// [`Union`]: crate::data::managed::union::Union + /// [`DataType`]: crate::data::managed::datatype::DataType pub unsafe fn new_unchecked<'target, V, T>( target: T, types: V, @@ -150,7 +150,7 @@ impl<'scope> Union<'scope> { impl_julia_typecheck!(Union<'scope>, jl_uniontype_type, 'scope); impl_debug!(Union<'_>); -impl<'scope> WrapperPriv<'scope, '_> for Union<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for Union<'scope> { type Wraps = jl_uniontype_t; type TypeConstructorPriv<'target, 'da> = Union<'target>; const NAME: &'static str = "Union"; diff --git a/jlrs/src/wrappers/ptr/union_all.rs b/jlrs/src/data/managed/union_all.rs similarity index 94% rename from jlrs/src/wrappers/ptr/union_all.rs rename to jlrs/src/data/managed/union_all.rs index 58159546..bb52b93b 100644 --- a/jlrs/src/wrappers/ptr/union_all.rs +++ b/jlrs/src/data/managed/union_all.rs @@ -1,26 +1,17 @@ -//! Wrapper for `UnionAll`, A union of types over all values of a type parameter. +//! Managed for `UnionAll`, A union of types over all values of a type parameter. use cfg_if::cfg_if; use jl_sys::{ - jl_abstractarray_type, - jl_anytuple_type_type, - jl_array_type, - jl_densearray_type, - jl_llvmpointer_type, - jl_namedtuple_type, - jl_pointer_type, - jl_ref_type, - jl_type_type, - jl_type_unionall, - jl_unionall_t, - jl_unionall_type, + jl_abstractarray_type, jl_anytuple_type_type, jl_array_type, jl_densearray_type, + jl_llvmpointer_type, jl_namedtuple_type, jl_pointer_type, jl_ref_type, jl_type_type, + jl_type_unionall, jl_unionall_t, jl_unionall_type, }; use crate::{ + data::managed::{datatype::DataType, private::ManagedPriv, type_var::TypeVar, value::Value}, impl_julia_typecheck, memory::target::Target, private::Private, - wrappers::ptr::{datatype::DataType, private::WrapperPriv, type_var::TypeVar, value::Value}, }; cfg_if! { @@ -240,7 +231,7 @@ impl<'base> UnionAll<'base> { impl_julia_typecheck!(UnionAll<'scope>, jl_unionall_type, 'scope); impl_debug!(UnionAll<'_>); -impl<'scope> WrapperPriv<'scope, '_> for UnionAll<'scope> { +impl<'scope> ManagedPriv<'scope, '_> for UnionAll<'scope> { type Wraps = jl_unionall_t; type TypeConstructorPriv<'target, 'da> = UnionAll<'target>; const NAME: &'static str = "UnionAll"; diff --git a/jlrs/src/data/managed/value/field_accessor.rs b/jlrs/src/data/managed/value/field_accessor.rs new file mode 100644 index 00000000..dd125369 --- /dev/null +++ b/jlrs/src/data/managed/value/field_accessor.rs @@ -0,0 +1,757 @@ +use std::{mem::MaybeUninit, ptr::NonNull, sync::atomic::Ordering, usize}; + +use cfg_if::cfg_if; +use jl_sys::{jl_array_typetagdata, jl_value_t}; + +use super::{Value, ValueRef}; +use crate::{ + data::managed::{ + array::Array, + datatype::{DataType, DataTypeRef}, + private::ManagedPriv, + union::{nth_union_component, Union}, + Managed, + }, + error::{AccessError, JlrsResult, CANNOT_DISPLAY_TYPE}, + layout::{field_index::FieldIndex, valid_layout::ValidLayout}, + memory::target::unrooted::Unrooted, + private::Private, +}; + +cfg_if! { + if #[cfg(not(feature = "julia-1-6"))] { + use jl_sys::{jlrs_lock, jlrs_unlock}; + + use std::{ + ptr::null_mut, + sync::atomic::{AtomicPtr, AtomicU16, AtomicU32, AtomicU64, AtomicU8}, + }; + } +} + +#[repr(C)] +#[derive(Clone, Copy)] +#[cfg(not(feature = "julia-1-6"))] +union AtomicBuffer { + bytes: [MaybeUninit; 8], + ptr: *mut jl_value_t, +} + +#[cfg(not(feature = "julia-1-6"))] +impl AtomicBuffer { + fn new() -> Self { + AtomicBuffer { ptr: null_mut() } + } +} + +#[derive(Copy, Clone, PartialEq)] +enum ViewState { + #[cfg(not(feature = "julia-1-6"))] + Locked, + Unlocked, + #[cfg(not(feature = "julia-1-6"))] + AtomicBuffer, + Array, +} + +// TODO: track + +/// Access the raw contents of a Julia value. +/// +/// A `FieldAccessor` for a value can be created with [`Value::field_accessor`]. By chaining calls +/// to the `field` and `atomic_field` methods you can access deeply nested fields without +/// allocating temporary Julia data. These two methods support three kinds of field identifiers: +/// field names, numerical field indices, and n-dimensional array indices. The first two can be +/// used with types that have named fields, the second must be used with tuples, and the last one +/// with arrays. +pub struct FieldAccessor<'scope, 'data> { + value: Option>, + current_field_type: Option>, + #[cfg(not(feature = "julia-1-6"))] + buffer: AtomicBuffer, + offset: u32, + state: ViewState, +} + +impl<'scope, 'data> FieldAccessor<'scope, 'data> { + pub(crate) fn new(value: Value<'scope, 'data>) -> Self { + FieldAccessor { + value: Some(value.as_ref()), + current_field_type: Some(value.datatype().as_ref()), + offset: 0, + #[cfg(not(feature = "julia-1-6"))] + buffer: AtomicBuffer::new(), + state: ViewState::Unlocked, + } + } + /// Access the field the accessor is currenty pointing to as a value of type `T`. + /// + /// This method accesses the field using its concrete type. If the concrete type of the field + /// has a matching pointer wrapper type it can be accessed as a `ValueRef` or a `Ref` of to + /// that pointer wrapper type. For example, a field that contains a `Module` can be accessed + /// as a `ModuleRef`. In all other cases an inline wrapper type must be used. For example, an + /// untyped field that currently holds a `Float64` must be accessed as `f64`. + pub fn access(self) -> JlrsResult { + if self.current_field_type.is_none() { + Err(AccessError::UndefRef)?; + } + + if self.value.is_none() { + Err(AccessError::UndefRef)?; + } + + // Safety: in this block, the first check ensures that T is correct + // for the data that is accessed. If the data is in the atomic buffer + // it's read from there. If T is as Ref, the pointer is converted. If + // it's an array, the element at the desired position is read. + // Otherwise, the field is read at the offset where it has been determined + // to be stored. + unsafe { + let ty = self.current_field_type.unwrap().as_value(); + if !T::valid_layout(ty) { + let value_type = ty.display_string_or(CANNOT_DISPLAY_TYPE).into(); + Err(AccessError::InvalidLayout { value_type })?; + } + + #[cfg(not(feature = "julia-1-6"))] + if self.state == ViewState::AtomicBuffer { + debug_assert!(!T::IS_REF); + debug_assert!(std::mem::size_of::() <= 8); + return Ok(std::ptr::read( + self.buffer.bytes[self.offset as usize..].as_ptr() as *const T, + )); + } + + if T::IS_REF { + Ok(std::mem::transmute_copy(&self.value)) + } else if self.state == ViewState::Array { + Ok(self + .value + .unwrap() + .as_value() + .cast_unchecked::() + .data_ptr() + .cast::() + .add(self.offset as usize) + .cast::() + .read()) + } else { + Ok(self + .value + .unwrap() + .ptr() + .cast::() + .as_ptr() + .add(self.offset as usize) + .cast::() + .read()) + } + } + } + + /// Returns `true` if `self.access::()` will succeed, `false` if it will fail. + pub fn can_access_as(&self) -> bool { + if self.current_field_type.is_none() { + return false; + } + + // Safety: the current_field_type field is not undefined. + let ty = unsafe { self.current_field_type.unwrap().as_value() }; + if !T::valid_layout(ty) { + return false; + } + + true + } + + /// Update the accessor to point to `field`. + /// + /// Three kinds of field indices exist: field names, numerical field indices, and + /// n-dimensional array indices. The first two can be used with types that have named fields, + /// the second must be used with tuples, and the last one with arrays. + /// + /// If `field` is an invalid identifier an error is returned. Calls to `field` can be chained + /// to access nested fields. + /// + /// If the field is an atomic field the same ordering is used as Julia uses by default: + /// `Relaxed` for pointer fields, `SeqCst` for small inline fields, and a lock for large + /// inline fields. + pub fn field(mut self, field: F) -> JlrsResult { + if self.value.is_none() { + Err(AccessError::UndefRef)? + } + + if self.current_field_type.is_none() { + Err(AccessError::UndefRef)? + } + + // Safety: how to access the next field depends on the current view. If an array + // is accessed the view is updated to the requested element. Otherwise, the offset + // is adjusted to target the requested field. Because the starting point is assumed + // to be rooted, all pointer fields are either reachablle or undefined. If a field is + // atomic, atomic accesses (or locks for large atomic fields) are used. + unsafe { + let current_field_type = self.current_field_type.unwrap().as_managed(); + if self.state == ViewState::Array && current_field_type.is::() { + let arr = self.value.unwrap().as_value().cast_unchecked::(); + // accessing an array, find the offset of the requested element + let index = field.array_index(arr, Private)?; + self.get_array_field(arr, index); + return Ok(self); + } + + let index = field.field_index(current_field_type, Private)?; + let global = Unrooted::new(); + + let next_field_type = match current_field_type.field_type_unchecked(global, index) { + Some(ty) => ty, + _ => Err(AccessError::UndefRef)?, + }; + + let next_field_type = next_field_type.as_managed(); + let is_pointer_field = current_field_type.is_pointer_field_unchecked(index); + let field_offset = current_field_type.field_offset_unchecked(index); + self.offset += field_offset; + + match self.state { + ViewState::Array => { + self.get_inline_array_field(is_pointer_field, next_field_type)? + } + ViewState::Unlocked => self.get_unlocked_inline_field( + is_pointer_field, + current_field_type, + next_field_type, + index, + Ordering::Relaxed, + Ordering::SeqCst, + ), + #[cfg(not(feature = "julia-1-6"))] + ViewState::Locked => { + self.get_locked_inline_field(is_pointer_field, next_field_type) + } + #[cfg(not(feature = "julia-1-6"))] + ViewState::AtomicBuffer => { + self.get_atomic_buffer_field(is_pointer_field, next_field_type) + } + } + } + + Ok(self) + } + + /// Update the accessor to point to `field`. + /// + /// If the field is a small atomic field `ordering` is used to read it. The ordering is + /// ignored for non-atomic fields and fields that require a lock to access. See + /// [`FieldAccessor::field`] for more information. + #[cfg(not(feature = "julia-1-6"))] + pub fn atomic_field(mut self, field: F, ordering: Ordering) -> JlrsResult { + if self.value.is_none() { + Err(AccessError::UndefRef)? + } + + if self.current_field_type.is_none() { + Err(AccessError::UndefRef)? + } + + // Safety: how to access the next field depends on the current view. If an array + // is accessed the view is updated to the requested element. Otherwise, the offset + // is adjusted to target the requested field. Because the starting point is assumed + // to be rooted, all pointer fields are either reachablle or undefined. If a field is + // atomic, atomic accesses (or locks for large atomic fields) are used. + unsafe { + let current_field_type = self.current_field_type.unwrap().as_managed(); + if self.state == ViewState::Array && current_field_type.is::() { + let arr = self.value.unwrap().as_value().cast_unchecked::(); + // accessing an array, find the offset of the requested element + let index = field.array_index(arr, Private)?; + self.get_array_field(arr, index); + return Ok(self); + } + + let index = field.field_index(current_field_type, Private)?; + let global = Unrooted::new(); + + let next_field_type = match current_field_type.field_type_unchecked(global, index) { + Some(ty) => ty, + _ => Err(AccessError::UndefRef)?, + }; + + let next_field_type = next_field_type.as_managed(); + let is_pointer_field = current_field_type.is_pointer_field_unchecked(index); + let field_offset = current_field_type.field_offset_unchecked(index); + self.offset += field_offset; + + match self.state { + ViewState::Array => { + self.get_inline_array_field(is_pointer_field, next_field_type)? + } + ViewState::Unlocked => self.get_unlocked_inline_field( + is_pointer_field, + current_field_type, + next_field_type, + index, + ordering, + ordering, + ), + ViewState::Locked => { + self.get_locked_inline_field(is_pointer_field, next_field_type) + } + ViewState::AtomicBuffer => { + self.get_atomic_buffer_field(is_pointer_field, next_field_type) + } + } + } + + Ok(self) + } + + /// Try to clone this accessor and its state. + /// + /// If the current value this accessor is accessing is locked an error is returned. + pub fn try_clone(&self) -> JlrsResult { + #[cfg(not(feature = "julia-1-6"))] + if self.state == ViewState::Locked { + Err(AccessError::Locked)?; + } + + Ok(FieldAccessor { + value: self.value, + current_field_type: self.current_field_type, + offset: self.offset, + #[cfg(not(feature = "julia-1-6"))] + buffer: self.buffer.clone(), + state: self.state, + }) + } + + /// Returns `true` if the current value the accessor is accessing is locked. + #[cfg(not(feature = "julia-1-6"))] + pub fn is_locked(&self) -> bool { + self.state == ViewState::Locked + } + + /// Returns `true` if the current value the accessor is accessing is locked. + #[cfg(feature = "julia-1-6")] + pub fn is_locked(&self) -> bool { + false + } + + /// Returns the type of the field the accessor is currently pointing at. + pub fn current_field_type(&self) -> Option> { + self.current_field_type + } + + /// Returns the value the accessor is currently inspecting. + pub fn value(&self) -> Option> { + self.value + } + + #[cfg(not(feature = "julia-1-6"))] + // Safety: the view state must be ViewState::AtomicBuffer + unsafe fn get_atomic_buffer_field( + &mut self, + is_pointer_field: bool, + next_field_type: Value<'scope, 'data>, + ) { + if is_pointer_field { + debug_assert_eq!(self.offset, 0); + let ptr = self.buffer.ptr; + if ptr.is_null() { + self.value = None; + } else { + self.value = Some(ValueRef::wrap(NonNull::new_unchecked(ptr))); + } + + self.state = ViewState::Unlocked; + if self.value.is_none() { + if let Ok(ty) = next_field_type.cast::() { + if ty.is_concrete_type() { + self.current_field_type = Some(ty.as_ref()); + } else { + self.current_field_type = None; + } + } else { + self.current_field_type = None; + } + } else { + self.current_field_type = + Some(self.value.unwrap().as_managed().datatype().as_ref()); + } + } else { + debug_assert!(next_field_type.is::()); + self.current_field_type = Some(next_field_type.cast_unchecked::().as_ref()); + } + } + + // Safety: the view state must be ViewState::Unlocked + #[cfg(not(feature = "julia-1-6"))] + unsafe fn get_unlocked_inline_field( + &mut self, + is_pointer_field: bool, + current_field_type: DataType<'scope>, + next_field_type: Value<'scope, 'data>, + index: usize, + pointer_ordering: Ordering, + inline_ordering: Ordering, + ) { + let is_atomic_field = current_field_type.is_atomic_field_unchecked(index); + if is_pointer_field { + if is_atomic_field { + self.get_atomic_pointer_field(next_field_type, pointer_ordering); + } else { + self.get_pointer_field(false, next_field_type); + } + } else if let Ok(un) = next_field_type.cast::() { + self.get_bits_union_field(un); + } else { + debug_assert!(next_field_type.is::()); + self.current_field_type = Some(next_field_type.cast_unchecked::().as_ref()); + + if is_atomic_field { + self.lock_or_copy_atomic(inline_ordering); + } + } + } + + // Safety: the view state must be ViewState::Unlocked + #[cfg(feature = "julia-1-6")] + unsafe fn get_unlocked_inline_field( + &mut self, + is_pointer_field: bool, + _current_field_type: DataType<'scope>, + next_field_type: Value<'scope, 'data>, + _index: usize, + _pointer_ordering: Ordering, + _inline_ordering: Ordering, + ) { + if is_pointer_field { + self.get_pointer_field(false, next_field_type); + } else if let Ok(un) = next_field_type.cast::() { + self.get_bits_union_field(un); + } else { + debug_assert!(next_field_type.is::()); + self.current_field_type = Some(next_field_type.cast_unchecked::().as_ref()); + } + } + + // Safety: the view state must be ViewState::Locked + #[cfg(not(feature = "julia-1-6"))] + unsafe fn get_locked_inline_field( + &mut self, + is_pointer_field: bool, + next_field_type: Value<'scope, 'data>, + ) { + if is_pointer_field { + self.get_pointer_field(true, next_field_type); + } else if let Ok(un) = next_field_type.cast::() { + self.get_bits_union_field(un); + } else { + debug_assert!(next_field_type.is::()); + self.current_field_type = Some(next_field_type.cast_unchecked::().as_ref()); + } + } + + // Safety: the view state must be ViewState::Array + unsafe fn get_inline_array_field( + &mut self, + is_pointer_field: bool, + next_field_type: Value<'scope, 'data>, + ) -> JlrsResult<()> { + // Inline field of the current array + if is_pointer_field { + self.value = self + .value + .unwrap() + .as_value() + .cast::()? + .data_ptr() + .cast::>() + .add(self.offset as usize) + .cast::>() + .read(); + + self.offset = 0; + self.state = ViewState::Unlocked; + + if self.value.is_none() { + if let Ok(ty) = next_field_type.cast::() { + if ty.is_concrete_type() { + self.current_field_type = Some(ty.as_ref()); + } else { + self.current_field_type = None; + } + } else { + self.current_field_type = None; + } + } else { + self.current_field_type = Some(self.value.unwrap().as_value().datatype().as_ref()); + } + } else { + self.current_field_type = Some(next_field_type.cast::()?.as_ref()); + } + + Ok(()) + } + + #[cfg(not(feature = "julia-1-6"))] + // Safety: must only be used to read an atomic field + unsafe fn lock_or_copy_atomic(&mut self, ordering: Ordering) { + let ptr = self + .value + .unwrap() + .ptr() + .cast::>() + .as_ptr() + .add(self.offset as usize); + + match self.current_field_type.unwrap().as_managed().size() { + 0 => (), + 1 => { + let atomic = &*ptr.cast::(); + let v = atomic.load(ordering); + let dst_ptr = self.buffer.bytes.as_mut_ptr(); + std::ptr::copy_nonoverlapping(&v as *const _ as *const u8, dst_ptr as _, 1); + self.state = ViewState::AtomicBuffer; + self.offset = 0; + } + 2 => { + let atomic = &*ptr.cast::(); + let v = atomic.load(ordering); + let dst_ptr = self.buffer.bytes.as_mut_ptr(); + std::ptr::copy_nonoverlapping(&v as *const _ as *const u8, dst_ptr as _, 2); + self.state = ViewState::AtomicBuffer; + self.offset = 0; + } + sz if sz <= 4 => { + let atomic = &*ptr.cast::(); + let v = atomic.load(ordering); + let dst_ptr = self.buffer.bytes.as_mut_ptr(); + std::ptr::copy_nonoverlapping( + &v as *const _ as *const u8, + dst_ptr as _, + sz as usize, + ); + self.state = ViewState::AtomicBuffer; + self.offset = 0; + } + sz if sz <= 8 => { + let atomic = &*ptr.cast::(); + let v = atomic.load(ordering); + let dst_ptr = self.buffer.bytes.as_mut_ptr(); + std::ptr::copy_nonoverlapping( + &v as *const _ as *const u8, + dst_ptr as _, + sz as usize, + ); + self.state = ViewState::AtomicBuffer; + self.offset = 0; + } + _ => { + jlrs_lock(self.value.unwrap().ptr().as_ptr()); + self.state = ViewState::Locked; + } + } + } + + // Safety: must only be used to read an array element + unsafe fn get_array_field(&mut self, arr: Array<'scope, 'data>, index: usize) { + debug_assert!(self.state == ViewState::Array); + let el_size = arr.element_size(); + self.offset = (index * el_size) as u32; + + if arr.is_value_array() { + self.value = arr.data_ptr().cast::>().add(index).read(); + self.offset = 0; + if self.value.is_none() { + if let Ok(ty) = arr.element_type().cast::() { + if ty.is_concrete_type() { + self.current_field_type = Some(ty.as_ref()); + } else { + self.current_field_type = None; + } + + if !ty.is::() { + self.state = ViewState::Unlocked; + } + } else { + self.current_field_type = None; + self.state = ViewState::Unlocked; + } + } else { + let ty = self.value.unwrap().as_value().datatype(); + self.current_field_type = Some(ty.as_ref()); + if !ty.is::() { + self.state = ViewState::Unlocked; + } + } + } else if arr.is_union_array() { + let mut tag = *jl_array_typetagdata(arr.unwrap(Private)).add(index) as i32; + let component = nth_union_component(arr.element_type(), &mut tag); + debug_assert!(component.is_some()); + let ty = component.unwrap_unchecked(); + debug_assert!(ty.is::()); + let ty = ty.cast_unchecked::(); + debug_assert!(ty.is_concrete_type()); + self.current_field_type = Some(ty.as_ref()); + } else { + let ty = arr.element_type(); + debug_assert!(ty.is::()); + self.current_field_type = Some(ty.cast_unchecked::().as_ref()); + } + } + + #[cfg(not(feature = "julia-1-6"))] + // Safety: must only be used to read an pointer field + unsafe fn get_pointer_field(&mut self, locked: bool, next_field_type: Value<'scope, 'data>) { + let value = self + .value + .unwrap() + .ptr() + .cast::() + .as_ptr() + .add(self.offset as usize) + .cast::>() + .read(); + + if locked { + jlrs_unlock(self.value.unwrap().ptr().as_ptr()); + self.state = ViewState::Unlocked; + } + + self.value = value; + self.offset = 0; + + if self.value.is_none() { + if let Ok(ty) = next_field_type.cast::() { + if ty.is_concrete_type() { + self.current_field_type = Some(ty.as_ref()); + } else { + self.current_field_type = None; + } + } else { + self.current_field_type = None; + } + } else { + let value = self.value.unwrap().as_value(); + self.current_field_type = Some(value.datatype().as_ref()); + if value.is::() { + self.state = ViewState::Array; + } + } + } + + #[cfg(feature = "julia-1-6")] + // Safety: must only be used to read an pointer field + unsafe fn get_pointer_field(&mut self, _locked: bool, next_field_type: Value<'scope, 'data>) { + self.value = self + .value + .unwrap() + .ptr() + .cast::() + .as_ptr() + .add(self.offset as usize) + .cast::>() + .read(); + + self.offset = 0; + + if self.value.is_none() { + if let Ok(ty) = next_field_type.cast::() { + if ty.is_concrete_type() { + self.current_field_type = Some(ty.as_ref()); + } else { + self.current_field_type = None; + } + } else { + self.current_field_type = None; + } + } else { + let value = self.value.unwrap().as_value(); + self.current_field_type = Some(value.datatype().as_ref()); + if value.is::() { + self.state = ViewState::Array; + } + } + } + + #[cfg(not(feature = "julia-1-6"))] + // Safety: must only be used to read an atomic pointer field + unsafe fn get_atomic_pointer_field( + &mut self, + next_field_type: Value<'scope, 'data>, + ordering: Ordering, + ) { + let v = &*self + .value + .unwrap() + .ptr() + .cast::() + .as_ptr() + .add(self.offset as usize) + .cast::>(); + + let ptr = v.load(ordering); + if ptr.is_null() { + self.value = None; + } else { + self.value = Some(ValueRef::wrap(NonNull::new_unchecked(ptr))); + } + + self.offset = 0; + + if self.value.is_none() { + if let Ok(ty) = next_field_type.cast::() { + if ty.is_concrete_type() { + self.current_field_type = Some(ty.as_ref()); + } else { + self.current_field_type = None; + } + } else { + self.current_field_type = None; + } + } else { + let value = self.value.unwrap().as_value(); + self.current_field_type = Some(value.datatype().as_ref()); + if value.is::() { + self.state = ViewState::Array; + } + } + } + + // Safety: must only be used to read a bits union field + unsafe fn get_bits_union_field(&mut self, union: Union<'scope>) { + let mut size = 0; + let isbits = union.isbits_size_align(&mut size, &mut 0); + debug_assert!(isbits); + let flag_offset = self.offset as usize + size; + let mut flag = self + .value + .unwrap() + .ptr() + .cast::() + .as_ptr() + .add(flag_offset) + .read() as i32; + + let active_ty = nth_union_component(union.as_value(), &mut flag); + debug_assert!(active_ty.is_some()); + let active_ty = active_ty.unwrap_unchecked(); + debug_assert!(active_ty.is::()); + + let ty = active_ty.cast_unchecked::(); + debug_assert!(ty.is_concrete_type()); + self.current_field_type = Some(ty.as_ref()); + } +} + +impl Drop for FieldAccessor<'_, '_> { + fn drop(&mut self) { + #[cfg(not(feature = "julia-1-6"))] + if self.state == ViewState::Locked { + debug_assert!(!self.value.is_none()); + // Safety: the value is currently locked. + unsafe { jlrs_unlock(self.value.unwrap().ptr().as_ptr()) } + } + } +} diff --git a/jlrs/src/data/managed/value/leaked.rs b/jlrs/src/data/managed/value/leaked.rs new file mode 100644 index 00000000..076f3a4b --- /dev/null +++ b/jlrs/src/data/managed/value/leaked.rs @@ -0,0 +1,29 @@ +use std::ptr::NonNull; + +use jl_sys::jl_value_t; + +use super::Value; +use crate::{data::managed::private::ManagedPriv, memory::target::Target, private::Private}; + +/// While jlrs generally enforces that Julia data can only exist and be used while a frame is +/// active, it's possible to leak global values: [`Symbol`]s, [`Module`]s, and globals defined in +/// those modules. +#[derive(Copy, Clone)] +pub struct LeakedValue(Value<'static, 'static>); + +impl LeakedValue { + // Safety: ptr must point to valid Julia data + pub(crate) unsafe fn wrap_non_null(ptr: NonNull) -> Self { + LeakedValue(Value::wrap_non_null(ptr, Private)) + } + + /// Convert this [`LeakedValue`] back to a [`Value`]. This requires an [`Unrooted`], so this + /// method can only be called inside a closure taken by one of the `scope`-methods. + /// + /// Safety: you must guarantee this value has not been freed by the garbage collector. While + /// `Symbol`s are never garbage collected, modules and their contents can be redefined. + #[inline(always)] + pub unsafe fn as_value<'scope, T: Target<'scope>>(self, _: &T) -> Value<'scope, 'static> { + self.0 + } +} diff --git a/jlrs/src/wrappers/ptr/value.rs b/jlrs/src/data/managed/value/mod.rs similarity index 62% rename from jlrs/src/wrappers/ptr/value.rs rename to jlrs/src/data/managed/value/mod.rs index e5a7b076..9777ab3a 100644 --- a/jlrs/src/wrappers/ptr/value.rs +++ b/jlrs/src/data/managed/value/mod.rs @@ -1,4 +1,4 @@ -//! Wrapper for arbitrary Julia data. +//! Managed for arbitrary Julia data. //! //! Julia data returned by the C API is often returned as a pointer to `jl_value_t`, which is //! an opaque type. This pointer is wrapped in jlrs by [`Value`]. The layout of the data that is @@ -20,9 +20,13 @@ //! order to call functions with keyword arguments. The macro [`named_tuple`] is defined in this //! module which provides an easy way to create values of this type. //! -//! [`TypedArray`]: crate::wrappers::ptr::array::TypedArray +//! [`TypedArray`]: crate::data::managed::array::TypedArray //! [`named_tuple`]: crate::named_tuple! +pub mod field_accessor; +pub mod leaked; +pub mod tracked; + #[doc(hidden)] #[macro_export] macro_rules! count { @@ -69,13 +73,13 @@ macro_rules! count { #[macro_export] macro_rules! named_tuple { ($frame:expr, $name:expr => $value:expr) => { - $crate::wrappers::ptr::value::Value::new_named_tuple($frame, &mut [$name], &mut [$value]).expect("Invalid use of named_tuple!") + $crate::data::managed::value::Value::new_named_tuple($frame, &mut [$name], &mut [$value]).expect("Invalid use of named_tuple!") }; ($frame:expr, $name:expr => $value:expr, $($rest:tt)+) => { { let n = $crate::count!($($rest)+); - let mut names = ::smallvec::SmallVec::<[_; $crate::wrappers::ptr::value::MAX_SIZE]>::with_capacity(n); - let mut values = ::smallvec::SmallVec::<[_; $crate::wrappers::ptr::value::MAX_SIZE]>::with_capacity(n); + let mut names = ::smallvec::SmallVec::<[_; $crate::data::managed::value::MAX_SIZE]>::with_capacity(n); + let mut values = ::smallvec::SmallVec::<[_; $crate::data::managed::value::MAX_SIZE]>::with_capacity(n); names.push($name); values.push($value); @@ -93,7 +97,7 @@ macro_rules! named_tuple { { $names.push($name); $values.push($value); - $crate::wrappers::ptr::value::Value::new_named_tuple($frame, $names, $values).expect("Invalid use of named_tuple!") + $crate::data::managed::value::Value::new_named_tuple($frame, $names, $values).expect("Invalid use of named_tuple!") } }; } @@ -104,71 +108,42 @@ use std::{ mem::MaybeUninit, path::Path, ptr::NonNull, - sync::atomic::Ordering, usize, }; -use cfg_if::cfg_if; use jl_sys::{ - jl_an_empty_string, - jl_an_empty_vec_any, - jl_apply_type, - jl_array_any_type, - jl_array_int32_type, - jl_array_symbol_type, - jl_array_typetagdata, - jl_array_uint8_type, - jl_astaggedvalue, - jl_bottom_type, - jl_call, - jl_call0, - jl_call1, - jl_call2, - jl_call3, - jl_diverror_exception, - jl_egal, - jl_emptytuple, - jl_eval_string, - jl_exception_occurred, - jl_false, - jl_field_index, - jl_field_isptr, - jl_gc_add_finalizer, - jl_gc_add_ptr_finalizer, - jl_get_nth_field, - jl_get_nth_field_noalloc, - jl_interrupt_exception, - jl_isa, - jl_memory_exception, - jl_nothing, - jl_object_id, - jl_readonlymemory_exception, - jl_set_nth_field, - jl_stackovf_exception, - jl_stderr_obj, - jl_stdout_obj, - jl_subtype, - jl_true, - jl_typeof_str, - jl_undefref_exception, - jl_value_t, + jl_an_empty_string, jl_an_empty_vec_any, jl_apply_type, jl_array_any_type, jl_array_int32_type, + jl_array_symbol_type, jl_array_uint8_type, jl_astaggedvalue, jl_bottom_type, jl_call, jl_call0, + jl_call1, jl_call2, jl_call3, jl_diverror_exception, jl_egal, jl_emptytuple, jl_eval_string, + jl_exception_occurred, jl_false, jl_field_index, jl_field_isptr, jl_gc_add_finalizer, + jl_gc_add_ptr_finalizer, jl_get_nth_field, jl_get_nth_field_noalloc, jl_interrupt_exception, + jl_isa, jl_memory_exception, jl_nothing, jl_object_id, jl_readonlymemory_exception, + jl_set_nth_field, jl_stackovf_exception, jl_stderr_obj, jl_stdout_obj, jl_subtype, jl_true, + jl_typeof_str, jl_undefref_exception, jl_value_t, }; +use self::field_accessor::FieldAccessor; use super::Ref; use crate::{ call::{Call, ProvideKeywords, WithKeywords}, convert::{into_julia::IntoJulia, to_symbol::ToSymbol, unbox::Unbox}, + data::managed::{ + array::Array, + datatype::DataType, + module::Module, + private::ManagedPriv, + string::JuliaString, + symbol::Symbol, + union::Union, + union_all::UnionAll, + value::tracked::{Tracked, TrackedMut}, + Managed, + }, error::{ - AccessError, - IOError, - InstantiationError, - JlrsError, - JlrsResult, - TypeError, + AccessError, IOError, InstantiationError, JlrsError, JlrsResult, TypeError, CANNOT_DISPLAY_TYPE, }, layout::{ - field_index::FieldIndex, inline_layout::InlineLayout, typecheck::{NamedTuple, Typecheck}, valid_layout::{ValidField, ValidLayout}, @@ -179,33 +154,8 @@ use crate::{ target::{unrooted::Unrooted, ExtendedTarget, Target}, }, private::Private, - wrappers::{ - ptr::{ - array::Array, - datatype::{DataType, DataTypeRef}, - module::Module, - private::WrapperPriv, - string::JuliaString, - symbol::Symbol, - union::{nth_union_component, Union}, - union_all::UnionAll, - Wrapper, - }, - tracked::{Tracked, TrackedMut}, - }, }; -cfg_if! { - if #[cfg(not(feature = "julia-1-6"))] { - use jl_sys::{jlrs_lock, jlrs_unlock}; - - use std::{ - ptr::null_mut, - sync::atomic::{AtomicPtr, AtomicU16, AtomicU32, AtomicU64, AtomicU8}, - }; - } -} - /// In some cases it's necessary to place one or more arguments in front of the arguments a /// function is called with. Examples include the `named_tuple` macro and `Value::call_async`. /// If they are called with fewer than `MAX_SIZE` arguments (including the added arguments), no @@ -229,7 +179,7 @@ pub struct Value<'scope, 'data>( PhantomData<&'data mut ()>, ); -impl<'scope, 'data, T: Wrapper<'scope, 'data>> PartialEq for Value<'_, '_> { +impl<'scope, 'data, T: Managed<'scope, 'data>> PartialEq for Value<'_, '_> { fn eq(&self, other: &T) -> bool { self.egal(other.as_value()) } @@ -327,7 +277,7 @@ impl Value<'_, '_> { /// /// If the types can't be applied to `self` this methods catches and returns the exception. /// - /// [`Union::new`]: crate::wrappers::ptr::union::Union::new + /// [`Union::new`]: crate::data::managed::union::Union::new #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] pub fn apply_type<'target, 'value, 'data, V, T>( self, @@ -373,7 +323,7 @@ impl Value<'_, '_> { /// Safety: an exception must not be thrown if this method is called from a `ccall`ed /// function. /// - /// [`Union::new`]: crate::wrappers::ptr::union::Union::new + /// [`Union::new`]: crate::data::managed::union::Union::new pub unsafe fn apply_type_unchecked<'target, 'value, 'data, T, V>( self, target: T, @@ -451,7 +401,7 @@ impl Value<'_, '_> { /// /// A full list of supported checks can be found [here]. /// - /// [`JuliaStruct`]: crate::wrappers::ptr::traits::julia_struct::JuliaStruct + /// [`JuliaStruct`]: crate::data::managed::traits::julia_struct::JuliaStruct /// [here]: ../../../layout/typecheck/trait.Typecheck.html#implementors pub fn is(self) -> bool { self.datatype().is::() @@ -604,7 +554,7 @@ impl<'scope, 'data> Value<'scope, 'data> { /// used to convert a [`Value`] to the appropriate pointer wrapper type. For example, if the /// [`Value`] is a Julia array it can be cast to [`Array`]. Because this only involves a pointer /// cast it's always possible to convert a wrapper to a [`Value`] by calling -/// [`Wrapper::as_value`]. The second way is unboxing, which is used to copy the data the +/// [`Managed::as_value`]. The second way is unboxing, which is used to copy the data the /// [`Value`] points to to Rust. If a [`Value`] is a `UInt8`, it can be unboxed as a `u8`. By /// default, jlrs can unbox the default primitive types and Julia strings, but the [`Unbox`] trait /// can be implemented for other types. It's recommended that you use JlrsReflect.jl to do so. @@ -613,7 +563,7 @@ impl<'scope, 'data> Value<'scope, 'data> { impl<'scope, 'data> Value<'scope, 'data> { /// Cast the value to a pointer wrapper type `T`. Returns an error if the conversion is /// invalid. - pub fn cast + Typecheck>(self) -> JlrsResult { + pub fn cast + Typecheck>(self) -> JlrsResult { if self.is::() { // Safety: self.is::() returning true guarantees this is safe unsafe { Ok(self.cast_unchecked()) } @@ -627,7 +577,7 @@ impl<'scope, 'data> Value<'scope, 'data> { /// Cast the value to a pointer wrapper type `T` without checking if this conversion is valid. /// /// Safety: You must guarantee `self.is::()` would have returned `true`. - pub unsafe fn cast_unchecked>(self) -> T { + pub unsafe fn cast_unchecked>(self) -> T { T::from_value_unchecked(self, Private) } @@ -690,14 +640,7 @@ impl<'scope, 'data> Value<'scope, 'data> { /// Returns an accessor to access the contents of this value without allocating temporary Julia data. pub fn field_accessor(self) -> FieldAccessor<'scope, 'data> { - FieldAccessor { - value: Some(self.as_ref()), - current_field_type: Some(self.datatype().as_ref()), - offset: 0, - #[cfg(not(feature = "julia-1-6"))] - buffer: AtomicBuffer::new(), - state: ViewState::Unlocked, - } + FieldAccessor::new(self) } /// Roots the field at index `idx` if it exists and returns it, or a @@ -882,11 +825,11 @@ impl<'scope, 'data> Value<'scope, 'data> { let field_type = self .datatype() .field_types(&target) - .wrapper() + .as_managed() .data() .as_slice()[idx as usize] .unwrap() - .value(); + .as_value(); let dt = value.datatype(); if !Value::subtype(dt.as_value(), field_type) { @@ -951,11 +894,11 @@ impl<'scope, 'data> Value<'scope, 'data> { let field_type = self .datatype() .field_types(&target) - .wrapper() + .as_managed() .data() .as_slice()[idx as usize] .unwrap() - .value(); + .as_value(); let dt = value.datatype(); if !Value::subtype(dt.as_value(), field_type) { @@ -1078,7 +1021,9 @@ impl Value<'_, '_> { let (output, scope) = target.split(); return scope.scope(|mut frame| { let path_jl_str = JuliaString::new(&mut frame, path.as_ref().to_string_lossy()); - let include_func = Module::main(&frame).function(&frame, "include")?.wrapper(); + let include_func = Module::main(&frame) + .function(&frame, "include")? + .as_managed(); Ok(include_func.call1(output, path_jl_str.as_value())) }); @@ -1439,7 +1384,7 @@ impl<'value, 'data> ProvideKeywords<'value, 'data> for Value<'value, 'data> { impl_debug!(Value<'_, '_>); -impl<'scope, 'data> WrapperPriv<'scope, 'data> for Value<'scope, 'data> { +impl<'scope, 'data> ManagedPriv<'scope, 'data> for Value<'scope, 'data> { type Wraps = jl_value_t; type TypeConstructorPriv<'target, 'da> = Value<'target, 'da>; const NAME: &'static str = "Value"; @@ -1455,745 +1400,6 @@ impl<'scope, 'data> WrapperPriv<'scope, 'data> for Value<'scope, 'data> { } } -/// While jlrs generally enforces that Julia data can only exist and be used while a frame is -/// active, it's possible to leak global values: [`Symbol`]s, [`Module`]s, and globals defined in -/// those modules. -#[derive(Copy, Clone)] -pub struct LeakedValue(Value<'static, 'static>); - -impl LeakedValue { - // Safety: ptr must point to valid Julia data - pub(crate) unsafe fn wrap_non_null(ptr: NonNull) -> Self { - LeakedValue(Value::wrap_non_null(ptr, Private)) - } - - /// Convert this [`LeakedValue`] back to a [`Value`]. This requires an [`Unrooted`], so this - /// method can only be called inside a closure taken by one of the `scope`-methods. - /// - /// Safety: you must guarantee this value has not been freed by the garbage collector. While - /// `Symbol`s are never garbage collected, modules and their contents can be redefined. - #[inline(always)] - pub unsafe fn as_value<'scope, T: Target<'scope>>(self, _: &T) -> Value<'scope, 'static> { - self.0 - } -} - -#[repr(C)] -#[derive(Clone, Copy)] -#[cfg(not(feature = "julia-1-6"))] -union AtomicBuffer { - bytes: [MaybeUninit; 8], - ptr: *mut jl_value_t, -} - -#[cfg(not(feature = "julia-1-6"))] -impl AtomicBuffer { - fn new() -> Self { - AtomicBuffer { ptr: null_mut() } - } -} - -#[derive(Copy, Clone, PartialEq)] -enum ViewState { - #[cfg(not(feature = "julia-1-6"))] - Locked, - Unlocked, - #[cfg(not(feature = "julia-1-6"))] - AtomicBuffer, - Array, -} - -// TODO: track - -/// Access the raw contents of a Julia value. -/// -/// A `FieldAccessor` for a value can be created with [`Value::field_accessor`]. By chaining calls -/// to the `field` and `atomic_field` methods you can access deeply nested fields without -/// allocating temporary Julia data. These two methods support three kinds of field identifiers: -/// field names, numerical field indices, and n-dimensional array indices. The first two can be -/// used with types that have named fields, the second must be used with tuples, and the last one -/// with arrays. -pub struct FieldAccessor<'scope, 'data> { - value: Option>, - current_field_type: Option>, - #[cfg(not(feature = "julia-1-6"))] - buffer: AtomicBuffer, - offset: u32, - state: ViewState, -} - -impl<'scope, 'data> FieldAccessor<'scope, 'data> { - /// Access the field the accessor is currenty pointing to as a value of type `T`. - /// - /// This method accesses the field using its concrete type. If the concrete type of the field - /// has a matching pointer wrapper type it can be accessed as a `ValueRef` or a `Ref` of to - /// that pointer wrapper type. For example, a field that contains a `Module` can be accessed - /// as a `ModuleRef`. In all other cases an inline wrapper type must be used. For example, an - /// untyped field that currently holds a `Float64` must be accessed as `f64`. - pub fn access(self) -> JlrsResult { - if self.current_field_type.is_none() { - Err(AccessError::UndefRef)?; - } - - if self.value.is_none() { - Err(AccessError::UndefRef)?; - } - - // Safety: in this block, the first check ensures that T is correct - // for the data that is accessed. If the data is in the atomic buffer - // it's read from there. If T is as Ref, the pointer is converted. If - // it's an array, the element at the desired position is read. - // Otherwise, the field is read at the offset where it has been determined - // to be stored. - unsafe { - let ty = self.current_field_type.unwrap().value(); - if !T::valid_layout(ty) { - let value_type = ty.display_string_or(CANNOT_DISPLAY_TYPE).into(); - Err(AccessError::InvalidLayout { value_type })?; - } - - #[cfg(not(feature = "julia-1-6"))] - if self.state == ViewState::AtomicBuffer { - debug_assert!(!T::IS_REF); - debug_assert!(std::mem::size_of::() <= 8); - return Ok(std::ptr::read( - self.buffer.bytes[self.offset as usize..].as_ptr() as *const T, - )); - } - - if T::IS_REF { - Ok(std::mem::transmute_copy(&self.value)) - } else if self.state == ViewState::Array { - Ok(self - .value - .unwrap() - .value() - .cast_unchecked::() - .data_ptr() - .cast::() - .add(self.offset as usize) - .cast::() - .read()) - } else { - Ok(self - .value - .unwrap() - .ptr() - .cast::() - .as_ptr() - .add(self.offset as usize) - .cast::() - .read()) - } - } - } - - /// Returns `true` if `self.access::()` will succeed, `false` if it will fail. - pub fn can_access_as(&self) -> bool { - if self.current_field_type.is_none() { - return false; - } - - // Safety: the current_field_type field is not undefined. - let ty = unsafe { self.current_field_type.unwrap().value() }; - if !T::valid_layout(ty) { - return false; - } - - true - } - - /// Update the accessor to point to `field`. - /// - /// Three kinds of field indices exist: field names, numerical field indices, and - /// n-dimensional array indices. The first two can be used with types that have named fields, - /// the second must be used with tuples, and the last one with arrays. - /// - /// If `field` is an invalid identifier an error is returned. Calls to `field` can be chained - /// to access nested fields. - /// - /// If the field is an atomic field the same ordering is used as Julia uses by default: - /// `Relaxed` for pointer fields, `SeqCst` for small inline fields, and a lock for large - /// inline fields. - pub fn field(mut self, field: F) -> JlrsResult { - if self.value.is_none() { - Err(AccessError::UndefRef)? - } - - if self.current_field_type.is_none() { - Err(AccessError::UndefRef)? - } - - // Safety: how to access the next field depends on the current view. If an array - // is accessed the view is updated to the requested element. Otherwise, the offset - // is adjusted to target the requested field. Because the starting point is assumed - // to be rooted, all pointer fields are either reachablle or undefined. If a field is - // atomic, atomic accesses (or locks for large atomic fields) are used. - unsafe { - let current_field_type = self.current_field_type.unwrap().wrapper(); - if self.state == ViewState::Array && current_field_type.is::() { - let arr = self.value.unwrap().value().cast_unchecked::(); - // accessing an array, find the offset of the requested element - let index = field.array_index(arr, Private)?; - self.get_array_field(arr, index); - return Ok(self); - } - - let index = field.field_index(current_field_type, Private)?; - let global = Unrooted::new(); - - let next_field_type = match current_field_type.field_type_unchecked(global, index) { - Some(ty) => ty, - _ => Err(AccessError::UndefRef)?, - }; - - let next_field_type = next_field_type.wrapper(); - let is_pointer_field = current_field_type.is_pointer_field_unchecked(index); - let field_offset = current_field_type.field_offset_unchecked(index); - self.offset += field_offset; - - match self.state { - ViewState::Array => { - self.get_inline_array_field(is_pointer_field, next_field_type)? - } - ViewState::Unlocked => self.get_unlocked_inline_field( - is_pointer_field, - current_field_type, - next_field_type, - index, - Ordering::Relaxed, - Ordering::SeqCst, - ), - #[cfg(not(feature = "julia-1-6"))] - ViewState::Locked => { - self.get_locked_inline_field(is_pointer_field, next_field_type) - } - #[cfg(not(feature = "julia-1-6"))] - ViewState::AtomicBuffer => { - self.get_atomic_buffer_field(is_pointer_field, next_field_type) - } - } - } - - Ok(self) - } - - /// Update the accessor to point to `field`. - /// - /// If the field is a small atomic field `ordering` is used to read it. The ordering is - /// ignored for non-atomic fields and fields that require a lock to access. See - /// [`FieldAccessor::field`] for more information. - #[cfg(not(feature = "julia-1-6"))] - pub fn atomic_field(mut self, field: F, ordering: Ordering) -> JlrsResult { - if self.value.is_none() { - Err(AccessError::UndefRef)? - } - - if self.current_field_type.is_none() { - Err(AccessError::UndefRef)? - } - - // Safety: how to access the next field depends on the current view. If an array - // is accessed the view is updated to the requested element. Otherwise, the offset - // is adjusted to target the requested field. Because the starting point is assumed - // to be rooted, all pointer fields are either reachablle or undefined. If a field is - // atomic, atomic accesses (or locks for large atomic fields) are used. - unsafe { - let current_field_type = self.current_field_type.unwrap().wrapper(); - if self.state == ViewState::Array && current_field_type.is::() { - let arr = self.value.unwrap().value().cast_unchecked::(); - // accessing an array, find the offset of the requested element - let index = field.array_index(arr, Private)?; - self.get_array_field(arr, index); - return Ok(self); - } - - let index = field.field_index(current_field_type, Private)?; - let global = Unrooted::new(); - - let next_field_type = match current_field_type.field_type_unchecked(global, index) { - Some(ty) => ty, - _ => Err(AccessError::UndefRef)?, - }; - - let next_field_type = next_field_type.wrapper(); - let is_pointer_field = current_field_type.is_pointer_field_unchecked(index); - let field_offset = current_field_type.field_offset_unchecked(index); - self.offset += field_offset; - - match self.state { - ViewState::Array => { - self.get_inline_array_field(is_pointer_field, next_field_type)? - } - ViewState::Unlocked => self.get_unlocked_inline_field( - is_pointer_field, - current_field_type, - next_field_type, - index, - ordering, - ordering, - ), - ViewState::Locked => { - self.get_locked_inline_field(is_pointer_field, next_field_type) - } - ViewState::AtomicBuffer => { - self.get_atomic_buffer_field(is_pointer_field, next_field_type) - } - } - } - - Ok(self) - } - - /// Try to clone this accessor and its state. - /// - /// If the current value this accessor is accessing is locked an error is returned. - pub fn try_clone(&self) -> JlrsResult { - #[cfg(not(feature = "julia-1-6"))] - if self.state == ViewState::Locked { - Err(AccessError::Locked)?; - } - - Ok(FieldAccessor { - value: self.value, - current_field_type: self.current_field_type, - offset: self.offset, - #[cfg(not(feature = "julia-1-6"))] - buffer: self.buffer.clone(), - state: self.state, - }) - } - - /// Returns `true` if the current value the accessor is accessing is locked. - #[cfg(not(feature = "julia-1-6"))] - pub fn is_locked(&self) -> bool { - self.state == ViewState::Locked - } - - /// Returns `true` if the current value the accessor is accessing is locked. - #[cfg(feature = "julia-1-6")] - pub fn is_locked(&self) -> bool { - false - } - - /// Returns the type of the field the accessor is currently pointing at. - pub fn current_field_type(&self) -> Option> { - self.current_field_type - } - - /// Returns the value the accessor is currently inspecting. - pub fn value(&self) -> Option> { - self.value - } - - #[cfg(not(feature = "julia-1-6"))] - // Safety: the view state must be ViewState::AtomicBuffer - unsafe fn get_atomic_buffer_field( - &mut self, - is_pointer_field: bool, - next_field_type: Value<'scope, 'data>, - ) { - if is_pointer_field { - debug_assert_eq!(self.offset, 0); - let ptr = self.buffer.ptr; - if ptr.is_null() { - self.value = None; - } else { - self.value = Some(ValueRef::wrap(NonNull::new_unchecked(ptr))); - } - - self.state = ViewState::Unlocked; - if self.value.is_none() { - if let Ok(ty) = next_field_type.cast::() { - if ty.is_concrete_type() { - self.current_field_type = Some(ty.as_ref()); - } else { - self.current_field_type = None; - } - } else { - self.current_field_type = None; - } - } else { - self.current_field_type = Some(self.value.unwrap().wrapper().datatype().as_ref()); - } - } else { - debug_assert!(next_field_type.is::()); - self.current_field_type = Some(next_field_type.cast_unchecked::().as_ref()); - } - } - - // Safety: the view state must be ViewState::Unlocked - #[cfg(not(feature = "julia-1-6"))] - unsafe fn get_unlocked_inline_field( - &mut self, - is_pointer_field: bool, - current_field_type: DataType<'scope>, - next_field_type: Value<'scope, 'data>, - index: usize, - pointer_ordering: Ordering, - inline_ordering: Ordering, - ) { - let is_atomic_field = current_field_type.is_atomic_field_unchecked(index); - if is_pointer_field { - if is_atomic_field { - self.get_atomic_pointer_field(next_field_type, pointer_ordering); - } else { - self.get_pointer_field(false, next_field_type); - } - } else if let Ok(un) = next_field_type.cast::() { - self.get_bits_union_field(un); - } else { - debug_assert!(next_field_type.is::()); - self.current_field_type = Some(next_field_type.cast_unchecked::().as_ref()); - - if is_atomic_field { - self.lock_or_copy_atomic(inline_ordering); - } - } - } - - // Safety: the view state must be ViewState::Unlocked - #[cfg(feature = "julia-1-6")] - unsafe fn get_unlocked_inline_field( - &mut self, - is_pointer_field: bool, - _current_field_type: DataType<'scope>, - next_field_type: Value<'scope, 'data>, - _index: usize, - _pointer_ordering: Ordering, - _inline_ordering: Ordering, - ) { - if is_pointer_field { - self.get_pointer_field(false, next_field_type); - } else if let Ok(un) = next_field_type.cast::() { - self.get_bits_union_field(un); - } else { - debug_assert!(next_field_type.is::()); - self.current_field_type = Some(next_field_type.cast_unchecked::().as_ref()); - } - } - - // Safety: the view state must be ViewState::Locked - #[cfg(not(feature = "julia-1-6"))] - unsafe fn get_locked_inline_field( - &mut self, - is_pointer_field: bool, - next_field_type: Value<'scope, 'data>, - ) { - if is_pointer_field { - self.get_pointer_field(true, next_field_type); - } else if let Ok(un) = next_field_type.cast::() { - self.get_bits_union_field(un); - } else { - debug_assert!(next_field_type.is::()); - self.current_field_type = Some(next_field_type.cast_unchecked::().as_ref()); - } - } - - // Safety: the view state must be ViewState::Array - unsafe fn get_inline_array_field( - &mut self, - is_pointer_field: bool, - next_field_type: Value<'scope, 'data>, - ) -> JlrsResult<()> { - // Inline field of the current array - if is_pointer_field { - self.value = self - .value - .unwrap() - .value() - .cast::()? - .data_ptr() - .cast::>() - .add(self.offset as usize) - .cast::>() - .read(); - - self.offset = 0; - self.state = ViewState::Unlocked; - - if self.value.is_none() { - if let Ok(ty) = next_field_type.cast::() { - if ty.is_concrete_type() { - self.current_field_type = Some(ty.as_ref()); - } else { - self.current_field_type = None; - } - } else { - self.current_field_type = None; - } - } else { - self.current_field_type = Some(self.value.unwrap().value().datatype().as_ref()); - } - } else { - self.current_field_type = Some(next_field_type.cast::()?.as_ref()); - } - - Ok(()) - } - - #[cfg(not(feature = "julia-1-6"))] - // Safety: must only be used to read an atomic field - unsafe fn lock_or_copy_atomic(&mut self, ordering: Ordering) { - let ptr = self - .value - .unwrap() - .ptr() - .cast::>() - .as_ptr() - .add(self.offset as usize); - - match self.current_field_type.unwrap().wrapper().size() { - 0 => (), - 1 => { - let atomic = &*ptr.cast::(); - let v = atomic.load(ordering); - let dst_ptr = self.buffer.bytes.as_mut_ptr(); - std::ptr::copy_nonoverlapping(&v as *const _ as *const u8, dst_ptr as _, 1); - self.state = ViewState::AtomicBuffer; - self.offset = 0; - } - 2 => { - let atomic = &*ptr.cast::(); - let v = atomic.load(ordering); - let dst_ptr = self.buffer.bytes.as_mut_ptr(); - std::ptr::copy_nonoverlapping(&v as *const _ as *const u8, dst_ptr as _, 2); - self.state = ViewState::AtomicBuffer; - self.offset = 0; - } - sz if sz <= 4 => { - let atomic = &*ptr.cast::(); - let v = atomic.load(ordering); - let dst_ptr = self.buffer.bytes.as_mut_ptr(); - std::ptr::copy_nonoverlapping( - &v as *const _ as *const u8, - dst_ptr as _, - sz as usize, - ); - self.state = ViewState::AtomicBuffer; - self.offset = 0; - } - sz if sz <= 8 => { - let atomic = &*ptr.cast::(); - let v = atomic.load(ordering); - let dst_ptr = self.buffer.bytes.as_mut_ptr(); - std::ptr::copy_nonoverlapping( - &v as *const _ as *const u8, - dst_ptr as _, - sz as usize, - ); - self.state = ViewState::AtomicBuffer; - self.offset = 0; - } - _ => { - jlrs_lock(self.value.unwrap().ptr().as_ptr()); - self.state = ViewState::Locked; - } - } - } - - // Safety: must only be used to read an array element - unsafe fn get_array_field(&mut self, arr: Array<'scope, 'data>, index: usize) { - debug_assert!(self.state == ViewState::Array); - let el_size = arr.element_size(); - self.offset = (index * el_size) as u32; - - if arr.is_value_array() { - self.value = arr.data_ptr().cast::>().add(index).read(); - self.offset = 0; - if self.value.is_none() { - if let Ok(ty) = arr.element_type().cast::() { - if ty.is_concrete_type() { - self.current_field_type = Some(ty.as_ref()); - } else { - self.current_field_type = None; - } - - if !ty.is::() { - self.state = ViewState::Unlocked; - } - } else { - self.current_field_type = None; - self.state = ViewState::Unlocked; - } - } else { - let ty = self.value.unwrap().value().datatype(); - self.current_field_type = Some(ty.as_ref()); - if !ty.is::() { - self.state = ViewState::Unlocked; - } - } - } else if arr.is_union_array() { - let mut tag = *jl_array_typetagdata(arr.unwrap(Private)).add(index) as i32; - let component = nth_union_component(arr.element_type(), &mut tag); - debug_assert!(component.is_some()); - let ty = component.unwrap_unchecked(); - debug_assert!(ty.is::()); - let ty = ty.cast_unchecked::(); - debug_assert!(ty.is_concrete_type()); - self.current_field_type = Some(ty.as_ref()); - } else { - let ty = arr.element_type(); - debug_assert!(ty.is::()); - self.current_field_type = Some(ty.cast_unchecked::().as_ref()); - } - } - - #[cfg(not(feature = "julia-1-6"))] - // Safety: must only be used to read an pointer field - unsafe fn get_pointer_field(&mut self, locked: bool, next_field_type: Value<'scope, 'data>) { - let value = self - .value - .unwrap() - .ptr() - .cast::() - .as_ptr() - .add(self.offset as usize) - .cast::>() - .read(); - - if locked { - jlrs_unlock(self.value.unwrap().ptr().as_ptr()); - self.state = ViewState::Unlocked; - } - - self.value = value; - self.offset = 0; - - if self.value.is_none() { - if let Ok(ty) = next_field_type.cast::() { - if ty.is_concrete_type() { - self.current_field_type = Some(ty.as_ref()); - } else { - self.current_field_type = None; - } - } else { - self.current_field_type = None; - } - } else { - let value = self.value.unwrap().value(); - self.current_field_type = Some(value.datatype().as_ref()); - if value.is::() { - self.state = ViewState::Array; - } - } - } - - #[cfg(feature = "julia-1-6")] - // Safety: must only be used to read an pointer field - unsafe fn get_pointer_field(&mut self, _locked: bool, next_field_type: Value<'scope, 'data>) { - self.value = self - .value - .unwrap() - .ptr() - .cast::() - .as_ptr() - .add(self.offset as usize) - .cast::>() - .read(); - - self.offset = 0; - - if self.value.is_none() { - if let Ok(ty) = next_field_type.cast::() { - if ty.is_concrete_type() { - self.current_field_type = Some(ty.as_ref()); - } else { - self.current_field_type = None; - } - } else { - self.current_field_type = None; - } - } else { - let value = self.value.unwrap().value(); - self.current_field_type = Some(value.datatype().as_ref()); - if value.is::() { - self.state = ViewState::Array; - } - } - } - - #[cfg(not(feature = "julia-1-6"))] - // Safety: must only be used to read an atomic pointer field - unsafe fn get_atomic_pointer_field( - &mut self, - next_field_type: Value<'scope, 'data>, - ordering: Ordering, - ) { - let v = &*self - .value - .unwrap() - .ptr() - .cast::() - .as_ptr() - .add(self.offset as usize) - .cast::>(); - - let ptr = v.load(ordering); - if ptr.is_null() { - self.value = None; - } else { - self.value = Some(ValueRef::wrap(NonNull::new_unchecked(ptr))); - } - - self.offset = 0; - - if self.value.is_none() { - if let Ok(ty) = next_field_type.cast::() { - if ty.is_concrete_type() { - self.current_field_type = Some(ty.as_ref()); - } else { - self.current_field_type = None; - } - } else { - self.current_field_type = None; - } - } else { - let value = self.value.unwrap().value(); - self.current_field_type = Some(value.datatype().as_ref()); - if value.is::() { - self.state = ViewState::Array; - } - } - } - - // Safety: must only be used to read a bits union field - unsafe fn get_bits_union_field(&mut self, union: Union<'scope>) { - let mut size = 0; - let isbits = union.isbits_size_align(&mut size, &mut 0); - debug_assert!(isbits); - let flag_offset = self.offset as usize + size; - let mut flag = self - .value - .unwrap() - .ptr() - .cast::() - .as_ptr() - .add(flag_offset) - .read() as i32; - - let active_ty = nth_union_component(union.as_value(), &mut flag); - debug_assert!(active_ty.is_some()); - let active_ty = active_ty.unwrap_unchecked(); - debug_assert!(active_ty.is::()); - - let ty = active_ty.cast_unchecked::(); - debug_assert!(ty.is_concrete_type()); - self.current_field_type = Some(ty.as_ref()); - } -} - -impl Drop for FieldAccessor<'_, '_> { - fn drop(&mut self) { - #[cfg(not(feature = "julia-1-6"))] - if self.state == ViewState::Locked { - debug_assert!(!self.value.is_none()); - // Safety: the value is currently locked. - unsafe { jlrs_unlock(self.value.unwrap().ptr().as_ptr()) } - } - } -} - /// A reference to a [`Value`] that has not been explicitly rooted. pub type ValueRef<'scope, 'data> = Ref<'scope, 'data, Value<'scope, 'data>>; diff --git a/jlrs/src/wrappers/tracked.rs b/jlrs/src/data/managed/value/tracked.rs similarity index 97% rename from jlrs/src/wrappers/tracked.rs rename to jlrs/src/data/managed/value/tracked.rs index 1e3c8151..9532e04a 100644 --- a/jlrs/src/wrappers/tracked.rs +++ b/jlrs/src/data/managed/value/tracked.rs @@ -9,9 +9,8 @@ use std::{ }; use crate::{ - layout::inline_layout::InlineLayout, + data::managed::value::Value, layout::inline_layout::InlineLayout, memory::context::ledger::Ledger, - wrappers::ptr::value::Value, }; /// Immutable tracked data. diff --git a/jlrs/src/wrappers/mod.rs b/jlrs/src/data/mod.rs similarity index 65% rename from jlrs/src/wrappers/mod.rs rename to jlrs/src/data/mod.rs index 0cc17118..c1c5a54e 100644 --- a/jlrs/src/wrappers/mod.rs +++ b/jlrs/src/data/mod.rs @@ -1,4 +1,4 @@ -//! Wrapper types for Julia data +//! Managed types for Julia data //! //! Whenever the C API returns data owned by the garbage collector it's returned as a pointer. //! jlrs provides several types that wrap these pointers, relevant functionality from the Julia C @@ -14,17 +14,15 @@ //! tuples that can have up to 32 elements which are available in the [`tuple`] module. Inline //! wrappers for other types can be generated with the JlrsReflect.jl package. //! -//! [`Value`]: crate::wrappers::ptr::value::Value -//! [`Value::new`]: crate::wrappers::ptr::value::Value::new -//! [`Value::unbox`]: crate::wrappers::ptr::value::Value::unbox -//! [`Array`]: crate::wrappers::ptr::array::Array -//! [`Module`]: crate::wrappers::ptr::module::Module -//! [`Ref`]: crate::wrappers::ptr::Ref -//! [`Char`]: crate::wrappers::inline::char::Char -//! [`Bool`]: crate::wrappers::inline::bool::Bool -//! [`tuple`]: crate::wrappers::inline::tuple +//! [`Value`]: crate::data::managed::value::Value +//! [`Value::new`]: crate::data::managed::value::Value::new +//! [`Value::unbox`]: crate::data::managed::value::Value::unbox +//! [`Array`]: crate::data::managed::array::Array +//! [`Module`]: crate::data::managed::module::Module +//! [`Ref`]: crate::data::managed::Ref +//! [`Char`]: crate::data::layout::char::Char +//! [`Bool`]: crate::data::layout::bool::Bool +//! [`tuple`]: crate::data::layout::tuple -pub mod foreign; -pub mod inline; -pub mod ptr; -pub mod tracked; +pub mod layout; +pub mod managed; diff --git a/jlrs/src/error.rs b/jlrs/src/error.rs index 44def1c7..b51b2c8e 100644 --- a/jlrs/src/error.rs +++ b/jlrs/src/error.rs @@ -4,7 +4,7 @@ use std::error::Error as StdErr; use thiserror::Error; -use crate::wrappers::ptr::{ +use crate::data::managed::{ array::dimensions::Dimensions, value::{Value, ValueRef}, }; diff --git a/jlrs/src/info.rs b/jlrs/src/info.rs index a31d292e..10205e9c 100644 --- a/jlrs/src/info.rs +++ b/jlrs/src/info.rs @@ -4,25 +4,14 @@ use std::{ffi::CStr, ptr::NonNull}; use cfg_if::cfg_if; use jl_sys::{ - jl_cpu_threads, - jl_get_ARCH, - jl_get_UNAME, - jl_getallocationgranularity, - jl_getpagesize, - jl_git_branch, - jl_git_commit, - jl_is_debugbuild, - jl_n_threads, - jl_ver_is_release, - jl_ver_major, - jl_ver_minor, - jl_ver_patch, - jl_ver_string, + jl_cpu_threads, jl_get_ARCH, jl_get_UNAME, jl_getallocationgranularity, jl_getpagesize, + jl_git_branch, jl_git_commit, jl_is_debugbuild, jl_n_threads, jl_ver_is_release, jl_ver_major, + jl_ver_minor, jl_ver_patch, jl_ver_string, }; use crate::{ + data::managed::{private::ManagedPriv, symbol::Symbol}, private::Private, - wrappers::ptr::{private::WrapperPriv, symbol::Symbol}, }; /// Global Julia information. diff --git a/jlrs/src/layout/bits_union.rs b/jlrs/src/layout/bits_union.rs index a77e18f1..d51aad84 100644 --- a/jlrs/src/layout/bits_union.rs +++ b/jlrs/src/layout/bits_union.rs @@ -36,7 +36,7 @@ unsafe impl Flag for u8 {} mod private { use std::fmt::Debug; - use crate::wrappers::inline::union::{Align1, Align16, Align2, Align4, Align8, BitsUnion}; + use crate::data::layout::union::{Align1, Align16, Align2, Align4, Align8, BitsUnion}; pub trait AlignPriv: Copy + Debug {} impl AlignPriv for Align1 {} diff --git a/jlrs/src/layout/field_index.rs b/jlrs/src/layout/field_index.rs index 4eb7b1e1..b97d28ca 100644 --- a/jlrs/src/layout/field_index.rs +++ b/jlrs/src/layout/field_index.rs @@ -3,22 +3,22 @@ /// Trait implemented by types that can be used in combination with a /// [`FieldAccessor`]. /// -/// [`FieldAccessor`]: crate::wrappers::ptr::value::FieldAccessor +/// [`FieldAccessor`]: crate::data::managed::value::FieldAccessor pub trait FieldIndex: private::FieldIndexPriv {} impl FieldIndex for I {} mod private { use crate::{ convert::to_symbol::private::ToSymbolPriv, - error::{AccessError, JlrsResult, CANNOT_DISPLAY_TYPE}, - private::Private, - wrappers::ptr::{ + data::managed::{ array::{dimensions::Dims, Array}, datatype::DataType, string::JuliaString, symbol::Symbol, - Wrapper, + Managed, }, + error::{AccessError, JlrsResult, CANNOT_DISPLAY_TYPE}, + private::Private, }; pub trait FieldIndexPriv { diff --git a/jlrs/src/layout/typecheck.rs b/jlrs/src/layout/typecheck.rs index 09325ea7..2015162c 100644 --- a/jlrs/src/layout/typecheck.rs +++ b/jlrs/src/layout/typecheck.rs @@ -2,44 +2,29 @@ //! //! Several properties of Julia data can be checked by using [`Value::is`] and [`DataType::is`], //! these methods must be used in combination with a type that implements the [`Typecheck`] trait. -//! Most types that implement this trait also implement [`Wrapper`] or [`Unbox`], for these types +//! Most types that implement this trait also implement [`Managed`] or [`Unbox`], for these types //! the typecheck indicates whether or not it's valid to cast the value to or unbox it as that //! type. //! -//! [`Value::is`]: crate::wrappers::ptr::value::Value::is -//! [`Wrapper`]: crate::wrappers::ptr::Wrapper +//! [`Value::is`]: crate::data::managed::value::Value::is +//! [`Managed`]: crate::data::managed::Managed //! [`Unbox`]: crate::convert::unbox::Unbox use std::ffi::c_void; use jl_sys::{ - jl_code_info_type, - jl_globalref_type, - jl_gotonode_type, - jl_intrinsic_type, - jl_linenumbernode_type, - jl_namedtuple_typename, - jl_newvarnode_type, - jl_phicnode_type, - jl_phinode_type, - jl_pinode_type, - jl_quotenode_type, - jl_slotnumber_type, - jl_string_type, - jl_typedslot_type, - jl_upsilonnode_type, + jl_code_info_type, jl_globalref_type, jl_gotonode_type, jl_intrinsic_type, + jl_linenumbernode_type, jl_namedtuple_typename, jl_newvarnode_type, jl_phicnode_type, + jl_phinode_type, jl_pinode_type, jl_quotenode_type, jl_slotnumber_type, jl_string_type, + jl_typedslot_type, jl_upsilonnode_type, }; use crate::{ convert::into_julia::IntoJulia, + data::managed::{ + datatype::DataType, private::ManagedPriv, type_name::TypeName, union_all::UnionAll, Managed, + }, memory::target::unrooted::Unrooted, private::Private, - wrappers::ptr::{ - datatype::DataType, - private::WrapperPriv, - type_name::TypeName, - union_all::UnionAll, - Wrapper, - }, }; /// This trait is used in combination with [`Value::is`] and [`DataType::is`] to check if that @@ -49,9 +34,9 @@ use crate::{ /// method `typecheck` must only return `true` if it's guaranteed that `Unbox::unbox` can safely /// be called for values whose type is that method's argument. /// -/// [`Value::is`]: crate::wrappers::ptr::value::Value::is +/// [`Value::is`]: crate::data::managed::value::Value::is /// [`Unbox`]: crate::convert::unbox::Unbox -/// [`Wrapper`]: crate::wrappers::ptr::Wrapper +/// [`Managed`]: crate::data::managed::Managed pub unsafe trait Typecheck { /// Returns whether the property implied by `Self` holds true. fn typecheck(t: DataType) -> bool; @@ -63,9 +48,9 @@ macro_rules! impl_julia_typecheck { ($type:ty, $jl_type:expr, $($lt:lifetime),+) => { unsafe impl<$($lt),+> crate::layout::typecheck::Typecheck for $type { #[inline(always)] - fn typecheck(t: $crate::wrappers::ptr::datatype::DataType) -> bool { + fn typecheck(t: $crate::data::managed::datatype::DataType) -> bool { unsafe { - <$crate::wrappers::ptr::datatype::DataType as $crate::wrappers::ptr::private::WrapperPriv>::unwrap(t, crate::private::Private) == $jl_type + <$crate::data::managed::datatype::DataType as $crate::data::managed::private::ManagedPriv>::unwrap(t, crate::private::Private) == $jl_type } } } @@ -73,9 +58,9 @@ macro_rules! impl_julia_typecheck { ($type:ty, $jl_type:expr) => { unsafe impl crate::layout::typecheck::Typecheck for $type { #[inline(always)] - fn typecheck(t: $crate::wrappers::ptr::datatype::DataType) -> bool { + fn typecheck(t: $crate::data::managed::datatype::DataType) -> bool { unsafe { - <$crate::wrappers::ptr::datatype::DataType as $crate::wrappers::ptr::private::WrapperPriv>::unwrap(t, crate::private::Private) == $jl_type + <$crate::data::managed::datatype::DataType as $crate::data::managed::private::ManagedPriv>::unwrap(t, crate::private::Private) == $jl_type } } } @@ -83,10 +68,10 @@ macro_rules! impl_julia_typecheck { ($type:ty) => { unsafe impl crate::layout::typecheck::Typecheck for $type { #[inline(always)] - fn typecheck(t: crate::wrappers::ptr::datatype::DataType) -> bool { + fn typecheck(t: crate::data::managed::datatype::DataType) -> bool { unsafe { let global = $crate::memory::target::unrooted::Unrooted::new(); - <$crate::wrappers::ptr::datatype::DataType as $crate::wrappers::ptr::private::WrapperPriv>::unwrap(t, crate::private::Private) == <$type as $crate::convert::into_julia::IntoJulia>::julia_type(global).ptr().as_ptr() + <$crate::data::managed::datatype::DataType as $crate::data::managed::private::ManagedPriv>::unwrap(t, crate::private::Private) == <$type as $crate::convert::into_julia::IntoJulia>::julia_type(global).ptr().as_ptr() } } } @@ -122,7 +107,7 @@ unsafe impl Typecheck for *mut T { let params = t.parameters(); let params = params.data().as_slice(); let inner_ty = T::julia_type(global); - if params[0].unwrap().value() != inner_ty.value() { + if params[0].unwrap().as_value() != inner_ty.as_value() { return false; } diff --git a/jlrs/src/layout/valid_layout.rs b/jlrs/src/layout/valid_layout.rs index 6f94eac8..29087b32 100644 --- a/jlrs/src/layout/valid_layout.rs +++ b/jlrs/src/layout/valid_layout.rs @@ -6,13 +6,13 @@ //! has the same layout as a given Julia type. It is implemented automatically by JlrsReflect.jl, //! you should not implement it manually. //! -//! [`DataType`]: crate::wrappers::ptr::datatype::DataType +//! [`DataType`]: crate::data::managed::datatype::DataType use std::ffi::c_void; use crate::{ convert::into_julia::IntoJulia, - wrappers::ptr::{datatype::DataType, value::Value}, + data::managed::{datatype::DataType, value::Value}, }; /// Trait used to check if a Rust type and Julia type have matching layouts. @@ -21,9 +21,9 @@ use crate::{ /// checked recursively to determine if the value can be unboxed as that type. pub unsafe trait ValidLayout { /// Must be `true` if the Rust type is a pointer wrapper type, i.e. if `Self` implements - /// [`WrapperRef`], `false` otherwise. + /// [`ManagedRef`], `false` otherwise. /// - /// [`WrapperRef`]: crate::wrappers::ptr::WrapperRef + /// [`ManagedRef`]: crate::data::managed::ManagedRef const IS_REF: bool = false; /// Check if the layout of the implementor is compatible with the layout of `ty`. This @@ -38,8 +38,8 @@ macro_rules! impl_valid_layout { ($type:ty, $($lt:lifetime),+) => { unsafe impl<$($lt),+> $crate::layout::valid_layout::ValidLayout for $type { #[inline(always)] - fn valid_layout(v: $crate::wrappers::ptr::value::Value) -> bool { - if let Ok(dt) = v.cast::<$crate::wrappers::ptr::datatype::DataType>() { + fn valid_layout(v: $crate::data::managed::value::Value) -> bool { + if let Ok(dt) = v.cast::<$crate::data::managed::datatype::DataType>() { dt.is::<$type>() } else { false @@ -51,8 +51,8 @@ macro_rules! impl_valid_layout { unsafe impl<$($lt),+> $crate::layout::valid_layout::ValidField for $type { #[inline(always)] - fn valid_field(v: $crate::wrappers::ptr::value::Value) -> bool { - if let Ok(dt) = v.cast::<$crate::wrappers::ptr::datatype::DataType>() { + fn valid_field(v: $crate::data::managed::value::Value) -> bool { + if let Ok(dt) = v.cast::<$crate::data::managed::datatype::DataType>() { dt.is::<$type>() } else { false @@ -63,8 +63,8 @@ macro_rules! impl_valid_layout { ($t:ty) => { unsafe impl $crate::layout::valid_layout::ValidLayout for $t { #[inline(always)] - fn valid_layout(v: $crate::wrappers::ptr::value::Value) -> bool { - if let Ok(dt) = v.cast::<$crate::wrappers::ptr::datatype::DataType>() { + fn valid_layout(v: $crate::data::managed::value::Value) -> bool { + if let Ok(dt) = v.cast::<$crate::data::managed::datatype::DataType>() { dt.is::<$t>() } else { false @@ -76,8 +76,8 @@ macro_rules! impl_valid_layout { unsafe impl $crate::layout::valid_layout::ValidField for $t { #[inline(always)] - fn valid_field(v: $crate::wrappers::ptr::value::Value) -> bool { - if let Ok(dt) = v.cast::<$crate::wrappers::ptr::datatype::DataType>() { + fn valid_field(v: $crate::data::managed::value::Value) -> bool { + if let Ok(dt) = v.cast::<$crate::data::managed::datatype::DataType>() { dt.is::<$t>() } else { false diff --git a/jlrs/src/lib.rs b/jlrs/src/lib.rs index 0f0885e7..e1900e33 100644 --- a/jlrs/src/lib.rs +++ b/jlrs/src/lib.rs @@ -658,20 +658,20 @@ //! [`CCall::uv_async_send`]: crate::ccall::CCall::uv_async_send //! [`Unrooted`]: crate::memory::target::unrooted::Unrooted //! [`GcFrame`]: crate::memory::target::frame::GcFrame -//! [`Module`]: crate::wrappers::ptr::module::Module -//! [`Function`]: crate::wrappers::ptr::function::Function -//! [`Value`]: crate::wrappers::ptr::value::Value +//! [`Module`]: crate::data::managed::module::Module +//! [`Function`]: crate::data::managed::function::Function +//! [`Value`]: crate::data::managed::value::Value //! [`Call`]: crate::call::Call -//! [`Value::eval_string`]: crate::wrappers::ptr::value::Value::eval_string -//! [`Value::new`]: crate::wrappers::ptr::value::Value::new -//! [`Array`]: crate::wrappers::ptr::array::Array -//! [`JuliaString`]: crate::wrappers::ptr::string::JuliaString -//! [`Module::main`]: crate::wrappers::ptr::module::Module::main -//! [`Module::base`]: crate::wrappers::ptr::module::Module::base -//! [`Module::core`]: crate::wrappers::ptr::module::Module::core -//! [`Module::function`]: crate::wrappers::ptr::module::Module::function -//! [`Module::global`]: crate::wrappers::ptr::module::Module::global -//! [`Module::submodule`]: crate::wrappers::ptr::module::Module::submodule +//! [`Value::eval_string`]: crate::data::managed::value::Value::eval_string +//! [`Value::new`]: crate::data::managed::value::Value::new +//! [`Array`]: crate::data::managed::array::Array +//! [`JuliaString`]: crate::data::managed::string::JuliaString +//! [`Module::main`]: crate::data::managed::module::Module::main +//! [`Module::base`]: crate::data::managed::module::Module::base +//! [`Module::core`]: crate::data::managed::module::Module::core +//! [`Module::function`]: crate::data::managed::module::Module::function +//! [`Module::global`]: crate::data::managed::module::Module::global +//! [`Module::submodule`]: crate::data::managed::module::Module::submodule //! [`AsyncJulia::init_with_image`]: crate::multitask::runtime::AsyncJulia::init_with_image //! [`AsyncJulia::init_with_image_async`]: crate::multitask::runtime::AsyncJulia::init_with_image_async //! [`IntoJulia`]: crate::convert::into_julia::IntoJulia @@ -687,8 +687,8 @@ //! [`PersistentHandle`]: crate::runtime::async_rt::PersistentHandle //! [`AsyncJulia`]: crate::runtime::async_rt::AsyncJulia //! [`CallAsync`]: crate::call::CallAsync -//! [`DataType`]: crate::wrappers::ptr::datatype::DataType -//! [`TypedArray`]: crate::wrappers::ptr::array::TypedArray +//! [`DataType`]: crate::data::managed::datatype::DataType +//! [`TypedArray`]: crate::data::managed::array::TypedArray //! [`RuntimeBuilder`]: crate::runtime::builder::RuntimeBuilder //! [`AsyncRuntimeBuilder`]: crate::runtime::builder::AsyncRuntimeBuilder //! [`jlrs::prelude`]: crate::prelude @@ -701,12 +701,12 @@ macro_rules! init_fn { pub(crate) unsafe fn $name<'frame>( frame: &mut $crate::memory::target::frame::GcFrame<'frame>, ) -> () { - match $crate::wrappers::ptr::value::Value::eval_string(frame, $include) { + match $crate::data::managed::value::Value::eval_string(frame, $include) { Ok(_) => (), Err(e) => { panic!( "{}", - $crate::wrappers::ptr::Wrapper::error_string_or( + $crate::data::managed::Managed::error_string_or( e, $crate::error::CANNOT_DISPLAY_VALUE ) @@ -725,6 +725,7 @@ pub(crate) mod catch; #[cfg(feature = "ccall")] pub mod ccall; pub mod convert; +pub mod data; pub mod error; pub mod info; pub mod layout; @@ -740,4 +741,3 @@ pub mod safety; #[doc(hidden)] #[cfg(feature = "sync-rt")] pub mod util; -pub mod wrappers; diff --git a/jlrs/src/memory/context/stack.rs b/jlrs/src/memory/context/stack.rs index 596213e2..249291a9 100644 --- a/jlrs/src/memory/context/stack.rs +++ b/jlrs/src/memory/context/stack.rs @@ -19,11 +19,11 @@ use atomic_refcell::AtomicRefCell; use jl_sys::{jl_gc_wb, jl_value_t}; use crate::{ - memory::{gc::mark_queue_objarray, stack_frame::PinnedFrame, target::unrooted::Unrooted, PTls}, - wrappers::{ - foreign::{create_foreign_type, ForeignType}, - ptr::{module::Module, symbol::Symbol, value::Value, Wrapper}, + data::{ + layout::foreign::{create_foreign_type, ForeignType}, + managed::{module::Module, symbol::Symbol, value::Value, Managed}, }, + memory::{gc::mark_queue_objarray, stack_frame::PinnedFrame, target::unrooted::Unrooted, PTls}, }; #[repr(C)] @@ -63,7 +63,7 @@ impl Stack { let ptr = dt_ref.ptr(); frame.set_sync_root(ptr.cast().as_ptr()); - let dt = dt_ref.wrapper(); + let dt = dt_ref.as_managed(); module.set_const_unchecked(sym, dt.as_value()); } diff --git a/jlrs/src/memory/gc.rs b/jlrs/src/memory/gc.rs index 8e607fe2..e31b9358 100644 --- a/jlrs/src/memory/gc.rs +++ b/jlrs/src/memory/gc.rs @@ -3,24 +3,18 @@ use std::ffi::c_void; use jl_sys::{ - jl_gc_collect, - jl_gc_collection_t, - jl_gc_enable, - jl_gc_is_enabled, - jl_gc_mark_queue_obj, - jl_gc_mark_queue_objarray, - jl_gc_safepoint, - jl_gc_wb, + jl_gc_collect, jl_gc_collection_t, jl_gc_enable, jl_gc_is_enabled, jl_gc_mark_queue_obj, + jl_gc_mark_queue_objarray, jl_gc_safepoint, jl_gc_wb, }; use super::{target::Target, PTls}; #[cfg(feature = "sync-rt")] use crate::runtime::sync_rt::Julia; #[cfg(not(feature = "julia-1-6"))] -use crate::{call::Call, wrappers::ptr::module::Module}; +use crate::{call::Call, data::managed::module::Module}; use crate::{ + data::managed::{private::ManagedPriv, value::Value}, private::Private, - wrappers::ptr::{private::WrapperPriv, value::Value}, }; /// The different collection modes. @@ -61,10 +55,10 @@ pub trait Gc: private::GcPriv { Module::base(&global) .submodule(&global, "GC") .expect("No GC module in Base") - .wrapper() + .as_managed() .function(&global, "enable_logging") .expect("No enable_logging function in GC") - .wrapper() + .as_managed() }; let arg = if on { diff --git a/jlrs/src/memory/stack_frame.rs b/jlrs/src/memory/stack_frame.rs index 062a2fb7..c3c24e9f 100644 --- a/jlrs/src/memory/stack_frame.rs +++ b/jlrs/src/memory/stack_frame.rs @@ -12,8 +12,8 @@ use jl_sys::{jl_get_current_task, jl_task_t}; use super::context::stack::Stack; use crate::{ + data::managed::{private::ManagedPriv, value::Value}, private::Private, - wrappers::ptr::{private::WrapperPriv, value::Value}, }; const ROOT: Cell<*mut c_void> = Cell::new(null_mut()); diff --git a/jlrs/src/memory/target/frame.rs b/jlrs/src/memory/target/frame.rs index f82c4d44..fda6f503 100644 --- a/jlrs/src/memory/target/frame.rs +++ b/jlrs/src/memory/target/frame.rs @@ -14,13 +14,13 @@ use cfg_if::cfg_if; use super::{output::Output, reusable_slot::ReusableSlot, unrooted::Unrooted}; use crate::{ + data::managed::Managed, error::JlrsResult, memory::{ context::stack::Stack, target::{ExtendedTarget, Target}, }, private::Private, - wrappers::ptr::Wrapper, }; /// A frame associated with a scope. @@ -163,7 +163,7 @@ impl<'scope> GcFrame<'scope> { } // Safety: ptr must be a valid pointer to T - pub(crate) unsafe fn root<'data, T: Wrapper<'scope, 'data>>( + pub(crate) unsafe fn root<'data, T: Managed<'scope, 'data>>( &self, ptr: NonNull, ) -> T { diff --git a/jlrs/src/memory/target/mod.rs b/jlrs/src/memory/target/mod.rs index 945e2dc6..6a3b5872 100644 --- a/jlrs/src/memory/target/mod.rs +++ b/jlrs/src/memory/target/mod.rs @@ -30,7 +30,7 @@ //! //! The last row means that any target `T` can be used as a non-rooting target by using a //! reference to that target. When a non-rooting target is used, Julia data is returned as a -//! [`Ref`] rather than a [`Wrapper`]. This is useful in cases where it can be guaranteed the +//! [`Ref`] rather than a [`Managed`]. This is useful in cases where it can be guaranteed the //! data is globally rooted, or if you don't care about the result. More information about these //! target types can be found in the submodules that define them. //! @@ -39,8 +39,8 @@ //! a target, the `BorrowedFrame` can be used to create a temporary scope and the target for the //! data that is returned. //! -//! [`Ref`]: crate::wrappers::ptr::Ref -//! [`Wrapper`]: crate::wrappers::ptr::Wrapper +//! [`Ref`]: crate::data::managed::Ref +//! [`Managed`]: crate::data::managed::Managed use std::marker::PhantomData; @@ -176,20 +176,15 @@ pub(crate) mod private { #[cfg(feature = "async")] use super::AsyncGcFrame; use super::{ - reusable_slot::ReusableSlot, - target_type::TargetType, - unrooted::Unrooted, - GcFrame, - Output, + reusable_slot::ReusableSlot, target_type::TargetType, unrooted::Unrooted, GcFrame, Output, }; use crate::{ - private::Private, - wrappers::ptr::{ - private::WrapperPriv, + data::managed::{ + private::ManagedPriv, value::{Value, ValueRef}, - Ref, - Wrapper, + Managed, Ref, }, + private::Private, }; pub trait TargetBase<'target>: Sized {} @@ -218,21 +213,21 @@ pub(crate) mod private { pub trait TargetPriv<'target>: TargetType<'target> { // Safety: the pointer must point to valid data. - unsafe fn data_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn data_from_ptr<'data, T: Managed<'target, 'data>>( self, value: NonNull, _: Private, ) -> Self::Data<'data, T>; // Safety: the pointer must point to valid data. - unsafe fn result_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn result_from_ptr<'data, T: Managed<'target, 'data>>( self, result: Result, NonNull>, _: Private, ) -> Self::Result<'data, T>; // Safety: the pointer must point to valid data. - unsafe fn result_from_unrooted<'data, T: Wrapper<'target, 'data>>( + unsafe fn result_from_unrooted<'data, T: Managed<'target, 'data>>( self, result: Result, ValueRef<'target, 'data>>, _: Private, @@ -246,7 +241,7 @@ pub(crate) mod private { } // Safety: the pointer must point to valid data. - unsafe fn result_from_rooted<'data, T: Wrapper<'target, 'data>>( + unsafe fn result_from_rooted<'data, T: Managed<'target, 'data>>( self, result: Result>, _: Private, @@ -269,7 +264,7 @@ pub(crate) mod private { impl<'target> TargetPriv<'target> for &mut GcFrame<'target> { // Safety: the pointer must point to valid data. - unsafe fn data_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn data_from_ptr<'data, T: Managed<'target, 'data>>( self, value: NonNull, _: Private, @@ -278,7 +273,7 @@ pub(crate) mod private { } // Safety: the pointer must point to valid data. - unsafe fn result_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn result_from_ptr<'data, T: Managed<'target, 'data>>( self, result: Result, NonNull>, _: Private, @@ -304,7 +299,7 @@ pub(crate) mod private { impl<'target> TargetPriv<'target> for GcFrame<'target> { // Safety: the pointer must point to valid data. - unsafe fn data_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn data_from_ptr<'data, T: Managed<'target, 'data>>( self, value: NonNull, _: Private, @@ -313,7 +308,7 @@ pub(crate) mod private { } // Safety: the pointer must point to valid data. - unsafe fn result_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn result_from_ptr<'data, T: Managed<'target, 'data>>( self, result: Result, NonNull>, _: Private, @@ -340,7 +335,7 @@ pub(crate) mod private { #[cfg(feature = "async")] impl<'target> TargetPriv<'target> for &mut AsyncGcFrame<'target> { // Safety: the pointer must point to valid data. - unsafe fn data_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn data_from_ptr<'data, T: Managed<'target, 'data>>( self, value: NonNull, _: Private, @@ -349,7 +344,7 @@ pub(crate) mod private { } // Safety: the pointer must point to valid data. - unsafe fn result_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn result_from_ptr<'data, T: Managed<'target, 'data>>( self, result: Result, NonNull>, _: Private, @@ -376,7 +371,7 @@ pub(crate) mod private { #[cfg(feature = "async")] impl<'target> TargetPriv<'target> for AsyncGcFrame<'target> { // Safety: the pointer must point to valid data. - unsafe fn data_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn data_from_ptr<'data, T: Managed<'target, 'data>>( self, value: NonNull, _: Private, @@ -385,7 +380,7 @@ pub(crate) mod private { } // Safety: the pointer must point to valid data. - unsafe fn result_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn result_from_ptr<'data, T: Managed<'target, 'data>>( self, result: Result, NonNull>, _: Private, @@ -411,7 +406,7 @@ pub(crate) mod private { impl<'target> TargetPriv<'target> for Output<'target> { // Safety: the pointer must point to valid data. - unsafe fn data_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn data_from_ptr<'data, T: Managed<'target, 'data>>( self, value: NonNull, _: Private, @@ -420,7 +415,7 @@ pub(crate) mod private { } // Safety: the pointer must point to valid data. - unsafe fn result_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn result_from_ptr<'data, T: Managed<'target, 'data>>( self, result: Result, NonNull>, _: Private, @@ -446,7 +441,7 @@ pub(crate) mod private { impl<'target> TargetPriv<'target> for &'target mut Output<'_> { // Safety: the pointer must point to valid data. - unsafe fn data_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn data_from_ptr<'data, T: Managed<'target, 'data>>( self, value: NonNull, _: Private, @@ -455,7 +450,7 @@ pub(crate) mod private { } // Safety: the pointer must point to valid data. - unsafe fn result_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn result_from_ptr<'data, T: Managed<'target, 'data>>( self, result: Result, NonNull>, _: Private, @@ -481,7 +476,7 @@ pub(crate) mod private { impl<'target> TargetPriv<'target> for ReusableSlot<'target> { // Safety: the pointer must point to valid data. - unsafe fn data_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn data_from_ptr<'data, T: Managed<'target, 'data>>( self, value: NonNull, _: Private, @@ -490,7 +485,7 @@ pub(crate) mod private { } // Safety: the pointer must point to valid data. - unsafe fn result_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn result_from_ptr<'data, T: Managed<'target, 'data>>( self, result: Result, NonNull>, _: Private, @@ -516,7 +511,7 @@ pub(crate) mod private { impl<'target> TargetPriv<'target> for &mut ReusableSlot<'target> { // Safety: the pointer must point to valid data. - unsafe fn data_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn data_from_ptr<'data, T: Managed<'target, 'data>>( self, value: NonNull, _: Private, @@ -525,7 +520,7 @@ pub(crate) mod private { } // Safety: the pointer must point to valid data. - unsafe fn result_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn result_from_ptr<'data, T: Managed<'target, 'data>>( self, result: Result, NonNull>, _: Private, @@ -551,7 +546,7 @@ pub(crate) mod private { impl<'target> TargetPriv<'target> for Unrooted<'target> { // Safety: the pointer must point to valid data. - unsafe fn data_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn data_from_ptr<'data, T: Managed<'target, 'data>>( self, value: NonNull, _: Private, @@ -560,7 +555,7 @@ pub(crate) mod private { } // Safety: the pointer must point to valid data. - unsafe fn result_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn result_from_ptr<'data, T: Managed<'target, 'data>>( self, result: Result, NonNull>, _: Private, @@ -586,7 +581,7 @@ pub(crate) mod private { impl<'target, U: TargetPriv<'target>> TargetPriv<'target> for &U { // Safety: the pointer must point to valid data. - unsafe fn data_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn data_from_ptr<'data, T: Managed<'target, 'data>>( self, value: NonNull, _: Private, @@ -595,7 +590,7 @@ pub(crate) mod private { } // Safety: the pointer must point to valid data. - unsafe fn result_from_ptr<'data, T: Wrapper<'target, 'data>>( + unsafe fn result_from_ptr<'data, T: Managed<'target, 'data>>( self, result: Result, NonNull>, _: Private, diff --git a/jlrs/src/memory/target/output.rs b/jlrs/src/memory/target/output.rs index 6b079ffd..dae88285 100644 --- a/jlrs/src/memory/target/output.rs +++ b/jlrs/src/memory/target/output.rs @@ -2,7 +2,7 @@ use std::ptr::NonNull; -use crate::{memory::context::stack::Stack, private::Private, wrappers::ptr::Wrapper}; +use crate::{data::managed::Managed, memory::context::stack::Stack, private::Private}; /// A target that uses a reserved slot in a frame. /// @@ -75,7 +75,7 @@ pub struct Output<'target> { } impl<'scope> Output<'scope> { - pub(crate) unsafe fn consume<'data, T: Wrapper<'scope, 'data>>( + pub(crate) unsafe fn consume<'data, T: Managed<'scope, 'data>>( self, ptr: NonNull, ) -> T { @@ -83,7 +83,7 @@ impl<'scope> Output<'scope> { T::wrap_non_null(ptr, Private) } - pub(crate) unsafe fn temporary<'target, 'data, T: Wrapper<'target, 'data>>( + pub(crate) unsafe fn temporary<'target, 'data, T: Managed<'target, 'data>>( &'target mut self, ptr: NonNull, ) -> T { diff --git a/jlrs/src/memory/target/reusable_slot.rs b/jlrs/src/memory/target/reusable_slot.rs index 6a9fafd3..842e9dfc 100644 --- a/jlrs/src/memory/target/reusable_slot.rs +++ b/jlrs/src/memory/target/reusable_slot.rs @@ -3,9 +3,9 @@ use std::ptr::NonNull; use crate::{ + data::managed::{Managed, Ref}, memory::context::stack::Stack, private::Private, - wrappers::ptr::{Ref, Wrapper}, }; /// A target that uses a reserved slot in a frame. @@ -82,7 +82,7 @@ pub struct ReusableSlot<'target> { } impl<'scope> ReusableSlot<'scope> { - pub(crate) unsafe fn consume<'data, T: Wrapper<'scope, 'data>>( + pub(crate) unsafe fn consume<'data, T: Managed<'scope, 'data>>( self, ptr: NonNull, ) -> T { @@ -90,7 +90,7 @@ impl<'scope> ReusableSlot<'scope> { T::wrap_non_null(ptr, Private) } - pub(crate) unsafe fn temporary<'data, T: Wrapper<'scope, 'data>>( + pub(crate) unsafe fn temporary<'data, T: Managed<'scope, 'data>>( &mut self, ptr: NonNull, ) -> Ref<'scope, 'data, T> { diff --git a/jlrs/src/memory/target/target_type.rs b/jlrs/src/memory/target/target_type.rs index 51a8a1a9..2920a6d9 100644 --- a/jlrs/src/memory/target/target_type.rs +++ b/jlrs/src/memory/target/target_type.rs @@ -4,9 +4,9 @@ use super::reusable_slot::ReusableSlot; #[cfg(feature = "async")] use crate::memory::target::frame::AsyncGcFrame; use crate::{ + data::managed::{Managed, Ref}, error::{JuliaResult, JuliaResultRef}, memory::target::{frame::GcFrame, output::Output, unrooted::Unrooted}, - wrappers::ptr::{Ref, Wrapper}, }; /// Defines the return types of a target, `Data`, `Exception`, and `Result`. @@ -15,13 +15,13 @@ pub trait TargetType<'target>: Sized { /// /// For rooting targets, this type is `T`. /// For non-rooting targets, this type is [`Ref<'target, 'data, T>`]. - type Data<'data, T: Wrapper<'target, 'data>>; + type Data<'data, T: Managed<'target, 'data>>; /// Type returned by methods that catch Julia exceptions. /// /// For rooting targets, this type is [`JuliaResult<'target, 'data, T>`]. /// For non-rooting targets, this type is [`JuliaResultRef<'target, 'data, Ref<'target, 'data, T>>`]. - type Result<'data, T: Wrapper<'target, 'data>>; + type Result<'data, T: Managed<'target, 'data>>; /// Type returned by methods that don't return Julia data on succes, but can throw a Julia /// exception which is caught. @@ -32,66 +32,66 @@ pub trait TargetType<'target>: Sized { } impl<'target> TargetType<'target> for &mut GcFrame<'target> { - type Data<'data, T: Wrapper<'target, 'data>> = T; - type Result<'data, T: Wrapper<'target, 'data>> = JuliaResult<'target, 'data, T>; + type Data<'data, T: Managed<'target, 'data>> = T; + type Result<'data, T: Managed<'target, 'data>> = JuliaResult<'target, 'data, T>; type Exception<'data, T> = JuliaResult<'target, 'data, T>; } impl<'target> TargetType<'target> for GcFrame<'target> { - type Data<'data, T: Wrapper<'target, 'data>> = T; - type Result<'data, T: Wrapper<'target, 'data>> = JuliaResult<'target, 'data, T>; + type Data<'data, T: Managed<'target, 'data>> = T; + type Result<'data, T: Managed<'target, 'data>> = JuliaResult<'target, 'data, T>; type Exception<'data, T> = JuliaResult<'target, 'data, T>; } #[cfg(feature = "async")] impl<'target> TargetType<'target> for &mut AsyncGcFrame<'target> { - type Data<'data, T: Wrapper<'target, 'data>> = T; - type Result<'data, T: Wrapper<'target, 'data>> = JuliaResult<'target, 'data, T>; + type Data<'data, T: Managed<'target, 'data>> = T; + type Result<'data, T: Managed<'target, 'data>> = JuliaResult<'target, 'data, T>; type Exception<'data, T> = JuliaResult<'target, 'data, T>; } #[cfg(feature = "async")] impl<'target> TargetType<'target> for AsyncGcFrame<'target> { - type Data<'data, T: Wrapper<'target, 'data>> = T; - type Result<'data, T: Wrapper<'target, 'data>> = JuliaResult<'target, 'data, T>; + type Data<'data, T: Managed<'target, 'data>> = T; + type Result<'data, T: Managed<'target, 'data>> = JuliaResult<'target, 'data, T>; type Exception<'data, T> = JuliaResult<'target, 'data, T>; } impl<'target> TargetType<'target> for Output<'target> { - type Data<'data, T: Wrapper<'target, 'data>> = T; - type Result<'data, T: Wrapper<'target, 'data>> = JuliaResult<'target, 'data, T>; + type Data<'data, T: Managed<'target, 'data>> = T; + type Result<'data, T: Managed<'target, 'data>> = JuliaResult<'target, 'data, T>; type Exception<'data, T> = JuliaResult<'target, 'data, T>; } impl<'target> TargetType<'target> for &'target mut Output<'_> { - type Data<'data, T: Wrapper<'target, 'data>> = T; - type Result<'data, T: Wrapper<'target, 'data>> = JuliaResult<'target, 'data, T>; + type Data<'data, T: Managed<'target, 'data>> = T; + type Result<'data, T: Managed<'target, 'data>> = JuliaResult<'target, 'data, T>; type Exception<'data, T> = JuliaResult<'target, 'data, T>; } impl<'target> TargetType<'target> for ReusableSlot<'target> { - type Data<'data, T: Wrapper<'target, 'data>> = T; - type Result<'data, T: Wrapper<'target, 'data>> = JuliaResult<'target, 'data, T>; + type Data<'data, T: Managed<'target, 'data>> = T; + type Result<'data, T: Managed<'target, 'data>> = JuliaResult<'target, 'data, T>; type Exception<'data, T> = JuliaResult<'target, 'data, T>; } impl<'target> TargetType<'target> for &mut ReusableSlot<'target> { - type Data<'data, T: Wrapper<'target, 'data>> = Ref<'target, 'data, T>; - type Result<'data, T: Wrapper<'target, 'data>> = + type Data<'data, T: Managed<'target, 'data>> = Ref<'target, 'data, T>; + type Result<'data, T: Managed<'target, 'data>> = JuliaResultRef<'target, 'data, Ref<'target, 'data, T>>; type Exception<'data, T> = JuliaResultRef<'target, 'data, T>; } impl<'target> TargetType<'target> for Unrooted<'target> { - type Data<'data, T: Wrapper<'target, 'data>> = Ref<'target, 'data, T>; - type Result<'data, T: Wrapper<'target, 'data>> = + type Data<'data, T: Managed<'target, 'data>> = Ref<'target, 'data, T>; + type Result<'data, T: Managed<'target, 'data>> = JuliaResultRef<'target, 'data, Ref<'target, 'data, T>>; type Exception<'data, T> = JuliaResultRef<'target, 'data, T>; } impl<'target, U: TargetType<'target>> TargetType<'target> for &U { - type Data<'data, T: Wrapper<'target, 'data>> = Ref<'target, 'data, T>; - type Result<'data, T: Wrapper<'target, 'data>> = + type Data<'data, T: Managed<'target, 'data>> = Ref<'target, 'data, T>; + type Result<'data, T: Managed<'target, 'data>> = JuliaResultRef<'target, 'data, Ref<'target, 'data, T>>; type Exception<'data, T> = JuliaResultRef<'target, 'data, T>; } diff --git a/jlrs/src/prelude.rs b/jlrs/src/prelude.rs index dd6c5809..ed170ce1 100644 --- a/jlrs/src/prelude.rs +++ b/jlrs/src/prelude.rs @@ -26,12 +26,9 @@ pub use crate::{ pub use crate::{ call::{Call, ProvideKeywords}, convert::into_jlrs_result::IntoJlrsResult, - error::JlrsResult, - memory::target::{target_type::TargetType, Target}, - named_tuple, - wrappers::{ - inline::{bool::Bool, char::Char, nothing::Nothing, tuple::*}, - ptr::{ + data::{ + layout::{bool::Bool, char::Char, nothing::Nothing, tuple::*}, + managed::{ array::ArrayRef, array::TypedArrayRef, array::{tracked::ArrayWrapper, Array, TypedArray}, @@ -44,9 +41,12 @@ pub use crate::{ symbol::Symbol, value::Value, value::ValueRef, - /* Ref, */ Wrapper, + /* Ref, */ Managed, }, }, + error::JlrsResult, + memory::target::{target_type::TargetType, Target}, + named_tuple, }; #[cfg(feature = "sync-rt")] pub use crate::{ diff --git a/jlrs/src/pyplot/mod.rs b/jlrs/src/pyplot/mod.rs index 6d36b1d2..4e795371 100644 --- a/jlrs/src/pyplot/mod.rs +++ b/jlrs/src/pyplot/mod.rs @@ -13,14 +13,14 @@ use crate::{call::CallAsync, memory::target::frame::AsyncGcFrame}; use crate::{ call::{Call, ProvideKeywords}, convert::into_jlrs_result::IntoJlrsResult, - error::JlrsResult, - memory::target::{frame::GcFrame, Target}, - wrappers::ptr::{ + data::managed::{ function::Function, module::Module, value::{Value, MAX_SIZE}, - Wrapper, + Managed, }, + error::JlrsResult, + memory::target::{frame::GcFrame, Target}, }; init_fn!(init_jlrs_py_plot, JLRS_PY_PLOT_JL, "JlrsPyPlot.jl"); @@ -62,10 +62,10 @@ impl<'scope> PyPlot<'scope> { let plt = Module::main(&frame) .submodule(&frame, "JlrsPyPlot") .unwrap() - .wrapper() + .as_managed() .function(&frame, "jlrsplot") .unwrap() - .wrapper() + .as_managed() .call(frame, vals) .into_jlrs_result()?; @@ -97,10 +97,10 @@ impl<'scope> PyPlot<'scope> { let plt = Module::main(&frame) .submodule(&frame, "JlrsPyPlot") .unwrap() - .wrapper() + .as_managed() .function(&frame, "jlrsplot") .unwrap() - .wrapper() + .as_managed() .provide_keywords(keywords)? .call(frame, vals) .into_jlrs_result()?; @@ -133,10 +133,10 @@ impl<'scope> PyPlot<'scope> { Module::main(&frame) .submodule(&frame, "JlrsPyPlot") .unwrap() - .wrapper() + .as_managed() .function(&frame, "updateplot!") .unwrap() - .wrapper() + .as_managed() .call(frame, vals) .into_jlrs_result()? .unbox::() @@ -168,10 +168,10 @@ impl<'scope> PyPlot<'scope> { Module::main(&frame) .submodule(&frame, "JlrsPyPlot") .unwrap() - .wrapper() + .as_managed() .function(&frame, "updateplot!") .unwrap() - .wrapper() + .as_managed() .provide_keywords(keywords)? .call(frame, vals) .into_jlrs_result()? @@ -183,7 +183,7 @@ impl<'scope> PyPlot<'scope> { unsafe { Module::base(&frame) .function(&frame, "wait")? - .wrapper() + .as_managed() .call1(frame, self.0) .into_jlrs_result()?; @@ -206,10 +206,10 @@ impl<'scope> PyPlot<'scope> { Module::main(&frame) .submodule(&frame, "JlrsPyPlot") .unwrap() - .wrapper() + .as_managed() .function(&frame, "setversion") .unwrap() - .wrapper() + .as_managed() .call1(frame, version) .into_jlrs_result()?; @@ -224,7 +224,7 @@ impl<'scope> PyPlot<'scope> { unsafe { Module::base(&frame) .function(&frame, "wait")? - .wrapper() + .as_managed() .call_async_main(frame, &mut [self.0]) .await .into_jlrs_result()?; @@ -243,7 +243,7 @@ impl<'scope> PyPlot<'scope> { unsafe { Module::base(&frame) .function(&frame, "wait")? - .wrapper() + .as_managed() .call_async_interactive(frame, &mut [self.0]) .await .into_jlrs_result()?; @@ -262,7 +262,7 @@ impl<'scope> PyPlot<'scope> { unsafe { Module::base(&frame) .function(&frame, "wait")? - .wrapper() + .as_managed() .call_async_local(frame, &mut [self.0]) .await .into_jlrs_result()?; @@ -278,7 +278,7 @@ impl<'scope> PyPlot<'scope> { unsafe { Module::base(&frame) .function(&frame, "wait")? - .wrapper() + .as_managed() .call_async(frame, &mut [self.0]) .await .into_jlrs_result()?; @@ -297,10 +297,10 @@ pub trait AccessPlotsModule: private::AccessPlotsModulePriv { Module::main(target) .submodule(target, "JlrsPyPlot") .unwrap() - .wrapper() + .as_managed() .submodule(target, "Plots") .unwrap() - .wrapper() + .as_managed() } } } @@ -308,7 +308,7 @@ pub trait AccessPlotsModule: private::AccessPlotsModulePriv { impl<'scope> AccessPlotsModule for Module<'scope> {} mod private { - use crate::wrappers::ptr::module::Module; + use crate::data::managed::module::Module; pub trait AccessPlotsModulePriv {} diff --git a/jlrs/src/runtime/async_rt/async_std_rt.rs b/jlrs/src/runtime/async_rt/async_std_rt.rs index c3801a15..72d74168 100644 --- a/jlrs/src/runtime/async_rt/async_std_rt.rs +++ b/jlrs/src/runtime/async_rt/async_std_rt.rs @@ -15,12 +15,7 @@ use async_trait::async_trait; use crate::{ async_util::channel::{ - Channel, - ChannelReceiver, - ChannelSender, - OneshotSender, - SendError, - TrySendError, + Channel, ChannelReceiver, ChannelSender, OneshotSender, SendError, TrySendError, }, error::{JlrsError, JlrsResult}, runtime::async_rt::{AsyncRuntime, Message}, diff --git a/jlrs/src/runtime/async_rt/mod.rs b/jlrs/src/runtime/async_rt/mod.rs index c069cfe0..e96d76fd 100644 --- a/jlrs/src/runtime/async_rt/mod.rs +++ b/jlrs/src/runtime/async_rt/mod.rs @@ -43,12 +43,7 @@ use std::{ use async_trait::async_trait; use futures::Future; use jl_sys::{ - jl_atexit_hook, - jl_init, - jl_init_with_image, - jl_is_initialized, - jl_options, - jl_process_events, + jl_atexit_hook, jl_init, jl_init_with_image, jl_is_initialized, jl_options, jl_process_events, jl_yield, }; #[cfg(any(feature = "julia-1-10", feature = "julia-1-9"))] @@ -62,24 +57,14 @@ use crate::{ channel::{Channel, ChannelSender, OneshotSender, TrySendError}, future::wake_task, internal::{ - BlockingTask, - BlockingTaskEnvelope, - CallPersistentTask, - IncludeTask, - IncludeTaskEnvelope, - InnerPersistentMessage, - PendingTask, - PendingTaskEnvelope, - Persistent, - PersistentComms, - RegisterPersistent, - RegisterTask, - SetErrorColorTask, - SetErrorColorTaskEnvelope, - Task, + BlockingTask, BlockingTaskEnvelope, CallPersistentTask, IncludeTask, + IncludeTaskEnvelope, InnerPersistentMessage, PendingTask, PendingTaskEnvelope, + Persistent, PersistentComms, RegisterPersistent, RegisterTask, SetErrorColorTask, + SetErrorColorTaskEnvelope, Task, }, task::{sleep, Affinity, AsyncTask, PersistentTask}, }, + data::managed::{module::Module, value::Value}, error::{IOError, JlrsError, JlrsResult, RuntimeError}, memory::{ context::stack::Stack, @@ -87,7 +72,6 @@ use crate::{ target::{frame::GcFrame, unrooted::Unrooted}, }, runtime::{builder::AsyncRuntimeBuilder, init_jlrs, INIT}, - wrappers::ptr::{module::Module, value::Value}, }; #[cfg(any(feature = "julia-1-10", feature = "julia-1-9"))] @@ -816,12 +800,12 @@ fn set_custom_fns(stack: &Stack) -> JlrsResult<()> { let jlrs_mod = Module::main(&frame) .submodule(&frame, "JlrsMultitask")? - .wrapper(); + .as_managed(); let wake_rust = Value::new(&mut frame, wake_task as *mut c_void); jlrs_mod .global(&frame, "wakerust")? - .wrapper() + .as_managed() .set_nth_field_unchecked(0, wake_rust); std::mem::drop(owner); diff --git a/jlrs/src/runtime/async_rt/tokio_rt.rs b/jlrs/src/runtime/async_rt/tokio_rt.rs index de80b45c..cc8cf05c 100644 --- a/jlrs/src/runtime/async_rt/tokio_rt.rs +++ b/jlrs/src/runtime/async_rt/tokio_rt.rs @@ -18,22 +18,14 @@ use async_trait::async_trait; use tokio::{ runtime::Builder, sync::mpsc::{ - Receiver as BoundedReceiver, - Sender as BoundedSender, - UnboundedReceiver, - UnboundedSender, + Receiver as BoundedReceiver, Sender as BoundedSender, UnboundedReceiver, UnboundedSender, }, task::{JoinError, JoinHandle, LocalSet}, }; use crate::{ async_util::channel::{ - Channel, - ChannelReceiver, - ChannelSender, - OneshotSender, - SendError, - TrySendError, + Channel, ChannelReceiver, ChannelSender, OneshotSender, SendError, TrySendError, }, error::{JlrsError, JlrsResult}, runtime::async_rt::{AsyncRuntime, Message}, diff --git a/jlrs/src/runtime/sync_rt.rs b/jlrs/src/runtime/sync_rt.rs index b5d2fa19..cd3422f2 100644 --- a/jlrs/src/runtime/sync_rt.rs +++ b/jlrs/src/runtime/sync_rt.rs @@ -10,6 +10,7 @@ use jl_sys::{jl_atexit_hook, jl_init, jl_init_with_image, jl_is_initialized}; use crate::{ call::Call, convert::into_jlrs_result::IntoJlrsResult, + data::managed::{module::Module, string::JuliaString, value::Value, Managed}, error::{IOError, JlrsResult, RuntimeError}, memory::{ context::stack::Stack, @@ -17,7 +18,6 @@ use crate::{ target::frame::GcFrame, }, runtime::{builder::RuntimeBuilder, init_jlrs, INIT}, - wrappers::ptr::{module::Module, string::JuliaString, value::Value, Wrapper}, }; /// A pending Julia instance. @@ -126,9 +126,9 @@ impl Julia<'_> { Module::main(&frame) .submodule(&frame, "Jlrs")? - .wrapper() + .as_managed() .global(&frame, "color")? - .value() + .as_value() .set_field_unchecked("x", enable) })?; @@ -162,7 +162,7 @@ impl Julia<'_> { let path_jl_str = JuliaString::new(&mut frame, path.as_ref().to_string_lossy()); Module::main(&frame) .function(&frame, "include")? - .wrapper() + .as_managed() .call1(&mut frame, path_jl_str.as_value()) .into_jlrs_result() .map(|_| ()) diff --git a/jlrs/src/safety.rs b/jlrs/src/safety.rs index 882e2f3a..ed480e81 100644 --- a/jlrs/src/safety.rs +++ b/jlrs/src/safety.rs @@ -100,8 +100,8 @@ //! in Rust. Exceptions in Julia are implemented as jumps, and jumping over a Rust function back //! to Julia is undefined behavior. //! -//! [`Bool`]: crate::wrappers::inline::bool::Bool -//! [`Char`]: crate::wrappers::inline::char::Char -//! [`Value`]: crate::wrappers::ptr::value::Value -//! [`Array`]: crate::wrappers::ptr::array::Array -//! [`TypedArray`]: crate::wrappers::ptr::array::TypedArray +//! [`Bool`]: crate::data::layout::bool::Bool +//! [`Char`]: crate::data::layout::char::Char +//! [`Value`]: crate::data::managed::value::Value +//! [`Array`]: crate::data::managed::array::Array +//! [`TypedArray`]: crate::data::managed::array::TypedArray diff --git a/jlrs/tests/abstract_fields.rs b/jlrs/tests/abstract_fields.rs index a417520d..7b0304ff 100644 --- a/jlrs/tests/abstract_fields.rs +++ b/jlrs/tests/abstract_fields.rs @@ -16,9 +16,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "WithAbstract")? - .value() + .as_value() }; let arg1 = Value::new(&mut frame, 3u32); diff --git a/jlrs/tests/access_fields.rs b/jlrs/tests/access_fields.rs index d7705471..376f2e21 100644 --- a/jlrs/tests/access_fields.rs +++ b/jlrs/tests/access_fields.rs @@ -6,7 +6,7 @@ mod tests { use jlrs::{convert::to_symbol::ToSymbol, prelude::*}; #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] - use jlrs::{layout::typecheck::Mutable, wrappers::inline::union::EmptyUnion}; + use jlrs::{data::layout::union::EmptyUnion, layout::typecheck::Mutable}; use super::util::{JULIA, MIXED_BAG_JL}; @@ -20,9 +20,9 @@ mod tests { let mut tys = [Value::new(&mut frame, 0usize)]; let res = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "WithEmpty")? - .wrapper() + .as_managed() .apply_type(&mut frame, &mut tys) .into_jlrs_result()? .cast::()? @@ -49,9 +49,9 @@ mod tests { // Returns (1, 2, 3) as Tuple{UInt32, UInt16, Int64} let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "inlinetuple")? - .wrapper(); + .as_managed(); let tup = func.call0(&mut frame).unwrap(); assert!(tup.is::()); @@ -80,9 +80,9 @@ mod tests { // Returns (1, 2, 3) as Tuple{UInt32, UInt16, Int64} let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "inlinetuple")? - .wrapper(); + .as_managed(); let tup = func.call0(&mut frame).unwrap(); assert!(tup.get_nth_field(&mut frame, 3).is_err()); @@ -101,9 +101,9 @@ mod tests { // Returns (1, 2, 3) as Tuple{UInt32, UInt16, Int64} let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "inlinetuple")? - .wrapper(); + .as_managed(); let tup = func.call0(&mut frame).unwrap(); assert!(tup.get_nth_field_ref(2).is_err()); @@ -126,9 +126,9 @@ mod tests { //end let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "MutableStruct")? - .wrapper() + .as_managed() .cast::()?; let x = Value::new(&mut frame, 2.0f32); @@ -143,7 +143,7 @@ mod tests { let x_val = mut_struct.get_field_ref("x"); assert!(x_val.is_ok()); { - assert!(x_val.unwrap().unwrap().wrapper().is::()); + assert!(x_val.unwrap().unwrap().as_managed().is::()); } let output = frame.output(); let _ = frame.scope(|_| mut_struct.get_field(output, "y"))?; @@ -168,9 +168,9 @@ mod tests { //end let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "MutableStruct")? - .wrapper() + .as_managed() .cast::()?; let x = Value::new(&mut frame, 2.0f32); @@ -199,7 +199,9 @@ mod tests { let idx = Value::new(&mut frame, 4usize); let data = vec![1.0f64, 2., 3.]; let array = Array::from_vec_unchecked(frame.as_extended_target(), data, 3)?; - let func = Module::base(&frame).function(&frame, "getindex")?.wrapper(); + let func = Module::base(&frame) + .function(&frame, "getindex")? + .as_managed(); let out = func.call2(&mut frame, array.as_value(), idx).unwrap_err(); assert_eq!(out.datatype_name().unwrap(), "BoundsError"); @@ -232,7 +234,9 @@ mod tests { let idx = Value::new(&mut frame, 4usize); let data = vec![1.0f64, 2., 3.]; let array = Array::from_vec_unchecked(frame.as_extended_target(), data, 3)?; - let func = Module::base(&frame).function(&frame, "getindex")?.wrapper(); + let func = Module::base(&frame) + .function(&frame, "getindex")? + .as_managed(); let out = func.call2(&mut frame, array.as_value(), idx).unwrap_err(); let field_names = out.field_names(); @@ -256,7 +260,9 @@ mod tests { let idx = Value::new(&mut frame, 4usize); let data = vec![1.0f64, 2., 3.]; let array = Array::from_vec_unchecked(frame.as_extended_target(), data, 3)?; - let func = Module::base(&frame).function(&frame, "getindex")?.wrapper(); + let func = Module::base(&frame) + .function(&frame, "getindex")? + .as_managed(); let out = func.call2(&mut frame, array.as_value(), idx).unwrap_err(); let field_names = out.field_names(); @@ -282,7 +288,9 @@ mod tests { let idx = Value::new(&mut frame, 4usize); let data = vec![1.0f64, 2., 3.]; let array = Array::from_vec_unchecked(frame.as_extended_target(), data, 3)?; - let func = Module::base(&frame).function(&frame, "getindex")?.wrapper(); + let func = Module::base(&frame) + .function(&frame, "getindex")? + .as_managed(); let out = func.call2(&mut frame, array.as_value(), idx).unwrap_err(); let field_names = out.field_names(); @@ -309,7 +317,7 @@ mod tests { .into_jlrs_result()? .cast::()? .global(&frame, "mixedbag")? - .wrapper(); + .as_managed(); { let field = value @@ -364,7 +372,7 @@ mod tests { .field("normal_union")? .access::()?; - assert_eq!(field.wrapper(), Module::main(&frame)); + assert_eq!(field.as_managed(), Module::main(&frame)); } #[cfg(not(feature = "julia-1-6"))] @@ -435,7 +443,7 @@ mod tests { .field("ptr")? .access::()?; - assert_eq!(field.wrapper(), Module::main(&frame)); + assert_eq!(field.as_managed(), Module::main(&frame)); } { @@ -447,7 +455,7 @@ mod tests { .field((0,))? .access::()?; - assert_eq!(field.wrapper(), Module::base(&frame)); + assert_eq!(field.as_managed(), Module::base(&frame)); } } @@ -492,7 +500,7 @@ mod tests { .field("normal_union")? .access::()?; - assert_eq!(field.wrapper(), Module::main(&frame)); + assert_eq!(field.as_managed(), Module::main(&frame)); } { @@ -585,7 +593,7 @@ mod tests { .field("ptr")? .access::()?; - assert_eq!(field.wrapper(), Module::main(&frame)); + assert_eq!(field.as_managed(), Module::main(&frame)); } { @@ -597,7 +605,7 @@ mod tests { .field((0,))? .access::()?; - assert_eq!(field.wrapper(), Module::base(&frame)); + assert_eq!(field.as_managed(), Module::base(&frame)); } } { @@ -716,7 +724,7 @@ mod tests { .field(1)? .access::()?; - assert_eq!(field.wrapper(), Module::base(&frame)); + assert_eq!(field.as_managed(), Module::base(&frame)); } { diff --git a/jlrs/tests/access_raw_field.rs b/jlrs/tests/access_raw_field.rs index 61c4f64f..d2fa8f0e 100644 --- a/jlrs/tests/access_raw_field.rs +++ b/jlrs/tests/access_raw_field.rs @@ -15,9 +15,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "NoUnionsBits")? - .value() + .as_value() }; let arg1 = Value::new(&mut frame, 3i16); let arg2 = Value::new(&mut frame, -3i32); @@ -47,9 +47,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "NoUnionsBitsPtr")? - .value() + .as_value() }; let arg1 = Value::new(&mut frame, 3i16); let arg2 = DataType::bool_type(&frame); @@ -65,7 +65,7 @@ mod tests { .field_accessor() .field("b")? .access::()?; - assert_eq!(unsafe { b.wrapper() }, arg2); + assert_eq!(unsafe { b.as_managed() }, arg2); Ok(()) }) @@ -82,9 +82,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "BitsBitsUnion")? - .value() + .as_value() }; let arg1 = Value::new(&mut frame, 3i16); let arg2 = Value::new(&mut frame, -3i32); @@ -114,9 +114,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "PtrBitsUnion")? - .value() + .as_value() }; let arg1 = DataType::bool_type(&frame); let arg2 = Value::new(&mut frame, -3i32); @@ -129,7 +129,7 @@ mod tests { .field_accessor() .field("a")? .access::()?; - assert_eq!(unsafe { a.wrapper() }, arg1); + assert_eq!(unsafe { a.as_managed() }, arg1); let b = instance.field_accessor().field("b")?.access::()?; assert_eq!(b, -3); @@ -149,9 +149,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "PtrNonBitsUnion")? - .value() + .as_value() }; let arg1 = DataType::bool_type(&frame); let arg2 = Value::new(&mut frame, -3i32); @@ -164,7 +164,7 @@ mod tests { .field_accessor() .field("a")? .access::()?; - assert_eq!(unsafe { a.wrapper() }, arg1); + assert_eq!(unsafe { a.as_managed() }, arg1); let b = instance.field_accessor().field("b")?.access::()?; assert_eq!(b, -3); @@ -184,9 +184,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "PtrNonBitsUnion")? - .value() + .as_value() }; let arg1 = DataType::bool_type(&frame); let arg2 = Value::new(&mut frame, -3i32); @@ -219,9 +219,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "HasArray")? - .value() + .as_value() }; let data = vec![1.0, 2.0, 3.0, 4.0]; let arg1 = Array::from_vec(frame.as_extended_target(), data, (2, 2))? @@ -262,9 +262,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "UaArray")? - .value() + .as_value() }; let data = vec![1.0, 2.0, 3.0, 4.0]; let arg1 = Array::from_vec(frame.as_extended_target(), data, (2, 2))? @@ -305,9 +305,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "PtrNonBitsUnion")? - .value() + .as_value() }; let arg1 = DataType::bool_type(&frame); let arg2 = Value::new(&mut frame, -3i32); @@ -332,9 +332,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "NoUnionsBits")? - .value() + .as_value() }; let arg1 = Value::new(&mut frame, 3i16); let arg2 = Value::new(&mut frame, -3i32); @@ -364,9 +364,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "NoUnionsBitsPtr")? - .value() + .as_value() }; let arg1 = Value::new(&mut frame, 3i16); let arg2 = DataType::bool_type(&frame); @@ -382,7 +382,7 @@ mod tests { .field_accessor() .field(1)? .access::()?; - assert_eq!(unsafe { b.wrapper() }, arg2); + assert_eq!(unsafe { b.as_managed() }, arg2); Ok(()) }) @@ -399,9 +399,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "BitsBitsUnion")? - .value() + .as_value() }; let arg1 = Value::new(&mut frame, 3i16); let arg2 = Value::new(&mut frame, -3i32); @@ -431,9 +431,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "PtrNonBitsUnion")? - .value() + .as_value() }; let arg1 = DataType::bool_type(&frame); let arg2 = Value::new(&mut frame, -3i32); @@ -446,7 +446,7 @@ mod tests { .field_accessor() .field(0)? .access::()?; - assert_eq!(unsafe { a.wrapper() }, arg1); + assert_eq!(unsafe { a.as_managed() }, arg1); let b = instance.field_accessor().field(1)?.access::()?; assert_eq!(b, -3); @@ -466,9 +466,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "PtrNonBitsUnion")? - .value() + .as_value() }; let arg1 = DataType::bool_type(&frame); let arg2 = Value::new(&mut frame, -3i32); @@ -501,9 +501,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "HasArray")? - .value() + .as_value() }; let data = vec![1.0, 2.0, 3.0, 4.0]; let arg1 = Array::from_vec(frame.as_extended_target(), data, (2, 2))? @@ -544,9 +544,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "UaArray")? - .value() + .as_value() }; let data = vec![1.0, 2.0, 3.0, 4.0]; let arg1 = Array::from_vec(frame.as_extended_target(), data, (2, 2))? @@ -587,9 +587,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "PtrNonBitsUnion")? - .value() + .as_value() }; let arg1 = DataType::bool_type(&frame); let arg2 = Value::new(&mut frame, -3i32); diff --git a/jlrs/tests/arrays.rs b/jlrs/tests/arrays.rs index 05cf9a88..0c204200 100644 --- a/jlrs/tests/arrays.rs +++ b/jlrs/tests/arrays.rs @@ -4,9 +4,7 @@ mod util; #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] mod tests { use jlrs::{ - layout::valid_layout::ValidLayout, - prelude::*, - wrappers::ptr::array::dimensions::Dims, + data::managed::array::dimensions::Dims, layout::valid_layout::ValidLayout, prelude::*, }; use crate::util::JULIA; diff --git a/jlrs/tests/async_std_rt.rs b/jlrs/tests/async_std_rt.rs index d8b43d9e..43bf3e94 100644 --- a/jlrs/tests/async_std_rt.rs +++ b/jlrs/tests/async_std_rt.rs @@ -483,7 +483,7 @@ mod tests { Module::base(&frame) .function(&frame, "+") .unwrap() - .wrapper() + .as_managed() .call2(&mut frame, one, one) .into_jlrs_result()? .unbox::() diff --git a/jlrs/tests/atomic_fields.rs b/jlrs/tests/atomic_fields.rs index d6366bf5..829ff900 100644 --- a/jlrs/tests/atomic_fields.rs +++ b/jlrs/tests/atomic_fields.rs @@ -15,9 +15,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsStableTests")? - .wrapper() + .as_managed() .global(&frame, "WithAtomic")? - .value() + .as_value() }; let arg1 = Value::new(&mut frame, 3u32); @@ -44,9 +44,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsStableTests")? - .wrapper() + .as_managed() .global(&frame, "WithLargeAtomic")? - .value() + .as_value() }; let tup = Value::new(&mut frame, Tuple4(1u64, 2u64, 3u64, 4u64)); @@ -77,9 +77,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsStableTests")? - .wrapper() + .as_managed() .global(&frame, "WithOddlySizedAtomic")? - .value() + .as_value() }; let tup = Value::new(&mut frame, Tuple2(1u32, 2u16)); @@ -110,9 +110,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsStableTests")? - .wrapper() + .as_managed() .global(&frame, "WithAtomicUnion")? - .value() + .as_value() }; assert!(ty.cast::()?.is_pointer_field(0)?); @@ -137,7 +137,7 @@ mod tests { DataType::datatype_type(&frame) .type_name() .cache(&frame) - .wrapper() + .as_managed() .len(), 0 ) diff --git a/jlrs/tests/borrow_array.rs b/jlrs/tests/borrow_array.rs index 6bd514a6..83683d23 100644 --- a/jlrs/tests/borrow_array.rs +++ b/jlrs/tests/borrow_array.rs @@ -3,7 +3,7 @@ mod util; #[cfg(feature = "sync-rt")] #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] mod tests { - use jlrs::{prelude::*, wrappers::ptr::array::dimensions::Dims}; + use jlrs::{data::managed::array::dimensions::Dims, prelude::*}; use crate::util::JULIA; @@ -53,7 +53,7 @@ mod tests { Module::base(&frame) .function(&frame, "sum")? - .wrapper() + .as_managed() .call1(&mut frame, array.as_value()) .unwrap() .unbox::() diff --git a/jlrs/tests/borrow_array_data.rs b/jlrs/tests/borrow_array_data.rs index ec276dca..eb17c679 100644 --- a/jlrs/tests/borrow_array_data.rs +++ b/jlrs/tests/borrow_array_data.rs @@ -4,9 +4,9 @@ mod util; #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] mod tests { use jlrs::{ + data::managed::array::dimensions::Dims, memory::gc::{Gc, GcCollection}, prelude::*, - wrappers::ptr::array::dimensions::Dims, }; use crate::util::JULIA; @@ -36,7 +36,9 @@ mod tests { } } - let gi = Module::base(&frame).function(&frame, "getindex")?.wrapper(); + let gi = Module::base(&frame) + .function(&frame, "getindex")? + .as_managed(); let one = Value::new(&mut frame, 1usize); let two = Value::new(&mut frame, 2usize); let three = Value::new(&mut frame, 3usize); @@ -91,7 +93,9 @@ mod tests { } } } - let gi = Module::base(&frame).function(&frame, "getindex")?.wrapper(); + let gi = Module::base(&frame) + .function(&frame, "getindex")? + .as_managed(); let one = Value::new(&mut frame, 1usize); let two = Value::new(&mut frame, 2usize); let three = Value::new(&mut frame, 3usize); @@ -281,7 +285,9 @@ mod tests { } } - let gi = Module::base(&frame).function(&frame, "getindex")?.wrapper(); + let gi = Module::base(&frame) + .function(&frame, "getindex")? + .as_managed(); let one = Value::new(&mut frame, 1usize); let two = Value::new(&mut frame, 2usize); let three = Value::new(&mut frame, 3usize); @@ -363,15 +369,15 @@ mod tests { unsafe { let arr = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "vecofmodules")? - .wrapper() + .as_managed() .call0(&mut frame) .unwrap() .cast::()?; let data = { arr.value_data()? }; - assert!(data[0].unwrap().wrapper().is::()); + assert!(data[0].unwrap().as_managed().is::()); } Ok(()) }) @@ -389,17 +395,19 @@ mod tests { unsafe { let submod = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper(); + .as_managed(); let mut arr = submod .function(&frame, "vecofmodules")? - .wrapper() + .as_managed() .call0(&mut frame) .unwrap() .cast::()?; let mut data = { arr.value_data_mut()? }; data.set(0, Some(submod.as_value()))?; - let getindex = Module::base(&frame).function(&frame, "getindex")?.wrapper(); + let getindex = Module::base(&frame) + .function(&frame, "getindex")? + .as_managed(); let idx = Value::new(&mut frame, 1usize); let entry = getindex .call2(&mut frame, arr.as_value(), idx) @@ -424,15 +432,15 @@ mod tests { unsafe { let arr = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "vecofmodules")? - .wrapper() + .as_managed() .call0(&mut frame) .unwrap() .cast::>>()?; let data = { arr.value_data()? }; - assert!(data[0].unwrap().wrapper().is::()); + assert!(data[0].unwrap().as_managed().is::()); } Ok(()) }) @@ -450,17 +458,19 @@ mod tests { unsafe { let submod = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper(); + .as_managed(); let mut arr = submod .function(&frame, "vecofmodules")? - .wrapper() + .as_managed() .call0(&mut frame) .unwrap() .cast::>>()?; let mut data = { arr.value_data_mut()? }; data.set(0, Some(submod.as_value()))?; - let getindex = Module::base(&frame).function(&frame, "getindex")?.wrapper(); + let getindex = Module::base(&frame) + .function(&frame, "getindex")? + .as_managed(); let idx = Value::new(&mut frame, 1usize); let entry = getindex .call2(&mut frame, arr.as_value(), idx) diff --git a/jlrs/tests/bounds_error.rs b/jlrs/tests/bounds_error.rs index a16cf0a2..c77da7b2 100644 --- a/jlrs/tests/bounds_error.rs +++ b/jlrs/tests/bounds_error.rs @@ -19,7 +19,9 @@ mod tests { let data = vec![1.0f64, 2., 3.]; let array = Array::from_vec(frame.as_extended_target(), data, 3)? .into_jlrs_result()?; - let func = Module::base(&frame).function(&frame, "getindex")?.wrapper(); + let func = Module::base(&frame) + .function(&frame, "getindex")? + .as_managed(); let out = func.call2(&mut frame, array.as_value(), idx).unwrap_err(); assert_eq!(out.datatype_name().unwrap(), "BoundsError"); diff --git a/jlrs/tests/call_exception.rs b/jlrs/tests/call_exception.rs index 25a612c7..5d35b59b 100644 --- a/jlrs/tests/call_exception.rs +++ b/jlrs/tests/call_exception.rs @@ -15,9 +15,9 @@ mod tests { .scope(|mut frame| unsafe { let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "throws_exception")? - .wrapper(); + .as_managed(); let res = func.call0(&mut frame); assert!(res.is_err()); @@ -39,9 +39,9 @@ mod tests { let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "throws_exception")? - .wrapper() + .as_managed() .provide_keywords(kw)?; let res = func.call0(&mut frame); @@ -62,9 +62,9 @@ mod tests { let arg = Value::new(&mut frame, 1usize); let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "throws_exception")? - .wrapper(); + .as_managed(); let res = func.call1(&mut frame, arg); assert!(res.is_err()); @@ -86,9 +86,9 @@ mod tests { let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "throws_exception")? - .wrapper() + .as_managed() .provide_keywords(kw)?; let res = func.call1(&mut frame, arg); @@ -109,9 +109,9 @@ mod tests { let arg = Value::new(&mut frame, 1usize); let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "throws_exception")? - .wrapper(); + .as_managed(); let res = func.call2(&mut frame, arg, arg); assert!(res.is_err()); @@ -133,9 +133,9 @@ mod tests { let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "throws_exception")? - .wrapper() + .as_managed() .provide_keywords(kw)?; let res = func.call2(&mut frame, arg, arg); @@ -156,9 +156,9 @@ mod tests { let arg = Value::new(&mut frame, 1usize); let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "throws_exception")? - .wrapper(); + .as_managed(); let res = func.call3(&mut frame, arg, arg, arg); assert!(res.is_err()); @@ -180,9 +180,9 @@ mod tests { let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "throws_exception")? - .wrapper() + .as_managed() .provide_keywords(kw)?; let res = func.call3(&mut frame, arg, arg, arg); @@ -202,9 +202,9 @@ mod tests { .scope(|mut frame| unsafe { let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "throws_exception")? - .wrapper(); + .as_managed(); let res = func.call(&mut frame, []); assert!(res.is_err()); @@ -226,9 +226,9 @@ mod tests { let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "throws_exception")? - .wrapper() + .as_managed() .provide_keywords(kw)?; let res = func.call(&mut frame, []); diff --git a/jlrs/tests/ccall.rs b/jlrs/tests/ccall.rs index e09a57f3..4caa4364 100644 --- a/jlrs/tests/ccall.rs +++ b/jlrs/tests/ccall.rs @@ -71,9 +71,9 @@ mod tests { Array::from_slice_unchecked(frame.as_extended_target(), &mut arr_data, 2)?; let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "callrustwitharr")? - .wrapper(); + .as_managed(); let out = func.call2(&mut frame, fn_ptr, arr.as_value()).unwrap(); let ok = out.unbox::()?.as_bool(); @@ -97,9 +97,9 @@ mod tests { Array::from_slice_unchecked(frame.as_extended_target(), &mut arr_data, 2)?; let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "callrustwitharr")? - .wrapper(); + .as_managed(); let out = func.call2(&mut frame, fn_ptr, arr.as_value()).unwrap(); let ok = out.unbox::()?.as_bool(); @@ -126,9 +126,9 @@ mod tests { Array::from_slice_unchecked(frame.as_extended_target(), &mut arr_data, 2)?; let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "callrustwitharr")? - .wrapper(); + .as_managed(); let out = func.call2(&mut frame, fn_ptr, arr.as_value()).unwrap(); let ok = out.unbox::()?.as_bool(); @@ -182,9 +182,9 @@ mod tests { let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "callrustwithasynccond")? - .wrapper(); + .as_managed(); let out = func .call2(&mut frame, fn_ptr, destroy_handle_fn_ptr) diff --git a/jlrs/tests/constants.rs b/jlrs/tests/constants.rs index 5a3c647c..98f18721 100644 --- a/jlrs/tests/constants.rs +++ b/jlrs/tests/constants.rs @@ -2,7 +2,7 @@ mod util; #[cfg(feature = "sync-rt")] #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] mod tests { - use jlrs::{prelude::*, wrappers::ptr::union_all::UnionAll}; + use jlrs::{data::managed::union_all::UnionAll, prelude::*}; use super::util::JULIA; @@ -16,8 +16,9 @@ mod tests { jlrs.instance(&mut frame) .scope(|frame| { let v1 = Value::$func(&frame); - let v2 = - unsafe { Module::core(&frame).global(&frame, $tyname)?.wrapper() }; + let v2 = unsafe { + Module::core(&frame).global(&frame, $tyname)?.as_managed() + }; assert!(v1.datatype().as_value() == v2); Ok(()) }) @@ -40,7 +41,7 @@ mod tests { unsafe { let v1 = Value::$func(&frame); let v2 = unsafe { - Module::core(&frame).global(&frame, $tyname)?.wrapper() + Module::core(&frame).global(&frame, $tyname)?.as_managed() }; assert!(v1.isa(v2)); } @@ -65,7 +66,7 @@ mod tests { unsafe { let v1 = Value::$func(&frame); let v2 = unsafe { - Module::core(&frame).global(&frame, $tyname)?.wrapper() + Module::core(&frame).global(&frame, $tyname)?.as_managed() }; assert!(v1.subtype(v2)); } @@ -87,8 +88,9 @@ mod tests { jlrs.instance(&mut frame) .scope(|frame| { let v1 = UnionAll::$func(&frame); - let v2 = - unsafe { Module::core(&frame).global(&frame, $tyname)?.wrapper() }; + let v2 = unsafe { + Module::core(&frame).global(&frame, $tyname)?.as_managed() + }; assert!(v1.as_value() == v2); Ok(()) }) @@ -108,8 +110,9 @@ mod tests { jlrs.instance(&mut frame) .scope(|frame| { let v1 = UnionAll::$func(&frame); - let v2 = - unsafe { Module::core(&frame).global(&frame, $tyname)?.wrapper() }; + let v2 = unsafe { + Module::core(&frame).global(&frame, $tyname)?.as_managed() + }; assert!(v1.as_value().isa(v2)); Ok(()) }) @@ -129,8 +132,9 @@ mod tests { jlrs.instance(&mut frame) .scope(|frame| { let v1 = DataType::$func(&frame); - let v2 = - unsafe { Module::core(&frame).global(&frame, $tyname)?.wrapper() }; + let v2 = unsafe { + Module::core(&frame).global(&frame, $tyname)?.as_managed() + }; assert!(v1.as_value().isa(v2)); Ok(()) }) diff --git a/jlrs/tests/constructor.rs b/jlrs/tests/constructor.rs index 9d63f300..34d2d3e5 100644 --- a/jlrs/tests/constructor.rs +++ b/jlrs/tests/constructor.rs @@ -28,9 +28,9 @@ mod tests { unsafe { let ty = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "HasConstructors")? - .value(); + .as_value(); assert!(ty.is::()); @@ -41,7 +41,7 @@ mod tests { .field_accessor() .field("a")? .access::()? - .wrapper() + .as_managed() .is::(); assert!(is_bool); @@ -67,9 +67,9 @@ mod tests { unsafe { let ty = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "HasConstructors")? - .value(); + .as_value(); let arg = Value::new(&mut frame, 1i16); @@ -80,7 +80,7 @@ mod tests { .field_accessor() .field("a")? .access::()? - .wrapper() + .as_managed() .is::(); assert!(is_i16); @@ -106,9 +106,9 @@ mod tests { unsafe { let ty = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "HasConstructors")? - .value(); + .as_value(); let arg = Value::new(&mut frame, 1i16); let args = [DataType::int64_type(&frame).as_value(), arg]; @@ -121,7 +121,7 @@ mod tests { .field_accessor() .field("a")? .access::()? - .wrapper() + .as_managed() .is::(); assert!(is_i64); diff --git a/jlrs/tests/datatype.rs b/jlrs/tests/datatype.rs index ec82f7a2..3278621c 100644 --- a/jlrs/tests/datatype.rs +++ b/jlrs/tests/datatype.rs @@ -4,24 +4,20 @@ mod util; #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] mod tests { #[cfg(feature = "internal-types")] - use jlrs::wrappers::ptr::internal::code_instance::CodeInstance; + use jlrs::data::managed::internal::code_instance::CodeInstance; #[cfg(feature = "internal-types")] - use jlrs::wrappers::ptr::internal::expr::Expr; + use jlrs::data::managed::internal::expr::Expr; #[cfg(feature = "internal-types")] - use jlrs::wrappers::ptr::internal::method::Method; + use jlrs::data::managed::internal::method::Method; #[cfg(feature = "internal-types")] - use jlrs::wrappers::ptr::internal::method_instance::MethodInstance; + use jlrs::data::managed::internal::method_instance::MethodInstance; use jlrs::{ + data::managed::{ + simple_vector::SimpleVector, symbol::SymbolRef, type_name::TypeName, type_var::TypeVar, + union::Union, union_all::UnionAll, + }, layout::typecheck::*, prelude::*, - wrappers::ptr::{ - simple_vector::SimpleVector, - symbol::SymbolRef, - type_name::TypeName, - type_var::TypeVar, - union::Union, - union_all::UnionAll, - }, }; use crate::util::JULIA; @@ -117,9 +113,9 @@ mod tests { .scope(|mut frame| unsafe { let dt = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "datatype")? - .wrapper(); + .as_managed(); let dt_val = dt.call0(&mut frame).unwrap(); assert!(dt_val.is::()); @@ -160,9 +156,9 @@ mod tests { let tn = dt.field_names(); let tn = tn.typed_data::()?.as_slice(); - assert_eq!(tn[0].unwrap().wrapper().as_string().unwrap(), "name"); - assert_eq!(tn[1].unwrap().wrapper().as_string().unwrap(), "lb"); - assert_eq!(tn[2].unwrap().wrapper().as_string().unwrap(), "ub"); + assert_eq!(tn[0].unwrap().as_managed().as_string().unwrap(), "name"); + assert_eq!(tn[1].unwrap().as_managed().as_string().unwrap(), "lb"); + assert_eq!(tn[2].unwrap().as_managed().as_string().unwrap(), "ub"); } Ok(()) @@ -435,7 +431,7 @@ mod tests { .scope(|frame| { let dt = UnionAll::array_type(&frame).base_type(); assert_eq!(dt.n_parameters(), 2); - let param = unsafe { dt.parameter(&frame, 0).unwrap().value() }; + let param = unsafe { dt.parameter(&frame, 0).unwrap().as_value() }; assert!(param.is::()); Ok(()) @@ -454,7 +450,7 @@ mod tests { DataType::unionall_type(&frame) .field_type(&frame, 0) .unwrap() - .wrapper() + .as_managed() }; assert!(val.is::()); @@ -474,7 +470,7 @@ mod tests { DataType::unionall_type(&frame) .field_type_concrete(&frame, 0) .unwrap() - .wrapper() + .as_managed() }; assert!(val.is::()); @@ -548,9 +544,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsStableTests")? - .wrapper() + .as_managed() .global(&frame, "WithConst")? - .value() + .as_value() .cast::()? }; @@ -595,9 +591,9 @@ mod tests { let ty = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "WithAbstract")? - .value() + .as_value() .cast::()? }; diff --git a/jlrs/tests/derive.rs b/jlrs/tests/derive.rs index 48e6116e..541942c3 100644 --- a/jlrs/tests/derive.rs +++ b/jlrs/tests/derive.rs @@ -437,7 +437,7 @@ mod tests { unsafe { assert!(Module::base(&frame) .function(&frame, "typeof")? - .wrapper() + .as_managed() .call1(&mut frame, jl_val) .unwrap() .cast::()? @@ -474,9 +474,9 @@ mod tests { .scope(|mut frame| unsafe { let constr = Module::main(&frame) .submodule(&frame, "WithBitsUnion")? - .wrapper() + .as_managed() .global(&frame, "SingleVariant")? - .wrapper(); + .as_managed(); let v1 = Value::new(&mut frame, 1i8); let v2 = Value::new(&mut frame, 2i32); let v3 = Value::new(&mut frame, 3i8); @@ -484,7 +484,7 @@ mod tests { assert!(Module::base(&frame) .function(&frame, "typeof")? - .wrapper() + .as_managed() .call1(&mut frame, jl_val) .unwrap() .cast::()? @@ -516,9 +516,9 @@ mod tests { .scope(|mut frame| unsafe { let constr = Module::main(&frame) .submodule(&frame, "WithBitsUnion")? - .wrapper() + .as_managed() .global(&frame, "DoubleVariant")? - .wrapper() + .as_managed() .cast::()?; let v1 = Value::new(&mut frame, 1i8); @@ -530,7 +530,7 @@ mod tests { assert!(Module::base(&frame) .function(&frame, "typeof")? - .wrapper() + .as_managed() .call1(&mut frame, jl_val) .unwrap() .cast::()? @@ -564,9 +564,9 @@ mod tests { .scope(|mut frame| unsafe { let constr = Module::main(&frame) .submodule(&frame, "WithBitsUnion")? - .wrapper() + .as_managed() .global(&frame, "SizeAlignMismatch")? - .wrapper(); + .as_managed(); let v1 = Value::new(&mut frame, 1i8); let v2 = Value::new(&mut frame, 2i32); @@ -575,7 +575,7 @@ mod tests { assert!(Module::base(&frame) .function(&frame, "typeof")? - .wrapper() + .as_managed() .call1(&mut frame, jl_val) .unwrap() .cast::()? @@ -609,9 +609,9 @@ mod tests { .scope(|mut frame| unsafe { let constr = Module::main(&frame) .submodule(&frame, "WithBitsUnion")? - .wrapper() + .as_managed() .global(&frame, "UnionInTuple")? - .wrapper(); + .as_managed(); let v1 = Value::new(&mut frame, 1i8); let v2 = Value::new(&mut frame, Tuple1(2i32)); @@ -647,16 +647,16 @@ mod tests { .scope(|mut frame| unsafe { let constr = Module::main(&frame) .submodule(&frame, "WithNonBitsUnion")? - .wrapper() + .as_managed() .global(&frame, "NonBitsUnion")? - .wrapper(); + .as_managed(); let v1 = Value::new(&mut frame, 1i8); let jl_val = constr.call1(&mut frame, v1).unwrap(); assert!(Module::base(&frame) .function(&frame, "typeof")? - .wrapper() + .as_managed() .call1(&mut frame, jl_val) .unwrap() .cast::()? @@ -683,14 +683,14 @@ mod tests { julia.instance(&mut frame) .scope(|mut frame| unsafe { let constr = Module::main(&frame) - .submodule(&frame, "WithStrings")?.wrapper() - .global(&frame, "WithString")?.wrapper(); + .submodule(&frame, "WithStrings")?.as_managed() + .global(&frame, "WithString")?.as_managed(); let v1 = Value::new(&mut frame, "foo")?; let jl_val = constr.call1(&mut frame, v1)?.unwrap(); assert!(Module::base(&frame) - .function(&frame, "typeof")?.wrapper() + .function(&frame, "typeof")?.as_managed() .call1(&mut frame, jl_val)? .unwrap() .cast::()? @@ -719,16 +719,16 @@ mod tests { .scope(|mut frame| unsafe { let constr = Module::main(&frame) .submodule(&frame, "WithGeneric")? - .wrapper() + .as_managed() .global(&frame, "WithGenericT")? - .wrapper(); + .as_managed(); let v1 = Value::new(&mut frame, 1i32); let jl_val = constr.call1(&mut frame, v1).unwrap(); assert!(Module::base(&frame) .function(&frame, "typeof")? - .wrapper() + .as_managed() .call1(&mut frame, jl_val) .unwrap() .cast::()? @@ -756,24 +756,24 @@ mod tests { .scope(|mut frame| unsafe { let constr = Module::main(&frame) .submodule(&frame, "WithGeneric")? - .wrapper() + .as_managed() .global(&frame, "WithGenericT")? - .wrapper(); + .as_managed(); let v1 = Value::new(&mut frame, 1i32); let wgt = constr.call1(&mut frame, v1).unwrap(); let constr = Module::main(&frame) .submodule(&frame, "WithGeneric")? - .wrapper() + .as_managed() .global(&frame, "WithGenericUnionAll")? - .wrapper(); + .as_managed(); let jl_val = constr.call1(&mut frame, wgt).unwrap(); assert!(Module::base(&frame) .function(&frame, "typeof")? - .wrapper() + .as_managed() .call1(&mut frame, jl_val) .unwrap() .cast::()? @@ -801,24 +801,24 @@ mod tests { .scope(|mut frame| unsafe { let constr = Module::main(&frame) .submodule(&frame, "WithGeneric")? - .wrapper() + .as_managed() .global(&frame, "WithGenericT")? - .wrapper(); + .as_managed(); let v1 = Value::new(&mut frame, 1i32); let wgt = constr.call1(&mut frame, v1).unwrap(); let constr = Module::main(&frame) .submodule(&frame, "WithGeneric")? - .wrapper() + .as_managed() .global(&frame, "WithNestedGenericT")? - .wrapper(); + .as_managed(); let jl_val = constr.call1(&mut frame, wgt).unwrap(); assert!(Module::base(&frame) .function(&frame, "typeof")? - .wrapper() + .as_managed() .call1(&mut frame, jl_val) .unwrap() .cast::()? @@ -847,9 +847,9 @@ mod tests { let global = frame.unrooted(); let constr = Module::main(&frame) .submodule(&frame, "WithGeneric")? - .wrapper() + .as_managed() .global(&frame, "WithGenericT")? - .wrapper(); + .as_managed(); let wgt = constr .call1(&mut frame, Module::base(&global).as_value()) @@ -857,15 +857,15 @@ mod tests { let constr = Module::main(&frame) .submodule(&frame, "WithGeneric")? - .wrapper() + .as_managed() .global(&frame, "WithPropagatedLifetime")? - .wrapper(); + .as_managed(); let jl_val = constr.call1(&mut frame, wgt).unwrap(); assert!(Module::base(&frame) .function(&frame, "typeof")? - .wrapper() + .as_managed() .call1(&mut frame, jl_val) .unwrap() .cast::()? @@ -897,28 +897,28 @@ mod tests { let wgt_constr = Module::main(&frame) .submodule(&frame, "WithGeneric")? - .wrapper() + .as_managed() .global(&frame, "WithGenericT")? - .wrapper(); + .as_managed(); let wgt = wgt_constr.call1(&mut frame, arr.as_value()).unwrap(); - let constr = Module::base(&frame).function(&frame, "tuple")?.wrapper(); + let constr = Module::base(&frame).function(&frame, "tuple")?.as_managed(); let int = Value::new(&mut frame, 2i32); let tup = constr.call2(&mut frame, int, wgt).unwrap(); let a = wgt_constr.call1(&mut frame, tup).unwrap(); let constr = Module::main(&frame) .submodule(&frame, "WithGeneric")? - .wrapper() + .as_managed() .global(&frame, "WithPropagatedLifetimes")? - .wrapper(); + .as_managed(); let jl_val = constr.call1(&mut frame, a).unwrap(); assert!(Module::base(&frame) .function(&frame, "typeof")? - .wrapper() + .as_managed() .call1(&mut frame, jl_val) .unwrap() .cast::()? @@ -948,24 +948,24 @@ mod tests { .scope(|mut frame| unsafe { let wgt_constr = Module::main(&frame) .submodule(&frame, "WithGeneric")? - .wrapper() + .as_managed() .global(&frame, "WithGenericT")? - .wrapper(); + .as_managed(); let v1 = Value::new(&mut frame, 1i64); let wgt = wgt_constr.call1(&mut frame, v1).unwrap(); let constr = Module::main(&frame) .submodule(&frame, "WithGeneric")? - .wrapper() + .as_managed() .global(&frame, "WithSetGeneric")? - .wrapper(); + .as_managed(); let jl_val = constr.call1(&mut frame, wgt).unwrap(); assert!(Module::base(&frame) .function(&frame, "typeof")? - .wrapper() + .as_managed() .call1(&mut frame, jl_val) .unwrap() .cast::()? @@ -993,27 +993,27 @@ mod tests { .scope(|mut frame| unsafe { let wgt_constr = Module::main(&frame) .submodule(&frame, "WithGeneric")? - .wrapper() + .as_managed() .global(&frame, "WithGenericT")? - .wrapper(); + .as_managed(); let v1 = Value::new(&mut frame, 1i64); let wgt = wgt_constr.call1(&mut frame, v1).unwrap(); - let tup_constr = Module::base(&frame).function(&frame, "tuple")?.wrapper(); + let tup_constr = Module::base(&frame).function(&frame, "tuple")?.as_managed(); let v2 = tup_constr.call1(&mut frame, wgt).unwrap(); let constr = Module::main(&frame) .submodule(&frame, "WithGeneric")? - .wrapper() + .as_managed() .global(&frame, "WithSetGenericTuple")? - .wrapper(); + .as_managed(); let jl_val = constr.call1(&mut frame, v2).unwrap(); assert!(Module::base(&frame) .function(&frame, "typeof")? - .wrapper() + .as_managed() .call1(&mut frame, jl_val) .unwrap() .cast::()? @@ -1041,16 +1041,16 @@ mod tests { .scope(|mut frame| unsafe { let wvt_constr = Module::main(&frame) .submodule(&frame, "WithGeneric")? - .wrapper() + .as_managed() .global(&frame, "withvaluetype")? - .wrapper(); + .as_managed(); let v1 = Value::new(&mut frame, 1i64); let jl_val = wvt_constr.call1(&mut frame, v1).unwrap(); assert!(Module::base(&frame) .function(&frame, "typeof")? - .wrapper() + .as_managed() .call1(&mut frame, jl_val) .unwrap() .cast::()? diff --git a/jlrs/tests/eval_string.rs b/jlrs/tests/eval_string.rs index dcea2bdc..0e4ab7b1 100644 --- a/jlrs/tests/eval_string.rs +++ b/jlrs/tests/eval_string.rs @@ -52,7 +52,9 @@ mod tests { let mut jlrs = j.borrow_mut(); jlrs.instance(&mut frame) .scope(|mut frame| unsafe { - let func = Module::main(&frame).function(&frame, "increase")?.wrapper(); + let func = Module::main(&frame) + .function(&frame, "increase")? + .as_managed(); let twelve = Value::new(&mut frame, 12i32); let result = func.call1(&mut frame, twelve); assert_eq!(result.unwrap().unbox::().unwrap(), 13i32); diff --git a/jlrs/tests/function.rs b/jlrs/tests/function.rs index ede97101..56baee5e 100644 --- a/jlrs/tests/function.rs +++ b/jlrs/tests/function.rs @@ -17,7 +17,7 @@ mod tests { frame .scope(|frame| { let func = - unsafe { Module::base(&frame).function(&frame, "+")?.wrapper() }; + unsafe { Module::base(&frame).function(&frame, "+")?.as_managed() }; Ok(func.root(output)) }) .unwrap(); @@ -37,7 +37,7 @@ mod tests { let func_ty = unsafe { Module::base(&frame) .function(&frame, "+")? - .wrapper() + .as_managed() .datatype() }; diff --git a/jlrs/tests/functions.rs b/jlrs/tests/functions.rs index 3f03f3de..5689a785 100644 --- a/jlrs/tests/functions.rs +++ b/jlrs/tests/functions.rs @@ -57,7 +57,7 @@ mod tests { jlrs.instance(&mut frame) .scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "vect")?.wrapper(); + let func = Module::base(&frame).function(&frame, "vect")?.as_managed(); func.call0(&mut frame).unwrap(); Ok(()) }) @@ -74,7 +74,7 @@ mod tests { .scope(|frame| unsafe { Module::base(&frame) .function(&frame, "vect")? - .wrapper() + .as_managed() .call0(&frame) .unwrap(); @@ -94,7 +94,7 @@ mod tests { let output = frame.output(); frame .scope(|frame| unsafe { - let func = Module::base(&frame).function(&frame, "vect")?.wrapper(); + let func = Module::base(&frame).function(&frame, "vect")?.as_managed(); Ok(func.call0(output)) })? @@ -113,7 +113,7 @@ mod tests { jlrs.instance(&mut frame) .scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "vect")?.wrapper(); + let func = Module::base(&frame).function(&frame, "vect")?.as_managed(); func.call0(&mut frame).unwrap(); Ok(()) }) @@ -131,7 +131,7 @@ mod tests { let output = frame.output(); frame .scope(|frame| unsafe { - let func = Module::base(&frame).function(&frame, "vect")?.wrapper(); + let func = Module::base(&frame).function(&frame, "vect")?.as_managed(); Ok(func.call0(output)) })? @@ -148,7 +148,7 @@ mod tests { let mut jlrs = j.borrow_mut(); let out = jlrs.instance(&mut frame).scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "cos")?.wrapper(); + let func = Module::base(&frame).function(&frame, "cos")?.as_managed(); let angle = Value::new(&mut frame, std::f32::consts::PI); let out = func.call1(&mut frame, angle).unwrap(); out.unbox::() @@ -164,10 +164,10 @@ mod tests { let mut jlrs = j.borrow_mut(); let out = jlrs.instance(&mut frame).scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "cos")?.wrapper(); + let func = Module::base(&frame).function(&frame, "cos")?.as_managed(); let angle = Value::new(&mut frame, std::f32::consts::PI); let out = func.call1(&frame, angle).unwrap(); - out.wrapper().unbox::() + out.as_managed().unbox::() }); assert_eq!(out.unwrap(), -1.); @@ -184,7 +184,7 @@ mod tests { let output = frame.output(); let out = frame .scope(|mut frame| { - let func = Module::base(&frame).function(&frame, "cos")?.wrapper(); + let func = Module::base(&frame).function(&frame, "cos")?.as_managed(); let angle = Value::new(&mut frame, std::f32::consts::PI); Ok(func.call1(output, angle)) @@ -208,7 +208,7 @@ mod tests { let output = frame.output(); let out = frame .scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "cos")?.wrapper(); + let func = Module::base(&frame).function(&frame, "cos")?.as_managed(); let angle = Value::new(&mut frame, std::f32::consts::PI); func.call1(output, angle).into_jlrs_result() @@ -231,7 +231,7 @@ mod tests { let output = frame.output(); let out = frame .scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "cos")?.wrapper(); + let func = Module::base(&frame).function(&frame, "cos")?.as_managed(); let angle = Value::new(&mut frame, std::f32::consts::PI); func.call1(output, angle).into_jlrs_result() @@ -250,7 +250,7 @@ mod tests { let mut jlrs = j.borrow_mut(); let out = jlrs.instance(&mut frame).scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); let out = func.call2(&mut frame, arg0, arg1).unwrap(); @@ -267,11 +267,11 @@ mod tests { let mut jlrs = j.borrow_mut(); let out = jlrs.instance(&mut frame).scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); let out = func.call2(&frame, arg0, arg1).unwrap(); - out.wrapper().unbox::() + out.as_managed().unbox::() }); assert_eq!(out.unwrap(), 3); @@ -289,7 +289,7 @@ mod tests { let output = frame.output(); frame .scope(|mut frame| { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg1 = Value::new(&mut frame, 2u32); Ok(func.call(output, [arg0, arg1])) })? @@ -310,7 +310,7 @@ mod tests { let output = frame.output(); frame .scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); @@ -330,7 +330,7 @@ mod tests { let mut jlrs = j.borrow_mut(); let out = jlrs.instance(&mut frame).scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); let out = func.call2(&mut frame, arg0, arg1).unwrap(); @@ -350,7 +350,7 @@ mod tests { let output = frame.output(); frame .scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); @@ -370,7 +370,7 @@ mod tests { let mut jlrs = j.borrow_mut(); let out = jlrs.instance(&mut frame).scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); let arg2 = Value::new(&mut frame, 3u32); @@ -388,12 +388,12 @@ mod tests { let mut jlrs = j.borrow_mut(); let out = jlrs.instance(&mut frame).scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); let arg2 = Value::new(&mut frame, 3u32); let out = func.call3(&frame, arg0, arg1, arg2).unwrap(); - out.wrapper().unbox::() + out.as_managed().unbox::() }); assert_eq!(out.unwrap(), 6); @@ -409,7 +409,7 @@ mod tests { let output = frame.output(); frame .scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); let arg2 = Value::new(&mut frame, 3u32); @@ -430,7 +430,7 @@ mod tests { let mut jlrs = j.borrow_mut(); let out = jlrs.instance(&mut frame).scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); let arg2 = Value::new(&mut frame, 3u32); @@ -451,7 +451,7 @@ mod tests { let output = frame.output(); frame .scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); let arg2 = Value::new(&mut frame, 3u32); @@ -472,7 +472,7 @@ mod tests { let mut jlrs = j.borrow_mut(); let out = jlrs.instance(&mut frame).scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); let arg2 = Value::new(&mut frame, 3u32); @@ -493,13 +493,13 @@ mod tests { let mut jlrs = j.borrow_mut(); let out = jlrs.instance(&mut frame).scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); let arg2 = Value::new(&mut frame, 3u32); let arg3 = Value::new(&mut frame, 4u32); let out = func.call(&frame, &mut [arg0, arg1, arg2, arg3]).unwrap(); - out.wrapper().unbox::() + out.as_managed().unbox::() }); assert_eq!(out.unwrap(), 10); @@ -515,7 +515,7 @@ mod tests { let output = frame.output(); frame .scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); let arg2 = Value::new(&mut frame, 3u32); @@ -540,7 +540,7 @@ mod tests { let output = frame.output(); frame .scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); let arg2 = Value::new(&mut frame, 3u32); @@ -565,7 +565,7 @@ mod tests { let output = frame.output(); frame .scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let arg0 = Value::new(&mut frame, 1u32); let arg1 = Value::new(&mut frame, 2u32); let arg2 = Value::new(&mut frame, 3u32); diff --git a/jlrs/tests/into_julia.rs b/jlrs/tests/into_julia.rs index d2019bed..088e6024 100644 --- a/jlrs/tests/into_julia.rs +++ b/jlrs/tests/into_julia.rs @@ -4,7 +4,7 @@ mod util; mod tests { use std::{ffi::c_void, ptr::null_mut}; - use jlrs::{convert::into_julia::IntoJulia, prelude::*, wrappers::ptr::union_all::UnionAll}; + use jlrs::{convert::into_julia::IntoJulia, data::managed::union_all::UnionAll, prelude::*}; use super::util::JULIA; @@ -17,7 +17,7 @@ mod tests { jlrs.instance(&mut frame) .scope(|frame| unsafe { - let ty = <$type as IntoJulia>::julia_type(&frame).value(); + let ty = <$type as IntoJulia>::julia_type(&frame).as_value(); assert_eq!(ty, DataType::$assoc_ty(&frame).as_value()); assert!(ty.cast::()?.is::<$type>()); @@ -34,7 +34,7 @@ mod tests { jlrs.instance(&mut frame) .scope(|frame| unsafe { - let val = $val.into_julia(&frame).value(); + let val = $val.into_julia(&frame).as_value(); assert!(val.is::<$type>()); Ok(()) @@ -54,7 +54,7 @@ mod tests { jlrs.instance(&mut frame) .scope(|mut frame| unsafe { - let ty = <*mut $type as IntoJulia>::julia_type(&frame).value(); + let ty = <*mut $type as IntoJulia>::julia_type(&frame).as_value(); let args = [DataType::$assoc_ty(&frame).as_value()]; let applied = UnionAll::pointer_type(&frame) @@ -77,7 +77,7 @@ mod tests { jlrs.instance(&mut frame) .scope(|frame| unsafe { - let val = null_mut::<$type>().into_julia(&frame).value(); + let val = null_mut::<$type>().into_julia(&frame).as_value(); assert!(val.is::<*mut $type>()); Ok(()) }) @@ -190,7 +190,7 @@ mod tests { jlrs.instance(&mut frame) .scope(|frame| unsafe { - let ty = <*mut c_void as IntoJulia>::julia_type(&frame).value(); + let ty = <*mut c_void as IntoJulia>::julia_type(&frame).as_value(); assert_eq!(ty, DataType::voidpointer_type(&frame).as_value()); assert!(ty.cast::()?.is::<*mut c_void>()); Ok(()) @@ -206,7 +206,7 @@ mod tests { jlrs.instance(&mut frame) .scope(|frame| unsafe { - let val = null_mut::().into_julia(&frame).value(); + let val = null_mut::().into_julia(&frame).as_value(); assert!(val.is::<*mut c_void>()); Ok(()) }) diff --git a/jlrs/tests/kw_func.rs b/jlrs/tests/kw_func.rs index f96a1330..d9a8f71e 100644 --- a/jlrs/tests/kw_func.rs +++ b/jlrs/tests/kw_func.rs @@ -15,9 +15,9 @@ mod tests { let a_value = Value::new(&mut frame, 1isize); let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "funcwithkw")? - .wrapper(); + .as_managed(); let v = func .call(&mut frame, &mut [a_value]) @@ -42,9 +42,9 @@ mod tests { let b_value = Value::new(&mut frame, 10isize); let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "funcwithkw")? - .wrapper(); + .as_managed(); let kw = named_tuple!(frame.as_extended_target(), "b" => b_value); let v = func @@ -70,9 +70,9 @@ mod tests { let b_value = Value::new(&mut frame, 10isize); let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "funcwithkw")? - .wrapper(); + .as_managed(); let kw = named_tuple!(frame.as_extended_target(), "b" => b_value); let v = func @@ -99,9 +99,9 @@ mod tests { let b_value = Value::new(&mut frame, 10isize); let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "funcwithkw")? - .wrapper(); + .as_managed(); let kw = named_tuple!(frame.as_extended_target(), "b" => b_value); let v = func @@ -129,9 +129,9 @@ mod tests { let c_value = Value::new(&mut frame, 5isize); let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "funcwithkw")? - .wrapper(); + .as_managed(); let kw = named_tuple!(frame.as_extended_target(), "b" => b_value); let v = func @@ -159,9 +159,9 @@ mod tests { let c_value = Value::new(&mut frame, 5isize); let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "funcwithkw")? - .wrapper(); + .as_managed(); let kw = named_tuple!(frame.as_extended_target(), "b" => b_value); let v = func @@ -190,9 +190,9 @@ mod tests { let d_value = Value::new(&mut frame, 4isize); let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "funcwithkw")? - .wrapper(); + .as_managed(); let kw = named_tuple!(frame.as_extended_target(), "b" => b_value); let v = func @@ -222,9 +222,9 @@ mod tests { let e_value = Value::new(&mut frame, 2isize); let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "funcwithkw")? - .wrapper(); + .as_managed(); let kw = named_tuple!(frame.as_extended_target(), "b" => b_value); let v = func @@ -251,9 +251,9 @@ mod tests { let b_value = Value::new(&mut frame, 10f32); let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "funcwithabstractkw")? - .wrapper(); + .as_managed(); let kw = named_tuple!(frame.as_extended_target(), "b" => b_value); let v = func @@ -280,9 +280,9 @@ mod tests { let b_value = Value::new(&mut frame, 10f64); let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "funcwithabstractkw")? - .wrapper(); + .as_managed(); let kw = named_tuple!(frame.as_extended_target(), "b" => b_value); let v = func diff --git a/jlrs/tests/managed_array.rs b/jlrs/tests/managed_array.rs index 2192b021..e0a7e804 100644 --- a/jlrs/tests/managed_array.rs +++ b/jlrs/tests/managed_array.rs @@ -3,7 +3,7 @@ mod util; #[cfg(feature = "sync-rt")] #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] mod tests { - use jlrs::{prelude::*, wrappers::ptr::array::dimensions::Dims}; + use jlrs::{data::managed::array::dimensions::Dims, prelude::*}; use crate::util::JULIA; diff --git a/jlrs/tests/module.rs b/jlrs/tests/module.rs index dc4b9aef..c184af0d 100644 --- a/jlrs/tests/module.rs +++ b/jlrs/tests/module.rs @@ -177,9 +177,9 @@ mod tests { .scope(|mut frame| unsafe { let base = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "base")? - .wrapper(); + .as_managed(); let base_val = base.call0(&mut frame).unwrap(); assert!(base_val.is::()); @@ -260,7 +260,7 @@ mod tests { main.set_global(&mut frame, "one", value) .into_jlrs_result()?; - let value = main.global(&frame, "one")?.wrapper(); + let value = main.global(&frame, "one")?.as_managed(); assert_eq!(value.unbox::()?, 1); Ok(()) }) @@ -279,7 +279,7 @@ mod tests { main.set_const(&mut frame, "ONE", value) .into_jlrs_result()?; - let value = main.global(&frame, "ONE")?.wrapper(); + let value = main.global(&frame, "ONE")?.as_managed(); assert_eq!(value.unbox::()?, 2); Ok(()) }) @@ -299,7 +299,7 @@ mod tests { let value1 = Value::new(&mut frame, 3usize); let value2 = Value::new(&mut frame, 4usize); main.set_const(&frame, "TWICE", value1) - .map_err(|v| unsafe { v.value() }) + .map_err(|v| unsafe { v.as_value() }) .into_jlrs_result()?; main.set_const(&mut frame, "TWICE", value2) .into_jlrs_result()?; diff --git a/jlrs/tests/move_array.rs b/jlrs/tests/move_array.rs index 9be77b97..5a17b3e7 100644 --- a/jlrs/tests/move_array.rs +++ b/jlrs/tests/move_array.rs @@ -3,7 +3,7 @@ mod util; #[cfg(feature = "sync-rt")] #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] mod tests { - use jlrs::{prelude::*, wrappers::ptr::array::dimensions::Dims}; + use jlrs::{data::managed::array::dimensions::Dims, prelude::*}; use crate::util::JULIA; diff --git a/jlrs/tests/ndarray.rs b/jlrs/tests/ndarray.rs index ae2d8e1e..86477942 100644 --- a/jlrs/tests/ndarray.rs +++ b/jlrs/tests/ndarray.rs @@ -5,8 +5,8 @@ mod util; mod tests { use jlrs::{ convert::ndarray::{NdArrayView, NdArrayViewMut}, + data::managed::array::{Array, TypedArray}, memory::stack_frame::StackFrame, - wrappers::ptr::array::{Array, TypedArray}, }; use super::util::JULIA; diff --git a/jlrs/tests/opaque_closure.rs b/jlrs/tests/opaque_closure.rs index c77bd489..d18fb383 100644 --- a/jlrs/tests/opaque_closure.rs +++ b/jlrs/tests/opaque_closure.rs @@ -6,9 +6,9 @@ mod util; ))] mod not_lts { use jlrs::{ + data::managed::internal::opaque_closure::{OpaqueClosure, OpaqueClosureRef}, layout::valid_layout::ValidLayout, prelude::*, - wrappers::ptr::internal::opaque_closure::{OpaqueClosure, OpaqueClosureRef}, }; use super::util::JULIA; diff --git a/jlrs/tests/output_frame.rs b/jlrs/tests/output_frame.rs index b556e8bf..17a103ab 100644 --- a/jlrs/tests/output_frame.rs +++ b/jlrs/tests/output_frame.rs @@ -33,7 +33,7 @@ mod tests { frame .scope(|mut frame| { frame.scope(|mut frame| unsafe { - let func = Module::base(&frame).function(&frame, "+")?.wrapper(); + let func = Module::base(&frame).function(&frame, "+")?.as_managed(); let v1 = Value::new(frame.as_mut(), 1usize); let v2 = Value::new(frame.as_mut(), 2usize); Ok(func.call2(output, v1, v2)) diff --git a/jlrs/tests/primitives.rs b/jlrs/tests/primitives.rs index 7abcece6..fdde5f90 100644 --- a/jlrs/tests/primitives.rs +++ b/jlrs/tests/primitives.rs @@ -309,9 +309,9 @@ mod tests { let res = unsafe { Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "callrust")? - .wrapper() + .as_managed() .call1(&mut frame, val) .unwrap() .unbox::()? diff --git a/jlrs/tests/require.rs b/jlrs/tests/require.rs index 8732cdb9..cc9ec9bf 100644 --- a/jlrs/tests/require.rs +++ b/jlrs/tests/require.rs @@ -49,7 +49,7 @@ mod tests { .expect("Cannot load LinearAlgebra") .cast::()? .function(&frame, "dot")? - .wrapper(); + .as_managed(); let mut arr1 = vec![1.0f64, 2.0f64]; let mut arr2 = vec![2.0f64, 3.0f64]; diff --git a/jlrs/tests/simple_vector.rs b/jlrs/tests/simple_vector.rs index 476db613..69357567 100644 --- a/jlrs/tests/simple_vector.rs +++ b/jlrs/tests/simple_vector.rs @@ -3,13 +3,13 @@ mod util; #[cfg(feature = "sync-rt")] mod tests { use jlrs::{ - layout::valid_layout::ValidLayout, - prelude::*, - wrappers::ptr::{ + data::managed::{ simple_vector::{SimpleVector, SimpleVectorRef}, symbol::SymbolRef, union_all::UnionAll, }, + layout::valid_layout::ValidLayout, + prelude::*, }; use crate::util::JULIA; @@ -110,7 +110,7 @@ mod tests { unsafe { let data = svec.typed_data_unchecked::(); - assert_eq!(data.as_slice()[0].unwrap().wrapper(), sym); + assert_eq!(data.as_slice()[0].unwrap().as_managed(), sym); } Ok(()) }) diff --git a/jlrs/tests/string.rs b/jlrs/tests/string.rs index cb97f897..78c00de2 100644 --- a/jlrs/tests/string.rs +++ b/jlrs/tests/string.rs @@ -4,7 +4,7 @@ mod util; mod tests { use std::borrow::Cow; - use jlrs::{layout::valid_layout::ValidLayout, prelude::*, wrappers::ptr::string::JuliaString}; + use jlrs::{data::managed::string::JuliaString, layout::valid_layout::ValidLayout, prelude::*}; use crate::util::JULIA; diff --git a/jlrs/tests/symbol.rs b/jlrs/tests/symbol.rs index 5103b09a..f88809bc 100644 --- a/jlrs/tests/symbol.rs +++ b/jlrs/tests/symbol.rs @@ -34,9 +34,9 @@ mod tests { .scope(|mut frame| unsafe { let smb = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "symbol")? - .wrapper(); + .as_managed(); let smb_val = smb.call0(&mut frame).unwrap(); assert!(smb_val.is::()); diff --git a/jlrs/tests/task.rs b/jlrs/tests/task.rs index 9ecc9855..c23a5e3d 100644 --- a/jlrs/tests/task.rs +++ b/jlrs/tests/task.rs @@ -2,7 +2,7 @@ mod util; #[cfg(feature = "sync-rt")] mod tests { - use jlrs::{prelude::*, wrappers::ptr::task::Task}; + use jlrs::{data::managed::task::Task, prelude::*}; use super::util::JULIA; diff --git a/jlrs/tests/to_symbol.rs b/jlrs/tests/to_symbol.rs index e9828d7e..5e14961d 100644 --- a/jlrs/tests/to_symbol.rs +++ b/jlrs/tests/to_symbol.rs @@ -2,7 +2,7 @@ mod util; #[cfg(feature = "sync-rt")] mod tests { - use jlrs::{prelude::*, wrappers::ptr::symbol::Symbol}; + use jlrs::{data::managed::symbol::Symbol, prelude::*}; use super::util::JULIA; diff --git a/jlrs/tests/tokio_rt.rs b/jlrs/tests/tokio_rt.rs index 0e044a15..76578c73 100644 --- a/jlrs/tests/tokio_rt.rs +++ b/jlrs/tests/tokio_rt.rs @@ -483,7 +483,7 @@ mod tests { Module::base(&frame) .function(&frame, "+") .unwrap() - .wrapper() + .as_managed() .call2(&mut frame, one, one) .into_jlrs_result()? .unbox::() diff --git a/jlrs/tests/typecheck.rs b/jlrs/tests/typecheck.rs index da11da3e..2765de53 100644 --- a/jlrs/tests/typecheck.rs +++ b/jlrs/tests/typecheck.rs @@ -4,7 +4,7 @@ mod util; mod tests { use std::{ffi::c_void, ptr::null_mut}; - use jlrs::{layout::typecheck::*, prelude::*, wrappers::ptr::union_all::UnionAll}; + use jlrs::{data::managed::union_all::UnionAll, layout::typecheck::*, prelude::*}; use super::util::JULIA; diff --git a/jlrs/tests/unbox.rs b/jlrs/tests/unbox.rs index 178a3db9..74c5b9a0 100644 --- a/jlrs/tests/unbox.rs +++ b/jlrs/tests/unbox.rs @@ -22,7 +22,7 @@ mod tests { .scope(|frame| unsafe { let val: $type = $val; assert_eq!( - <$type as Unbox>::unbox(val.into_julia(&frame).value()), + <$type as Unbox>::unbox(val.into_julia(&frame).as_value()), $val ); Ok(()) diff --git a/jlrs/tests/union_all.rs b/jlrs/tests/union_all.rs index 1fced7c8..200e694c 100644 --- a/jlrs/tests/union_all.rs +++ b/jlrs/tests/union_all.rs @@ -3,8 +3,8 @@ mod util; #[cfg(not(all(target_os = "windows", feature = "julia-1-6")))] mod tests { use jlrs::{ + data::managed::{type_var::TypeVar, union_all::UnionAll}, prelude::*, - wrappers::ptr::{type_var::TypeVar, union_all::UnionAll}, }; use super::util::JULIA; @@ -28,7 +28,7 @@ mod tests { let equals = Module::base(&frame) .function(&frame, "!=")? - .wrapper() + .as_managed() .call2(&mut frame, v.as_value(), atype.var().as_value()) .unwrap() .unbox::()? @@ -50,9 +50,9 @@ mod tests { let args = [DataType::int8_type(&frame).as_value()]; let out = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "ParameterStruct")? - .wrapper() + .as_managed() .apply_type(&mut frame, args) .into_jlrs_result()? .cast::()? @@ -79,9 +79,9 @@ mod tests { let vts = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "ValueTypeStruct")? - .wrapper(); + .as_managed(); let v1 = vts .apply_type(&mut frame, &mut [ty1]) @@ -99,9 +99,9 @@ mod tests { let func = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .function(&frame, "valuedispatch")? - .wrapper(); + .as_managed(); let o1 = func.call1(&mut frame, v1).unwrap().unbox::()?; let o2 = func.call1(&mut frame, v2).unwrap().unbox::()?; diff --git a/jlrs/tests/union_layout.rs b/jlrs/tests/union_layout.rs index 9a88d695..8a46d6d2 100644 --- a/jlrs/tests/union_layout.rs +++ b/jlrs/tests/union_layout.rs @@ -13,14 +13,14 @@ mod tests { .scope(|frame| unsafe { let field = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "has_module")? - .value() + .as_value() .field_accessor() .field("a")? .access::()?; - assert!(field.value().is::()); + assert!(field.as_value().is::()); Ok(()) }) @@ -36,9 +36,9 @@ mod tests { .scope(|frame| unsafe { let _field = Module::main(&frame) .submodule(&frame, "JlrsTests")? - .wrapper() + .as_managed() .global(&frame, "has_nothing")? - .value() + .as_value() .field_accessor() .field("a")? .access::()?; diff --git a/jlrs/tests/util/async_tasks.rs b/jlrs/tests/util/async_tasks.rs index 7dff07fe..98514466 100644 --- a/jlrs/tests/util/async_tasks.rs +++ b/jlrs/tests/util/async_tasks.rs @@ -16,9 +16,9 @@ impl AsyncTask for MyTask { let v = unsafe { Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .as_value() .call_async(&mut frame, &mut [dims, iters]) .await @@ -46,9 +46,9 @@ impl AsyncTask for OtherRetTypeTask { let v = unsafe { Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .as_value() .call_async(&mut frame, &mut [dims, iters]) .await @@ -78,9 +78,9 @@ impl AsyncTask for KwTask { let v = unsafe { Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "kwfunc")? - .wrapper() + .as_managed() .provide_keywords(nt)? .call_async(&mut frame, &mut [dims, iters]) .await @@ -102,9 +102,9 @@ impl AsyncTask for ThrowingTask { let v = unsafe { Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "throwingfunc")? - .wrapper() + .as_managed() .call_async(&mut frame, []) .await .into_jlrs_result()? @@ -133,9 +133,9 @@ impl AsyncTask for NestingTaskAsyncFrame { unsafe { Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .as_value() .call_async(&mut frame, &mut [dims, iters]) .await @@ -168,9 +168,9 @@ impl AsyncTask for NestingTaskAsyncValueFrame { let out = unsafe { Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .as_value() .call_async(&mut frame, &mut [dims, iters]) .await @@ -205,9 +205,9 @@ impl AsyncTask for NestingTaskAsyncCallFrame { let out = unsafe { Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .as_value() .call_async(&mut frame, &mut [dims, iters]) .await @@ -248,9 +248,9 @@ impl AsyncTask for NestingTaskAsyncGcFrame { unsafe { Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .as_value() .call_async(&mut frame, &mut [dims, iters]) .await @@ -283,9 +283,9 @@ impl AsyncTask for NestingTaskAsyncDynamicValueFrame { let out = unsafe { Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .as_value() .call_async(&mut frame, &mut [dims, iters]) .await @@ -320,9 +320,9 @@ impl AsyncTask for NestingTaskAsyncDynamicCallFrame { let out = unsafe { Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .as_value() .call_async(&mut frame, &mut [dims, iters]) .await @@ -377,7 +377,9 @@ impl PersistentTask for AccumulatorTask { async move { // A nested scope is used to only root a single value in the frame provided to // init, rather than two. - let func = Module::main(&frame).global(&frame, "MutFloat64")?.value(); + let func = Module::main(&frame) + .global(&frame, "MutFloat64")? + .as_value(); let init_v = Value::new(&mut frame, init_value); Ok(func.call1(output, init_v)) @@ -423,9 +425,9 @@ impl AsyncTask for LocalTask { let v = unsafe { Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .call_async_local(&mut frame, &mut [dims, iters]) .await .unwrap() @@ -452,9 +454,9 @@ impl AsyncTask for LocalSchedulingTask { let v = unsafe { let task = Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .schedule_async_local(&mut frame, &mut [dims, iters]) .unwrap(); @@ -485,9 +487,9 @@ impl AsyncTask for MainTask { let v = unsafe { Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .call_async_main(&mut frame, &mut [dims, iters]) .await .unwrap() @@ -514,9 +516,9 @@ impl AsyncTask for MainSchedulingTask { let v = unsafe { let task = Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .schedule_async_main(&mut frame, &mut [dims, iters]) .unwrap(); @@ -547,9 +549,9 @@ impl AsyncTask for SchedulingTask { let v = unsafe { let task = Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "complexfunc")? - .wrapper() + .as_managed() .schedule_async(&mut frame, &mut [dims, iters]) .unwrap(); @@ -583,9 +585,9 @@ impl AsyncTask for LocalKwSchedulingTask { let task = Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "kwfunc")? - .wrapper() + .as_managed() .provide_keywords(nt)? .schedule_async_local(&mut frame, &mut [dims, iters]) .unwrap(); @@ -620,9 +622,9 @@ impl AsyncTask for KwSchedulingTask { let task = Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "kwfunc")? - .wrapper() + .as_managed() .provide_keywords(nt)? .schedule_async(&mut frame, &mut [dims, iters]) .unwrap(); @@ -657,9 +659,9 @@ impl AsyncTask for MainKwSchedulingTask { let task = Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "kwfunc")? - .wrapper() + .as_managed() .provide_keywords(nt)? .schedule_async_main(&mut frame, &mut [dims, iters]) .unwrap(); @@ -693,9 +695,9 @@ impl AsyncTask for LocalKwTask { let v = unsafe { Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "kwfunc")? - .wrapper() + .as_managed() .provide_keywords(nt)? .call_async_local(&mut frame, &mut [dims, iters]) .await @@ -725,9 +727,9 @@ impl AsyncTask for MainKwTask { let v = unsafe { Module::main(&frame) .submodule(&frame, "AsyncTests")? - .wrapper() + .as_managed() .function(&frame, "kwfunc")? - .wrapper() + .as_managed() .provide_keywords(nt)? .call_async_main(&mut frame, &mut [dims, iters]) .await diff --git a/jlrs/tests/util/derive_impls.rs b/jlrs/tests/util/derive_impls.rs index 6d4c48cb..39d21698 100644 --- a/jlrs/tests/util/derive_impls.rs +++ b/jlrs/tests/util/derive_impls.rs @@ -4,7 +4,7 @@ use jlrs::prelude::*; #[derive(Clone, Debug, Unbox, ValidLayout, ValidField, Typecheck, IntoJulia)] #[jlrs(julia_type = "Main.BitsWithCustom.BitsCharBitsIntChar")] pub struct BitsCharBitsIntChar { - pub a: ::jlrs::wrappers::inline::char::Char, + pub a: ::jlrs::data::layout::char::Char, pub b: BitsIntChar, } @@ -14,7 +14,7 @@ pub struct BitsCharBitsIntChar { #[jlrs(julia_type = "Main.BitsWithCustom.BitsIntChar")] pub struct BitsIntChar { pub a: i64, - pub b: ::jlrs::wrappers::inline::char::Char, + pub b: ::jlrs::data::layout::char::Char, } #[cfg(target_pointer_width = "32")] @@ -23,7 +23,7 @@ pub struct BitsIntChar { #[jlrs(julia_type = "Main.BitsWithCustom.BitsIntChar")] pub struct BitsIntChar { pub a: i32, - pub b: ::jlrs::wrappers::inline::char::Char, + pub b: ::jlrs::data::layout::char::Char, } #[repr(C)] @@ -31,7 +31,7 @@ pub struct BitsIntChar { #[jlrs(julia_type = "Main.BitsWithTuples.BitsUInt8TupleInt32Int64")] pub struct BitsUInt8TupleInt32Int64 { pub a: u8, - pub b: ::jlrs::wrappers::inline::tuple::Tuple2, + pub b: ::jlrs::data::layout::tuple::Tuple2, } #[repr(C)] @@ -39,17 +39,14 @@ pub struct BitsUInt8TupleInt32Int64 { #[jlrs(julia_type = "Main.BitsWithTuples.BitsUInt8TupleInt32TupleInt16UInt16")] pub struct BitsUInt8TupleInt32TupleInt16UInt16 { pub a: u8, - pub b: ::jlrs::wrappers::inline::tuple::Tuple2< - i32, - ::jlrs::wrappers::inline::tuple::Tuple2, - >, + pub b: ::jlrs::data::layout::tuple::Tuple2>, } #[repr(C)] #[derive(Clone, Debug, Unbox, ValidLayout, ValidField, Typecheck, IntoJulia)] #[jlrs(julia_type = "Main.MultiFieldBits.BitsCharFloat32Float64")] pub struct BitsCharFloat32Float64 { - pub a: ::jlrs::wrappers::inline::char::Char, + pub a: ::jlrs::data::layout::char::Char, pub b: f32, pub c: f64, } @@ -60,7 +57,7 @@ pub struct BitsCharFloat32Float64 { #[jlrs(julia_type = "Main.MultiFieldBits.BitsIntBool")] pub struct BitsIntBool { pub a: i64, - pub b: ::jlrs::wrappers::inline::bool::Bool, + pub b: ::jlrs::data::layout::bool::Bool, } #[cfg(target_pointer_width = "32")] @@ -69,21 +66,21 @@ pub struct BitsIntBool { #[jlrs(julia_type = "Main.MultiFieldBits.BitsIntBool")] pub struct BitsIntBool { pub a: i32, - pub b: ::jlrs::wrappers::inline::bool::Bool, + pub b: ::jlrs::data::layout::bool::Bool, } #[repr(C)] #[derive(Clone, Debug, Unbox, ValidLayout, ValidField, Typecheck, IntoJulia)] #[jlrs(julia_type = "Main.SingleFieldBits.BitsTypeBool")] pub struct BitsTypeBool { - pub a: ::jlrs::wrappers::inline::bool::Bool, + pub a: ::jlrs::data::layout::bool::Bool, } #[repr(C)] #[derive(Clone, Debug, Unbox, ValidLayout, ValidField, Typecheck, IntoJulia)] #[jlrs(julia_type = "Main.SingleFieldBits.BitsTypeChar")] pub struct BitsTypeChar { - pub a: ::jlrs::wrappers::inline::char::Char, + pub a: ::jlrs::data::layout::char::Char, } #[repr(C)] @@ -193,9 +190,9 @@ pub struct BitsTypeUInt8 { pub struct DoubleVariant { pub a: i8, #[jlrs(bits_union_align)] - _b_align: ::jlrs::wrappers::inline::union::Align4, + _b_align: ::jlrs::data::layout::union::Align4, #[jlrs(bits_union)] - pub b: ::jlrs::wrappers::inline::union::BitsUnion<4>, + pub b: ::jlrs::data::layout::union::BitsUnion<4>, #[jlrs(bits_union_flag)] pub b_flag: u8, pub c: i8, @@ -216,9 +213,9 @@ pub struct SingleVariant { pub struct SizeAlignMismatch { pub a: i8, #[jlrs(bits_union_align)] - _b_align: ::jlrs::wrappers::inline::union::Align4, + _b_align: ::jlrs::data::layout::union::Align4, #[jlrs(bits_union)] - pub b: ::jlrs::wrappers::inline::union::BitsUnion<6>, + pub b: ::jlrs::data::layout::union::BitsUnion<6>, #[jlrs(bits_union_flag)] pub b_flag: u8, pub c: i8, @@ -229,7 +226,7 @@ pub struct SizeAlignMismatch { #[jlrs(julia_type = "Main.WithBitsUnion.UnionInTuple")] pub struct UnionInTuple<'frame, 'data> { pub a: i8, - pub b: ::std::option::Option<::jlrs::wrappers::ptr::value::ValueRef<'frame, 'data>>, + pub b: ::std::option::Option<::jlrs::data::managed::value::ValueRef<'frame, 'data>>, pub c: i8, } @@ -247,7 +244,7 @@ where #[derive(Clone, Debug, Unbox, ValidLayout, ValidField, Typecheck)] #[jlrs(julia_type = "Main.WithGeneric.WithGenericUnionAll")] pub struct WithGenericUnionAll<'frame, 'data> { - pub a: ::std::option::Option<::jlrs::wrappers::ptr::value::ValueRef<'frame, 'data>>, + pub a: ::std::option::Option<::jlrs::data::managed::value::ValueRef<'frame, 'data>>, } #[repr(C)] @@ -264,7 +261,7 @@ where #[derive(Clone, Debug, Unbox, ValidLayout, ValidField, Typecheck)] #[jlrs(julia_type = "Main.WithGeneric.WithPropagatedLifetime")] pub struct WithPropagatedLifetime<'frame> { - pub a: WithGenericT<::std::option::Option<::jlrs::wrappers::ptr::module::ModuleRef<'frame>>>, + pub a: WithGenericT<::std::option::Option<::jlrs::data::managed::module::ModuleRef<'frame>>>, } #[repr(C)] @@ -272,10 +269,10 @@ pub struct WithPropagatedLifetime<'frame> { #[jlrs(julia_type = "Main.WithGeneric.WithPropagatedLifetimes")] pub struct WithPropagatedLifetimes<'frame, 'data> { pub a: WithGenericT< - ::jlrs::wrappers::inline::tuple::Tuple2< + ::jlrs::data::layout::tuple::Tuple2< i32, WithGenericT< - ::std::option::Option<::jlrs::wrappers::ptr::array::ArrayRef<'frame, 'data>>, + ::std::option::Option<::jlrs::data::managed::array::ArrayRef<'frame, 'data>>, >, >, >, @@ -292,7 +289,7 @@ pub struct WithSetGeneric { #[derive(Clone, Debug, Unbox, ValidLayout, ValidField, Typecheck, IntoJulia)] #[jlrs(julia_type = "Main.WithGeneric.WithSetGenericTuple")] pub struct WithSetGenericTuple { - pub a: ::jlrs::wrappers::inline::tuple::Tuple1>, + pub a: ::jlrs::data::layout::tuple::Tuple1>, } #[repr(C)] @@ -306,7 +303,7 @@ pub struct WithValueType { #[derive(Clone, Debug, Unbox, ValidLayout, ValidField, Typecheck)] #[jlrs(julia_type = "Main.WithNonBitsUnion.NonBitsUnion")] pub struct NonBitsUnion<'frame, 'data> { - pub a: ::std::option::Option<::jlrs::wrappers::ptr::value::ValueRef<'frame, 'data>>, + pub a: ::std::option::Option<::jlrs::data::managed::value::ValueRef<'frame, 'data>>, } #[repr(C)] diff --git a/jlrs/tests/util/mod.rs b/jlrs/tests/util/mod.rs index b2de8768..2b4bb316 100644 --- a/jlrs/tests/util/mod.rs +++ b/jlrs/tests/util/mod.rs @@ -2,9 +2,9 @@ use std::cell::RefCell; #[cfg(feature = "sync-rt")] use jlrs::{ + data::managed::value::Value, memory::stack_frame::StackFrame, runtime::{builder::RuntimeBuilder, sync_rt::PendingJulia}, - wrappers::ptr::value::Value, }; #[cfg(feature = "sync-rt")] diff --git a/jlrs/tests/valid_layout.rs b/jlrs/tests/valid_layout.rs index 3c4612e3..4252ed8a 100644 --- a/jlrs/tests/valid_layout.rs +++ b/jlrs/tests/valid_layout.rs @@ -168,7 +168,7 @@ mod tests { .as_value(); assert!(ArrayRef::valid_layout(v.datatype().as_value())); - let ua = Module::base(&frame).global(&frame, "Array")?.wrapper(); + let ua = Module::base(&frame).global(&frame, "Array")?.as_managed(); assert!(ArrayRef::valid_layout(ua)); } diff --git a/jlrs/tests/value_array.rs b/jlrs/tests/value_array.rs index 24e62257..d9b75984 100644 --- a/jlrs/tests/value_array.rs +++ b/jlrs/tests/value_array.rs @@ -33,12 +33,12 @@ mod tests { } { - let data = unsafe { arr.wrapper_data::()? }; + let data = unsafe { arr.managed_data::()? }; assert_eq!(unsafe { data.dimensions().as_slice() }, &[4]); } unsafe { - let data = arr.wrapper_data_mut::()?; + let data = arr.managed_data_mut::()?; assert_eq!(data.dimensions().as_slice(), &[4]); } @@ -71,29 +71,29 @@ mod tests { assert!(data.set(0, Some(module)).is_ok()); assert!(data.set(1, Some(module)).is_ok()); assert!(!data[0].is_none()); - assert_eq!(data[0].unwrap().value(), module); + assert_eq!(data[0].unwrap().as_value(), module); assert_eq!(data.get(&mut frame, 0).unwrap(), module); } unsafe { let data = arr.value_data()?; - assert_eq!(data[0].unwrap().value(), module); + assert_eq!(data[0].unwrap().as_value(), module); assert_eq!(data.get(&mut frame, 0).unwrap(), module); } unsafe { - let data = arr.wrapper_data::()?; - assert_eq!(data[1].unwrap().value(), module); + let data = arr.managed_data::()?; + assert_eq!(data[1].unwrap().as_value(), module); assert_eq!(data.get(&mut frame, 1).unwrap(), module.cast::()?); } unsafe { - let mut data = arr.wrapper_data_mut::()?; + let mut data = arr.managed_data_mut::()?; assert!(data[2].is_none()); assert!(data.set(2, Some(module)).is_ok()); assert!(!data[2].is_none()); - assert_eq!(data[2].unwrap().value(), module); - assert_eq!(data.get(&frame, 2).unwrap().value(), module); + assert_eq!(data[2].unwrap().as_value(), module); + assert_eq!(data.get(&frame, 2).unwrap().as_value(), module); assert!(data.set(2, None).is_ok()); assert!(data[2].is_none()); @@ -128,7 +128,7 @@ mod tests { } { - let mut data = unsafe { arr.wrapper_data_mut::()? }; + let mut data = unsafe { arr.managed_data_mut::()? }; assert!(data.set(0, Some(module)).is_err()); } @@ -166,13 +166,13 @@ mod tests { } { - let data = unsafe { arr.wrapper_data::()? }; + let data = unsafe { arr.managed_data::()? }; let slice = data.as_slice(); assert_eq!(slice.len(), 4) } { - let data = unsafe { arr.wrapper_data_mut::()? }; + let data = unsafe { arr.managed_data_mut::()? }; let slice = data.as_slice(); assert_eq!(slice.len(), 4) } diff --git a/jlrs/tests/vararg.rs b/jlrs/tests/vararg.rs index c8d5dc6f..7dab415a 100644 --- a/jlrs/tests/vararg.rs +++ b/jlrs/tests/vararg.rs @@ -6,9 +6,9 @@ mod util; ))] mod not_lts { use jlrs::{ + data::managed::internal::vararg::{Vararg, VarargRef}, layout::valid_layout::ValidLayout, prelude::*, - wrappers::ptr::internal::vararg::{Vararg, VarargRef}, }; use super::util::JULIA; @@ -30,7 +30,7 @@ mod not_lts { let vararg = vararg.cast::()?; assert_eq!( - vararg.t(&frame).unwrap().value().cast::()?, + vararg.t(&frame).unwrap().as_value().cast::()?, DataType::int32_type(&frame) ); assert!(vararg.n(&frame).is_none()); @@ -80,7 +80,7 @@ mod not_lts { let vararg = instance.cast::()?; assert_eq!( - vararg.t(&frame).unwrap().value().cast::()?, + vararg.t(&frame).unwrap().as_value().cast::()?, DataType::int32_type(&frame) ); assert!(vararg.n(&frame).is_none()); @@ -108,10 +108,10 @@ mod not_lts { let vararg = instance.cast::()?; assert_eq!( - vararg.t(&frame).unwrap().value().cast::()?, + vararg.t(&frame).unwrap().as_value().cast::()?, DataType::int32_type(&frame) ); - assert_eq!(vararg.n(&frame).unwrap().value().unbox::()?, 3); + assert_eq!(vararg.n(&frame).unwrap().as_value().unbox::()?, 3); Ok(()) }) .unwrap(); diff --git a/jlrs_derive/src/lib.rs b/jlrs_derive/src/lib.rs index 80a8ad02..91d5adbe 100644 --- a/jlrs_derive/src/lib.rs +++ b/jlrs_derive/src/lib.rs @@ -188,22 +188,22 @@ fn impl_into_julia(ast: &syn::DeriveInput) -> TokenStream { let into_julia_impl = quote! { unsafe impl ::jlrs::convert::into_julia::IntoJulia for #name { - fn julia_type<'scope, T>(target: T) -> ::jlrs::wrappers::ptr::datatype::DataTypeData<'scope, T> + fn julia_type<'scope, T>(target: T) -> ::jlrs::data::managed::datatype::DataTypeData<'scope, T> where T: ::jlrs::memory::target::Target<'scope>, { unsafe { let global = target.unrooted(); - ::jlrs::wrappers::ptr::module::Module::#func(&global) + ::jlrs::data::managed::module::Module::#func(&global) #( .submodule(&global, #modules_it) .expect(&format!("Submodule {} cannot be found", #modules_it_b)) - .wrapper() + .as_managed() )* .global(&global, #ty) .expect(&format!("Type {} cannot be found in module", #ty)) - .value() - .cast::<::jlrs::wrappers::ptr::datatype::DataType>() + .as_value() + .cast::<::jlrs::data::managed::datatype::DataType>() .expect("Type is not a DataType") .root(target) } @@ -219,15 +219,15 @@ fn impl_into_julia(ast: &syn::DeriveInput) -> TokenStream { fn impl_into_julia_fn(attrs: &JlrsTypeAttrs) -> Option { if attrs.zst { Some(quote! { - unsafe fn into_julia<'target, T>(self, target: T) -> ::jlrs::wrappers::ptr::value::ValueData<'target, 'static, T> + unsafe fn into_julia<'target, T>(self, target: T) -> ::jlrs::data::managed::value::ValueData<'target, 'static, T> where T: ::jlrs::memory::target::Target<'scope>, { let ty = self.julia_type(global); unsafe { - ty.wrapper() + ty.as_managed() .instance() - .value() + .as_value() .expect("Instance is undefined") .as_ref() } @@ -267,7 +267,7 @@ fn impl_typecheck(ast: &syn::DeriveInput) -> TokenStream { let typecheck_impl = quote! { unsafe impl #generics ::jlrs::layout::typecheck::Typecheck for #name #generics #where_clause { - fn typecheck(dt: ::jlrs::wrappers::ptr::datatype::DataType) -> bool { + fn typecheck(dt: ::jlrs::data::managed::datatype::DataType) -> bool { ::valid_layout(dt.as_value()) } } @@ -308,28 +308,28 @@ fn impl_valid_layout(ast: &syn::DeriveInput) -> TokenStream { let valid_layout_impl = quote! { unsafe impl #generics ::jlrs::layout::valid_layout::ValidLayout for #name #generics #where_clause { - fn valid_layout(v: ::jlrs::wrappers::ptr::value::Value) -> bool { + fn valid_layout(v: ::jlrs::data::managed::value::Value) -> bool { unsafe { - if let Ok(dt) = v.cast::<::jlrs::wrappers::ptr::datatype::DataType>() { + if let Ok(dt) = v.cast::<::jlrs::data::managed::datatype::DataType>() { if dt.n_fields() as usize != #n_fields { return false; } let global = v.unrooted_target(); let field_types = dt.field_types(global); - let field_types_svec = field_types.wrapper(); + let field_types_svec = field_types.as_managed(); let field_types_data = field_types_svec.data(); let field_types = field_types_data.as_slice(); #( - if !<#rs_non_union_fields as ::jlrs::layout::valid_layout::ValidField>::valid_field(field_types[#jl_non_union_field_idxs].unwrap().wrapper()) { + if !<#rs_non_union_fields as ::jlrs::layout::valid_layout::ValidField>::valid_field(field_types[#jl_non_union_field_idxs].unwrap().as_managed()) { return false; } )* #( - if let Ok(u) = field_types[#jl_union_field_idxs].unwrap().wrapper().cast::<::jlrs::wrappers::ptr::union::Union>() { - if !::jlrs::wrappers::inline::union::correct_layout_for::<#rs_align_fields, #rs_union_fields, #rs_flag_fields>(u) { + if let Ok(u) = field_types[#jl_union_field_idxs].unwrap().as_managed().cast::<::jlrs::data::managed::union::Union>() { + if !::jlrs::data::layout::union::correct_layout_for::<#rs_align_fields, #rs_union_fields, #rs_flag_fields>(u) { return false } } else { @@ -363,7 +363,7 @@ fn impl_valid_field(ast: &syn::DeriveInput) -> TokenStream { let valid_field_impl = quote! { unsafe impl #generics ::jlrs::layout::valid_layout::ValidField for #name #generics #where_clause { - fn valid_field(v: ::jlrs::wrappers::ptr::value::Value) -> bool { + fn valid_field(v: ::jlrs::data::managed::value::Value) -> bool { ::valid_layout(v) } } diff --git a/rustfmt.toml b/rustfmt.toml index d5539bb4..e5a4dc4a 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,4 +1,3 @@ -# imports_layout = "HorizontalVertical" -# imports_granularity = "Crate" -# group_imports = "StdExternalCrate" -# format_code_in_doc_comments = true +imports_granularity = "Crate" +group_imports = "StdExternalCrate" +format_code_in_doc_comments = true