From 2dbf5aefb39f10a1a67e15a6ad4d52a8b0506b5f Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Thu, 23 Nov 2023 19:56:04 -0600 Subject: [PATCH] AP_HAL_ESP32: 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_ESP32/system.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libraries/AP_HAL_ESP32/system.cpp b/libraries/AP_HAL_ESP32/system.cpp index 20f07a0147..4ee607c561 100644 --- a/libraries/AP_HAL_ESP32/system.cpp +++ b/libraries/AP_HAL_ESP32/system.cpp @@ -56,8 +56,14 @@ uint64_t millis64() } // namespace AP_HAL +static HAL_ESP32 hal_esp32; + const AP_HAL::HAL& AP_HAL::get_HAL() { - static const HAL_ESP32 hal; - return hal; + return hal_esp32; +} + +AP_HAL::HAL& AP_HAL::get_HAL_mutable() +{ + return hal_esp32; }