value types now store Rc<RefCell<NonNull<sys::EvalState>>>

This commit is contained in:
do butterflies cry? 2026-03-29 18:29:47 +10:00
parent 07a3b6c0bc
commit 37e78a9052
Signed by: cry
GPG key ID: F68745A836CA0412
11 changed files with 50 additions and 50 deletions

View file

@ -4,16 +4,16 @@ use std::ptr::{self, NonNull};
use std::rc::Rc;
use super::{NixThunk, NixValue, Value};
use crate::NixError;
use crate::errors::{ErrorContext, NixideError};
use crate::stdext::{AsCPtr, CCharPtrExt};
use crate::sys;
use crate::util::wrappers::AsInnerPtr;
use crate::util::{panic_issue_call_failed, wrap};
use crate::{EvalState, NixError};
pub struct NixAttrs {
inner: NonNull<sys::nix_value>,
state: Rc<RefCell<EvalState>>,
state: Rc<RefCell<NonNull<sys::EvalState>>>,
len: u32,
}
@ -61,7 +61,7 @@ impl NixValue for NixAttrs {
sys::ValueType_NIX_TYPE_ATTRS
}
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<EvalState>>) -> Self {
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
let len = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
sys::nix_get_attrs_size(ctx.as_ptr(), inner.as_ptr())
})
@ -88,7 +88,7 @@ impl NixAttrs {
sys::nix_get_attr_byidx(
ctx.as_ptr(),
self.as_ptr(),
self.state.borrow().as_ptr(),
self.state.borrow_mut().as_ptr(),
index,
name_ptr,
)
@ -115,7 +115,7 @@ impl NixAttrs {
sys::nix_get_attr_byidx_lazy(
ctx.as_ptr(),
self.as_ptr(),
self.state.borrow().as_ptr(),
self.state.borrow_mut().as_ptr(),
index,
name_ptr,
)
@ -140,7 +140,7 @@ impl NixAttrs {
sys::nix_get_attr_name_byidx(
ctx.as_ptr(),
self.as_ptr(),
self.state.borrow().as_ptr(),
self.state.borrow_mut().as_ptr(),
index,
)
})
@ -161,7 +161,7 @@ impl NixAttrs {
sys::nix_get_attr_byname(
ctx.as_ptr(),
self.as_ptr(),
self.state.borrow().as_ptr(),
self.state.borrow_mut().as_ptr(),
name.as_ref()
.into_c_ptr()
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err)),
@ -187,7 +187,7 @@ impl NixAttrs {
sys::nix_get_attr_byname_lazy(
ctx.as_ptr(),
self.as_ptr(),
self.state.borrow().as_ptr(),
self.state.borrow_mut().as_ptr(),
name.as_ref()
.into_c_ptr()
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err)),

View file

@ -5,14 +5,14 @@ use std::rc::Rc;
use super::NixValue;
use crate::errors::ErrorContext;
use crate::sys;
use crate::util::panic_issue_call_failed;
use crate::util::wrap;
use crate::util::wrappers::AsInnerPtr;
use crate::{EvalState, sys};
pub struct NixBool {
inner: NonNull<sys::nix_value>,
state: Rc<RefCell<EvalState>>,
state: Rc<RefCell<NonNull<sys::EvalState>>>,
value: bool,
}
@ -60,7 +60,7 @@ impl NixValue for NixBool {
sys::ValueType_NIX_TYPE_BOOL
}
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<EvalState>>) -> Self {
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
sys::nix_get_bool(ctx.as_ptr(), inner.as_ptr())
})

View file

@ -5,13 +5,13 @@ use std::rc::Rc;
use super::NixValue;
use crate::errors::ErrorContext;
use crate::sys;
use crate::util::wrappers::AsInnerPtr;
use crate::util::{panic_issue_call_failed, wrap};
use crate::{EvalState, sys};
pub struct NixFloat {
inner: NonNull<sys::nix_value>,
state: Rc<RefCell<EvalState>>,
state: Rc<RefCell<NonNull<sys::EvalState>>>,
value: f64,
}
@ -59,7 +59,7 @@ impl NixValue for NixFloat {
sys::ValueType_NIX_TYPE_FLOAT
}
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<EvalState>>) -> Self {
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
sys::nix_get_float(ctx.as_ptr(), inner.as_ptr())
})

View file

@ -3,16 +3,16 @@ use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
use std::ptr::NonNull;
use std::rc::Rc;
use super::{NixThunk, NixValue, Value};
use super::{NixValue, Value};
use crate::errors::ErrorContext;
use crate::stdext::SliceExt;
use crate::sys;
use crate::util::wrappers::AsInnerPtr;
use crate::util::{panic_issue_call_failed, wrap};
use crate::{EvalState, sys};
pub struct NixFunction {
inner: NonNull<sys::nix_value>,
state: Rc<RefCell<EvalState>>,
state: Rc<RefCell<NonNull<sys::EvalState>>>,
value: i64,
}
@ -60,7 +60,7 @@ impl NixValue for NixFunction {
sys::ValueType_NIX_TYPE_FUNCTION
}
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<EvalState>>) -> Self {
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
sys::nix_get_int(ctx.as_ptr(), inner.as_ptr())
})

View file

