From cc5385d3adffce7de21b8ae3c74b572352f59eab Mon Sep 17 00:00:00 2001 From: aditya Date: Fri, 22 May 2026 19:22:13 +0530 Subject: [PATCH] Add UNITY_OUTPUT_START/COMPLETE_HEADER_DECLARATION macros (closes #799). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `UNITY_OUTPUT_CHAR` and `UNITY_OUTPUT_FLUSH` already let users provide their own extern prototype via the matching `*_HEADER_DECLARATION` macro (unity_internals.h:333-335 and :349-351). `UNITY_OUTPUT_START` and `UNITY_OUTPUT_COMPLETE` did not — so users wanting to install init / deinit hooks (e.g. serial port open/close, RTT/JTAG bring-up) could override the macro but had no Unity-sanctioned way to declare the function prototype. Add the matching `_HEADER_DECLARATION` triad for both `START` and `COMPLETE`, mirroring the FLUSH pattern verbatim. Add the corresponding commented-out documentation lines to examples/unity_config.h so users discover the new option alongside the existing ones. Purely additive — the new code path only activates when the user defines both `UNITY_OUTPUT_START` (or `_COMPLETE`) AND the matching `*_HEADER_DECLARATION`. Default no-op behaviour is unchanged. --- examples/unity_config.h | 6 ++++-- src/unity_internals.h | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/unity_config.h b/examples/unity_config.h index c79dd5a90..41195c2bd 100644 --- a/examples/unity_config.h +++ b/examples/unity_config.h @@ -228,8 +228,10 @@ /* #define UNITY_OUTPUT_CHAR_HEADER_DECLARATION RS232_putc(int) */ /* #define UNITY_OUTPUT_FLUSH() RS232_flush() */ /* #define UNITY_OUTPUT_FLUSH_HEADER_DECLARATION RS232_flush(void) */ -/* #define UNITY_OUTPUT_START() RS232_config(115200,1,8,0) */ -/* #define UNITY_OUTPUT_COMPLETE() RS232_close() */ +/* #define UNITY_OUTPUT_START() RS232_config(115200,1,8,0) */ +/* #define UNITY_OUTPUT_START_HEADER_DECLARATION RS232_config(int,int,int,int) */ +/* #define UNITY_OUTPUT_COMPLETE() RS232_close() */ +/* #define UNITY_OUTPUT_COMPLETE_HEADER_DECLARATION RS232_close(void) */ /* Some compilers require a custom attribute to be assigned to pointers, like * `near` or `far`. In these cases, you can give Unity a safe default for these diff --git a/src/unity_internals.h b/src/unity_internals.h index e8a26ad22..a39c5a52e 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -363,10 +363,20 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT; #ifndef UNITY_OUTPUT_START #define UNITY_OUTPUT_START() +#else + /* If defined as something else, make sure we declare it here so it's ready for use */ + #ifdef UNITY_OUTPUT_START_HEADER_DECLARATION + extern void UNITY_OUTPUT_START_HEADER_DECLARATION; + #endif #endif #ifndef UNITY_OUTPUT_COMPLETE #define UNITY_OUTPUT_COMPLETE() +#else + /* If defined as something else, make sure we declare it here so it's ready for use */ + #ifdef UNITY_OUTPUT_COMPLETE_HEADER_DECLARATION + extern void UNITY_OUTPUT_COMPLETE_HEADER_DECLARATION; + #endif #endif #ifdef UNITY_INCLUDE_EXEC_TIME