vaues now use Rc<RefCell<NonNull<sys::EvalState>>>
This commit is contained in:
parent
c5c3f6c8d4
commit
f96f1cf95e
16 changed files with 60 additions and 103 deletions
|
|
@ -101,7 +101,7 @@ impl EvalState {
|
||||||
sys::nix_expr_eval_from_string(ctx.as_ptr(), self.as_ptr(), expr, path, value.as_ptr());
|
sys::nix_expr_eval_from_string(ctx.as_ptr(), self.as_ptr(), expr, path, value.as_ptr());
|
||||||
value
|
value
|
||||||
})
|
})
|
||||||
.map(|ptr| Value::from((ptr, self)))
|
.map(|ptr| Value::from((ptr, self.inner_ref().clone())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,22 +22,6 @@ pub struct EvalStateBuilder {
|
||||||
store: Rc<RefCell<Store>>,
|
store: Rc<RefCell<Store>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl Clone for EvalStateBuilder {
|
|
||||||
// fn clone(&self) -> Self {
|
|
||||||
// let inner = self.inner.clone();
|
|
||||||
//
|
|
||||||
// wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
|
||||||
// sys::nix_gc_incref(ctx.as_ptr(), self.as_ptr() as *mut c_void);
|
|
||||||
// })
|
|
||||||
// .unwrap();
|
|
||||||
//
|
|
||||||
// Self {
|
|
||||||
// inner,
|
|
||||||
// store: self.store.clone(),
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
impl AsInnerPtr<sys::nix_eval_state_builder> for EvalStateBuilder {
|
impl AsInnerPtr<sys::nix_eval_state_builder> for EvalStateBuilder {
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn as_ptr(&self) -> *mut sys::nix_eval_state_builder {
|
unsafe fn as_ptr(&self) -> *mut sys::nix_eval_state_builder {
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@ use std::ptr::{self, NonNull};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use super::{NixThunk, NixValue, Value};
|
use super::{NixThunk, NixValue, Value};
|
||||||
|
use crate::NixError;
|
||||||
use crate::errors::{ErrorContext, NixideError};
|
use crate::errors::{ErrorContext, NixideError};
|
||||||
use crate::stdext::{AsCPtr, CCharPtrExt};
|
use crate::stdext::{AsCPtr, CCharPtrExt};
|
||||||
use crate::sys;
|
use crate::sys;
|
||||||
use crate::util::wrappers::AsInnerPtr;
|
use crate::util::wrappers::AsInnerPtr;
|
||||||
use crate::util::{panic_issue_call_failed, wrap};
|
use crate::util::{panic_issue_call_failed, wrap};
|
||||||
use crate::{EvalState, NixError};
|
|
||||||
|
|
||||||
pub struct NixAttrs {
|
pub struct NixAttrs {
|
||||||
inner: NonNull<sys::nix_value>,
|
inner: NonNull<sys::nix_value>,
|
||||||
|
|
@ -78,17 +78,13 @@ impl NixValue for NixAttrs {
|
||||||
sys::ValueType_NIX_TYPE_ATTRS
|
sys::ValueType_NIX_TYPE_ATTRS
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from(inner: NonNull<sys::nix_value>, state: &EvalState) -> Self {
|
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||||
let len = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
let len = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
sys::nix_get_attrs_size(ctx.as_ptr(), inner.as_ptr())
|
sys::nix_get_attrs_size(ctx.as_ptr(), inner.as_ptr())
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
||||||
|
|
||||||
Self {
|
Self { inner, state, len }
|
||||||
inner,
|
|
||||||
state: state.inner_ref().clone(),
|
|
||||||
len,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,7 +116,7 @@ impl NixAttrs {
|
||||||
.to_utf8_string()
|
.to_utf8_string()
|
||||||
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
||||||
|
|
||||||
let value = Value::from((inner, &self.state));
|
let value = Value::from((inner, self.state.clone()));
|
||||||
|
|
||||||
Some((name, value))
|
Some((name, value))
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +143,7 @@ impl NixAttrs {
|
||||||
.to_utf8_string()
|
.to_utf8_string()
|
||||||
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
||||||
|
|
||||||
let value = <NixThunk as NixValue>::from(inner, &self.state);
|
let value = <NixThunk as NixValue>::from(inner, self.state.clone());
|
||||||
|
|
||||||
Some((name, value))
|
Some((name, value))
|
||||||
}
|
}
|
||||||
|
|
@ -190,7 +186,7 @@ impl NixAttrs {
|
||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(inner) => Some(Value::from((inner, &self.state))),
|
Ok(inner) => Some(Value::from((inner, self.state.clone()))),
|
||||||
|
|
||||||
Err(NixideError::NixError {
|
Err(NixideError::NixError {
|
||||||
err: NixError::KeyNotFound(_),
|
err: NixError::KeyNotFound(_),
|
||||||
|
|
@ -216,7 +212,7 @@ impl NixAttrs {
|
||||||
});
|
});
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(inner) => Some(<NixThunk as NixValue>::from(inner, &self.state)),
|
Ok(inner) => Some(<NixThunk as NixValue>::from(inner, self.state.clone())),
|
||||||
|
|
||||||
Err(NixideError::NixError {
|
Err(NixideError::NixError {
|
||||||
err: NixError::KeyNotFound(_),
|
err: NixError::KeyNotFound(_),
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ use std::rc::Rc;
|
||||||
|
|
||||||
use super::NixValue;
|
use super::NixValue;
|
||||||
use crate::errors::ErrorContext;
|
use crate::errors::ErrorContext;
|
||||||
|
use crate::sys;
|
||||||
use crate::util::panic_issue_call_failed;
|
use crate::util::panic_issue_call_failed;
|
||||||
use crate::util::wrap;
|
use crate::util::wrap;
|
||||||
use crate::util::wrappers::AsInnerPtr;
|
use crate::util::wrappers::AsInnerPtr;
|
||||||
use crate::{EvalState, sys};
|
|
||||||
|
|
||||||
pub struct NixBool {
|
pub struct NixBool {
|
||||||
inner: NonNull<sys::nix_value>,
|
inner: NonNull<sys::nix_value>,
|
||||||
|
|
@ -77,7 +77,7 @@ impl NixValue for NixBool {
|
||||||
sys::ValueType_NIX_TYPE_BOOL
|
sys::ValueType_NIX_TYPE_BOOL
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from(inner: NonNull<sys::nix_value>, state: &EvalState) -> Self {
|
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||||
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
sys::nix_get_bool(ctx.as_ptr(), inner.as_ptr())
|
sys::nix_get_bool(ctx.as_ptr(), inner.as_ptr())
|
||||||
})
|
})
|
||||||
|
|
@ -87,7 +87,7 @@ impl NixValue for NixBool {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
inner,
|
inner,
|
||||||
state: state.inner_ref().clone(),
|
state,
|
||||||
value,
|
value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ use std::ptr::NonNull;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use super::NixValue;
|
use super::NixValue;
|
||||||
use crate::EvalState;
|
|
||||||
use crate::errors::ErrorContext;
|
use crate::errors::ErrorContext;
|
||||||
use crate::sys;
|
use crate::sys;
|
||||||
use crate::util::wrappers::AsInnerPtr;
|
use crate::util::wrappers::AsInnerPtr;
|
||||||
|
|
@ -77,7 +76,7 @@ impl NixValue for NixFloat {
|
||||||
sys::ValueType_NIX_TYPE_FLOAT
|
sys::ValueType_NIX_TYPE_FLOAT
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from(inner: NonNull<sys::nix_value>, state: &EvalState) -> Self {
|
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||||
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
sys::nix_get_float(ctx.as_ptr(), inner.as_ptr())
|
sys::nix_get_float(ctx.as_ptr(), inner.as_ptr())
|
||||||
})
|
})
|
||||||
|
|
@ -87,7 +86,7 @@ impl NixValue for NixFloat {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
inner,
|
inner,
|
||||||
state: state.inner_ref().clone(),
|
state,
|
||||||
value,
|
value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ use std::rc::Rc;
|
||||||
use super::{NixValue, Value};
|
use super::{NixValue, Value};
|
||||||
use crate::errors::ErrorContext;
|
use crate::errors::ErrorContext;
|
||||||
use crate::stdext::SliceExt;
|
use crate::stdext::SliceExt;
|
||||||
|
use crate::sys;
|
||||||
use crate::util::wrappers::AsInnerPtr;
|
use crate::util::wrappers::AsInnerPtr;
|
||||||
use crate::util::{panic_issue_call_failed, wrap};
|
use crate::util::{panic_issue_call_failed, wrap};
|
||||||
use crate::{EvalState, sys};
|
|
||||||
|
|
||||||
pub struct NixFunction {
|
pub struct NixFunction {
|
||||||
inner: NonNull<sys::nix_value>,
|
inner: NonNull<sys::nix_value>,
|
||||||
|
|
@ -75,11 +75,8 @@ impl NixValue for NixFunction {
|
||||||
sys::ValueType_NIX_TYPE_FUNCTION
|
sys::ValueType_NIX_TYPE_FUNCTION
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from(inner: NonNull<sys::nix_value>, state: &EvalState) -> Self {
|
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||||
Self {
|
Self { inner, state }
|
||||||
inner,
|
|
||||||
state: state.inner_ref().clone(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,7 +101,7 @@ impl NixFunction {
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
||||||
|
|
||||||
Value::from((inner, &self.state))
|
Value::from((inner, self.state.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn call_many<T>(&self, args: &[&T]) -> Value
|
pub fn call_many<T>(&self, args: &[&T]) -> Value
|
||||||
|
|
@ -128,7 +125,7 @@ impl NixFunction {
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
||||||
|
|
||||||
Value::from((inner, &self.state))
|
Value::from((inner, self.state.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ use std::ptr::NonNull;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use super::NixValue;
|
use super::NixValue;
|
||||||
use crate::EvalState;
|
|
||||||
use crate::errors::ErrorContext;
|
use crate::errors::ErrorContext;
|
||||||
use crate::sys;
|
use crate::sys;
|
||||||
use crate::util::wrappers::AsInnerPtr;
|
use crate::util::wrappers::AsInnerPtr;
|
||||||
|
|
@ -77,7 +76,7 @@ impl NixValue for NixInt {
|
||||||
sys::ValueType_NIX_TYPE_INT
|
sys::ValueType_NIX_TYPE_INT
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from(inner: NonNull<sys::nix_value>, state: &EvalState) -> Self {
|
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||||
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
sys::nix_get_int(ctx.as_ptr(), inner.as_ptr())
|
sys::nix_get_int(ctx.as_ptr(), inner.as_ptr())
|
||||||
})
|
})
|
||||||
|
|
@ -85,7 +84,7 @@ impl NixValue for NixInt {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
inner,
|
inner,
|
||||||
state: state.inner_ref().clone(),
|
state,
|
||||||
value,
|
value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ use std::ptr::NonNull;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use super::{NixThunk, NixValue, Value};
|
use super::{NixThunk, NixValue, Value};
|
||||||
use crate::EvalState;
|
|
||||||
use crate::errors::ErrorContext;
|
use crate::errors::ErrorContext;
|
||||||
use crate::sys;
|
use crate::sys;
|
||||||
use crate::util::wrappers::AsInnerPtr;
|
use crate::util::wrappers::AsInnerPtr;
|
||||||
|
|
@ -75,11 +74,8 @@ impl NixValue for NixList {
|
||||||
sys::ValueType_NIX_TYPE_LIST
|
sys::ValueType_NIX_TYPE_LIST
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from(inner: NonNull<sys::nix_value>, state: &EvalState) -> Self {
|
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||||
Self {
|
Self { inner, state }
|
||||||
inner,
|
|
||||||
state: state.inner_ref().clone(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,7 +123,7 @@ impl NixList {
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
||||||
|
|
||||||
Value::from((inner, &self.state))
|
Value::from((inner, self.state.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_lazy(&self, index: u32) -> NixThunk {
|
pub fn get_lazy(&self, index: u32) -> NixThunk {
|
||||||
|
|
@ -141,6 +137,6 @@ impl NixList {
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
||||||
|
|
||||||
<NixThunk as NixValue>::from(inner, &self.state)
|
<NixThunk as NixValue>::from(inner, self.state.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,11 @@ pub use path::NixPath;
|
||||||
pub use string::NixString;
|
pub use string::NixString;
|
||||||
pub use thunk::NixThunk;
|
pub use thunk::NixThunk;
|
||||||
|
|
||||||
|
use std::cell::RefCell;
|
||||||
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
|
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::EvalState;
|
|
||||||
use crate::errors::ErrorContext;
|
use crate::errors::ErrorContext;
|
||||||
use crate::sys;
|
use crate::sys;
|
||||||
use crate::sys::{
|
use crate::sys::{
|
||||||
|
|
@ -43,7 +44,7 @@ pub trait NixValue: Clone + Drop + Display + Debug + AsInnerPtr<sys::nix_value>
|
||||||
fn type_id(&self) -> sys::ValueType;
|
fn type_id(&self) -> sys::ValueType;
|
||||||
|
|
||||||
/// TODO
|
/// TODO
|
||||||
fn from(inner: NonNull<sys::nix_value>, state: &EvalState) -> Self;
|
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Nix value
|
/// A Nix value
|
||||||
|
|
@ -109,12 +110,22 @@ pub enum Value {
|
||||||
// Failed(NixFailed),
|
// Failed(NixFailed),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(NonNull<sys::nix_value>, &EvalState)> for Value {
|
impl
|
||||||
fn from(value: (NonNull<sys::nix_value>, &EvalState)) -> Self {
|
From<(
|
||||||
|
NonNull<sys::nix_value>,
|
||||||
|
Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||||
|
)> for Value
|
||||||
|
{
|
||||||
|
fn from(
|
||||||
|
value: (
|
||||||
|
NonNull<sys::nix_value>,
|
||||||
|
Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||||
|
),
|
||||||
|
) -> Self {
|
||||||
let (inner, state) = value;
|
let (inner, state) = value;
|
||||||
|
|
||||||
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
sys::nix_value_force(ctx.as_ptr(), state.as_ptr(), inner.as_ptr())
|
sys::nix_value_force(ctx.as_ptr(), state.borrow().as_ptr(), inner.as_ptr())
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ use std::ptr::NonNull;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use super::NixValue;
|
use super::NixValue;
|
||||||
use crate::EvalState;
|
|
||||||
use crate::errors::ErrorContext;
|
use crate::errors::ErrorContext;
|
||||||
use crate::sys;
|
use crate::sys;
|
||||||
use crate::util::wrap;
|
use crate::util::wrap;
|
||||||
|
|
@ -75,10 +74,7 @@ impl NixValue for NixNull {
|
||||||
sys::ValueType_NIX_TYPE_NULL
|
sys::ValueType_NIX_TYPE_NULL
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from(inner: NonNull<sys::nix_value>, state: &EvalState) -> Self {
|
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||||
Self {
|
Self { inner, state }
|
||||||
inner,
|
|
||||||
state: state.inner_ref().clone(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@ use std::rc::Rc;
|
||||||
use super::NixValue;
|
use super::NixValue;
|
||||||
use crate::errors::ErrorContext;
|
use crate::errors::ErrorContext;
|
||||||
use crate::stdext::CCharPtrExt;
|
use crate::stdext::CCharPtrExt;
|
||||||
|
use crate::sys;
|
||||||
use crate::util::panic_issue_call_failed;
|
use crate::util::panic_issue_call_failed;
|
||||||
use crate::util::wrap;
|
use crate::util::wrap;
|
||||||
use crate::util::wrappers::AsInnerPtr;
|
use crate::util::wrappers::AsInnerPtr;
|
||||||
use crate::{EvalState, sys};
|
|
||||||
|
|
||||||
pub struct NixPath {
|
pub struct NixPath {
|
||||||
inner: NonNull<sys::nix_value>,
|
inner: NonNull<sys::nix_value>,
|
||||||
|
|
@ -79,7 +79,7 @@ impl NixValue for NixPath {
|
||||||
sys::ValueType_NIX_TYPE_PATH
|
sys::ValueType_NIX_TYPE_PATH
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from(inner: NonNull<sys::nix_value>, state: &EvalState) -> Self {
|
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||||
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
sys::nix_get_path_string(ctx.as_ptr(), inner.as_ptr())
|
sys::nix_get_path_string(ctx.as_ptr(), inner.as_ptr())
|
||||||
})
|
})
|
||||||
|
|
@ -89,7 +89,7 @@ impl NixValue for NixPath {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
inner,
|
inner,
|
||||||
state: state.inner_ref().clone(),
|
state,
|
||||||
value,
|
value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ use std::rc::Rc;
|
||||||
|
|
||||||
use super::NixValue;
|
use super::NixValue;
|
||||||
use crate::errors::ErrorContext;
|
use crate::errors::ErrorContext;
|
||||||
|
use crate::sys;
|
||||||
use crate::util::panic_issue_call_failed;
|
use crate::util::panic_issue_call_failed;
|
||||||
use crate::util::wrap;
|
use crate::util::wrap;
|
||||||
use crate::util::wrappers::AsInnerPtr;
|
use crate::util::wrappers::AsInnerPtr;
|
||||||
use crate::{EvalState, sys};
|
|
||||||
|
|
||||||
pub struct NixString {
|
pub struct NixString {
|
||||||
inner: NonNull<sys::nix_value>,
|
inner: NonNull<sys::nix_value>,
|
||||||
|
|
@ -78,7 +78,7 @@ impl NixValue for NixString {
|
||||||
sys::ValueType_NIX_TYPE_STRING
|
sys::ValueType_NIX_TYPE_STRING
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from(inner: NonNull<sys::nix_value>, state: &EvalState) -> Self {
|
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||||
let value = wrap::nix_string_callback!(
|
let value = wrap::nix_string_callback!(
|
||||||
|callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe {
|
|callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe {
|
||||||
sys::nix_get_string(
|
sys::nix_get_string(
|
||||||
|
|
@ -93,7 +93,7 @@ impl NixValue for NixString {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
inner,
|
inner,
|
||||||
state: state.inner_ref().clone(),
|
state,
|
||||||
value,
|
value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ use std::ptr::NonNull;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use super::{NixValue, Value};
|
use super::{NixValue, Value};
|
||||||
use crate::EvalState;
|
|
||||||
use crate::errors::ErrorContext;
|
use crate::errors::ErrorContext;
|
||||||
use crate::sys;
|
use crate::sys;
|
||||||
use crate::util::wrappers::AsInnerPtr;
|
use crate::util::wrappers::AsInnerPtr;
|
||||||
|
|
@ -75,11 +74,8 @@ impl NixValue for NixThunk {
|
||||||
sys::ValueType_NIX_TYPE_THUNK
|
sys::ValueType_NIX_TYPE_THUNK
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from(inner: NonNull<sys::nix_value>, state: &EvalState) -> Self {
|
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||||
Self {
|
Self { inner, state }
|
||||||
inner,
|
|
||||||
state: state.inner_ref().clone(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,6 +90,6 @@ impl NixThunk {
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
|
||||||
|
|
||||||
Value::from((self.inner, &self.state))
|
Value::from((self.inner, self.state.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
use std::ffi::c_void;
|
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
use crate::NixideResult;
|
use crate::NixideResult;
|
||||||
|
|
@ -20,19 +19,6 @@ impl Drop for FlakeSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl Clone for FlakeSettings {
|
|
||||||
// fn clone(&self) -> Self {
|
|
||||||
// let inner = self.inner.clone();
|
|
||||||
//
|
|
||||||
// wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
|
||||||
// sys::nix_gc_incref(ctx.as_ptr(), self.as_ptr() as *mut c_void);
|
|
||||||
// })
|
|
||||||
// .unwrap();
|
|
||||||
//
|
|
||||||
// Self { inner }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
impl AsInnerPtr<sys::nix_flake_settings> for FlakeSettings {
|
impl AsInnerPtr<sys::nix_flake_settings> for FlakeSettings {
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn as_ptr(&self) -> *mut sys::nix_flake_settings {
|
unsafe fn as_ptr(&self) -> *mut sys::nix_flake_settings {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
// XXX: TODO: find a way to read directly from FlakeSettings and FetchersSettings (the C++ classes)
|
// XXX: TODO: find a way to read directly from FlakeSettings and FetchersSettings (the C++ classes)
|
||||||
|
|
||||||
use std::ffi::c_void;
|
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
use super::{FetchersSettings, FlakeLockFlags, FlakeReference, FlakeSettings};
|
use super::{FetchersSettings, FlakeLockFlags, FlakeReference, FlakeSettings};
|
||||||
|
|
@ -130,8 +129,8 @@ mod tests {
|
||||||
fn flake_settings_getflake_exists() {
|
fn flake_settings_getflake_exists() {
|
||||||
init();
|
init();
|
||||||
|
|
||||||
let store = Store::default().expect("Failed to open store connection");
|
let store_ref = Store::default().expect("Failed to open store connection");
|
||||||
let state = EvalStateBuilder::new(&store)
|
let state = EvalStateBuilder::new(store_ref.clone())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.flakes()
|
.flakes()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -165,10 +164,10 @@ mod tests {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let store = Store::default().unwrap();
|
let store_ref = Store::default().unwrap();
|
||||||
let flake_settings = FlakeSettings::new().unwrap();
|
let flake_settings = FlakeSettings::new().unwrap();
|
||||||
|
|
||||||
let mut eval_state = EvalStateBuilder::new(&store)
|
let mut eval_state = EvalStateBuilder::new(store_ref.clone())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_flake_settings(&flake_settings)
|
.set_flake_settings(&flake_settings)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
@ -214,10 +213,10 @@ mod tests {
|
||||||
fn flake_lock_load_flake_with_flags() {
|
fn flake_lock_load_flake_with_flags() {
|
||||||
init();
|
init();
|
||||||
|
|
||||||
let store = Store::default().unwrap();
|
let store_ref = Store::default().unwrap();
|
||||||
let fetchers_settings = FetchersSettings::new().unwrap();
|
let fetchers_settings = FetchersSettings::new().unwrap();
|
||||||
let flake_settings = FlakeSettings::new().unwrap();
|
let flake_settings = FlakeSettings::new().unwrap();
|
||||||
let mut eval_state = EvalStateBuilder::new(&store)
|
let mut eval_state = EvalStateBuilder::new(store_ref.clone())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_flake_settings(&flake_settings)
|
.set_flake_settings(&flake_settings)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
use super::{Store, StorePath};
|
use super::{Store, StorePath};
|
||||||
use crate::errors::ErrorContext;
|
|
||||||
use crate::init::LIBNIX_INIT_STATUS;
|
use crate::init::LIBNIX_INIT_STATUS;
|
||||||
use crate::sys;
|
|
||||||
use crate::util::wrappers::AsInnerPtr as _;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[serial]
|
#[serial]
|
||||||
|
|
@ -22,7 +19,7 @@ fn test_store_path_parse() {
|
||||||
let store = Store::default().expect("Failed to open store");
|
let store = Store::default().expect("Failed to open store");
|
||||||
|
|
||||||
// Try parsing a well-formed store path
|
// Try parsing a well-formed store path
|
||||||
let result = StorePath::fake_path(&store);
|
let result = StorePath::fake_path(&store.borrow());
|
||||||
result.expect("idk hopefully this fails");
|
result.expect("idk hopefully this fails");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,7 +31,8 @@ fn test_store_path_clone() {
|
||||||
let store = Store::default().expect("Failed to open store");
|
let store = Store::default().expect("Failed to open store");
|
||||||
|
|
||||||
// Try to get a valid store path by parsing
|
// Try to get a valid store path by parsing
|
||||||
let path = StorePath::fake_path(&store).expect("Failed to create `StorePath::fake_path`");
|
let path =
|
||||||
|
StorePath::fake_path(&store.borrow()).expect("Failed to create `StorePath::fake_path`");
|
||||||
let cloned = path.clone();
|
let cloned = path.clone();
|
||||||
|
|
||||||
// Assert that the cloned path has the same name as the original
|
// Assert that the cloned path has the same name as the original
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue