Commits

wlav committed 21866df

fix immutable directives

Comments (0)

Files changed (4)

pypy/module/cppyy/converter.py

 
 
 class TypeConverter(object):
+    _immutable_fields_ = ['libffitype', 'uses_local', 'name']
+
     libffitype = lltype.nullptr(jit_libffi.FFI_TYPE_P.TO)
     uses_local = False
-
     name = ""
 
     def __init__(self, space, extra):
 
 class ArrayTypeConverterMixin(object):
     _mixin_ = True
+    _immutable_fields_ = ['libffitype', 'size']
+
     libffitype = jit_libffi.types.pointer
 
     def __init__(self, space, array_size):
 
 class PtrTypeConverterMixin(object):
     _mixin_ = True
+    _immutable_fields_ = ['libffitype', 'size']
+
     libffitype = jit_libffi.types.pointer
 
     def __init__(self, space, array_size):
 
 class ConstRefNumericTypeConverterMixin(NumericTypeConverterMixin):
     _mixin_ = True
+    _immutable_fields_ = ['uses_local']
+
     uses_local = True
 
     def convert_argument_libffi(self, space, w_obj, address, call_local):
 
 
 class VoidConverter(TypeConverter):
+    _immutable_fields_ = ['libffitype', 'name']
+
     libffitype = jit_libffi.types.void
 
     def __init__(self, space, name):
         address[0] = self._unwrap_object(space, w_value)
 
 class FloatConverter(ffitypes.typeid(rffi.FLOAT), FloatTypeConverterMixin, TypeConverter):
+    _immutable_fields_ = ['default']
+
     def __init__(self, space, default):
         if default:
             fval = float(rfloat.rstring_to_float(default))
         return space.wrap(float(rffiptr[0]))
 
 class ConstFloatRefConverter(FloatConverter):
+    _immutable_fields_ = ['libffitype', 'typecode']
+
     libffitype = jit_libffi.types.pointer
     typecode = 'F'
 
         raise FastCallNotPossible
 
 class DoubleConverter(ffitypes.typeid(rffi.DOUBLE), FloatTypeConverterMixin, TypeConverter):
+    _immutable_fields_ = ['default']
+
     def __init__(self, space, default):
         if default:
             self.default = rffi.cast(self.c_type, rfloat.rstring_to_float(default))
             self.default = rffi.cast(self.c_type, 0.)
 
 class ConstDoubleRefConverter(ConstRefNumericTypeConverterMixin, DoubleConverter):
+    _immutable_fields_ = ['libffitype', 'typecode']
+
     libffitype = jit_libffi.types.pointer
     typecode = 'D'
 
 
 
 class VoidPtrConverter(TypeConverter):
+    _immutable_fields_ = ['libffitype']
+
     libffitype = jit_libffi.types.pointer
 
     def _unwrap_object(self, space, w_obj):
         x[0] = self._unwrap_object(space, w_obj)
 
 class VoidPtrPtrConverter(TypeConverter):
+    _immutable_fields_ = ['uses_local']
+
     uses_local = True
 
     def convert_argument(self, space, w_obj, address, call_local):
             pass             # no set on buffer/array/None
 
 class VoidPtrRefConverter(VoidPtrPtrConverter):
+    _immutable_fields_ = ['uses_local']
     uses_local = True
 
 class InstancePtrConverter(TypeConverter):
+    _immutable_fields_ = ['libffitype', 'cppclass']
+
     libffitype  = jit_libffi.types.pointer
 
     def __init__(self, space, cppclass):
         address[0] = rffi.cast(rffi.VOIDP, self._unwrap_object(space, w_value))
 
 class InstanceConverter(InstancePtrConverter):
+
     def convert_argument_libffi(self, space, w_obj, address, call_local):
         from pypy.module.cppyy.interp_cppyy import FastCallNotPossible
         raise FastCallNotPossible       # TODO: by-value is a jit_libffi special case
         self._is_abstract(space)
 
 class InstancePtrPtrConverter(InstancePtrConverter):
