[pypy-svn] r51895 - in pypy/dist/pypy: rpython/lltypesystem rpython/memory rpython/memory/gctransform translator/c translator/js/test

arigo at codespeak.net arigo at codespeak.net
Wed Feb 27 10:16:39 CET 2008


Author: arigo
Date: Wed Feb 27 10:16:38 2008
New Revision: 51895

Modified:
   pypy/dist/pypy/rpython/lltypesystem/llmemory.py
   pypy/dist/pypy/rpython/lltypesystem/lltype.py
   pypy/dist/pypy/rpython/lltypesystem/rstr.py
   pypy/dist/pypy/rpython/memory/gctransform/transform.py
   pypy/dist/pypy/rpython/memory/gctypelayout.py
   pypy/dist/pypy/translator/c/node.py
   pypy/dist/pypy/translator/js/test/test_typed.py
Log:
issue356 resolved

kill the extra null character at the end of rpystrings.


Modified: pypy/dist/pypy/rpython/lltypesystem/llmemory.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/llmemory.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/llmemory.py	Wed Feb 27 10:16:38 2008
@@ -237,8 +237,6 @@
             count = rest[0].repeat
         else:
             count = 0
-        if self.TYPE._hints.get('isrpystring'):
-            count -= 1  # because malloc() will give us the extra char for free
         p = lltype.malloc(parenttype or self.TYPE, count,
                           immortal = self.TYPE._gckind == 'raw',
                           zero = zero)

Modified: pypy/dist/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/lltype.py	Wed Feb 27 10:16:38 2008
@@ -1068,15 +1068,6 @@
         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.
-        if isinstance(self._T, (Array, FixedSizeArray)):
-            for i in range(self._obj.getlength()):
-                yield self[i]
-        else:
-            raise TypeError("%r instance is not an array" % (self._T,))
-
     def __repr__(self):
         return '<%s>' % (self,)
 
@@ -1497,37 +1488,16 @@
 
     def getbounds(self):
         stop = len(self.items)
-        if self._TYPE._hints.get('isrpystring', False):
-            # special hack for the null terminator
-            assert self._TYPE.OF == Char
-            stop += 1
         return 0, stop
 
     def getitem(self, index, uninitialized_ok=False):
-        try:
-            v = self.items[index]
-            if isinstance(v, _uninitialized) and not uninitialized_ok:
-                raise UninitializedMemoryAccess("%r[%s]"%(self, index))
-            return v
-        except IndexError:
-            if (self._TYPE._hints.get('isrpystring', False) and
-                index == len(self.items)):
-                # special hack for the null terminator
-                assert self._TYPE.OF == Char
-                return '\x00'
-            raise
+        v = self.items[index]
+        if isinstance(v, _uninitialized) and not uninitialized_ok:
+            raise UninitializedMemoryAccess("%r[%s]"%(self, index))
+        return v
 
     def setitem(self, index, value):
-        try:
-            self.items[index] = value
-        except IndexError:
-            if (self._TYPE._hints.get('isrpystring', False) and
-                index == len(self.items)):
-                # special hack for the null terminator: can overwrite it
-                # with another null
-                assert value == '\x00'
-                return
-            raise
+        self.items[index] = value
 
 assert not '__dict__' in dir(_array)
 assert not '__dict__' in dir(_struct)

Modified: pypy/dist/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rstr.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rstr.py	Wed Feb 27 10:16:38 2008
@@ -48,8 +48,7 @@
     return emptyunicode
 
 STR.become(GcStruct('rpy_string', ('hash',  Signed),
-                    ('chars', Array(Char, hints={'immutable': True,
-                                                 'isrpystring': True})),
+                    ('chars', Array(Char, hints={'immutable': True})),
                     adtmeths={'malloc' : staticAdtMethod(mallocstr),
                               'empty'  : staticAdtMethod(emptystrfun)}))
 UNICODE.become(GcStruct('rpy_unicode', ('hash', Signed),

Modified: pypy/dist/pypy/rpython/memory/gctransform/transform.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctransform/transform.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctransform/transform.py	Wed Feb 27 10:16:38 2008
@@ -559,10 +559,7 @@
         else:
             ARRAY = TYPE
         assert isinstance(ARRAY, lltype.Array)
-        if ARRAY._hints.get('isrpystring', False):
-            c_const_size = intconst(llmemory.sizeof(TYPE, 1))
-        else:
-            c_const_size = intconst(llmemory.sizeof(TYPE, 0))
+        c_const_size = intconst(llmemory.sizeof(TYPE, 0))
         c_item_size = intconst(llmemory.sizeof(ARRAY.OF))
 
         if ARRAY._hints.get("nolength", False):

Modified: pypy/dist/pypy/rpython/memory/gctypelayout.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gctypelayout.py	(original)
+++ pypy/dist/pypy/rpython/memory/gctypelayout.py	Wed Feb 27 10:16:38 2008
@@ -160,9 +160,6 @@
             ofs1 = llmemory.offsetof(TYPE, TYPE._arrayfld)
             info.ofstolength = ofs1 + llmemory.ArrayLengthOffset(ARRAY)
             info.ofstovar = ofs1 + llmemory.itemoffsetof(ARRAY, 0)
-            # XXX we probably don't need isrpystring any more
-            if ARRAY._hints.get('isrpystring'):
-                info.fixedsize = llmemory.sizeof(TYPE, 1)
         else:
             ARRAY = TYPE
             info.ofstolength = llmemory.ArrayLengthOffset(ARRAY)

Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py	(original)
+++ pypy/dist/pypy/translator/c/node.py	Wed Feb 27 10:16:38 2008
@@ -200,9 +200,6 @@
         self.LLTYPE = ARRAY
         original_varlength = varlength
         self.gcfields = []
-        
-        if ARRAY._hints.get('isrpystring'):
-            varlength += 1   # for the NUL char terminator at the end of the string
         self.varlength = varlength
         if original_varlength == 1:
             basename = 'array'
@@ -597,8 +594,6 @@
             yield '}'
         elif self.T.OF == Char:
             s = ''.join(self.obj.items)
-            if self.T._hints.get('isrpystring', False):
-                s += '\x00'
             yield '\t%s%s' % (length, c_char_array_constant(s))
             yield '}'
         else:

Modified: pypy/dist/pypy/translator/js/test/test_typed.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_typed.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_typed.py	Wed Feb 27 10:16:38 2008
@@ -158,7 +158,6 @@
             assert res == testfn_endswith(i, j)
 
 def test_str_join():
-    #py.test.skip("issue with malloc_varsize of varsized struct (rpystring here)")
     #py.test.skip("stringBuilder support")
     def testfn(i, j):
         s1 = [ '', ',', ' and ']



More information about the Pypy-commit mailing list