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>
This commit is contained in:
committed by
Damien George
parent
6da41b5900
commit
94beeabd2e
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user