-
Notifications
You must be signed in to change notification settings - Fork 131
Interop: send events to fallback event handler if active configuration not present #1439
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
base: main
Are you sure you want to change the base?
Interop: send events to fallback event handler if active configuration not present #1439
Conversation
…n not present WIP, needs some additional work to get build working locally. Although the `_swift_testing_getFallbackEventHandler` is forward declared, I don't think it will be present at link time since we're not linking against _TestingInterop.
|
|
||
| #if !SWT_NO_INTEROP | ||
|
|
||
| typedef void (*FallbackEventHandler)(const char *recordJSONSchemaVersionNumber, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR's still a draft, but if you stick with this approach, please plan to add some documentation for these (even if it's a cursory explanation of how they shadow functions elsewhere).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| typedef void (*FallbackEventHandler)(const char *recordJSONSchemaVersionNumber, | |
| typedef void (* FallbackEventHandler)(const char *recordJSONSchemaVersionNumber, |
The smallest possible nitpick. :)
| /// currently-installed handler belongs to the testing library, returns | ||
| /// `false`. | ||
| borrowing func postToFallbackHandler(in context: borrowing Context) -> Bool { | ||
| #if canImport(_TestingInterop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style-wise, we usually outdent #if guards to column 0
| } | ||
| #endif | ||
|
|
||
| #if !SWT_NO_INTEROP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anywhere you're doing this, I suggest changing it to:
| #if !SWT_NO_INTEROP | |
| #if compiler(>=6.3) && !SWT_NO_INTEROP |
So that when we build against the 6.2 toolchain, we don't even try to link this function.
| long recordJSONByteCount, | ||
| const void *_Nullable reserved); | ||
|
|
||
| FallbackEventHandler _Nullable _swift_testing_getFallbackEventHandler(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| FallbackEventHandler _Nullable _swift_testing_getFallbackEventHandler(); | |
| SWT_EXTERN FallbackEventHandler _Nullable _swift_testing_getFallbackEventHandler(void); |
The argument lists () and (void) don't mean the same thing in C. 😱
| } | ||
|
|
||
| // Encode the event as JSON and pass it to the handler. | ||
| let encodeAndInvoke = ABI.CurrentVersion.eventHandler(encodeAsJSONLines: false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to cache this event handler somewhere as there's a bit of runtime overhead to generating it. Remember the fallback event handler can't change after its initial assignment, and will be set by the time an event is generated, so we don't need to worry about it having changed on later calls (i.e. the closure we generate here can permanently capture it.)
WIP, needs some additional work to get build working locally. Although the
_swift_testing_getFallbackEventHandleris forward declared, I don't think it will be present at link time since we're not linking against _TestingInterop.