MCPcopy Index your code
hub / github.com/RustPython/RustPython / QueryValue

Function QueryValue

crates/vm/src/stdlib/winreg.rs:649–737  ·  view source on GitHub ↗
(key: HKEYArg, sub_key: Option<String>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

647
648 #[pyfunction]
649 fn QueryValue(key: HKEYArg, sub_key: Option<String>, vm: &VirtualMachine) -> PyResult<String> {
650 let hkey = key.0;
651
652 if hkey == Registry::HKEY_PERFORMANCE_DATA {
653 return Err(os_error_from_windows_code(
654 vm,
655 Foundation::ERROR_INVALID_HANDLE as i32,
656 ));
657 }
658
659 // Open subkey if provided and non-empty
660 let child_key = if let Some(ref sk) = sub_key {
661 if !sk.is_empty() {
662 let wide_sub_key = sk.to_wide_with_nul();
663 let mut out_key = core::ptr::null_mut();
664 let res = unsafe {
665 Registry::RegOpenKeyExW(
666 hkey,
667 wide_sub_key.as_ptr(),
668 0,
669 Registry::KEY_QUERY_VALUE,
670 &mut out_key,
671 )
672 };
673 if res != 0 {
674 return Err(os_error_from_windows_code(vm, res as i32));
675 }
676 Some(out_key)
677 } else {
678 None
679 }
680 } else {
681 None
682 };
683
684 let target_key = child_key.unwrap_or(hkey);
685 let mut buf_size: u32 = 256;
686 let mut buffer: Vec<u8> = vec![0; buf_size as usize];
687 let mut reg_type: u32 = 0;
688
689 // Loop to handle ERROR_MORE_DATA
690 let result = loop {
691 let mut size = buf_size;
692 let res = unsafe {
693 Registry::RegQueryValueExW(
694 target_key,
695 core::ptr::null(), // NULL value name for default value
696 core::ptr::null_mut(),
697 &mut reg_type,
698 buffer.as_mut_ptr(),
699 &mut size,
700 )
701 };
702 if res == ERROR_MORE_DATA {
703 buf_size *= 2;
704 buffer.resize(buf_size as usize, 0);
705 continue;
706 }

Callers 4

_read_test_dataMethod · 0.85
test_changing_valueMethod · 0.85
test_reflectionMethod · 0.85

Calls 13

newFunction · 0.85
bytes_as_wide_sliceFunction · 0.85
to_wide_with_nulMethod · 0.80
as_mut_ptrMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
is_emptyMethod · 0.45
as_ptrMethod · 0.45
resizeMethod · 0.45
positionMethod · 0.45
iterMethod · 0.45

Tested by 4

_read_test_dataMethod · 0.68
test_changing_valueMethod · 0.68
test_reflectionMethod · 0.68