From 6097c5a3c1bb4e41e0631c78f7225230f6681d61 Mon Sep 17 00:00:00 2001 From: ABuffEr Date: Tue, 7 Mar 2023 13:45:14 +0100 Subject: [PATCH 01/18] Avoid freeze in Windows API Level 0 console when UIA support is enabled --- source/speechDictHandler/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index d4f1487465f..4109b4cc039 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -118,6 +118,14 @@ def sub(self, text): def processText(text): if not globalVars.speechDictionaryProcessing: return text + try: + # see issue 14689 + if config.conf["UIA"]["winConsoleImplementation"] == "UIA": + stripText = text.rstrip() + if len(text)-len(stripText) > 10000: + text = stripText + except KeyError: + pass for type in dictTypes: text=dictionaries[type].sub(text) return text From bc553c07edb766c115316fdc9fdf4ea62abc885f Mon Sep 17 00:00:00 2001 From: Alberto Buffolino Date: Tue, 7 Mar 2023 15:05:48 +0100 Subject: [PATCH 02/18] Update source/speechDictHandler/__init__.py Better issue comment Co-authored-by: Bill Dengler --- source/speechDictHandler/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index 4109b4cc039..d716e7e8d09 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -119,7 +119,7 @@ def processText(text): if not globalVars.speechDictionaryProcessing: return text try: - # see issue 14689 + # #14689: API level 0 UIA consoles have many blank lines, which slows processing to a halt if config.conf["UIA"]["winConsoleImplementation"] == "UIA": stripText = text.rstrip() if len(text)-len(stripText) > 10000: From 8332fc6293e02915db425adf701ae09eedce9a5f Mon Sep 17 00:00:00 2001 From: ABuffEr Date: Tue, 7 Mar 2023 20:21:14 +0100 Subject: [PATCH 03/18] Use apiLevel instead of config --- source/speechDictHandler/__init__.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index d716e7e8d09..ca802d22d43 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -9,7 +9,6 @@ import os import codecs import api -import config from . import dictFormatUpgrade from .speechDictVars import speechDictsPath @@ -118,14 +117,15 @@ def sub(self, text): def processText(text): if not globalVars.speechDictionaryProcessing: return text - try: - # #14689: API level 0 UIA consoles have many blank lines, which slows processing to a halt - if config.conf["UIA"]["winConsoleImplementation"] == "UIA": - stripText = text.rstrip() - if len(text)-len(stripText) > 10000: - text = stripText - except KeyError: - pass + # #14689: API level < 2 UIA consoles have many blank lines, which slows processing to a halt + # Because from UIAHandler.constants import WinConsoleAPILevel + # cause crashes as global import, and probably slowdowns here + # use 2 instead of WinConsoleAPILevel.FORMATTED constant + focus = api.getFocusObject() + if hasattr(focus, "apiLevel") and focus.apiLevel < 2: + stripText = text.rstrip() + if len(text)-len(stripText) > 10000: + text = stripText for type in dictTypes: text=dictionaries[type].sub(text) return text From 7ce15430cdf34cfc36ae8d91d32fdd2abecf4ea1 Mon Sep 17 00:00:00 2001 From: ABuffEr Date: Tue, 7 Mar 2023 21:03:36 +0100 Subject: [PATCH 04/18] Fix lint --- source/speechDictHandler/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index ca802d22d43..41bc475042a 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -124,7 +124,7 @@ def processText(text): focus = api.getFocusObject() if hasattr(focus, "apiLevel") and focus.apiLevel < 2: stripText = text.rstrip() - if len(text)-len(stripText) > 10000: + if len(text) - len(stripText) > 10000: text = stripText for type in dictTypes: text=dictionaries[type].sub(text) From 06bd4d001a53e578f0716c549b1fe9a912a833e0 Mon Sep 17 00:00:00 2001 From: Alberto Buffolino Date: Tue, 28 Mar 2023 19:42:43 +0200 Subject: [PATCH 05/18] Update source/speechDictHandler/__init__.py Accept seanbudd suggestion. Co-authored-by: Sean Budd --- source/speechDictHandler/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index 41bc475042a..6f93c8a8a33 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -124,7 +124,8 @@ def processText(text): focus = api.getFocusObject() if hasattr(focus, "apiLevel") and focus.apiLevel < 2: stripText = text.rstrip() - if len(text) - len(stripText) > 10000: + IGNORE_TRAILING_WHITESPACE_LENGTH = 1000 + if len(text) - len(stripText) > IGNORE_TRAILING_WHITESPACE_LENGTH: text = stripText for type in dictTypes: text=dictionaries[type].sub(text) From 6a0e6a737fc0f3fcba72c7695ec10846e05cb226 Mon Sep 17 00:00:00 2001 From: ABuffEr Date: Tue, 28 Mar 2023 19:53:31 +0200 Subject: [PATCH 06/18] Moved IGNORE_TRAILING_WHITESPACE_LENGTH outside of the function, and reduced to 100 --- source/speechDictHandler/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index 6f93c8a8a33..88dd131711c 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -114,6 +114,9 @@ def sub(self, text): del self[index] return text +# useful for #14689 (see below) +IGNORE_TRAILING_WHITESPACE_LENGTH = 100 + def processText(text): if not globalVars.speechDictionaryProcessing: return text @@ -124,7 +127,6 @@ def processText(text): focus = api.getFocusObject() if hasattr(focus, "apiLevel") and focus.apiLevel < 2: stripText = text.rstrip() - IGNORE_TRAILING_WHITESPACE_LENGTH = 1000 if len(text) - len(stripText) > IGNORE_TRAILING_WHITESPACE_LENGTH: text = stripText for type in dictTypes: From 306970b5328f9db9d5696ac89778f952a4e623d1 Mon Sep 17 00:00:00 2001 From: ABuffEr Date: Tue, 28 Mar 2023 19:56:26 +0200 Subject: [PATCH 07/18] Fix lint --- source/speechDictHandler/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index 88dd131711c..9eff36e7fc5 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -114,6 +114,7 @@ def sub(self, text): del self[index] return text + # useful for #14689 (see below) IGNORE_TRAILING_WHITESPACE_LENGTH = 100 From b0846e420506e93450b315a6c9720cf33ae7dcf5 Mon Sep 17 00:00:00 2001 From: ABuffEr Date: Thu, 30 Mar 2023 13:43:47 +0200 Subject: [PATCH 08/18] New approach: check isinstance of ConsoleUIATextInfo --- source/speechDictHandler/__init__.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index 9eff36e7fc5..a7defc9b320 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -8,7 +8,7 @@ from logHandler import log import os import codecs -import api +import review from . import dictFormatUpgrade from .speechDictVars import speechDictsPath @@ -122,11 +122,16 @@ def processText(text): if not globalVars.speechDictionaryProcessing: return text # #14689: API level < 2 UIA consoles have many blank lines, which slows processing to a halt - # Because from UIAHandler.constants import WinConsoleAPILevel - # cause crashes as global import, and probably slowdowns here - # use 2 instead of WinConsoleAPILevel.FORMATTED constant - focus = api.getFocusObject() - if hasattr(focus, "apiLevel") and focus.apiLevel < 2: + focus = globalVars.focusObject + try: + # get TextInfo implementation for object review mode + textInfo, obj = review.getObjectPosition(focus) + except AttributeError: # no makeTextInfo + textInfo = None + # import at this stage to avoid crashes + # ConsoleUIATextInfo is shared by apiLevel 1 and 0 implementations (not 2) + from NVDAObjects.UIA.winConsoleUIA import ConsoleUIATextInfo + if isinstance(textInfo, ConsoleUIATextInfo): stripText = text.rstrip() if len(text) - len(stripText) > IGNORE_TRAILING_WHITESPACE_LENGTH: text = stripText From f59b8c8f3b1e020702d9cde31994346175efbe5b Mon Sep 17 00:00:00 2001 From: Alberto Buffolino Date: Mon, 3 Apr 2023 18:52:12 +0200 Subject: [PATCH 09/18] Update source/speechDictHandler/__init__.py Rename to _IGNORE_TRAILING_WHITESPACE_LENGTH to keep it private Co-authored-by: Sean Budd --- source/speechDictHandler/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index a7defc9b320..333ab010197 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -116,7 +116,7 @@ def sub(self, text): # useful for #14689 (see below) -IGNORE_TRAILING_WHITESPACE_LENGTH = 100 +_IGNORE_TRAILING_WHITESPACE_LENGTH = 100 def processText(text): if not globalVars.speechDictionaryProcessing: From acffc639234fb2a800f8019e24df8f1e902a431f Mon Sep 17 00:00:00 2001 From: Alberto Buffolino Date: Mon, 3 Apr 2023 19:29:27 +0200 Subject: [PATCH 10/18] Update source/speechDictHandler/__init__.py Better comment for late import Co-authored-by: Sean Budd --- source/speechDictHandler/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index 333ab010197..099179e4697 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -128,7 +128,7 @@ def processText(text): textInfo, obj = review.getObjectPosition(focus) except AttributeError: # no makeTextInfo textInfo = None - # import at this stage to avoid crashes + # late import to prevent circular dependency # ConsoleUIATextInfo is shared by apiLevel 1 and 0 implementations (not 2) from NVDAObjects.UIA.winConsoleUIA import ConsoleUIATextInfo if isinstance(textInfo, ConsoleUIATextInfo): From d8651d82696998b89336dc8b199f90a49ade4781 Mon Sep 17 00:00:00 2001 From: ABuffEr Date: Mon, 3 Apr 2023 19:40:24 +0200 Subject: [PATCH 11/18] Fix _IGNORE_TRAILING_WHITESPACE_LENGTH into function --- source/speechDictHandler/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index 099179e4697..14991a8de63 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -133,7 +133,7 @@ def processText(text): from NVDAObjects.UIA.winConsoleUIA import ConsoleUIATextInfo if isinstance(textInfo, ConsoleUIATextInfo): stripText = text.rstrip() - if len(text) - len(stripText) > IGNORE_TRAILING_WHITESPACE_LENGTH: + if len(text) - len(stripText) > _IGNORE_TRAILING_WHITESPACE_LENGTH: text = stripText for type in dictTypes: text=dictionaries[type].sub(text) From bf542b7cc9902ccc45abb0ffbd2f30563206dcf0 Mon Sep 17 00:00:00 2001 From: Alberto Buffolino Date: Tue, 4 Apr 2023 16:02:45 +0200 Subject: [PATCH 12/18] Update source/speechDictHandler/__init__.py Readability: rename and move IGNORE_TRAILING_WHITESPACE_LENGTH into function Co-authored-by: Sean Budd --- source/speechDictHandler/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index 14991a8de63..c18de35c9e0 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -133,7 +133,8 @@ def processText(text): from NVDAObjects.UIA.winConsoleUIA import ConsoleUIATextInfo if isinstance(textInfo, ConsoleUIATextInfo): stripText = text.rstrip() - if len(text) - len(stripText) > _IGNORE_TRAILING_WHITESPACE_LENGTH: + IGNORE_TRAILING_WHITESPACE_LENGTH = 100 + if len(text) - len(stripText) > IGNORE_TRAILING_WHITESPACE_LENGTH: text = stripText for type in dictTypes: text=dictionaries[type].sub(text) From d6f86fd5d99cadf104b235d6ee32eea67223d6b2 Mon Sep 17 00:00:00 2001 From: ABuffEr Date: Tue, 4 Apr 2023 16:06:49 +0200 Subject: [PATCH 13/18] Removed global _IGNORE_TRAILING_WHITESPACE_LENGTH --- source/speechDictHandler/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index c18de35c9e0..3edac1c9917 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -115,9 +115,6 @@ def sub(self, text): return text -# useful for #14689 (see below) -_IGNORE_TRAILING_WHITESPACE_LENGTH = 100 - def processText(text): if not globalVars.speechDictionaryProcessing: return text From 54aa703a7e3827c705c9a14ea12e8e68885f3426 Mon Sep 17 00:00:00 2001 From: ABuffEr Date: Tue, 4 Apr 2023 16:09:17 +0200 Subject: [PATCH 14/18] Use api.getFocusObject instead of globalVars.focusObject --- source/speechDictHandler/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index 3edac1c9917..eea3979547e 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -9,6 +9,7 @@ import os import codecs import review +import api from . import dictFormatUpgrade from .speechDictVars import speechDictsPath @@ -119,7 +120,7 @@ def processText(text): if not globalVars.speechDictionaryProcessing: return text # #14689: API level < 2 UIA consoles have many blank lines, which slows processing to a halt - focus = globalVars.focusObject + focus = api.getFocusObject() try: # get TextInfo implementation for object review mode textInfo, obj = review.getObjectPosition(focus) From ba204f515c2abbfa3a95358c6c4c2df206447739 Mon Sep 17 00:00:00 2001 From: Alberto Buffolino Date: Wed, 5 Apr 2023 07:53:18 +0200 Subject: [PATCH 15/18] Update source/speechDictHandler/__init__.py Better comment about ConsoleUIATextInfo Co-authored-by: Bill Dengler --- source/speechDictHandler/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index eea3979547e..cbed6ec7b08 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -127,7 +127,7 @@ def processText(text): except AttributeError: # no makeTextInfo textInfo = None # late import to prevent circular dependency - # ConsoleUIATextInfo is shared by apiLevel 1 and 0 implementations (not 2) + # ConsoleUIATextInfo is used by IMPROVED and END_INCLUSIVE consoles from NVDAObjects.UIA.winConsoleUIA import ConsoleUIATextInfo if isinstance(textInfo, ConsoleUIATextInfo): stripText = text.rstrip() From 46bb1a990741e80cbea7953733d7f13a7bdf9b38 Mon Sep 17 00:00:00 2001 From: Alberto Buffolino Date: Wed, 5 Apr 2023 07:54:17 +0200 Subject: [PATCH 16/18] Update source/speechDictHandler/__init__.py Better comment describing solved issue Co-authored-by: Bill Dengler --- source/speechDictHandler/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index cbed6ec7b08..e52d6053023 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -119,7 +119,7 @@ def sub(self, text): def processText(text): if not globalVars.speechDictionaryProcessing: return text - # #14689: API level < 2 UIA consoles have many blank lines, which slows processing to a halt + # #14689: older (IMPROVED and END_INCLUSIVE) UIA consoles have many blank lines, which slows processing to a halt focus = api.getFocusObject() try: # get TextInfo implementation for object review mode From 657f601b40acbcc16d366467de177ad52193b152 Mon Sep 17 00:00:00 2001 From: Sean Budd Date: Wed, 5 Apr 2023 16:17:46 +1000 Subject: [PATCH 17/18] update changes --- user_docs/en/changes.t2t | 1 + 1 file changed, 1 insertion(+) diff --git a/user_docs/en/changes.t2t b/user_docs/en/changes.t2t index f677ecff64e..5b28c510373 100644 --- a/user_docs/en/changes.t2t +++ b/user_docs/en/changes.t2t @@ -55,6 +55,7 @@ This only worked for Bluetooth Serial ports before. (#14524) Instead NVDA reports that the link has no destination. (#14723) - Several stability fixes to input/output for braille displays, resulting in less frequent errors and crashes of NVDA. (#14627) - NVDA again recovers from many more situations such as applications that stop responding which previously caused it to freeze completely. (#14759) +- When forcing UIA support with certain terminal and consoles, a bug is fixed which caused a freeze and the log file to be spammed. (#14689) - From 0c0d82f8bb22a0fb75bd4bae5811f00d1437e704 Mon Sep 17 00:00:00 2001 From: ABuffEr Date: Wed, 5 Apr 2023 15:27:39 +0200 Subject: [PATCH 18/18] Fix comment lint --- source/speechDictHandler/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/speechDictHandler/__init__.py b/source/speechDictHandler/__init__.py index e52d6053023..5ea53ff8712 100644 --- a/source/speechDictHandler/__init__.py +++ b/source/speechDictHandler/__init__.py @@ -119,7 +119,8 @@ def sub(self, text): def processText(text): if not globalVars.speechDictionaryProcessing: return text - # #14689: older (IMPROVED and END_INCLUSIVE) UIA consoles have many blank lines, which slows processing to a halt + # #14689: older (IMPROVED and END_INCLUSIVE) UIA consoles have many blank lines, + # which slows processing to a halt focus = api.getFocusObject() try: # get TextInfo implementation for object review mode