[pypy-svn] r31528 - in pypy/branch/no-zeroing-assumption/pypy: annotation rpython rpython/lltypesystem rpython/lltypesystem/test rpython/ootypesystem rpython/test
mwh at codespeak.net
mwh at codespeak.net
Wed Aug 23 13:17:19 CEST 2006
Author: mwh
Date: Wed Aug 23 13:17:08 2006
New Revision: 31528
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/lltype.py
pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rdict.py
pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rstr.py
pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/test/test_lltype.py
pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/test/test_picklelltype.py
pypy/branch/no-zeroing-assumption/pypy/rpython/ootypesystem/ootype.py
pypy/branch/no-zeroing-assumption/pypy/rpython/rcpy.py
pypy/branch/no-zeroing-assumption/pypy/rpython/test/test_llinterp.py
Log:
beginnings of removing the zeroing assumption from lltype.
rdict is still broken (and boy is that going to be fun to fix) and this
explains the majority of the 50-odd failures in py.test rpython/test.
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 Wed Aug 23 13:17:08 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[0] = v_lltype._defl(example=True)
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 Wed Aug 23 13:17:08 2006
@@ -414,7 +414,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()))
+ return ll_to_annotation(lltype.cast_primitive(T.const, annotation_to_lltype(s_v)._defl(example=True)))
def nullptr(T):
assert T.is_constant()
@@ -424,13 +424,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())
+ cast_p = lltype.cast_pointer(PtrT.const, s_p.ll_ptrtype._defl(example=True))
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())
+ cast_p = lltype.cast_opaque_ptr(PtrT.const, s_p.ll_ptrtype._defl(example=True))
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 Wed Aug 23 13:17:08 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())
+ setattr(example, s_attr.const, v_lltype._defl(example=True))
def simple_call(p, *args_s):
- llargs = [annotation_to_lltype(arg_s)._defl() for arg_s in args_s]
+ llargs = [annotation_to_lltype(arg_s)._defl(example=True) 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/lltype.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/lltype.py Wed Aug 23 13:17:08 2006
@@ -14,6 +14,8 @@
TLS = tlsobject()
+Uninitialized = object()
+
def saferecursive(func, defl):
def safe(*args):
try:
@@ -113,7 +115,7 @@
def _short_name(self):
return str(self)
- def _defl(self, parent=None, parentindex=None):
+ def _defl(self, parent=None, parentindex=None, example=False):
raise NotImplementedError
def _freeze_(self):
@@ -252,15 +254,16 @@
def _short_name(self):
return "%s %s" % (self.__class__.__name__, self._name)
- def _defl(self, parent=None, parentindex=None):
- return _struct(self, parent=parent, parentindex=parentindex)
+ def _defl(self, parent=None, parentindex=None, example=False):
+ return _struct(self, parent=parent, parentindex=parentindex,
+ example=example)
def _container_example(self):
if self._arrayfld is None:
n = None
else:
n = 1
- return _struct(self, n)
+ return _struct(self, n, example=True)
class RttiStruct(Struct):
_runtime_type_info = None
@@ -356,7 +359,7 @@
_short_name = saferecursive(_short_name, '...')
def _container_example(self):
- return _array(self, 1)
+ return _array(self, 1, example=True)
class GcArray(Array):
_gckind = 'gc'
@@ -422,7 +425,7 @@
def _container_example(self):
def ex(*args):
- return self.RESULT._defl()
+ return self.RESULT._defl(example=True)
return _func(self, _callable=ex)
def _trueargs(self):
@@ -445,7 +448,7 @@
def _container_example(self):
return _opaque(self)
- def _defl(self, parent=None, parentindex=None):
+ def _defl(self, parent=None, parentindex=None, example=False):
return _opaque(self, parent=parent, parentindex=parentindex)
RuntimeTypeInfo = OpaqueType("RuntimeTypeInfo")
@@ -466,7 +469,7 @@
return "PyObject"
def _inline_is_varsize(self, last):
return False
- def _defl(self, parent=None, parentindex=None):
+ def _defl(self, parent=None, parentindex=None, example=False):
return _pyobjheader(parent, parentindex)
PyObject = PyObjectType()
@@ -505,13 +508,16 @@
def __str__(self):
return self._name
- def _defl(self, parent=None, parentindex=None):
+ def _defl(self, parent=None, parentindex=None, example=False):
+ if not example and self is not Void:
+ return Uninitialized
return self._default
def _is_atomic(self):
return True
- _example = _defl
+ def _example(self, parent=None, parentindex=None, example=False):
+ return self._default
class Number(Primitive):
@@ -574,8 +580,11 @@
def _is_atomic(self):
return self.TO._gckind == 'raw'
- def _defl(self, parent=None, parentindex=None):
- return _ptr(self, None)
+ def _defl(self, parent=None, parentindex=None, example=False):
+ if example or self._needsgc:
+ return _ptr(self, None)
+ else:
+ return Uninitialized
def _example(self):
o = self.TO._container_example()
@@ -589,6 +598,8 @@
try:
return val._TYPE
except AttributeError:
+ if val is Uninitialized:
+ raise UninitializedMemoryAccess("typeOf uninitialized value")
tp = type(val)
if tp is NoneType:
return Void # maybe
@@ -826,6 +837,9 @@
class DelayedPointer(Exception):
pass
+class UninitializedMemoryAccess(Exception):
+ pass
+
class _ptr(object):
__slots__ = ('_TYPE', '_T',
'_weak', '_solid',
@@ -920,6 +934,9 @@
if isinstance(self._T, Struct):
if field_name in self._T._flds:
o = getattr(self._obj, field_name)
+ if o is Uninitialized:
+ raise UninitializedMemoryAccess(
+ "%r->%s"%(self, field_name))
return _expose(o, self._solid)
if isinstance(self._T, ContainerType):
try:
@@ -1193,11 +1210,11 @@
__slots__ = ()
- def __new__(self, TYPE, n=None, parent=None, parentindex=None):
+ def __new__(self, TYPE, n=None, parent=None, parentindex=None, example=False):
my_variety = _struct_variety(TYPE._names)
return object.__new__(my_variety)
- def __init__(self, TYPE, n=None, parent=None, parentindex=None):
+ def __init__(self, TYPE, n=None, parent=None, parentindex=None, example=False):
_parentable.__init__(self, TYPE)
if n is not None and TYPE._arrayfld is None:
raise TypeError("%r is not variable-sized" % (TYPE,))
@@ -1206,9 +1223,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)
+ value = _array(typ, n, parent=self, parentindex=fld, example=example)
else:
- value = typ._defl(parent=self, parentindex=fld)
+ value = typ._defl(parent=self, parentindex=fld, example=example)
setattr(self, fld, value)
if parent is not None:
self._setparentstructure(parent, parentindex)
@@ -1227,7 +1244,7 @@
for name in names:
T = self._TYPE._flds[name]
if isinstance(T, Primitive):
- reprvalue = repr(getattr(self, name))
+ reprvalue = repr(getattr(self, name, '<uninitialized>'))
else:
reprvalue = '...'
fields.append('%s=%s' % (name, reprvalue))
@@ -1270,13 +1287,13 @@
__slots__ = ('items',)
- def __init__(self, TYPE, n, parent=None, parentindex=None):
+ def __init__(self, TYPE, n, parent=None, parentindex=None, example=False):
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)
+ self.items = [TYPE.OF._defl(parent=self, parentindex=j, example=example)
for j in range(n)]
if parent is not None:
self._setparentstructure(parent, parentindex)
@@ -1285,6 +1302,8 @@
return '<%s>' % (self,)
def _str_item(self, item):
+ if type(item) is object:
+ return '#'
if isinstance(self._TYPE.OF, Struct):
of = self._TYPE.OF
if self._TYPE._anonym_struct:
@@ -1319,7 +1338,10 @@
def getitem(self, index):
try:
- return self.items[index]
+ v = self.items[index]
+ if v is Uninitialized:
+ raise UninitializedMemoryAccess("%r[%s]"%(self, index))
+ return v
except IndexError:
if (self._TYPE._hints.get('isrpystring', False) and
index == len(self.items)):
@@ -1502,11 +1524,11 @@
return "pyobjheader of type %r" % (getattr(self, 'ob_type', '???'),)
-def malloc(T, n=None, flavor='gc', immortal=False, extra_args=()):
+def malloc(T, n=None, flavor='gc', immortal=False, extra_args=(), zero=False):
if isinstance(T, Struct):
- o = _struct(T, n)
+ o = _struct(T, n, example=zero)
elif isinstance(T, Array):
- o = _array(T, n)
+ o = _array(T, n, example=zero)
else:
raise TypeError, "malloc for Structs and Arrays only"
if T._gckind != 'gc' and not immortal and flavor.startswith('gc'):
Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rdict.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rdict.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rdict.py Wed Aug 23 13:17:08 2006
@@ -551,7 +551,7 @@
def ll_newdict(DICT):
d = lltype.malloc(DICT)
d.entries = lltype.malloc(DICT.entries.TO, DICT_INITSIZE)
- #d.num_items = 0 -- defaults
+ d.num_items = 0
d.num_pristine_entries = DICT_INITSIZE
return d
@@ -562,7 +562,7 @@
n *= 2
d = lltype.malloc(DICT)
d.entries = lltype.malloc(DICT.entries.TO, n)
- #d.num_items = 0 -- defaults
+ d.num_items = 0
d.num_pristine_entries = DICT_INITSIZE
return d
Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rstr.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/rstr.py Wed Aug 23 13:17:08 2006
@@ -48,6 +48,7 @@
p = malloc(STR, len(value))
for i in range(len(value)):
p.chars[i] = value[i]
+ p.hash = 0
self.ll.ll_strhash(p) # precompute the hash
CONST_STR_CACHE[value] = p
return p
Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/test/test_lltype.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/test/test_lltype.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/test/test_lltype.py Wed Aug 23 13:17:08 2006
@@ -10,13 +10,12 @@
s0 = malloc(S0)
print s0
assert typeOf(s0) == Ptr(S0)
- assert s0.a == 0
- assert s0.b == 0
- assert typeOf(s0.a) == Signed
+ py.test.raises(UninitializedMemoryAccess, "s0.a")
s0.a = 1
s0.b = s0.a
assert s0.a == 1
assert s0.b == 1
+ assert typeOf(s0.a) == Signed
# simple array
Ar = GcArray(('v', Signed))
x = malloc(Ar,0)
@@ -26,11 +25,10 @@
print x
assert typeOf(x) == Ptr(Ar)
assert isweak(x[0], Ar.OF)
- assert typeOf(x[0].v) == Signed
- assert x[0].v == 0
x[0].v = 1
x[1].v = 2
x[2].v = 3
+ assert typeOf(x[0].v) == Signed
assert [x[z].v for z in range(3)] == [1, 2, 3]
#
def define_list(T):
@@ -94,10 +92,12 @@
S1 = GcStruct("s1", ('a', Signed), ('rest', Array(('v', Signed))))
py.test.raises(TypeError, "malloc(S1)")
s1 = malloc(S1, 4)
+ s1.a = 0
assert s1.a == 0
assert isweak(s1.rest, S1.rest)
assert len(s1.rest) == 4
assert isweak(s1.rest[0], S1.rest.OF)
+ s1.rest[0].v = 0
assert typeOf(s1.rest[0].v) == Signed
assert s1.rest[0].v == 0
py.test.raises(IndexError, "s1.rest[4]")
@@ -206,7 +206,6 @@
S1 = GcStruct("s1", ('sub1', S2), ('sub2', S2), ('tail', Array(('e', Signed))))
p1 = malloc(S1, 1)
p2 = p1.sub2
- assert p2.a == 0
p3 = p1.tail
p3[0].e = 1
assert p3[0].e == 1
@@ -220,8 +219,6 @@
A1 = GcArray(('v', Signed))
p1 = malloc(A1, 10)
p1[5].v=3
- assert p1[0].v == 0
- assert p1[9].v == 0
assert p1[5].v == 3
p1_5 = p1[5]
del p1
@@ -327,9 +324,7 @@
As = GcArray(Signed)
a = malloc(As, 3)
assert typeOf(a) == Ptr(As)
- assert a[0] == 0
- assert a[1] == 0
- assert a[2] == 0
+ py.test.raises(UninitializedMemoryAccess, "a[0]")
a[1] = 3
assert a[1] == 3
S = GcStruct('s', ('x', Signed))
@@ -398,10 +393,13 @@
S = GcStruct('s', ('x', Signed))
attachRuntimeTypeInfo(S)
s = malloc(S)
+ s.x = 0
assert runtime_type_info(s) == getRuntimeTypeInfo(S)
S1 = GcStruct('s1', ('sub', S), ('x', Signed))
attachRuntimeTypeInfo(S1)
s1 = malloc(S1)
+ s1.sub.x = 0
+ s1.x = 0
assert runtime_type_info(s1) == getRuntimeTypeInfo(S1)
assert runtime_type_info(s1.sub) == getRuntimeTypeInfo(S1)
assert runtime_type_info(cast_pointer(Ptr(S), s1)) == getRuntimeTypeInfo(S1)
Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/test/test_picklelltype.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/test/test_picklelltype.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/lltypesystem/test/test_picklelltype.py Wed Aug 23 13:17:08 2006
@@ -92,6 +92,9 @@
S1 = GcStruct("s1", ('a', Signed), ('rest', Array(('v', Signed))))
py.test.raises(TypeError, "malloc(S1)")
s1 = malloc(S1, 4)
+ s1.a = 0
+ for i in range(4):
+ s1.rest[i].v = 0
p_s1 = pickle.dumps(s1)
r_s1 = pickle.loads(p_s1)
assert r_s1.a == 0
@@ -166,6 +169,8 @@
def test_best_effort_gced_parent_for_arrays():
A1 = GcArray(('v', Signed))
p1 = malloc(A1, 10)
+ for i in range(10):
+ p1[i].v = 0
p1[5].v = 3
p1_5 = p1[5]
r_p1_5 = pickle.loads(pickle.dumps(p1_5))
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 Wed Aug 23 13:17:08 2006
@@ -30,7 +30,7 @@
class Class(OOType):
- def _defl(self):
+ def _defl(self, example=False):
return nullruntimeclass
Class = Class()
@@ -66,7 +66,7 @@
def __hash__(self):
return object.__hash__(self)
- def _defl(self):
+ def _defl(self, example=False):
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())
+ fields[name] = (defn, defn._defl(example=True))
else:
ootype, default = defn
@@ -195,7 +195,7 @@
_retval = self.RESULT._example()
return _static_meth(self, _callable=lambda *args: _retval)
- def _defl(self):
+ def _defl(self, example=False):
return null(self)
def __repr__(self):
@@ -219,7 +219,7 @@
def _example(self):
return new(self)
- def _defl(self):
+ def _defl(self, example=False):
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()
+ self._fields[name] = ITEMTYPE, ITEMTYPE._defl(example=True)
self._null = _null_record(self)
- def _defl(self):
+ def _defl(self, example=False):
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):
+ def _defl(self, example=False):
return make_string("")
def _example(self):
return self._defl()
@@ -344,7 +344,7 @@
})
self._setup_methods({})
- def _defl(self):
+ def _defl(self, example=False):
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):
+ def _defl(self, example=False):
return self._null
def _set_itemtype(self, ITEMTYPE):
Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/rcpy.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/rcpy.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/rcpy.py Wed Aug 23 13:17:08 2006
@@ -255,7 +255,8 @@
# build the PyTypeObject structure
pytypeobj = lltype.malloc(PY_TYPE_OBJECT, flavor='cpy',
- extra_args=(typetype,))
+ extra_args=(typetype,),
+ zero=True)
name = cpytype.name
T = lltype.FixedSizeArray(lltype.Char, len(name)+1)
p = lltype.malloc(T, immortal=True)
Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/test/test_llinterp.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/test/test_llinterp.py (original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/test/test_llinterp.py Wed Aug 23 13:17:08 2006
@@ -1,4 +1,3 @@
-
import py
from pypy.rpython.lltypesystem.lltype import typeOf, pyobjectptr, Ptr, PyObject, Void
from pypy.rpython.lltypesystem.lloperation import llop
More information about the Pypy-commit
mailing list