[pypy-svn] r60121 - in pypy/branch/oo-jit/pypy/rpython: . lltypesystem lltypesystem/test

arigo at codespeak.net arigo at codespeak.net
Mon Nov 24 18:31:36 CET 2008


Author: arigo
Date: Mon Nov 24 18:31:35 2008
New Revision: 60121

Modified:
   pypy/branch/oo-jit/pypy/rpython/llinterp.py
   pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py
   pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
Log:
Remove 'rtyper' in ll2ctypes.  Replace it with a global
variable that contains the currently running LLInterpreter,
which is not bad.


Modified: pypy/branch/oo-jit/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/llinterp.py	(original)
+++ pypy/branch/oo-jit/pypy/rpython/llinterp.py	Mon Nov 24 18:31:35 2008
@@ -40,6 +40,8 @@
 class LLInterpreter(object):
     """ low level interpreter working with concrete values. """
 
+    current_interpreter = None
+
     def __init__(self, typer, tracing=True, exc_data_ptr=None,
                  malloc_check=True):
         self.bindings = {}
@@ -64,6 +66,8 @@
         retval = None
         self.traceback_frames = []
         old_frame_stack = self.frame_stack[:]
+        prev_interpreter = LLInterpreter.current_interpreter
+        LLInterpreter.current_interpreter = self
         try:
             try:
                 retval = llframe.eval()
@@ -86,6 +90,7 @@
                     self.tracer.dump(line + '\n')
                 raise
         finally:
+            LLInterpreter.current_interpreter = prev_interpreter
             assert old_frame_stack == self.frame_stack
             if self.tracer:
                 if retval is not None:

Modified: pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py	(original)
+++ pypy/branch/oo-jit/pypy/rpython/lltypesystem/ll2ctypes.py	Mon Nov 24 18:31:35 2008
@@ -52,7 +52,7 @@
 
 
 
-def build_ctypes_struct(rtyper, S, delayed_builders, max_n=None):
+def build_ctypes_struct(S, delayed_builders, max_n=None):
     def builder():
         # called a bit later to fill in _fields_
         # (to handle recursive structure pointers)
@@ -60,9 +60,9 @@
         for fieldname in S._names:
             FIELDTYPE = S._flds[fieldname]
             if max_n is not None and fieldname == S._arrayfld:
-                cls = get_ctypes_array_of_size(rtyper, FIELDTYPE, max_n)
+                cls = get_ctypes_array_of_size(FIELDTYPE, max_n)
             else:
-                cls = get_ctypes_type(rtyper, FIELDTYPE)
+                cls = get_ctypes_type(FIELDTYPE)
             fields.append((fieldname, cls))
         CStruct._fields_ = fields
 
@@ -78,7 +78,7 @@
             else:
                 if n is None:
                     raise TypeError("%r is variable-sized" % (S,))
-                biggercls = build_ctypes_struct(rtyper, S, None, n)
+                biggercls = build_ctypes_struct(S, None, n)
                 bigstruct = biggercls()
                 array = getattr(bigstruct, S._arrayfld)
                 if hasattr(array, 'length'):
@@ -86,20 +86,18 @@
                 return bigstruct
         _malloc = classmethod(_malloc)
 
-        _rtyper = rtyper
-
     CStruct.__name__ = 'ctypes_%s' % (S,)
     if max_n is not None:
-        CStruct._normalized_ctype = get_ctypes_type(rtyper, S)
+        CStruct._normalized_ctype = get_ctypes_type(S)
         builder()    # no need to be lazy here
     else:
         delayed_builders.append(builder)
     return CStruct
 
-def build_ctypes_array(rtyper, A, delayed_builders, max_n=0):
+def build_ctypes_array(A, delayed_builders, max_n=0):
     assert max_n >= 0
     ITEM = A.OF
-    ctypes_item = get_ctypes_type(rtyper, ITEM, delayed_builders)
+    ctypes_item = get_ctypes_type(ITEM, delayed_builders)
 
     class CArray(ctypes.Structure):
         if not A._hints.get('nolength'):
@@ -111,7 +109,7 @@
         def _malloc(cls, n=None):
             if not isinstance(n, int):
                 raise TypeError, "array length must be an int"
-            biggercls = get_ctypes_array_of_size(rtyper, A, n)
+            biggercls = get_ctypes_array_of_size(A, n)
             bigarray = biggercls()
             if hasattr(bigarray, 'length'):
                 bigarray.length = n
@@ -130,72 +128,67 @@
                 items = self._indexable(index)
             cobj = items[index]
             if isinstance(ITEM, lltype.ContainerType):
-                return ctypes2lltype(lltype.Ptr(ITEM), ctypes.pointer(cobj),
-                                     rtyper)
+                return ctypes2lltype(lltype.Ptr(ITEM), ctypes.pointer(cobj))
             else:
-                return ctypes2lltype(ITEM, cobj, rtyper)
+                return ctypes2lltype(ITEM, cobj)
 
         def _setitem(self, index, value, boundscheck=True):
             if boundscheck:
                 items = self.items
             else:
                 items = self._indexable(index)
-            cobj = lltype2ctypes(value, rtyper)
+            cobj = lltype2ctypes(value)
             items[index] = cobj
 
     CArray.__name__ = 'ctypes_%s*%d' % (A, max_n)
     if max_n > 0:
-        CArray._normalized_ctype = get_ctypes_type(rtyper, A)
+        CArray._normalized_ctype = get_ctypes_type(A)
     return CArray
 
-def get_ctypes_array_of_size(rtyper, FIELDTYPE, max_n):
+def get_ctypes_array_of_size(FIELDTYPE, max_n):
     if max_n > 0:
         # no need to cache the results in this case, because the exact
         # type is never seen - the array instances are cast to the
         # array's _normalized_ctype, which is always the same.
-        return build_ctypes_array(rtyper, FIELDTYPE, None, max_n)
+        return build_ctypes_array(FIELDTYPE, None, max_n)
     else:
-        return get_ctypes_type(rtyper, FIELDTYPE)
+        return get_ctypes_type(FIELDTYPE)
 
-def get_ctypes_type(rtyper, T, delayed_builders=None):
+def get_ctypes_type(T, delayed_builders=None):
     try:
         return _ctypes_cache[T]
     except KeyError:
