Skip to content

Commit 756088e

Browse files
committed
more winapi to windows-sys
1 parent 4729ca3 commit 756088e

File tree

6 files changed

+64
-27
lines changed

6 files changed

+64
-27
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stdlib/Cargo.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,16 @@ widestring = { workspace = true }
112112
[target.'cfg(windows)'.dependencies.winapi]
113113
version = "0.3.9"
114114
features = [
115-
"winsock2", "ws2def", "std", "wincrypt", "fileapi",
116-
"impl-default", "vcruntime", "ifdef", "netioapi", "profileapi",
115+
"winsock2", "ifdef", "netioapi",
116+
]
117+
118+
[target.'cfg(windows)'.dependencies.windows-sys]
119+
version = "0.52.0"
120+
features = [
121+
"Win32_Networking_WinSock",
122+
"Win32_NetworkManagement_IpHelper",
123+
"Win32_NetworkManagement_Ndis",
124+
"Win32_Security_Cryptography",
117125
]
118126

119127
[target.'cfg(target_os = "macos")'.dependencies]

stdlib/src/multiprocessing.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ pub(crate) use _multiprocessing::make_module;
44
#[pymodule]
55
mod _multiprocessing {
66
use crate::vm::{function::ArgBytesLike, stdlib::os, PyResult, VirtualMachine};
7-
use winapi::um::winsock2::{self, SOCKET};
7+
use windows_sys::Win32::Networking::WinSock::{self, SOCKET};
88

99
#[pyfunction]
1010
fn closesocket(socket: usize, vm: &VirtualMachine) -> PyResult<()> {
11-
let res = unsafe { winsock2::closesocket(socket as SOCKET) };
11+
let res = unsafe { WinSock::closesocket(socket as SOCKET) };
1212
if res == 0 {
1313
Err(os::errno_err(vm))
1414
} else {
@@ -20,7 +20,7 @@ mod _multiprocessing {
2020
fn recv(socket: usize, size: usize, vm: &VirtualMachine) -> PyResult<libc::c_int> {
2121
let mut buf = vec![0; size];
2222
let nread =
23-
unsafe { winsock2::recv(socket as SOCKET, buf.as_mut_ptr() as *mut _, size as i32, 0) };
23+
unsafe { WinSock::recv(socket as SOCKET, buf.as_mut_ptr() as *mut _, size as i32, 0) };
2424
if nread < 0 {
2525
Err(os::errno_err(vm))
2626
} else {
@@ -31,7 +31,7 @@ mod _multiprocessing {
3131
#[pyfunction]
3232
fn send(socket: usize, buf: ArgBytesLike, vm: &VirtualMachine) -> PyResult<libc::c_int> {
3333
let ret = buf.with_ref(|b| unsafe {
34-
winsock2::send(socket as SOCKET, b.as_ptr() as *const _, b.len() as i32, 0)
34+
WinSock::send(socket as SOCKET, b.as_ptr() as *const _, b.len() as i32, 0)
3535
});
3636
if ret < 0 {
3737
Err(os::errno_err(vm))

stdlib/src/select.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ mod platform {
3030
#[allow(non_snake_case)]
3131
#[cfg(windows)]
3232
mod platform {
33-
use winapi::um::winsock2;
34-
pub use winsock2::{fd_set, select, timeval, FD_SETSIZE, SOCKET as RawFd};
33+
use windows_sys::Win32::Networking::WinSock;
34+
pub use WinSock::{select, FD_SET as fd_set, FD_SETSIZE, SOCKET as RawFd, TIMEVAL as timeval};
3535

3636
// based off winsock2.h: https://gist.github.com/piscisaureus/906386#file-winsock2-h-L128-L141
3737

@@ -45,7 +45,7 @@ mod platform {
4545
slot = slot.add(1);
4646
}
4747
// slot == &fd_array[fd_count] at this point
48-
if fd_count < FD_SETSIZE as u32 {
48+
if fd_count < FD_SETSIZE {
4949
*slot = fd as RawFd;
5050
(*set).fd_count += 1;
5151
}
@@ -56,12 +56,12 @@ mod platform {
5656
}
5757

5858
pub unsafe fn FD_ISSET(fd: RawFd, set: *mut fd_set) -> bool {
59-
use winapi::um::winsock2::__WSAFDIsSet;
59+
use WinSock::__WSAFDIsSet;
6060
__WSAFDIsSet(fd as _, set) != 0
6161
}
6262

6363
pub fn check_err(x: i32) -> bool {
64-
x == winsock2::SOCKET_ERROR
64+
x == WinSock::SOCKET_ERROR
6565
}
6666
}
6767

stdlib/src/socket.rs

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,46 @@ mod _socket {
3434
use libc as c;
3535
#[cfg(windows)]
3636
mod c {
37-
pub use winapi::shared::ifdef::IF_MAX_STRING_SIZE as IF_NAMESIZE;
38-
pub use winapi::shared::mstcpip::*;
3937
pub use winapi::shared::netioapi::{if_indextoname, if_nametoindex};
40-
pub use winapi::shared::ws2def::*;
41-
pub use winapi::shared::ws2ipdef::*;
38+
pub use winapi::shared::ws2def::{
39+
INADDR_ANY, INADDR_BROADCAST, INADDR_LOOPBACK, INADDR_NONE,
40+
};
4241
pub use winapi::um::winsock2::{
43-
IPPORT_RESERVED, SD_BOTH as SHUT_RDWR, SD_RECEIVE as SHUT_RD, SD_SEND as SHUT_WR,
44-
SOCK_DGRAM, SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_STREAM, SOL_SOCKET, SO_BROADCAST,
45-
SO_ERROR, SO_EXCLUSIVEADDRUSE, SO_LINGER, SO_OOBINLINE, SO_REUSEADDR, SO_TYPE,
46-
SO_USELOOPBACK, *,
42+
getprotobyname, getservbyname, getservbyport, getsockopt, setsockopt,
43+
SO_EXCLUSIVEADDRUSE,
44+
};
45+
pub use winapi::um::ws2tcpip::{
46+
EAI_AGAIN, EAI_BADFLAGS, EAI_FAIL, EAI_FAMILY, EAI_MEMORY, EAI_NODATA, EAI_NONAME,
47+
EAI_SERVICE, EAI_SOCKTYPE,
48+
};
49+
pub use windows_sys::Win32::Networking::WinSock::{
50+
AF_DECnet, AF_APPLETALK, AF_IPX, AF_LINK, AI_ADDRCONFIG, AI_ALL, AI_CANONNAME,
51+
AI_NUMERICSERV, AI_V4MAPPED, IPPORT_RESERVED, IPPROTO_AH, IPPROTO_DSTOPTS, IPPROTO_EGP,
52+
IPPROTO_ESP, IPPROTO_FRAGMENT, IPPROTO_GGP, IPPROTO_HOPOPTS, IPPROTO_ICMP,
53+
IPPROTO_ICMPV6, IPPROTO_IDP, IPPROTO_IGMP, IPPROTO_IP, IPPROTO_IP as IPPROTO_IPIP,
54+
IPPROTO_IPV4, IPPROTO_IPV6, IPPROTO_ND, IPPROTO_NONE, IPPROTO_PIM, IPPROTO_PUP,
55+
IPPROTO_RAW, IPPROTO_ROUTING, IPPROTO_TCP, IPPROTO_UDP, IPV6_CHECKSUM, IPV6_DONTFRAG,
56+
IPV6_HOPLIMIT, IPV6_HOPOPTS, IPV6_JOIN_GROUP, IPV6_LEAVE_GROUP, IPV6_MULTICAST_HOPS,
57+
IPV6_MULTICAST_IF, IPV6_MULTICAST_LOOP, IPV6_PKTINFO, IPV6_RECVRTHDR, IPV6_RECVTCLASS,
58+
IPV6_RTHDR, IPV6_TCLASS, IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP,
59+
IP_DROP_MEMBERSHIP, IP_HDRINCL, IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL,
60+
IP_OPTIONS, IP_RECVDSTADDR, IP_TOS, IP_TTL, MSG_BCAST, MSG_CTRUNC, MSG_DONTROUTE,
61+
MSG_MCAST, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, NI_DGRAM, NI_MAXHOST, NI_MAXSERV,
62+
NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST, NI_NUMERICSERV, RCVALL_IPLEVEL, RCVALL_OFF,
63+
RCVALL_ON, RCVALL_SOCKETLEVELONLY, SD_BOTH as SHUT_RDWR, SD_RECEIVE as SHUT_RD,
64+
SD_SEND as SHUT_WR, SIO_KEEPALIVE_VALS, SIO_LOOPBACK_FAST_PATH, SIO_RCVALL, SOCK_DGRAM,
65+
SOCK_RAW, SOCK_RDM, SOCK_SEQPACKET, SOCK_STREAM, SOL_SOCKET, SOMAXCONN, SO_BROADCAST,
66+
SO_ERROR, SO_LINGER, SO_OOBINLINE, SO_REUSEADDR, SO_TYPE, SO_USELOOPBACK, TCP_NODELAY,
67+
WSAEBADF, WSAECONNRESET, WSAENOTSOCK, WSAEWOULDBLOCK,
4768
};
48-
pub use winapi::um::ws2tcpip::*;
69+
pub const IF_NAMESIZE: usize =
70+
windows_sys::Win32::NetworkManagement::Ndis::IF_MAX_STRING_SIZE as _;
71+
pub const AF_UNSPEC: i32 = windows_sys::Win32::Networking::WinSock::AF_UNSPEC as _;
72+
pub const AF_INET: i32 = windows_sys::Win32::Networking::WinSock::AF_INET as _;
73+
pub const AF_INET6: i32 = windows_sys::Win32::Networking::WinSock::AF_INET6 as _;
74+
pub const AI_PASSIVE: i32 = windows_sys::Win32::Networking::WinSock::AI_PASSIVE as _;
75+
pub const AI_NUMERICHOST: i32 =
76+
windows_sys::Win32::Networking::WinSock::AI_NUMERICHOST as _;
4977
}
5078
// constants
5179
#[pyattr(name = "has_ipv6")]
@@ -658,7 +686,7 @@ mod _socket {
658686

659687
#[cfg(windows)]
660688
#[pyattr]
661-
use winapi::shared::ws2def::{
689+
use windows_sys::Win32::Networking::WinSock::{
662690
IPPROTO_CBT, IPPROTO_ICLFXBM, IPPROTO_IGP, IPPROTO_L2TP, IPPROTO_PGM, IPPROTO_RDP,
663691
IPPROTO_SCTP, IPPROTO_ST,
664692
};
@@ -2216,7 +2244,7 @@ mod _socket {
22162244
}
22172245
#[cfg(windows)]
22182246
{
2219-
winapi::um::winsock2::INVALID_SOCKET as RawSocket
2247+
windows_sys::Win32::Networking::WinSock::INVALID_SOCKET as RawSocket
22202248
}
22212249
};
22222250

@@ -2329,7 +2357,7 @@ mod _socket {
23292357
#[cfg(unix)]
23302358
use libc::close;
23312359
#[cfg(windows)]
2332-
use winapi::um::winsock2::closesocket as close;
2360+
use windows_sys::Win32::Networking::WinSock::closesocket as close;
23332361
let ret = unsafe { close(x as _) };
23342362
if ret < 0 {
23352363
let err = crate::common::os::errno();

stdlib/src/ssl.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ mod windows {
14531453
#[pyfunction]
14541454
fn enum_certificates(store_name: PyStrRef, vm: &VirtualMachine) -> PyResult<Vec<PyObjectRef>> {
14551455
use schannel::{cert_context::ValidUses, cert_store::CertStore, RawPointer};
1456-
use winapi::um::wincrypt;
1456+
use windows_sys::Win32::Security::Cryptography;
14571457

14581458
// TODO: check every store for it, not just 2 of them:
14591459
// https://github.com/python/cpython/blob/3.8/Modules/_ssl.c#L5603-L5610
@@ -1465,12 +1465,12 @@ mod windows {
14651465
let certs = stores.iter().flat_map(|s| s.certs()).map(|c| {
14661466
let cert = vm.ctx.new_bytes(c.to_der().to_owned());
14671467
let enc_type = unsafe {
1468-
let ptr = c.as_ptr() as wincrypt::PCCERT_CONTEXT;
1468+
let ptr = c.as_ptr() as *const Cryptography::CERT_CONTEXT;
14691469
(*ptr).dwCertEncodingType
14701470
};
14711471
let enc_type = match enc_type {
1472-
wincrypt::X509_ASN_ENCODING => vm.new_pyobj(ascii!("x509_asn")),
1473-
wincrypt::PKCS_7_ASN_ENCODING => vm.new_pyobj(ascii!("pkcs_7_asn")),
1472+
Cryptography::X509_ASN_ENCODING => vm.new_pyobj(ascii!("x509_asn")),
1473+
Cryptography::PKCS_7_ASN_ENCODING => vm.new_pyobj(ascii!("pkcs_7_asn")),
14741474
other => vm.new_pyobj(other),
14751475
};
14761476
let usage: PyObjectRef = match c.valid_uses()? {

0 commit comments

Comments
 (0)