mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
ctypes callback functions only support 'fundamental' result types.
Check this and raise an error when something else is used - before this change ctypes would hang or crash when such a callback was called. This is a partial fix for #1574584. Will backport to release25-maint.
This commit is contained in:
parent
fefbc2029c
commit
d2ea4a2584
3 changed files with 22 additions and 2 deletions
|
@ -101,6 +101,19 @@ class Callbacks(unittest.TestCase):
|
|||
after = grc(o)
|
||||
self.failUnlessEqual((after, o), (before, o))
|
||||
|
||||
def test_unsupported_restype_1(self):
|
||||
# Only "fundamental" result types are supported for callback
|
||||
# functions, the type must have a non-NULL stgdict->setfunc.
|
||||
# POINTER(c_double), for example, is not supported.
|
||||
|
||||
prototype = self.functype.im_func(POINTER(c_double))
|
||||
# The type is checked when the prototype is called
|
||||
self.assertRaises(TypeError, prototype, lambda: None)
|
||||
|
||||
def test_unsupported_restype_2(self):
|
||||
prototype = self.functype.im_func(object)
|
||||
self.assertRaises(TypeError, prototype, lambda: None)
|
||||
|
||||
try:
|
||||
WINFUNCTYPE
|
||||
except NameError:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue