refactor(core/rust): do not rely too much on new_exception helpers

pull/1821/head
matejcik 3 years ago committed by Martin Milata
parent 5e452dc57c
commit 7a17124b43

@ -97,8 +97,6 @@ fn generate_micropython_bindings() {
// exceptions // exceptions
.allowlist_function("nlr_jump") .allowlist_function("nlr_jump")
.allowlist_function("mp_obj_new_exception") .allowlist_function("mp_obj_new_exception")
.allowlist_function("mp_obj_new_exception_msg")
.allowlist_function("mp_obj_new_exception_arg1")
.allowlist_function("mp_obj_new_exception_args") .allowlist_function("mp_obj_new_exception_args")
.allowlist_function("trezor_obj_call_protected") .allowlist_function("trezor_obj_call_protected")
.allowlist_var("mp_type_AttributeError") .allowlist_var("mp_type_AttributeError")

@ -34,10 +34,14 @@ impl Error {
Error::AllocationFailed => ffi::mp_obj_new_exception(&ffi::mp_type_MemoryError), Error::AllocationFailed => ffi::mp_obj_new_exception(&ffi::mp_type_MemoryError),
Error::CaughtException(obj) => obj, Error::CaughtException(obj) => obj,
Error::KeyError(key) => { Error::KeyError(key) => {
ffi::mp_obj_new_exception_arg1(&ffi::mp_type_KeyError, key.into()) ffi::mp_obj_new_exception_args(&ffi::mp_type_KeyError, 1, &key.into())
} }
Error::ValueError(msg) => { Error::ValueError(msg) => {
ffi::mp_obj_new_exception_msg(&ffi::mp_type_ValueError, msg.as_ptr()) if let Ok(msg) = msg.try_into() {
ffi::mp_obj_new_exception_args(&ffi::mp_type_ValueError, 1, &msg)
} else {
ffi::mp_obj_new_exception(&ffi::mp_type_ValueError)
}
} }
Error::ValueErrorParam(msg, param) => { Error::ValueErrorParam(msg, param) => {
if let Ok(msg) = msg.try_into() { if let Ok(msg) = msg.try_into() {
@ -48,7 +52,7 @@ impl Error {
} }
} }
Error::AttributeError(attr) => { Error::AttributeError(attr) => {
ffi::mp_obj_new_exception_arg1(&ffi::mp_type_AttributeError, attr.into()) ffi::mp_obj_new_exception_args(&ffi::mp_type_AttributeError, 1, &attr.into())
} }
} }
} }

Loading…
Cancel
Save