-        try:
-            return _ctypes_cache[rtyper, T]
-        except KeyError:
-            toplevel = delayed_builders is None
-            if toplevel:
-                delayed_builders = []
-            cls = build_new_ctypes_type(rtyper, T, delayed_builders)
-            if (rtyper, T) not in _ctypes_cache:
-                _ctypes_cache[rtyper, T] = cls
-            else:
-                # check for buggy recursive structure logic
-                assert _ctypes_cache[rtyper, T] is cls
-            if toplevel:
-                complete_builders(delayed_builders)
-            return cls
+        toplevel = delayed_builders is None
+        if toplevel:
+            delayed_builders = []
+        cls = build_new_ctypes_type(T, delayed_builders)
+        if T not in _ctypes_cache:
+            _ctypes_cache[T] = cls
+        else:
+            # check for buggy recursive structure logic
+            assert _ctypes_cache[T] is cls
+        if toplevel:
+            complete_builders(delayed_builders)
+        return cls
 
-def build_new_ctypes_type(rtyper, T, delayed_builders):
+def build_new_ctypes_type(T, delayed_builders):
     if isinstance(T, lltype.Ptr):
         if isinstance(T.TO, lltype.FuncType):
-            argtypes = [get_ctypes_type(rtyper, ARG) for ARG in T.TO.ARGS
-                                                     if ARG is not lltype.Void]
+            argtypes = [get_ctypes_type(ARG) for ARG in T.TO.ARGS
+                                             if ARG is not lltype.Void]
             if T.TO.RESULT is lltype.Void:
                 restype = None
             else:
-                restype = get_ctypes_type(rtyper, T.TO.RESULT)
+                restype = get_ctypes_type(T.TO.RESULT)
             return ctypes.CFUNCTYPE(restype, *argtypes)
         else:
-            return ctypes.POINTER(get_ctypes_type(rtyper, T.TO,
-                                                  delayed_builders))
+            return ctypes.POINTER(get_ctypes_type(T.TO, delayed_builders))
     elif T is lltype.Void:
         return ctypes.c_long # opaque pointer
     elif isinstance(T, lltype.Struct):
-        return build_ctypes_struct(rtyper, T, delayed_builders)
+        return build_ctypes_struct(T, delayed_builders)
     elif isinstance(T, lltype.Array):
-        return build_ctypes_array(rtyper, T, delayed_builders)
+        return build_ctypes_array(T, delayed_builders)
     elif isinstance(T, lltype.OpaqueType):
         if T is lltype.RuntimeTypeInfo:
             return ctypes.c_char * 2
@@ -213,17 +206,17 @@
         delayed_builders.pop()()
 
 
-def convert_struct(rtyper, container, cstruct=None):
+def convert_struct(container, cstruct=None):
     STRUCT = container._TYPE
     if cstruct is None:
         # if 'container' is an inlined substructure, convert the whole
         # bigger structure at once
         parent, parentindex = lltype.parentlink(container)
         if parent is not None:
-            convert_struct(rtyper, parent)
+            convert_struct(parent)
             return
         # regular case: allocate a new ctypes Structure of the proper type
-        cls = get_ctypes_type(rtyper, STRUCT)
+        cls = get_ctypes_type(STRUCT)
         if STRUCT._arrayfld is not None:
             n = getattr(container, STRUCT._arrayfld).getlength()
         else:
@@ -236,15 +229,15 @@
         if not isinstance(FIELDTYPE, lltype.ContainerType):
             # regular field
             if FIELDTYPE != lltype.Void:
-                setattr(cstruct, field_name, lltype2ctypes(field_value, rtyper))
+                setattr(cstruct, field_name, lltype2ctypes(field_value))
         else:
             # inlined substructure/subarray
             if isinstance(FIELDTYPE, lltype.Struct):
                 csubstruct = getattr(cstruct, field_name)
-                convert_struct(rtyper, field_value, csubstruct)
+                convert_struct(field_value, csubstruct)
             elif field_name == STRUCT._arrayfld:    # inlined var-sized part
                 csubarray = getattr(cstruct, field_name)
-                convert_array(rtyper, field_value, csubarray)
+                convert_array(field_value, csubarray)
             else:
                 raise NotImplementedError('inlined field', FIELDTYPE)
     remove_regular_struct_content(container)
@@ -256,29 +249,29 @@
         if not isinstance(FIELDTYPE, lltype.ContainerType):
             delattr(container, field_name)
 
-def convert_array(rtyper, container, carray=None):
+def convert_array(container, carray=None):
     ARRAY = container._TYPE
     if carray is None:
         # if 'container' is an inlined substructure, convert the whole
         # bigger structure at once
         parent, parentindex = lltype.parentlink(container)
         if parent is not None:
-            convert_struct(rtyper, parent)
+            convert_struct(parent)
             return
         # regular case: allocate a new ctypes array of the proper type
-        cls = get_ctypes_type(rtyper, ARRAY)
+        cls = get_ctypes_type(ARRAY)
         carray = cls._malloc(container.getlength())
     add_storage(container, _array_mixin, carray)
     if not isinstance(ARRAY.OF, lltype.ContainerType):
         for i in range(container.getlength()):
             item_value = container.items[i]    # fish fish
-            carray.items[i] = lltype2ctypes(item_value, rtyper)
+            carray.items[i] = lltype2ctypes(item_value)
         remove_regular_array_content(container)
     else:
         assert isinstance(ARRAY.OF, lltype.Struct)
         for i in range(container.getlength()):
             item_ptr = container.items[i]    # fish fish
-            convert_struct(rtyper, item_ptr, carray.items[i])
+            convert_struct(item_ptr, carray.items[i])
 
 def remove_regular_array_content(container):
     for i in range(container.getlength()):
@@ -391,13 +384,13 @@
     def __getattr__(self, field_name):
         T = getattr(self._TYPE, field_name)
         cobj = getattr(self._storage, field_name)
-        return ctypes2lltype(T, cobj, self._storage._rtyper)
+        return ctypes2lltype(T, cobj)
 
     def __setattr__(self, field_name, value):
         if field_name.startswith('_'):
             object.__setattr__(self, field_name, value)  # '_xxx' attributes
         else:
-            cobj = lltype2ctypes(value, self._storage._rtyper)
+            cobj = lltype2ctypes(value)
             setattr(self._storage, field_name, cobj)
 
 class _array_mixin(_parentable_mixin):
@@ -450,36 +443,41 @@
 _opaque_cache = {Dummy():0}
 _opaque_list = [Dummy()]
 
-def new_opaque_object(rtyper, llobj):
+def new_opaque_object(llobj):
     try:
         return _opaque_cache[llobj]
     except KeyError:
         assert len(_opaque_cache) == len(_opaque_list)
