napperley
07/09/2021, 11:55 PMAtomicReference
can cause a Kotlin Native program to terminate suddenly?Jason5lee
07/11/2021, 1:41 AMnapperley
07/11/2021, 11:31 PMmartmists
07/12/2021, 9:04 AMUncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.collections.ArrayList@1aa3f68
at kfun:kotlin.Throwable#<init>(kotlin.String?){} (0x4169a9)
at kfun:kotlin.Exception#<init>(kotlin.String?){} (0x410c87)
at kfun:kotlin.RuntimeException#<init>(kotlin.String?){} (0x410d97)
at kfun:kotlin.native.concurrent.InvalidMutabilityException#<init>(kotlin.String){} (0x433557)
at ThrowInvalidMutabilityException (0x434a76)
at Kotlin_AtomicReference_checkIfFrozen (0x523c71)
at kfun:kotlin.native.concurrent.AtomicReference#<init>(1:0){} (0x4328ae)
at ...
MJegorovas
07/12/2021, 9:30 AMy9san9
07/12/2021, 2:20 PMNothing
type, I was trynna use it with generics in entity like Either
.
sealed interface Either<out TLeft, out TRight> {
class Failure<T>(...) : Either<T, Nothing>
class Success<T>(...) : Result<Nothing, T>
}
This is cool approach in Kotlin and everything works fine:
val result: Either<Entity, Error> = result as Success<Entity>
BUT in swift I can't do stuff like this:
guard let result: Either<Entity, Error> = result as? Success<Entity> else { return }
This will break at runtime, since swift generics aren't erased, and it won't pass type check (Nothing
!= Error
). Any ideas how to workaround it?
cc @alex009napperley
07/12/2021, 11:22 PM/home/napperley/.konan/dependencies/arm-unknown-linux-gnueabihf-gcc-8.3.0-glibc-2.19-kernel-4.9-2/arm-unknown-linux-gnueabihf/bin/ld.bfd: /mnt/pi_image/usr/lib/arm-linux-gnueabihf/libgdk-3.so: undefined reference to `wl_display_dispatch_pending'
However if Kotlin 1.4.31 is used then none of the errors appear, and the build is successful.
In the build output there are a boatload of warnings about missing libraries (at the linking stage) if Kotlin 1.5.0 or later is used, eg:
/home/napperley/.konan/dependencies/arm-unknown-linux-gnueabihf-gcc-8.3.0-glibc-2.19-kernel-4.9-2/arm-unknown-linux-gnueabihf/bin/ld.bfd: warning: libpcre.so.3, needed by /mnt/pi_image/usr/lib/arm-linux-gnueabihf/libglib-2.0.so, not found (try using -rpath or -rpath-link)
Are there some additional linking options that need to be passed to the linker to resolve the errors, and if so which ones?napperley
07/12/2021, 11:37 PMMatthias Geisler
07/14/2021, 7:56 AMIaroslav Postovalov
07/15/2021, 3:13 PMmingwX64
. My test process fails with -1073741515
exit code and no output. When I've opened the test.exe
binary with Dependency Walker, it gave out that binary can't be linked with some Microsoft binaries.Iaroslav Postovalov
07/15/2021, 5:10 PMld
successfully links against .lib
file, but as the result .dll
is lost, and the executable can't find itIaroslav Postovalov
07/16/2021, 7:59 AMitnoles
07/17/2021, 2:45 PMsuspend fun fetch() : HttpResponse = suspendCoroutine {
val semaphore = dispatch_semaphore_create(0)
val nativeRequest = NSMutableURLRequest(uRL = NSURL.URLWithString("<https://api.spacexdata.com/v4/launches>")!!)
nativeRequest.setHTTPMethod("GET")
val result = AtomicReference(HttpResponse().freeze())
val completionHandler = { nsData: NSData?, nsURLResponse: NSURLResponse?, nsError: NSError? ->
if (nsError != null) {
val message =
"The response is: " + nsURLResponse?.description() + ", error is: " + nsError.description()
println(message)
}
val response = nsURLResponse as NSHTTPURLResponse
val httpResponse = HttpResponse().apply {
statusCode = response.statusCode.toInt()
body = nsData?.bytes?.reinterpret<ByteVar>()?.toKString()
}.freeze()
result.value = httpResponse
dispatch_semaphore_signal(semaphore)
Unit
}.freeze()
val task =
NSURLSession.sharedSession.dataTaskWithRequest(nativeRequest, completionHandler)
task.resume()
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
it.resume(result.value)
}
I really want to simplified this code. Can anyone help me with it?Big Chungus
07/17/2021, 10:43 PMType mismatch: inferred type is bool /* = Byte */ but Boolean was expected
Big Chungus
07/18/2021, 5:07 PMCause: cannot assign instance of java.util.Collections$EmptyList to field java.lang.StackTraceElement.moduleVersion of type java.lang.String in instance of java.lang.StackTraceElement
The test
import kotlin.test.Test
import kotlin.test.assertEquals
class TestMe {
@Test
fun shouldTest(){
assertEquals("test", "test");
}
}
Any pointers?吴少滨
07/21/2021, 3:51 AMcoolcat
07/21/2021, 8:47 PMnative.cocoapods
plugin recently? I am trying to write a KMM library whose iOS code depends on a cocoapod, which I import using
cocoapods {
pod("AFNetworking")
}
However cinterop
gives me
fatal error: module 'AFNetworking' not found
as in this issue. But I don’t think it’s the same problem. Anyone had similar?napperley
07/22/2021, 12:54 AMAJ Alt
07/23/2021, 3:47 PMJulius Hannink
07/26/2021, 8:14 AM@ankushg
any progress on your side?吴少滨
07/26/2021, 12:07 PMkpgalligan
07/27/2021, 11:59 PM@ObjCMethod
annotation. We've been doing some experiments with cinterop and can successfully link and call to objc methods. As a concrete example, on iOS the objc class for Crashlytics is FIRCrashlytics
. We only care about getting the global instance and logging a string, so after seeing what cinterop does, we just made this Kotlin class. It'll successfully link to the objc, and calls the methods as we expect.
@ExternalObjCClass
open class FIRCrashlytics : NSObject() {
@ExternalObjCClass
companion object : NSObjectMeta(), ObjCClassOf<FIRCrashlytics> {
@ObjCMethod("crashlytics", "@16@0:8")
external fun crashlytics(): FIRCrashlytics
}
@ObjCMethod(selector = "log:", encoding = "v24@0:8@16")
open external fun log(msg: String)
}
Kartik Prakash
07/28/2021, 1:27 AMbenkuly
07/28/2021, 10:23 AMsomeByteArray.refTo(0)
and someByteArray.pinned{it.addressOf(0)}
? Which of them should I use, when I call a native function?
And what shoud I do, when the function wants CValuesRef<uint8_tVar /* = UByteVarOf<uint8_t /* = UByte */> */>
? Is it enough to do someByteArray.asUByteArray().refTo(0)
?Landry Norris
07/28/2021, 2:45 PMMatthias Geisler
07/29/2021, 6:12 PMnapperley
07/30/2021, 3:13 AMcairo_region_create_rectangles
function ( https://www.cairographics.org/manual/cairo-Regions.html#cairo-region-create-rectangles ) from the Cairo library, but the function is after CValuesRef<cairo_rectangle_int_t>?
as the first parameter and I don't know how to provide a CValuesRef
that contains multiple struct pointers. Below is the code that fails to compile (the values variable doesn't match what the cairo_region_create_rectangles function
is expecting):
// ...
fun createWithMultipleRectangles(vararg rectangles: IntRectangle): Region {
val tmpArr = rectangles.map { it.cairoRect.ptr }.toTypedArray()
val values = cValuesOf(*tmpArr)
return Region(cairo_region_create_rectangles(values, rectangles.size))
}
// ...
Tristan
07/30/2021, 8:31 PMclass MyClass {
private val arrayQueue = ArrayQueue<String>()
fun save(item: String) {
arrayQueue.add(item);
}
val last: String
get() = arrayQueue.last()
}
I use it in objective C
+ (instancetype)sharedInstance {
static NativeClass *nativeClass = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
nativeClass = [[NativeClass alloc] init];
nativeClass.myClass = [[MyClass alloc] init];
});
return nativeClass;
}
First of all, accessing it was an issue just to get .last
, so I created a wrapper to get a frozen version.
fun getMyClass() = MyClass().freeze()
But by doing this, I cannot mutate it anymore kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen
How can I overcome this kind of issue?iamsteveholmes
07/30/2021, 8:40 PMLandry Norris
08/02/2021, 3:28 PM