[pypy-svn] r31652 - in pypy/branch/no-zeroing-assumption/pypy: annotation rpython/lltypesystem rpython/lltypesystem/test rpython/ootypesystem
mwh at codespeak.net
mwh at codespeak.net
Fri Aug 25 18:30:24 CEST 2006
Author: mwh
Date: Fri Aug 25 18:30:19 2006
New Revision: 31652
Modified:
pypy/branch/no-zeroing-assumption/pypy/annotation/binaryop.py
pypy/branch/no-zeroing-assumption/pypy/annotation/builtin.py
pypy/branch/no-zeroing-assumption/pypy/annotation/unaryop.py
pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/llmemory.py
pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/lltype.py
pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rclass.py
pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rpbc.py
pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/test/test_llmemory.py
pypy/branch/no-zeroing-assumption/pypy/rpython/ootypesystem/ootype.py
Log:
(pedronis, mwh)
increase sanity in lltype and in the process make raw mallocs not zero pointer
fields. see new test for intent.
also, this lets me revert the changes i made to places that i shouldn't have
needed to change in the first place.
Modified: pypy/branch/no-zeroing-assumption/pypy/annotation/binaryop.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/annotation/binaryop.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/annotation/binaryop.py Fri Aug 25 18:30:19 2006
@@ -669,7 +669,7 @@
example = p.ll_ptrtype._example()
if example[0] is not None: # ignore Void s_value
v_lltype = annotation_to_lltype(s_value)
- example[0] = v_lltype._defl(example=True)
+ example[0] = v_lltype._defl()
setitem.can_only_throw = []
class __extend__(pairtype(SomePtr, SomeObject)):
Modified: pypy/branch/no-zeroing-assumption/pypy/annotation/builtin.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/annotation/builtin.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/annotation/builtin.py Fri Aug 25 18:30:19 2006
@@ -416,7 +416,7 @@
def cast_primitive(T, s_v):
assert T.is_constant()
- return ll_to_annotation(lltype.cast_primitive(T.const, annotation_to_lltype(s_v)._defl(example=True)))
+ return ll_to_annotation(lltype.cast_primitive(T.const, annotation_to_lltype(s_v)._defl()))
def nullptr(T):
assert T.is_constant()
@@ -426,13 +426,13 @@
def cast_pointer(PtrT, s_p):
assert isinstance(s_p, SomePtr), "casting of non-pointer: %r" % s_p
assert PtrT.is_constant()
- cast_p = lltype.cast_pointer(PtrT.const, s_p.ll_ptrtype._defl(example=True))
+ cast_p = lltype.cast_pointer(PtrT.const, s_p.ll_ptrtype._defl())
return SomePtr(ll_ptrtype=lltype.typeOf(cast_p))
def cast_opaque_ptr(PtrT, s_p):
assert isinstance(s_p, SomePtr), "casting of non-pointer: %r" % s_p
assert PtrT.is_constant()
- cast_p = lltype.cast_opaque_ptr(PtrT.const, s_p.ll_ptrtype._defl(example=True))
+ cast_p = lltype.cast_opaque_ptr(PtrT.const, s_p.ll_ptrtype._defl())
return SomePtr(ll_ptrtype=lltype.typeOf(cast_p))
def direct_fieldptr(s_p, s_fieldname):
Modified: pypy/branch/no-zeroing-assumption/pypy/annotation/unaryop.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/annotation/unaryop.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/annotation/unaryop.py Fri Aug 25 18:30:19 2006
@@ -605,10 +605,10 @@
example = p.ll_ptrtype._example()
if getattr(example, s_attr.const) is not None: # ignore Void s_value
v_lltype = annotation_to_lltype(s_value)
- setattr(example, s_attr.const, v_lltype._defl(example=True))
+ setattr(example, s_attr.const, v_lltype._defl())
def simple_call(p, *args_s):
- llargs = [annotation_to_lltype(arg_s)._defl(example=True) for arg_s in args_s]
+ llargs = [annotation_to_lltype(arg_s)._defl() for arg_s in args_s]
v = p.ll_ptrtype._example()(*llargs)
return ll_to_annotation(v)
Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/llmemory.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/llmemory.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/llmemory.py Fri Aug 25 18:30:19 2006
@@ -56,7 +56,7 @@
if (isinstance(self.TYPE, lltype.ContainerType)
and self.TYPE._gckind == 'gc'):
assert self.repeat == 1
- p = lltype.malloc(self.TYPE)
+ p = lltype.malloc(self.TYPE, flavor='raw')
return cast_ptr_to_adr(p)
else:
T = lltype.FixedSizeArray(self.TYPE, self.repeat)
Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/lltype.py Fri Aug 25 18:30:19 2006
@@ -115,7 +115,11 @@
def _short_name(self):
return str(self)
- def _defl(self, parent=None, parentindex=None, example=False):
+ def _defl(self, parent=None, parentindex=None):
+ raise NotImplementedError
+
+ def _allocate(self, initialization, parent=None, parentindex=None):
+ assert initialization in ('raw', 'malloc', 'example')
raise NotImplementedError
def _freeze_(self):
@@ -254,16 +258,19 @@
def _short_name(self):
return "%s %s" % (self.__class__.__name__, self._name)
- def _defl(self, parent=None, parentindex=None, example=False):
- return _struct(self, parent=parent, parentindex=parentindex,
- example=example)
+## def _defl(self, parent=None, parentindex=None):
+## return _struct(self, parent=parent, parentindex=parentindex)
+
+ def _allocate(self, initialization, parent=None, parentindex=None):
+ return _struct(self, initialization=initialization,
+ parent=parent, parentindex=parentindex)
def _container_example(self):
if self._arrayfld is None:
n = None
else:
n = 1
- return _struct(self, n, example=True)
+ return _struct(self, n, initialization='example')
class RttiStruct(Struct):
_runtime_type_info = None
@@ -359,7 +366,7 @@
_short_name = saferecursive(_short_name, '...')
def _container_example(self):
- return _array(self, 1, example=True)
+ return _array(self, 1, initialization='example')
class GcArray(Array):
_gckind = 'gc'
@@ -425,7 +432,7 @@
def _container_example(self):
def ex(*args):
- return self.RESULT._defl(example=True)
+ return self.RESULT._defl()
return _func(self, _callable=ex)
def _trueargs(self):
@@ -448,9 +455,12 @@
def _container_example(self):
return _opaque(self)
- def _defl(self, parent=None, parentindex=None, example=False):
+ def _defl(self, parent=None, parentindex=None):
return _opaque(self, parent=parent, parentindex=parentindex)
+ def _allocate(self, initialization, parent=None, parentindex=None):
+ return self._defl(parent=parent, parentindex=parentindex)
+
RuntimeTypeInfo = OpaqueType("RuntimeTypeInfo")
class GcOpaqueType(OpaqueType):
@@ -469,8 +479,10 @@
return "PyObject"
def _inline_is_varsize(self, last):
return False
- def _defl(self, parent=None, parentindex=None, example=False):
+ def _defl(self, parent=None, parentindex=None):
return _pyobjheader(parent, parentindex)
+ def _allocate(self, initialization, parent=None, parentindex=None):
+ return self._defl(parent=parent, parentindex=parentindex)
PyObject = PyObjectType()
@@ -508,15 +520,19 @@
def __str__(self):
return self._name
- def _defl(self, parent=None, parentindex=None, example=False):
- if not example and self is not Void:
- return Uninitialized
+ def _defl(self, parent=None, parentindex=None):
return self._default
+ def _allocate(self, initialization, parent=None, parentindex=None):
+ if self is not Void and initialization != 'example':
+ return Uninitialized
+ else:
+ return self._default
+
def _is_atomic(self):
return True
- def _example(self, parent=None, parentindex=None, example=False):
+ def _example(self, parent=None, parentindex=None):
return self._default
class Number(Primitive):
@@ -580,8 +596,13 @@
def _is_atomic(self):
return self.TO._gckind == 'raw'
- def _defl(self, parent=None, parentindex=None, example=False):
- if example or self._needsgc:
+ def _defl(self, parent=None, parentindex=None):
+ return _ptr(self, None)
+
+ def _allocate(self, initialization, parent=None, parentindex=None):
+ if initialization == 'example':
+ return _ptr(self, None)
+ elif initialization == 'malloc' and self._needsgc():
return _ptr(self, None)
else:
return Uninitialized
@@ -1210,11 +1231,11 @@
__slots__ = ()
- def __new__(self, TYPE, n=None, parent=None, parentindex=None, example=False):
+ def __new__(self, TYPE, n=None, initialization=None, parent=None, parentindex=None):
my_variety = _struct_variety(TYPE._names)
return object.__new__(my_variety)
- def __init__(self, TYPE, n=None, parent=None, parentindex=None, example=False):
+ def __init__(self, TYPE, n=None, initialization=None, parent=None, parentindex=None):
_parentable.__init__(self, TYPE)
if n is not None and TYPE._arrayfld is None:
raise TypeError("%r is not variable-sized" % (TYPE,))
@@ -1223,9 +1244,9 @@
first, FIRSTTYPE = TYPE._first_struct()
for fld, typ in TYPE._flds.items():
if fld == TYPE._arrayfld:
- value = _array(typ, n, parent=self, parentindex=fld, example=example)
+ value = _array(typ, n, initialization=initialization, parent=self, parentindex=fld)
else:
- value = typ._defl(parent=self, parentindex=fld, example=example)
+ value = typ._allocate(initialization=initialization, parent=self, parentindex=fld)
setattr(self, fld, value)
if parent is not None:
self._setparentstructure(parent, parentindex)
@@ -1287,13 +1308,13 @@
__slots__ = ('items',)
- def __init__(self, TYPE, n, parent=None, parentindex=None, example=False):
+ def __init__(self, TYPE, n, initialization=None, parent=None, parentindex=None):
if not isinstance(n, int):
raise TypeError, "array length must be an int"
if n < 0:
raise ValueError, "negative array length"
_parentable.__init__(self, TYPE)
- self.items = [TYPE.OF._defl(parent=self, parentindex=j, example=example)
+ self.items = [TYPE.OF._allocate(initialization=initialization, parent=self, parentindex=j)
for j in range(n)]
if parent is not None:
self._setparentstructure(parent, parentindex)
@@ -1525,10 +1546,16 @@
def malloc(T, n=None, flavor='gc', immortal=False, extra_args=(), zero=False):
+ if zero or immortal:
+ initialization = 'example'
+ elif flavor == 'raw':
+ initialization = 'raw'
+ else:
+ initialization = 'malloc'
if isinstance(T, Struct):
- o = _struct(T, n, example=zero or immortal)
+ o = _struct(T, n, initialization=initialization)
elif isinstance(T, Array):
- o = _array(T, n, example=zero or immortal)
+ o = _array(T, n, initialization=initialization)
else:
raise TypeError, "malloc for Structs and Arrays only"
if T._gckind != 'gc' and not immortal and flavor.startswith('gc'):
@@ -1555,7 +1582,7 @@
return _ptr(Ptr(TYPE), o)
def nullptr(T):
- return Ptr(T)._defl(example=True)
+ return Ptr(T)._defl()
def opaqueptr(TYPE, name, **attrs):
if not isinstance(TYPE, OpaqueType):
Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rclass.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rclass.py Fri Aug 25 18:30:19 2006
@@ -440,7 +440,7 @@
if attrvalue is None:
warning("prebuilt instance %r has no attribute %r" % (
value, name))
- llattrvalue = r.lowleveltype._defl(example=True)
+ llattrvalue = r.lowleveltype._defl()
else:
llattrvalue = r.convert_desc_or_const(attrvalue)
else:
Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rpbc.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rpbc.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rpbc.py Fri Aug 25 18:30:19 2006
@@ -73,7 +73,7 @@
return malloc(self.EMPTY, immortal=True)
def null_instance(self):
- return llmemory.Address._defl(example=True)
+ return llmemory.Address._defl()
class __extend__(pairtype(MultipleUnrelatedFrozenPBCRepr,
MultipleUnrelatedFrozenPBCRepr),
Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/test/test_llmemory.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/test/test_llmemory.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/test/test_llmemory.py Fri Aug 25 18:30:19 2006
@@ -295,6 +295,20 @@
py.test.raises(IndexError, "adr.signed[-1]")
py.test.raises(IndexError, "adr.signed[1]")
+def test_raw_malloc_access():
+ S = lltype.GcStruct("S", ('x', lltype.Signed))
+ T = lltype.GcStruct("T", ('y', lltype.Signed), ('s', lltype.Ptr(S)))
+ # regular malloc zeros GC pointers
+ p_t = lltype.malloc(T)
+ assert p_t.s == lltype.nullptr(S)
+ # raw malloc does not
+ p_raw_t = lltype.malloc(T, flavor="raw")
+ py.test.raises(lltype.UninitializedMemoryAccess, "p_raw_t.s")
+ # this sort of raw_malloc too
+ p_raw_t = cast_adr_to_ptr(raw_malloc(sizeof(T)), lltype.Ptr(T))
+ py.test.raises(lltype.UninitializedMemoryAccess, "p_raw_t.s")
+
+
def test_raw_malloc_signed_bunch():
adr = raw_malloc(sizeof(lltype.Signed) * 50)
p = cast_adr_to_ptr(adr,
Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/ootypesystem/ootype.py Fri Aug 25 18:30:19 2006
@@ -30,7 +30,7 @@
class Class(OOType):
- def _defl(self, example=False):
+ def _defl(self):
return nullruntimeclass
Class = Class()
@@ -66,7 +66,7 @@
def __hash__(self):
return object.__hash__(self)
- def _defl(self, example=False):
+ def _defl(self):
return self._null
def _example(self): return new(self)
@@ -92,7 +92,7 @@
if isinstance(defn, Meth):
raise TypeError("Attempting to store method in field")
- fields[name] = (defn, defn._defl(example=True))
+ fields[name] = (defn, defn._defl())
else:
ootype, default = defn
@@ -195,7 +195,7 @@
_retval = self.RESULT._example()
return _static_meth(self, _callable=lambda *args: _retval)
- def _defl(self, example=False):
+ def _defl(self):
return null(self)
def __repr__(self):
@@ -219,7 +219,7 @@
def _example(self):
return new(self)
- def _defl(self, example=False):
+ def _defl(self):
return self._null
def _get_interp_class(self):
@@ -233,10 +233,10 @@
def __init__(self, fields):
self._fields = frozendict()
for name, ITEMTYPE in fields.items():
- self._fields[name] = ITEMTYPE, ITEMTYPE._defl(example=True)
+ self._fields[name] = ITEMTYPE, ITEMTYPE._defl()
self._null = _null_record(self)
- def _defl(self, example=False):
+ def _defl(self):
return self._null
def _get_interp_class(self):
@@ -321,7 +321,7 @@
return BuiltinADTType._enforce(self, value)
# TODO: should it return _null or ''?
- def _defl(self, example=False):
+ def _defl(self):
return make_string("")
def _example(self):
return self._defl()
@@ -344,7 +344,7 @@
})
self._setup_methods({})
- def _defl(self, example=False):
+ def _defl(self):
return self._null
def _get_interp_class(self):
@@ -430,7 +430,7 @@
ITEMTYPE = self._specialize_type(self._ITEMTYPE, generic_types)
return self.__class__(ITEMTYPE)
- def _defl(self, example=False):
+ def _defl(self):
return self._null
def _set_itemtype(self, ITEMTYPE):
More information about the Pypy-commit
mailing list