Source

mino-pypy / pypy / module / cppyy / converter.py

Diff from to

File 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()
-