From 40b4cd375dcc702c5b29d19bf3749b0ad4678a8e Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Mon, 13 Nov 2023 21:06:13 +0000 Subject: [PATCH 1/3] Fixed typos (issue #4) --- riscos_toolbox/user_messages/data_transfer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/riscos_toolbox/user_messages/data_transfer.py b/riscos_toolbox/user_messages/data_transfer.py index dbf8bc0..515f3f7 100644 --- a/riscos_toolbox/user_messages/data_transfer.py +++ b/riscos_toolbox/user_messages/data_transfer.py @@ -18,7 +18,7 @@ class Messages: class DataTransferMessage(UserMessage): _fields_ = [ ("destination_window", ctypes.c_int32), - ("estination_icon", ctypes.c_int32), + ("destination_icon", ctypes.c_int32), ("destination_position", Point), ("estimated_size", ctypes.c_int32), ("file_type", ctypes.c_int32), @@ -42,7 +42,7 @@ class DataLoadAckMessage(DataTransferMessage): event_id = Messages.DataLoadAck -class DataSavedkMessage(UserMessage): +class DataSavedMessage(UserMessage): event_id = Messages.DataSaved @@ -52,7 +52,7 @@ class DataOpenMessage(UserMessage): _fields_ = [ ("window_handle", ctypes.c_int32), ("spare", ctypes.c_int32), - ("pposition", Point), + ("position", Point), ("zero", ctypes.c_int32), ("file_type", ctypes.c_int32), ("_path_name", ctypes.c_char * 212), From bd0db5b89e6e4c9061249d3a807c29b1b9883dea Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Mon, 13 Nov 2023 22:09:36 +0000 Subject: [PATCH 2/3] Use throwback when reporting errors. (#37) * Use throwback when reporting errors. --- riscos_toolbox/__init__.py | 39 +++++++++++++++++++++++++++-------- riscos_toolbox/application.py | 3 ++- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/riscos_toolbox/__init__.py b/riscos_toolbox/__init__.py index 158bdbe..14bcc7c 100644 --- a/riscos_toolbox/__init__.py +++ b/riscos_toolbox/__init__.py @@ -57,16 +57,38 @@ def task_name(): return "Python Application" -def report_exception(e): +def throwback_traceback(e): + try: + type, value, tb = sys.exc_info() + stack = reversed(traceback.extract_tb(tb)) + swi.swi("DDEUtils_ThrowbackStart", "s", task_name()) + frame = next(stack) + swi.swi("DDEUtils_ThrowbackSend", "i.siis", + 1, frame.filename, frame.lineno, 1, str(e)) + for frame in stack: + swi.swi("DDEUtils_ThrowbackSend", "i.siis", + 2, frame.filename, frame.lineno, 0, "called from here") + swi.swi("DDEUtils_ThrowbackEnd", "") + except Exception as e: + report_exception(e, throwback=False) + + +def report_exception(e, throwback): error_block = swi.block(64) error_block[0] = 0 + # Write the error to the block at offset 4 error_block.padstring(str(e).encode('latin-1')[:250], b'\0', 4) - - if swi.swi('Wimp_ReportError', 'bIs000;.I', - error_block, 0b000100000011, task_name()) == 2: - global _quit - _quit = True - + if throwback: + sel = swi.swi('Wimp_ReportError', 'bIs00s;.I', + error_block, 0b000100000011, task_name(), + "Throwback") + else: + sel = swi.swi('Wimp_ReportError', 'bIs000;.I', + error_block, 0b000100000011, task_name()) + if sel == 2: + sys.exit(1) + if sel == 3 and throwback: + throwback_traceback(e) def initialise(appdir): def _handler_block(handlers, add=[]): @@ -121,7 +143,6 @@ def run(application): obj_class = swi.swi('Toolbox_GetObjectClass', '0I;I', _id_block.self.id) - _objects[_id_block.self.id] = Object.create( obj_class, name, _id_block.self.id) continue @@ -143,7 +164,7 @@ def run(application): wimp_dispatch(reason, application, _id_block, poll_block) except Exception as e: - report_exception(e) + report_exception(e, application.throwback) def quit(): diff --git a/riscos_toolbox/application.py b/riscos_toolbox/application.py index 100279c..898cbb5 100644 --- a/riscos_toolbox/application.py +++ b/riscos_toolbox/application.py @@ -5,8 +5,9 @@ class Application(EventHandler): - def __init__(self, appdir): + def __init__(self, appdir, throwback=True): super().__init__() + self.throwback = throwback global _application _application = self initialise(appdir) From 582d00a0050250d2bf6fd1568290804c66c18a51 Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Mon, 13 Nov 2023 22:15:33 +0000 Subject: [PATCH 3/3] linter fixes. --- riscos_toolbox/__init__.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/riscos_toolbox/__init__.py b/riscos_toolbox/__init__.py index 14bcc7c..f4c148a 100644 --- a/riscos_toolbox/__init__.py +++ b/riscos_toolbox/__init__.py @@ -90,6 +90,7 @@ def report_exception(e, throwback): if sel == 3 and throwback: throwback_traceback(e) + def initialise(appdir): def _handler_block(handlers, add=[]): ids = sorted( @@ -134,13 +135,11 @@ def run(application): try: poll_block = bytes(poll_buffer) if reason == Wimp.ToolboxEvent: - size, reference, event_code, flags = \ - struct.unpack("IIII", poll_block[0:16]) + size, reference, event_code, flags = struct.unpack("IIII", poll_block[0:16]) if event_code == Toolbox.ObjectAutoCreated: - name =''.join([chr(c) for c in \ - iter(lambda i=iter(poll_block[0x10:]): next(i), 0)]) - + name = ''.join([chr(c) for c in iter( + lambda i=iter(poll_block[0x10:]): next(i), 0)]) obj_class = swi.swi('Toolbox_GetObjectClass', '0I;I', _id_block.self.id) _objects[_id_block.self.id] = Object.create(