Support importing string literal macros with cinterop

This commit is contained in:
Svyatoslav Scherbina
2018-02-19 15:58:14 +03:00
committed by SvyatoslavScherbina
parent 4335f891b7
commit e035ac1022
12 changed files with 119 additions and 52 deletions
+12
View File
@@ -2350,6 +2350,10 @@ kotlinNativeInterop {
defFile 'interop/basics/cfunptr.def'
}
cmacros {
defFile 'interop/basics/cmacros.def'
}
if (isMac()) {
objcSmoke {
defFile 'interop/objc/objcSmoke.def'
@@ -2425,6 +2429,12 @@ task interop_globals(type: RunInteropKonanTest) {
interop = 'cglobals'
}
task interop_macros(type: RunInteropKonanTest) {
disabled = (project.testTarget == 'wasm32') // No interop for wasm yet.
source = "interop/basics/macros.kt"
interop = 'cmacros'
}
task interop_echo_server(type: RunInteropKonanTest) {
disabled = (project.testTarget == 'wasm32') // No interop for wasm yet.
if (!isMac()) {
@@ -2452,6 +2462,8 @@ if (isMac()) {
"true\ntrue\n" +
"Global string\nAnother global string\nnull\nglobal object\n" +
"5\n" +
"String macro\n" +
"CFString macro\n" +
"Deallocated\nDeallocated\n"
source = "interop/objc/smoke.kt"
@@ -0,0 +1,14 @@
---
#define ZERO 0
#define ONE 1
#define MAX_LONG 9223372036854775807
#define FOO_STRING "foo"
// This one should be ignored:
#define WIDE_FOO_STRING L"foo"
#define FOURTY_TWO 42
#define SEVENTEEN ((long long) 17)
#define ONE_POINT_ZERO 1.0
#define ONE_POINT_FIVE 1.5f
#define BAD1 bar
#define BAD2 5;
@@ -0,0 +1,19 @@
import kotlin.test.*
import cmacros.*
fun main(args: Array<String>) {
assertEquals("foo", FOO_STRING)
assertEquals(0, ZERO)
assertEquals(1, ONE)
assertEquals(Long.MAX_VALUE, MAX_LONG)
assertEquals(42, FOURTY_TWO)
val seventeen: Long = SEVENTEEN
assertEquals(17L, seventeen)
val onePointFive: Float = ONE_POINT_FIVE
val onePointZero: Double = ONE_POINT_ZERO
assertEquals(1.5f, onePointFive)
assertEquals(1.0, onePointZero)
}
@@ -1,4 +1,5 @@
#import <objc/NSObject.h>
#import <CoreFoundation/CoreFoundation.h>
@class Foo;
@@ -57,3 +58,6 @@ extern NSString* globalString;
extern NSObject* globalObject;
int formatStringLength(NSString* format, ...);
#define STRING_MACRO @"String macro"
#define CFSTRING_MACRO CFSTR("CFString macro")
@@ -62,6 +62,9 @@ fun run() {
println(globalObject)
println(formatStringLength("%d %d", 42, 17))
println(STRING_MACRO)
println(CFSTRING_MACRO)
}
fun MutablePairProtocol.swap() {