changeset 114:867184e01852

Change interface of dexfile_insert_classdefs_relative - orign name dexfile_insert_class_relative - new name dexfile_insert_classdefs_relative
author Thinker K.F. Li <thinker@codemud.net>
date Tue, 02 Aug 2011 20:40:48 +0800
parents ee13c86d84f2
children d112c27f657a
files paraspace/injection.py paraspace/tests/injection_test.py
diffstat 2 files changed, 19 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/injection.py	Tue Aug 02 18:10:48 2011 +0800
+++ b/paraspace/injection.py	Tue Aug 02 20:40:48 2011 +0800
@@ -298,15 +298,15 @@
 
 
 ## \brief Collects relative type IDs and classes definition for given class.
-def collect_classdef_relative(dex, classdef):
-    rel_classdefs = set([classdef])
+def collect_classdefs_relative(dex, classdefs):
+    rel_classdefs = set(classdefs)
     rel_typeids = set()
     
-    classdef_queue = [classdef]
+    classdef_queue = list(classdefs)
     while classdef_queue:
         cur_classdef = classdef_queue.pop(0)
         
-        classdefs, typeids = _find_class_relative(dex, classdef)
+        classdefs, typeids = _find_class_relative(dex, cur_classdef)
         rel_typeids.update(typeids)
         new_classdefs = list(set(classdefs) - rel_classdefs)
         classdef_queue = classdef_queue + new_classdefs
@@ -321,7 +321,7 @@
 # \param dex_src is a DEXFile_linked where the cloned class is from.
 # \param classdef is a _DEX_ClassDef that will be cloned.
 #
-def dexfile_insert_class_relative(dex_dst, dex_src, classdef):
+def dexfile_insert_classdefs_relative(dex_dst, dex_src, classdefs):
     from paraspace.dexfile import DEXFile_linked
     
     def classdef_not_in_dst(classdef):
@@ -341,7 +341,7 @@
         return False
     
     relative_classdefs, relative_typeids = \
-        collect_classdef_relative(dex_src, classdef)
+        collect_classdefs_relative(dex_src, classdefs)
     
     inserting_classdefs = filter(classdef_not_in_dst, relative_classdefs)
     inserting_typeids = filter(typeid_not_in_dst, relative_typeids)
@@ -349,10 +349,12 @@
     dexfile_insert_classdefs(dex_dst, dex_src, inserting_classdefs)
     dexfile_insert_typeids(dex_dst, dex_src, inserting_typeids)
 
-    classname = DEXFile_linked.get_classdef_name(classdef)
-    cloning = dex_dst.find_class_name(classname)
+    classnames = [DEXFile_linked.get_classdef_name(classdef)
+                  for classdef in classdefs]
+    clonings = [dex_dst.find_class_name(classname)
+                for classname in classnames]
     
-    return cloning
+    return clonings
 
 
 ## \brief Redirect types and methods for the code of given method.
--- a/paraspace/tests/injection_test.py	Tue Aug 02 18:10:48 2011 +0800
+++ b/paraspace/tests/injection_test.py	Tue Aug 02 20:40:48 2011 +0800
@@ -220,9 +220,9 @@
     pass
 
 
-def dexfile_insert_class_relative_test():
+def dexfile_insert_classdefs_relative_test():
     from paraspace.dex_deptracker import prepare_dep_decls
-    from paraspace.injection import dexfile_insert_class_relative
+    from paraspace.injection import dexfile_insert_classdefs_relative
     
     _install_dexfile_4_deptracker()
     
@@ -261,10 +261,12 @@
     assert fakefile_dataheader.directMethodsSize == 1
     assert fakefile_dataheader.virtualMethodsSize == 0
 
-    clone = dexfile_insert_class_relative(helloworld_linked,
-                                          fakefile_linked, fakefile_def)
-    assert clone
-    assert clone != fakefile_def
+    clones = dexfile_insert_classdefs_relative(helloworld_linked,
+                                               fakefile_linked,
+                                               [fakefile_def])
+    assert clones
+    assert len(clones) == 1
+    assert clones[0] != fakefile_def
 
     helloworld_unlinked = helloworld_linked.get_unlinked()
     assert helloworld_unlinked