sys/cpp11-compat: use new/delete operators from sys/cpp_new_delete#17475
Merged
aabadie merged 2 commits intoRIOT-OS:masterfrom Jan 6, 2022
Merged
sys/cpp11-compat: use new/delete operators from sys/cpp_new_delete#17475aabadie merged 2 commits intoRIOT-OS:masterfrom
aabadie merged 2 commits intoRIOT-OS:masterfrom
Conversation
The `new` and `delete` operators that don't need `libtsdc++` are also provided by module `sys/cpp_new_delete` for platforms that don't have the `libstdc++`. Since these operators in `sys/cpp11-compat` are just wrappers for standard `malloc`/`free` functions like in `sys/cpp_new_delete`, the `new`/`delete` operators that don't need `libstdc++` are used from `sys/cpp_new_delete`. Only the `new`/`delete` operators that require the `libstd++` are left in `sys/cpp11-compat`. So it is sufficient for the use of the (re)defined `new`/`delete` operators that an application uses the module `sys/cpp_new_delete` instead of `sys/cpp11-compat` and thus also works on platforms without `libstdc++`.
On ARM platforms, `__dso_handle` is used for dynamic shared objects. But it is also required if global static objects are used. To avoid that `sys/cpp11_compat` is required only for using the (re)defined `new`/`delete` operators, `__dso_handle` is moved to module `sys/cpp_new_delete`
benpicco
approved these changes
Jan 6, 2022
Contributor
Author
|
Thanks for reviewing and merging. |
jenswet
reviewed
Feb 23, 2022
| endif | ||
|
|
||
| ifneq (,$(filter cpp11-compat,$(USEMODULE))) | ||
| USEMODULE += cpp_new_delete |
Contributor
There was a problem hiding this comment.
Hi @gschorcht,
Trying to understand the cpp11-compat and cpp_new_delete structure I have a question regarding this PR:
The docs of cpp_new_delete state the following:
@brief This module provides the `new` and `delete` operators for platforms
that do not use `libstdc++`.
@warning This module is automatically selected, if needed. Never add it
manually.
# Background
On some platforms `libstdc++` is not used or not available, like on the AVR.
Such platforms can use this module to implement the C++ `new` and `delete`
operators using `malloc` and `free` respectively. However, to be thread-safe,
a thread-safe implementation of `malloc` and `free` must be present.
# Usage
This module is intended to be use by platforms that not providing the required
operators. Hence, application developers and users should never select this
module by hand.
This PR adds the above module whenever cpp-compat is selected which contradicts to the above docs. Which is correct?
I'd like to file a PR to break down cpp11-compat in separate modules and align them better to the current RIOT structure, but first I need to understand this.
Thanks a lot!
CC @maribu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution description
This PR provides code deduplication as well as the ability for an application to use (re)defined
new/deleteoperators without requiringlibstdc++.The
sys/cpp11-compatmodule (re)defines thenew/deleteoperators but depends onlibstdc++even fornew/deleteoperators that don't needlibtsdc++. Modulesys/cpp_new_deleteprovides these operators for platforms that don't have thelibstdc++. Since these operators insys/cpp11-compatare just wrappers for standardmalloc/freefunctions like insys/cpp_new_delete, thenew/deleteoperators that don't needlibstdc++are used fromsys/cpp_new_delete. Only thenew/deleteoperators that require thelibstd++are left insys/cpp11-compat.So it is sufficient for the use of the (re)defined
new/deleteoperators that an application uses the modulesys/cpp_new_deleteinstead ofsys/cpp11-compatand thus also works on platforms withoutlibstdc++.On ARM platforms,
__dso_handleis used for dynamic shared objects. But it is also required if global static objects are used. To avoid thatsys/cpp11_compatis required only for using the (re)definednew/deleteoperators,__dso_handleis moved to modulesys/cpp_new_deleteTesting procedure
Green CI.
Issues/PRs references
Uses the module introduced by PR #17464