Skip to content

Replace deprecated native methods in macOS implementation #3186

@HannesWell

Description

@HannesWell

The SWT implementation for macOS currently referenced multiple deprecated native API methods:

  • CFURLCreateFromFSRef is deprecated

    os.c:1102:14: warning: 'CFURLCreateFromFSRef' is deprecated: first deprecated in macOS 10.9 - Not supported [-Wdeprecated-declarations]
            rc = (jlong)CFURLCreateFromFSRef((CFAllocatorRef)arg0, (FSRef*)lparg1);
                        ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFURL.h:484:10: note: 'CFURLCreateFromFSRef' has been explicitly marked deprecated here
    CFURLRef CFURLCreateFromFSRef(CFAllocatorRef allocator, const struct FSRef *fsRef) API_DEPRECATED("Not supported", macos(10.0,10.9), ios(2.0,7.0), watchos(2.0,2.0), tvos(9.0,9.0));
             ^
    
  • GetCurrentProcess is deprecated

    os.c:1920:13: warning: 'GetCurrentProcess' is deprecated: first deprecated in macOS 10.9 [-Wdeprecated-declarations]
            rc = (jint)GetCurrentProcess((ProcessSerialNumber *)lparg0);
                       ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/ApplicationServices.framework/Frameworks/HIServices.framework/Headers/Processes.h:415:1: note: 'GetCurrentProcess' has been explicitly marked deprecated here
    MacGetCurrentProcess(ProcessSerialNumber * PSN)               AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_9;
    ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/ApplicationServices.framework/Frameworks/HIServices.framework/Headers/Processes.h:412:34: note: expanded from macro 'MacGetCurrentProcess'
        #define MacGetCurrentProcess GetCurrentProcess
                                   ^
    
  • LSGetApplicationForInfo is deprecated

    os.c:2119:14: warning: 'LSGetApplicationForInfo' is deprecated: first deprecated in macOS 10.10 - Use -[NSWorkspace URLForApplicationToOpenContentType:] instead. [-Wdeprecated-declarations]
            rc = (jlong)LSGetApplicationForInfo((OSType)arg0, (OSType)arg1, (CFStringRef)arg2, (LSRolesMask)arg3, (FSRef *)lparg4, (CFURLRef *)lparg5);
                        ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Headers/LSInfoDeprecated.h:611:1: note: 'LSGetApplicationForInfo' has been explicitly marked deprecated here
    LSGetApplicationForInfo(
    ^
    
  • NSPrintSavePath is deprecated

    os.c:4040:14: warning: 'NSPrintSavePath' is deprecated: first deprecated in macOS 10.6 - Use NSPrintJobSavingURL instead [-Wdeprecated-declarations]
            rc = (jlong)NSPrintSavePath;
                        ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSPrintInfo.h:197:32: note: 'NSPrintSavePath' has been explicitly marked deprecated here
    APPKIT_EXTERN NSString * const NSPrintSavePath API_DEPRECATED("Use NSPrintJobSavingURL instead", macos(10.0,10.6));
                                   ^
    
  • SecPolicySearchCopyNext is deprecated

    os.c:4678:13: warning: 'SecPolicySearchCopyNext' is deprecated: first deprecated in macOS 10.7 [-Wdeprecated-declarations]
            rc = (jint)SecPolicySearchCopyNext((SecPolicySearchRef)arg0, (SecPolicyRef *)lparg1);
                       ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Security.framework/Headers/SecPolicySearch.h:78:10: note: 'SecPolicySearchCopyNext' has been explicitly marked deprecated here
    OSStatus SecPolicySearchCopyNext(SecPolicySearchRef searchRef, SecPolicyRef * __nonnull CF_RETURNS_RETAINED policyRef)
             ^
    
  • SecPolicySearchCreate is deprecated

    os.c:4694:13: warning: 'SecPolicySearchCreate' is deprecated: first deprecated in macOS 10.7 [-Wdeprecated-declarations]
            rc = (jint)SecPolicySearchCreate((CSSM_CERT_TYPE)arg0, (CSSM_OID *)arg1, (CSSM_DATA *)arg2, (SecPolicySearchRef *)lparg3);
                     ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Security.framework/Headers/SecPolicySearch.h:67:10: note: 'SecPolicySearchCreate' has been explicitly marked deprecated here
    OSStatus SecPolicySearchCreate(CSSM_CERT_TYPE certType, const CSSM_OID *policyOID, const CSSM_DATA * __nullable value, SecPolicySearchRef * __nonnull CF_RETURNS_RETAINED searchRef)
             ^
    
  • WebView is deprecated

    os.c:998:67: warning: 'WebView' is deprecated: first deprecated in macOS 10.14 - No longer supported; please adopt WKWebView. [-Wdeprecated-declarations]
      998 | static void proc_CALLBACK_1webView_1setFrame_1(id arg0, SEL arg1, WebView* arg2, NSRect arg3) {
          |                                                                   ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/WebKit.framework/Headers/WebView.h:119:12: note: 'WebView' has been explicitly marked deprecated here
      119 | @interface WebView : NSView
          |            ^
    
  • WebView is deprecated

    os.c:999:22: warning: 'WebView' is deprecated: first deprecated in macOS 10.14 - No longer supported; please adopt WKWebView. [-Wdeprecated-declarations]
      999 |         ((void (*)(id, SEL, WebView*, NSRect*))CALLBACK_1webView_1setFrame_1)(arg0, arg1, arg2, &arg3);
          |                             ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/WebKit.framework/Headers/WebView.h:119:12: note: 'WebView' has been explicitly marked deprecated here
      119 | @interface WebView : NSView
          |            ^
    
  • CFURLCreateStringByAddingPercentEscapes is deprecated

    os.c:1116:14: warning: 'CFURLCreateStringByAddingPercentEscapes' is deprecated: first deprecated in macOS 10.11 - Use [NSString stringByAddingPercentEncodingWithAllowedCharacters:] instead, which always uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent (since each URL component or subcomponent has different rules for what characters are valid). [-Wdeprecated-declarations]
     1116 |         rc = (jlong)CFURLCreateStringByAddingPercentEscapes((CFAllocatorRef)arg0, (CFStringRef)arg1, (CFStringRef)arg2, (CFStringRef)arg3, (CFStringEncoding)arg4);
          |                     ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFURL.h:408:13: note: 'CFURLCreateStringByAddingPercentEscapes' has been explicitly marked deprecated here
      408 | CFStringRef CFURLCreateStringByAddingPercentEscapes(CFAllocatorRef allocator, CFStringRef originalString, CFStringRef charactersToLeaveUnescaped, CFStringRef legalURLCharactersToBeEscaped, CFStringEncoding encoding) API_DEPRECATED("Use [NSString stringByAddingPercentEncodingWithAllowedCharacters:] instead, which always uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent (since each URL component or subcomponent has different rules for what characters are valid).", macos(10.0,10.11), ios(2.0,9.0), watchos(2.0,2.0), tvos(9.0,9.0));
          |             ^
    
  • NSDragPboard is deprecated

    os.c:3666:14: warning: 'NSDragPboard' is deprecated: first deprecated in macOS 10.13 [-Wdeprecated-declarations]
     3666 |         rc = (jlong)NSDragPboard;
          |                     ^~~~~~~~~~~~
          |                     NSPasteboardNameDrag
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSPasteboard.h:531:32: note: 'NSDragPboard' has been explicitly marked deprecated here
      531 | APPKIT_EXTERN NSPasteboardName NSDragPboard API_DEPRECATED_WITH_REPLACEMENT("NSPasteboardNameDrag", macos(10.0,10.13));
          |                                ^
    
  • NSFilenamesPboardType is deprecated

    os.c:3709:14: warning: 'NSFilenamesPboardType' is deprecated: first deprecated in macOS 10.14 - Create multiple pasteboard items with NSPasteboardTypeFileURL or kUTTypeFileURL instead [-Wdeprecated-declarations]
     3709 |         rc = (jlong)NSFilenamesPboardType;
          |                     ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSPasteboard.h:505:32: note: 'NSFilenamesPboardType' has been explicitly marked deprecated here
      505 | APPKIT_EXTERN NSPasteboardType NSFilenamesPboardType API_DEPRECATED("Create multiple pasteboard items with NSPasteboardTypeFileURL or kUTTypeFileURL instead", macos(10.0,10.14));
          |                                ^
    
  • NSTIFFPboardType is deprecated

    os.c:4186:14: warning: 'NSTIFFPboardType' is deprecated: first deprecated in macOS 10.14 [-Wdeprecated-declarations]
     4186 |         rc = (jlong)NSTIFFPboardType;
          |                     ^~~~~~~~~~~~~~~~
          |                     NSPasteboardTypeTIFF
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSPasteboard.h:506:32: note: 'NSTIFFPboardType' has been explicitly marked deprecated here
      506 | APPKIT_EXTERN NSPasteboardType NSTIFFPboardType API_DEPRECATED_WITH_REPLACEMENT("NSPasteboardTypeTIFF", macos(10.0,10.14));
          |                                ^
    
  • NSURLPboardType is deprecated

    os.c:4222:14: warning: 'NSURLPboardType' is deprecated: first deprecated in macOS 10.14 [-Wdeprecated-declarations]
     4222 |         rc = (jlong)NSURLPboardType;
          |                     ^~~~~~~~~~~~~~~
          |                     NSPasteboardTypeURL
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSPasteboard.h:514:32: note: 'NSURLPboardType' has been explicitly marked deprecated here
      514 | APPKIT_EXTERN NSPasteboardType NSURLPboardType API_DEPRECATED_WITH_REPLACEMENT("NSPasteboardTypeURL", macos(10.0,10.14));
          |                                ^
    
  • NSViewGlobalFrameDidChangeNotification is deprecated

    os.c:4258:14: warning: 'NSViewGlobalFrameDidChangeNotification' is deprecated: first deprecated in macOS 10.14 - Use NSOpenGLView instead. [-Wdeprecated-declarations]
     4258 |         rc = (jlong)NSViewGlobalFrameDidChangeNotification;
          |                     ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSView.h:668:34: note: 'NSViewGlobalFrameDidChangeNotification' has been explicitly marked deprecated here
      668 | APPKIT_EXTERN NSNotificationName NSViewGlobalFrameDidChangeNotification API_DEPRECATED("Use NSOpenGLView instead.", macos(10.0,10.14));
          |                                  ^
    
  • passing arguments to a function without a prototype is deprecated

    os.c:4883:20: warning: passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C23 [-Wdeprecated-non-prototype]
     4883 |         ((void (*)())arg0)(arg1, arg2);
          |                           ^
    
  • cast of type SEL _Nonnull [...] is deprecated

    os.c:7648:14: warning: cast of type 'SEL _Nonnull' to 'jlong' (aka 'long') is deprecated; use sel_getName instead [-Wcast-of-sel-type]
            rc = (jlong)sel_registerName(lparg0);
                        ^~~~~~~~~~~~~~~~~~~~~~~~
    
  • OSAtomicIncrement32 is deprecated

    callback.c:1968:2: warning: 'OSAtomicIncrement32' is deprecated: first deprecated in macOS 10.12 - Use atomic_fetch_add_explicit(memory_order_relaxed) from <stdatomic.h> instead [-Wdeprecated-declarations]
     1968 |         ATOMIC_INC(callbackEntryCount);
          |         ^
    callback.c:49:27: note: expanded from macro 'ATOMIC_INC'
       49 | #define ATOMIC_INC(value) OSAtomicIncrement32(&value);
          |                           ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libkern/OSAtomicDeprecated.h:173:9: note: 'OSAtomicIncrement32' has been explicitly marked deprecated here
      173 | int32_t OSAtomicIncrement32( volatile int32_t *__theValue );
          |         ^
    
  • OSAtomicDecrement32 is deprecated

    callback.c:1999:2: warning: 'OSAtomicDecrement32' is deprecated: first deprecated in macOS 10.12 - Use atomic_fetch_sub_explicit(memory_order_relaxed) from <stdatomic.h> instead [-Wdeprecated-declarations]
     1999 |         ATOMIC_DEC(callbackEntryCount);
          |         ^
    callback.c:50:27: note: expanded from macro 'ATOMIC_DEC'
       50 | #define ATOMIC_DEC(value) OSAtomicDecrement32(&value);
          |                           ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libkern/OSAtomicDeprecated.h:192:9: note: 'OSAtomicDecrement32' has been explicitly marked deprecated here
      192 | int32_t OSAtomicDecrement32( volatile int32_t *__theValue );
          |         ^
    

In total 18 (16 + 2) warnings are generated.
It would be good to replace them as it would allow us to fail on all kind of warnings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    macOShappens on macOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions