Skip to content

Commit cb35402

Browse files
authored
pythongh-88750: On Windows, PyThread_acquire_lock() no longer checks for NULL (python#92586)
On Windows, PyThread_acquire_lock(), PyThread_acquire_lock_timed() and PyThread_release_lock() no longer check at runtime if the lock is not NULL.
1 parent 6ed7c35 commit cb35402

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Python/thread_nt.h

+12-8
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,17 @@ PyThread_exit_thread(void)
264264
PyThread_type_lock
265265
PyThread_allocate_lock(void)
266266
{
267-
PNRMUTEX aLock;
267+
PNRMUTEX mutex;
268268

269269
if (!initialized)
270270
PyThread_init_thread();
271271

272-
aLock = AllocNonRecursiveMutex() ;
272+
mutex = AllocNonRecursiveMutex() ;
273273

274-
return (PyThread_type_lock) aLock;
274+
PyThread_type_lock aLock = (PyThread_type_lock) mutex;
275+
assert(aLock);
276+
277+
return aLock;
275278
}
276279

277280
void
@@ -295,6 +298,8 @@ PyLockStatus
295298
PyThread_acquire_lock_timed(PyThread_type_lock aLock,
296299
PY_TIMEOUT_T microseconds, int intr_flag)
297300
{
301+
assert(aLock);
302+
298303
/* Fow now, intr_flag does nothing on Windows, and lock acquires are
299304
* uninterruptible. */
300305
PyLockStatus success;
@@ -321,8 +326,8 @@ PyThread_acquire_lock_timed(PyThread_type_lock aLock,
321326
milliseconds = INFINITE;
322327
}
323328

324-
if (aLock && EnterNonRecursiveMutex((PNRMUTEX)aLock,
325-
(DWORD)milliseconds) == WAIT_OBJECT_0) {
329+
if (EnterNonRecursiveMutex((PNRMUTEX)aLock,
330+
(DWORD)milliseconds) == WAIT_OBJECT_0) {
326331
success = PY_LOCK_ACQUIRED;
327332
}
328333
else {
@@ -340,9 +345,8 @@ PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag)
340345
void
341346
PyThread_release_lock(PyThread_type_lock aLock)
342347
{
343-
if (aLock) {
344-
(void)LeaveNonRecursiveMutex((PNRMUTEX) aLock);
345-
}
348+
assert(aLock);
349+
(void)LeaveNonRecursiveMutex((PNRMUTEX) aLock);
346350
}
347351

348352
/* minimum/maximum thread stack sizes supported */

0 commit comments

Comments
 (0)