File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -94,16 +94,13 @@ pub unsafe extern "C" fn PyDict_GetItemString(
9494) -> * mut PyObject {
9595 with_vm ( |vm| {
9696 let dict = unsafe { & * dict } . try_downcast_ref :: < PyDict > ( vm) ?;
97- let key = match unsafe { CStr :: from_ptr ( key) } . to_str ( ) {
98- Ok ( key) => key,
99- Err ( _) => {
100- return Ok ( core:: ptr:: null_mut ( ) ) ;
101- }
102- } ;
97+ let key = unsafe { CStr :: from_ptr ( key) }
98+ . to_str ( )
99+ . map_err ( |_| vm. new_unicode_decode_error ( "dictionary key must be valid UTF-8" ) ) ?;
103100
104- match dict. inner_getitem_opt ( key, vm) {
105- Ok ( Some ( value) ) => Ok ( value. as_object ( ) . as_raw ( ) . cast_mut ( ) ) ,
106- Ok ( None ) | Err ( _ ) => Ok ( core:: ptr:: null_mut ( ) ) ,
101+ match dict. inner_getitem_opt ( key, vm) ? {
102+ Some ( value) => Ok ( value. as_object ( ) . as_raw ( ) . cast_mut ( ) ) ,
103+ None => Ok ( core:: ptr:: null_mut ( ) ) ,
107104 }
108105 } )
109106}
You can’t perform that action at this time.
0 commit comments