Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r60900:266b2f7ea599
Date: 2013-02-06 11:10 +0100
http://bitbucket.org/pypy/pypy/changeset/266b2f7ea599/

Log:    Calling str() on bytearrays in RPython.

diff --git a/rpython/rtyper/lltypesystem/rbytearray.py 
b/rpython/rtyper/lltypesystem/rbytearray.py
--- a/rpython/rtyper/lltypesystem/rbytearray.py
+++ b/rpython/rtyper/lltypesystem/rbytearray.py
@@ -57,6 +57,17 @@
             p.chars[i] = chr(c)
         return p
 
+    def ll_str(self, ll_b):
+        from rpython.rtyper.lltypesystem.rstr import mallocstr, STR
+        if ll_b:
+            lgt = ll_b.length()
+            ll_s = mallocstr(lgt)
+            for i in range(lgt):
+                ll_s.chars[i] = ll_b.chars[i]
+            return ll_s
+        else:
+            return lltype.nullptr(STR)
+
 bytearray_repr = ByteArrayRepr()
 
 def hlbytearray(ll_b):
diff --git a/rpython/rtyper/test/test_rbytearray.py 
b/rpython/rtyper/test/test_rbytearray.py
--- a/rpython/rtyper/test/test_rbytearray.py
+++ b/rpython/rtyper/test/test_rbytearray.py
@@ -43,3 +43,10 @@
 
         ll_res = self.interpret(f, [llstr("abc"), 1, ord('d')])
         assert ll_res == ord('d') + ord('c') * 255
+
+    def test_str_of_bytearray(self):
+        def f(x):
+            return str(bytearray(str(x)))
+
+        ll_res = self.interpret(f, [123])
+        assert hlstr(ll_res) == "123"
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to