diff --git a/Lib/test/test_selectors.py b/Lib/test/test_selectors.py index 59c1d26a7c5..643775597c5 100644 --- a/Lib/test/test_selectors.py +++ b/Lib/test/test_selectors.py @@ -131,8 +131,6 @@ def test_unregister_after_fd_close_and_reuse(self): s.unregister(r) s.unregister(w) - # TODO: RUSTPYTHON - @unittest.expectedFailureIfWindows("TODO: RUSTPYTHON") def test_unregister_after_socket_close(self): s = self.SELECTOR() self.addCleanup(s.close) diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py index 113f959ff2d..cdbf341b9cb 100644 --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -178,13 +178,11 @@ def dgram_examine(self, proto, addr): buf += data self.assertEqual(buf, TEST_STR) - @unittest.expectedFailureIfWindows("TODO: RUSTPYTHON; AssertionError: -1 != 18446744073709551615") def test_TCPServer(self): self.run_server(socketserver.TCPServer, socketserver.StreamRequestHandler, self.stream_examine) - @unittest.expectedFailureIfWindows("TODO: RUSTPYTHON; AssertionError: -1 != 18446744073709551615") def test_ThreadingTCPServer(self): self.run_server(socketserver.ThreadingTCPServer, socketserver.StreamRequestHandler, @@ -217,13 +215,11 @@ def test_ForkingUnixStreamServer(self): socketserver.StreamRequestHandler, self.stream_examine) - @unittest.expectedFailureIfWindows("TODO: RUSTPYTHON; AssertionError: -1 != 18446744073709551615") def test_UDPServer(self): self.run_server(socketserver.UDPServer, socketserver.DatagramRequestHandler, self.dgram_examine) - @unittest.expectedFailureIfWindows("TODO: RUSTPYTHON; AssertionError: -1 != 18446744073709551615") def test_ThreadingUDPServer(self): self.run_server(socketserver.ThreadingUDPServer, socketserver.DatagramRequestHandler, @@ -298,7 +294,6 @@ def test_tcpserver_bind_leak(self): socketserver.TCPServer((HOST, -1), socketserver.StreamRequestHandler) - @unittest.expectedFailureIfWindows("TODO: RUSTPYTHON; AssertionError: -1 != 18446744073709551615") def test_context_manager(self): with socketserver.TCPServer((HOST, 0), socketserver.StreamRequestHandler) as server: diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py index 488a67e80fd..b291d530169 100644 --- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -730,7 +730,6 @@ def testTraceback(self): @unittest.skipIf(os_helper.TESTFN_UNENCODABLE is None, "need an unencodable filename") - @unittest.expectedFailureIfWindows("TODO: RUSTPYTHON") def testUnencodable(self): filename = os_helper.TESTFN_UNENCODABLE + ".zip" self.addCleanup(os_helper.unlink, filename) diff --git a/crates/stdlib/src/socket.rs b/crates/stdlib/src/socket.rs index d75595648aa..b4e4dac88aa 100644 --- a/crates/stdlib/src/socket.rs +++ b/crates/stdlib/src/socket.rs @@ -1065,8 +1065,7 @@ mod _socket { fn repr_str(zelf: &Py, _vm: &VirtualMachine) -> PyResult { Ok(format!( "", - // cast because INVALID_SOCKET is unsigned, so would show usize::MAX instead of -1 - zelf.fileno() as i64, + zelf.fileno(), zelf.family.load(), zelf.kind.load(), zelf.proto.load(), @@ -1462,25 +1461,25 @@ mod _socket { #[pymethod] fn close(&self) -> io::Result<()> { let sock = self.detach(); - if sock != INVALID_SOCKET { - close_inner(sock)?; + if sock != INVALID_SOCKET as i64 { + close_inner(sock as RawSocket)?; } Ok(()) } #[pymethod] #[inline] - fn detach(&self) -> RawSocket { + fn detach(&self) -> i64 { let sock = self.sock.write().take(); - sock.map_or(INVALID_SOCKET, into_sock_fileno) + sock.map_or(INVALID_SOCKET as i64, |s| into_sock_fileno(s) as i64) } #[pymethod] - fn fileno(&self) -> RawSocket { + fn fileno(&self) -> i64 { self.sock .read() .as_ref() - .map_or(INVALID_SOCKET, sock_fileno) + .map_or(INVALID_SOCKET as i64, |s| sock_fileno(s) as i64) } #[pymethod] diff --git a/crates/vm/src/stdlib/nt.rs b/crates/vm/src/stdlib/nt.rs index ce68b9d25f8..ada939b1549 100644 --- a/crates/vm/src/stdlib/nt.rs +++ b/crates/vm/src/stdlib/nt.rs @@ -1122,10 +1122,18 @@ pub(crate) mod module { } #[pyfunction] - fn _path_splitroot(path: OsPath, vm: &VirtualMachine) -> PyResult<(String, String)> { + fn _path_splitroot( + path: OsPath, + _vm: &VirtualMachine, + ) -> ( + rustpython_common::wtf8::Wtf8Buf, + rustpython_common::wtf8::Wtf8Buf, + ) { + use rustpython_common::wtf8::Wtf8Buf; + let orig: Vec<_> = path.path.to_wide(); if orig.is_empty() { - return Ok(("".to_owned(), "".to_owned())); + return (Wtf8Buf::new(), Wtf8Buf::new()); } let backslashed: Vec<_> = orig .iter() @@ -1134,15 +1142,11 @@ pub(crate) mod module { .chain(std::iter::once(0)) // null-terminated .collect(); - fn from_utf16(wstr: &[u16], vm: &VirtualMachine) -> PyResult { - String::from_utf16(wstr).map_err(|e| vm.new_unicode_decode_error(e.to_string())) - } - let mut end: *const u16 = std::ptr::null(); let hr = unsafe { windows_sys::Win32::UI::Shell::PathCchSkipRoot(backslashed.as_ptr(), &mut end) }; - let (root, path) = if hr == 0 { + if hr == 0 { // S_OK assert!(!end.is_null()); let len: usize = unsafe { end.offset_from(backslashed.as_ptr()) } @@ -1155,11 +1159,13 @@ pub(crate) mod module { len, backslashed.len() ); - (from_utf16(&orig[..len], vm)?, from_utf16(&orig[len..], vm)?) + ( + Wtf8Buf::from_wide(&orig[..len]), + Wtf8Buf::from_wide(&orig[len..]), + ) } else { - ("".to_owned(), from_utf16(&orig, vm)?) - }; - Ok((root, path)) + (Wtf8Buf::new(), Wtf8Buf::from_wide(&orig)) + } } #[pyfunction]