Skip to content

Commit

Permalink
Improve FlashString portability (#2796)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
mikee47 authored Jun 11, 2024
1 parent 16e3fd5 commit cf4e1c9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sming/Components/IFS
3 changes: 2 additions & 1 deletion Sming/Core/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ template <typename TFileName> inline int fileSetContent(const TFileName& fileNam
return fileSystem->setContent(fileName, content, length);
}

template <typename TFileName, typename TContent> inline int fileSetContent(const TFileName& fileName, TContent content)
template <typename TFileName, typename TContent>
inline int fileSetContent(const TFileName& fileName, const TContent& content)
{
CHECK_FS(setContent)
return fileSystem->setContent(fileName, content);
Expand Down
16 changes: 16 additions & 0 deletions docs/source/upgrading/5.1-5.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit cf4e1c9

Please sign in to comment.