Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r58872:21866df6f6b4
Date: 2012-11-13 15:56 -0800
http://bitbucket.org/pypy/pypy/changeset/21866df6f6b4/
Log: fix immutable directives
diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -67,9 +67,10 @@
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):
@@ -127,6 +128,8 @@
class ArrayTypeConverterMixin(object):
_mixin_ = True
+ _immutable_fields_ = ['libffitype', 'size']
+
libffitype = jit_libffi.types.pointer
def __init__(self, space, array_size):
@@ -156,6 +159,8 @@
class PtrTypeConverterMixin(object):
_mixin_ = True
+ _immutable_fields_ = ['libffitype', 'size']
+
libffitype = jit_libffi.types.pointer
def __init__(self, space, array_size):
@@ -218,6 +223,8 @@
class ConstRefNumericTypeConverterMixin(NumericTypeConverterMixin):
_mixin_ = True
+ _immutable_fields_ = ['uses_local']
+
uses_local = True
def convert_argument_libffi(self, space, w_obj, address, call_local):
@@ -246,6 +253,8 @@
class VoidConverter(TypeConverter):
+ _immutable_fields_ = ['libffitype', 'name']
+
libffitype = jit_libffi.types.void
def __init__(self, space, name):
@@ -297,6 +306,8 @@
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))
@@ -310,6 +321,8 @@
return space.wrap(float(rffiptr[0]))
class ConstFloatRefConverter(FloatConverter):
+ _immutable_fields_ = ['libffitype', 'typecode']
+
libffitype = jit_libffi.types.pointer
typecode = 'F'
@@ -318,6 +331,8 @@
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))
@@ -325,6 +340,8 @@
self.default = rffi.cast(self.c_type, 0.)
class ConstDoubleRefConverter(ConstRefNumericTypeConverterMixin,
DoubleConverter):
+ _immutable_fields_ = ['libffitype', 'typecode']
+
libffitype = jit_libffi.types.pointer
typecode = 'D'
@@ -347,6 +364,8 @@
class VoidPtrConverter(TypeConverter):
+ _immutable_fields_ = ['libffitype']
+
libffitype = jit_libffi.types.pointer
def _unwrap_object(self, space, w_obj):
@@ -367,6 +386,8 @@
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):
@@ -388,9 +409,12 @@
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):
@@ -433,6 +457,7 @@
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
@@ -447,6 +472,8 @@
self._is_abstract(space)
class InstancePtrPtrConverter(InstancePtrConverter):
+ _immutable_fields_ = ['uses_local']
+
uses_local = True
def convert_argument(self, space, w_obj, address, call_local):
@@ -478,6 +505,8 @@
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")
@@ -508,6 +537,8 @@
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")
@@ -515,6 +546,8 @@
class PyObjectConverter(TypeConverter):
+ _immutable_fields_ = ['libffitype']
+
libffitype = jit_libffi.types.pointer
def convert_argument(self, space, w_obj, address, call_local):
@@ -643,9 +676,11 @@
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
@@ -658,9 +693,11 @@
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):
@@ -682,9 +719,11 @@
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
@@ -735,4 +774,3 @@
for c_type, alias in aliases:
_converters[alias] = _converters[c_type]
_add_aliased_converters()
-
diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py
--- a/pypy/module/cppyy/executor.py
+++ b/pypy/module/cppyy/executor.py
@@ -27,6 +27,8 @@
NULL = lltype.nullptr(jit_libffi.FFI_TYPE_P.TO)
class FunctionExecutor(object):
+ _immutable_fields_ = ['libffitype']
+
libffitype = NULL
def __init__(self, space, extra):
@@ -42,6 +44,8 @@
class PtrTypeExecutor(FunctionExecutor):
+ _immutable_fields_ = ['libffitype', 'typecode']
+
libffitype = jit_libffi.types.pointer
typecode = 'P'
@@ -63,6 +67,8 @@
class VoidExecutor(FunctionExecutor):
+ _immutable_fields_ = ['libffitype']
+
libffitype = jit_libffi.types.void
def execute(self, space, cppmethod, cppthis, num_args, args):
@@ -139,6 +145,8 @@
class InstancePtrExecutor(FunctionExecutor):
+ _immutable_fields_ = ['libffitype', 'cppclass']
+
libffitype = jit_libffi.types.pointer
def __init__(self, space, cppclass):
@@ -314,8 +322,10 @@
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
@@ -341,6 +351,7 @@
for tcode, names in ptr_info:
class PtrExecutor(PtrTypeExecutor):
+ _immutable_fields_ = ['typecode']
typecode = tcode
for name in names:
_executors[name+'*'] = PtrExecutor
diff --git a/pypy/module/cppyy/ffitypes.py b/pypy/module/cppyy/ffitypes.py
--- a/pypy/module/cppyy/ffitypes.py
+++ b/pypy/module/cppyy/ffitypes.py
@@ -12,6 +12,8 @@
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
@@ -28,6 +30,8 @@
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
@@ -51,6 +55,8 @@
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
@@ -60,6 +66,8 @@
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
@@ -69,6 +77,8 @@
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
@@ -78,6 +88,8 @@
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
@@ -87,6 +99,8 @@
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
@@ -96,6 +110,8 @@
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
@@ -105,6 +121,8 @@
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
@@ -114,6 +132,8 @@
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
@@ -123,6 +143,8 @@
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
@@ -136,6 +158,8 @@
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
diff --git a/pypy/module/cppyy/interp_cppyy.py
b/pypy/module/cppyy/interp_cppyy.py
--- a/pypy/module/cppyy/interp_cppyy.py
+++ b/pypy/module/cppyy/interp_cppyy.py
@@ -118,6 +118,11 @@
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
@@ -144,7 +149,6 @@
@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)
@@ -160,7 +164,7 @@
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:
@@ -188,7 +192,6 @@
@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
@@ -312,7 +315,6 @@
@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)):
@@ -364,6 +366,8 @@
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()
@@ -373,6 +377,8 @@
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
@@ -393,6 +399,8 @@
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:
@@ -408,7 +416,9 @@
"""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
@@ -443,7 +453,7 @@
#
# 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:
@@ -486,6 +496,8 @@
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
@@ -532,7 +544,8 @@
class W_CPPScope(Wrappable):
- #_immutable_fields_ = ["methods[*]", "datamembers[*]"]
+ _attrs_ = ['space', 'name', 'handle', 'methods', 'datamembers']
+ _immutable_fields_ = ['kind', 'name']
kind = "scope"
@@ -632,6 +645,8 @@
# 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):
@@ -715,6 +730,9 @@
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):
@@ -819,6 +837,8 @@
class W_CPPTemplateType(Wrappable):
+ _attrs_ = ['space', 'name', 'handle']
+ _immutable_fields = ['name', 'handle']
def __init__(self, space, name, opaque_handle):
self.space = space
@@ -840,6 +860,7 @@
class W_CPPInstance(Wrappable):
+ _attrs_ = ['space', 'cppclass', '_rawobject', 'isref', 'python_owns']
_immutable_fields_ = ["cppclass", "isref"]
def __init__(self, space, cppclass, rawobject, isref, python_owns):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit