mirror of
https://github.com/python/cpython.git
synced 2025-08-23 10:16:01 +00:00
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>
This commit is contained in:
parent
1fdc35ef51
commit
f5b76330cf
3 changed files with 14 additions and 4 deletions
|
@ -6020,3 +6020,14 @@ def install_tests_in_module_dict(remote_globs, start_method):
|
||||||
|
|
||||||
remote_globs['setUpModule'] = setUpModule
|
remote_globs['setUpModule'] = setUpModule
|
||||||
remote_globs['tearDownModule'] = tearDownModule
|
remote_globs['tearDownModule'] = tearDownModule
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(not hasattr(_multiprocessing, 'SemLock'), 'SemLock not available')
|
||||||
|
class SemLockTests(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_semlock_subclass(self):
|
||||||
|
class SemLock(_multiprocessing.SemLock):
|
||||||
|
pass
|
||||||
|
name = f'test_semlock_subclass-{os.getpid()}'
|
||||||
|
s = SemLock(1, 0, 10, name, 0)
|
||||||
|
_multiprocessing.sem_unlink(name)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix crash when deallocating an instance of a subclass of ``_multiprocessing.SemLock``. Patch by Kumar Aditya.
|
|
@ -454,9 +454,7 @@ static PyObject *
|
||||||
newsemlockobject(PyTypeObject *type, SEM_HANDLE handle, int kind, int maxvalue,
|
newsemlockobject(PyTypeObject *type, SEM_HANDLE handle, int kind, int maxvalue,
|
||||||
char *name)
|
char *name)
|
||||||
{
|
{
|
||||||
SemLockObject *self;
|
SemLockObject *self = (SemLockObject *)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
self = PyObject_New(SemLockObject, type);
|
|
||||||
if (!self)
|
if (!self)
|
||||||
return NULL;
|
return NULL;
|
||||||
self->handle = handle;
|
self->handle = handle;
|
||||||
|
@ -573,7 +571,7 @@ semlock_dealloc(SemLockObject* self)
|
||||||
if (self->handle != SEM_FAILED)
|
if (self->handle != SEM_FAILED)
|
||||||
SEM_CLOSE(self->handle);
|
SEM_CLOSE(self->handle);
|
||||||
PyMem_Free(self->name);
|
PyMem_Free(self->name);
|
||||||
PyObject_Free(self);
|
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue