Skip to content

Commit a0d067e

Browse files
Auto-format: cargo fmt --all
1 parent 274519c commit a0d067e

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
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: 16 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,25 @@ 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 {
228232
pub stg_info: StgInfo,
229233
}
230234

231-
232235
#[pyclass(flags(BASETYPE), with(AsNumber))]
233236
impl PyCSimpleType {
234237
/// Get stg_info for a simple type by reading _type_ attribute
235238
pub fn get_stg_info(cls: &PyTypeRef, vm: &VirtualMachine) -> StgInfo {
236239
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-
}
240+
&& let Ok(type_str) = type_attr.str(vm)
241+
{
242+
let tp_str = type_str.to_string();
243+
if tp_str.len() == 1 {
244+
let size = super::_ctypes::get_size(&tp_str);
245+
let align = super::_ctypes::get_align(&tp_str);
246+
return StgInfo::new(size, align);
244247
}
248+
}
245249
StgInfo::default()
246250
}
247251
#[allow(clippy::new_ret_no_self)]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ impl PyCStructType {
163163
// TODO: Calculate element size properly
164164
// For structures, element size is the structure size (sum of field sizes)
165165
let element_size = std::mem::size_of::<usize>(); // Default, should calculate from fields
166-
let total_size = element_size.checked_mul(n as usize)
166+
let total_size = element_size
167+
.checked_mul(n as usize)
167168
.ok_or_else(|| vm.new_overflow_error("array size too large".to_owned()))?;
168169
let mut stg_info = super::util::StgInfo::new(total_size, element_size);
169170
stg_info.length = n as usize;

0 commit comments

Comments
 (0)