Skip to content

Commit 77bf797

Browse files
committed
update docs
1 parent 145bbfe commit 77bf797

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

Sources/SwiftJava/BridgedValues/JavaValue+Integers.swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,13 @@ extension UInt64: JavaValue {
354354
public static var jvalueKeyPath: WritableKeyPath<jvalue, JNIType> { \.j }
355355

356356
public func getJNIValue(in environment: JNIEnvironment) -> JNIType {
357-
// On 32-bit, standard JDK jlong is defined as long long = Int64
358-
// On 64-bit, standard JDK jlong is defined as long = Int
359-
// On Android it's correctly marked as int64_t
357+
// `jlong` is always 64-bit, no matter the system pointer size.
358+
// Due to differences in JNI headers between Android, JDK and how Swift sees these type imports
359+
// we have to handle this a bit differently.
360+
//
361+
// On 32-bit, the standard JDK jlong is defined in C as `long long`, which yields Swift `Int64`
362+
// On 64-bit, the standard JDK jlong is defined in C as `long`, which yields Swift `Int`
363+
// On Android it's correctly marked as int64_t, always yielding `Int64` in Swift.
360364
#if os(Android) || _pointerBitWidth(_32)
361365
return Int64(bitPattern: self)
362366
#else
@@ -365,12 +369,18 @@ extension UInt64: JavaValue {
365369
}
366370

367371
public init(fromJNI value: JNIType, in environment: JNIEnvironment) {
368-
// On 32-bit, standard JDK jlong is defined as long long = Int64
369-
// On 64-bit, standard JDK jlong is defined as long = Int
370-
// On Android it's correctly marked as int64_t
372+
// `jlong` is always 64-bit, no matter the system pointer size.
373+
// Due to differences in JNI headers between Android, JDK and how Swift sees these type imports
374+
// we have to handle this a bit differently.
375+
//
376+
// On 32-bit, the standard JDK jlong is defined in C as `long long`, which yields Swift `Int64`
377+
// On 64-bit, the standard JDK jlong is defined in C as `long`, which yields Swift `Int`
378+
// On Android it's correctly marked as int64_t, always yielding `Int64` in Swift.
371379
#if os(Android) || _pointerBitWidth(_32)
380+
// In this case `jlong` is seen in Swift as `Int64`.
372381
self = UInt64(bitPattern: value)
373382
#else
383+
// In this case `jlong` is since as just `Int`, which is always Int64
374384
self = UInt64(bitPattern: Int64(value))
375385
#endif
376386
}

0 commit comments

Comments
 (0)