# HG changeset patch # User Paul Boddie # Date 1106520759 -3600 # Node ID a52e70c3f294e6505e9997327db157270caef830 # Parent 2485a9127f2ade8df399478671f72b77657f188f Added "safety measures" for exception offset insertion, although better measures are necessary to avoid bizarre JDK 1.4 exception tables. diff -r 2485a9127f2a -r a52e70c3f294 javaclass/bytecode.py --- a/javaclass/bytecode.py Sun Jan 23 21:32:42 2005 +0100 +++ b/javaclass/bytecode.py Sun Jan 23 23:52:39 2005 +0100 @@ -37,6 +37,9 @@ # A stack of exception block handler pointers. self.exception_handlers = [] + # A list of exception offset details. + self.exception_offsets = [] + # A dictionary mapping labels to jump instructions referencing such labels. self.jumps = {} @@ -294,10 +297,13 @@ current_exception_start = self.blocks.pop() # Convert the "lazy" absolute value. current_exception_target = self.exception_handlers.pop() - target = current_exception_target.get_value() - #print "*", current_exception_start, target # NOTE: Using 3 as the assumed length of the SETUP_* instruction. - self._rewrite_value(current_exception_start + 1, target - current_exception_start - 3) + self.exception_offsets.append((current_exception_start + 1, current_exception_target, current_exception_start)) + + def end_exceptions(self): + for position, exception_target, exception_start in self.exception_offsets: + #print "*", exception_start, exception_target.get_value() + self._rewrite_value(position, exception_target.get_value() - exception_start - 3) def start_handler(self, exc_name, class_file): @@ -816,6 +822,10 @@ self.java_position = next_java_position + # Tidy up exceptions. + + program.end_exceptions() + def process_bytecode(self, mnemonic, number_of_arguments, code, program): """