-        ctypes_type = get_ctypes_type(rtyper, base_ptr_lltype())
+        ctypes_type = get_ctypes_type(base_ptr_lltype())
         val = ctypes.cast(len(_opaque_cache), ctypes_type)
         _opaque_list.append(llobj)
         _opaque_cache[llobj] = val
         return val
 
-def lltype2ctypes(llobj, rtyper, normalize=True):
+def get_rtyper():
+    llinterp = LLInterpreter.current_interpreter
+    if llinterp is not None:
+        return llinterp.typer
+    else:
+        return None
+
+def lltype2ctypes(llobj, normalize=True):
     """Convert the lltype object 'llobj' to its ctypes equivalent.
     'normalize' should only be False in tests, where we want to
     inspect the resulting ctypes object manually.
     """
     if isinstance(llobj, lltype._uninitialized):
-        return uninitialized2ctypes(llobj.TYPE, rtyper)
+        return uninitialized2ctypes(llobj.TYPE)
 
     T = lltype.typeOf(llobj)
     if isinstance(T, lltype.Ptr):
         if not llobj:   # NULL pointer
-            return get_ctypes_type(rtyper, T)()
+            return get_ctypes_type(T)()
 
         if T is base_ptr_lltype():
-            return new_opaque_object(rtyper, llobj)
+            return new_opaque_object(llobj)
         container = llobj._obj
         if isinstance(T.TO, lltype.FuncType):
-            if hasattr(container, 'graph'):
-                assert rtyper is not None
             v1voidlist = [(i, getattr(container, '_void' + str(i), None))
                              for i in range(len(T.TO.ARGS))
                                  if T.TO.ARGS[i] is lltype.Void]
@@ -493,16 +491,18 @@
                     if ARG is lltype.Void:
                         llargs.append(carg)
                     else:
-                        llargs.append(ctypes2lltype(ARG, carg, rtyper))
+                        llargs.append(ctypes2lltype(ARG, carg))
                 if hasattr(container, 'graph'):
-                    llinterp = LLInterpreter(rtyper)
+                    if LLInterpreter.current_interpreter is None:
+                        raise AssertionError
+                    llinterp = LLInterpreter.current_interpreter
                     llres = llinterp.eval_graph(container.graph, llargs)
                 else:
                     llres = container._callable(*llargs)
                 assert lltype.typeOf(llres) == T.TO.RESULT
                 if T.TO.RESULT is lltype.Void:
                     return None
-                res = lltype2ctypes(llres, rtyper)
+                res = lltype2ctypes(llres)
                 if isinstance(T.TO.RESULT, lltype.Ptr):
                     _all_callbacks.append(res)
                     res = ctypes.cast(res, ctypes.c_void_p).value
@@ -520,12 +520,12 @@
             if isinstance(T.TO.RESULT, lltype.Ptr):
                 TMod = lltype.Ptr(lltype.FuncType(T.TO.ARGS,
                                                   lltype.Signed))
-                ctypes_func_type = get_ctypes_type(rtyper, TMod)
+                ctypes_func_type = get_ctypes_type(TMod)
                 res = ctypes_func_type(callback)
-                ctypes_func_type = get_ctypes_type(rtyper, T)
+                ctypes_func_type = get_ctypes_type(T)
                 res = ctypes.cast(res, ctypes_func_type)
             else:
-                ctypes_func_type = get_ctypes_type(rtyper, T)
+                ctypes_func_type = get_ctypes_type(T)
                 res = ctypes_func_type(callback)
             _all_callbacks.append(res)
             _callback2obj[ctypes.cast(res, ctypes.c_void_p).value] = container
@@ -536,9 +536,9 @@
         if container._storage is True:
             # container has regular lltype storage, convert it to ctypes
             if isinstance(T.TO, lltype.Struct):
-                convert_struct(rtyper, container)
+                convert_struct(container)
             elif isinstance(T.TO, lltype.Array):
-                convert_array(rtyper, container)
+                convert_array(container)
             elif isinstance(T.TO, lltype.OpaqueType):
                 if T.TO != lltype.RuntimeTypeInfo:
                     cbuf = ctypes.create_string_buffer(T.TO.hints['getsize']())
@@ -556,8 +556,7 @@
 
     if isinstance(llobj, Symbolic):
         if isinstance(llobj, llmemory.ItemOffset):
-            llobj = ctypes.sizeof(get_ctypes_type(rtyper, llobj.TYPE)) \
-                      * llobj.repeat
+            llobj = ctypes.sizeof(get_ctypes_type(llobj.TYPE)) * llobj.repeat
         elif isinstance(llobj, ComputedIntSymbolic):
             llobj = llobj.compute_fn()
         else:
@@ -571,7 +570,7 @@
 
     return llobj
 
-def ctypes2lltype(T, cobj, rtyper):
+def ctypes2lltype(T, cobj):
     """Convert the ctypes object 'cobj' to its lltype equivalent.
     'T' is the expected lltype type.
     """
@@ -586,20 +585,16 @@
                 container = lltype._struct(T.TO, carray.length)
             else:
                 # special treatment of 'OBJECT' subclasses
-                if rtyper and lltype._castdepth(T.TO, OBJECT) > 0:
-                    ctypes_object = get_ctypes_type(rtyper,
-                                                    lltype.Ptr(OBJECT))
+                if get_rtyper() and lltype._castdepth(T.TO, OBJECT) > 0:
+                    ctypes_object = get_ctypes_type(lltype.Ptr(OBJECT))
                     as_obj = ctypes2lltype(lltype.Ptr(OBJECT),
-                                           ctypes.cast(cobj, ctypes_object),
-                                           rtyper)
-                    TObj = rtyper.get_type_for_typeptr(as_obj.typeptr)
+                                           ctypes.cast(cobj, ctypes_object))
+                    TObj = get_rtyper().get_type_for_typeptr(as_obj.typeptr)
                     if TObj != T.TO:
-                        ctypes_instance = get_ctypes_type(rtyper,
-                                                          lltype.Ptr(TObj))
+                        ctypes_instance = get_ctypes_type(lltype.Ptr(TObj))
                         return lltype.cast_pointer(T,
                             ctypes2lltype(lltype.Ptr(TObj),
-                                          ctypes.cast(cobj, ctypes_instance),
-                                          rtyper))
+                                          ctypes.cast(cobj, ctypes_instance)))
                 container = lltype._struct(T.TO)
             struct_use_ctypes_storage(container, cobj.contents)
         elif isinstance(T.TO, lltype.Array):
