[pypy-svn] r32405 - in pypy/dist/pypy: annotation rpython/lltypesystem
arigo at codespeak.net
arigo at codespeak.net
Sun Sep 17 12:17:30 CEST 2006
Author: arigo
Date: Sun Sep 17 12:17:28 2006
New Revision: 32405
Modified:
pypy/dist/pypy/annotation/binaryop.py
pypy/dist/pypy/annotation/unaryop.py
pypy/dist/pypy/rpython/lltypesystem/lltype.py
Log:
Support for annotator-propagated length of FixedSizeArrays,
and for no crashing on FixedSizeArrays of length 0.
Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py (original)
+++ pypy/dist/pypy/annotation/binaryop.py Sun Sep 17 12:17:28 2006
@@ -661,7 +661,11 @@
class __extend__(pairtype(SomePtr, SomeInteger)):
def getitem((p, int1)):
- v = p.ll_ptrtype._example()[0]
+ example = p.ll_ptrtype._example()
+ try:
+ v = example[0]
+ except IndexError:
+ return None # impossible value, e.g. FixedSizeArray(0)
return ll_to_annotation(v)
getitem.can_only_throw = []
@@ -784,24 +788,6 @@
pass
def getitem((s_cto, s_index)):
- if s_index.is_immutable_constant():
- # check that the constant index is valid, just because we
- # are nice (users should really catch such errors by
- # testing their programs!)
- idx = s_index.const
- knowntype = s_cto.knowntype
- try:
- length = knowntype._length_
- except AttributeError:
- pass
- else:
- if idx < 0:
- idx += length
- if idx >= length:
- raise IndexError( "invalid index" )
- elif idx < 0:
- raise IndexError( "invalid index" )
-
# Note: The following works for index either pointers and arrays,
# because both have a _type_ attribute that contains the type of the
# object pointed to or in the case of an array the element type.
Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py (original)
+++ pypy/dist/pypy/annotation/unaryop.py Sun Sep 17 12:17:28 2006
@@ -614,8 +614,11 @@
getattr.can_only_throw = []
def len(p):
- len(p.ll_ptrtype._example()) # just doing checking
- return SomeObject.len(p)
+ length = p.ll_ptrtype._example()._fixedlength()
+ if length is None:
+ return SomeObject.len(p)
+ else:
+ return immutablevalue(length)
def setattr(p, s_attr, s_value): # just doing checking
assert s_attr.is_constant(), "setattr on ptr %r with non-constant field-name" % p.ll_ptrtype
Modified: pypy/dist/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/lltype.py Sun Sep 17 12:17:28 2006
@@ -1051,6 +1051,13 @@
return self._obj.getlength()
raise TypeError("%r instance is not an array" % (self._T,))
+ def _fixedlength(self):
+ length = len(self) # always do this, for the checking
+ if isinstance(self._T, FixedSizeArray):
+ return length
+ else:
+ return None
+
def __iter__(self):
# this is a work-around for the 'isrpystring' hack in __getitem__,
# which otherwise causes list(p) to include the extra \x00 character.
More information about the Pypy-commit
mailing list