summaryrefslogtreecommitdiff
path: root/py/moduerrno.c
diff options
context:
space:
mode:
authorMatt Wozniski <mwozniski@bloomberg.net>2018-06-01 13:49:04 -0400
committerMatt Wozniski <mwozniski@bloomberg.net>2018-06-01 19:03:51 -0400
commit1c35dbfb5d43ed94108475e8cd17bcb81cda646f (patch)
treea52fae0572fc6c89bfb9cced2f10ae554b09e8e6 /py/moduerrno.c
parent6479cb08060d7fb29b9189430a1ee8d105d37b26 (diff)
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.
Diffstat (limited to 'py/moduerrno.c')
-rw-r--r--py/moduerrno.c15
1 files changed, 13 insertions, 2 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