[pypy-commit] pypy ffi-backend: First round of translation fixes.

arigo noreply at buildbot.pypy.org
Fri Jul 6 16:32:22 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: ffi-backend
Changeset: r55937:ed5f7dd15456
Date: 2012-07-06 16:32 +0200
http://bitbucket.org/pypy/pypy/changeset/ed5f7dd15456/

Log:	First round of translation fixes.

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1033,6 +1033,10 @@
         w_meth = self.getattr(w_obj, self.wrap(methname))
         return self.call_function(w_meth, *arg_w)
 
+    def raise_key_error(self, w_key):
+        e = self.call_function(self.w_KeyError, w_key)
+        raise OperationError(self.w_KeyError, e)
+
     def lookup(self, w_obj, name):
         w_type = self.type(w_obj)
         w_mro = self.getattr(w_type, self.wrap("__mro__"))
diff --git a/pypy/module/_cffi_backend/ccallback.py b/pypy/module/_cffi_backend/ccallback.py
--- a/pypy/module/_cffi_backend/ccallback.py
+++ b/pypy/module/_cffi_backend/ccallback.py
@@ -14,6 +14,7 @@
 
 
 class W_CDataCallback(W_CDataApplevelOwning):
+    _immutable_ = True
     ll_error = lltype.nullptr(rffi.CCHARP.TO)
 
     def __init__(self, space, ctype, w_callable, w_error):
diff --git a/pypy/module/_cffi_backend/cdataobj.py b/pypy/module/_cffi_backend/cdataobj.py
--- a/pypy/module/_cffi_backend/cdataobj.py
+++ b/pypy/module/_cffi_backend/cdataobj.py
@@ -189,6 +189,7 @@
     """This is the abstract base class for classes that are of the app-level
     type '_cffi_backend.CDataOwn'.  These are weakrefable."""
     _attrs_ = []
+    _immutable_ = True
 
     def _owning_num_bytes(self):
         return self.ctype.size
@@ -202,6 +203,7 @@
     """This is the class used for the app-level type
     '_cffi_backend.CDataOwn' created by newp()."""
     _attrs_ = []
+    _immutable_ = True
 
     def __init__(self, space, size, ctype):
         cdata = lltype.malloc(rffi.CCHARP.TO, size, flavor='raw', zero=True)
@@ -216,6 +218,7 @@
     """Subclass with an explicit length, for allocated instances of
     the C type 'foo[]'."""
     _attrs_ = ['length']
+    _immutable_ = True
 
     def __init__(self, space, size, ctype, length):
         W_CDataNewOwning.__init__(self, space, size, ctype)
@@ -230,6 +233,7 @@
     It has a strong reference to a W_CDataNewOwning that really owns the
     struct, which is the object returned by the app-level expression 'p[0]'."""
     _attrs_ = ['structobj']
+    _immutable_ = True
 
     def __init__(self, space, cdata, ctype, structobj):
         W_CDataApplevelOwning.__init__(self, space, cdata, ctype)
@@ -251,6 +255,7 @@
     small bits of memory (e.g. just an 'int').  Its point is to not be
     a subclass of W_CDataApplevelOwning."""
     _attrs_ = []
+    _immutable_ = True
 
     def __init__(self, space, size, ctype):
         cdata = lltype.malloc(rffi.CCHARP.TO, size, flavor='raw', zero=True)
diff --git a/pypy/module/_cffi_backend/ctypeenum.py b/pypy/module/_cffi_backend/ctypeenum.py
--- a/pypy/module/_cffi_backend/ctypeenum.py
+++ b/pypy/module/_cffi_backend/ctypeenum.py
@@ -4,7 +4,7 @@
 
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.rpython.lltypesystem import rffi
-from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import intmask, r_ulonglong
 from pypy.rlib.objectmodel import keepalive_until_here
 
 from pypy.module._cffi_backend.ctypeprim import W_CTypePrimitiveSigned
@@ -60,6 +60,7 @@
                 raise
         if space.isinstance_w(w_ob, space.w_str):
             value = self.convert_enum_string_to_int(space.str_w(w_ob))
+            value = r_ulonglong(value)
             misc.write_raw_integer_data(cdata, value, self.size)
         else:
             raise self._convert_error("str or int", w_ob)
diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py
--- a/pypy/module/_cffi_backend/ctypeprim.py
+++ b/pypy/module/_cffi_backend/ctypeprim.py
@@ -40,8 +40,10 @@
         if (isinstance(ob, cdataobj.W_CData) and
                isinstance(ob.ctype, ctypeptr.W_CTypePtrOrArray)):
             value = rffi.cast(lltype.Signed, ob._cdata)
+            value = r_ulonglong(value)
         elif space.isinstance_w(w_ob, space.w_str):
             value = self.cast_str(w_ob)
