Fix build with panic="abort"#1038
Merged
milyin merged 1 commit intoeclipse-zenoh:mainfrom Jun 26, 2025
Merged
Conversation
When building with `panic="abort"` and `std` built from source, the size of `Mutex<()>` varies when wrapped in `Option<>` or not such that the owned and loaned types have different sizes. This is specifically due to the `poison` flag in `Mutex` getting compiled out when the `panic` mode is not set to `"unwind"`. The build fails as follows: ``` note: evaluation panicked: Size mismatch: type z_loaned_mutex_t has size 16 while type z_owned_mutex_t has size 24 ``` To address, we switch to `decl_c_type_inequal!` which seems to be safe since we shouldn't be `reinterpret_cast()`-ing this type and `zenoh-cpp` doesn't seem to ever reference it.
|
PR missing one of the required labels: {'new feature', 'enhancement', 'bug', 'internal', 'breaking-change', 'dependencies', 'documentation'} |
Contributor
Author
|
I want second-hand confirmation that this is fixing it the correct way and that there isn't any implicit assumptions in uses of |
DenisBiryukov91
approved these changes
Jun 25, 2025
Contributor
Yes, indeed this looks like a correct fix given that z_xxx_mutex is not used in C++ so requirement to have size_of::() == size_of::<Option>() is irrelevant (at least this is similar to what we do with z_owned_mutex_t in zenoh-pico). |
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.
When building with
panic="abort"andstdbuilt from source, the size ofMutex<()>varies when wrapped inOption<>or not such that the owned and loaned types have different sizes.This is specifically due to the
poisonflag field inMutexgetting compiled out when thepanicmode is not set to"unwind". This field's omission pushes the size of the struct to the edge of the 16 byte boundary such that niche optimization no longer has bits to fiddle with after aligning to 8 bytes.The build fails as follows:
To address, we switch to
decl_c_type_inequal!which seems to be safe since we shouldn't bereinterpret_cast()-ing this type andzenoh-cppdoesn't seem to ever reference it.