From d06680e16553163a2eb436c0df0600fc440f50e1 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 24 May 2021 10:46:56 -0400 Subject: [PATCH 1/2] Fix #1048, filter only whole words for keyword match In the stub generator script, filter only whole words when ignoring keywords. Do not match if the word appears as a substring inside a larger word. --- src/ut-stubs/osapi-timebase-stubs.c | 4 ++-- ut_assert/scripts/generate_stubs.pl | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ut-stubs/osapi-timebase-stubs.c b/src/ut-stubs/osapi-timebase-stubs.c index c1e3439dc..cf5163ab2 100644 --- a/src/ut-stubs/osapi-timebase-stubs.c +++ b/src/ut-stubs/osapi-timebase-stubs.c @@ -38,13 +38,13 @@ extern void UT_DefaultHandler_OS_TimeBaseGetInfo(void *, UT_EntryKey_t, const UT * Generated stub function for OS_TimeBaseCreate() * ---------------------------------------------------- */ -int32 OS_TimeBaseCreate(osal_id_t *timebase_id, const char *timebase_name, OS_TimerSync_t al_sync) +int32 OS_TimeBaseCreate(osal_id_t *timebase_id, const char *timebase_name, OS_TimerSync_t external_sync) { UT_GenStub_SetupReturnBuffer(OS_TimeBaseCreate, int32); UT_GenStub_AddParam(OS_TimeBaseCreate, osal_id_t *, timebase_id); UT_GenStub_AddParam(OS_TimeBaseCreate, const char *, timebase_name); - UT_GenStub_AddParam(OS_TimeBaseCreate, OS_TimerSync_t, al_sync); + UT_GenStub_AddParam(OS_TimeBaseCreate, OS_TimerSync_t, external_sync); UT_GenStub_Execute(OS_TimeBaseCreate, Basic, UT_DefaultHandler_OS_TimeBaseCreate); diff --git a/ut_assert/scripts/generate_stubs.pl b/ut_assert/scripts/generate_stubs.pl index fefa2623f..720ee37f1 100755 --- a/ut_assert/scripts/generate_stubs.pl +++ b/ut_assert/scripts/generate_stubs.pl @@ -155,20 +155,20 @@ # Now Find function prototypes foreach (@lines) { - next if (/typedef/); # ignore typedefs - next if (/static inline/); # ignore + next if (/\btypedef\b/); # ignore typedefs + next if (/\bstatic inline\b/); # ignore # discard "extern" qualifier # (but other qualifiers like "const" are OK and should be preserved, as # it is part of return type). - s/extern//; + s/\bextern\b//; # The following macros are defined in OSAL common_types.h as function attributes # They may appear on other function declarations, and should be ignored here. - s/_EXTENSION_//; - s/OS_USED//; - s/OS_PRINTF\(.*?\)//; + s/\b_EXTENSION_\b//; + s/\bOS_USED\b//; + s/\bOS_PRINTF\(.*?\)//; # scrub whitespace for consistency - multiple spaces become single space # and trim leading/trailing spaces again From e8add95c74d0499e04a33e1a3c69c2595dd908f3 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 25 May 2021 10:21:25 -0400 Subject: [PATCH 2/2] Fix #1048, also filter C++-style comments Truncate input lines at C++-style comment markers, in case users/projects allow this style of comment. --- ut_assert/scripts/generate_stubs.pl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ut_assert/scripts/generate_stubs.pl b/ut_assert/scripts/generate_stubs.pl index 720ee37f1..9dff1e610 100755 --- a/ut_assert/scripts/generate_stubs.pl +++ b/ut_assert/scripts/generate_stubs.pl @@ -129,6 +129,12 @@ } close(HDR); + foreach (@lines) + { + # Truncate each line at C++-style comment + s/\/\/.*$//; + } + # combine all content into a single string # this eases processing of multi-line constructs $file = join('', @lines);