From 1c35dbfb5d43ed94108475e8cd17bcb81cda646f Mon Sep 17 00:00:00 2001 From: Matt Wozniski Date: Fri, 1 Jun 2018 13:49:04 -0400 Subject: Provide mp_errno_to_str even without uerrno We can provide a basic version of mp_errno_to_str even if the uerrno module won't be provided. Rather than looking errno names up in the uerrno module's globals dict, we'll just rely on a simple mapping in the function itself. --- py/moduerrno.c | 15 +++++++++++++-- py/mperrno.h | 6 ------ py/objexcept.c | 2 -- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/py/moduerrno.c b/py/moduerrno.c index ce8a6bf89..660fca07a 100644 --- a/py/moduerrno.c +++ b/py/moduerrno.c @@ -30,8 +30,6 @@ #include "py/obj.h" #include "py/mperrno.h" -#if MICROPY_PY_UERRNO - // 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. #ifndef MICROPY_PY_UERRNO_LIST @@ -61,6 +59,8 @@ #endif +#if MICROPY_PY_UERRNO + #if MICROPY_PY_UERRNO_ERRORCODE STATIC const mp_rom_map_elem_t errorcode_table[] = { #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 } +#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 diff --git a/py/mperrno.h b/py/mperrno.h index caac116ab..a028157ba 100644 --- a/py/mperrno.h +++ b/py/mperrno.h @@ -142,12 +142,6 @@ #endif -#if MICROPY_PY_UERRNO - -#include "py/obj.h" - qstr mp_errno_to_str(mp_obj_t errno_val); -#endif - #endif // MICROPY_INCLUDED_PY_MPERRNO_H diff --git a/py/objexcept.c b/py/objexcept.c index a800a13fb..f0874df77 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -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, ""); return; } else if (o->args->len == 1) { - #if MICROPY_PY_UERRNO // try to provide a nice OSError error message 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]); @@ -122,7 +121,6 @@ STATIC void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_pr return; } } - #endif mp_obj_print_helper(print, o->args->items[0], PRINT_STR); return; } -- cgit v1.2.3 From e798b67ca2be756c07558d18887698f2c9c06c2b Mon Sep 17 00:00:00 2001 From: Matt Wozniski Date: Fri, 1 Jun 2018 14:01:09 -0400 Subject: Begin a custom list of errnos for atmel-samd The uerrno module was written to allow boards to customize the list of errnos they can raise. Start by copying the default list. --- ports/atmel-samd/mpconfigport.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h index cd05927b0..b338fb6bb 100644 --- a/ports/atmel-samd/mpconfigport.h +++ b/ports/atmel-samd/mpconfigport.h @@ -290,6 +290,30 @@ 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_ustack),(mp_obj_t)&ustack_module } +#define MICROPY_PY_UERRNO_LIST \ + X(EPERM) \ + X(ENOENT) \ + X(EIO) \ + X(EBADF) \ + X(EAGAIN) \ + X(ENOMEM) \ + X(EACCES) \ + X(EEXIST) \ + X(ENODEV) \ + X(EISDIR) \ + X(EINVAL) \ + X(EOPNOTSUPP) \ + X(EADDRINUSE) \ + X(ECONNABORTED) \ + X(ECONNRESET) \ + X(ENOBUFS) \ + X(ENOTCONN) \ + X(ETIMEDOUT) \ + X(ECONNREFUSED) \ + X(EHOSTUNREACH) \ + X(EALREADY) \ + X(EINPROGRESS) \ + // We need to provide a declaration/definition of alloca() #include -- cgit v1.2.3 From 22f443878788ac5ed50a713897a7a3d4471c68da Mon Sep 17 00:00:00 2001 From: Matt Wozniski Date: Fri, 1 Jun 2018 14:06:10 -0400 Subject: Prune atmel-samd errno list Remove errnos that are only raised by modules that aren't linked into the atmel-samd port. --- ports/atmel-samd/mpconfigport.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h index b338fb6bb..eefc11957 100644 --- a/ports/atmel-samd/mpconfigport.h +++ b/ports/atmel-samd/mpconfigport.h @@ -294,7 +294,6 @@ extern const struct _mp_obj_module_t usb_hid_module; X(EPERM) \ X(ENOENT) \ X(EIO) \ - X(EBADF) \ X(EAGAIN) \ X(ENOMEM) \ X(EACCES) \ @@ -302,17 +301,6 @@ extern const struct _mp_obj_module_t usb_hid_module; X(ENODEV) \ X(EISDIR) \ X(EINVAL) \ - X(EOPNOTSUPP) \ - X(EADDRINUSE) \ - X(ECONNABORTED) \ - X(ECONNRESET) \ - X(ENOBUFS) \ - X(ENOTCONN) \ - X(ETIMEDOUT) \ - X(ECONNREFUSED) \ - X(EHOSTUNREACH) \ - X(EALREADY) \ - X(EINPROGRESS) \ // We need to provide a declaration/definition of alloca() #include -- cgit v1.2.3 From d0e6bb269fa425995a31083f02753203afccd253 Mon Sep 17 00:00:00 2001 From: Matt Wozniski Date: Sat, 2 Jun 2018 12:55:07 -0400 Subject: Use the system errno's on nrf --- ports/nrf/mpconfigport.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index 442e98de5..e379469c0 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -82,7 +82,7 @@ #define MICROPY_STREAMS_NON_BLOCK (1) #define MICROPY_MODULE_WEAK_LINKS (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_BUILTINS_STR_UNICODE (1) #define MICROPY_PY_BUILTINS_STR_CENTER (0) -- cgit v1.2.3