[pypy-svn] r25625 - in pypy/dist/pypy/rpython/lltypesystem: . test
arigo at codespeak.net
arigo at codespeak.net
Sun Apr 9 16:49:18 CEST 2006
Author: arigo
Date: Sun Apr 9 16:49:17 2006
New Revision: 25625
Modified:
pypy/dist/pypy/rpython/lltypesystem/lltype.py
pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py
Log:
(arre, arigo)
Mostly revert r25613: these conversions are horribly messy to implement.
They would make the back-ends' life not much fun too.
Modified: pypy/dist/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/lltype.py Sun Apr 9 16:49:17 2006
@@ -612,24 +612,6 @@
raise TypeError, "can only cast pointers to other pointers"
return ptr._cast_to(PTRTYPE)
-def cast_array_pointer(PTRTYPE, ptr):
- CURTYPE = typeOf(ptr)
- if not isinstance(CURTYPE, Ptr) or not isinstance(PTRTYPE, Ptr):
- raise TypeError, "can only cast pointers to other pointers"
- if (not isinstance(PTRTYPE.TO, Array) or
- not PTRTYPE.TO._hints.get('nolength', False)):
- raise TypeError, "can only convert to nolength Arrays"
- if isinstance(CURTYPE.TO, Array):
- if CURTYPE.TO._hints.get('nolength', False):
- raise TypeError, "cannot convert from a nolength Array"
- elif isinstance(CURTYPE.TO, FixedSizeArray):
- pass
- else:
- raise TypeError, "can only convert from an array"
- if CURTYPE.TO.OF != PTRTYPE.TO.OF:
- raise TypeError, "pointers to arrays of different item types"
- return ptr._cast_array_to(PTRTYPE)
-
def _expose(val, solid=False):
"""XXX A nice docstring here"""
T = typeOf(val)
@@ -710,8 +692,7 @@
def _setobj(self, pointing_to, solid=False):
if pointing_to is None:
obj0 = None
- elif (solid or isinstance(self._T, (GC_CONTAINER, FuncType))
- or isinstance(pointing_to, _nolengtharray)):
+ elif solid or isinstance(self._T, (GC_CONTAINER, FuncType)):
obj0 = pointing_to
else:
self._set_weak(True)
@@ -861,9 +842,6 @@
raise TypeError("widening %r inside %r instead of %r" % (CURTYPE, PARENTTYPE, PTRTYPE.TO))
return _ptr(PTRTYPE, struc, solid=self._solid)
- def _cast_array_to(self, PTRTYPE):
- return _ptr(PTRTYPE, _nolengtharray(PTRTYPE.TO, self._obj))
-
def _cast_to_int(self):
obj = self._obj
while obj._parentstructure():
@@ -1032,32 +1010,6 @@
def setitem(self, index, value):
self.items[index] = value
-class _nolengtharray(object):
- _kind = "array"
-
- __slots__ = ('_TYPE', 'wr_parentarray')
-
- def __init__(self, TYPE, parentarray):
- self._TYPE = TYPE
- self.wr_parentarray = pickleable_weakref(parentarray)
-
- def getparentarray(self):
- parentarray = self.wr_parentarray()
- if parentarray is None:
- raise RuntimeError("accessing already garbage collected %r"
- % (self._T,))
- return parentarray
-
- def getlength(self):
- # for debugging only
- return self.getparentarray().getlength()
-
- def getitem(self, index):
- return self.getparentarray().getitem(index)
-
- def setitem(self, index, value):
- return self.getparentarray().setitem(index, value)
-
assert not '__dict__' in dir(_array)
assert not '__dict__' in dir(_struct)
Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py Sun Apr 9 16:49:17 2006
@@ -519,50 +519,6 @@
a = malloc(A, 10)
py.test.raises(TypeError, len, a)
-def test_cast_length_to_no_length():
- A = Array(Char, hints={'nolength': True})
- S = GcStruct("str", ("hash", Signed),
- ("chars", Array(Char)))
- s = malloc(S, 5)
- s.chars[0] = 'h'
- s.chars[1] = 'e'
- s.chars[2] = 'l'
- s.chars[3] = 'l'
- s.chars[4] = 'o'
- a = cast_array_pointer(Ptr(A), s.chars)
- assert a[0] == 'h'
- assert a[1] == 'e'
- assert a[2] == 'l'
- assert a[3] == 'l'
- assert a[4] == 'o'
- py.test.raises(TypeError, len, a)
- a[1] = 'E'
- assert s.chars[1] == 'E'
- s.chars[2] = 'L'
- assert a[2] == 'L'
-
-def test_cast_fixed_to_no_length():
- A = Array(Char, hints={'nolength': True})
- S = GcStruct("str", ("hash", Signed),
- ("chars", FixedSizeArray(Char, 5)))
- s = malloc(S)
- s.chars[0] = 'h'
- s.chars[1] = 'e'
- s.chars[2] = 'l'
- s.chars[3] = 'l'
- s.chars[4] = 'o'
- a = cast_array_pointer(Ptr(A), s.chars)
- assert a[0] == 'h'
- assert a[1] == 'e'
- assert a[2] == 'l'
- assert a[3] == 'l'
- assert a[4] == 'o'
- py.test.raises(TypeError, len, a)
- a[1] = 'E'
- assert s.chars[1] == 'E'
- s.chars[2] = 'L'
- assert a[2] == 'L'
-
def test_dissect_ll_instance():
assert list(dissect_ll_instance(1)) == [(Signed, 1)]
GcS = GcStruct("S", ('x', Signed))
More information about the Pypy-commit
mailing list