[pypy-svn] r31729 - pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes

mwh at codespeak.net mwh at codespeak.net
Sun Aug 27 15:37:13 CEST 2006


Author: mwh
Date: Sun Aug 27 15:37:12 2006
New Revision: 31729

Modified:
   pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/astringbuf.py
   pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rarray.py
   pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rchar_p.py
   pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rmodel.py
   pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rstringbuf.py
Log:
ctypes assumed zeroed memory, so rctypes gets it too.
also fix a couple of string allocations (need to write a helper for that, i
guess)


Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/astringbuf.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/astringbuf.py	(original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/astringbuf.py	Sun Aug 27 15:37:12 2006
@@ -34,7 +34,7 @@
         [v_length] = hop.inputargs(lltype.Signed)
         r_stringbuf = hop.r_result
         hop.exception_cannot_occur()
-        return hop.genop("malloc_varsize", [
+        return hop.genop("zero_malloc_varsize", [
             hop.inputconst(lltype.Void, r_stringbuf.lowleveltype.TO),
             v_length,
             ], resulttype=r_stringbuf.lowleveltype,

Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rarray.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rarray.py	(original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rarray.py	Sun Aug 27 15:37:12 2006
@@ -155,6 +155,7 @@
     p = box.c_data
     length = rchar_p.ll_strnlen(lltype.direct_arrayitems(p), len(p))
     newstr = lltype.malloc(string_repr.lowleveltype.TO, length)
+    newstr.hash = 0
     for i in range(length):
         newstr.chars[i] = p[i]
     return newstr

Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rchar_p.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rchar_p.py	(original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rchar_p.py	Sun Aug 27 15:37:12 2006
@@ -119,6 +119,7 @@
         return lltype.nullptr(string_repr.lowleveltype.TO)
     length = ll_strlen(p)
     newstr = lltype.malloc(string_repr.lowleveltype.TO, length)
+    newstr.hash = 0
     for i in range(length):
         newstr.chars[i] = p[i]
     return newstr
@@ -135,6 +136,7 @@
         else:
             length = ll_strlen(p)
         newstr = lltype.malloc(string_repr.lowleveltype.TO, length)
+        newstr.hash = 0
         for i in range(length):
             newstr.chars[i] = p[i]
         return newstr

Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rmodel.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rmodel.py	(original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rmodel.py	Sun Aug 27 15:37:12 2006
@@ -86,14 +86,14 @@
             return self.const_cache[key][0]
         except KeyError:
             self.setup()
-            p = lltype.malloc(self.r_memoryowner.lowleveltype.TO)
+            p = lltype.malloc(self.r_memoryowner.lowleveltype.TO, zero=True)
             self.initialize_const(p, value)
             if self.ownsmemory:
                 result = p
             else:
                 # we must return a non-memory-owning box that keeps the
                 # memory-owning box alive
-                result = lltype.malloc(self.lowleveltype.TO)
+                result = lltype.malloc(self.lowleveltype.TO, zero=True)
                 result.c_data = p.c_data    # initialize c_data pointer
                 result.c_data_owner_keepalive = p
             self.const_cache[key] = result, keepalive
@@ -123,14 +123,14 @@
         if TYPE._is_varsize():
             raise TyperError("allocating array with unknown length")
         c1 = inputconst(lltype.Void, TYPE)
-        return llops.genop("malloc", [c1], resulttype=self.lowleveltype)
+        return llops.genop("zero_malloc", [c1], resulttype=self.lowleveltype)
 
     def allocate_instance_varsize(self, llops, v_length):
         TYPE = self.lowleveltype.TO
         if not TYPE._is_varsize():
             raise TyperError("allocating non-array with a specified length")
         c1 = inputconst(lltype.Void, TYPE)
-        return llops.genop("malloc_varsize", [c1, v_length],
+        return llops.genop("zero_malloc_varsize", [c1, v_length],
                            resulttype=self.lowleveltype)
 
     def allocate_instance_ref(self, llops, v_c_data, v_c_data_owner=None):
@@ -277,8 +277,11 @@
                 subdst = dest[i]
                 reccopy(subsrc, subdst)
             else:
-                llvalue = source[i]
-                dest[i] = llvalue
+                try:
+                    llvalue = source[i]
+                    dest[i] = llvalue
+                except lltype.UninitializedMemoryAccess:
+                    pass # oh well
     elif isinstance(T, lltype.Struct):
         for name in T._names:
             FIELDTYPE = getattr(T, name)
@@ -287,8 +290,11 @@
                 subdst = getattr(dest,   name)
                 reccopy(subsrc, subdst)
             else:
-                llvalue = getattr(source, name)
-                setattr(dest, name, llvalue)
+                try:
+                    llvalue = getattr(source, name)
+                    setattr(dest, name, llvalue)
+                except lltype.UninitializedMemoryAccess:
+                    pass # oh well
     else:
         raise TypeError(T)
 

Modified: pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rstringbuf.py
==============================================================================
--- pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rstringbuf.py	(original)
+++ pypy/branch/no-zeroing-assumption/pypy/rpython/rctypes/rstringbuf.py	Sun Aug 27 15:37:12 2006
@@ -102,6 +102,7 @@
         start = stop
     newlength = stop - start
     newstr = lltype.malloc(string_repr.lowleveltype.TO, newlength)
+    newstr.hash = 0
     for i in range(newlength):
         newstr.chars[i] = sbuf[start + i]
     return newstr
@@ -122,6 +123,7 @@
     p = box.c_data
     length = len(p)
     newstr = lltype.malloc(string_repr.lowleveltype.TO, length)
+    newstr.hash = 0
     for i in range(length):
         newstr.chars[i] = p[i]
     return newstr



More information about the Pypy-commit mailing list