From 94e61a263dc76fb1947532a381a7d1f36468748a Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 15 Aug 2023 14:14:02 +1000 Subject: [PATCH] AP_InternalError: improve gating of use of AP_InternalError library - gate calls into library directly on the define - INTERNAL_ERROR becomes empty if library not compiled in --- libraries/AP_InternalError/AP_InternalError.cpp | 10 +++++++++- libraries/AP_InternalError/AP_InternalError.h | 8 ++++++++ libraries/AP_InternalError/AP_InternalError_config.h | 7 +++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 libraries/AP_InternalError/AP_InternalError_config.h diff --git a/libraries/AP_InternalError/AP_InternalError.cpp b/libraries/AP_InternalError/AP_InternalError.cpp index 2bb3b3170e..bc505804a8 100644 --- a/libraries/AP_InternalError/AP_InternalError.cpp +++ b/libraries/AP_InternalError/AP_InternalError.cpp @@ -1,6 +1,12 @@ +#include "AP_InternalError_config.h" + +#if AP_INTERNALERROR_ENABLED + #include "AP_InternalError.h" -#include +#include +#include + #include extern const AP_HAL::HAL &hal; @@ -137,3 +143,5 @@ void AP_memory_guard_error(uint32_t size) AP_HAL::panic("memory guard size=%u\n", unsigned(size)); } } + +#endif // AP_INTERNALERROR_ENABLED diff --git a/libraries/AP_InternalError/AP_InternalError.h b/libraries/AP_InternalError/AP_InternalError.h index 4cbbb29043..d6936d978c 100644 --- a/libraries/AP_InternalError/AP_InternalError.h +++ b/libraries/AP_InternalError/AP_InternalError.h @@ -22,6 +22,10 @@ #pragma once +#include "AP_InternalError_config.h" + +#if AP_INTERNALERROR_ENABLED + #include class AP_InternalError { @@ -113,3 +117,7 @@ extern "C" { #define INTERNAL_ERROR(error_number) \ AP::internalerror().error(error_number, __AP_LINE__); + +#else // AP_INTERNALERROR_ENABLED is false +#define INTERNAL_ERROR(error_number) +#endif // AP_INTERNALERROR_ENABLED diff --git a/libraries/AP_InternalError/AP_InternalError_config.h b/libraries/AP_InternalError/AP_InternalError_config.h new file mode 100644 index 0000000000..64bbb03f69 --- /dev/null +++ b/libraries/AP_InternalError/AP_InternalError_config.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +#ifndef AP_INTERNALERROR_ENABLED +#define AP_INTERNALERROR_ENABLED 1 +#endif