Commits

Armin Rigo committed 1373174

More translation issues in ll_str2raw

Comments (0)

Files changed (1)

rpython/rtyper/lltypesystem/rbuilder.py

         # --- no GC! ---
         raw = rffi.cast(rffi.CCHARP, ll_builder.current_buf)
         rffi.c_memcpy(rffi.ptradd(raw, ofs),
-                      str2raw(ll_str, 0),
+                      ll_str2raw(ll_str, 0),
                       part1)
         # --- end ---
         # Next, the remaining part, in a new piece
         ll_assert(not ll_builder.current_buf, "after grow(), current_buf!=NULL")
         raw = lltype.nullptr(rffi.CCHARP.TO)
         rffi.c_memcpy(rffi.ptradd(raw, ofs),
-                      str2raw(ll_str, part1),
+                      ll_str2raw(ll_str, part1),
                       part2 * ll_builder.charsize)
         # --- end ---
 
     }
 )
 
-@specialize.ll()
-def str2raw(ll_str, charoffset):
+
+def ll_str2raw(ll_str, charoffset):
     STRTYPE = lltype.typeOf(ll_str).TO
-    raw_data = (llmemory.cast_ptr_to_adr(ll_str) +
-                llmemory.sizeof(STRTYPE, charoffset))
-    return rffi.cast(rffi.CCHARP, raw_data)
+    ofs = (rffi.offsetof(STRTYPE, 'chars') +
+           rffi.itemoffsetof(STRTYPE.chars, 0))
+    ofs = llmemory.raw_malloc_usage(ofs)    # for direct run
+    ofs += rffi.sizeof(STRTYPE.chars.OF) * charoffset
+    return rffi.ptradd(rffi.cast(rffi.CCHARP, ll_str), ofs)
 
-@specialize.ll()
-def rawsetitem(raw, byteoffset, char):
+def ll_rawsetitem(raw, byteoffset, char):
     raw = rffi.ptradd(raw, byteoffset)
     if lltype.typeOf(char) == lltype.Char:
         raw[0] = char
             # --- no GC! ---
             raw = rffi.cast(rffi.CCHARP, ll_builder.current_buf)
             rffi.c_memcpy(rffi.ptradd(raw, ofs),
-                          str2raw(ll_str, 0),
+                          ll_str2raw(ll_str, 0),
                           lgt)
             # --- end ---
 
             ofs = ll_builder.grow(ll_builder, 1)
         # --- no GC! ---
         raw = rffi.cast(rffi.CCHARP, ll_builder.current_buf)
-        rawsetitem(raw, ofs, char)
+        ll_rawsetitem(raw, ofs, char)
         # --- end ---
         ll_builder.current_ofs = ofs + ll_builder.charsize
 
             # --- no GC! ---
             raw = rffi.cast(rffi.CCHARP, ll_builder.current_buf)
             rffi.c_memcpy(rffi.ptradd(raw, ofs),
-                          str2raw(ll_str, start),
+                          ll_str2raw(ll_str, start),
                           lgt)
             # --- end ---
 
             # --- no GC! ---
             raw = rffi.cast(rffi.CCHARP, ll_builder.current_buf)
             while ofs < newofs:
-                rawsetitem(raw, ofs, char)
+                ll_rawsetitem(raw, ofs, char)
                 ofs += ll_builder.charsize
             # --- end ---
 
         ll_builder.current_ofs = 0
 
         # --- no GC! ---
-        dst = str2raw(result, final_size)
+        dst = ll_str2raw(result, final_size)
         while True:
             dst = rffi.ptradd(dst, -piece_lgt)
             rffi.c_memcpy(dst, extra.raw_ptr, piece_lgt)
         # --- end ---
 
         initial_len = len(ll_builder.initial_buf.chars)
-        ll_assert(dst == str2raw(result, initial_len), "bad first piece size")
+        ll_assert(dst == ll_str2raw(result, initial_len),
+                  "bad first piece size")
         cls.copy_string_contents_fn(ll_builder.initial_buf, result,
                                     0, 0, initial_len)
         return result