@@ -146,8 +146,7 @@ fn _nothing() -> PyObjectRef {
146
146
PyObject {
147
147
kind : PyObjectKind :: None ,
148
148
typ : None ,
149
- }
150
- . into_ref ( )
149
+ } . into_ref ( )
151
150
}
152
151
153
152
pub fn create_type (
@@ -220,7 +219,7 @@ impl PyContext {
220
219
) ;
221
220
let context = PyContext {
222
221
bool_type : bool_type,
223
- memoryview_type : memoryview_type,
222
+ memoryview_type : memoryview_type,
224
223
bytearray_type : bytearray_type,
225
224
bytes_type : bytes_type,
226
225
code_type : code_type,
@@ -412,7 +411,10 @@ impl PyContext {
412
411
}
413
412
414
413
pub fn new_bytearray ( & self , data : Vec < u8 > ) -> PyObjectRef {
415
- PyObject :: new ( PyObjectKind :: Bytes { value : data } , self . bytearray_type ( ) )
414
+ PyObject :: new (
415
+ PyObjectKind :: ByteArray { value : data } ,
416
+ self . bytearray_type ( ) ,
417
+ )
416
418
}
417
419
418
420
pub fn new_bool ( & self , b : bool ) -> PyObjectRef {
@@ -464,8 +466,7 @@ impl PyContext {
464
466
PyObject {
465
467
kind : PyObjectKind :: Scope { scope : scope } ,
466
468
typ : None ,
467
- }
468
- . into_ref ( )
469
+ } . into_ref ( )
469
470
}
470
471
471
472
pub fn new_module ( & self , name : & str , scope : PyObjectRef ) -> PyObjectRef {
@@ -745,6 +746,21 @@ impl DictProtocol for PyObjectRef {
745
746
}
746
747
}
747
748
749
+ pub trait BufferProtocol {
750
+ fn readonly ( & self ) -> bool ;
751
+ }
752
+
753
+ impl BufferProtocol for PyObjectRef {
754
+ fn readonly ( & self ) -> bool {
755
+ match self . borrow ( ) . kind {
756
+ PyObjectKind :: Bytes { value : _ } => false ,
757
+ PyObjectKind :: ByteArray { value : _ } => true ,
758
+ PyObjectKind :: MemoryView { obj : _ } => true ,
759
+ _ => panic ! ( "Bytes-Like type expected not {:?}" , self ) ,
760
+ }
761
+ }
762
+ }
763
+
748
764
impl fmt:: Debug for PyObject {
749
765
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
750
766
write ! ( f, "[PyObj {:?}]" , self . kind)
@@ -826,6 +842,9 @@ pub enum PyObjectKind {
826
842
Bytes {
827
843
value : Vec < u8 > ,
828
844
} ,
845
+ ByteArray {
846
+ value : Vec < u8 > ,
847
+ } ,
829
848
Sequence {
830
849
elements : Vec < PyObjectRef > ,
831
850
} ,
@@ -845,7 +864,7 @@ pub enum PyObjectKind {
845
864
step : Option < i32 > ,
846
865
} ,
847
866
MemoryView {
848
- obj : PyObjectRef
867
+ obj : PyObjectRef ,
849
868
} ,
850
869
Code {
851
870
code : bytecode:: CodeObject ,
@@ -897,6 +916,7 @@ impl fmt::Debug for PyObjectKind {
897
916
& PyObjectKind :: Float { ref value } => write ! ( f, "float {}" , value) ,
898
917
& PyObjectKind :: Complex { ref value } => write ! ( f, "complex {}" , value) ,
899
918
& PyObjectKind :: Bytes { ref value } => write ! ( f, "bytes/bytearray {:?}" , value) ,
919
+ & PyObjectKind :: ByteArray { ref value } => write ! ( f, "bytes/bytearray {:?}" , value) ,
900
920
& PyObjectKind :: MemoryView { ref obj } => write ! ( f, "bytes/bytearray {:?}" , obj) ,
901
921
& PyObjectKind :: Sequence { elements : _ } => write ! ( f, "list or tuple" ) ,
902
922
& PyObjectKind :: Dict { elements : _ } => write ! ( f, "dict" ) ,
@@ -939,8 +959,7 @@ impl PyObject {
939
959
kind : kind,
940
960
typ : Some ( typ) ,
941
961
// dict: HashMap::new(), // dict,
942
- }
943
- . into_ref ( )
962
+ } . into_ref ( )
944
963
}
945
964
946
965
/// Deprecated method, please call `vm.to_pystr`
@@ -951,6 +970,7 @@ impl PyObject {
951
970
PyObjectKind :: Float { ref value } => format ! ( "{:?}" , value) ,
952
971
PyObjectKind :: Complex { ref value } => format ! ( "{:?}" , value) ,
953
972
PyObjectKind :: Bytes { ref value } => format ! ( "b'{:?}'" , value) ,
973
+ PyObjectKind :: ByteArray { ref value } => format ! ( "b'{:?}'" , value) ,
954
974
PyObjectKind :: MemoryView { ref obj } => format ! ( "b'{:?}'" , obj) ,
955
975
PyObjectKind :: Sequence { ref elements } => format ! (
956
976
"(/[{}]/)" ,
0 commit comments