summaryrefslogtreecommitdiff
path: root/unix
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-07-27 22:38:58 +0100
committerDamien George <damien.p.george@gmail.com>2014-07-27 22:38:58 +0100
commitadf0f2ae1a3debf8465ece7e065ddba2d4032e8c (patch)
tree090c7544536b130b47e30f8834d7450272dfb54a /unix
parent05c255f039b5c0fbdcb0754748fd5d36135acfd9 (diff)
py: Change stream protocol API: fns return uint; is_text for text.
Diffstat (limited to 'unix')
-rw-r--r--unix/file.c8
-rw-r--r--unix/modsocket.c6
2 files changed, 9 insertions, 5 deletions
diff --git a/unix/file.c b/unix/file.c
index 7cf0a5193..cdec1ad1a 100644
--- a/unix/file.c
+++ b/unix/file.c
@@ -66,22 +66,24 @@ STATIC void fdfile_print(void (*print)(void *env, const char *fmt, ...), void *e
print(env, "<io.%s %d>", mp_obj_get_type_str(self), self->fd);
}
-STATIC mp_int_t fdfile_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) {
+STATIC mp_uint_t fdfile_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) {
mp_obj_fdfile_t *o = o_in;
check_fd_is_open(o);
mp_int_t r = read(o->fd, buf, size);
if (r == -1) {
*errcode = errno;
+ return MP_STREAM_ERROR;
}
return r;
}
-STATIC mp_int_t fdfile_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) {
+STATIC mp_uint_t fdfile_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) {
mp_obj_fdfile_t *o = o_in;
check_fd_is_open(o);
mp_int_t r = write(o->fd, buf, size);
if (r == -1) {
*errcode = errno;
+ return MP_STREAM_ERROR;
}
return r;
}
@@ -190,7 +192,6 @@ STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table);
STATIC const mp_stream_p_t fileio_stream_p = {
.read = fdfile_read,
.write = fdfile_write,
- .is_bytes = true,
};
const mp_obj_type_t mp_type_fileio = {
@@ -208,6 +209,7 @@ const mp_obj_type_t mp_type_fileio = {
STATIC const mp_stream_p_t textio_stream_p = {
.read = fdfile_read,
.write = fdfile_write,
+ .is_text = true,
};
const mp_obj_type_t mp_type_textio = {
diff --git a/unix/modsocket.c b/unix/modsocket.c
index 160a1dcc0..a3380fb89 100644
--- a/unix/modsocket.c
+++ b/unix/modsocket.c
@@ -91,20 +91,22 @@ STATIC void socket_print(void (*print)(void *env, const char *fmt, ...), void *e
print(env, "<_socket %d>", self->fd);
}
-STATIC mp_int_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) {
+STATIC mp_uint_t socket_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) {
mp_obj_socket_t *o = o_in;
mp_int_t r = read(o->fd, buf, size);
if (r == -1) {
*errcode = errno;
+ return MP_STREAM_ERROR;
}
return r;
}
-STATIC mp_int_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) {
+STATIC mp_uint_t socket_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) {
mp_obj_socket_t *o = o_in;
mp_int_t r = write(o->fd, buf, size);
if (r == -1) {
*errcode = errno;
+ return MP_STREAM_ERROR;
}
return r;
}