🌐 AI搜索 & 代理 主页
Skip to content

Commit 39e6885

Browse files
committed
apply review
1 parent df369d0 commit 39e6885

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

crates/vm/src/stdlib/ctypes.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,10 @@ pub(crate) mod _ctypes {
350350
if !obj.fast_isinstance(PyCData::static_type())
351351
&& !obj.fast_isinstance(PyCSimple::static_type())
352352
{
353-
return Err(vm.new_type_error(
354-
"byref() argument must be a ctypes instance, not 'int'".to_string(),
355-
));
353+
return Err(vm.new_type_error(format!(
354+
"byref() argument must be a ctypes instance, not '{}'",
355+
obj.class().name()
356+
)));
356357
}
357358

358359
let offset_val = offset.unwrap_or(0);
@@ -428,14 +429,12 @@ pub(crate) mod _ctypes {
428429
}
429430
#[cfg(target_os = "windows")]
430431
{
431-
// On Windows, use wcslen from ucrt
432-
0
432+
todo!("On Windows, use wcslen from ucrt")
433433
}
434434
}
435435

436436
#[pyattr]
437437
fn _cast_addr(_vm: &VirtualMachine) -> usize {
438-
// TODO: RUSTPYTHON
439-
0
438+
todo!("Implement _cast_addr")
440439
}
441440
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,10 @@ impl PyCArray {
404404
impl PyCArray {
405405
#[allow(unused)]
406406
pub fn to_arg(&self, _vm: &VirtualMachine) -> PyResult<libffi::middle::Arg> {
407+
// TODO: This needs a different approach to ensure buffer lifetime
408+
// The buffer must outlive the Arg returned here
407409
let buffer = self.buffer.read();
408-
Ok(libffi::middle::Arg::new(&buffer.clone()))
410+
let ptr = buffer.as_ptr();
411+
Ok(libffi::middle::Arg::new(&ptr))
409412
}
410413
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use crate::stdlib::ctypes::_ctypes::get_size;
88
use crate::types::{AsNumber, Constructor};
99
use crate::{AsObject, PyObjectRef, PyPayload, PyResult, VirtualMachine};
1010
use crossbeam_utils::atomic::AtomicCell;
11+
use indexmap::IndexMap;
1112
use num_traits::ToPrimitive;
1213
use rustpython_common::lock::PyRwLock;
13-
use std::collections::HashMap;
1414
use std::fmt::Debug;
1515

1616
/// PyCStructType - metaclass for Structure
@@ -139,6 +139,7 @@ impl PyCStructType {
139139
if n < 0 {
140140
return Err(vm.new_value_error(format!("Array length must be >= 0, not {n}")));
141141
}
142+
// TODO: Calculate element size properly
142143
// For structures, element size is the structure size (sum of field sizes)
143144
let element_size = std::mem::size_of::<usize>(); // Default, should calculate from fields
144145
Ok(PyCArrayType {
@@ -196,7 +197,7 @@ pub struct PyCStructure {
196197
pub(super) buffer: PyRwLock<Vec<u8>>,
197198
/// Field information (name -> FieldInfo)
198199
#[allow(dead_code)]
199-
pub(super) fields: PyRwLock<HashMap<String, FieldInfo>>,
200+
pub(super) fields: PyRwLock<IndexMap<String, FieldInfo>>,
200201
/// Total size of the structure
201202
pub(super) size: AtomicCell<usize>,
202203
}
@@ -216,7 +217,7 @@ impl Constructor for PyCStructure {
216217
// Get _fields_ from the class using get_attr to properly search MRO
217218
let fields_attr = cls.as_object().get_attr("_fields_", vm).ok();
218219

219-
let mut fields_map = HashMap::new();
220+
let mut fields_map = IndexMap::new();
220221
let mut total_size = 0usize;
221222

222223
if let Some(fields_attr) = fields_attr {

0 commit comments

Comments
 (0)