@@ -41,8 +41,11 @@ lazy_static! {
41
41
42
42
#[ cfg( all( feature = "std" , feature = "lender" ) ) ]
43
43
#[ inline]
44
- fn is_lent < T > ( pointer : * const T ) -> bool {
45
- return LENT . read ( ) . unwrap ( ) . contains ( & ( pointer as usize ) ) ;
44
+ fn invalid_error_check < T > ( pointer : * const T ) -> Result < ( ) , crate :: error:: PointerError > {
45
+ if !LENT . read ( ) . unwrap ( ) . contains ( & ( pointer as usize ) ) {
46
+ return Err ( crate :: error:: PointerError :: Invalid ) ;
47
+ }
48
+ return Ok ( ( ) ) ;
46
49
}
47
50
48
51
#[ inline]
@@ -101,9 +104,7 @@ pub unsafe fn free<T>(pointer: *mut T) {
101
104
pub unsafe fn own_back < T > ( pointer : * mut T ) -> Result < T , crate :: error:: PointerError > {
102
105
null_error_check ( pointer) ?;
103
106
#[ cfg( all( feature = "std" , feature = "lender" ) ) ]
104
- if !is_lent ( pointer) {
105
- return Err ( crate :: error:: PointerError :: Invalid ) ;
106
- }
107
+ invalid_error_check ( pointer) ?;
107
108
let boxed = { Box :: from_raw ( pointer) } ;
108
109
#[ cfg( all( feature = "std" , feature = "lender" ) ) ]
109
110
LENT . write ( ) . unwrap ( ) . remove ( & ( pointer as usize ) ) ;
@@ -126,9 +127,7 @@ pub unsafe fn own_back<T>(pointer: *mut T) -> Result<T, crate::error::PointerErr
126
127
pub unsafe fn object < ' a , T > ( pointer : * const T ) -> Result < & ' a T , crate :: error:: PointerError > {
127
128
null_error_check ( pointer) ?;
128
129
#[ cfg( all( feature = "std" , feature = "lender" ) ) ]
129
- if !is_lent ( pointer) {
130
- return Err ( crate :: error:: PointerError :: Invalid ) ;
131
- }
130
+ invalid_error_check ( pointer) ?;
132
131
return Ok ( & * pointer) ;
133
132
}
134
133
@@ -148,8 +147,6 @@ pub unsafe fn object<'a, T>(pointer: *const T) -> Result<&'a T, crate::error::Po
148
147
pub unsafe fn mut_object < ' a , T > ( pointer : * mut T ) -> Result < & ' a mut T , crate :: error:: PointerError > {
149
148
null_error_check ( pointer) ?;
150
149
#[ cfg( all( feature = "std" , feature = "lender" ) ) ]
151
- if !is_lent ( pointer) {
152
- return Err ( crate :: error:: PointerError :: Invalid ) ;
153
- }
150
+ invalid_error_check ( pointer) ?;
154
151
return Ok ( & mut * pointer) ;
155
152
}
0 commit comments