Skip to content

Commit c35cb89

Browse files
authored
Merge pull request RustPython#6473 from youknowone/libffi
Upgrade libffi 5
2 parents 2785bd8 + 7c7e55f commit c35cb89

File tree

7 files changed

+21
-30
lines changed

7 files changed

+21
-30
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ itertools = "0.14.0"
178178
is-macro = "0.3.7"
179179
junction = "1.3.0"
180180
libc = "0.2.178"
181-
libffi = "4.1"
181+
libffi = "5"
182182
log = "0.4.29"
183183
nix = { version = "0.30", features = ["fs", "user", "process", "term", "time", "signal", "ioctl", "socket", "sched", "zerocopy", "dir", "hostname", "net", "poll"] }
184184
malachite-bigint = "0.8"

crates/jit/src/lib.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl CompiledCode {
157157
Ok(unsafe { self.invoke_raw(&cif_args) })
158158
}
159159

160-
unsafe fn invoke_raw(&self, cif_args: &[libffi::middle::Arg]) -> Option<AbiValue> {
160+
unsafe fn invoke_raw(&self, cif_args: &[libffi::middle::Arg<'_>]) -> Option<AbiValue> {
161161
unsafe {
162162
let cif = self.sig.to_cif();
163163
let value = cif.call::<UnTypedAbiValue>(
@@ -219,7 +219,7 @@ pub enum AbiValue {
219219
}
220220

221221
impl AbiValue {
222-
fn to_libffi_arg(&self) -> libffi::middle::Arg {
222+
fn to_libffi_arg(&self) -> libffi::middle::Arg<'_> {
223223
match self {
224224
AbiValue::Int(i) => libffi::middle::Arg::new(i),
225225
AbiValue::Float(f) => libffi::middle::Arg::new(f),
@@ -350,26 +350,25 @@ impl<'a> ArgsBuilder<'a> {
350350
}
351351

352352
pub fn into_args(self) -> Option<Args<'a>> {
353-
self.values
354-
.iter()
355-
.map(|v| v.as_ref().map(AbiValue::to_libffi_arg))
356-
.collect::<Option<_>>()
357-
.map(|cif_args| Args {
358-
_values: self.values,
359-
cif_args,
360-
code: self.code,
361-
})
353+
// Ensure all values are set
354+
if self.values.iter().any(|v| v.is_none()) {
355+
return None;
356+
}
357+
Some(Args {
358+
values: self.values.into_iter().map(|v| v.unwrap()).collect(),
359+
code: self.code,
360+
})
362361
}
363362
}
364363

365364
pub struct Args<'a> {
366-
_values: Vec<Option<AbiValue>>,
367-
cif_args: Vec<libffi::middle::Arg>,
365+
values: Vec<AbiValue>,
368366
code: &'a CompiledCode,
369367
}
370368

371369
impl Args<'_> {
372370
pub fn invoke(&self) -> Option<AbiValue> {
373-
unsafe { self.code.invoke_raw(&self.cif_args) }
371+
let cif_args: Vec<_> = self.values.iter().map(AbiValue::to_libffi_arg).collect();
372+
unsafe { self.code.invoke_raw(&cif_args) }
374373
}
375374
}

crates/vm/src/stdlib/ctypes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ pub(crate) mod _ctypes {
11021102
return Err(vm.new_value_error("NULL function pointer"));
11031103
}
11041104

1105-
let mut ffi_args: Vec<Arg> = Vec::with_capacity(args.len());
1105+
let mut ffi_args: Vec<Arg<'_>> = Vec::with_capacity(args.len());
11061106
let mut arg_values: Vec<isize> = Vec::with_capacity(args.len());
11071107
let mut arg_types: Vec<Type> = Vec::with_capacity(args.len());
11081108

crates/vm/src/stdlib/ctypes/array.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,14 +1058,6 @@ impl PyCArray {
10581058
}
10591059
}
10601060

1061-
impl PyCArray {
1062-
#[allow(unused)]
1063-
pub fn to_arg(&self, _vm: &VirtualMachine) -> PyResult<libffi::middle::Arg> {
1064-
let buffer = self.0.buffer.read();
1065-
Ok(libffi::middle::Arg::new(&*buffer))
1066-
}
1067-
}
1068-
10691061
impl AsBuffer for PyCArray {
10701062
fn as_buffer(zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<PyBuffer> {
10711063
let buffer_len = zelf.0.buffer.read().len();

crates/vm/src/stdlib/ctypes/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ pub enum FfiArgValue {
18211821

18221822
impl FfiArgValue {
18231823
/// Create an Arg reference to this owned value
1824-
pub fn as_arg(&self) -> libffi::middle::Arg {
1824+
pub fn as_arg(&self) -> libffi::middle::Arg<'_> {
18251825
match self {
18261826
FfiArgValue::U8(v) => libffi::middle::Arg::new(v),
18271827
FfiArgValue::I8(v) => libffi::middle::Arg::new(v),

crates/vm/src/stdlib/ctypes/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ enum RawResult {
14491449
fn ctypes_callproc(code_ptr: CodePtr, arguments: &[Argument], call_info: &CallInfo) -> RawResult {
14501450
let ffi_arg_types: Vec<Type> = arguments.iter().map(|a| a.ffi_type.clone()).collect();
14511451
let cif = Cif::new(ffi_arg_types, call_info.ffi_return_type.clone());
1452-
let ffi_args: Vec<Arg> = arguments.iter().map(|a| a.value.as_arg()).collect();
1452+
let ffi_args: Vec<Arg<'_>> = arguments.iter().map(|a| a.value.as_arg()).collect();
14531453

14541454
if call_info.restype_is_none {
14551455
unsafe { cif.call::<()>(code_ptr, &ffi_args) };

0 commit comments

Comments
 (0)