From a194ec18e788b10cc2e78d14f17b0c2d9d252f81 Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Wed, 27 Nov 2019 14:43:20 +0700 Subject: [PATCH] [cinterop] Fix mapping of typedefs to pointers to typedefs Mapping type aliases from stub ir to metadata is kinda tricky. We need to preserve references to type alias declarations when translating expanded types. The problem is that we translate C declarations and types independently. In the most cases these processes are coherent. But not for type aliases to pointers to type aliases. This commit fixes it. --- .../kotlin/native/interop/gen/Mappings.kt | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/Mappings.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/Mappings.kt index d095738f19f..0d7c7223823 100644 --- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/Mappings.kt +++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/Mappings.kt @@ -469,12 +469,20 @@ fun mirror(declarationMapper: DeclarationMapper, type: Type): TypeMirror = when val name = type.def.name when (baseType) { - is TypeMirror.ByValue -> TypeMirror.ByValue( - Classifier.topLevel(pkg, "${name}Var").typeAbbreviation(baseType.pointedType), - baseType.info, - Classifier.topLevel(pkg, name).typeAbbreviation(baseType.valueType), - nullable = baseType.nullable - ) + is TypeMirror.ByValue -> { + val valueType = Classifier.topLevel(pkg, name).typeAbbreviation(baseType.valueType) + val underlyingPointedType = if (baseType.info is TypeInfo.Pointer) { + KotlinTypes.cPointerVarOf.typeWith(valueType) + } else { + baseType.pointedType + } + val pointedType = Classifier.topLevel(pkg, "${name}Var").typeAbbreviation(underlyingPointedType) + TypeMirror.ByValue( + pointedType, + baseType.info, + valueType, + nullable = baseType.nullable) + } is TypeMirror.ByRef -> TypeMirror.ByRef( Classifier.topLevel(pkg, name).typeAbbreviation(baseType.pointedType),