# HG changeset patch # User Thinker K.F. Li # Date 1311571382 -28800 # Node ID 2fa9b6f2134494d738960ce4c86d467bdfacdf96 # Parent 1728795c29b7c92efb726b13ec99419773f656da Add DEXFile_linked to model linked DEX diff -r 1728795c29b7 -r 2fa9b6f21344 paraspace/dexfile.py --- a/paraspace/dexfile.py Mon Jul 25 10:01:14 2011 +0800 +++ b/paraspace/dexfile.py Mon Jul 25 13:23:02 2011 +0800 @@ -1658,6 +1658,36 @@ pass +## \brief A linked version of a DEXFile. +# +# Instances of this class was built from instances of DEXFile. +# Dependencies are linked to depend-on objects; the target of a +# dependence. +# +class DEXFile_linked(DEXFile): + def _copy_attributes(self, dex): + super(DEXFile_linked, self).__init__() + for attr, value in dex.__dict__.items(): + setattr(self, attr, value) + pass + pass + + ## \brief Factory function to return a DEXFile_linked of given DEXFile. + @staticmethod + def build_dependencies(dex, dep_decls): + from paraspace.dex_deptracker import build_dependencies + + if not isinstance(dex, DEXFile): + raise TypeError, 'first argument must be an instance of DEXFile' + + linked = DEXFile_linked() + build_dependencies(dex, dep_decls) + linked._copy_attributes(dex) + + return linked + pass + + if __name__ == '__main__': import sys diff -r 1728795c29b7 -r 2fa9b6f21344 paraspace/tests/injection_test.py --- a/paraspace/tests/injection_test.py Mon Jul 25 10:01:14 2011 +0800 +++ b/paraspace/tests/injection_test.py Mon Jul 25 13:23:02 2011 +0800 @@ -3,7 +3,7 @@ def _install_dexfile_4_deptracker(): global dexfile - import imp + import imp, sys from paraspace import dex_deptracker try: @@ -14,6 +14,8 @@ dex_deptracker.dexfile = new_dexfile dexfile = new_dexfile dex_deptracker._nest_types = (dexfile.array, dexfile.cond, dexfile.switch) + + sys.modules['paraspace.dexfile'] = new_dexfile pass @@ -30,10 +32,14 @@ helloworld_fn = os.path.join(srcroot, 'data', 'helloworld.dex') helloworld_dex = dexfile.DEXFile.open(helloworld_fn) - build_dependencies(helloworld_dex, all_dep_decls) + helloworld_linked = \ + dexfile.DEXFile_linked.build_dependencies(helloworld_dex, + all_dep_decls) fakefile_fn = os.path.join(srcroot, 'data', 'fakefile.dex') fakefile_dex = dexfile.DEXFile.open(fakefile_fn) - build_dependencies(fakefile_dex, all_dep_decls) + fakefile_linked = \ + dexfile.DEXFile_linked.build_dependencies(fakefile_dex, + all_dep_decls) pass