Repository navigation
Align Windows helper call contracts #9650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
01b9bc6
1c6d8a7
3bbf3ae
91bcedd
e76139b
e8943cb
95da34e
7b69987
8a06517
6257576
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,17 +10,35 @@ mod _wmi { | |
| use crate::{PyResult, VirtualMachine}; | ||
| use rustpython_host_env::wmi as host_wmi; | ||
|
|
||
| #[pyfunction] | ||
| fn exec_query(query: PyStrRef, vm: &VirtualMachine) -> PyResult<String> { | ||
| let query_str = query.expect_str(); | ||
| #[derive(FromArgs)] | ||
| struct ExecQueryArgs { | ||
| #[pyarg(any)] | ||
| query: PyStrRef, | ||
| } | ||
|
|
||
| if !query_str | ||
| #[pyfunction] | ||
| fn exec_query(args: ExecQueryArgs, vm: &VirtualMachine) -> PyResult<PyStrRef> { | ||
| // Bind all keywords before converting the query, as Argument Clinic does. | ||
| let query = args.query; | ||
| vm.audit("_wmi.exec_query", || (query.clone(),))?; | ||
| let mut code_units = query.as_wtf8().encode_wide().collect::<Vec<_>>(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| // Adding the terminator first makes even a trailing input NUL interior. | ||
| code_units.push(0); | ||
| let wide = widestring::WideCString::from_vec(code_units) | ||
| .map_err(|_| vm.new_value_error("embedded null character"))?; | ||
| if !query | ||
| .as_wtf8() | ||
| .as_bytes() | ||
| .get(..7) | ||
| .is_some_and(|s| s.eq_ignore_ascii_case("select ")) | ||
| .is_some_and(|s| s.eq_ignore_ascii_case(b"select ")) | ||
| { | ||
| return Err(vm.new_value_error("only SELECT queries are supported")); | ||
| } | ||
|
|
||
| host_wmi::exec_query(query_str).map_err(|err| err.to_pyexception(vm)) | ||
| host_wmi::exec_query_wide(&wide) | ||
| .map(|result| { | ||
| vm.ctx | ||
| .new_str(crate::common::wtf8::Wtf8Buf::from_wide(&result)) | ||
| }) | ||
| .map_err(|err| err.to_pyexception(vm)) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: RustPython/RustPython
Length of output: 1593
Script executed:
Repository: RustPython/RustPython
Length of output: 5640
Script executed:
Repository: RustPython/RustPython
Length of output: 3245
Remove the
_ioattribute check fromwrite_input.write_inputlooks up_io._WindowsConsoleIOat call time. Python code that replaces that attribute makes a valid console stream fail the type check withTypeError.raw_windows_console_fdalready performs the native type check, so the module lookup is redundant.Suggested fix
Remove the
builtins::PyTypeRefimport if the compiler reports it as unused.