1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 06:48:16 +00:00

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

This commit is contained in:
matejcik 2021-09-17 15:10:48 +02:00 committed by Martin Milata
parent 5e452dc57c
commit 7a17124b43
2 changed files with 7 additions and 5 deletions

View File

@ -97,8 +97,6 @@ fn generate_micropython_bindings() {
// exceptions
.allowlist_function("nlr_jump")
.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("trezor_obj_call_protected")
.allowlist_var("mp_type_AttributeError")

View File

@ -34,10 +34,14 @@ impl Error {
Error::AllocationFailed => ffi::mp_obj_new_exception(&ffi::mp_type_MemoryError),
Error::CaughtException(obj) => obj,
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) => {
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) => {
if let Ok(msg) = msg.try_into() {
@ -48,7 +52,7 @@ impl Error {
}
}
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())
}
}
}