Fix C API generation. (#1182)

This commit is contained in:
Nikolay Igotti
2017-12-25 16:24:16 +03:00
committed by GitHub
parent 38069d47ea
commit a05688351a
5 changed files with 160 additions and 28 deletions
+8 -1
View File
@@ -2345,7 +2345,14 @@ task produce_dynamic(type: DynamicKonanTest) {
disabled = (project.testTarget != null && project.testTarget != project.hostName)
source = "produce_dynamic/simple/hello.kt"
cSource = "$projectDir/produce_dynamic/simple/main.c"
goldValue = "Hello, dynamic!\n"
goldValue = "Hello, dynamic!\n" +
"Base.foo\n" +
"Base.fooParam: a 1\n" +
"Child.fooParam: b 2\n" +
"Child.fooParam: c 3\n" +
"Impl1.I: d 4 Impl1\n" +
"Impl2.I: e 5 Impl2\n" +
"String is Kotlin/Native\n"
}
task buildKonanTests(type: BuildKonanTest) {
@@ -1,4 +1,37 @@
// Top level functions.
fun hello() {
println("Hello, dynamic!")
}
fun getString() = "Kotlin/Native"
// Class with inheritance.
open class Base {
open fun foo() = println("Base.foo")
open fun fooParam(arg0: String, arg1: Int) = println("Base.fooParam: $arg0 $arg1")
}
class Child : Base() {
override fun fooParam(arg0: String, arg1: Int) = println("Child.fooParam: $arg0 $arg1")
}
// Interface.
interface I {
fun foo(arg0: String, arg1: Int, arg2: I)
fun fooImpl() = foo("Hi", 239, this)
}
open class Impl1: I {
override fun foo(arg0: String, arg1: Int, arg2: I) {
println("Impl1.I: $arg0 $arg1 ${arg2::class.qualifiedName}")
}
}
class Impl2 : Impl1() {
override fun foo(arg0: String, arg1: Int, arg2: I) {
println("Impl2.I: $arg0 $arg1 ${arg2::class.qualifiedName}")
}
}
@@ -1,7 +1,36 @@
#include <stdio.h>
#include "testlib_api.h"
#define __ testlib_symbols()->
#define T_(x) testlib_kref_ ## x
#define CAST(T, v) testlib_kref_ ## T { .pinned = v }
int main(void) {
testlib_symbols()->kotlin.root.hello();
T_(Base) base = __ kotlin.root.Base.Base();
T_(Child) child = __ kotlin.root.Child.Child();
T_(Impl1) impl1 = __ kotlin.root.Impl1.Impl1();
T_(Impl2) impl2 = __ kotlin.root.Impl2.Impl2();
T_(Base) casted_child = { .pinned = child.pinned };
T_(I) casted_impl1 = { .pinned = impl1.pinned };
T_(I) casted_impl2 = { .pinned = impl2.pinned };
const char* string = __ kotlin.root.getString();
__ kotlin.root.hello();
__ kotlin.root.Base.foo(base);
__ kotlin.root.Base.fooParam(base, "a", 1);
__ kotlin.root.Child.fooParam(child, "b", 2);
__ kotlin.root.Base.fooParam(casted_child, "c", 3);
__ kotlin.root.I.foo(casted_impl1, "d", 4, casted_impl1);
__ kotlin.root.I.foo(casted_impl2, "e", 5, casted_impl2);
printf("String is %s\n", string);
__ DisposeString(string);
__ DisposeStablePointer(base.pinned);
__ DisposeStablePointer(child.pinned);
__ DisposeStablePointer(impl1.pinned);
__ DisposeStablePointer(impl2.pinned);
return 0;
}