Commits

Antonio Cuni  committed e6043c6

test and fix for issue807

  • Participants
  • Parent commits ca9f485

Comments (0)

Files changed (2)

File lib-python/modified-2.7/ctypes/__init__.py

     return CFunctionType
 
 def cast(obj, typ):
+    try:
+        c_void_p.from_param(obj)
+    except TypeError, e:
+        raise ArgumentError(str(e))
     return _cast_addr(obj, obj, typ)
 
 _string_at = PYFUNCTYPE(py_object, c_void_p, c_int)(_string_at_addr)

File pypy/module/test_lib_pypy/ctypes_tests/test_cast.py

         assert sqrt._objects is my_sqrt._objects   # on CPython too
         my_sqrt._objects.clear()
         my_sqrt._objects.update(saved_objects)
+
+    def test_cast_argumenterror(self):
+        param = c_uint(42)
+        py.test.raises(ArgumentError, "cast(param, c_void_p)")
+