Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
temp remove
  • Loading branch information
youknowone committed Nov 29, 2025
commit efebed6810722d15dec0edef5189607a80436acd
1 change: 1 addition & 0 deletions crates/vm/src/stdlib/ctypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub(crate) mod _ctypes {
#[derive(Debug, PyPayload)]
pub struct CArgObject {
pub obj: PyObjectRef,
#[allow(dead_code)]
pub offset: isize,
}

Expand Down
54 changes: 2 additions & 52 deletions crates/vm/src/stdlib/ctypes/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ impl AsNumber for PyCStructType {
}

/// Structure field info stored in instance
#[allow(dead_code)]
#[derive(Debug, Clone)]
pub struct FieldInfo {
pub name: String,
Expand All @@ -194,6 +195,7 @@ pub struct PyCStructure {
/// Raw memory buffer for the structure
pub(super) buffer: PyRwLock<Vec<u8>>,
/// Field information (name -> FieldInfo)
#[allow(dead_code)]
pub(super) fields: PyRwLock<HashMap<String, FieldInfo>>,
/// Total size of the structure
pub(super) size: AtomicCell<usize>,
Expand Down Expand Up @@ -300,58 +302,6 @@ impl Constructor for PyCStructure {
// Note: GetAttr and SetAttr are not implemented here.
// Field access is handled by CField descriptors registered on the class.

impl PyCStructure {
/// Convert bytes to a Python value
fn bytes_to_value(bytes: &[u8], _type_ref: &PyTypeRef, vm: &VirtualMachine) -> PyResult {
match bytes.len() {
1 => Ok(vm.ctx.new_int(bytes[0] as i8).into()),
2 => {
let val = i16::from_ne_bytes([bytes[0], bytes[1]]);
Ok(vm.ctx.new_int(val).into())
}
4 => {
let val = i32::from_ne_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]);
Ok(vm.ctx.new_int(val).into())
}
8 => {
let val = i64::from_ne_bytes([
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
]);
Ok(vm.ctx.new_int(val).into())
}
_ => Ok(vm.ctx.new_int(0).into()),
}
}

/// Convert a Python value to bytes
fn value_to_bytes(value: &PyObjectRef, size: usize, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
if let Ok(int_val) = value.try_int(vm) {
let i = int_val.as_bigint();
match size {
1 => {
let val = i.to_i8().unwrap_or(0);
Ok(val.to_ne_bytes().to_vec())
}
2 => {
let val = i.to_i16().unwrap_or(0);
Ok(val.to_ne_bytes().to_vec())
}
4 => {
let val = i.to_i32().unwrap_or(0);
Ok(val.to_ne_bytes().to_vec())
}
8 => {
let val = i.to_i64().unwrap_or(0);
Ok(val.to_ne_bytes().to_vec())
}
_ => Ok(vec![0u8; size]),
}
} else {
Ok(vec![0u8; size])
}
}
}

#[pyclass(flags(BASETYPE, IMMUTABLETYPE), with(Constructor))]
impl PyCStructure {
#[pygetset]
Expand Down