@@ -37,7 +37,7 @@ impl fmt::Display for ArrayTypeSpecifierError {
3737}
3838
3939macro_rules! def_array_enum {
40- ( $( ( $n: ident, $t: ty, $c: literal) ) ,* $( , ) ?) => {
40+ ( $( ( $n: ident, $t: ty, $c: literal, $scode : literal ) ) ,* $( , ) ?) => {
4141 #[ derive( Debug , Clone ) ]
4242 pub ( crate ) enum ArrayContentType {
4343 $( $n( Vec <$t>) , ) *
@@ -58,6 +58,12 @@ macro_rules! def_array_enum {
5858 }
5959 }
6060
61+ fn typecode_str( & self ) -> & ' static str {
62+ match self {
63+ $( ArrayContentType :: $n( _) => $scode, ) *
64+ }
65+ }
66+
6167 fn itemsize( & self ) -> usize {
6268 match self {
6369 $( ArrayContentType :: $n( _) => std:: mem:: size_of:: <$t>( ) , ) *
@@ -394,19 +400,19 @@ macro_rules! def_array_enum {
394400}
395401
396402def_array_enum ! (
397- ( SignedByte , i8 , 'b' ) ,
398- ( UnsignedByte , u8 , 'B' ) ,
403+ ( SignedByte , i8 , 'b' , "b" ) ,
404+ ( UnsignedByte , u8 , 'B' , "B" ) ,
399405 // TODO: support unicode char
400- ( SignedShort , raw:: c_short, 'h' ) ,
401- ( UnsignedShort , raw:: c_ushort, 'H' ) ,
402- ( SignedInt , raw:: c_int, 'i' ) ,
403- ( UnsignedInt , raw:: c_uint, 'I' ) ,
404- ( SignedLong , raw:: c_long, 'l' ) ,
405- ( UnsignedLong , raw:: c_ulong, 'L' ) ,
406- ( SignedLongLong , raw:: c_longlong, 'q' ) ,
407- ( UnsignedLongLong , raw:: c_ulonglong, 'Q' ) ,
408- ( Float , f32 , 'f' ) ,
409- ( Double , f64 , 'd' ) ,
406+ ( SignedShort , raw:: c_short, 'h' , "h" ) ,
407+ ( UnsignedShort , raw:: c_ushort, 'H' , "H" ) ,
408+ ( SignedInt , raw:: c_int, 'i' , "i" ) ,
409+ ( UnsignedInt , raw:: c_uint, 'I' , "I" ) ,
410+ ( SignedLong , raw:: c_long, 'l' , "l" ) ,
411+ ( UnsignedLong , raw:: c_ulong, 'L' , "L" ) ,
412+ ( SignedLongLong , raw:: c_longlong, 'q' , "q" ) ,
413+ ( UnsignedLongLong , raw:: c_ulonglong, 'Q' , "Q" ) ,
414+ ( Float , f32 , 'f' , "f" ) ,
415+ ( Double , f64 , 'd' , "d" ) ,
410416) ;
411417
412418trait ArrayElement : Sized {
@@ -875,7 +881,7 @@ impl Buffer for PyArrayRef {
875881 readonly : false ,
876882 len : array. len ( ) ,
877883 itemsize : array. itemsize ( ) ,
878- format : array. typecode ( ) . to_string ( ) ,
884+ format : array. typecode_str ( ) . into ( ) ,
879885 ..Default :: default ( )
880886 } ) ) ;
881887 PyRwLockWriteGuard :: downgrade ( w)
0 commit comments