[pypy-svn] r22654 - in pypy/dist/pypy/rpython/rctypes: . test
gromit at codespeak.net
gromit at codespeak.net
Wed Jan 25 16:40:40 CET 2006
Author: gromit
Date: Wed Jan 25 16:40:37 2006
New Revision: 22654
Modified:
pypy/dist/pypy/rpython/rctypes/implementation.py
pypy/dist/pypy/rpython/rctypes/interface.py
pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
Log:
ADD: (stephan,gromit) annotation of rcytpes' pointers
Modified: pypy/dist/pypy/rpython/rctypes/implementation.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/implementation.py (original)
+++ pypy/dist/pypy/rpython/rctypes/implementation.py Wed Jan 25 16:40:37 2006
@@ -97,6 +97,19 @@
RByref = RByrefObj()
+
+def RPOINTER(cls):
+ answer = POINTER(cls)
+ def compute_result_annotation(cls, s_arg):
+ """
+ Answer the result annotation of calling 'cls'.
+ """
+ assert answer is cls
+ return SomeCTypesObject(cls)
+ answer.compute_result_annotation = classmethod(compute_result_annotation)
+ return answer
+
+
class RCDLL(CDLL):
"""
This is the restricted version of ctypes' CDLL class.
Modified: pypy/dist/pypy/rpython/rctypes/interface.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/interface.py (original)
+++ pypy/dist/pypy/rpython/rctypes/interface.py Wed Jan 25 16:40:37 2006
@@ -1,6 +1,6 @@
from ctypes import _DLLS
-from implementation import RCDLL as CDLL, c_int, c_char_p, c_char, POINTER, \
- RStructure as Structure, RByref as byref
+from implementation import RCDLL as CDLL, c_int, c_char_p, c_char, \
+ RStructure as Structure, RByref as byref, RPOINTER as POINTER
try:
from implementation import RWinDLL as WinDLL
except ImportError:
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 Wed Jan 25 16:40:37 2006
@@ -85,6 +85,16 @@
mod.py_create_point = py_create_point
+ oppoint_type = POINTER(tagpoint)
+ def py_testfunc_POINTER(inpoint):
+ point = tagpoint()
+ oppoint = oppoint_type(point)
+ res = testfunc_byval(inpoint,oppoint)
+ return res, oppoint
+
+ mod.py_testfunc_POINTER = py_testfunc_POINTER
+ mod.POINTER = POINTER
+
class Test_rctypes:
@@ -165,3 +175,11 @@
assert s.items[0].knowntype == int
assert s.items[1].knowntype == tagpoint
+ def test_annotate_POINTER(self):
+ a = RPythonAnnotator()
+ s = a.build_types(py_testfunc_POINTER,[tagpoint])
+ assert s.knowntype == tuple
+ assert len(s.items) == 2
+ assert s.items[0].knowntype == int
+ assert s.items[1].knowntype == POINTER(tagpoint)
+
More information about the Pypy-commit
mailing list