@@ -614,7 +609,7 @@
             if cobjkey in _callback2obj:
                 container = _callback2obj[cobjkey]
             else:
-                _callable = get_ctypes_trampoline(rtyper, T.TO, cobj)
+                _callable = get_ctypes_trampoline(T.TO, cobj)
                 return lltype.functionptr(T.TO, getattr(cobj, '__name__', '?'),
                                           _callable=_callable)
         elif isinstance(T.TO, lltype.OpaqueType):
@@ -651,9 +646,9 @@
     assert lltype.typeOf(llobj) == T
     return llobj
 
-def uninitialized2ctypes(T, rtyper):
+def uninitialized2ctypes(T):
     "For debugging, create a ctypes object filled with 0xDD."
-    ctype = get_ctypes_type(rtyper, T)
+    ctype = get_ctypes_type(T)
     cobj = ctype()
     size = ctypes.sizeof(cobj)
     p = ctypes.cast(ctypes.pointer(cobj),
@@ -682,7 +677,7 @@
 # ____________________________________________
 
 
-def get_ctypes_callable(rtyper, funcptr, calling_conv):
+def get_ctypes_callable(funcptr, calling_conv):
     if not ctypes:
         raise ImportError("ctypes is needed to use ll2ctypes")
 
@@ -736,35 +731,32 @@
             funcname, place))
 
     # get_ctypes_type() can raise NotImplementedError too
-    cfunc.argtypes = [get_ctypes_type(rtyper, T) for T in FUNCTYPE.ARGS
-                                                 if T is not lltype.Void]
+    cfunc.argtypes = [get_ctypes_type(T) for T in FUNCTYPE.ARGS
+                                         if T is not lltype.Void]
     if FUNCTYPE.RESULT is lltype.Void:
         cfunc.restype = None
     else:
-        cfunc.restype = get_ctypes_type(rtyper, FUNCTYPE.RESULT)
+        cfunc.restype = get_ctypes_type(FUNCTYPE.RESULT)
     return cfunc
 
 class LL2CtypesCallable(object):
     # a special '_callable' object that invokes ctypes
 
-    def __init__(self, FUNCTYPE, calling_conv, rtyper=None):
+    def __init__(self, FUNCTYPE, calling_conv):
         self.FUNCTYPE = FUNCTYPE
         self.calling_conv = calling_conv
         self.trampoline = None
-        self.rtyper = rtyper
         #self.funcptr = ...  set later
 
     def __call__(self, *argvalues):
         if self.trampoline is None:
             # lazily build the corresponding ctypes function object
-            cfunc = get_ctypes_callable(self.rtyper, self.funcptr,
-                                        self.calling_conv)
-            self.trampoline = get_ctypes_trampoline(self.rtyper, self.FUNCTYPE,
-                                                    cfunc)
+            cfunc = get_ctypes_callable(self.funcptr, self.calling_conv)
+            self.trampoline = get_ctypes_trampoline(self.FUNCTYPE, cfunc)
         # perform the call
         return self.trampoline(*argvalues)
 
-def get_ctypes_trampoline(rtyper, FUNCTYPE, cfunc):
+def get_ctypes_trampoline(FUNCTYPE, cfunc):
     RESULT = FUNCTYPE.RESULT
     container_arguments = []
     for i in range(len(FUNCTYPE.ARGS)):
@@ -778,28 +770,28 @@
         cargs = []
         for i in range(len(FUNCTYPE.ARGS)):
             if i not in void_arguments:
-                cvalue = lltype2ctypes(argvalues[i], rtyper)
+                cvalue = lltype2ctypes(argvalues[i])
                 for i in container_arguments:
                     cvalue = cvalue.contents
                 cargs.append(cvalue)
         _restore_c_errno()
         cres = cfunc(*cargs)
         _save_c_errno()
-        return ctypes2lltype(RESULT, cres, rtyper)
+        return ctypes2lltype(RESULT, cres)
     return invoke_via_ctypes
 
-def force_cast(RESTYPE, value, rtyper=None):
+def force_cast(RESTYPE, value):
     """Cast a value to a result type, trying to use the same rules as C."""
     if not isinstance(RESTYPE, lltype.LowLevelType):
         raise TypeError("rffi.cast() first arg should be a TYPE")
     TYPE1 = lltype.typeOf(value)
-    cvalue = lltype2ctypes(value, rtyper)
-    cresulttype = get_ctypes_type(rtyper, RESTYPE)
+    cvalue = lltype2ctypes(value)
+    cresulttype = get_ctypes_type(RESTYPE)
     if isinstance(TYPE1, lltype.Ptr):
         if isinstance(RESTYPE, lltype.Ptr):
             # shortcut: ptr->ptr cast
             cptr = ctypes.cast(cvalue, cresulttype)
-            return ctypes2lltype(RESTYPE, cptr, rtyper)
+            return ctypes2lltype(RESTYPE, cptr)
         # first cast the input pointer to an integer
         cvalue = ctypes.cast(cvalue, ctypes.c_void_p).value
         if cvalue is None:
@@ -816,7 +808,7 @@
         cvalue = ctypes.cast(ctypes.c_void_p(cvalue), cresulttype)
     else:
         cvalue = cresulttype(cvalue).value   # mask high bits off if needed
-    return ctypes2lltype(RESTYPE, cvalue, rtyper)
+    return ctypes2lltype(RESTYPE, cvalue)
 
 class ForceCastEntry(ExtRegistryEntry):
     _about_ = force_cast
@@ -842,7 +834,7 @@
     assert isinstance(T.TO, lltype.Array)
     assert T.TO._hints.get('nolength')
 
-def force_ptradd(ptr, n, rtyper=None):
+def force_ptradd(ptr, n):
     """'ptr' must be a pointer to an array.  Equivalent of 'ptr + n' in
     C, i.e. gives a pointer to the n'th item of the array.  The type of
     the result is again a pointer to an array, the same as the type of
@@ -850,13 +842,13 @@
     """
     T = lltype.typeOf(ptr)
     typecheck_ptradd(T)
-    ctypes_item_type = get_ctypes_type(rtyper, T.TO.OF)
-    ctypes_arrayptr_type = get_ctypes_type(rtyper, T)
-    cptr = lltype2ctypes(ptr, rtyper)
+    ctypes_item_type = get_ctypes_type(T.TO.OF)
+    ctypes_arrayptr_type = get_ctypes_type(T)
+    cptr = lltype2ctypes(ptr)
     baseaddr = ctypes.addressof(cptr.contents.items)
     addr = baseaddr + n * ctypes.sizeof(ctypes_item_type)
     cptr = ctypes.cast(ctypes.c_void_p(addr), ctypes_arrayptr_type)
