Fix NSUInteger size for Watchos x64

This commit is contained in:
Pavel Punegov
2020-12-24 15:50:56 +03:00
committed by Nikolay Krasko
parent 6cc60ad6a2
commit e241d1249c
2 changed files with 8 additions and 19 deletions
@@ -1586,34 +1586,22 @@ internal fun ObjCExportCodeGenerator.getEncoding(methodBridge: MethodBridge): St
}
}
val targetFamily = context.config.target.family
val returnTypeEncoding = methodBridge.returnBridge.getObjCEncoding(targetFamily)
val returnTypeEncoding = methodBridge.returnBridge.getObjCEncoding(context)
val paramSize = paramOffset
return "$returnTypeEncoding$paramSize$params"
}
// https://developer.apple.com/documentation/objectivec/nsuinteger?language=objc
// `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) {
private fun MethodBridge.ReturnValue.getObjCEncoding(context: Context): String = when (this) {
MethodBridge.ReturnValue.Suspend,
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
MethodBridge.ReturnValue.WithError.Success -> ObjCValueType.BOOL.encoding
MethodBridge.ReturnValue.Instance.InitResult,
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) {
@@ -67,11 +67,12 @@ fun run() {
// hashCode (directly):
// 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.
OsFamily.WATCHOS -> foo.hash().toInt()
foo.hash().toInt()
} else {
// `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) {
// toString (virtually):