self.assertEqual(len(ws_typ), 0, ws_typ)
self.assertEqual(len(ws_ptr), 0, ws_ptr)
+ def test_pointer_proto_missing_argtypes_error(self):
+ class BadType(ctypes._Pointer):
+ # _type_ is intentionally missing
+ pass
+
+ func = ctypes.pythonapi.Py_GetVersion
+ func.argtypes = (BadType,)
+
+ with self.assertRaises(ctypes.ArgumentError):
+ func(object())
class PointerTypeCacheTestCase(unittest.TestCase):
# dummy tests to check warnings and base behavior
--- /dev/null
+Fixed a crash in ctypes when using a deprecated ``POINTER(str)`` type in
+``argtypes``. Instead of aborting, ctypes now raises a proper Python
+exception when the pointer target type is unresolved.
/* If we expect POINTER(<type>), but receive a <type> instance, accept
it by calling byref(<type>).
*/
- assert(typeinfo->proto);
+ if (typeinfo->proto == NULL) {
+ PyErr_SetString(
+ PyExc_TypeError,
+ "cannot convert argument: POINTER _type_ type is not set"
+ );
+ return NULL;
+ }
switch (PyObject_IsInstance(value, typeinfo->proto)) {
case 1:
Py_INCREF(value); /* _byref steals a refcount */