Author: Armin Rigo <ar...@tunes.org>
Branch: null_byte_after_str
Changeset: r85914:8c4847b9f717
Date: 2016-07-29 18:46 +0200
http://bitbucket.org/pypy/pypy/changeset/8c4847b9f717/

Log:    Test, and fixes for tests

diff --git a/rpython/jit/backend/llsupport/test/ztranslation_test.py 
b/rpython/jit/backend/llsupport/test/ztranslation_test.py
--- a/rpython/jit/backend/llsupport/test/ztranslation_test.py
+++ b/rpython/jit/backend/llsupport/test/ztranslation_test.py
@@ -3,7 +3,7 @@
 from rpython.rlib.jit import JitDriver, unroll_parameters, set_param
 from rpython.rlib.jit import PARAMETERS, dont_look_inside
 from rpython.rlib.jit import promote, _get_virtualizable_token
-from rpython.rlib import jit_hooks, rposix
+from rpython.rlib import jit_hooks, rposix, rgc
 from rpython.rlib.objectmodel import keepalive_until_here
 from rpython.rlib.rthread import ThreadLocalReference, ThreadLocalField
 from rpython.jit.backend.detect_cpu import getcpuclass
@@ -11,7 +11,7 @@
 from rpython.jit.codewriter.policy import StopAtXPolicy
 from rpython.config.config import ConfigError
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rtyper.lltypesystem import lltype, rffi, rstr
 from rpython.rlib.rjitlog import rjitlog as jl
 
 
@@ -29,6 +29,7 @@
         # - floats neg and abs
         # - cast_int_to_float
         # - llexternal with macro=True
+        # - extra place for the zero after STR instances
 
         class BasicFrame(object):
             _virtualizable_ = ['i']
@@ -56,7 +57,7 @@
             return ("/home.py",0,0)
 
         jitdriver = JitDriver(greens = [],
-                              reds = ['total', 'frame', 'j'],
+                              reds = ['total', 'frame', 'prev_s', 'j'],
                               virtualizables = ['frame'],
                               get_location = get_location)
         def f(i, j):
@@ -68,9 +69,12 @@
             total = 0
             frame = Frame(i)
             j = float(j)
+            prev_s = rstr.mallocstr(16)
             while frame.i > 3:
-                jitdriver.can_enter_jit(frame=frame, total=total, j=j)
-                jitdriver.jit_merge_point(frame=frame, total=total, j=j)
+                jitdriver.can_enter_jit(frame=frame, total=total, j=j,
+                                        prev_s=prev_s)
+                jitdriver.jit_merge_point(frame=frame, total=total, j=j,
+                                          prev_s=prev_s)
                 _get_virtualizable_token(frame)
                 total += frame.i
                 if frame.i >= 20:
@@ -82,6 +86,11 @@
                 k = myabs1(myabs2(j))
                 if k - abs(j):  raise ValueError
                 if k - abs(-j): raise ValueError
+                s = rstr.mallocstr(16)
+                rgc.ll_write_final_null_char(s)
+                rgc.ll_write_final_null_char(prev_s)
+                if (frame.i & 3) == 0:
+                    prev_s = s
             return chr(total % 253)
         #
         class Virt2(object):
diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -1273,17 +1273,20 @@
 @no_collect
 @specialize.ll()
 def ll_write_final_null_char(s):
-    """'s' is a low-level STR; writes a NULL character after all the
-    other characters in 's'.  Warning, this only works because of
+    """'s' is a low-level STR; writes a terminating NULL character after
+    the other characters in 's'.  Warning, this only works because of
     the 'extra_item_after_alloc' hack inside the definition of STR.
     """
+    from rpython.rtyper.lltypesystem import rffi
     PSTR = lltype.typeOf(s)
     _check_final_null_char(PSTR)
-    # no GC operation here!
-    adr_s = llmemory.cast_ptr_to_adr(s)
-    adr_a = adr_s + llmemory.offsetof(PSTR.TO, 'chars')
-    adr_a += llmemory.itemoffsetof(PSTR.TO.chars, 0)
-    adr_a.char[len(s.chars)] = '\x00'
+    n = llmemory.offsetof(PSTR.TO, 'chars')
+    n += llmemory.itemoffsetof(PSTR.TO.chars, 0)
+    n = llmemory.raw_malloc_usage(n)
+    n += len(s.chars)
+    # no GC operation from here!
+    ptr = rffi.cast(rffi.CCHARP, s)
+    ptr[n] = '\x00'
 
 @specialize.memo()
 def _check_final_null_char(PSTR):
diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py 
b/rpython/rtyper/lltypesystem/ll2ctypes.py
--- a/rpython/rtyper/lltypesystem/ll2ctypes.py
+++ b/rpython/rtyper/lltypesystem/ll2ctypes.py
@@ -250,7 +250,9 @@
 
         if not A._hints.get('nolength'):
             _fields_ = [('length', lentype),
-                        ('items',  max_n * ctypes_item)]
+                        ('items',
+                           (max_n + A._hints.get('extra_item_after_alloc', 0))
+                           * ctypes_item)]
         else:
             _fields_ = [('items',  max_n * ctypes_item)]
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to