@@ -8,9 +8,9 @@ use crate::stdlib::ctypes::_ctypes::get_size;
88use crate :: types:: { AsNumber , Constructor } ;
99use crate :: { AsObject , PyObjectRef , PyPayload , PyResult , VirtualMachine } ;
1010use crossbeam_utils:: atomic:: AtomicCell ;
11+ use indexmap:: IndexMap ;
1112use num_traits:: ToPrimitive ;
1213use rustpython_common:: lock:: PyRwLock ;
13- use std:: collections:: HashMap ;
1414use 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