[pypy-svn] r36612 - in pypy/dist/pypy: annotation rpython rpython/module

fijal at codespeak.net fijal at codespeak.net
Fri Jan 12 19:30:39 CET 2007


Author: fijal
Date: Fri Jan 12 19:30:24 2007
New Revision: 36612

Modified:
   pypy/dist/pypy/annotation/signature.py
   pypy/dist/pypy/rpython/extfunc.py
   pypy/dist/pypy/rpython/module/ll_os.py
Log:
Wack a bit to get better feeling of declaring external functions.


Modified: pypy/dist/pypy/annotation/signature.py
==============================================================================
--- pypy/dist/pypy/annotation/signature.py	(original)
+++ pypy/dist/pypy/annotation/signature.py	Fri Jan 12 19:30:24 2007
@@ -24,6 +24,17 @@
 
     """The most precise SomeValue instance that contains all
     objects of type t."""
+    if isinstance(t, list):
+        assert len(t) == 1, "We do not support type joining in list"
+        listdef = ListDef(None, annotation(t[0]))
+        listdef.listitem.dont_change_any_more = False
+        return SomeList(listdef)
+    elif isinstance(t, tuple):
+        return SomeTuple(tuple([annotation(i) for i in t]))
+    elif isinstance(t, dict):
+        assert len(t) == 1, "We do not support type joining in dict"
+        return SomeDict(DictDef(None, annotation(t.keys()[0]),
+                                annotation(t.values()[0])))
     assert isinstance(t, (type, types.ClassType))
     if t is bool:
         return SomeBool()
@@ -40,15 +51,6 @@
     # can't do tuple
     elif t is types.NoneType:
         return s_None
-    elif isinstance(t, list):
-        assert len(t) == 1, "We do not support type joining in list"
-        return SomeList(ListDef(None, annotation(t[0])))
-    elif isinstance(t, tuple):
-        return SomeTuple(tuple([annotation(i) for i in t]))
-    elif isinstance(t, dict):
-        assert len(t) == 1, "We do not support type joining in dict"
-        return SomeDict(DictDef(None, annotation(t.keys()[0]),
-                                annotation(t.values()[0])))
     elif t in EXTERNAL_TYPE_ANALYZERS:
         return SomeExternalObject(t)
     elif bookkeeper and extregistry.is_registered_type(t, bookkeeper.policy):

Modified: pypy/dist/pypy/rpython/extfunc.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunc.py	(original)
+++ pypy/dist/pypy/rpython/extfunc.py	Fri Jan 12 19:30:24 2007
@@ -3,6 +3,7 @@
 from pypy.rpython.lltypesystem.lltype import typeOf
 from pypy.objspace.flow.model import Constant
 from pypy.annotation.model import unionof
+from pypy.annotation.signature import annotation
 
 class ExtFuncEntry(ExtRegistryEntry):
     def compute_result_annotation(self, *args_s):
@@ -31,3 +32,18 @@
         vlist = [hop.inputconst(typeOf(obj), obj)] + hop.inputargs(*args_r)
         hop.exception_is_here()
         return hop.genop('direct_call', vlist, r_result)
+
+def register_external(function, args, result, export_name=None,
+                      llimpl=None, ooimpl=None):
+    
+    class FunEntry(ExtFuncEntry):
+        _about_ = function
+        signature_args = [annotation(arg) for arg in args]
+        signature_result = annotation(result)
+        name=export_name
+        if llimpl:
+            lltypeimpl = llimpl
+        if ooimpl:
+            ootypeimpl = ooimpl
+
+    FunEntry.__name__ = export_name

Modified: pypy/dist/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_os.py	(original)
+++ pypy/dist/pypy/rpython/module/ll_os.py	Fri Jan 12 19:30:24 2007
@@ -20,7 +20,7 @@
 from pypy.rlib.rarithmetic import r_longlong
 from pypy.tool.staticmethods import ClassMethods
 import stat
-from pypy.rpython.extfunc import ExtFuncEntry
+from pypy.rpython.extfunc import ExtFuncEntry, register_external
 from pypy.annotation.model import SomeString, SomeInteger, s_ImpossibleValue, \
     s_None
 from pypy.annotation.listdef import s_list_of_strings
@@ -35,26 +35,23 @@
     os_execv.argtypes = [ctypes.c_char_p, ctypes.POINTER(ctypes.c_char_p)]
     os_execv.restype = ctypes.c_int
 
-    class ExecvFuncEntry(ExtFuncEntry):
-        _about_ = os.execv
-        name = "ll_os.ll_os_execv"
-        signature_args = [SomeString(), s_list_of_strings]
-        signature_result = s_ImpossibleValue
-
-        def lltypeimpl(path, args):
-            # XXX incredible code to work around rctypes limitations
-            length = len(args) + 1
-            num_bytes = ctypes.sizeof(ctypes.c_char_p) * length
-            buffer = ctypes.create_string_buffer(num_bytes)
-            array = ctypes.cast(buffer, ctypes.POINTER(ctypes.c_char_p))
-            buffer_addr = ctypes.cast(buffer, ctypes.c_void_p).value
-            for num in range(len(args)):
-                adr1 = buffer_addr + ctypes.sizeof(ctypes.c_char_p) * num
-                ptr = ctypes.c_void_p(adr1)
-                arrayitem = ctypes.cast(ptr, ctypes.POINTER(ctypes.c_char_p))
-                arrayitem[0] = args[num]
-            os_execv(path, array)
-            raise OSError(geterrno(), "execv failed")
+    def execv_lltypeimpl(path, args):
+        # XXX incredible code to work around rctypes limitations
+        length = len(args) + 1
+        num_bytes = ctypes.sizeof(ctypes.c_char_p) * length
+        buffer = ctypes.create_string_buffer(num_bytes)
+        array = ctypes.cast(buffer, ctypes.POINTER(ctypes.c_char_p))
+        buffer_addr = ctypes.cast(buffer, ctypes.c_void_p).value
+        for num in range(len(args)):
+            adr1 = buffer_addr + ctypes.sizeof(ctypes.c_char_p) * num
+            ptr = ctypes.c_void_p(adr1)
+            arrayitem = ctypes.cast(ptr, ctypes.POINTER(ctypes.c_char_p))
+            arrayitem[0] = args[num]
+        os_execv(path, array)
+        raise OSError(geterrno(), "execv failed")
+
+    register_external(os.execv, [str, [str]], s_ImpossibleValue, llimpl=
+                      execv_lltypeimpl, export_name="ll_os.ll_os_execv")
 
 os_dup = libc.dup
 os_dup.argtypes = [ctypes.c_int]



More information about the Pypy-commit mailing list