-    return ctypes2lltype(T, cptr, rtyper)
+    return ctypes2lltype(T, cptr)
 
 class ForcePtrAddEntry(ExtRegistryEntry):
     _about_ = force_ptradd

Modified: pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py	(original)
+++ pypy/branch/oo-jit/pypy/rpython/lltypesystem/test/test_ll2ctypes.py	Mon Nov 24 18:31:35 2008
@@ -18,51 +18,48 @@
 
     def setup_method(self, meth):
         ALLOCATED.clear()
-        self.rtyper = RPythonTyper(RPythonAnnotator())
 
     def test_primitive(self):
-        rtyper = self.rtyper
-        assert lltype2ctypes(5, rtyper) == 5
-        assert lltype2ctypes('?', rtyper) == ord('?')
-        assert lltype2ctypes('\xE0', rtyper) == 0xE0
-        assert lltype2ctypes(unichr(1234), rtyper) == 1234
-        assert ctypes2lltype(lltype.Signed, 5, rtyper) == 5
-        assert ctypes2lltype(lltype.Char, ord('a'), rtyper) == 'a'
-        assert ctypes2lltype(lltype.UniChar, ord(u'x'), rtyper) == u'x'
-        assert ctypes2lltype(lltype.Char, 0xFF, rtyper) == '\xFF'
-        assert lltype2ctypes(5.25, rtyper) == 5.25
-        assert ctypes2lltype(lltype.Float, 5.25, rtyper) == 5.25
-        assert lltype2ctypes(u'x', rtyper) == ord(u'x')
-        res = lltype2ctypes(rffi.r_singlefloat(-3.5), rtyper)
+        assert lltype2ctypes(5) == 5
+        assert lltype2ctypes('?') == ord('?')
+        assert lltype2ctypes('\xE0') == 0xE0
+        assert lltype2ctypes(unichr(1234)) == 1234
+        assert ctypes2lltype(lltype.Signed, 5) == 5
+        assert ctypes2lltype(lltype.Char, ord('a')) == 'a'
+        assert ctypes2lltype(lltype.UniChar, ord(u'x')) == u'x'
+        assert ctypes2lltype(lltype.Char, 0xFF) == '\xFF'
+        assert lltype2ctypes(5.25) == 5.25
+        assert ctypes2lltype(lltype.Float, 5.25) == 5.25
+        assert lltype2ctypes(u'x') == ord(u'x')
+        res = lltype2ctypes(rffi.r_singlefloat(-3.5))
         assert isinstance(res, ctypes.c_float)
         assert res.value == -3.5
-        res = ctypes2lltype(lltype.SingleFloat, ctypes.c_float(-3.5), rtyper)
+        res = ctypes2lltype(lltype.SingleFloat, ctypes.c_float(-3.5))
         assert isinstance(res, rffi.r_singlefloat)
         assert float(res) == -3.5
-        assert lltype2ctypes(rffi.r_ulong(-1), rtyper) == sys.maxint * 2 + 1
-        res = ctypes2lltype(lltype.Unsigned, sys.maxint * 2 + 1, rtyper)
+        assert lltype2ctypes(rffi.r_ulong(-1)) == sys.maxint * 2 + 1
+        res = ctypes2lltype(lltype.Unsigned, sys.maxint * 2 + 1)
         assert (res, type(res)) == (rffi.r_ulong(-1), rffi.r_ulong)
 
-        res = lltype2ctypes(llmemory.sizeof(lltype.Signed), rtyper)
+        res = lltype2ctypes(llmemory.sizeof(lltype.Signed))
         assert res == struct.calcsize("l")
         S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Signed))
-        res = lltype2ctypes(llmemory.sizeof(S), rtyper)
+        res = lltype2ctypes(llmemory.sizeof(S))
         assert res == struct.calcsize("ll")
 
         p = lltype.nullptr(S)
-        cptr = lltype2ctypes(p, rtyper)
+        cptr = lltype2ctypes(p)
         assert not cptr
         py.test.raises(ValueError, 'cptr.contents')   # NULL pointer access
-        res = ctypes2lltype(lltype.Ptr(S), cptr, rtyper)
+        res = ctypes2lltype(lltype.Ptr(S), cptr)
         assert res == p
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_simple_struct(self):
-        rtyper = self.rtyper
         S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Signed))
         s = lltype.malloc(S, flavor='raw')
         s.x = 123
-        sc = lltype2ctypes(s, rtyper)
+        sc = lltype2ctypes(s)
         assert isinstance(sc.contents, ctypes.Structure)
         assert sc.contents.x == 123
         sc.contents.x = 456
@@ -75,7 +72,6 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_struct_ptrs(self):
-        rtyper = self.rtyper
         S2 = lltype.Struct('S2', ('y', lltype.Signed))
         S1 = lltype.Struct('S', ('x', lltype.Signed), ('p', lltype.Ptr(S2)))
         s1 = lltype.malloc(S1, flavor='raw')
@@ -83,10 +79,10 @@
         s2b = lltype.malloc(S2, flavor='raw')
         s2a.y = ord('a')
         s2b.y = ord('b')
-        sc1 = lltype2ctypes(s1, rtyper)
+        sc1 = lltype2ctypes(s1)
         sc1.contents.x = 50
         assert s1.x == 50
-        sc1.contents.p = lltype2ctypes(s2a, rtyper)
+        sc1.contents.p = lltype2ctypes(s2a)
         assert s1.p == s2a
         s1.p.y -= 32
         assert sc1.contents.p.contents.y == ord('A')
@@ -99,13 +95,12 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_simple_array(self):
-        rtyper = self.rtyper
         A = lltype.Array(lltype.Signed)
         a = lltype.malloc(A, 10, flavor='raw')
         a[0] = 100
         a[1] = 101
         a[2] = 102
-        ac = lltype2ctypes(a, rtyper, normalize=False)
+        ac = lltype2ctypes(a, normalize=False)
         assert isinstance(ac.contents, ctypes.Structure)
         assert ac.contents.length == 10
         assert ac.contents.items[1] == 101
@@ -117,13 +112,12 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_array_nolength(self):
-        rtyper = self.rtyper
         A = lltype.Array(lltype.Signed, hints={'nolength': True})
         a = lltype.malloc(A, 10, flavor='raw')
         a[0] = 100
         a[1] = 101
         a[2] = 102
