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:
parent
b666895303
commit
31de21718f
@ -57,6 +57,11 @@ impl Obj {
|
|||||||
// micropython/py/obj.h mp_obj_is_obj
|
// micropython/py/obj.h mp_obj_is_obj
|
||||||
self.as_bits() & 3 == 0
|
self.as_bits() & 3 == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_null(self) -> bool {
|
||||||
|
// obj == NULL
|
||||||
|
self.as_bits() == 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Obj {
|
impl Obj {
|
||||||
|
@ -86,7 +86,7 @@ impl MsgObj {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn setattr(&mut self, attr: Qstr, value: Obj) -> Result<(), Error> {
|
fn setattr(&mut self, attr: Qstr, value: Obj) -> Result<(), Error> {
|
||||||
if value == Obj::const_null() {
|
if value.is_null() {
|
||||||
// this would be a delattr
|
// this would be a delattr
|
||||||
return Err(Error::TypeError);
|
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 _);
|
let attr = Qstr::from_u16(attr as _);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if dest.read() == Obj::const_null() {
|
if dest.read().is_null() {
|
||||||
// Load attribute
|
// Load attribute
|
||||||
dest.write(this.getattr(attr)?);
|
dest.write(this.getattr(attr)?);
|
||||||
} else {
|
} 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 this = Gc::<MsgDefObj>::try_from(self_in)?;
|
||||||
let attr = Qstr::from_u16(attr as _);
|
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
|
// this would be a setattr
|
||||||
return Err(Error::TypeError);
|
return Err(Error::TypeError);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user