Skip to content

feat: _winapi.GetModuleFileName#4098

Merged
youknowone merged 6 commits into
RustPython:mainfrom
jiang1997:win32api
Aug 21, 2022
Merged

feat: _winapi.GetModuleFileName#4098
youknowone merged 6 commits into
RustPython:mainfrom
jiang1997:win32api

Conversation

@jiang1997
Copy link
Copy Markdown
Contributor

@jiang1997 jiang1997 commented Aug 18, 2022

close #4001
close #3925 by including its all commits

Comment thread stdlib/src/lib.rs Outdated
Comment on lines +139 to +142
#[cfg(windows)]
{
"win32api" => win32api::make_module,
}
Copy link
Copy Markdown
Member

@youknowone youknowone Aug 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_winapi.GetModuleFileName is part of _winapi module. We don't need to add our original module for the purpose.
check winapi.rs file for the module.

@fanninpm
Copy link
Copy Markdown
Contributor

You might be looking for "feat". "feta" is a kind of cheese.

@youknowone youknowone changed the title feta: winapi.GetModuleFileName feat: winapi.GetModuleFileName Aug 18, 2022
@youknowone
Copy link
Copy Markdown
Member

You might be looking for "feat". "feta" is a kind of cheese.

@fanninpm you have permission to edit any title or text

Comment thread vm/src/stdlib/winapi.rs Outdated
}
}

const MAX_PATH: usize = 260;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@youknowone Do you have any idea to set MAX_PATH?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/python/cpython/blob/v3.10.5/Modules/_winapi.c#L1309-L1324
I found that in the implementation of cpython, it uses WCHAR[MAX_PATH](WCHAR = ctypes.c_wchar
) and ctypes.c_wchar has a fixed size of 2 bytes nvaccess/nvda#8981.
So it's fine to reuse MAX_PATH of windows-rs.

@jiang1997 jiang1997 marked this pull request as ready for review August 19, 2022 02:18
@youknowone youknowone changed the title feat: winapi.GetModuleFileName feat: _winapi.GetModuleFileName Aug 19, 2022
Copy link
Copy Markdown
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, looks very good. I left a few comments.
I will try to test this one with the http update because we don't have test for this function.

Comment thread vm/src/stdlib/winapi.rs Outdated
Comment on lines +440 to +421
#[pyfunction]
fn LoadLibrary(path: PyStrRef, vm: &VirtualMachine) -> PyResult<isize> {
let path = path.as_str().to_wide_null();
let handle = unsafe { LoadLibraryW(PCWSTR::from_raw(path.as_ptr())).unwrap() };
if handle.is_invalid() {
return Err(vm.new_runtime_error("LoadLibrary failed".to_owned()));
}
Ok(handle.0)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function seems not a _winapi function. By searching, ctypes? but we don't have one.
I need to think where to put this one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I forget to mention that it's for my personal test only.
Before getting a module's file name, I must load someone first.

Comment thread vm/src/stdlib/winapi.rs Outdated
Comment thread vm/src/stdlib/winapi.rs Outdated
Comment thread vm/src/stdlib/winapi.rs Outdated
Comment thread vm/src/stdlib/winapi.rs Outdated
Comment thread vm/src/stdlib/winapi.rs Outdated
Comment on lines +410 to +411
use std::ffi::{OsStr, OsString};
use std::os::windows::prelude::*;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we prefer to keep imports in a single group. relocate to line 23 will be the best (and cargo fmt --all to sort again)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

@youknowone youknowone force-pushed the win32api branch 2 times, most recently from 8657469 to ebafe66 Compare August 21, 2022 06:40
Copy link
Copy Markdown
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged it with the HTTP tests to check if it runs as expected.
Thank you for contributing!

@youknowone youknowone merged commit 6afb05b into RustPython:main Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_winapi.GetModuleFileName

3 participants