-        ac = lltype2ctypes(a, rtyper, normalize=False)
+        ac = lltype2ctypes(a, normalize=False)
         assert isinstance(ac.contents, ctypes.Structure)
         assert ac.contents.items[1] == 101
         ac.contents.items[2] = 456
@@ -135,9 +129,8 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_charp(self):
-        rtyper = self.rtyper
         s = rffi.str2charp("hello")
-        sc = lltype2ctypes(s, rtyper, normalize=False)
+        sc = lltype2ctypes(s, normalize=False)
         assert sc.contents.items[0] == ord('h')
         assert sc.contents.items[1] == ord('e')
         assert sc.contents.items[2] == ord('l')
@@ -153,14 +146,13 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_unicharp(self):
-        rtyper = self.rtyper
         SP = rffi.CArrayPtr(lltype.UniChar)
         s = lltype.malloc(SP.TO, 4, flavor='raw')
         s[0] = u'x'
         s[1] = u'y'
         s[2] = u'z'
         s[3] = u'\x00'
-        sc = lltype2ctypes(s, rtyper, normalize=False)
+        sc = lltype2ctypes(s, normalize=False)
         assert sc.contents.items[0] == ord(u'x')
         assert sc.contents.items[1] == ord(u'y')
         assert sc.contents.items[2] == ord(u'z')
@@ -203,13 +195,12 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_cstruct_to_ll(self):
-        rtyper = self.rtyper
         S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Signed))
         s = lltype.malloc(S, flavor='raw')
         s2 = lltype.malloc(S, flavor='raw')
         s.x = 123
-        sc = lltype2ctypes(s, rtyper)
-        t = ctypes2lltype(lltype.Ptr(S), sc, rtyper)
+        sc = lltype2ctypes(s)
+        t = ctypes2lltype(lltype.Ptr(S), sc)
         assert lltype.typeOf(t) == lltype.Ptr(S)
         assert s == t
         assert not (s != t)
@@ -233,15 +224,14 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_carray_to_ll(self):
-        rtyper = self.rtyper
         A = lltype.Array(lltype.Signed, hints={'nolength': True})
         a = lltype.malloc(A, 10, flavor='raw')
         a2 = lltype.malloc(A, 10, flavor='raw')
         a[0] = 100
         a[1] = 101
         a[2] = 110
-        ac = lltype2ctypes(a, rtyper)
-        b = ctypes2lltype(lltype.Ptr(A), ac, rtyper)
+        ac = lltype2ctypes(a)
+        b = ctypes2lltype(lltype.Ptr(A), ac)
         assert lltype.typeOf(b) == lltype.Ptr(A)
         assert b == a
         assert not (b != a)
@@ -327,24 +317,22 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_simple_cast(self):
-        rtyper = self.rtyper
-        assert rffi.cast(rffi.SIGNEDCHAR, 0x123456, rtyper) == 0x56
-        assert rffi.cast(rffi.SIGNEDCHAR, 0x123481, rtyper) == -127
-        assert rffi.cast(rffi.CHAR, 0x123456, rtyper) == '\x56'
-        assert rffi.cast(rffi.CHAR, 0x123481, rtyper) == '\x81'
-        assert rffi.cast(rffi.UCHAR, 0x123481, rtyper) == 0x81
+        assert rffi.cast(rffi.SIGNEDCHAR, 0x123456) == 0x56
+        assert rffi.cast(rffi.SIGNEDCHAR, 0x123481) == -127
+        assert rffi.cast(rffi.CHAR, 0x123456) == '\x56'
+        assert rffi.cast(rffi.CHAR, 0x123481) == '\x81'
+        assert rffi.cast(rffi.UCHAR, 0x123481) == 0x81
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_forced_ptr_cast(self):
         import array
-        rtyper = self.rtyper
         A = lltype.Array(lltype.Signed, hints={'nolength': True})
         B = lltype.Array(lltype.Char, hints={'nolength': True})
         a = lltype.malloc(A, 10, flavor='raw')
         for i in range(10):
             a[i] = i*i
 
-        b = rffi.cast(lltype.Ptr(B), a, rtyper)
+        b = rffi.cast(lltype.Ptr(B), a)
 
         checker = array.array('l')
         for i in range(10):
@@ -354,52 +342,49 @@
         for i in range(len(expected)):
             assert b[i] == expected[i]
 
-        c = rffi.cast(rffi.VOIDP, a, rtyper)
-        addr = lltype2ctypes(c, rtyper)
+        c = rffi.cast(rffi.VOIDP, a)
+        addr = lltype2ctypes(c)
         #assert addr == ctypes.addressof(a._obj._ctypes_storage)
-        d = ctypes2lltype(rffi.VOIDP, addr, rtyper)
+        d = ctypes2lltype(rffi.VOIDP, addr)
         assert lltype.typeOf(d) == rffi.VOIDP
         assert c == d
-        e = rffi.cast(lltype.Ptr(A), d, rtyper)
+        e = rffi.cast(lltype.Ptr(A), d)
         for i in range(10):
             assert e[i] == i*i
 
         c = lltype.nullptr(rffi.VOIDP.TO)
-        addr = rffi.cast(lltype.Signed, c, rtyper)
+        addr = rffi.cast(lltype.Signed, c)
         assert addr == 0
 
         lltype.free(a, flavor='raw')
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_funcptr1(self):
-        rtyper = self.rtyper
         def dummy(n):
             return n+1
 
         FUNCTYPE = lltype.FuncType([lltype.Signed], lltype.Signed)
-        cdummy = lltype2ctypes(llhelper(lltype.Ptr(FUNCTYPE), dummy),
-                               rtyper)
+        cdummy = lltype2ctypes(llhelper(lltype.Ptr(FUNCTYPE), dummy))
         assert isinstance(cdummy,
                           ctypes.CFUNCTYPE(ctypes.c_long, ctypes.c_long))
         res = cdummy(41)
         assert res == 42
-        lldummy = ctypes2lltype(lltype.Ptr(FUNCTYPE), cdummy, rtyper)
+        lldummy = ctypes2lltype(lltype.Ptr(FUNCTYPE), cdummy)
         assert lltype.typeOf(lldummy) == lltype.Ptr(FUNCTYPE)
         res = lldummy(41)
         assert res == 42
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_funcptr2(self):
-        rtyper = self.rtyper
         FUNCTYPE = lltype.FuncType([rffi.CCHARP], lltype.Signed)
         cstrlen = standard_c_lib.strlen
