changeset 120:c7a5de2d2334

Fix issue of compute_size of various types
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 05 Aug 2011 21:51:35 +0800
parents 4f508f84c8a1
children 7644cb633d4b
files paraspace/dex_deptracker.py paraspace/dexfile.py
diffstat 2 files changed, 20 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dex_deptracker.py	Fri Aug 05 14:39:32 2011 +0800
+++ b/paraspace/dex_deptracker.py	Fri Aug 05 21:51:35 2011 +0800
@@ -878,10 +878,6 @@
     pass
 
 
-def _sync_dependencies():
-    pass
-
-
 ## \brief Prepare and return dependency declares.
 def prepare_dep_decls():
     decls = collect_all_dep_decls()
--- a/paraspace/dexfile.py	Fri Aug 05 14:39:32 2011 +0800
+++ b/paraspace/dexfile.py	Fri Aug 05 21:51:35 2011 +0800
@@ -107,17 +107,11 @@
     return len(_to_leb128(v))
 
 
-def _compute_sz(o):
+def _compute_sz(o, _type):
     if hasattr(o, 'compute_size'):
         o.compute_size()
-        pass
-    return o.data_size
-
-
-def _sum_data_size(obj_list):
-    obj_sizes = itertools.imap(_compute_sz, obj_list)
-    total = sum(obj_sizes)
-    return total
+        return o.data_size
+    return _type.sizeof(o)
 
 
 class _dex_type(object):
@@ -539,7 +533,8 @@
         return obj
 
     def compute_size(self):
-        sizes = [compute_size(item) for item in self.items]
+        sizes = [_compute_sz(item, self.child_type)
+                 for item in self.items]
         size = sum(sizes)
         self.data_size = size
         pass
@@ -587,10 +582,11 @@
         return obj
 
     def compute_size(self):
-        children = [getattr(self, child_name)
+        children = [(getattr(self, child_name),
+                     getattr(self.__class__, child_name))
                     for child_name in self.children()]
-        child_sizes = [compute_size(child)
-                       for child in children]
+        child_sizes = [_compute_sz(child, child_type)
+                       for child, child_type in children]
         self.data_size = sum(child_sizes)
         pass
 
@@ -642,11 +638,11 @@
         return self.child_type.sizeof(v.value)
 
     def compute_size(self):
-        if isinstance(self.value, relocatable):
-            self.value.compute_size()
+        if self.is_true:
+            self.data_size = _compute_sz(self.value, self.child_type)
+        else:
+            self.data_size = 0
             pass
-
-        self.data_size = self.sizeof(self.value)
         pass
 
     @staticmethod
@@ -707,11 +703,7 @@
         return v.child_type.sizeof(v.value)
 
     def compute_size(self):
-        if isinstance(self.value, relocatable):
-            self.value.compute_size()
-            pass
-
-        self.data_size = self.sizeof(self.value)
+        self.data_size = _compute_sz(self.value, self.child_type)
         pass
 
     @staticmethod
@@ -779,9 +771,7 @@
         return v
 
     def compute_size(self, child):
-        if issubclass(self.back_type, relocatable):
-            self.back_type.compute_size(child)
-            pass
+        _compute_sz(child, self.back_type)
         pass
 
     def to_str(self, child):
@@ -1401,6 +1391,8 @@
         return self
 
     def compute_size(self):
+        import itertools
+        
         def compute_opcode_size(code):
             opcode = code[0]
             
@@ -1656,6 +1648,9 @@
 
     def make_checksum(self):
         from paraspace.tools import adler32
+        
+        self.compute_size()
+        self.header.fileSize = self.sizeof(self)
         raw = self.to_str()
         sz = self.header.fileSize
         nosum = _DEX_header.magic.sizeof(self.header.magic) + \