From db12f428c500673a25e525216bdf8c866b20e826 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Thu, 23 Nov 2023 19:56:23 -0600 Subject: [PATCH] AP_HAL_Empty: introduce get_HAL_mutable() to complement get_HAL() Returns a mutable reference to the same HAL for certain purposes where the HAL needs to be mutated to avoid UB problems with casting away const and to make the fact that mutation is happening obvious. --- libraries/AP_HAL_Empty/HAL_Empty_Class.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libraries/AP_HAL_Empty/HAL_Empty_Class.cpp b/libraries/AP_HAL_Empty/HAL_Empty_Class.cpp index b2271a7df8..2045e9c289 100644 --- a/libraries/AP_HAL_Empty/HAL_Empty_Class.cpp +++ b/libraries/AP_HAL_Empty/HAL_Empty_Class.cpp @@ -66,9 +66,14 @@ void HAL_Empty::run(int argc, char* const argv[], Callbacks* callbacks) const } } +static HAL_Empty hal_empty; + const AP_HAL::HAL& AP_HAL::get_HAL() { - static const HAL_Empty hal; - return hal; + return hal_empty; +} + +AP_HAL::HAL& AP_HAL::get_HAL_mutable() { + return hal_empty; } #endif