Split monolithic raw crates into sys crates

Creating a crate for bwd-gc highlights the fact that it would be nice to
fix 2!

The file blocklist is a lost less unmaintainable then the more
fine-grained one we had before.

Fix #9
This commit is contained in:
John Ericson 2025-12-06 15:44:20 -05:00
parent 485070ffa9
commit dbb00333b1
51 changed files with 571 additions and 104 deletions

View file

@ -134,14 +134,16 @@ use anyhow::Context as _;
use anyhow::{bail, Result};
use cstr::cstr;
use lazy_static::lazy_static;
use nix_bindings_bdwgc_sys as gc;
use nix_bindings_expr_sys as raw;
use nix_bindings_store::path::StorePath;
use nix_bindings_store::store::{Store, StoreWeak};
use nix_bindings_store_sys as raw_store;
use nix_bindings_util::context::Context;
use nix_bindings_util::string_return::{
callback_get_result_string, callback_get_result_string_data,
};
use nix_bindings_util::{check_call, check_call_opt_key, result_string_init};
use nix_bindings_util_sys as raw;
use std::ffi::{c_char, CString};
use std::iter::FromIterator;
use std::os::raw::c_uint;
@ -151,7 +153,7 @@ use std::sync::{Arc, Weak};
lazy_static! {
static ref INIT: Result<()> = {
unsafe {
raw::GC_allow_register_threads();
gc::GC_allow_register_threads();
check_call!(raw::libexpr_init(&mut Context::new()))?;
Ok(())
}
@ -887,7 +889,7 @@ impl EvalState {
let mut paths = Vec::with_capacity(n as usize);
for i in 0..n {
let path = raw::realised_string_get_store_path(rs, i);
let path = NonNull::new(path as *mut raw::StorePath).ok_or_else(|| {
let path = NonNull::new(path as *mut raw_store::StorePath).ok_or_else(|| {
anyhow::format_err!(
"nix_realised_string_get_store_path returned a null pointer"
)
@ -1153,7 +1155,7 @@ impl Drop for ThreadRegistrationGuard {
fn drop(&mut self) {
if self.must_unregister {
unsafe {
raw::GC_unregister_my_thread();
gc::GC_unregister_my_thread();
}
}
}
@ -1161,14 +1163,14 @@ impl Drop for ThreadRegistrationGuard {
fn gc_register_my_thread_do_it() -> Result<()> {
unsafe {
let mut sb: raw::GC_stack_base = raw::GC_stack_base {
let mut sb: gc::GC_stack_base = gc::GC_stack_base {
mem_base: null_mut(),
};
let r = raw::GC_get_stack_base(&mut sb);
if r as u32 != raw::GC_SUCCESS {
let r = gc::GC_get_stack_base(&mut sb);
if r as u32 != gc::GC_SUCCESS {
Err(anyhow::format_err!("GC_get_stack_base failed: {}", r))?;
}
raw::GC_register_my_thread(&sb);
gc::GC_register_my_thread(&sb);
Ok(())
}
}
@ -1179,7 +1181,7 @@ fn gc_register_my_thread_do_it() -> Result<()> {
pub fn gc_register_my_thread() -> Result<ThreadRegistrationGuard> {
init()?;
unsafe {
let already_done = raw::GC_thread_is_registered();
let already_done = gc::GC_thread_is_registered();
if already_done != 0 {
return Ok(ThreadRegistrationGuard {
must_unregister: false,

View file

@ -1,8 +1,9 @@
use crate::eval_state::{EvalState, EvalStateWeak};
use crate::value::Value;
use anyhow::Result;
use nix_bindings_expr_sys as raw;
use nix_bindings_util::check_call;
use nix_bindings_util_sys as raw;
use nix_bindings_util_sys as raw_util;
use std::ffi::{c_int, c_void, CStr, CString};
use std::mem::ManuallyDrop;
use std::ptr::{null, null_mut};
@ -84,7 +85,7 @@ struct PrimOpContext {
unsafe extern "C" fn function_adapter(
user_data: *mut ::std::os::raw::c_void,
context_out: *mut raw::c_context,
context_out: *mut raw_util::c_context,
_state: *mut raw::EvalState,
args: *mut *mut raw::Value,
ret: *mut raw::Value,
@ -111,7 +112,7 @@ unsafe extern "C" fn function_adapter(
CString::new("<rust nix-expr application error message contained null byte>")
.unwrap()
});
raw::set_err_msg(context_out, raw::err_NIX_ERR_UNKNOWN, cstr.as_ptr());
raw_util::set_err_msg(context_out, raw_util::err_NIX_ERR_UNKNOWN, cstr.as_ptr());
},
}
}

View file

@ -1,7 +1,7 @@
pub mod __private;
use nix_bindings_expr_sys as raw;
use nix_bindings_util::{check_call, context::Context};
use nix_bindings_util_sys as raw;
use std::ptr::{null_mut, NonNull};
// TODO: test: cloning a thunk does not duplicate the evaluation.

View file

@ -1,6 +1,6 @@
//! Functions that are relevant for other bindings modules, but normally not end users.
use super::Value;
use nix_bindings_util_sys as raw;
use nix_bindings_expr_sys as raw;
/// Take ownership of a new [`Value`].
///