AsahiLinux/macvdmtool

warning: 'kIOMasterPortDefault' is deprecated: first deprecated in macOS 12.0

n8felton opened this issue · 3 comments

% sw_vers
ProductName:		macOS
ProductVersion:		13.5
BuildVersion:		22G74

% xcodebuild -version

Xcode 14.3
Build version 14E222b

image

main.cpp:102:56: warning: 'kIOMasterPortDefault' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, matching);
                                                       ^~~~~~~~~~~~~~~~~~~~
                                                       kIOMainPortDefault
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOKitLib.h:133:19: note: 'kIOMasterPortDefault' has been explicitly marked deprecated here
const mach_port_t kIOMasterPortDefault
                  ^
main.cpp:130:38: warning: 'kIOMasterPortDefault' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]
    if (IOServiceGetMatchingServices(kIOMasterPortDefault, matching, &iter) != kIOReturnSuccess)
                                     ^~~~~~~~~~~~~~~~~~~~
                                     kIOMainPortDefault
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOKitLib.h:133:19: note: 'kIOMasterPortDefault' has been explicitly marked deprecated here
const mach_port_t kIOMasterPortDefault
                  ^

Changing kIOMainPortDefault to just 0 should work. Hoping to test and submit PR, but documenting it for now.

Of course after hitting submit I realize that all they're really doing is renaming kIOMasterPortDefault to kIOMainPortDefault. (Master to Main)

Option 1

Switch kIOMasterPortDefault to kIOMainPortDefault but kIOMainPortDefault will only work with macOS 12+ unless we do something like libusb/hidapi#377 (comment)

#if (MAC_OS_X_VERSION_MAX_ALLOWED < 120000) // Before macOS 12 Monterey
  #define kIOMainPortDefault kIOMasterPortDefault
#endif

Option 2

When specifying a primary port to IOKit functions, the NULL argument indicates "use the default". This is a synonym for NULL, if you'd rather use a named constant.

kIOMasterPortDefault and kIOMainPortDefault are just synonyms for NULL, which is just 0 in C++. So, change kIOMasterPortDefault to 0 and not care about which version of macOS/Xcode we're compiling for/on.