+    _immutable_fields_ = ['uses_local']
+
     uses_local = True
 
     def convert_argument(self, space, w_obj, address, call_local):
 
 
 class StdStringConverter(InstanceConverter):
+    _immutable_fields_ = ['cppclass']
+
     def __init__(self, space, extra):
         from pypy.module.cppyy import interp_cppyy
         cppclass = interp_cppyy.scope_byname(space, "std::string")
         capi.c_free_stdstring(rffi.cast(capi.C_OBJECT, rffi.cast(rffi.VOIDPP, arg)[0]))
 
 class StdStringRefConverter(InstancePtrConverter):
+    _immutable_fields_ = ['cppclass']
+
     def __init__(self, space, extra):
         from pypy.module.cppyy import interp_cppyy
         cppclass = interp_cppyy.scope_byname(space, "std::string")
 
 
 class PyObjectConverter(TypeConverter):
+    _immutable_fields_ = ['libffitype']
+
     libffitype = jit_libffi.types.pointer
 
     def convert_argument(self, space, w_obj, address, call_local):
 
     for c_type, names in type_info:
         class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin, TypeConverter):
+            _immutable_ = True
             def __init__(self, space, default):
                 self.default = rffi.cast(self.c_type, capi.c_strtoll(default))
         class ConstRefConverter(ConstRefNumericTypeConverterMixin, BasicConverter):
+            _immutable_ = True
             libffitype = jit_libffi.types.pointer
         for name in names:
             _converters[name] = BasicConverter
 
     for c_type, names in type_info:
         class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin, TypeConverter):
+            _immutable_ = True
             def __init__(self, space, default):
                 self.default = rffi.cast(self.c_type, capi.c_strtoll(default))
         class ConstRefConverter(ConstRefNumericTypeConverterMixin, BasicConverter):
+            _immutable_ = True
             libffitype = jit_libffi.types.pointer
             typecode = 'r'
             def convert_argument(self, space, w_obj, address, call_local):
 
     for c_type, names in type_info:
         class BasicConverter(ffitypes.typeid(c_type), IntTypeConverterMixin, TypeConverter):
+            _immutable_ = True
             def __init__(self, space, default):
                 self.default = rffi.cast(self.c_type, capi.c_strtoull(default))
         class ConstRefConverter(ConstRefNumericTypeConverterMixin, BasicConverter):
+            _immutable_ = True
             libffitype = jit_libffi.types.pointer
         for name in names:
             _converters[name] = BasicConverter
     for c_type, alias in aliases:
         _converters[alias] = _converters[c_type]
 _add_aliased_converters()
-

pypy/module/cppyy/executor.py

 NULL = lltype.nullptr(jit_libffi.FFI_TYPE_P.TO)
 
 class FunctionExecutor(object):
+    _immutable_fields_ = ['libffitype']
+
     libffitype = NULL
 
     def __init__(self, space, extra):
 
 
 class PtrTypeExecutor(FunctionExecutor):
+    _immutable_fields_ = ['libffitype', 'typecode']
+
     libffitype = jit_libffi.types.pointer
     typecode = 'P'
 
 
 
 class VoidExecutor(FunctionExecutor):
+    _immutable_fields_ = ['libffitype']
+
     libffitype = jit_libffi.types.void
 
     def execute(self, space, cppmethod, cppthis, num_args, args):
 
 
 class InstancePtrExecutor(FunctionExecutor):
+    _immutable_fields_ = ['libffitype', 'cppclass']
+
     libffitype = jit_libffi.types.pointer
 
     def __init__(self, space, cppclass):
 
     for c_type, stub, names in type_info:
         class BasicExecutor(ffitypes.typeid(c_type), NumericExecutorMixin, FunctionExecutor):
+            _immutable_ = True
             c_stubcall  = staticmethod(stub)
         class BasicRefExecutor(ffitypes.typeid(c_type), NumericRefExecutorMixin, FunctionExecutor):
