Skip to content

Commit 0c7c082

Browse files
authored
Merge pull request #891 from godlygeek/low_flash_errno_fixes
Human readable OSError messages for low flash devices
2 parents 9a6a5ea + d0e6bb2 commit 0c7c082

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

ports/atmel-samd/mpconfigport.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,18 @@ extern const struct _mp_obj_module_t usb_hid_module;
292292
{ MP_OBJ_NEW_QSTR(MP_QSTR_uheap),(mp_obj_t)&uheap_module }, \
293293
{ MP_OBJ_NEW_QSTR(MP_QSTR_ustack),(mp_obj_t)&ustack_module }
294294

295+
#define MICROPY_PY_UERRNO_LIST \
296+
X(EPERM) \
297+
X(ENOENT) \
298+
X(EIO) \
299+
X(EAGAIN) \
300+
X(ENOMEM) \
301+
X(EACCES) \
302+
X(EEXIST) \
303+
X(ENODEV) \
304+
X(EISDIR) \
305+
X(EINVAL) \
306+
295307
// We need to provide a declaration/definition of alloca()
296308
#include <alloca.h>
297309

ports/nrf/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
#define MICROPY_STREAMS_NON_BLOCK (1)
8383
#define MICROPY_MODULE_WEAK_LINKS (1)
8484
#define MICROPY_CAN_OVERRIDE_BUILTINS (1)
85-
#define MICROPY_USE_INTERNAL_ERRNO (1)
85+
#define MICROPY_USE_INTERNAL_ERRNO (0)
8686
#define MICROPY_PY_FUNCTION_ATTRS (1)
8787
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
8888
#define MICROPY_PY_BUILTINS_STR_CENTER (0)

py/moduerrno.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
#include "py/obj.h"
3131
#include "py/mperrno.h"
3232

33-
#if MICROPY_PY_UERRNO
34-
3533
// This list can be defined per port in mpconfigport.h to tailor it to a
3634
// specific port's needs. If it's not defined then we provide a default.
3735
#ifndef MICROPY_PY_UERRNO_LIST
@@ -61,6 +59,8 @@
6159

6260
#endif
6361

62+
#if MICROPY_PY_UERRNO
63+
6464
#if MICROPY_PY_UERRNO_ERRORCODE
6565
STATIC const mp_rom_map_elem_t errorcode_table[] = {
6666
#define X(e) { MP_ROM_INT(MP_ ## e), MP_ROM_QSTR(MP_QSTR_## e) },
@@ -133,4 +133,15 @@ qstr mp_errno_to_str(mp_obj_t errno_val) {
133133
#endif
134134
}
135135

136+
#else //MICROPY_PY_UERRNO
137+
138+
qstr mp_errno_to_str(mp_obj_t errno_val) {
139+
int v = MP_OBJ_SMALL_INT_VALUE(errno_val);
140+
#define X(e) if (v == e) return (MP_QSTR_ ## e);
141+
MICROPY_PY_UERRNO_LIST
142+
#undef X
143+
144+
return MP_QSTR_;
145+
}
146+
136147
#endif //MICROPY_PY_UERRNO

py/mperrno.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,6 @@
142142

143143
#endif
144144

145-
#if MICROPY_PY_UERRNO
146-
147-
#include "py/obj.h"
148-
149145
qstr mp_errno_to_str(mp_obj_t errno_val);
150146

151-
#endif
152-
153147
#endif // MICROPY_INCLUDED_PY_MPERRNO_H

py/objexcept.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ STATIC void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_pr
113113
mp_print_str(print, "");
114114
return;
115115
} else if (o->args->len == 1) {
116-
#if MICROPY_PY_UERRNO
117116
// try to provide a nice OSError error message
118117
if (o->base.type == &mp_type_OSError && MP_OBJ_IS_SMALL_INT(o->args->items[0])) {
119118
qstr qst = mp_errno_to_str(o->args->items[0]);
@@ -122,7 +121,6 @@ STATIC void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_pr
122121
return;
123122
}
124123
}
125-
#endif
126124
mp_obj_print_helper(print, o->args->items[0], PRINT_STR);
127125
return;
128126
}

0 commit comments

Comments
 (0)