-        llstrlen = ctypes2lltype(lltype.Ptr(FUNCTYPE), cstrlen, rtyper)
+        llstrlen = ctypes2lltype(lltype.Ptr(FUNCTYPE), cstrlen)
         assert lltype.typeOf(llstrlen) == lltype.Ptr(FUNCTYPE)
         p = rffi.str2charp("hi there")
         res = llstrlen(p)
         assert res == 8
-        cstrlen2 = lltype2ctypes(llstrlen, rtyper)
-        cp = lltype2ctypes(p, rtyper)
+        cstrlen2 = lltype2ctypes(llstrlen)
+        cp = lltype2ctypes(p)
         assert cstrlen2.restype == ctypes.c_long
         res = cstrlen2(cp)
         assert res == 8
@@ -445,7 +430,6 @@
     # def test_signal(self):...
 
     def test_uninitialized2ctypes(self):
-        rtyper = self.rtyper
         # for now, uninitialized fields are filled with 0xDD in the ctypes data
         def checkobj(o, size):
             p = ctypes.cast(ctypes.c_void_p(ctypes.addressof(o)),
@@ -457,33 +441,32 @@
             res = struct.pack(fmt, v)
             assert res == "\xDD" * len(res)
 
-        checkval(uninitialized2ctypes(rffi.CHAR, rtyper), 'B')
-        checkval(uninitialized2ctypes(rffi.SHORT, rtyper), 'h')
-        checkval(uninitialized2ctypes(rffi.INT, rtyper), 'i')
-        checkval(uninitialized2ctypes(rffi.UINT, rtyper), 'I')
-        checkval(uninitialized2ctypes(rffi.LONGLONG, rtyper), 'q')
-        checkval(uninitialized2ctypes(rffi.DOUBLE, rtyper), 'd')
-        checkobj(uninitialized2ctypes(rffi.INTP, rtyper),
+        checkval(uninitialized2ctypes(rffi.CHAR), 'B')
+        checkval(uninitialized2ctypes(rffi.SHORT), 'h')
+        checkval(uninitialized2ctypes(rffi.INT), 'i')
+        checkval(uninitialized2ctypes(rffi.UINT), 'I')
+        checkval(uninitialized2ctypes(rffi.LONGLONG), 'q')
+        checkval(uninitialized2ctypes(rffi.DOUBLE), 'd')
+        checkobj(uninitialized2ctypes(rffi.INTP),
                  ctypes.sizeof(ctypes.c_void_p))
-        checkobj(uninitialized2ctypes(rffi.CCHARP, rtyper),
+        checkobj(uninitialized2ctypes(rffi.CCHARP),
                  ctypes.sizeof(ctypes.c_void_p))
 
         S = lltype.Struct('S', ('x', lltype.Signed), ('y', lltype.Signed))
         s = lltype.malloc(S, flavor='raw')
-        sc = lltype2ctypes(s, rtyper)
+        sc = lltype2ctypes(s)
         checkval(sc.contents.x, 'l')
         checkval(sc.contents.y, 'l')
         lltype.free(s, flavor='raw')
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_substructures(self):
-        rtyper = self.rtyper
         S1  = lltype.Struct('S1', ('x', lltype.Signed))
         BIG = lltype.Struct('BIG', ('s1a', S1), ('s1b', S1))
         s = lltype.malloc(BIG, flavor='raw')
         s.s1a.x = 123
         s.s1b.x = 456
-        sc = lltype2ctypes(s, rtyper)
+        sc = lltype2ctypes(s)
         assert sc.contents.s1a.x == 123
         assert sc.contents.s1b.x == 456
         sc.contents.s1a.x += 1
@@ -497,9 +480,9 @@
         lltype.free(s, flavor='raw')
 
         s = lltype.malloc(BIG, flavor='raw')
-        s1ac = lltype2ctypes(s.s1a, rtyper)
+        s1ac = lltype2ctypes(s.s1a)
         s1ac.contents.x = 53
-        sc = lltype2ctypes(s, rtyper)
+        sc = lltype2ctypes(s)
         assert sc.contents.s1a.x == 53
         sc.contents.s1a.x += 1
         assert s1ac.contents.x == 54
@@ -511,14 +494,14 @@
         assert s1ac.contents.x == 59
         assert s.s1a.x == 59
 
-        t = ctypes2lltype(lltype.Ptr(BIG), sc, rtyper)
+        t = ctypes2lltype(lltype.Ptr(BIG), sc)
         assert t == s
         assert t.s1a == s.s1a
         assert t.s1a.x == 59
         s.s1b.x = 8888
         assert t.s1b == s.s1b
         assert t.s1b.x == 8888
-        t1 = ctypes2lltype(lltype.Ptr(S1), s1ac, rtyper)
+        t1 = ctypes2lltype(lltype.Ptr(S1), s1ac)
         assert t.s1a == t1
         assert t1.x == 59
         t1.x += 1
@@ -527,7 +510,6 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_recursive_struct(self):
-        rtyper = self.rtyper
         SX = lltype.ForwardReference()
         S1 = lltype.Struct('S1', ('p', lltype.Ptr(SX)), ('x', lltype.Signed))
         SX.become(S1)
@@ -541,7 +523,7 @@
         s1.p = s2
         s2.p = s3
         s3.p = lltype.nullptr(S1)
-        sc1 = lltype2ctypes(s1, rtyper)
+        sc1 = lltype2ctypes(s1)
         sc2 = sc1.contents.p
         sc3 = sc2.contents.p
         assert not sc3.contents.p
@@ -559,7 +541,7 @@
         s1 = lltype.malloc(S1, flavor='raw')
         s1.x = 12
         s1.p = s1
-        sc1 = lltype2ctypes(s1, rtyper)
+        sc1 = lltype2ctypes(s1)
         assert sc1.contents.x == 12
         assert (ctypes.addressof(sc1.contents.p.contents) ==
                 ctypes.addressof(sc1.contents))
@@ -573,7 +555,7 @@
         s1.p = s2
         s2.x = 222
         s2.p = s1
-        sc1 = lltype2ctypes(s1, rtyper)
+        sc1 = lltype2ctypes(s1)
         assert sc1.contents.x == 111
         assert sc1.contents.p.contents.x == 222
         assert (ctypes.addressof(sc1.contents.p.contents) !=
@@ -585,7 +567,6 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_indirect_recursive_struct(self):
-        rtyper = self.rtyper
         S2Forward = lltype.ForwardReference()
         S1 = lltype.Struct('S1', ('p', lltype.Ptr(S2Forward)))
         A2 = lltype.Array(lltype.Ptr(S1), hints={'nolength': True})
@@ -597,7 +578,7 @@
         s2.a = a2
         a2[5] = s1
         s1.p = s2
-        ac2 = lltype2ctypes(a2, rtyper, normalize=False)
+        ac2 = lltype2ctypes(a2, normalize=False)
         sc1 = ac2.contents.items[5]
         sc2 = sc1.contents.p
         assert (ctypes.addressof(sc2.contents.a.contents) ==
@@ -608,7 +589,6 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_arrayofstruct(self):
-        rtyper = self.rtyper
         S1 = lltype.Struct('S1', ('x', lltype.Signed))
         A = lltype.Array(S1, hints={'nolength': True})
         a = lltype.malloc(A, 5, flavor='raw')
@@ -617,19 +597,18 @@
         a[2].x = 102
         a[3].x = 103
         a[4].x = 104
-        ac = lltype2ctypes(a, rtyper, normalize=False)
+        ac = lltype2ctypes(a, normalize=False)
         assert ac.contents.items[0].x == 100
         assert ac.contents.items[2].x == 102
         ac.contents.items[3].x += 500
         assert a[3].x == 603
         a[4].x += 600
         assert ac.contents.items[4].x == 704
-        a1 = ctypes2lltype(lltype.Ptr(A), ac, rtyper)
+        a1 = ctypes2lltype(lltype.Ptr(A), ac)
         assert a1 == a
         assert a1[2].x == 102
         aitem1 = ctypes2lltype(lltype.Ptr(S1),
-                               ctypes.pointer(ac.contents.items[1]),
-                               rtyper)
+                               ctypes.pointer(ac.contents.items[1]))
         assert aitem1.x == 101
         assert aitem1 == a1[1]
         lltype.free(a, flavor='raw')
@@ -672,12 +651,11 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_storage_stays_around(self):
-        rtyper = self.rtyper
         data = "hello, world!" * 100
         A = lltype.Array(rffi.CHAR, hints={'nolength': True})
         S = lltype.Struct('S', ('a', lltype.Ptr(A)))
         s = lltype.malloc(S, flavor='raw')
-        lltype2ctypes(s, rtyper)     # force it to escape
+        lltype2ctypes(s)     # force it to escape
         s.a = lltype.malloc(A, len(data), flavor='raw')
         # the storage for the array should not be freed by lltype even
         # though the _ptr object appears to go away here
@@ -690,16 +668,15 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_arrayoffloat(self):
-        rtyper = self.rtyper
         a = lltype.malloc(rffi.FLOATP.TO, 3, flavor='raw')
         a[0] = rffi.r_singlefloat(0.0)
         a[1] = rffi.r_singlefloat(1.1)
         a[2] = rffi.r_singlefloat(2.2)
-        ac = lltype2ctypes(a, rtyper, normalize=False)
+        ac = lltype2ctypes(a, normalize=False)
         assert ac.contents.items[0] == 0.0
         assert abs(ac.contents.items[1] - 1.1) < 1E-6
         assert abs(ac.contents.items[2] - 2.2) < 1E-6
-        b = ctypes2lltype(rffi.FLOATP, ac, rtyper)
+        b = ctypes2lltype(rffi.FLOATP, ac)
         assert isinstance(b[0], rffi.r_singlefloat)
         assert float(b[0]) == 0.0
         assert isinstance(b[1], rffi.r_singlefloat)
@@ -808,25 +785,23 @@
             assert a[i] == i + 1
 
     def test_array_type_bug(self):
-        rtyper = self.rtyper
         A = lltype.Array(lltype.Signed)
         a1 = lltype.malloc(A, 0, flavor='raw')
         a2 = lltype.malloc(A, 0, flavor='raw')
-        c1 = lltype2ctypes(a1, rtyper)
-        c2 = lltype2ctypes(a2, rtyper)
+        c1 = lltype2ctypes(a1)
+        c2 = lltype2ctypes(a2)
         assert type(c1) is type(c2)
         lltype.free(a1, flavor='raw')
         lltype.free(a2, flavor='raw')
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_varsized_struct(self):
-        rtyper = self.rtyper
         S = lltype.Struct('S', ('x', lltype.Signed),
                                ('a', lltype.Array(lltype.Char)))
         s1 = lltype.malloc(S, 6, flavor='raw')
         s1.x = 5
         s1.a[2] = 'F'
-        sc = lltype2ctypes(s1, rtyper, normalize=False)
+        sc = lltype2ctypes(s1, normalize=False)
         assert isinstance(sc.contents, ctypes.Structure)
         assert sc.contents.x == 5
         assert sc.contents.a.length == 6
@@ -836,7 +811,7 @@
         s1.a[1] = 'y'
         assert sc.contents.a.items[1] == ord('y')
         # now go back to lltype...
-        res = ctypes2lltype(lltype.Ptr(S), sc, rtyper)
+        res = ctypes2lltype(lltype.Ptr(S), sc)
         assert res == s1
         assert res.x == 5
         assert len(res.a) == 6
@@ -844,14 +819,13 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_with_explicit_length(self):
-        rtyper = self.rtyper
         A = lltype.Array(lltype.Signed)
         a1 = lltype.malloc(A, 5, flavor='raw')
         a1[0] = 42
-        c1 = lltype2ctypes(a1, rtyper, normalize=False)
+        c1 = lltype2ctypes(a1, normalize=False)
         assert c1.contents.length == 5
         assert c1.contents.items[0] == 42
-        res = ctypes2lltype(lltype.Ptr(A), c1, rtyper)
+        res = ctypes2lltype(lltype.Ptr(A), c1)
         assert res == a1
         assert len(res) == 5
         assert res[0] == 42
@@ -868,7 +842,6 @@
         assert not ALLOCATED     # detects memory leaks in the test
 
     def test_c_callback_with_void_arg_2(self):
-        rtyper = self.rtyper
         ftest = []
         def f(x):
             ftest.append(x)
@@ -876,10 +849,10 @@
         fn = lltype.functionptr(F, 'askjh', _callable=f, _void0=-5)
         fn(-5)
         assert ftest == [-5]
-        fn2 = lltype2ctypes(fn, rtyper)
+        fn2 = lltype2ctypes(fn)
         fn2()
         assert ftest == [-5, -5]
-        fn3 = ctypes2lltype(lltype.Ptr(F), fn2, rtyper)
+        fn3 = ctypes2lltype(lltype.Ptr(F), fn2)
         fn3(-5)
         assert ftest == [-5, -5, -5]
 



More information about the Pypy-commit mailing list