[pypy-svn] r54475 - in pypy/dist/pypy/lib: _ctypes app_test/ctypes_tests

arigo at codespeak.net arigo at codespeak.net
Tue May 6 14:25:06 CEST 2008


Author: arigo
Date: Tue May  6 14:25:05 2008
New Revision: 54475

Modified:
   pypy/dist/pypy/lib/_ctypes/array.py
   pypy/dist/pypy/lib/_ctypes/basics.py
   pypy/dist/pypy/lib/app_test/ctypes_tests/test_extra.py
Log:
Trivial fixes to "ctype * integer" variants.


Modified: pypy/dist/pypy/lib/_ctypes/array.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/array.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/array.py	Tue May  6 14:25:05 2008
@@ -191,6 +191,8 @@
 ARRAY_CACHE = {}
 
 def create_array_type(base, length):
+    if not isinstance(length, (int, long)):
+        raise TypeError("Can't multiply a ctypes type by a non-integer")
     if length < 0:
         raise ValueError("Array length must be >= 0")
     key = (base, length)

Modified: pypy/dist/pypy/lib/_ctypes/basics.py
==============================================================================
--- pypy/dist/pypy/lib/_ctypes/basics.py	(original)
+++ pypy/dist/pypy/lib/_ctypes/basics.py	Tue May  6 14:25:05 2008
@@ -72,6 +72,8 @@
         from _ctypes.array import create_array_type
         return create_array_type(self, other)
 
+    __rmul__ = __mul__
+
     def _is_pointer_like(self):
         return False
 

Modified: pypy/dist/pypy/lib/app_test/ctypes_tests/test_extra.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/ctypes_tests/test_extra.py	(original)
+++ pypy/dist/pypy/lib/app_test/ctypes_tests/test_extra.py	Tue May  6 14:25:05 2008
@@ -229,6 +229,14 @@
         # other working cases of from_param
         assert isinstance(c_void_p.from_param((c_int * 4)()), c_int*4)
 
+    def test_array_mul(self):
+        assert c_int * 10 == 10 * c_int == c_int * 10L == 10L * c_int
+        py.test.raises(TypeError, 'c_int * c_int')
+        py.test.raises(TypeError, 'c_int * (-1.5)')
+        py.test.raises(TypeError, 'c_int * "foo"')
+        py.test.raises(TypeError, '(-1.5) * c_int')
+        py.test.raises(TypeError, '"foo" * c_int')
+
     def test_cast_none(self):
         def check(P):
             x = cast(None, P)



More information about the Pypy-commit mailing list