Merge pull request #891 from godlygeek/low_flash_errno_fixes

Human readable OSError messages for low flash devices
This commit is contained in:
Scott Shawcroft 2018-06-04 17:22:57 -07:00 committed by GitHub
commit 0c7c0821fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 11 deletions

View File

@ -292,6 +292,18 @@ extern const struct _mp_obj_module_t usb_hid_module;
{ MP_OBJ_NEW_QSTR(MP_QSTR_uheap),(mp_obj_t)&uheap_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_uheap),(mp_obj_t)&uheap_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_ustack),(mp_obj_t)&ustack_module } { MP_OBJ_NEW_QSTR(MP_QSTR_ustack),(mp_obj_t)&ustack_module }
#define MICROPY_PY_UERRNO_LIST \
X(EPERM) \
X(ENOENT) \
X(EIO) \
X(EAGAIN) \
X(ENOMEM) \
X(EACCES) \
X(EEXIST) \
X(ENODEV) \
X(EISDIR) \
X(EINVAL) \
// We need to provide a declaration/definition of alloca() // We need to provide a declaration/definition of alloca()
#include <alloca.h> #include <alloca.h>

View File

@ -82,7 +82,7 @@
#define MICROPY_STREAMS_NON_BLOCK (1) #define MICROPY_STREAMS_NON_BLOCK (1)
#define MICROPY_MODULE_WEAK_LINKS (1) #define MICROPY_MODULE_WEAK_LINKS (1)
#define MICROPY_CAN_OVERRIDE_BUILTINS (1) #define MICROPY_CAN_OVERRIDE_BUILTINS (1)
#define MICROPY_USE_INTERNAL_ERRNO (1) #define MICROPY_USE_INTERNAL_ERRNO (0)
#define MICROPY_PY_FUNCTION_ATTRS (1) #define MICROPY_PY_FUNCTION_ATTRS (1)
#define MICROPY_PY_BUILTINS_STR_UNICODE (1) #define MICROPY_PY_BUILTINS_STR_UNICODE (1)
#define MICROPY_PY_BUILTINS_STR_CENTER (0) #define MICROPY_PY_BUILTINS_STR_CENTER (0)

View File

@ -30,8 +30,6 @@
#include "py/obj.h" #include "py/obj.h"
#include "py/mperrno.h" #include "py/mperrno.h"
#if MICROPY_PY_UERRNO
// This list can be defined per port in mpconfigport.h to tailor it to a // This list can be defined per port in mpconfigport.h to tailor it to a
// specific port's needs. If it's not defined then we provide a default. // specific port's needs. If it's not defined then we provide a default.
#ifndef MICROPY_PY_UERRNO_LIST #ifndef MICROPY_PY_UERRNO_LIST
@ -61,6 +59,8 @@
#endif #endif
#if MICROPY_PY_UERRNO
#if MICROPY_PY_UERRNO_ERRORCODE #if MICROPY_PY_UERRNO_ERRORCODE
STATIC const mp_rom_map_elem_t errorcode_table[] = { STATIC const mp_rom_map_elem_t errorcode_table[] = {
#define X(e) { MP_ROM_INT(MP_ ## e), MP_ROM_QSTR(MP_QSTR_## e) }, #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) {
#endif #endif
} }
#else //MICROPY_PY_UERRNO
qstr mp_errno_to_str(mp_obj_t errno_val) {
int v = MP_OBJ_SMALL_INT_VALUE(errno_val);
#define X(e) if (v == e) return (MP_QSTR_ ## e);
MICROPY_PY_UERRNO_LIST
#undef X
return MP_QSTR_;
}
#endif //MICROPY_PY_UERRNO #endif //MICROPY_PY_UERRNO

View File

@ -142,12 +142,6 @@
#endif #endif
#if MICROPY_PY_UERRNO
#include "py/obj.h"
qstr mp_errno_to_str(mp_obj_t errno_val); qstr mp_errno_to_str(mp_obj_t errno_val);
#endif
#endif // MICROPY_INCLUDED_PY_MPERRNO_H #endif // MICROPY_INCLUDED_PY_MPERRNO_H

View File

@ -113,7 +113,6 @@ STATIC void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_pr
mp_print_str(print, ""); mp_print_str(print, "");
return; return;
} else if (o->args->len == 1) { } else if (o->args->len == 1) {
#if MICROPY_PY_UERRNO
// try to provide a nice OSError error message // try to provide a nice OSError error message
if (o->base.type == &mp_type_OSError && MP_OBJ_IS_SMALL_INT(o->args->items[0])) { if (o->base.type == &mp_type_OSError && MP_OBJ_IS_SMALL_INT(o->args->items[0])) {
qstr qst = mp_errno_to_str(o->args->items[0]); 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
return; return;
} }
} }
#endif
mp_obj_print_helper(print, o->args->items[0], PRINT_STR); mp_obj_print_helper(print, o->args->items[0], PRINT_STR);
return; return;
} }