diff options
author | Damien George <damien.p.george@gmail.com> | 2014-07-27 22:38:58 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-07-27 22:38:58 +0100 |
commit | adf0f2ae1a3debf8465ece7e065ddba2d4032e8c (patch) | |
tree | 090c7544536b130b47e30f8834d7450272dfb54a /stmhal | |
parent | 05c255f039b5c0fbdcb0754748fd5d36135acfd9 (diff) | |
download | micropython-adf0f2ae1a3debf8465ece7e065ddba2d4032e8c.tar.gz micropython-adf0f2ae1a3debf8465ece7e065ddba2d4032e8c.zip |
py: Change stream protocol API: fns return uint; is_text for text.
Diffstat (limited to 'stmhal')
-rw-r--r-- | stmhal/file.c | 10 | ||||
-rw-r--r-- | stmhal/pybstdio.c | 16 |
2 files changed, 13 insertions, 13 deletions
diff --git a/stmhal/file.c b/stmhal/file.c index c1a2924903..db6d08e5e5 100644 --- a/stmhal/file.c +++ b/stmhal/file.c @@ -73,24 +73,24 @@ void file_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, m print(env, "<io.%s %p>", mp_obj_get_type_str(self_in), self_in); } -STATIC mp_int_t file_obj_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +STATIC mp_uint_t file_obj_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { pyb_file_obj_t *self = self_in; UINT sz_out; FRESULT res = f_read(&self->fp, buf, size, &sz_out); if (res != FR_OK) { *errcode = fresult_to_errno_table[res]; - return -1; + return MP_STREAM_ERROR; } return sz_out; } -STATIC mp_int_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +STATIC mp_uint_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { pyb_file_obj_t *self = self_in; UINT sz_out; FRESULT res = f_write(&self->fp, buf, size, &sz_out); if (res != FR_OK) { *errcode = fresult_to_errno_table[res]; - return -1; + return MP_STREAM_ERROR; } return sz_out; } @@ -240,7 +240,6 @@ STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table); STATIC const mp_stream_p_t fileio_stream_p = { .read = file_obj_read, .write = file_obj_write, - .is_bytes = true, }; const mp_obj_type_t mp_type_fileio = { @@ -258,6 +257,7 @@ const mp_obj_type_t mp_type_fileio = { STATIC const mp_stream_p_t textio_stream_p = { .read = file_obj_read, .write = file_obj_write, + .is_text = true, }; const mp_obj_type_t mp_type_textio = { diff --git a/stmhal/pybstdio.c b/stmhal/pybstdio.c index 9846ce0453..88f47d1b44 100644 --- a/stmhal/pybstdio.c +++ b/stmhal/pybstdio.c @@ -27,6 +27,7 @@ #include <stdio.h> #include <stdint.h> #include <string.h> +#include <errno.h> #include "mpconfig.h" #include "misc.h" @@ -109,7 +110,7 @@ void stdio_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, print(env, "<io.FileIO %d>", self->fd); } -STATIC mp_int_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +STATIC mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { pyb_stdio_obj_t *self = self_in; if (self->fd == STDIO_FD_IN) { for (uint i = 0; i < size; i++) { @@ -119,23 +120,21 @@ STATIC mp_int_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *err } ((byte*)buf)[i] = c; } - *errcode = 0; return size; } else { - *errcode = 1; - return 0; + *errcode = EPERM; + return MP_STREAM_ERROR; } } -STATIC mp_int_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { pyb_stdio_obj_t *self = self_in; if (self->fd == STDIO_FD_OUT || self->fd == STDIO_FD_ERR) { stdout_tx_strn_cooked(buf, size); - *errcode = 0; return size; } else { - *errcode = 1; - return 0; + *errcode = EPERM; + return MP_STREAM_ERROR; } } @@ -162,6 +161,7 @@ STATIC MP_DEFINE_CONST_DICT(stdio_locals_dict, stdio_locals_dict_table); STATIC const mp_stream_p_t stdio_obj_stream_p = { .read = stdio_read, .write = stdio_write, + .is_text = true, }; STATIC const mp_obj_type_t stdio_obj_type = { |