1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-10 23:40:58 +00:00

feat(core/rust): introduce Obj.is_null()

[no changelog]
This commit is contained in:
matejcik 2021-09-10 11:20:45 +02:00 committed by Martin Milata
parent b666895303
commit 31de21718f
2 changed files with 9 additions and 3 deletions

View File

@ -57,6 +57,11 @@ impl Obj {
// micropython/py/obj.h mp_obj_is_obj
self.as_bits() & 3 == 0
}
pub fn is_null(self) -> bool {
// obj == NULL
self.as_bits() == 0
}
}
impl Obj {

View File

@ -86,7 +86,7 @@ impl MsgObj {
}
fn setattr(&mut self, attr: Qstr, value: Obj) -> Result<(), Error> {
if value == Obj::const_null() {
if value.is_null() {
// this would be a delattr
return Err(Error::TypeError);
}
@ -131,7 +131,7 @@ unsafe extern "C" fn msg_obj_attr(self_in: Obj, attr: ffi::qstr, dest: *mut Obj)
let attr = Qstr::from_u16(attr as _);
unsafe {
if dest.read() == Obj::const_null() {
if dest.read().is_null() {
// Load attribute
dest.write(this.getattr(attr)?);
} else {
@ -204,7 +204,8 @@ unsafe extern "C" fn msg_def_obj_attr(self_in: Obj, attr: ffi::qstr, dest: *mut
let this = Gc::<MsgDefObj>::try_from(self_in)?;
let attr = Qstr::from_u16(attr as _);
if unsafe { dest.read() } != Obj::const_null() {
let arg = unsafe { dest.read() };
if !arg.is_null() {
// this would be a setattr
return Err(Error::TypeError);
}