summaryrefslogtreecommitdiffstatshomepage
path: root/unix
diff options
context:
space:
mode:
Diffstat (limited to 'unix')
-rw-r--r--unix/file.c8
-rw-r--r--unix/main.c5
-rw-r--r--unix/modsocket.c6
3 files changed, 14 insertions, 5 deletions
diff --git a/unix/file.c b/unix/file.c
index 7cf0a51932..cdec1ad1af 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/main.c b/unix/main.c
index 45ccc23c20..936d7a13a0 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -95,6 +95,11 @@ STATIC int execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind,
}
qstr source_name = mp_lexer_source_name(lex);
+ #if MICROPY_PY___FILE__
+ if (input_kind == MP_PARSE_FILE_INPUT) {
+ mp_store_global(MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name));
+ }
+ #endif
mp_lexer_free(lex);
/*
diff --git a/unix/modsocket.c b/unix/modsocket.c
index 160a1dcc02..a3380fb89a 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;
}