+            _immutable_fields_ = ['libffitype']
             libffitype = jit_libffi.types.pointer
         for name in names:
             _executors[name]              = BasicExecutor
 
     for tcode, names in ptr_info:
         class PtrExecutor(PtrTypeExecutor):
+            _immutable_fields_ = ['typecode']
             typecode = tcode
         for name in names:
             _executors[name+'*'] = PtrExecutor

pypy/module/cppyy/ffitypes.py

 
 class BoolTypeMixin(object):
     _mixin_     = True
+    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+
     libffitype  = jit_libffi.types.uchar
     c_type      = rffi.UCHAR
     c_ptrtype   = rffi.UCHARP
 
 class CharTypeMixin(object):
     _mixin_     = True
+    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+
     libffitype  = jit_libffi.types.schar
     c_type      = rffi.CHAR
     c_ptrtype   = rffi.CCHARP           # there's no such thing as rffi.CHARP
 
 class ShortTypeMixin(object):
     _mixin_     = True
+    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+
     libffitype  = jit_libffi.types.sshort
     c_type      = rffi.SHORT
     c_ptrtype   = rffi.SHORTP
 
 class UShortTypeMixin(object):
     _mixin_     = True
+    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+
     libffitype  = jit_libffi.types.ushort
     c_type      = rffi.USHORT
     c_ptrtype   = rffi.USHORTP
 
 class IntTypeMixin(object):
     _mixin_     = True
+    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+
     libffitype  = jit_libffi.types.sint
     c_type      = rffi.INT
     c_ptrtype   = rffi.INTP
 
 class UIntTypeMixin(object):
     _mixin_     = True
+    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+
     libffitype  = jit_libffi.types.uint
     c_type      = rffi.UINT
     c_ptrtype   = rffi.UINTP
 
 class LongTypeMixin(object):
     _mixin_     = True
+    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+
     libffitype  = jit_libffi.types.slong
     c_type      =  rffi.LONG
     c_ptrtype   = rffi.LONGP
 
 class ULongTypeMixin(object):
     _mixin_     = True
+    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+
     libffitype  = jit_libffi.types.ulong
     c_type      = rffi.ULONG
     c_ptrtype   = rffi.ULONGP
 
 class LongLongTypeMixin(object):
     _mixin_     = True
+    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+
     libffitype  = jit_libffi.types.sint64
     c_type      = rffi.LONGLONG
     c_ptrtype   = rffi.LONGLONGP
 
 class ULongLongTypeMixin(object):
     _mixin_     = True
+    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype']
+
     libffitype  = jit_libffi.types.uint64
     c_type      = rffi.ULONGLONG
     c_ptrtype   = rffi.ULONGLONGP
 
 class FloatTypeMixin(object):
     _mixin_     = True
+    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype', 'typecode']
+
     libffitype  = jit_libffi.types.float
     c_type      = rffi.FLOAT
     c_ptrtype   = rffi.FLOATP
 
 class DoubleTypeMixin(object):
     _mixin_     = True
+    _immutable_fields_ = ['libffitype', 'c_type', 'c_ptrtype', 'typecode']
+
     libffitype  = jit_libffi.types.double
     c_type      = rffi.DOUBLE
     c_ptrtype   = rffi.DOUBLEP

