Handle different ThreadDestructor signatures between Android NDK 27 and NDK 28 #3249
+21
−1
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.
This change enables swift-nio to be compiled for Android against both NDK 27 and NDK 28
Motivation:
Android's NDK had been adopting nullability annotations in its C headers, and they have been changing them from release to release. The churn has mostly died down since the release of the NDK 27 (LTS), but one new change in NDK 28 affects the destructor argument for
pthread_create
, making the existingThreadDestructor
typealias invalid and leading to the following compile error when the Android SDK bundle is installed and linked to NDK 28:This change adapts the parameter we pass to that function to accommodate both NDK 27 and NDK 28.
Modifications:
There's currently no way to determine which version of the NDK is in use at compile time (see swiftlang/swift#81402), so this accommodation is implementing by having two functions named
coerceThreadDestructor
that return values that are suitable either NDK 27 or NDK 28 (usingunsafeBitCast
, but the layout of C functions doesn't know anything about nullability, so this is safe), and then let the type inference forpthread_create
handle the rest.Result:
swift-nio can be compiled against both NDK 27 and NDK 28 without errors.