[pypy-svn] r15635 - pypy/dist/pypy/rpython/memory

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Aug 4 18:50:08 CEST 2005


Author: cfbolz
Date: Thu Aug  4 18:50:07 2005
New Revision: 15635

Modified:
   pypy/dist/pypy/rpython/memory/lltypesimulation.py
Log:
factored out get_total_size (will need it in more places soon

Modified: pypy/dist/pypy/rpython/memory/lltypesimulation.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/lltypesimulation.py	(original)
+++ pypy/dist/pypy/rpython/memory/lltypesimulation.py	Thu Aug  4 18:50:07 2005
@@ -55,6 +55,16 @@
     else:
         assert 0, "not yet implemented"
 
+def get_total_size(TYPE, i=None):
+    fixedsize = get_fixed_size(TYPE)
+    varsize = get_variable_size(TYPE)
+    if i is None:
+        assert varsize == 0
+        return fixedsize
+    else:
+        return fixedsize + i * varsize
+    
+
 def _expose(T, address):
     """XXX A nice docstring here"""
     if isinstance(T, (lltype.Struct, lltype.Array)):
@@ -75,13 +85,7 @@
         self.__dict__['_layout'] = get_layout(TYPE.TO)
 
     def _zero_initialize(self, i=None):
-        fixedsize = get_fixed_size(self._T)
-        varsize = get_variable_size(self._T)
-        if i is None:
-            assert varsize == 0
-            size = fixedsize
-        else:
-            size = fixedsize + i * varsize
+        size = get_total_size(self._T, i)
         self._address._store("c" * size, *(["\x00"] * size))
 
     def _init_size(self, size):
@@ -192,8 +196,6 @@
     # I'm not sure whether this is the right way to go...
     return simulatorptr(PTRTYPE, ptr._address)
 
-
-
 # for now use the simulators raw_malloc
 def malloc(T, n=None, immortal=False):
     fixedsize = get_fixed_size(T)



More information about the Pypy-commit mailing list