pypy/module/cppyy/interp_cppyy.py

     also takes care of offset casting and recycling of known objects through
     the memory_regulator."""
 
+    _attrs_ = ['space', 'scope', 'index', 'cppmethod', 'arg_defs', 'args_required',
+               'args_expected', 'converters', 'executor', '_funcaddr', 'cif_descr',
+               'uses_local']
+    _immutable_ = True
+
     def __init__(self, space, containing_scope, method_index, arg_defs, args_required):
         self.space = space
         self.scope = containing_scope
 
     @jit.unroll_safe
     def call(self, cppthis, args_w):
-        #jit.promote(self)
         assert lltype.typeOf(cppthis) == capi.C_OBJECT
 
         # check number of given arguments against required (== total - defaults)
                 self._setup(cppthis)
             except Exception, e:
                 pass
-    
+
         # some calls, e.g. for ptr-ptr or reference need a local array to store data for
         # the duration of the call
         if self.uses_local:
 
     @jit.unroll_safe
     def do_fast_call(self, cppthis, args_w, call_local):
-        #jit.promote(self)
         if self.cif_descr is None:
             raise FastCallNotPossible
         cif_descr = self.cif_descr
 
     @jit.unroll_safe
     def prepare_arguments(self, args_w, call_local):
-        #jit.promote(self)
         args = capi.c_allocate_function_args(len(args_w))
         stride = capi.c_function_arg_sizeof()
         for i in range(len(args_w)):
     all the needed functionality, by allowing the C++ this pointer to be null
     in the call. An optimization is expected there, however."""
 
+    _immutable_ = True
+
     def __repr__(self):
         return "CPPFunction: %s" % self.signature()
 
     it allocates memory for the newly constructed object and sets ownership
     to Python."""
 
+    _immutable_ = True
+
     def call(self, cppthis, args_w):
         newthis = capi.c_allocate(self.scope)
         assert lltype.typeOf(newthis) == capi.C_OBJECT
     operator[](int). The former function takes an extra argument to assign to
     the return type of the latter."""
 
+    _immutable_ = True
+
     def call(self, cppthis, args_w):
         end = len(args_w)-1
         if 0 <= end:
     """Dispatcher that is actually available at the app-level: it is a
     collection of (possibly) overloaded methods or functions. It calls these
     in order and deals with error handling and reporting."""
-    #_immutable_fields_ = ["functions[*]"]
+
+    _attrs_ = ['space', 'scope', 'functions']
+    _immutable_fields_ = ['scope', 'functions[*]']
 
     def __init__(self, space, containing_scope, functions):
         self.space = space
         #
         # TODO: figure out what happens if a callback into from the C++ call
         # raises a Python exception.
-        #jit.promote(self)
+        jit.promote(self)
         for i in range(len(self.functions)):
             cppyyfunc = self.functions[i]
             try:
 
 
 class W_CPPDataMember(Wrappable):
+    _attrs_ = ['space', 'scope', 'converter', 'offset', '_is_static']
+    _immutable_fields = ['scope', 'converter', 'offset', '_is_static']
 
     def __init__(self, space, containing_scope, type_name, offset, is_static):
         self.space = space
 
 
 class W_CPPScope(Wrappable):
-    #_immutable_fields_ = ["methods[*]", "datamembers[*]"]
+    _attrs_ = ['space', 'name', 'handle', 'methods', 'datamembers']
+    _immutable_fields_ = ['kind', 'name']
 
     kind = "scope"
 
 # classes for inheritance. Both are python classes, though, and refactoring
 # may be in order at some point.
 class W_CPPNamespace(W_CPPScope):
+    _immutable_fields_ = ['kind']
+
     kind = "namespace"
 
     def _make_cppfunction(self, pyname, index):
 
 
 class W_CPPClass(W_CPPScope):
+    _attrs_ = ['space', 'default_constructor', 'name', 'handle', 'methods', 'datamembers']
+    _immutable_fields_ = ['kind', 'default_constructor', 'methods[*]', 'datamembers[*]']
+
     kind = "class"
 
     def __init__(self, space, name, opaque_handle):
 
 
 class W_CPPTemplateType(Wrappable):
+    _attrs_ = ['space', 'name', 'handle']
+    _immutable_fields = ['name', 'handle']
 
     def __init__(self, space, name, opaque_handle):
         self.space = space
 
 
 class W_CPPInstance(Wrappable):
+    _attrs_ = ['space', 'cppclass', '_rawobject', 'isref', 'python_owns']
     _immutable_fields_ = ["cppclass", "isref"]
 
     def __init__(self, space, cppclass, rawobject, isref, python_owns):