Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions py/dynruntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ static inline mp_obj_t mp_obj_cast_to_native_base_dyn(mp_obj_t self_in, mp_const

if (MP_OBJ_FROM_PTR(self_type) == native_type) {
return self_in;
}
mp_parent_t parent = mp_type_get_parent_slot(self_type);
if (parent != native_type) {
Comment on lines -143 to -145
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably correct for us. It looks like this is an incorrect trace of my work to split type objects into a main part and an optional part; the 'parent' field ended up in the main part, but this code was to help adapt for the case that it was in the optional part.

} else if (self_type->parent != native_type) {
// The self_in object is not a direct descendant of native_type, so fail the cast.
// This is a very simple version of mp_obj_is_subclass_fast that could be improved.
return MP_OBJ_NULL;
Expand Down Expand Up @@ -221,7 +219,7 @@ static inline mp_obj_t mp_obj_len_dyn(mp_obj_t o) {

#define nlr_raise(o) (mp_raise_dyn(o))
#define mp_raise_type_arg(type, arg) (mp_raise_dyn(mp_obj_new_exception_arg1_dyn((type), (arg))))
#define mp_raise_msg(type, msg) (mp_fun_table.raise_msg_str((type), (msg)))
#define mp_raise_msg(type, msg) (mp_fun_table.raise_msg((type), (msg)))
#define mp_raise_OSError(er) (mp_raise_OSError_dyn(er))
#define mp_raise_NotImplementedError(msg) (mp_raise_msg(&mp_type_NotImplementedError, (msg)))
#define mp_raise_TypeError(msg) (mp_raise_msg(&mp_type_TypeError, (msg)))
Expand Down Expand Up @@ -281,7 +279,7 @@ static inline void mp_obj_get_array_dyn(mp_obj_t o, size_t *len, mp_obj_t **item
*len = l->len;
*items = l->items;
} else {
mp_raise_TypeError("expected tuple/list");
mp_raise_TypeError(MP_ERROR_TEXT("expected tuple/list"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion py/nativeglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ const mp_fun_table_t mp_fun_table = {
gc_realloc,
mp_printf,
mp_vprintf,
mp_raise_msg_str,
mp_raise_msg,
mp_obj_get_type,
mp_obj_new_str,
mp_obj_new_bytes,
Expand Down
2 changes: 1 addition & 1 deletion py/nativeglue.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ typedef struct _mp_fun_table_t {
#if defined(__GNUC__)
NORETURN // Only certain compilers support no-return attributes in function pointer declarations
#endif
void (*raise_msg_str)(const mp_obj_type_t *exc_type, const char *msg);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does raising exceptions from a native module actually work with these changes? I expect that it doesn't, because there's no way for the string to be entered in the list of translations that is baked into the core, and the translate() function is not available to call from the dynamic runtime either.

void (*raise_msg)(const mp_obj_type_t *exc_type, const compressed_string_t *);
const mp_obj_type_t *(*obj_get_type)(mp_const_obj_t o_in);
mp_obj_t (*obj_new_str)(const char *data, size_t len);
mp_obj_t (*obj_new_bytes)(const byte *data, size_t len);
Expand Down
2 changes: 1 addition & 1 deletion supervisor/shared/translate.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ uint16_t decompress_length(const compressed_string_t *compressed);

// Map MicroPython's error messages to our translations.
#if defined(MICROPY_ENABLE_DYNRUNTIME) && MICROPY_ENABLE_DYNRUNTIME
#define MP_ERROR_TEXT(x) (x)
#define MP_ERROR_TEXT(x) translate(x)
#else
#define MP_ERROR_TEXT(x) translate(x)
#endif
Expand Down