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.
This commit is contained in:
parent
6479cb0806
commit
1c35dbfb5d
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user