[pypy-svn] r22727 - pypy/dist/pypy/rpython/rctypes/test
gromit at codespeak.net
gromit at codespeak.net
Fri Jan 27 13:57:06 CET 2006
Author: gromit
Date: Fri Jan 27 13:57:04 2006
New Revision: 22727
Modified:
pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
Log:
ADD: A test that treats pointers like arrays.
Modified: pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py (original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py Fri Jan 27 13:57:04 2006
@@ -107,6 +107,7 @@
return c_float( a + 10 )
c_int_10 = ARRAY(c_int,10)
+c_int_p_test = POINTER(c_int)
def py_test_annotate_array():
return c_int_10()
@@ -118,6 +119,17 @@
return my_array[0]
+def py_test_annotate_pointer_content():
+ # Never run this function!
+ # See test_annotate_pointer_access_as_array_or_whatever
+ # for the weird reasons why this gets annotated
+ my_pointer = c_int_p_test(10)
+ my_pointer[0] = c_int(1)
+ my_pointer[1] = 2
+
+ return my_pointer[0]
+
+
class Test_rctypes:
def test_simple(self):
@@ -234,6 +246,9 @@
s = a.build_types(py_test_simple_ctypes_non_const,[])
assert s.knowntype == c_float
+
+class Test_array:
+
def test_annotate_array(self):
a = RPythonAnnotator()
s = a.build_types(py_test_annotate_array,[])
@@ -246,3 +261,19 @@
assert s.knowntype == int
#d#t.view()
+ def test_annotate_pointer_access_as_array(self):
+ """
+ Make sure that pointers work the same way as arrays, for
+ ctypes compatibility.
+
+ :Note: This works because pointer and array classes both
+ have a _type_ attribute, that contains the type of the
+ object pointed to or in the case of an array the element type.
+ """
+ t = TranslationContext()
+ a = t.buildannotator()
+ s = a.build_types(py_test_annotate_pointer_content,[])
+ assert s.knowntype == int
+ #t#t.view()
+
+
More information about the Pypy-commit
mailing list