Fix support for pointers to arrays in interop
Also represent multidimensional arrays as one-dimensional ones.
This commit is contained in:
committed by
SvyatoslavScherbina
parent
4a54fe793e
commit
9ad17f5e48
+15
-14
@@ -378,9 +378,12 @@ class StubGenerator(
|
|||||||
|
|
||||||
is PointerType -> {
|
is PointerType -> {
|
||||||
val pointeeType = type.pointeeType
|
val pointeeType = type.pointeeType
|
||||||
if (pointeeType.unwrapTypedefs() is VoidType) {
|
val unwrappedPointeeType = pointeeType.unwrapTypedefs()
|
||||||
|
if (unwrappedPointeeType is VoidType) {
|
||||||
val info = TypeInfo.Pointer("COpaque")
|
val info = TypeInfo.Pointer("COpaque")
|
||||||
TypeMirror.ByValue("COpaquePointerVar", info, "COpaquePointer")
|
TypeMirror.ByValue("COpaquePointerVar", info, "COpaquePointer")
|
||||||
|
} else if (unwrappedPointeeType is ArrayType) {
|
||||||
|
mirror(pointeeType)
|
||||||
} else {
|
} else {
|
||||||
val pointeeMirror = mirror(pointeeType)
|
val pointeeMirror = mirror(pointeeType)
|
||||||
val info = TypeInfo.Pointer(pointeeMirror.pointedTypeName)
|
val info = TypeInfo.Pointer(pointeeMirror.pointedTypeName)
|
||||||
@@ -392,9 +395,13 @@ class StubGenerator(
|
|||||||
is ArrayType -> {
|
is ArrayType -> {
|
||||||
// TODO: array type doesn't exactly correspond neither to pointer nor to value.
|
// TODO: array type doesn't exactly correspond neither to pointer nor to value.
|
||||||
val elemTypeMirror = mirror(type.elemType)
|
val elemTypeMirror = mirror(type.elemType)
|
||||||
val info = TypeInfo.Pointer(elemTypeMirror.pointedTypeName)
|
if (type.elemType.unwrapTypedefs() is ArrayType) {
|
||||||
TypeMirror.ByValue("CArrayPointerVar<${elemTypeMirror.pointedTypeName}>", info,
|
elemTypeMirror
|
||||||
"CArrayPointer<${elemTypeMirror.pointedTypeName}>")
|
} else {
|
||||||
|
val info = TypeInfo.Pointer(elemTypeMirror.pointedTypeName)
|
||||||
|
TypeMirror.ByValue("CArrayPointerVar<${elemTypeMirror.pointedTypeName}>", info,
|
||||||
|
"CArrayPointer<${elemTypeMirror.pointedTypeName}>")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is FunctionType -> byRefTypeMirror("CFunction<${type.kotlinName}>")
|
is FunctionType -> byRefTypeMirror("CFunction<${type.kotlinName}>")
|
||||||
@@ -440,11 +447,6 @@ class StubGenerator(
|
|||||||
* Constructs [OutValueBinding] for the value of given C type.
|
* Constructs [OutValueBinding] for the value of given C type.
|
||||||
*/
|
*/
|
||||||
fun getOutValueBinding(type: Type): OutValueBinding {
|
fun getOutValueBinding(type: Type): OutValueBinding {
|
||||||
if (type.unwrapTypedefs() is ArrayType) {
|
|
||||||
// array-typed C function argument or return value is actually a pointer to array.
|
|
||||||
return getOutValueBinding(PointerType(type))
|
|
||||||
}
|
|
||||||
|
|
||||||
val mirror = mirror(type)
|
val mirror = mirror(type)
|
||||||
|
|
||||||
return OutValueBinding(
|
return OutValueBinding(
|
||||||
@@ -467,6 +469,10 @@ class StubGenerator(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (unwrappedPointeeType is ArrayType) {
|
||||||
|
return representCFunctionParameterAsValuesRef(pointeeType)
|
||||||
|
}
|
||||||
|
|
||||||
return pointeeType
|
return pointeeType
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,11 +531,6 @@ class StubGenerator(
|
|||||||
* Constructs [InValueBinding] for the value of given C type.
|
* Constructs [InValueBinding] for the value of given C type.
|
||||||
*/
|
*/
|
||||||
fun getInValueBinding(type: Type): InValueBinding {
|
fun getInValueBinding(type: Type): InValueBinding {
|
||||||
if (type.unwrapTypedefs() is ArrayType) {
|
|
||||||
// array-typed C function argument or return value is actually a pointer to array.
|
|
||||||
return getInValueBinding(PointerType(type))
|
|
||||||
}
|
|
||||||
|
|
||||||
val mirror = mirror(type)
|
val mirror = mirror(type)
|
||||||
|
|
||||||
return InValueBinding(
|
return InValueBinding(
|
||||||
|
|||||||
Reference in New Issue
Block a user