Repository navigation
Conversation
C++'s IsRaw(RawImageTypes) reaches assert(false) for a value outside the enum. rust_is_raw_type returned false; abort instead.
Collaborator
|
We're fine with having the same prod behaviour for now. The debug assert is nice, but not worth the effort making a change for here. Thanks for the find! |
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.
Abort in IsRaw(type) for a value outside RawImageTypes, as C++ does
Problem
IsRaw(const RawImageTypes type)(C++, Rust) switches over the enum in C++:kNonRawImageis false, every raw type is true, and any other value reachesassert(false). WithoutNDEBUG, that aborts the process. The port returns false for any valueRawImageType::from_u32does not know. For example:IsRaw(static_cast<RawImageTypes>(-1))assert(false)fails, the process aborts (SIGABRT)IsRaw(static_cast<RawImageTypes>(25))Question
Which behaviour do we want: C++'s or the Rust port's? Specifically, for a value that is not a
RawImageTypesenumerator, shouldIsRawassert (like the C++ library), or return false (like the Rust port)?This PR implements C++'s behaviour.
Fix
rust_is_raw_typematches onRawImageType::from_u32(raw_type)and callsstd::process::abort()forNone:It aborts rather than panics because the
catch_unwindaround it would turn a panic back intofalse. The examples above then do what C++ does. Replayed before and after (x86-64):IsRaw(-1)IsRaw(25)Notes for review:
falsereturn into a process abort. That is what a C++ build withoutNDEBUGdoes; withNDEBUGthe C++assertis gone andIsRawreturns false, as the port does today. Which build the port should match is part of the question.RawImageTypebut not of piex'sRawImageTypes, so this PR alone still answers them (IsRaw(20)is true, C++ aborts). Use piex's RawImageTypes numbers in the cxx bridge #9 makes the bridge use piex's numbering and reads this value withfrom_cxx, which returnsNonefor them. Both PRs change this function, so whichever lands second needs a rebase; matching onfrom_cxx(raw_type)there makes 20 to 24 abort too.