summaryrefslogtreecommitdiff
path: root/py/objexcept.c
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2022-09-17 00:31:23 +1000
committerDamien George <damien@micropython.org>2022-09-19 19:06:15 +1000
commit94beeabd2ee179d587942046555833e022241f24 (patch)
treeda625bb1857de03c33cc40c2139660dd34ee1798 /py/objexcept.c
parent6da41b59007c9e9a2443ae17278d32210034a63f (diff)
py/obj: Convert make_new into a mp_obj_type_t slot.
Instead of being an explicit field, it's now a slot like all the other methods. This is a marginal code size improvement because most types have a make_new (100/138 on PYBV11), however it improves consistency in how types are declared, removing the special case for make_new. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'py/objexcept.c')
-rw-r--r--py/objexcept.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/py/objexcept.c b/py/objexcept.c
index 190213e12..3b76ae62c 100644
--- a/py/objexcept.c
+++ b/py/objexcept.c
@@ -288,7 +288,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
mp_type_BaseException,
MP_QSTR_BaseException,
MP_TYPE_FLAG_NONE,
- mp_obj_exception_make_new,
+ make_new, mp_obj_exception_make_new,
print, mp_obj_exception_print,
attr, mp_obj_exception_attr
);
@@ -375,12 +375,12 @@ MP_DEFINE_EXCEPTION(Exception, BaseException)
// *FORMAT-ON*
mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type) {
- assert(exc_type->make_new == mp_obj_exception_make_new);
+ assert(MP_OBJ_TYPE_GET_SLOT_OR_NULL(exc_type, make_new) == mp_obj_exception_make_new);
return mp_obj_exception_make_new(exc_type, 0, 0, NULL);
}
mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, const mp_obj_t *args) {
- assert(exc_type->make_new == mp_obj_exception_make_new);
+ assert(MP_OBJ_TYPE_GET_SLOT_OR_NULL(exc_type, make_new) == mp_obj_exception_make_new);
return mp_obj_exception_make_new(exc_type, n_args, 0, args);
}
@@ -388,7 +388,7 @@ mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args,
mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, mp_rom_error_text_t msg) {
// Check that the given type is an exception type
- assert(exc_type->make_new == mp_obj_exception_make_new);
+ assert(MP_OBJ_TYPE_GET_SLOT_OR_NULL(exc_type, make_new) == mp_obj_exception_make_new);
// Try to allocate memory for the message
mp_obj_str_t *o_str = m_new_obj_maybe(mp_obj_str_t);
@@ -467,7 +467,7 @@ mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, mp_rom_er
assert(fmt != NULL);
// Check that the given type is an exception type
- assert(exc_type->make_new == mp_obj_exception_make_new);
+ assert(MP_OBJ_TYPE_GET_SLOT_OR_NULL(exc_type, make_new) == mp_obj_exception_make_new);
// Try to allocate memory for the message
mp_obj_str_t *o_str = m_new_obj_maybe(mp_obj_str_t);
@@ -538,7 +538,7 @@ bool mp_obj_is_exception_type(mp_obj_t self_in) {
if (mp_obj_is_type(self_in, &mp_type_type)) {
// optimisation when self_in is a builtin exception
mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in);
- if (self->make_new == mp_obj_exception_make_new) {
+ if (MP_OBJ_TYPE_GET_SLOT_OR_NULL(self, make_new) == mp_obj_exception_make_new) {
return true;
}
}