@@ -75,7 +75,7 @@ impl Constructor for PyCArrayType {
7575#[ pyclass( flags( IMMUTABLETYPE ) , with( Callable , Constructor , AsNumber ) ) ]
7676impl PyCArrayType {
7777 #[ pygetset( name = "_type_" ) ]
78- fn typ ( & self ) -> PyTypeRef {
78+ fn typ ( & self ) -> PyObjectRef {
7979 self . inner . typ . read ( ) . clone ( )
8080 }
8181
@@ -96,10 +96,7 @@ impl PyCArrayType {
9696 let inner_element_size = zelf. inner . element_size . load ( ) ;
9797
9898 // The element type of the new array is the current array type itself
99- let obj_ref: PyObjectRef = zelf. to_owned ( ) . into ( ) ;
100- let current_array_type = obj_ref
101- . downcast :: < PyType > ( )
102- . expect ( "PyCArrayType should be a PyType" ) ;
99+ let current_array_type: PyObjectRef = zelf. as_object ( ) . to_owned ( ) ;
103100
104101 // Element size is the total size of the inner array
105102 let new_element_size = inner_length * inner_element_size;
@@ -144,7 +141,8 @@ impl AsNumber for PyCArrayType {
144141) ]
145142#[ derive( PyPayload ) ]
146143pub struct PyCArray {
147- pub ( super ) typ : PyRwLock < PyTypeRef > ,
144+ /// Element type - can be a simple type (c_int) or an array type (c_int * 5)
145+ pub ( super ) typ : PyRwLock < PyObjectRef > ,
148146 pub ( super ) length : AtomicCell < usize > ,
149147 pub ( super ) element_size : AtomicCell < usize > ,
150148 pub ( super ) buffer : PyRwLock < Vec < u8 > > ,
@@ -207,12 +205,8 @@ impl Constructor for PyCArray {
207205 }
208206 }
209207
210- let element_type_ref = element_type
211- . downcast :: < PyType > ( )
212- . unwrap_or_else ( |_| vm. ctx . types . object_type . to_owned ( ) ) ;
213-
214208 PyCArray {
215- typ : PyRwLock :: new ( element_type_ref ) ,
209+ typ : PyRwLock :: new ( element_type ) ,
216210 length : AtomicCell :: new ( length) ,
217211 element_size : AtomicCell :: new ( element_size) ,
218212 buffer : PyRwLock :: new ( buffer) ,
@@ -354,7 +348,7 @@ impl PyCArray {
354348 }
355349
356350 #[ pygetset( name = "_type_" ) ]
357- fn typ ( & self ) -> PyTypeRef {
351+ fn typ ( & self ) -> PyObjectRef {
358352 self . typ . read ( ) . clone ( )
359353 }
360354
0 commit comments