8000 Remove winapi dependency and upgrade windows-sys to 0.59 by arihant2math · Pull Request #5581 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

Remove winapi dependency and upgrade windows-sys to 0.59 #5581

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

Merged
merged 8 commits into from
Mar 5, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
resolve comments
  • Loading branch information
arihant2math committed Mar 5, 2025
commit b294628c9caa13e744f2701abd85890fc7e6152a
33 changes: 7 additions & 26 deletions stdlib/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1757,15 +1757,12 @@ mod _socket {
.map(|s| s.to_cstring(vm))
.transpose()?;
let cstr_proto = cstr_opt_as_ptr(&cstr_proto);
#[cfg(windows)]
let serv = unsafe {
c::getservbyname(
cstr_name.as_ptr() as windows_sys::core::PCSTR,
cstr_proto as windows_sys::core::PCSTR,
cstr_name.as_ptr() as _,
cstr_proto as _,
)
};
#[cfg(not(windows))]
let serv = unsafe { c::getservbyname(cstr_name.as_ptr(), cstr_proto) };
if serv.is_null() {
return Err(vm.new_os_error("service/proto not found".to_owned()));
}
Expand All @@ -1787,18 +1784,11 @@ mod _socket {
.map(|s| s.to_cstring(vm))
.transpose()?;
let cstr_proto = cstr_opt_as_ptr(&cstr_proto);
#[cfg(windows)]
let serv =
unsafe { c::getservbyport(port.to_be() as _, cstr_proto as windows_sys::core::PCSTR) };
#[cfg(not(windows))]
let serv = unsafe { c::getservbyport(port.to_be() as _, cstr_proto) };
let serv = unsafe { c::getservbyport(port.to_be() as _, cstr_proto as _) };
if serv.is_null() {
return Err(vm.new_os_error("port/proto not found".to_owned()));
}
#[cfg(windows)]
let s = unsafe { ffi::CStr::from_ptr((*serv CE45 ).s_name as *const i8) };
#[cfg(not(windows))]
let s = unsafe { ffi::CStr::from_ptr((*serv).s_name) };
let s = unsafe { ffi::CStr::from_ptr((*serv).s_name as _) };
Ok(s.to_string_lossy().into_owned())
}

Expand Down Expand Up @@ -2050,10 +2040,7 @@ mod _socket {
#[pyfunction]
fn getprotobyname(name: PyStrRef, vm: &VirtualMachine) -> PyResult {
let cstr = name.to_cstring(vm)?;
#[cfg(windows)]
let proto = unsafe { c::getprotobyname(cstr.as_ptr() as *const u8) };
#[cfg(not(windows))]
let proto = unsafe { c::getprotobyname(cstr.as_ptr()) };
let proto = unsafe { c::getprotobyname(cstr.as_ptr() as _) };
if proto.is_null() {
return Err(vm.new_os_error("protocol not found".to_owned()));
}
Expand Down Expand Up @@ -2138,10 +2125,7 @@ mod _socket {
fn if_nametoindex(name: FsPath, vm: &VirtualMachine) -> PyResult<IfIndex> {
let name = name.to_cstring(vm)?;

#[cfg(windows)]
let ret = unsafe { c::if_nametoindex(name.as_ptr() as *const u8) };
#[cfg(not(windows))]
let ret = unsafe { c::if_nametoindex(name.as_ptr()) };
let ret = unsafe { c::if_nametoindex(name.as_ptr() as _) };
if ret == 0 {
Err(vm.new_os_error("no interface with this name".to_owned()))
} else {
Expand All @@ -2157,10 +2141,7 @@ mod _socket {
if ret.is_null() {
Err(crate::vm::stdlib::os::errno_err(vm))
} else {
#[cfg(windows)]
let buf = unsafe { ffi::CStr::from_ptr(buf.as_ptr() as *const i8) };
#[cfg(not(windows))]
let buf = unsafe { ffi::CStr::from_ptr(buf.as_ptr()) };
let buf = unsafe { ffi::CStr::from_ptr(buf.as_ptr() as _) };
Ok(buf.to_string_lossy().into_owned())
}
}
Expand Down
Loading
0