aboutsummaryrefslogtreecommitdiff
path: root/py/objtype.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2020-02-11 11:48:28 +1100
committerDamien George <damien.p.george@gmail.com>2020-02-13 11:52:40 +1100
commitad7213d3c31bccb26a3f54f7492ccf4b0cc920f3 (patch)
tree2ab64a805c05d790579052f557a8168061afcebe /py/objtype.c
parent97eca38c4f03e76bd464fb25974544a043af2a9e (diff)
py: Add mp_raise_msg_varg helper and use it where appropriate.
This commit adds mp_raise_msg_varg(type, fmt, ...) as a helper for nlr_raise(mp_obj_new_exception_msg_varg(type, fmt, ...)). It makes the C-level API for raising exceptions more consistent, and reduces code size on most ports: bare-arm: +28 +0.042% minimal x86: +100 +0.067% unix x64: -56 -0.011% unix nanbox: -300 -0.068% stm32: -204 -0.054% PYBV10 cc3200: +0 +0.000% esp8266: -64 -0.010% GENERIC esp32: -104 -0.007% GENERIC nrf: -136 -0.094% pca10040 samd: +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
Diffstat (limited to 'py/objtype.c')
-rw-r--r--py/objtype.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/py/objtype.c b/py/objtype.c
index 57cfeeccb..b2c2f58d9 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -351,8 +351,8 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("__init__() should return None");
} else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
- "__init__() should return None, not '%s'", mp_obj_get_type_str(init_ret)));
+ mp_raise_msg_varg(&mp_type_TypeError,
+ "__init__() should return None, not '%s'", mp_obj_get_type_str(init_ret));
}
}
@@ -867,8 +867,8 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("object not callable");
} else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
- "'%s' object isn't callable", mp_obj_get_type_str(self_in)));
+ mp_raise_msg_varg(&mp_type_TypeError,
+ "'%s' object isn't callable", mp_obj_get_type_str(self_in));
}
}
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
@@ -992,8 +992,7 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("cannot create instance");
} else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
- "cannot create '%q' instances", self->name));
+ mp_raise_msg_varg(&mp_type_TypeError, "cannot create '%q' instances", self->name);
}
}
@@ -1115,8 +1114,8 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_TypeError("type isn't an acceptable base type");
} else {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
- "type '%q' isn't an acceptable base type", t->name));
+ mp_raise_msg_varg(&mp_type_TypeError,
+ "type '%q' isn't an acceptable base type", t->name);
}
}
#if ENABLE_SPECIAL_ACCESSORS