From 7a17124b43d79d7d4d27a30c2b439884e7959ed5 Mon Sep 17 00:00:00 2001 From: matejcik Date: Fri, 17 Sep 2021 15:10:48 +0200 Subject: [PATCH] refactor(core/rust): do not rely too much on new_exception helpers --- core/embed/rust/build.rs | 2 -- core/embed/rust/src/error.rs | 10 +++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/embed/rust/build.rs b/core/embed/rust/build.rs index add740f9d..fef21544e 100644 --- a/core/embed/rust/build.rs +++ b/core/embed/rust/build.rs @@ -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") diff --git a/core/embed/rust/src/error.rs b/core/embed/rust/src/error.rs index ba6af4c47..7ad5a8aca 100644 --- a/core/embed/rust/src/error.rs +++ b/core/embed/rust/src/error.rs @@ -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()) } } }