From d6818e3f946bae8e417de532e1a4d59c3bc4f72c Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 4 Jan 2023 17:50:08 +0000 Subject: [PATCH 1/5] Disable code style correction for bignum assembly The inline assembly defined in bn_mul.h confuses code style parsing, causing code style correction to fail. Disable code style correction for the whole section gated by "#if defined(MBEDTLS_HAVE_ASM)" to prevent this. Signed-off-by: David Horstmann --- include/mbedtls/bn_mul.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/mbedtls/bn_mul.h b/include/mbedtls/bn_mul.h index 30d445e63b..c04e31e802 100644 --- a/include/mbedtls/bn_mul.h +++ b/include/mbedtls/bn_mul.h @@ -84,13 +84,12 @@ #endif /* bits in mbedtls_mpi_uint */ +/* *INDENT-OFF* */ #if defined(MBEDTLS_HAVE_ASM) -/* *INDENT-OFF* */ #ifndef asm #define asm __asm #endif -/* *INDENT-ON* */ /* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */ #if defined(__GNUC__) && \ @@ -955,6 +954,7 @@ #endif /* MSVC */ #endif /* MBEDTLS_HAVE_ASM */ +/* *INDENT-ON* */ #if !defined(MULADDC_CORE) #if defined(MBEDTLS_HAVE_UDBL) From b92d30f987bc07f1675f6098c33458358428e5fd Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 4 Jan 2023 18:33:25 +0000 Subject: [PATCH 2/5] Check Uncrustify returncode in code_style.py Signed-off-by: David Horstmann --- scripts/code_style.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/scripts/code_style.py b/scripts/code_style.py index 8e82b93fb0..a23d3a5ce5 100755 --- a/scripts/code_style.py +++ b/scripts/code_style.py @@ -106,8 +106,12 @@ def check_style_is_correct(src_file_list: List[str]) -> bool: style_correct = True for src_file in src_file_list: uncrustify_cmd = [UNCRUSTIFY_EXE] + UNCRUSTIFY_ARGS + [src_file] - subprocess.run(uncrustify_cmd, stdout=subprocess.PIPE, \ + result = subprocess.run(uncrustify_cmd, stdout=subprocess.PIPE, \ stderr=subprocess.PIPE, check=False) + if result.returncode != 0: + print_err("Uncrustify returned " + str(result.returncode) + \ + " correcting file " + src_file) + return False # Uncrustify makes changes to the code and places the result in a new # file with the extension ".uncrustify". To get the changes (if any) @@ -135,15 +139,22 @@ def fix_style_single_pass(src_file_list: List[str]) -> None: code_change_args = UNCRUSTIFY_ARGS + ["--no-backup"] for src_file in src_file_list: uncrustify_cmd = [UNCRUSTIFY_EXE] + code_change_args + [src_file] - subprocess.run(uncrustify_cmd, check=False, stdout=STDOUT_UTF8, \ - stderr=STDERR_UTF8) + result = subprocess.run(uncrustify_cmd, check=False, \ + stdout=STDOUT_UTF8, stderr=STDERR_UTF8) + if result.returncode != 0: + print_err("Uncrustify with file returned: " + \ + str(result.returncode) + " correcting file " + \ + src_file) + return False def fix_style(src_file_list: List[str]) -> int: """ Fix the code style. This takes 2 passes of Uncrustify. """ - fix_style_single_pass(src_file_list) - fix_style_single_pass(src_file_list) + if fix_style_single_pass(src_file_list) != True: + return 1 + if fix_style_single_pass(src_file_list) != True: + return 1 # Guard against future changes that cause the codebase to require # more passes. From 2ccd77ac83f3a4ba29a9de73e8b419b264e0ae2e Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Thu, 5 Jan 2023 09:50:47 +0000 Subject: [PATCH 3/5] Don't restyle end of file Move the *INDENT-ON* annotation to the end of the file so that uncrustify does not restyle the later sections (since it introduces a risk of future problems). Signed-off-by: David Horstmann --- include/mbedtls/bn_mul.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mbedtls/bn_mul.h b/include/mbedtls/bn_mul.h index c04e31e802..bce9ce38c3 100644 --- a/include/mbedtls/bn_mul.h +++ b/include/mbedtls/bn_mul.h @@ -954,7 +954,6 @@ #endif /* MSVC */ #endif /* MBEDTLS_HAVE_ASM */ -/* *INDENT-ON* */ #if !defined(MULADDC_CORE) #if defined(MBEDTLS_HAVE_UDBL) @@ -1003,4 +1002,5 @@ #endif /* C (generic) */ #endif /* C (longlong) */ +/* *INDENT-ON* */ #endif /* bn_mul.h */ From fa69def8e3bf56e495b0d6243fca25862c30ee11 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Thu, 5 Jan 2023 09:59:35 +0000 Subject: [PATCH 4/5] Fix incorrect typing of function in code_style.py Signed-off-by: David Horstmann --- scripts/code_style.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/code_style.py b/scripts/code_style.py index a23d3a5ce5..2c7a77966f 100755 --- a/scripts/code_style.py +++ b/scripts/code_style.py @@ -132,7 +132,7 @@ def check_style_is_correct(src_file_list: List[str]) -> bool: return style_correct -def fix_style_single_pass(src_file_list: List[str]) -> None: +def fix_style_single_pass(src_file_list: List[str]) -> bool: """ Run Uncrustify once over the source files. """ @@ -146,6 +146,7 @@ def fix_style_single_pass(src_file_list: List[str]) -> None: str(result.returncode) + " correcting file " + \ src_file) return False + return True def fix_style(src_file_list: List[str]) -> int: """ From 242df48caba54d4fba46d765f00b6b0ed4da2762 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Thu, 5 Jan 2023 10:02:09 +0000 Subject: [PATCH 5/5] Fix pylint warnings about comparison to True Signed-off-by: David Horstmann --- scripts/code_style.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/code_style.py b/scripts/code_style.py index 2c7a77966f..aae3e24925 100755 --- a/scripts/code_style.py +++ b/scripts/code_style.py @@ -152,9 +152,9 @@ def fix_style(src_file_list: List[str]) -> int: """ Fix the code style. This takes 2 passes of Uncrustify. """ - if fix_style_single_pass(src_file_list) != True: + if not fix_style_single_pass(src_file_list): return 1 - if fix_style_single_pass(src_file_list) != True: + if not fix_style_single_pass(src_file_list): return 1 # Guard against future changes that cause the codebase to require