Mercurial > paraspace
diff paraspace/dex_deptracker.py @ 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 | 0c0a659187c2 |
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]