[pypy-svn] r22650 - in pypy/dist/pypy: annotation rpython/rctypes rpython/rctypes/test
stephan at codespeak.net
stephan at codespeak.net
Wed Jan 25 15:55:05 CET 2006
Author: stephan
Date: Wed Jan 25 15:55:01 2006
New Revision: 22650
Modified:
pypy/dist/pypy/annotation/unaryop.py
pypy/dist/pypy/rpython/rctypes/implementation.py
pypy/dist/pypy/rpython/rctypes/interface.py
pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
Log:
ctypes byref function is annotated
Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py (original)
+++ pypy/dist/pypy/annotation/unaryop.py Wed Jan 25 15:55:01 2006
@@ -628,7 +628,7 @@
def getattr(cto, s_attr):
if s_attr.is_constant() and isinstance(s_attr.const, str):
attr = s_attr.const
- atype = cto.knowntype._fielddef_[attr]
+ atype = cto.knowntype._fields_def_[attr]
try:
return atype.annotator_type
except AttributeError:
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 15:55:01 2006
@@ -10,7 +10,6 @@
from pypy.annotation.model import SomeInteger, SomeCTypesObject
from pypy.rpython.lltypesystem.lltype import Signed
-
c_int.annotator_type = SomeInteger()
c_int.ll_type = Signed
c_char_p.annotator_type = None
@@ -61,7 +60,7 @@
if _fields is not None:
for attr, atype in _fields:
_adict[attr] = atype
- clsdict['_fielddef_'] = _adict
+ clsdict['_fields_def_'] = _adict
return super(RStructureMeta,mta).__new__(mta, name, bases, clsdict)
@@ -80,6 +79,23 @@
return SomeCTypesObject(cls)
compute_result_annotation = classmethod(compute_result_annotation)
+class RByrefObj(object):
+
+ def __init__(self):
+ self.__name__ = 'RByrefObj'
+
+ def compute_result_annotation(cls, s_arg):
+ """
+ Answer the result annotation of calling 'byref'.
+ """
+ return SomeCTypesObject(POINTER(s_arg.knowntype))
+
+ compute_result_annotation = classmethod(compute_result_annotation)
+
+ def __call__(self,obj):
+ return byref(obj)
+
+RByref = RByrefObj()
class RCDLL(CDLL):
"""
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 15:55:01 2006
@@ -1,5 +1,6 @@
from ctypes import _DLLS
-from implementation import RCDLL as CDLL, c_int, c_char_p, c_char, POINTER, RStructure as Structure, byref
+from implementation import RCDLL as CDLL, c_int, c_char_p, c_char, POINTER, \
+ RStructure as Structure, RByref as byref
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 15:55:01 2006
@@ -29,6 +29,7 @@
return atoi(a)
mod.o_atoi = o_atoi
mod.cdll = cdll
+
class tagpoint(Structure):
_fields_ = [("x", c_int),
("y", c_int)]
@@ -43,6 +44,19 @@
else:
_rctypes_test = cdll.LoadLibrary("_rctypes_test.so")
+ # _testfunc_byval
+ testfunc_byval = _rctypes_test._testfunc_byval
+ testfunc_byval.restype = c_int
+ testfunc_byval.argtypes = [tagpoint,POINTER(tagpoint)]
+
+ def py_testfunc_byval(inpoint):
+ opoint = tagpoint()
+ res = testfunc_byval(inpoint,byref(opoint))
+
+ return res, opoint
+
+ mod.py_testfunc_byval = py_testfunc_byval
+
# _test_struct
testfunc_struct = _rctypes_test._testfunc_struct
testfunc_struct.restype = c_int
@@ -143,3 +157,11 @@
s = a.build_types(py_create_point,[])
assert s.knowntype == int
+ def test_annotate_byval(self):
+ a = RPythonAnnotator()
+ s = a.build_types(py_testfunc_byval,[tagpoint])
+ assert s.knowntype == tuple
+ assert len(s.items) == 2
+ assert s.items[0].knowntype == int
+ assert s.items[1].knowntype == tagpoint
+
More information about the Pypy-commit
mailing list