Commit ea2207d
[Cocoa] Fix deprecated SEL→jlong cast in sel_registerName via flags=cast
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 signature1 parent 596bef6 commit ea2207d
2 files changed
+5
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7645 | 7645 | | |
7646 | 7646 | | |
7647 | 7647 | | |
7648 | | - | |
| 7648 | + | |
7649 | 7649 | | |
7650 | 7650 | | |
7651 | 7651 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
562 | 562 | | |
563 | 563 | | |
564 | 564 | | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
565 | 569 | | |
566 | 570 | | |
567 | 571 | | |
| |||
0 commit comments