Skip to content

Commit 64f8c51

Browse files
committed
move init_winsock to nt
1 parent 66c041c commit 64f8c51

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

vm/src/stdlib/nt.rs

+8
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,11 @@ macro_rules! suppress_iph {
427427
ret
428428
}};
429429
}
430+
431+
pub fn init_winsock() {
432+
static WSA_INIT: parking_lot::Once = parking_lot::Once::new();
433+
WSA_INIT.call_once(|| unsafe {
434+
let mut wsa_data = std::mem::MaybeUninit::uninit();
435+
let _ = winapi::um::winsock2::WSAStartup(0x0101, wsa_data.as_mut_ptr());
436+
})
437+
}

vm/src/stdlib/select.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use crate::{PyObjectRef, PyResult, TryFromBorrowedObject, TryFromObject, Virtual
22
use std::{io, mem};
33

44
pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef {
5-
super::socket::init_winsock();
5+
#[cfg(windows)]
6+
super::nt::init_winsock();
7+
68
#[cfg(unix)]
79
{
810
use crate::PyClassImpl;

vm/src/stdlib/signal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub(crate) mod _signal {
192192

193193
#[cfg(windows)]
194194
let is_socket = if fd != INVALID_WAKEUP {
195-
crate::stdlib::socket::init_winsock();
195+
crate::stdlib::nt::init_winsock();
196196
let mut res = 0i32;
197197
let mut res_size = std::mem::size_of::<i32>() as i32;
198198
let res = unsafe {

vm/src/stdlib/socket.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,8 @@ rustpython_common::static_cell! {
18181818
}
18191819

18201820
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
1821-
init_winsock();
1821+
#[cfg(windows)]
1822+
super::nt::init_winsock();
18221823

18231824
let ctx = &vm.ctx;
18241825
let socket_timeout = TIMEOUT_ERROR
@@ -1978,14 +1979,3 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: &PyObjectRef) {
19781979
"sethostname" => named_function!(ctx, _socket, sethostname),
19791980
});
19801981
}
1981-
1982-
pub fn init_winsock() {
1983-
#[cfg(windows)]
1984-
{
1985-
static WSA_INIT: parking_lot::Once = parking_lot::Once::new();
1986-
WSA_INIT.call_once(|| unsafe {
1987-
let mut wsa_data = std::mem::MaybeUninit::uninit();
1988-
let _ = winapi::um::winsock2::WSAStartup(0x0101, wsa_data.as_mut_ptr());
1989-
})
1990-
}
1991-
}

0 commit comments

Comments
 (0)