[pypy-commit] pypy ffi-backend: Tweak the immutable hints.

arigo noreply at buildbot.pypy.org
Sun Jul 29 15:48:15 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: ffi-backend
Changeset: r56499:076963af41d7
Date: 2012-07-28 19:28 +0200
http://bitbucket.org/pypy/pypy/changeset/076963af41d7/

Log:	Tweak the immutable hints.

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
@@ -19,7 +19,7 @@
 
 
 class W_CDataCallback(W_CDataApplevelOwning):
-    _immutable_ = True
+    #_immutable_fields_ = ...
     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
@@ -13,7 +13,7 @@
 
 class W_CData(Wrappable):
     _attrs_ = ['space', '_cdata', 'ctype']
-    _immutable_ = True
+    _immutable_fields_ = ['_cdata', 'ctype']
     _cdata = lltype.nullptr(rffi.CCHARP.TO)
 
     def __init__(self, space, cdata, ctype):
@@ -230,7 +230,6 @@
     """This is the abstract base class for classes that are of the app-level
     type '_cffi_backend.CDataOwn'.  These are weakrefable."""
     _attrs_ = ['_lifeline_']    # for weakrefs
-    _immutable_ = True
 
     def _repr_extra(self):
         from pypy.module._cffi_backend.ctypeptr import W_CTypePointer
