Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Lib/multiprocessing/sharedctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@
#

def _new_value(type_):
size = ctypes.sizeof(type_)
try:
size = ctypes.sizeof(type_)
except TypeError as e:
raise TypeError("bad typecode (must be a ctypes type or one of "
"c, b, B, u, h, H, i, I, l, L, q, Q, f or d)") from e

wrapper = heap.BufferWrapper(size)
return rebuild_ctype(type_, wrapper, None)

Expand Down
12 changes: 12 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2463,6 +2463,12 @@ def test_getobj_getlock(self):
self.assertNotHasAttr(arr5, 'get_lock')
self.assertNotHasAttr(arr5, 'get_obj')

@unittest.skipIf(c_int is None, "requires _ctypes")
def test_invalid_typecode(self):
with self.assertRaisesRegex(TypeError, 'bad typecode'):
self.Value('x', None)
with self.assertRaisesRegex(TypeError, 'bad typecode'):
self.RawValue('x', None)

class _TestArray(BaseTestCase):

Expand Down Expand Up @@ -2543,6 +2549,12 @@ def test_getobj_getlock_obj(self):
self.assertNotHasAttr(arr5, 'get_lock')
self.assertNotHasAttr(arr5, 'get_obj')

@unittest.skipIf(c_int is None, "requires _ctypes")
def test_invalid_typecode(self):
with self.assertRaisesRegex(TypeError, 'bad typecode'):
self.Array('x', [])
with self.assertRaisesRegex(TypeError, 'bad typecode'):
self.RawArray('x', [])
#
#
#
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Improve the error message of :func:`multiprocessing.sharedctypes.Array`,
:func:`multiprocessing.sharedctypes.RawArray`, :func:`multiprocessing.sharedctypes.Value` and
:func:`multiprocessing.sharedctypes.RawValue` when an invalid typecode is passed. Patch
by Tomas Roun
Loading