@ -5,13 +5,13 @@ use std::rc::Rc;
use super::NixValue;
use crate::errors::ErrorContext;
use crate::sys;
use crate::util::wrappers::AsInnerPtr;
use crate::util::{panic_issue_call_failed, wrap};
use crate::{EvalState, sys};
pub struct NixInt {
inner: NonNull<sys::nix_value>,
state: Rc<RefCell<EvalState>>,
state: Rc<RefCell<NonNull<sys::EvalState>>>,
value: i64,
}
@ -59,7 +59,7 @@ impl NixValue for NixInt {
sys::ValueType_NIX_TYPE_INT
}
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<EvalState>>) -> Self {
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
sys::nix_get_int(ctx.as_ptr(), inner.as_ptr())
})

View file

@ -5,14 +5,13 @@ use std::rc::Rc;
use super::{NixThunk, NixValue, Value};
use crate::errors::ErrorContext;
use crate::sys;
use crate::util::wrappers::AsInnerPtr;
use crate::util::{panic_issue_call_failed, wrap};
use crate::{EvalState, sys};
pub struct NixList {
inner: NonNull<sys::nix_value>,
state: Rc<RefCell<EvalState>>,
value: i64,
state: Rc<RefCell<NonNull<sys::EvalState>>>,
}
impl Drop for NixList {
@ -59,17 +58,8 @@ impl NixValue for NixList {
sys::ValueType_NIX_TYPE_LIST
}
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<EvalState>>) -> Self {
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
sys::nix_get_int(ctx.as_ptr(), inner.as_ptr())
})
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
Self {
inner,
state,
value,
}
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
Self { inner, state }
}
}

View file

@ -45,7 +45,7 @@ pub trait NixValue: Drop + Display + Debug + AsInnerPtr<sys::nix_value> {
fn type_id(&self) -> sys::ValueType;
/// TODO
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<EvalState>>) -> Self;
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self;
}
/// A Nix value
@ -111,8 +111,18 @@ pub enum Value {
// Failed(NixFailed),
}
impl From<(NonNull<sys::nix_value>, Rc<RefCell<EvalState>>)> for Value {
fn from(value: (NonNull<sys::nix_value>, Rc<RefCell<EvalState>>)) -> Self {
impl
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;
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
@ -125,6 +135,7 @@ impl From<(NonNull<sys::nix_value>, Rc<RefCell<EvalState>>)> for Value {
})
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err));
#[allow(non_upper_case_globals)]
match type_id {
ValueType_NIX_TYPE_THUNK => Value::Thunk(<NixThunk as NixValue>::from(inner, state)),
ValueType_NIX_TYPE_INT => Value::Int(<NixInt as NixValue>::from(inner, state)),

View file

@ -5,12 +5,12 @@ use std::rc::Rc;
use super::NixValue;
use crate::errors::ErrorContext;
use crate::sys;
use crate::util::wrappers::AsInnerPtr;
use crate::{EvalState, sys};
pub struct NixNull {
inner: NonNull<sys::nix_value>,
state: Rc<RefCell<EvalState>>,
state: Rc<RefCell<NonNull<sys::EvalState>>>,
}
impl Drop for NixNull {
@ -57,7 +57,7 @@ impl NixValue for NixNull {
sys::ValueType_NIX_TYPE_NULL
}
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<EvalState>>) -> Self {
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
Self { inner, state }
}
}

View file

@ -7,14 +7,14 @@ use std::rc::Rc;
use super::NixValue;
use crate::errors::ErrorContext;
use crate::stdext::CCharPtrExt;
use crate::sys;
use crate::util::panic_issue_call_failed;
use crate::util::wrap;
use crate::util::wrappers::AsInnerPtr;
use crate::{EvalState, sys};
pub struct NixPath {
inner: NonNull<sys::nix_value>,
state: Rc<RefCell<EvalState>>,
state: Rc<RefCell<NonNull<sys::EvalState>>>,
value: PathBuf,
}
@ -62,7 +62,7 @@ impl NixValue for NixPath {
sys::ValueType_NIX_TYPE_PATH
}
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<EvalState>>) -> Self {
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
sys::nix_get_path_string(ctx.as_ptr(), inner.as_ptr())
})

View file

@ -6,14 +6,14 @@ use std::rc::Rc;
use super::NixValue;
use crate::errors::ErrorContext;
use crate::sys;
use crate::util::panic_issue_call_failed;
use crate::util::wrap;
use crate::util::wrappers::AsInnerPtr;
use crate::{EvalState, sys};
pub struct NixString {
inner: NonNull<sys::nix_value>,
state: Rc<RefCell<EvalState>>,
state: Rc<RefCell<NonNull<sys::EvalState>>>,
value: String,
}
@ -61,7 +61,7 @@ impl NixValue for NixString {
sys::ValueType_NIX_TYPE_STRING
}
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<EvalState>>) -> Self {
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
let value = wrap::nix_string_callback!(
|callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe {
sys::nix_get_string(

View file

@ -4,7 +4,6 @@ use std::ptr::NonNull;
use std::rc::Rc;
use super::{NixValue, Value};
use crate::EvalState;
use crate::errors::ErrorContext;
use crate::sys;
use crate::util::wrappers::AsInnerPtr;
@ -12,7 +11,7 @@ use crate::util::{panic_issue_call_failed, wrap};
pub struct NixThunk {
inner: NonNull<sys::nix_value>,
state: Rc<RefCell<EvalState>>,
state: Rc<RefCell<NonNull<sys::EvalState>>>,
}
impl Drop for NixThunk {
@ -59,7 +58,7 @@ impl NixValue for NixThunk {
sys::ValueType_NIX_TYPE_THUNK
}
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<EvalState>>) -> Self {
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
Self { inner, state }
}
}