Repository navigation
fix: compile with exceptions disabled in dispatch_queue - #243
Merged
Merged
Conversation
DispatchQueue::runTask wraps tasks in an unconditional try/catch, which breaks the build when the embedding app compiles with -fno-exceptions. Guard it on __cpp_exceptions (clang/gcc) and _CPPUNWIND (MSVC); without exceptions the wrapped task just runs and fulfills the promise, since nothing can throw. Behavior with exceptions enabled is unchanged.
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.
Building an app that consumes gpupixel with
-fno-exceptionscurrently fails:DispatchQueue::runTaskinsrc/utils/dispatch_queue.ccwraps the queued task in an unconditional try/catch, and the compiler rejectstrywhen exceptions are disabled. This is the only exception handling site in the library, so this one file blocks the whole build for such apps.This change guards the try/catch with
#if defined(__cpp_exceptions) || defined(_CPPUNWIND). When exceptions are disabled, the fallback simply runs the task and fulfills the promise, which is safe because no exception can be in flight in that mode. Behavior with exceptions enabled is unchanged.On the macro choice:
__cpp_exceptionsis used instead of__EXCEPTIONSbecause on Apple platforms the library sources are compiled as Objective-C++, where clang still defines__EXCEPTIONS(for ObjC exceptions) even under-fno-exceptions.__cpp_exceptionstracks C++ exceptions exactly on clang and gcc, and_CPPUNWINDcovers MSVC.Verified on macOS (arm64, Release):
./script/build_macos.shwith default flags builds as before, and the preprocessor keeps the existing try/catch path.-DCMAKE_CXX_FLAGS=-fno-exceptionsnow builds the gpupixel target cleanly; on current main it fails in dispatch_queue.cc.-fno-exceptions.