Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f5b7633

Browse filesBrowse files
GH-94736: Fix _multiprocessing.SemLock subclassing (#94738)
* fix allocator and deallocator * 📜🤖 Added by blurb_it. * code review Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
1 parent 1fdc35e commit f5b7633
Copy full SHA for f5b7633

File tree

Expand file treeCollapse file tree

3 files changed

+14
-4
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+14
-4
lines changed

‎Lib/test/_test_multiprocessing.py

Copy file name to clipboardExpand all lines: Lib/test/_test_multiprocessing.py
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6020,3 +6020,14 @@ def tearDownModule():
60206020

60216021
remote_globs['setUpModule'] = setUpModule
60226022
remote_globs['tearDownModule'] = tearDownModule
6023+
6024+
6025+
@unittest.skipIf(not hasattr(_multiprocessing, 'SemLock'), 'SemLock not available')
6026+
class SemLockTests(unittest.TestCase):
6027+
6028+
def test_semlock_subclass(self):
6029+
class SemLock(_multiprocessing.SemLock):
6030+
pass
6031+
name = f'test_semlock_subclass-{os.getpid()}'
6032+
s = SemLock(1, 0, 10, name, 0)
6033+
_multiprocessing.sem_unlink(name)
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix crash when deallocating an instance of a subclass of ``_multiprocessing.SemLock``. Patch by Kumar Aditya.

‎Modules/_multiprocessing/semaphore.c

Copy file name to clipboardExpand all lines: Modules/_multiprocessing/semaphore.c
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,7 @@ static PyObject *
454454
newsemlockobject(PyTypeObject *type, SEM_HANDLE handle, int kind, int maxvalue,
455455
char *name)
456456
{
457-
SemLockObject *self;
458-
459-
self = PyObject_New(SemLockObject, type);
457+
SemLockObject *self = (SemLockObject *)type->tp_alloc(type, 0);
460458
if (!self)
461459
return NULL;
462460
self->handle = handle;
@@ -573,7 +571,7 @@ semlock_dealloc(SemLockObject* self)
573571
if (self->handle != SEM_FAILED)
574572
SEM_CLOSE(self->handle);
575573
PyMem_Free(self->name);
576-
PyObject_Free(self);
574+
Py_TYPE(self)->tp_free((PyObject*)self);
577575
}
578576

579577
/*[clinic input]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.