@@ -14,7 +14,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in);
1414
1515STATIC mp_obj_t stream_read (uint n_args , const mp_obj_t * args ) {
1616 struct _mp_obj_base_t * o = (struct _mp_obj_base_t * )args [0 ];
17- if (o -> type -> stream_p . read == NULL ) {
17+ if (o -> type -> stream_p == NULL || o -> type -> stream_p -> read == NULL ) {
1818 // CPython: io.UnsupportedOperation, OSError subclass
1919 nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , "Operation not supported" ));
2020 }
@@ -25,7 +25,7 @@ STATIC mp_obj_t stream_read(uint n_args, const mp_obj_t *args) {
2525 }
2626 byte * buf = m_new (byte , sz );
2727 int error ;
28- machine_int_t out_sz = o -> type -> stream_p . read (o , buf , sz , & error );
28+ machine_int_t out_sz = o -> type -> stream_p -> read (o , buf , sz , & error );
2929 if (out_sz == -1 ) {
3030 nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError , "[Errno %d]" , error ));
3131 } else {
@@ -37,15 +37,15 @@ STATIC mp_obj_t stream_read(uint n_args, const mp_obj_t *args) {
3737
3838STATIC mp_obj_t stream_write (mp_obj_t self_in , mp_obj_t arg ) {
3939 struct _mp_obj_base_t * o = (struct _mp_obj_base_t * )self_in ;
40- if (o -> type -> stream_p . write == NULL ) {
40+ if (o -> type -> stream_p == NULL || o -> type -> stream_p -> write == NULL ) {
4141 // CPython: io.UnsupportedOperation, OSError subclass
4242 nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , "Operation not supported" ));
4343 }
4444
4545 uint sz ;
4646 const char * buf = mp_obj_str_get_data (arg , & sz );
4747 int error ;
48- machine_int_t out_sz = o -> type -> stream_p . write (self_in , buf , sz , & error );
48+ machine_int_t out_sz = o -> type -> stream_p -> write (self_in , buf , sz , & error );
4949 if (out_sz == -1 ) {
5050 nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError , "[Errno %d]" , error ));
5151 } else {
@@ -60,7 +60,7 @@ STATIC mp_obj_t stream_write(mp_obj_t self_in, mp_obj_t arg) {
6060#define READ_SIZE 256
6161STATIC mp_obj_t stream_readall (mp_obj_t self_in ) {
6262 struct _mp_obj_base_t * o = (struct _mp_obj_base_t * )self_in ;
63- if (o -> type -> stream_p . read == NULL ) {
63+ if (o -> type -> stream_p == NULL || o -> type -> stream_p -> read == NULL ) {
6464 // CPython: io.UnsupportedOperation, OSError subclass
6565 nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , "Operation not supported" ));
6666 }
@@ -72,7 +72,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) {
7272 int error ;
7373 int current_read = READ_SIZE ;
7474 while (true) {
75- machine_int_t out_sz = o -> type -> stream_p . read (self_in , p , current_read , & error );
75+ machine_int_t out_sz = o -> type -> stream_p -> read (self_in , p , current_read , & error );
7676 if (out_sz == -1 ) {
7777 nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError , "[Errno %d]" , error ));
7878 }
@@ -101,7 +101,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) {
101101// Unbuffered, inefficient implementation of readline() for raw I/O files.
102102STATIC mp_obj_t stream_unbuffered_readline (uint n_args , const mp_obj_t * args ) {
103103 struct _mp_obj_base_t * o = (struct _mp_obj_base_t * )args [0 ];
104- if (o -> type -> stream_p . read == NULL ) {
104+ if (o -> type -> stream_p == NULL || o -> type -> stream_p -> read == NULL ) {
105105 // CPython: io.UnsupportedOperation, OSError subclass
106106 nlr_raise (mp_obj_new_exception_msg (& mp_type_OSError , "Operation not supported" ));
107107 }
@@ -126,7 +126,7 @@ STATIC mp_obj_t stream_unbuffered_readline(uint n_args, const mp_obj_t *args) {
126126 nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError /*&mp_type_RuntimeError*/ , "Out of memory" ));
127127 }
128128
129- machine_int_t out_sz = o -> type -> stream_p . read (o , p , 1 , & error );
129+ machine_int_t out_sz = o -> type -> stream_p -> read (o , p , 1 , & error );
130130 if (out_sz == -1 ) {
131131 nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_OSError , "[Errno %d]" , error ));
132132 }
0 commit comments