Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typical usage of the library should not require casting away const qualifiers #175

Closed
pavel-kirienko opened this issue Jul 29, 2021 · 0 comments · Fixed by #182
Closed
Milestone

Comments

@pavel-kirienko
Copy link
Member

@thirtytwobits says:

the CanardTransfer payload is const void* but is <...> used to free the payload when you are done with it. This leads to const_cast<void*>(transfer->payload) in C++ which is not something you ever want to see. const is part of the API so if you violate the constness you are, technically, entering undefined behaviour.

to which I say:

This is a known issue, yes: https://github.com/UAVCAN/libcanard/blob/2a116170285fb47fcaae150ad21c2ccde0756a5f/libcanard/canard.h#L251-L252
The reason the deallocation function accepts a mutable void* is because the free() from the standard library is defined this way.
We could make it const void* but then if you are using the standard heap or pretty much any other heap manager implemented in C (like o1heap), you will have to cast away your const anyway before calling the deallocation function.
Making o1heapFree() accept a const void would require it to cast away the const also because it has to mutate the returned memory fragment.

Fixing this requires breaking API changes so it is postponed until v2.0.

@pavel-kirienko pavel-kirienko added this to the v2.0 milestone Jul 29, 2021
pavel-kirienko added a commit that referenced this issue Dec 4, 2021
* Drop canard_dsdl, use Nunavut instead

* Upgrade CI to LLVM 13

* Actualize license headers

* Support redundant transmission queues and use more consistent public field naming

* Ditch the deprecated canardRxAccept(), rename canardRxAccept2()

* Refactor the API to eliminate the need to cast away const qualifiers; fixes #175

* Tighten up memory checking in the test suite -- add canaries

* Fix race condition in the roundtrip test

* Do not use Catch2 macros from non-main thread because it is not thread-safe

* Support CANARD_CONFIG_HEADER

* CI: add style_check job

* Use AVL tree in the transmission queue

* Remove all linked lists

* Reduce indirection, pointer casts, and memory footprint by exposing the AVL tree in the public API

* Disable C++-specific warnings as they make no sense for a C library

* Add table-based CRC option (#186)

* CI: disable SonarCloud on forks

* Add docker utilities (#187)

* Add acceptance filter configuration helpers (#171)

Co-authored-by: Kalyan Sriram <coder.kalyan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant