summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-04-20 23:48:34 +1000
committerDamien George <damien.p.george@gmail.com>2020-04-27 23:58:46 +1000
commite08ca78f40bb1948acffa60c0315083acfb02227 (patch)
treedac5e7df1adfea8fbbb9d386adf50a43e0df0c97 /py
parent57fce3bdb203e9701dbd81ee108189898e19911b (diff)
py/stream: Remove mp_stream_errno and use system errno instead.
This change is made for two reasons: 1. A 3rd-party library (eg berkeley-db-1.xx, axtls) may use the system provided errno for certain errors, and yet MicroPython stream objects that it calls will be using the internal mp_stream_errno. So if the library returns an error it is not known whether the corresponding errno code is stored in the system errno or mp_stream_errno. Using the system errno in all cases (eg in the mp_stream_posix_XXX wrappers) fixes this ambiguity. 2. For systems that have threading the system-provided errno should always be used because the errno value is thread-local. For systems that do not have an errno, the new lib/embed/__errno.c file is provided.
Diffstat (limited to 'py')
-rw-r--r--py/stream.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/py/stream.c b/py/stream.c
index e6ffd3e2b..dce64a44d 100644
--- a/py/stream.c
+++ b/py/stream.c
@@ -503,14 +503,12 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_ioctl_obj, 2, 3, stream_ioctl);
* POSIX-compatible software to work with MicroPython streams.
*/
-// errno-like variable. If any of the functions below returned with error
-// status, this variable will contain error no.
-int mp_stream_errno;
+#include <errno.h>
ssize_t mp_stream_posix_write(void *stream, const void *buf, size_t len) {
mp_obj_base_t *o = stream;
const mp_stream_p_t *stream_p = o->type->protocol;
- mp_uint_t out_sz = stream_p->write(MP_OBJ_FROM_PTR(stream), buf, len, &mp_stream_errno);
+ mp_uint_t out_sz = stream_p->write(MP_OBJ_FROM_PTR(stream), buf, len, &errno);
if (out_sz == MP_STREAM_ERROR) {
return -1;
} else {
@@ -521,7 +519,7 @@ ssize_t mp_stream_posix_write(void *stream, const void *buf, size_t len) {
ssize_t mp_stream_posix_read(void *stream, void *buf, size_t len) {
mp_obj_base_t *o = stream;
const mp_stream_p_t *stream_p = o->type->protocol;
- mp_uint_t out_sz = stream_p->read(MP_OBJ_FROM_PTR(stream), buf, len, &mp_stream_errno);
+ mp_uint_t out_sz = stream_p->read(MP_OBJ_FROM_PTR(stream), buf, len, &errno);
if (out_sz == MP_STREAM_ERROR) {
return -1;
} else {
@@ -535,7 +533,7 @@ off_t mp_stream_posix_lseek(void *stream, off_t offset, int whence) {
struct mp_stream_seek_t seek_s;
seek_s.offset = offset;
seek_s.whence = whence;
- mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, &mp_stream_errno);
+ mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, &errno);
if (res == MP_STREAM_ERROR) {
return -1;
}
@@ -545,7 +543,7 @@ off_t mp_stream_posix_lseek(void *stream, off_t offset, int whence) {
int mp_stream_posix_fsync(void *stream) {
mp_obj_base_t *o = stream;
const mp_stream_p_t *stream_p = o->type->protocol;
- mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_FLUSH, 0, &mp_stream_errno);
+ mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_FLUSH, 0, &errno);
if (res == MP_STREAM_ERROR) {
return -1;
}