changeset 29:b0cc5da28141

pass parents to travel info
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 09 Jun 2011 09:32:17 +0800
parents 5ce7ca1187b3
children e790c6b2d5d9
files paraspace/dex_deptracker.py paraspace/dexfile.py paraspace/tests/dexfile_test.py
diffstat 3 files changed, 37 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dex_deptracker.py	Tue Jun 07 22:57:28 2011 +0800
+++ b/paraspace/dex_deptracker.py	Thu Jun 09 09:32:17 2011 +0800
@@ -184,7 +184,7 @@
 def _travel_dex_relocatable(root_obj, parents=[]):
     stk = [(root_obj, parents, root_obj.__class__.__name__)]
     
-    def make_travel_info(obj, obj_name, child_name):
+    def make_travel_info(obj, obj_name, child_name, parents):
         child_parents = parents + [obj]
         child_obj = _dex_tree_get_child(obj, child_name)
         if isinstance(child_obj, dexfile.composite):
@@ -199,7 +199,7 @@
         yield (obj, parents, obj_name)
         
         if isinstance(obj, list):
-            children = [make_travel_info(obj, obj_name, repr(idx))
+            children = [make_travel_info(obj, obj_name, repr(idx), parents)
                         for idx in range(len(obj))]
             stk.extend(children)
             continue
@@ -207,7 +207,7 @@
         if not isinstance(obj, dexfile.relocatable):
             continue
 
-        children = [make_travel_info(obj, obj_name, child_name)
+        children = [make_travel_info(obj, obj_name, child_name, parents)
                     for child_name in obj.children()]
         stk.extend(children)
         pass
@@ -314,9 +314,17 @@
         rev_parents.reverse()
 
         for parent in rev_parents:
-            rel_marker_info = getattr(parent, 'rel_marker_info', {})
-            items = getattr(parent, name_path, [])
-            items.append(obj)
+            try:
+                rel_marker_info = parent.rel_marker_info
+            except AttributeError:
+                try:
+                    rel_marker_info = {}
+                    parent.rel_marker_info = rel_marker_info
+                except AttributeError:
+                    continue
+                pass
+            depons = rel_marker_info.setdefault(name_path, [])
+            depons.append(obj)
             pass
         pass
 
@@ -332,6 +340,7 @@
                 continue
             if name_path in rel_marker_info:
                 depons = rel_marker_info[name_path]
+                print parent, depons
                 assert len(depons) == 1
                 depon = depons[0]
                 return depon
@@ -497,18 +506,14 @@
     #
     for obj, parents, name_path in \
             _travel_dex_relocatable(root_obj):
-        print name_path
         if name_path not in all_dep_decls:
             continue
 
-        rev_parents = list(parents)
-        rev_parents.reverse()
-        
         dep = all_dep_decls[name_path]
         dep_type = dep[0]
         if dep_type == dexfile.depend_off_rel:
-            depon1 = _rel_offset_marker.find_depon(dep[1])
-            depon2 = _rel_offset_marker.find_depon(dep[2])
+            depon1 = _rel_offset_marker.find_depon(dep[1], parents)
+            depon2 = _rel_offset_marker.find_depon(dep[2], parents)
 
             parent = parents[-1]
             name = name_path.split('.')[-1]
--- a/paraspace/dexfile.py	Tue Jun 07 22:57:28 2011 +0800
+++ b/paraspace/dexfile.py	Thu Jun 09 09:32:17 2011 +0800
@@ -404,6 +404,24 @@
     pass
 
 
+class rel_marker_info_check_also(relocatable):
+    name_path = None
+    back_type = None
+    
+    def __init__(self, name_path, back_type):
+        if not isinstance(back_type, array):
+            raise TypeError, 'back type should be a dexfile.array'
+        
+        self.name_path = name_path
+        self.back_type = back_type
+        pass
+
+    def parse(self, parent, data, off):
+        child = self.back_type.parse(parent, data, off)
+        return child
+    pass
+
+
 class composite(relocatable):
     child_names = None
 
--- a/paraspace/tests/dexfile_test.py	Tue Jun 07 22:57:28 2011 +0800
+++ b/paraspace/tests/dexfile_test.py	Thu Jun 09 09:32:17 2011 +0800
@@ -175,7 +175,7 @@
     pass
 
 
-def _install_markers_test():
+def install_markers_test():
     from paraspace.dex_deptracker import collect_all_dep_decls
     from paraspace.dex_deptracker import _install_markers, _idx_marker
     from paraspace.dex_deptracker import _offset_marker, _rel_offset_marker
@@ -192,13 +192,11 @@
 
     _patch_dex_type_markers(all_dep_decls)
     assert isinstance(dexfile._DEX_TypeList, _offset_marker)
-    print all_dep_decls.keys()
-    print dexfile.DEXFile.typeLists.child_type
     assert isinstance(dexfile.DEXFile.typeLists.child_type, _offset_marker)
     pass
 
 
-def _link_dependencies_test():
+def link_dependencies_test():
     from paraspace.dex_deptracker import collect_all_dep_decls
     from paraspace.dex_deptracker import _link_dependencies
     from paraspace.dex_deptracker import _install_markers, _idx_marker