[pypy-svn] r22594 - in pypy/dist/pypy/rpython/rctypes: . test
gromit at codespeak.net
gromit at codespeak.net
Tue Jan 24 14:58:28 CET 2006
Author: gromit
Date: Tue Jan 24 14:58:26 2006
New Revision: 22594
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:
(stephan,gromit) ADD: Specialization support, some additional types at the interface.
Modified: pypy/dist/pypy/rpython/rctypes/implementation.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/implementation.py (original)
+++ pypy/dist/pypy/rpython/rctypes/implementation.py Tue Jan 24 14:58:26 2006
@@ -5,11 +5,14 @@
from ctypes import *
from ctypes import _FUNCFLAG_CDECL, _FUNCFLAG_STDCALL
from pypy.annotation.model import SomeInteger
+from pypy.rpython.lltypesystem.lltype import Signed
+
c_int.annotator_type = SomeInteger()
+c_int.ll_type = Signed
-class FunctionPointerAnnotation(object):
+class FunctionPointerTranslation(object):
def compute_result_annotation(self, *args_s):
"""
@@ -17,13 +20,20 @@
"""
return self.restype.annotator_type
+ def __hash__(self):
+ return id(self)
+
+ def specialize(self, hop):
+ return hop.llops.gencapicall(self.__name__, hop.args_v[1:],
+ resulttype=self.restype.ll_type, _callable=None)
+
class RCDLL(CDLL):
"""
This is the restricted version of ctypes' CDLL class.
"""
- class _CdeclFuncPtr(FunctionPointerAnnotation, CDLL._CdeclFuncPtr):
+ class _CdeclFuncPtr(FunctionPointerTranslation, CDLL._CdeclFuncPtr):
"""
A simple extension of ctypes function pointers that
implements a simple interface to the anotator.
@@ -37,7 +47,7 @@
This is the restricted version of ctypes' WINDLL class
"""
- class _StdcallFuncPtr(FunctionPointerAnnotation, WinDLL._StdcallFuncPtr):
+ class _StdcallFuncPtr(FunctionPointerTranslation, WinDLL._StdcallFuncPtr):
"""
A simple extension of ctypes function pointers that
implements a simple interface to the anotator.
Modified: pypy/dist/pypy/rpython/rctypes/interface.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/interface.py (original)
+++ pypy/dist/pypy/rpython/rctypes/interface.py Tue Jan 24 14:58:26 2006
@@ -1,5 +1,5 @@
from ctypes import _DLLS
-from implementation import RCDLL as CDLL, RWinDLL as WinDLL, c_int, c_char_p
+from implementation import RCDLL as CDLL, RWinDLL as WinDLL, c_int, c_char_p, c_char, POINTER
cdll = _DLLS( CDLL )
windll = _DLLS( WinDLL )
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 Tue Jan 24 14:58:26 2006
@@ -7,7 +7,7 @@
py.test.skip("this test needs ctypes installed")
else:
import sys
- from pypy.rpython.rctypes.interface import cdll, c_char_p, c_int
+ from pypy.rpython.rctypes.interface import cdll, c_char_p, c_int, c_char, POINTER
if sys.platform == 'win32':
mylib = cdll.LoadLibrary('msvcrt.dll')
elif sys.platform == 'linux2':
@@ -19,6 +19,7 @@
atoi = mylib.atoi
atoi.restype = c_int
atoi.argstype = [c_char_p]
+ atoi.argstype = [POINTER(c_char)]
def o_atoi(a):
return atoi(a)
mod.o_atoi = o_atoi
@@ -27,6 +28,7 @@
class Test_rctypes:
from pypy.annotation.annrpython import RPythonAnnotator
+ from pypy.translator.translator import TranslationContext
def test_simple(self):
@@ -34,8 +36,17 @@
res = o_atoi('42')
assert res == 42
- def inprogress_test_annotate_simple(self):
+ def test_annotate_simple(self):
a = self.RPythonAnnotator()
s = a.build_types(o_atoi, [str])
# result should be an integer
assert s.knowntype == int
+
+ def test_specialize_simple(self):
+ t = self.TranslationContext()
+ a = t.buildannotator()
+ s = a.build_types(o_atoi, [str])
+ # result should be an integer
+ assert s.knowntype == int
+ t.buildrtyper().specialize()
+ #d#t.view()
More information about the Pypy-commit
mailing list