From ea2207dd78c765a2e3d9b3ad10f3014f8266e1e2 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Fri, 3 Apr 2026 17:05:11 +0200 Subject: [PATCH] =?UTF-8?q?[Cocoa]=20Fix=20deprecated=20SEL=E2=86=92jlong?= =?UTF-8?q?=20cast=20in=20sel=5FregisterName=20via=20flags=3Dcast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Clang compiler (-Wcast-of-sel-type) deprecates any direct cast of the Objective-C SEL type to an arithmetic or pointer type, recommending the use of sel_getName() instead. The warning appeared in os.c: rc = (jlong)sel_registerName(lparg0); // warning: cast of type 'SEL _Nonnull' to 'jlong' is deprecated; // use sel_getName instead [-Wcast-of-sel-type] Rather than routing through sel_getName() (which returns a const char* that would still require an integer cast), the fix applies the same pattern already used for objc_msgSend throughout SWT: the `flags=cast` JNI generator annotation, which casts the entire C function pointer to the desired return type instead of casting the returned value: rc = (jlong)((jlong (*)(const char*))sel_registerName)(lparg0); This avoids any explicit cast of the SEL value itself. The function pointer cast tells the compiler that the function returns jlong directly, bypassing the SEL type in the return position entirely. This is semantically safe on 64-bit platforms where SEL (a pointer) and jlong are both 8 bytes with the same bit representation. The annotation changes in OS.java drive the code generation: - @method flags=cast — use function-pointer-cast call pattern - @param selectorName cast=(const char*) — match the native signature --- bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c | 2 +- .../cocoa/org/eclipse/swt/internal/cocoa/OS.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c index b29812ac75..d4730bd444 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c @@ -7645,7 +7645,7 @@ JNIEXPORT jlong JNICALL OS_NATIVE(sel_1registerName) jlong rc = 0; OS_NATIVE_ENTER(env, that, sel_1registerName_FUNC); if (arg0) if ((lparg0 = (*env)->GetStringUTFChars(env, arg0, NULL)) == NULL) goto fail; - rc = (jlong)sel_registerName(lparg0); + rc = (jlong)((jlong (*)(const char*))sel_registerName)((const char*)lparg0); fail: if (arg0 && lparg0) (*env)->ReleaseStringUTFChars(env, arg0, lparg0); OS_NATIVE_EXIT(env, that, sel_1registerName_FUNC); diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java index fffa4837ed..9cdaaf233e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java @@ -562,6 +562,10 @@ public static boolean isBigSurOrLater () { * @param clazz cast=(Class) */ public static final native long object_setClass(long obj, long clazz); +/** + * @method flags=cast + * @param selectorName cast=(const char*) + */ public static final native long sel_registerName(String selectorName); public static final native int objc_super_sizeof();