mac-capture: Replace pragmas with availability markers
Description
Replace pragmas silencing -Wunguarded-availability-new by availlability markers.
Note: When placing the marker before a function declaration, clang-format can add an empty new line between the marker and the declaration. So markers were put after when it comes to function declaration.
Motivation and Context
I tried to unvendor simde and discover that mac-sdk-common.h pragmas somehow contaminated other mac-sck-*.mm files because of our vendored simde.
Simply moving the pragmas like the following allows to fix the contamination:
diff --git a/plugins/mac-capture/mac-sck-common.h b/plugins/mac-capture/mac-sck-common.h
index 32ca8d246a8a5..e8b1911f6164d 100644
--- a/plugins/mac-capture/mac-sck-common.h
+++ b/plugins/mac-capture/mac-sck-common.h
@@ -1,9 +1,6 @@
#include <AvailabilityMacros.h>
#include <Cocoa/Cocoa.h>
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunguarded-availability-new"
-
#include <stdlib.h>
#include <obs-module.h>
#include <util/threading.h>
@@ -14,6 +11,9 @@
#include <CoreMedia/CMSampleBuffer.h>
#include <CoreVideo/CVPixelBuffer.h>
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunguarded-availability-new"
+
#define MACCAP_LOG(level, msg, ...) blog(level, "[ mac-screencapture ]: " msg, ##__VA_ARGS__)
#define MACCAP_ERR(msg, ...) MACCAP_LOG(LOG_ERROR, msg, ##__VA_ARGS__)
Rather than fixing new warnings by adding more pragmas, I tried to find a better way.
And I found API_AVAILABLE() and based on Clang documentation:
If the caller of
my_fun()already checks thatmy_fun()is only called on 10.12, then add an availability attribute to it, which will also suppress the warning and require that calls to my_fun() are checked
And it seems to work for most of declaration not only functions.
How Has This Been Tested?
Building yes, macOS SCK was not tested.
Types of changes
- Bug fix (non-breaking change which fixes an issue)
- Tweak (non-breaking change to improve existing functionality)
- Code cleanup (non-breaking change which makes code smaller or more readable)
Checklist:
- [x] My code has been run through clang-format.
- [x] I have read the contributing document.
- [x] My code is not on the master branch.
- [ ] The code has been tested.
- [x] All commit messages are properly formatted and commits squashed where appropriate.
- [x] I have included updates to all appropriate documentation.
The whole SCK part is already behind one or two availability check. Adding checks all over already availability-checked code would make no sense.
The whole SCK part is behind one or two availability check. Adding checks all over already availability-checked code would make no sense.
Yeah looks like the availability attribute is necessary after all because the requirements leak across types.
Weirdly enough, when written out as __attribute__((availability(macos, introduced=13.0))), clang-format keeps it in front of a function, it's only when provided as the helper macro that it does this weird indentation - maybe this can be reigned in with the correct clang-format option..
Setting SeparateDefinitionBlocks: Leave (instead of Always) disables the formatting behaviour and allows placing the macro before or just above the function declaration (which is how Xcode automatically fixes the warnings).
I'm fine with setting it to Leave for ObjC in clang-format for this PR.
Like that @PatTheMav ? I'll squash if it's good.
Yeah I think it's fine - Xcode usually puts it on its own line above the function/type, but I dunno if clang-format moves it onto the same line again now.
clang-format moved some of them to the line above when I formatted, those were on the same line as the function before.
but I dunno if
clang-formatmoves it onto the same line again now.
No, it doesn't.
Edit: As in, if I split the function as two line between API_AVAILABLE and static it stays the newline is not removed.