Fix fixed NSString* parameters in variadic functions
This commit is contained in:
committed by
SvyatoslavScherbina
parent
c7a126a6b0
commit
e1b507f998
@@ -40,7 +40,15 @@ private tailrec fun convertArgument(
|
||||
}
|
||||
|
||||
is String -> {
|
||||
location.reinterpret<CPointerVar<*>>()[0] = argument.cstr.getPointer(additionalPlacement)
|
||||
location.reinterpret<CPointerVar<*>>()[0] = if (!isVariadic) {
|
||||
// If it is fixed argument, then it is not C string because it must have been already converted;
|
||||
// then treat it as NSString.
|
||||
// TODO: handle fixed NSString arguments in the stub instead.
|
||||
interpretCPointer<COpaque>(CreateNSStringFromKString(argument))
|
||||
} else {
|
||||
// It is passed as variadic argument; no type information available, so treat it as C string.
|
||||
argument.cstr.getPointer(additionalPlacement)
|
||||
}
|
||||
FFI_TYPE_KIND_POINTER
|
||||
}
|
||||
|
||||
|
||||
@@ -2332,6 +2332,7 @@ if (isMac()) {
|
||||
goldValue = "84\nFoo\nHello, World!\nKotlin says: Hello, everybody!\nHello from Kotlin\n2, 1\n" +
|
||||
"true\ntrue\n" +
|
||||
"Global string\nAnother global string\nnull\nglobal object\n" +
|
||||
"5\n" +
|
||||
"Deallocated\nDeallocated\n"
|
||||
|
||||
source = "interop/objc/smoke.kt"
|
||||
|
||||
@@ -55,3 +55,5 @@ Class (^ _Nonnull getClassGetter(NSObject* obj))(void);
|
||||
|
||||
extern NSString* globalString;
|
||||
extern NSObject* globalObject;
|
||||
|
||||
int formatStringLength(NSString* format, ...);
|
||||
|
||||
@@ -60,6 +60,8 @@ fun run() {
|
||||
override fun description() = "global object"
|
||||
}
|
||||
println(globalObject)
|
||||
|
||||
println(formatStringLength("%d %d", 42, 17))
|
||||
}
|
||||
|
||||
fun MutablePairProtocol.swap() {
|
||||
|
||||
@@ -60,3 +60,11 @@ Class (^ _Nonnull getClassGetter(NSObject* obj))() {
|
||||
|
||||
NSString* globalString = @"Global string";
|
||||
NSObject* globalObject = nil;
|
||||
|
||||
int formatStringLength(NSString* format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
NSString* result = [[NSString alloc] initWithFormat:format arguments:args];
|
||||
va_end(args);
|
||||
return result.length;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user