rename evalstate.rs + evalstatebuilder.rs
This commit is contained in:
parent
d6f3b5a691
commit
f3899a532a
3 changed files with 29 additions and 33 deletions
|
|
@ -1,10 +1,12 @@
|
||||||
|
use std::cell::RefCell;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::errors::new_nixide_error;
|
use crate::errors::new_nixide_error;
|
||||||
|
|
||||||
use super::{NixValue, Value};
|
use super::Value;
|
||||||
use crate::errors::ErrorContext;
|
use crate::errors::ErrorContext;
|
||||||
use crate::sys;
|
use crate::sys;
|
||||||
use crate::util::wrappers::AsInnerPtr;
|
use crate::util::wrappers::AsInnerPtr;
|
||||||
|
|
@ -16,7 +18,7 @@ use crate::{NixideResult, Store};
|
||||||
/// This provides the main interface for evaluating Nix expressions
|
/// This provides the main interface for evaluating Nix expressions
|
||||||
/// and creating values.
|
/// and creating values.
|
||||||
pub struct EvalState {
|
pub struct EvalState {
|
||||||
inner: NonNull<sys::EvalState>,
|
inner: Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||||
|
|
||||||
// XXX: TODO: is an `Arc<Store>` necessary or just a `Store`
|
// XXX: TODO: is an `Arc<Store>` necessary or just a `Store`
|
||||||
store: Arc<Store>,
|
store: Arc<Store>,
|
||||||
|
|
@ -25,24 +27,32 @@ pub struct EvalState {
|
||||||
impl AsInnerPtr<sys::EvalState> for EvalState {
|
impl AsInnerPtr<sys::EvalState> for EvalState {
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn as_ptr(&self) -> *mut sys::EvalState {
|
unsafe fn as_ptr(&self) -> *mut sys::EvalState {
|
||||||
self.inner.as_ptr()
|
self.inner.borrow().as_ptr()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn as_ref(&self) -> &sys::EvalState {
|
unsafe fn as_ref(&self) -> &sys::EvalState {
|
||||||
unsafe { self.inner.as_ref() }
|
unsafe { self.inner.borrow().as_ref() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn as_mut(&mut self) -> &mut sys::EvalState {
|
unsafe fn as_mut(&mut self) -> &mut sys::EvalState {
|
||||||
unsafe { self.inner.as_mut() }
|
unsafe { self.inner.borrow_mut().as_mut() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EvalState {
|
impl EvalState {
|
||||||
/// Construct a new EvalState directly from its attributes
|
/// Construct a new EvalState directly from its attributes
|
||||||
pub(super) fn new(inner: NonNull<sys::EvalState>, store: Arc<Store>) -> Self {
|
pub(super) fn new(inner: NonNull<sys::EvalState>, store: Arc<Store>) -> Self {
|
||||||
Self { inner, store }
|
Self {
|
||||||
|
inner: Rc::new(RefCell::new(inner)),
|
||||||
|
store,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub(crate) fn inner_ref(&self) -> Rc<RefCell<NonNull<sys::EvalState>>> {
|
||||||
|
self.inner.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
@ -82,22 +92,7 @@ impl EvalState {
|
||||||
);
|
);
|
||||||
value
|
value
|
||||||
})
|
})
|
||||||
.map(|ptr| Value::from((ptr, std::rc::Rc::new(std::cell::RefCell::new(self)))))
|
.map(|ptr| Value::from((ptr, self.inner_ref())))
|
||||||
}
|
|
||||||
|
|
||||||
/// Allocate a new value.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
///
|
|
||||||
/// Returns an error if value allocation fails.
|
|
||||||
pub(self) fn new_value(&self) -> NixideResult<Value> {
|
|
||||||
// XXX: TODO: should this function be `Value::new` instead?
|
|
||||||
let inner = wrap::nix_ptr_fn!(|ctx: &ErrorContext| unsafe {
|
|
||||||
sys::nix_alloc_value(ctx.as_ptr(), self.as_ptr())
|
|
||||||
})?;
|
|
||||||
|
|
||||||
// Ok(Value::from((inner, self)))
|
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,13 +129,14 @@ impl EvalStateBuilder {
|
||||||
.map(|()| self);
|
.map(|()| self);
|
||||||
|
|
||||||
// ensure all allocated memory is dropped
|
// ensure all allocated memory is dropped
|
||||||
unsafe {
|
// XXX: TODO!!
|
||||||
Vec::from_raw_parts(ptr, paths_len, paths_capacity)
|
// unsafe {
|
||||||
.into_iter()
|
// Vec::from_raw_parts(ptr, paths_len, paths_capacity)
|
||||||
.map(|p| {
|
// .into_iter()
|
||||||
_ = CString::from_raw(p as *mut c_char);
|
// .map(|p| {
|
||||||
})
|
// _ = CString::from_raw(p as *mut c_char);
|
||||||
};
|
// })
|
||||||
|
// };
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
mod evalstate;
|
mod eval_state;
|
||||||
mod evalstatebuilder;
|
mod eval_state_builder;
|
||||||
mod realised_string;
|
mod realised_string;
|
||||||
mod values;
|
mod values;
|
||||||
|
|
||||||
pub use evalstate::EvalState;
|
pub use eval_state::EvalState;
|
||||||
pub use evalstatebuilder::EvalStateBuilder;
|
pub use eval_state_builder::EvalStateBuilder;
|
||||||
pub use realised_string::RealisedString;
|
pub use realised_string::RealisedString;
|
||||||
pub use values::*;
|
pub use values::*;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue