3737// This file defines generic Python stream read/write methods which
3838// dispatch to the underlying stream interface of an object.
3939
40+ // TODO: should be in mpconfig.h
41+ #define DEFAULT_BUFFER_SIZE 256
42+
4043STATIC mp_obj_t stream_readall (mp_obj_t self_in );
4144
4245// TODO: This is POSIX-specific (but then POSIX is the only real thing,
@@ -101,8 +104,6 @@ STATIC mp_obj_t stream_write(mp_obj_t self_in, mp_obj_t arg) {
101104 }
102105}
103106
104- // TODO: should be in mpconfig.h
105- #define READ_SIZE 256
106107STATIC mp_obj_t stream_readall (mp_obj_t self_in ) {
107108 struct _mp_obj_base_t * o = (struct _mp_obj_base_t * )self_in ;
108109 if (o -> type -> stream_p == NULL || o -> type -> stream_p -> read == NULL ) {
@@ -111,11 +112,11 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) {
111112 }
112113
113114 int total_size = 0 ;
114- vstr_t * vstr = vstr_new_size (READ_SIZE );
115+ vstr_t * vstr = vstr_new_size (DEFAULT_BUFFER_SIZE );
115116 char * buf = vstr_str (vstr );
116117 char * p = buf ;
117118 int error ;
118- int current_read = READ_SIZE ;
119+ int current_read = DEFAULT_BUFFER_SIZE ;
119120 while (true) {
120121 machine_int_t out_sz = o -> type -> stream_p -> read (self_in , p , current_read , & error );
121122 if (out_sz == -1 ) {
@@ -138,7 +139,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) {
138139 current_read -= out_sz ;
139140 p += out_sz ;
140141 } else {
141- current_read = READ_SIZE ;
142+ current_read = DEFAULT_BUFFER_SIZE ;
142143 p = vstr_extend (vstr , current_read );
143144 if (p == NULL ) {
144145 // TODO
0 commit comments