From cb3b6ae580bf7e03922b285c22b82bcd20b54993 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 --- library/bn_mul.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/bn_mul.h b/library/bn_mul.h index a34a7c7d50..22574e6550 100644 --- a/library/bn_mul.h +++ b/library/bn_mul.h @@ -80,13 +80,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__) && \ @@ -1006,6 +1005,7 @@ #endif /* MSVC */ #endif /* MBEDTLS_HAVE_ASM */ +/* *INDENT-ON* */ #if !defined(MULADDC_X1_CORE) #if defined(MBEDTLS_HAVE_UDBL) From c571c5b1f09e099bd9190318984d4c9ed648d89a 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 bec95320ba0bf805a12689f80d1625776eb2b948 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 --- library/bn_mul.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/bn_mul.h b/library/bn_mul.h index 22574e6550..b7e9690e92 100644 --- a/library/bn_mul.h +++ b/library/bn_mul.h @@ -1005,7 +1005,6 @@ #endif /* MSVC */ #endif /* MBEDTLS_HAVE_ASM */ -/* *INDENT-ON* */ #if !defined(MULADDC_X1_CORE) #if defined(MBEDTLS_HAVE_UDBL) @@ -1073,4 +1072,5 @@ #define MULADDC_X8_CORE MULADDC_X4_CORE MULADDC_X4_CORE #endif /* MULADDC_X8_CORE */ +/* *INDENT-ON* */ #endif /* bn_mul.h */ From 8d1d6edb0b16259c039ec765d7665f417e62eff4 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 78d566b216c593932bf42758727e4488b3870171 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