mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-08 19:31:14 -03:00
Remove some environment and null_terminated_array ffi bits
These are now unused and can be removed.
This commit is contained in:
@@ -88,7 +88,6 @@ fn main() {
|
||||
"fish-rust/src/io.rs",
|
||||
"fish-rust/src/job_group.rs",
|
||||
"fish-rust/src/kill.rs",
|
||||
"fish-rust/src/null_terminated_array.rs",
|
||||
"fish-rust/src/operation_context.rs",
|
||||
"fish-rust/src/output.rs",
|
||||
"fish-rust/src/parse_constants.rs",
|
||||
|
||||
13
fish-rust/src/env/env_ffi.rs
vendored
13
fish-rust/src/env/env_ffi.rs
vendored
@@ -2,11 +2,9 @@
|
||||
use super::var::{ElectricVar, EnvVar, EnvVarFlags, Statuses};
|
||||
use crate::env::EnvMode;
|
||||
use crate::ffi::{wchar_t, wcharz_t, wcstring_list_ffi_t};
|
||||
use crate::null_terminated_array::OwningNullTerminatedArrayRefFFI;
|
||||
use crate::signal::Signal;
|
||||
use crate::wchar_ffi::WCharToFFI;
|
||||
use crate::wchar_ffi::{AsWstr, WCharFromFFI};
|
||||
use core::ffi::c_char;
|
||||
use cxx::{CxxVector, CxxWString, UniquePtr};
|
||||
use lazy_static::lazy_static;
|
||||
use std::ffi::c_int;
|
||||
@@ -149,10 +147,6 @@ fn set(
|
||||
fn push(&self, new_scope: bool);
|
||||
fn pop(&self);
|
||||
|
||||
// Returns a Box<OwningNullTerminatedArrayRefFFI>.into_raw() cast to a void*.
|
||||
// This is because we can't use the same C++ bindings to a Rust type from two different bridges.
|
||||
fn export_array(&self) -> *mut c_char;
|
||||
|
||||
fn snapshot(&self) -> Box<EnvDynFFI>;
|
||||
|
||||
// Access a variable stack that only represents globals.
|
||||
@@ -341,13 +335,6 @@ fn remove(&self, name: &CxxWString, flags: u16) -> EnvStackSetResult {
|
||||
self.0.remove(name.as_wstr(), mode)
|
||||
}
|
||||
|
||||
fn export_array(&self) -> *mut c_char {
|
||||
Box::into_raw(Box::new(OwningNullTerminatedArrayRefFFI(
|
||||
self.0.export_array(),
|
||||
)))
|
||||
.cast()
|
||||
}
|
||||
|
||||
fn snapshot(&self) -> Box<EnvDynFFI> {
|
||||
Box::new(EnvDynFFI(self.0.snapshot()))
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
use std::marker::PhantomData;
|
||||
use std::pin::Pin;
|
||||
use std::ptr;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub trait NulTerminatedString {
|
||||
type CharType: Copy;
|
||||
@@ -140,23 +139,8 @@ pub fn null_terminated_array_length<T>(mut arr: *const *const T) -> usize {
|
||||
len
|
||||
}
|
||||
|
||||
/// FFI bits.
|
||||
/// We often work in Arc<OwningNullTerminatedArray>.
|
||||
/// Expose this to C++.
|
||||
pub struct OwningNullTerminatedArrayRefFFI(pub Arc<OwningNullTerminatedArray>);
|
||||
impl OwningNullTerminatedArrayRefFFI {
|
||||
fn get(&self) -> *mut *const c_char {
|
||||
self.0.get()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl cxx::ExternType for OwningNullTerminatedArrayRefFFI {
|
||||
type Id = cxx::type_id!("OwningNullTerminatedArrayRefFFI");
|
||||
type Kind = cxx::kind::Opaque;
|
||||
}
|
||||
|
||||
/// Convert a CxxString to a CString, truncating at the first NUL.
|
||||
use cxx::{CxxString, CxxVector};
|
||||
use cxx::CxxString;
|
||||
fn cxxstring_to_cstring(s: &CxxString) -> CString {
|
||||
let bytes: &[u8] = s.as_bytes();
|
||||
let nul_pos = bytes.iter().position(|&b| b == 0);
|
||||
@@ -164,29 +148,6 @@ fn cxxstring_to_cstring(s: &CxxString) -> CString {
|
||||
CString::new(slice).unwrap()
|
||||
}
|
||||
|
||||
fn new_owning_null_terminated_array_ffi(
|
||||
strs: &CxxVector<CxxString>,
|
||||
) -> Box<OwningNullTerminatedArrayRefFFI> {
|
||||
let cstrs = strs.iter().map(cxxstring_to_cstring).collect();
|
||||
Box::new(OwningNullTerminatedArrayRefFFI(Arc::new(
|
||||
OwningNullTerminatedArray::new(cstrs),
|
||||
)))
|
||||
}
|
||||
|
||||
#[cxx::bridge]
|
||||
mod null_terminated_array_ffi {
|
||||
extern "Rust" {
|
||||
type OwningNullTerminatedArrayRefFFI;
|
||||
|
||||
fn get(&self) -> *mut *const c_char;
|
||||
|
||||
#[cxx_name = "new_owning_null_terminated_array"]
|
||||
fn new_owning_null_terminated_array_ffi(
|
||||
strs: &CxxVector<CxxString>,
|
||||
) -> Box<OwningNullTerminatedArrayRefFFI>;
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_null_terminated_array_length() {
|
||||
let arr = [&1, &2, &3, std::ptr::null()];
|
||||
|
||||
Reference in New Issue
Block a user