+            value = r_ulonglong(value)
         else:
             value = misc.as_unsigned_long_long(space, w_ob, strict=False)
         w_cdata = cdataobj.W_CDataCasted(space, self.size, self)
@@ -117,6 +119,7 @@
         if self.size < rffi.sizeof(lltype.SignedLongLong):
             if r_ulonglong(value) - self.vmin > self.vrangemax:
                 self._overflow(w_ob)
+        value = r_ulonglong(value)
         misc.write_raw_integer_data(cdata, value, self.size)
 
 
diff --git a/pypy/module/_cffi_backend/ctypestruct.py b/pypy/module/_cffi_backend/ctypestruct.py
--- a/pypy/module/_cffi_backend/ctypestruct.py
+++ b/pypy/module/_cffi_backend/ctypestruct.py
@@ -133,7 +133,8 @@
 
     def _check_only_one_argument_for_union(self, w_ob):
         space = self.space
-        if space.int_w(space.len(w_ob)) > 1:
+        n = space.int_w(space.len(w_ob))
+        if n > 1:
             raise operationerrfmt(space.w_ValueError,
                                   "initializer for '%s': %d items given, but "
                                   "only one supported (use a dict if needed)",
diff --git a/pypy/module/_cffi_backend/func.py b/pypy/module/_cffi_backend/func.py
--- a/pypy/module/_cffi_backend/func.py
+++ b/pypy/module/_cffi_backend/func.py
@@ -43,7 +43,7 @@
         if size < 0:
             raise operationerrfmt(space.w_ValueError,
                                   "ctype '%s' is of unknown size",
-                                  w_ctype.name)
+                                  ob.name)
     else:
         raise OperationError(space.w_TypeError,
                             space.wrap("expected a 'cdata' or 'ctype' object"))
diff --git a/pypy/module/_cffi_backend/newtype.py b/pypy/module/_cffi_backend/newtype.py
--- a/pypy/module/_cffi_backend/newtype.py
+++ b/pypy/module/_cffi_backend/newtype.py
@@ -2,11 +2,13 @@
 from pypy.interpreter.gateway import unwrap_spec
 from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.rlib.rarithmetic import ovfcheck
+from pypy.rlib.objectmodel import specialize
 
 from pypy.module._cffi_backend import ctypeobj, ctypeprim, ctypeptr, ctypearray
 from pypy.module._cffi_backend import ctypestruct, ctypevoid, ctypeenum
 
 
+ at specialize.memo()
 def alignment(TYPE):
     S = lltype.Struct('aligncheck', ('x', lltype.Char), ('y', TYPE))
     return rffi.offsetof(S, 'y')
diff --git a/pypy/module/_cffi_backend/test/test_ztranslation.py b/pypy/module/_cffi_backend/test/test_ztranslation.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_cffi_backend/test/test_ztranslation.py
@@ -0,0 +1,4 @@
+from pypy.objspace.fake.checkmodule import checkmodule
+
+def test_checkmodule():
+    checkmodule('_cffi_backend')
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -601,10 +601,6 @@
         else:
             return ObjSpace.call_method(self, w_obj, methname, *arg_w)
 
-    def raise_key_error(self, w_key):
-        e = self.call_function(self.w_KeyError, w_key)
-        raise OperationError(self.w_KeyError, e)
-
     def _type_issubtype(self, w_sub, w_type):
         if isinstance(w_sub, W_TypeObject) and isinstance(w_type, W_TypeObject):
             return self.wrap(w_sub.issubtype(w_type))
diff --git a/pypy/rpython/lltypesystem/llmemory.py b/pypy/rpython/lltypesystem/llmemory.py
--- a/pypy/rpython/lltypesystem/llmemory.py
+++ b/pypy/rpython/lltypesystem/llmemory.py
@@ -374,11 +374,14 @@
     return ItemOffset(TYPE)
 _sizeof_none._annspecialcase_ = 'specialize:memo'
 
+def _internal_array_field(TYPE):
+    return TYPE._arrayfld, TYPE._flds[TYPE._arrayfld]
+_internal_array_field._annspecialcase_ = 'specialize:memo'
+
 def _sizeof_int(TYPE, n):
-    "NOT_RPYTHON"
     if isinstance(TYPE, lltype.Struct):
-        return FieldOffset(TYPE, TYPE._arrayfld) + \
-               itemoffsetof(TYPE._flds[TYPE._arrayfld], n)
+        fldname, ARRAY = _internal_array_field(TYPE)
+        return offsetof(TYPE, fldname) + sizeof(ARRAY, n)
     else:
         raise Exception("don't know how to take the size of a %r"%TYPE)
 


More information about the pypy-commit mailing list