Skip to content

Commit 3ec7b5c

Browse files
authored
Implement Windows SemLock in _multiprocessing module (#7199)
* Implement Windows SemLock in _multiprocessing module Add SemLock class using Windows semaphore APIs (CreateSemaphoreW, WaitForSingleObjectEx, ReleaseSemaphore) so test_multiprocessing suites are no longer skipped with "lacks a functioning sem_open". Also add sem_unlink as no-op and flags dict for Windows. * Fix _multiprocessing recv to return bytes and improve SemLock reliability - recv() now returns bytes instead of int (matching CPython) - Remove spurious GetLastError() check after CreateSemaphoreW - Add signal checking during blocking SemLock acquire * Include winerror in OSError.__reduce__ on Windows * Remove expectedFailure for tests now passing with Windows SemLock * Fix OSError.__reduce__ to preserve winerror when filename is None When filename is None, __reduce__ was reconstructing a 2-element (errno, msg) tuple, dropping the winerror at position 3 in the original args. Use the original args tuple instead, matching CPython. * Validate maxvalue > 0 in SemLock and document winerror __reduce__ divergence * Reject embedded null characters in mmap tagname and _winapi file mapping names
1 parent f784a56 commit 3ec7b5c

6 files changed

Lines changed: 415 additions & 14 deletions

File tree

Lib/test/test_logging.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4119,8 +4119,6 @@ def test_90195(self):
41194119
# Logger should be enabled, since explicitly mentioned
41204120
self.assertFalse(logger.disabled)
41214121

4122-
# TODO: RUSTPYTHON - SemLock not implemented on Windows
4123-
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
41244122
def test_111615(self):
41254123
# See gh-111615
41264124
import_helper.import_module('_multiprocessing') # see gh-113692

Lib/test/test_socket.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6620,7 +6620,6 @@ def remoteProcessServer(cls, q):
66206620
s2.close()
66216621
s.close()
66226622

6623-
@unittest.expectedFailure # TODO: RUSTPYTHON; multiprocessing.SemLock not implemented
66246623
def testShare(self):
66256624
# Transfer the listening server socket to another process
66266625
# and service it from there.

crates/stdlib/src/mmap.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,15 @@ mod mmap {
557557
// Parse tagname: None or a string
558558
let tag_str: Option<String> = match tagname {
559559
Some(ref obj) if !vm.is_none(obj) => {
560-
Some(obj.try_to_value::<String>(vm).map_err(|_| {
560+
let s = obj.try_to_value::<String>(vm).map_err(|_| {
561561
vm.new_type_error("tagname must be a string or None".to_owned())
562-
})?)
562+
})?;
563+
if s.contains('\0') {
564+
return Err(vm.new_value_error(
565+
"tagname must not contain null characters".to_owned(),
566+
));
567+
}
568+
Some(s)
563569
}
564570
_ => None,
565571
};

0 commit comments

Comments
 (0)