@@ -246,7 +245,6 @@
     """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)
@@ -261,7 +259,7 @@
     """Subclass with an explicit length, for allocated instances of
     the C type 'foo[]'."""
     _attrs_ = ['length']
-    _immutable_ = True
+    _immutable_fields_ = ['length']
 
     def __init__(self, space, size, ctype, length):
         W_CDataNewOwning.__init__(self, space, size, ctype)
@@ -282,7 +280,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
+    _immutable_fields_ = ['structobj']
 
     def __init__(self, space, cdata, ctype, structobj):
         W_CDataApplevelOwning.__init__(self, space, cdata, ctype)
@@ -299,7 +297,6 @@
     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/ctypearray.py b/pypy/module/_cffi_backend/ctypearray.py
--- a/pypy/module/_cffi_backend/ctypearray.py
+++ b/pypy/module/_cffi_backend/ctypearray.py
@@ -18,7 +18,8 @@
 
 
 class W_CTypeArray(W_CTypePtrOrArray):
-    _immutable_ = True
+    _attrs_            = ['length', 'ctptr']
+    _immutable_fields_ = ['length', 'ctptr']
 
     def __init__(self, space, ctptr, length, arraysize, extra):
         W_CTypePtrOrArray.__init__(self, space, arraysize, extra, 0,
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
@@ -12,7 +12,8 @@
 
 
 class W_CTypeEnum(W_CTypePrimitiveSigned):
-    _immutable_ = True
+    _attrs_            = ['enumerators2values', 'enumvalues2erators']
+    _immutable_fields_ = ['enumerators2values', 'enumvalues2erators']
 
     def __init__(self, space, name, enumerators, enumvalues):
         from pypy.module._cffi_backend.newtype import alignment
diff --git a/pypy/module/_cffi_backend/ctypefunc.py b/pypy/module/_cffi_backend/ctypefunc.py
--- a/pypy/module/_cffi_backend/ctypefunc.py
+++ b/pypy/module/_cffi_backend/ctypefunc.py
@@ -22,7 +22,8 @@
 
 
 class W_CTypeFunc(W_CTypePtrBase):
-    _immutable_ = True
+    _attrs_            = ['fargs', 'ellipsis', 'cif_descr']
+    _immutable_fields_ = ['fargs', 'ellipsis', 'cif_descr']
 
     def __init__(self, space, fargs, fresult, ellipsis):
         extra = self._compute_extra_text(fargs, fresult, ellipsis)
diff --git a/pypy/module/_cffi_backend/ctypeobj.py b/pypy/module/_cffi_backend/ctypeobj.py
--- a/pypy/module/_cffi_backend/ctypeobj.py
+++ b/pypy/module/_cffi_backend/ctypeobj.py
@@ -10,8 +10,10 @@
 
 
 class W_CType(Wrappable):
-    _attrs_ = ['space', 'size?', 'name', 'name_position']
-    _immutable_fields_ = _attrs_
+    _attrs_   = ['space', 'size',  'name', 'name_position']
+    _immutable_fields_ = ['size?', 'name', 'name_position']
+    # note that 'size' is not strictly immutable, because it can change
+    # from -1 to the real value in the W_CTypeStruct subclass.
 
     cast_anything = False
     is_primitive_integer = False
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
@@ -12,7 +12,8 @@
 
 
 class W_CTypePrimitive(W_CType):
-    _immutable_ = True
+    _attrs_            = ['align']
+    _immutable_fields_ = ['align']
 
     def __init__(self, space, size, name, name_position, align):
         W_CType.__init__(self, space, size, name, name_position)
@@ -71,12 +72,12 @@
 
 
 class W_CTypePrimitiveCharOrUniChar(W_CTypePrimitive):
-    _immutable_ = True
+    _attrs_ = []
     is_primitive_integer = True
 
 
 class W_CTypePrimitiveChar(W_CTypePrimitiveCharOrUniChar):
-    _immutable_ = True
+    _attrs_ = []
     cast_anything = True
 
     def int(self, cdata):
@@ -108,7 +109,7 @@
 
 
 class W_CTypePrimitiveUniChar(W_CTypePrimitiveCharOrUniChar):
-    _immutable_ = True
+    _attrs_ = []
 
     def int(self, cdata):
         unichardata = rffi.cast(rffi.CWCHARP, cdata)
@@ -142,7 +143,8 @@
 
 
 class W_CTypePrimitiveSigned(W_CTypePrimitive):
-    _immutable_ = True
+    _attrs_            = ['value_fits_long', 'vmin', 'vrangemax']
+    _immutable_fields_ = ['value_fits_long', 'vmin', 'vrangemax']
     is_primitive_integer = True
 
     def __init__(self, *args):
@@ -179,7 +181,8 @@
 
 
 class W_CTypePrimitiveUnsigned(W_CTypePrimitive):
-    _immutable_ = True
+    _attrs_            = ['value_fits_long', 'vrangemax']
+    _immutable_fields_ = ['value_fits_long', 'vrangemax']
     is_primitive_integer = True
 
     def __init__(self, *args):
@@ -208,7 +211,7 @@
 
 
 class W_CTypePrimitiveFloat(W_CTypePrimitive):
-    _immutable_ = True
+    _attrs_ = []
 
     def cast(self, w_ob):
         space = self.space
diff --git a/pypy/module/_cffi_backend/ctypeptr.py b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -11,7 +11,8 @@
 
 
 class W_CTypePtrOrArray(W_CType):
-    _immutable_ = True
+    _attrs_            = ['ctitem', 'can_cast_anything', 'is_struct_ptr']
+    _immutable_fields_ = ['ctitem', 'can_cast_anything', 'is_struct_ptr']
 
     def __init__(self, space, size, extra, extra_position, ctitem,
                  could_cast_anything=True):
@@ -58,7 +59,7 @@
 
 class W_CTypePtrBase(W_CTypePtrOrArray):
     # base class for both pointers and pointers-to-functions
-    _immutable_ = True
+    _attrs_ = []
 
     def convert_to_object(self, cdata):
         ptrdata = rffi.cast(rffi.CCHARPP, cdata)[0]
@@ -88,7 +89,7 @@
 
 
 class W_CTypePointer(W_CTypePtrBase):
-    _immutable_ = True
+    _attrs_ = []
 
     def __init__(self, space, ctitem):
         from pypy.module._cffi_backend import ctypearray
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
@@ -14,8 +14,8 @@
 
 
 class W_CTypeStructOrUnion(W_CType):
-    _attrs_ = ['alignment?', 'fields_list?', 'fields_dict?',
-               'custom_field_pos?']
+    _immutable_fields_ = ['alignment?', 'fields_list?', 'fields_dict?',
+                          'custom_field_pos?']
     # fields added by complete_struct_or_union():
     alignment = -1
     fields_list = None
diff --git a/pypy/module/_cffi_backend/ctypevoid.py b/pypy/module/_cffi_backend/ctypevoid.py
--- a/pypy/module/_cffi_backend/ctypevoid.py
+++ b/pypy/module/_cffi_backend/ctypevoid.py
@@ -6,7 +6,7 @@
 
 
 class W_CTypeVoid(W_CType):
-    _immutable_ = True
+    _attrs_ = []
     cast_anything = True
 
     def __init__(self, space):


More information about the pypy-commit mailing list