From cf4e1c9ca27b6f964ae8e19a14b3da2b70572773 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 11 Jun 2024 10:18:38 +0100 Subject: [PATCH] Improve FlashString portability (#2796) This PR removes copy support from the FlashString library. Doing so simplifies the code, improves performance and portability to other compilers (e.g. clang). The FlashString library previously supported copies (references) like this:: ``` FlashString emptyString; FlashString stringCopy(FS("Inline string")); DEFINE_FSTR_DATA_LOCAL(flashHelloData, "Hello"); auto myCopy = flashHelloData; ``` These will now fail to compile. Copy construction and assignment has been explicitly deleted so avoid unintentional side-effects. Objects should always be passed by reference. This change has the additional benefit of catching pass-by-copy errors. These function/method templates have been fixed: - `fileSetContent` - `IFS::File::setAttribute` - `IFS::FileSystem::setUserAttribute` - `IFS::ArchiveStream::setUserAttribute` --- Sming/Components/FlashString | 2 +- Sming/Components/IFS | 2 +- Sming/Core/FileSystem.h | 3 ++- docs/source/upgrading/5.1-5.2.rst | 16 ++++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Sming/Components/FlashString b/Sming/Components/FlashString index c7f2b606c1..a44b584a10 160000 --- a/Sming/Components/FlashString +++ b/Sming/Components/FlashString @@ -1 +1 @@ -Subproject commit c7f2b606c121d757a385b17faa50b7b7367d223a +Subproject commit a44b584a100848fdb89cc6ea5f1778b4557d3227 diff --git a/Sming/Components/IFS b/Sming/Components/IFS index 4db9a92b7e..4d30df4bf9 160000 --- a/Sming/Components/IFS +++ b/Sming/Components/IFS @@ -1 +1 @@ -Subproject commit 4db9a92b7e893a0406f1c29ca30072adb676e753 +Subproject commit 4d30df4bf9e2bb155009595381d0822bdd81dbfa diff --git a/Sming/Core/FileSystem.h b/Sming/Core/FileSystem.h index 211813000f..c2682fc4f2 100644 --- a/Sming/Core/FileSystem.h +++ b/Sming/Core/FileSystem.h @@ -235,7 +235,8 @@ template inline int fileSetContent(const TFileName& fileNam return fileSystem->setContent(fileName, content, length); } -template inline int fileSetContent(const TFileName& fileName, TContent content) +template +inline int fileSetContent(const TFileName& fileName, const TContent& content) { CHECK_FS(setContent) return fileSystem->setContent(fileName, content); diff --git a/docs/source/upgrading/5.1-5.2.rst b/docs/source/upgrading/5.1-5.2.rst index 0d10a27c14..96f7fc41a4 100644 --- a/docs/source/upgrading/5.1-5.2.rst +++ b/docs/source/upgrading/5.1-5.2.rst @@ -75,3 +75,19 @@ Applications must explicitly call :cpp:func:`HttpRequest::onSslInit` and set the This extra step ensures that security checks are not unintentionally bypassed. The same behaviour is now presented when using Bearssl, and will now fail with ``X509_NOT_TRUSTED``. + + +**FlashString copy support removed** + +The :library:`FlashString` previously supported copies (references) like this:: + + FlashString emptyString; + FlashString stringCopy(FS("Inline string")); + + DEFINE_FSTR_DATA_LOCAL(flashHelloData, "Hello"); + auto myCopy = flashHelloData; + +These will now fail to compile. +Copy construction and assignment has been explicitly deleted so avoid unintentional side-effects. + +Objects should always be passed by reference.