[pypy-svn] r27093 - in pypy/dist/pypy/rpython: . lltypesystem

antocuni at codespeak.net antocuni at codespeak.net
Thu May 11 20:23:17 CEST 2006


Author: antocuni
Date: Thu May 11 20:23:09 2006
New Revision: 27093

Modified:
   pypy/dist/pypy/rpython/lltypesystem/rstr.py
   pypy/dist/pypy/rpython/rstr.py
Log:
Fixed a robject bug due to rstr refactoring.



Modified: pypy/dist/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rstr.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rstr.py	Thu May 11 20:23:09 2006
@@ -76,34 +76,33 @@
 
 
 
-class __extend__(pairtype(PyObjRepr, StringRepr)):
-    def convert_from_to((r_from, r_to), v, llops):
-        v_len = llops.gencapicall('PyString_Size', [v], resulttype=Signed)
-        cstr = inputconst(Void, STR)
-        v_result = llops.genop('malloc_varsize', [cstr, v_len],
-                               resulttype=Ptr(STR))
-        cchars = inputconst(Void, "chars")
-        v_chars = llops.genop('getsubstruct', [v_result, cchars],
-                              resulttype=Ptr(STR.chars))
-        llops.gencapicall('PyString_ToLLCharArray', [v, v_chars])
-        string_repr = llops.rtyper.type_system.rstr.string_repr
-        v_result = llops.convertvar(v_result, string_repr, r_to)
-        return v_result
-
-class __extend__(pairtype(StringRepr, PyObjRepr)):
-    def convert_from_to((r_from, r_to), v, llops):
-        string_repr = llops.rtyper.type_system.rstr.string_repr
-        v = llops.convertvar(v, r_from, string_repr)
-        cchars = inputconst(Void, "chars")
-        v_chars = llops.genop('getsubstruct', [v, cchars],
-                              resulttype=Ptr(STR.chars))
-        v_size = llops.genop('getarraysize', [v_chars],
-                             resulttype=Signed)
-        # xxx put in table        
-        return llops.gencapicall('PyString_FromLLCharArrayAndSize',
-                                 [v_chars, v_size],
-                                 resulttype=pyobj_repr,
-                                 _callable= lambda chars, sz: pyobjectptr(''.join(chars)))
+
+def convert_PyObjRepr_StringRepr((r_from, r_to), v, llops):
+    v_len = llops.gencapicall('PyString_Size', [v], resulttype=Signed)
+    cstr = inputconst(Void, STR)
+    v_result = llops.genop('malloc_varsize', [cstr, v_len],
+                           resulttype=Ptr(STR))
+    cchars = inputconst(Void, "chars")
+    v_chars = llops.genop('getsubstruct', [v_result, cchars],
+                          resulttype=Ptr(STR.chars))
+    llops.gencapicall('PyString_ToLLCharArray', [v, v_chars])
+    string_repr = llops.rtyper.type_system.rstr.string_repr
+    v_result = llops.convertvar(v_result, string_repr, r_to)
+    return v_result
+
+def convert_StringRepr_PyObjRepr((r_from, r_to), v, llops):
+    string_repr = llops.rtyper.type_system.rstr.string_repr
+    v = llops.convertvar(v, r_from, string_repr)
+    cchars = inputconst(Void, "chars")
+    v_chars = llops.genop('getsubstruct', [v, cchars],
+                          resulttype=Ptr(STR.chars))
+    v_size = llops.genop('getarraysize', [v_chars],
+                         resulttype=Signed)
+    # xxx put in table        
+    return llops.gencapicall('PyString_FromLLCharArrayAndSize',
+                             [v_chars, v_size],
+                             resulttype=pyobj_repr,
+                             _callable= lambda chars, sz: pyobjectptr(''.join(chars)))
 
 
 

Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py	(original)
+++ pypy/dist/pypy/rpython/rstr.py	Thu May 11 20:23:09 2006
@@ -4,6 +4,7 @@
 from pypy.rpython.error import TyperError
 from pypy.rpython.rmodel import IntegerRepr, IteratorRepr
 from pypy.rpython.rmodel import AbstractStringRepr, CharRepr, inputconst, UniCharRepr
+from pypy.rpython.robject import PyObjRepr, pyobj_repr
 from pypy.rpython.lltypesystem.rtuple import TupleRepr # XXX type system!
 from pypy.rpython import rint
 from pypy.rpython.lltypesystem.rslice import SliceRepr # XXX type system!
@@ -439,6 +440,15 @@
             return llops.gendirectcall(r_from.ll.ll_stritem_nonneg, v, c_zero)
         return NotImplemented
 
+class __extend__(pairtype(PyObjRepr, AbstractStringRepr)):
+    def convert_from_to(this_pair, v, llops):
+        rstr = llops.rtyper.type_system.rstr
+        return rstr.convert_PyObjRepr_StringRepr(this_pair, v, llops)
+
+class __extend__(pairtype(AbstractStringRepr, PyObjRepr)):
+    def convert_from_to(this_pair, v, llops):
+        rstr = llops.rtyper.type_system.rstr
+        return rstr.convert_StringRepr_PyObjRepr(this_pair, v, llops)
 
 
 # ____________________________________________________________



More information about the Pypy-commit mailing list