Skip to content

Commit 1e75d00

Browse files
committed
Make registry value conversion infallible
Remove the obsolete Result wrapper after surrogate-preserving conversions eliminated the last error path, resolving Windows Clippy unnecessary_wraps. Assisted-by: OpenAI Codex:model version unavailable
1 parent b206783 commit 1e75d00

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

‎crates/vm/src/stdlib/winreg.rs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ mod winreg {
519519

520520
// Slice the data buffer to the actual size returned.
521521
let data_slice = &ret_data_buf[..current_data_size as usize];
522-
let py_data = reg_to_py(vm, data_slice, reg_type)?;
522+
let py_data = reg_to_py(vm, data_slice, reg_type);
523523

524524
// Return tuple (value_name, data, type)
525525
return Ok(vm
@@ -646,7 +646,7 @@ mod winreg {
646646
let wide_name = WideCString::from_str(name).map_err(|e| e.to_pyexception(vm))?;
647647
let (ret_buf, typ) = host_winreg::query_value_bytes(hkey, &wide_name)
648648
.map_err(|err| os_error_from_windows_code(vm, err as i32))?;
649-
let obj = reg_to_py(vm, &ret_buf, typ)?;
649+
let obj = reg_to_py(vm, &ret_buf, typ);
650650
// Return tuple (value, type)
651651
Ok(vm.ctx.new_tuple(vec![obj, vm.ctx.new_int(typ).into()]))
652652
}
@@ -696,22 +696,22 @@ mod winreg {
696696
}
697697
}
698698

699-
fn reg_to_py(vm: &VirtualMachine, ret_data: &[u8], typ: u32) -> PyResult {
699+
fn reg_to_py(vm: &VirtualMachine, ret_data: &[u8], typ: u32) -> PyObjectRef {
700700
match typ {
701701
REG_DWORD => {
702702
// If there isn’t enough data, return 0.
703703
let val = ret_data
704704
.first_chunk::<4>()
705705
.copied()
706706
.map_or(0, u32::from_ne_bytes);
707-
Ok(vm.ctx.new_int(val).into())
707+
vm.ctx.new_int(val).into()
708708
}
709709
REG_QWORD => {
710710
let val = ret_data
711711
.first_chunk::<8>()
712712
.copied()
713713
.map_or(0, u64::from_ne_bytes);
714-
Ok(vm.ctx.new_int(val).into())
714+
vm.ctx.new_int(val).into()
715715
}
716716
REG_SZ | REG_EXPAND_SZ => {
717717
let u16_slice = host_winreg::bytes_as_wide_slice(ret_data);
@@ -721,11 +721,11 @@ mod winreg {
721721
.position(|&c| c == 0)
722722
.unwrap_or(u16_slice.len());
723723
let s = Wtf8Buf::from_wide(&u16_slice[..len]);
724-
Ok(vm.ctx.new_str(s).into())
724+
vm.ctx.new_str(s).into()
725725
}
726726
REG_MULTI_SZ => {
727727
if ret_data.is_empty() {
728-
Ok(vm.ctx.new_list(vec![]).into())
728+
vm.ctx.new_list(vec![]).into()
729729
} else {
730730
let u16_slice = host_winreg::bytes_as_wide_slice(ret_data);
731731
let u16_count = u16_slice.len();
@@ -751,15 +751,15 @@ mod winreg {
751751
let s = Wtf8Buf::from_wide(&u16_slice[start..len]);
752752
strings.push(vm.ctx.new_str(s).into());
753753
}
754-
Ok(vm.ctx.new_list(strings).into())
754+
vm.ctx.new_list(strings).into()
755755
}
756756
}
757757
// For REG_BINARY and any other unknown types, return a bytes object if data exists.
758758
_ => {
759759
if ret_data.is_empty() {
760-
Ok(vm.ctx.none())
760+
vm.ctx.none()
761761
} else {
762-
Ok(vm.ctx.new_bytes(ret_data.to_vec()).into())
762+
vm.ctx.new_bytes(ret_data.to_vec()).into()
763763
}
764764
}
765765
}

0 commit comments

Comments
 (0)