Fix NSUInteger size for Watchos x64
This commit is contained in:
committed by
Nikolay Krasko
parent
6cc60ad6a2
commit
e241d1249c
+4
-16
@@ -1586,34 +1586,22 @@ internal fun ObjCExportCodeGenerator.getEncoding(methodBridge: MethodBridge): St
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val targetFamily = context.config.target.family
|
val returnTypeEncoding = methodBridge.returnBridge.getObjCEncoding(context)
|
||||||
val returnTypeEncoding = methodBridge.returnBridge.getObjCEncoding(targetFamily)
|
|
||||||
|
|
||||||
val paramSize = paramOffset
|
val paramSize = paramOffset
|
||||||
return "$returnTypeEncoding$paramSize$params"
|
return "$returnTypeEncoding$paramSize$params"
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://developer.apple.com/documentation/objectivec/nsuinteger?language=objc
|
private fun MethodBridge.ReturnValue.getObjCEncoding(context: Context): String = when (this) {
|
||||||
// `typedef unsigned long NSUInteger` on iOS, macOS, tvOS.
|
|
||||||
// `typedef unsigned int NSInteger` on watchOS.
|
|
||||||
private val Family.nsUIntegerEncoding: String get() = when (this) {
|
|
||||||
Family.OSX,
|
|
||||||
Family.IOS,
|
|
||||||
Family.TVOS -> "L"
|
|
||||||
Family.WATCHOS -> "I"
|
|
||||||
else -> error("Unexpected target platform: $this")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun MethodBridge.ReturnValue.getObjCEncoding(targetFamily: Family): String = when (this) {
|
|
||||||
MethodBridge.ReturnValue.Suspend,
|
MethodBridge.ReturnValue.Suspend,
|
||||||
MethodBridge.ReturnValue.Void -> "v"
|
MethodBridge.ReturnValue.Void -> "v"
|
||||||
MethodBridge.ReturnValue.HashCode -> targetFamily.nsUIntegerEncoding
|
MethodBridge.ReturnValue.HashCode -> if (context.is64BitNSInteger()) "L" else "I"
|
||||||
is MethodBridge.ReturnValue.Mapped -> this.bridge.objCEncoding
|
is MethodBridge.ReturnValue.Mapped -> this.bridge.objCEncoding
|
||||||
MethodBridge.ReturnValue.WithError.Success -> ObjCValueType.BOOL.encoding
|
MethodBridge.ReturnValue.WithError.Success -> ObjCValueType.BOOL.encoding
|
||||||
|
|
||||||
MethodBridge.ReturnValue.Instance.InitResult,
|
MethodBridge.ReturnValue.Instance.InitResult,
|
||||||
MethodBridge.ReturnValue.Instance.FactoryResult -> ReferenceBridge.objCEncoding
|
MethodBridge.ReturnValue.Instance.FactoryResult -> ReferenceBridge.objCEncoding
|
||||||
is MethodBridge.ReturnValue.WithError.ZeroForError -> this.successBridge.getObjCEncoding(targetFamily)
|
is MethodBridge.ReturnValue.WithError.ZeroForError -> this.successBridge.getObjCEncoding(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val MethodBridgeParameter.objCEncoding: String get() = when (this) {
|
private val MethodBridgeParameter.objCEncoding: String get() = when (this) {
|
||||||
|
|||||||
@@ -67,11 +67,12 @@ fun run() {
|
|||||||
|
|
||||||
// hashCode (directly):
|
// hashCode (directly):
|
||||||
// hash() returns value of NSUInteger type.
|
// hash() returns value of NSUInteger type.
|
||||||
val hash = when (Platform.osFamily) {
|
val hash = if (Platform.osFamily == OsFamily.WATCHOS && Platform.cpuArchitecture.bitness == 32) {
|
||||||
// `typedef unsigned int NSInteger` on watchOS.
|
// `typedef unsigned int NSInteger` on watchOS.
|
||||||
OsFamily.WATCHOS -> foo.hash().toInt()
|
foo.hash().toInt()
|
||||||
|
} else {
|
||||||
// `typedef unsigned long NSUInteger` on iOS, macOS, tvOS.
|
// `typedef unsigned long NSUInteger` on iOS, macOS, tvOS.
|
||||||
else -> foo.hash().let { it.toInt() xor (it shr 32).toInt() }
|
foo.hash().let { it.toInt() xor (it shr 32).toInt() }
|
||||||
}
|
}
|
||||||
if (foo.hashCode() == hash) {
|
if (foo.hashCode() == hash) {
|
||||||
// toString (virtually):
|
// toString (virtually):
|
||||||
|
|||||||
Reference in New Issue
Block a user