Merge pull request #6473 from youknowone/libffi

Upgrade libffi 5
This commit is contained in:
Jeong, YunWon
2025-12-24 10:35:52 +09:00
committed by GitHub
7 changed files with 21 additions and 30 deletions

8
Cargo.lock generated
View File

@@ -1687,9 +1687,9 @@ checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
[[package]]
name = "libffi"
version = "4.1.2"
version = "5.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0feebbe0ccd382a2790f78d380540500d7b78ed7a3498b68fcfbc1593749a94"
checksum = "0444124f3ffd67e1b0b0c661a7f81a278a135eb54aaad4078e79fbc8be50c8a5"
dependencies = [
"libc",
"libffi-sys",
@@ -1697,9 +1697,9 @@ dependencies = [
[[package]]
name = "libffi-sys"
version = "3.3.3"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90c6c6e17136d4bc439d43a2f3c6ccf0731cccc016d897473a29791d3c2160c3"
checksum = "3d722da8817ea580d0669da6babe2262d7b86a1af1103da24102b8bb9c101ce7"
dependencies = [
"cc",
]

View File

@@ -178,7 +178,7 @@ itertools = "0.14.0"
is-macro = "0.3.7"
junction = "1.3.0"
libc = "0.2.178"
libffi = "4.1"
libffi = "5"
log = "0.4.29"
nix = { version = "0.30", features = ["fs", "user", "process", "term", "time", "signal", "ioctl", "socket", "sched", "zerocopy", "dir", "hostname", "net", "poll"] }
malachite-bigint = "0.8"

View File

@@ -157,7 +157,7 @@ impl CompiledCode {
Ok(unsafe { self.invoke_raw(&cif_args) })
}
unsafe fn invoke_raw(&self, cif_args: &[libffi::middle::Arg]) -> Option<AbiValue> {
unsafe fn invoke_raw(&self, cif_args: &[libffi::middle::Arg<'_>]) -> Option<AbiValue> {
unsafe {
let cif = self.sig.to_cif();
let value = cif.call::<UnTypedAbiValue>(
@@ -219,7 +219,7 @@ pub enum AbiValue {
}
impl AbiValue {
fn to_libffi_arg(&self) -> libffi::middle::Arg {
fn to_libffi_arg(&self) -> libffi::middle::Arg<'_> {
match self {
AbiValue::Int(i) => libffi::middle::Arg::new(i),
AbiValue::Float(f) => libffi::middle::Arg::new(f),
@@ -350,26 +350,25 @@ impl<'a> ArgsBuilder<'a> {
}
pub fn into_args(self) -> Option<Args<'a>> {
self.values
.iter()
.map(|v| v.as_ref().map(AbiValue::to_libffi_arg))
.collect::<Option<_>>()
.map(|cif_args| Args {
_values: self.values,
cif_args,
code: self.code,
})
// Ensure all values are set
if self.values.iter().any(|v| v.is_none()) {
return None;
}
Some(Args {
values: self.values.into_iter().map(|v| v.unwrap()).collect(),
code: self.code,
})
}
}
pub struct Args<'a> {
_values: Vec<Option<AbiValue>>,
cif_args: Vec<libffi::middle::Arg>,
values: Vec<AbiValue>,
code: &'a CompiledCode,
}
impl Args<'_> {
pub fn invoke(&self) -> Option<AbiValue> {
unsafe { self.code.invoke_raw(&self.cif_args) }
let cif_args: Vec<_> = self.values.iter().map(AbiValue::to_libffi_arg).collect();
unsafe { self.code.invoke_raw(&cif_args) }
}
}

View File

@@ -1102,7 +1102,7 @@ pub(crate) mod _ctypes {
return Err(vm.new_value_error("NULL function pointer"));
}
let mut ffi_args: Vec<Arg> = Vec::with_capacity(args.len());
let mut ffi_args: Vec<Arg<'_>> = Vec::with_capacity(args.len());
let mut arg_values: Vec<isize> = Vec::with_capacity(args.len());
let mut arg_types: Vec<Type> = Vec::with_capacity(args.len());

View File

@@ -1058,14 +1058,6 @@ impl PyCArray {
}
}
impl PyCArray {
#[allow(unused)]
pub fn to_arg(&self, _vm: &VirtualMachine) -> PyResult<libffi::middle::Arg> {
let buffer = self.0.buffer.read();
Ok(libffi::middle::Arg::new(&*buffer))
}
}
impl AsBuffer for PyCArray {
fn as_buffer(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
let buffer_len = zelf.0.buffer.read().len();

View File

@@ -1821,7 +1821,7 @@ pub enum FfiArgValue {
impl FfiArgValue {
/// Create an Arg reference to this owned value
pub fn as_arg(&self) -> libffi::middle::Arg {
pub fn as_arg(&self) -> libffi::middle::Arg<'_> {
match self {
FfiArgValue::U8(v) => libffi::middle::Arg::new(v),
FfiArgValue::I8(v) => libffi::middle::Arg::new(v),

View File

@@ -1449,7 +1449,7 @@ enum RawResult {
fn ctypes_callproc(code_ptr: CodePtr, arguments: &[Argument], call_info: &CallInfo) -> RawResult {
let ffi_arg_types: Vec<Type> = arguments.iter().map(|a| a.ffi_type.clone()).collect();
let cif = Cif::new(ffi_arg_types, call_info.ffi_return_type.clone());
let ffi_args: Vec<Arg> = arguments.iter().map(|a| a.value.as_arg()).collect();
let ffi_args: Vec<Arg<'_>> = arguments.iter().map(|a| a.value.as_arg()).collect();
if call_info.restype_is_none {
unsafe { cif.call::<()>(code_ptr, &ffi_args) };