Skip to content

Commit b8c7509

Browse files
committed
fixup
1 parent 274519c commit b8c7509

File tree

6 files changed

+38
-23
lines changed

6 files changed

+38
-23
lines changed

crates/vm/src/stdlib/ctypes.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,10 @@ pub(crate) mod _ctypes {
372372
Ok(PyCSimple {
373373
_type_: tp_str,
374374
value: AtomicCell::new(vm.ctx.none()),
375-
cdata: rustpython_common::lock::PyRwLock::new(CDataObject::from_bytes(vec![0u8; size], None)),
375+
cdata: rustpython_common::lock::PyRwLock::new(CDataObject::from_bytes(
376+
vec![0u8; size],
377+
None,
378+
)),
376379
})
377380
}
378381
} else {

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ pub struct CDataObject {
168168
pub objects: Option<PyObjectRef>,
169169
}
170170

171-
172171
impl CDataObject {
173172
/// Create from StgInfo (CPython's PyCData_MallocBuffer pattern)
174173
pub fn from_stg_info(stg_info: &StgInfo) -> Self {
@@ -192,7 +191,13 @@ impl CDataObject {
192191

193192
/// Create from base object (copies data from base's buffer at offset)
194193
#[allow(dead_code)]
195-
pub fn from_base(base: PyObjectRef, _offset: usize, size: usize, index: usize, objects: Option<PyObjectRef>) -> Self {
194+
pub fn from_base(
195+
base: PyObjectRef,
196+
_offset: usize,
197+
size: usize,
198+
index: usize,
199+
objects: Option<PyObjectRef>,
200+
) -> Self {
196201
CDataObject {
197202
buffer: vec![0u8; size],
198203
base: Some(base),
@@ -222,26 +227,26 @@ impl PyCData {
222227
}
223228

224229
#[pyclass(module = "_ctypes", name = "PyCSimpleType", base = PyType)]
225-
#[derive(Debug, PyPayload)]
226-
#[derive(Default)]
230+
#[derive(Debug, PyPayload, Default)]
227231
pub struct PyCSimpleType {
232+
#[allow(dead_code)]
228233
pub stg_info: StgInfo,
229234
}
230235

231-
232236
#[pyclass(flags(BASETYPE), with(AsNumber))]
233237
impl PyCSimpleType {
234238
/// Get stg_info for a simple type by reading _type_ attribute
235239
pub fn get_stg_info(cls: &PyTypeRef, vm: &VirtualMachine) -> StgInfo {
236240
if let Ok(type_attr) = cls.as_object().get_attr("_type_", vm)
237-
&& let Ok(type_str) = type_attr.str(vm) {
238-
let tp_str = type_str.to_string();
239-
if tp_str.len() == 1 {
240-
let size = super::_ctypes::get_size(&tp_str);
241-
let align = super::_ctypes::get_align(&tp_str);
242-
return StgInfo::new(size, align);
243-
}
241+
&& let Ok(type_str) = type_attr.str(vm)
242+
{
243+
let tp_str = type_str.to_string();
244+
if tp_str.len() == 1 {
245+
let size = super::_ctypes::get_size(&tp_str);
246+
let align = super::_ctypes::get_align(&tp_str);
247+
return StgInfo::new(size, align);
244248
}
249+
}
245250
StgInfo::default()
246251
}
247252
#[allow(clippy::new_ret_no_self)]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use super::util::StgInfo;
1414
#[pyclass(name = "PyCPointerType", base = PyType, module = "_ctypes")]
1515
#[derive(PyPayload, Debug)]
1616
pub struct PyCPointerType {
17+
#[allow(dead_code)]
1718
pub stg_info: StgInfo,
1819
}
1920

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::fmt::Debug;
1818
#[pyclass(name = "PyCStructType", base = PyType, module = "_ctypes")]
1919
#[derive(Debug, PyPayload)]
2020
pub struct PyCStructType {
21+
#[allow(dead_code)]
2122
pub stg_info: StgInfo,
2223
}
2324

@@ -163,7 +164,8 @@ impl PyCStructType {
163164
// TODO: Calculate element size properly
164165
// For structures, element size is the structure size (sum of field sizes)
165166
let element_size = std::mem::size_of::<usize>(); // Default, should calculate from fields
166-
let total_size = element_size.checked_mul(n as usize)
167+
let total_size = element_size
168+
.checked_mul(n as usize)
167169
.ok_or_else(|| vm.new_overflow_error("array size too large".to_owned()))?;
168170
let mut stg_info = super::util::StgInfo::new(total_size, element_size);
169171
stg_info.length = n as usize;
@@ -408,7 +410,7 @@ impl PyCStructure {
408410

409411
// Create instance
410412
Ok(PyCStructure {
411-
cdata: PyRwLock::new(CDataObject::from_bytes(data, None)),
413+
cdata: PyRwLock::new(CDataObject::from_bytes(data, Some(source))),
412414
fields: PyRwLock::new(IndexMap::new()),
413415
}
414416
.into_ref_with_type(vm, cls)?

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ fn ffi_to_python(ty: &PyTypeRef, ptr: *const c_void, vm: &VirtualMachine) -> PyO
4444
Some("H") => vm.ctx.new_int(*(ptr as *const u16) as i32).into(),
4545
Some("i") => vm.ctx.new_int(*(ptr as *const i32)).into(),
4646
Some("I") => vm.ctx.new_int(*(ptr as *const u32)).into(),
47-
Some("l") => vm.ctx.new_int(*(ptr as *const i64)).into(),
48-
Some("L") => vm.ctx.new_int(*(ptr as *const u64)).into(),
49-
Some("q") => vm.ctx.new_int(*(ptr as *const i64)).into(),
50-
Some("Q") => vm.ctx.new_int(*(ptr as *const u64)).into(),
47+
Some("l") => vm.ctx.new_int(*(ptr as *const libc::c_long)).into(),
48+
Some("L") => vm.ctx.new_int(*(ptr as *const libc::c_ulong)).into(),
49+
Some("q") => vm.ctx.new_int(*(ptr as *const libc::c_longlong)).into(),
50+
Some("Q") => vm.ctx.new_int(*(ptr as *const libc::c_ulonglong)).into(),
5151
Some("f") => vm.ctx.new_float(*(ptr as *const f32) as f64).into(),
5252
Some("d") => vm.ctx.new_float(*(ptr as *const f64)).into(),
5353
Some("P") | Some("z") | Some("Z") => vm.ctx.new_int(ptr as usize).into(),
@@ -166,6 +166,7 @@ unsafe extern "C" fn thunk_callback(
166166
/// Holds the closure and userdata together to ensure proper lifetime.
167167
/// The userdata is leaked to create a 'static reference that the closure can use.
168168
struct ThunkData {
169+
#[allow(dead_code)]
169170
closure: Closure<'static>,
170171
/// Raw pointer to the leaked userdata, for cleanup
171172
userdata_ptr: *mut ThunkUserData,

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ use crate::PyObjectRef;
33
/// Storage information for ctypes types (mirrors CPython's StgInfo)
44
#[derive(Debug, Clone)]
55
pub struct StgInfo {
6+
#[allow(dead_code)]
67
pub initialized: bool,
7-
pub size: usize, // number of bytes
8-
pub align: usize, // alignment requirements
9-
pub length: usize, // number of fields (for arrays/structures)
8+
pub size: usize, // number of bytes
9+
pub align: usize, // alignment requirements
10+
pub length: usize, // number of fields (for arrays/structures)
11+
#[allow(dead_code)]
1012
pub proto: Option<PyObjectRef>, // Only for Pointer/ArrayObject
11-
pub flags: i32, // calling convention and such
13+
#[allow(dead_code)]
14+
pub flags: i32, // calling convention and such
1215
}
1316

1417
impl Default for StgInfo {

0 commit comments

Comments
 (0)