[pypy-svn] r78157 - pypy/trunk/pypy/rpython/lltypesystem

arigo at codespeak.net arigo at codespeak.net
Thu Oct 21 11:23:06 CEST 2010


Author: arigo
Date: Thu Oct 21 11:23:05 2010
New Revision: 78157

Modified:
   pypy/trunk/pypy/rpython/lltypesystem/llarena.py
   pypy/trunk/pypy/rpython/lltypesystem/rffi.py
Log:
A non-rpython version of str2charp that allocates an immortal string.


Modified: pypy/trunk/pypy/rpython/lltypesystem/llarena.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/llarena.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/llarena.py	Thu Oct 21 11:23:05 2010
@@ -440,7 +440,7 @@
                                    [rffi.INT],
                                    rffi.INT,
                                    sandboxsafe=True, _nowrapper=True)
-    _dev_zero = rffi.str2charp('/dev/zero')   # prebuilt
+    _dev_zero = rffi.str2charp_immortal('/dev/zero')   # prebuilt
 
     def clear_large_memory_chunk(baseaddr, size):
         # on some Unixy platforms, reading from /dev/zero is the fastest way

Modified: pypy/trunk/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/rffi.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/rffi.py	Thu Oct 21 11:23:05 2010
@@ -607,6 +607,15 @@
         return array
     str2charp._annenforceargs_ = [strtype]
 
+    def str2charp_immortal(s):
+        "NOT_RPYTHON"
+        array = lltype.malloc(TYPEP.TO, len(s) + 1, flavor='raw',
+                              immortal=True)
+        for i in range(len(s)):
+            array[i] = s[i]
+        array[len(s)] = lastchar
+        return array
+
     def free_charp(cp):
         lltype.free(cp, flavor='raw')
 
@@ -725,19 +734,19 @@
         l = [cp[i] for i in range(size)]
         return emptystr.join(l)
 
-    return (str2charp, free_charp, charp2str,
+    return (str2charp, str2charp_immortal, free_charp, charp2str,
             get_nonmovingbuffer, free_nonmovingbuffer,
             alloc_buffer, str_from_buffer, keep_buffer_alive_until_here,
             charp2strn, charpsize2str,
             )
 
-(str2charp, free_charp, charp2str,
+(str2charp, str2charp_immortal, free_charp, charp2str,
  get_nonmovingbuffer, free_nonmovingbuffer,
  alloc_buffer, str_from_buffer, keep_buffer_alive_until_here,
  charp2strn, charpsize2str,
  ) = make_string_mappings(str)
 
-(unicode2wcharp, free_wcharp, wcharp2unicode,
+(unicode2wcharp, unicode2wcharp_immortal, free_wcharp, wcharp2unicode,
  get_nonmoving_unicodebuffer, free_nonmoving_unicodebuffer,
  alloc_unicodebuffer, unicode_from_buffer, keep_unicodebuffer_alive_until_here,
  wcharp2unicoden, wcharpsize2unicode,



More information about the Pypy-commit mailing list