roamingthings
12/29/2019, 1:01 PMorg.jetbrains.kotlin.platform.native
plugin in for this or do I also use the kotlin-multiplatform
plugin?StefMa
12/30/2019, 8:08 AMrelease
and debug
version?
Cause my release version crashes directly but my debug version works.
I don’t have add any special “cases” like “on release
do this and debug
do this”… so there should be a difference out of the box, right?Patrick
12/30/2019, 9:30 AMnikolaymetchev
12/30/2019, 6:07 PM#include<stdio.h>
#include<CL/cl.h>
int main(void)
{
cl_int err;
cl_uint numPlatforms;
err = clGetPlatformIDs(0, NULL, &numPlatforms);
if (CL_SUCCESS == err)
printf("\nDetected OpenCL platforms: %d", numPlatforms);
else
printf("\nError calling clGetPlatformIDs. Error code: %d", err);
return 0;
}
Here is what I thought the kotlin equivalent will be:
fun main() {
val numOfPlatforms: cl_uint = 0U
val result = clGetPlatformIDs(0, null, cValuesOf(numOfPlatforms))
if (CL_SUCCESS == result) {
println("Detected OpenCL platforms: ${numOfPlatforms}")
} else {
println("Error calling clGetPlatformIDs. Error code: $result");
}
}
However it seems that I am not passing the pointer to numOfPlatforms correctly as my program returns 0 instead of the expected value of 2. How do I pass a pointer to a an int using Kotlin native?nikolaymetchev
12/30/2019, 6:27 PMfun main() {
memScoped {
val pointer = cValuesOf(0U).getPointer(memScope)
val result = clGetPlatformIDs(0, null, pointer)
if (CL_SUCCESS == result) {
println("Detected OpenCL platforms: ${pointer[0]}")
} else {
println("Error calling clGetPlatformIDs. Error code: $result");
}
}
}
Brendan Weinstein
12/31/2019, 1:53 AMlaunch {
val response = withContext(Dispatchers.Default) {
val client = HttpClient { }
val emptyBody = object : OutgoingContent.NoContent() {
override val contentLength: Long = 0
override fun toString(): String = "EmptyContent"
}
client.get<String>(body = emptyBody, port = 0, block = {
url {
takeFrom("<https://api.basebeta.com>")
encodedPath = "/rankings"
}
})
}
output.send(Action.RankingsLoadedAction(
list = emptyList(),
diffResult = KDiffUtil.calculateDiff(
MItemDiffHelper(
oldList = emptyList(),
newList = emptyList()
)
),
fromNetwork = true
))
}
This leads to the below error
kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen <http://io.ktor.utils.io|io.ktor.utils.io>.core.ByteReadPacket@1bb0698
If I follow the stacktrace further down I see references to
io.ktor.client.features.HttpCallValidator.Companion
I've read that we should avoid companion objects being used by multiple threads. My understanding is that companion objects are implemented as singletons in native (static inners on jvm?). My hunch is that the inners of Ktor reference a singleton/companion object initialized on the main thread and that leads to recursive freezing throughout the ktor client object graph.
Is there a strategy to avoid this that still allows me to make requests on a background thread? I've seen code examples that use ktor on the main thread. For my aim I'd like to make a request via ktor on a background thread.saket
01/01/2020, 12:28 AMmbonnin
01/01/2020, 4:45 PM.freeze()
in? Is it possible to call .freeze()
from swift by somehow exporting it to a framework?serebit
01/02/2020, 2:32 AMserebit
01/02/2020, 2:33 AMPrateek Grover
01/02/2020, 9:11 AMprivate suspend fun syncFromNewtork(url: String): Boolean = suspendCoroutine { continuation ->
val knResponseCallback: KNSyncManagerResponseCallBack = freezeObject(KNSyncManagerResponseCallBack(continuation))
knNetworkBridge.makePostRestRequest(url: url)
}
class KNSyncManagerResponseCallBack(private val continuation: Continuation<Boolean>): KNResponseCallback {
override fun onSuccess(response: Any?) {
continuation.resume(true)
}
override fun onError(errorResponse: Any?) {
continuation.resume(false)
}
}
Big Chungus
01/02/2020, 11:42 AMfcosta
01/02/2020, 12:49 PMdispatch_async(dispatch_get_main_queue()) { /* */ }
😢
How can I handle the result operation?mbonnin
01/02/2020, 8:48 PMlinkDebugFrameworkMacosX64
after changing one string, which slows down development quite a lot. Is that expected, should I buy a bigger machine or am I doing something wrong ?alexcouch
01/02/2020, 11:12 PMld.lld: error: undefined symbol: SnowboyDetectConstructor
>>> referenced by Types.kt:162 (/mnt/agent/work/4d622a065c544371/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Types.kt:162)
>>> /tmp/konan_temp7723188199372240336/result.o:(snowboy_SnowboyDetectConstructor_wrapper0)
I'm not exactly sure what to do now. I've looked everywhere. I've dumped the cstubs for the library I'm trying to link and everything seems to be in order. I really don't understand why it says that Types.kt:162 is the one throwing the fit. I looked at that line and its CPointer<T>#getPointer. Not sure if its not able to find information on the types being pointed to in C code or what but I'm kinda at my wits end right now.Mikołaj Kąkol
01/03/2020, 7:52 AMkotlin.IllegalStateException: There is no event loop. Use runBlocking { ... } to start one.
in my native tests when I try to run something like
GlobalScope.async { /* any code*/ }.await()
I'm running that code inside custom runBlocking
implementation for iOS.
What is the go to solution? Should I use custom scope
for spawning corutines? How do you test async/await on iOS/native?Big Chungus
01/03/2020, 3:07 PMKris Wong
01/03/2020, 5:35 PMBrendan Weinstein
01/03/2020, 6:15 PM./gradlew bundle
still going this morningDominaezzz
01/04/2020, 4:31 PMserebit
01/04/2020, 6:00 PMtry
section of some code, and a SIGINT signal is received, will the finally
block attached to that try
be executed before the program closes?Thomas
01/04/2020, 7:55 PM-Xg0
and isStatic = true
all works fine (I need to download dsym from App Store and upload to Firebase each release). However, I need to build the Kotlin framework as a dynamic framework. (because of iOS app extensions, I can explain if needed). The documentation says the following:
If rebuilding is performed on App Store side, thenIs this really the case? If so, is there a workaround/fix for this while still building as a dynamic framework?of rebuilt dynamic framework seems discarded and not downloadable from App Store Connect. So in this case it may be required to make the framework static, e.g. with.dSYM
jk2018
01/05/2020, 2:15 AMPatrick
01/06/2020, 9:03 AMkotlin.native.initRuntimeIfNeeded()
function has to be called from. Is it inside the staticCFunction or outside of it? Should I call it at the beginning of the function?mzgreen
01/06/2020, 10:23 AMval ref = runOnBackgroundThread {
while(threadIsAlive) {
// do some work
runOnUIThread {
// refresh UI
}
sleep(100) // pause bg thread for 100ms
}
}
// at some later point
ref.cancel() // stop thread
I can do it on Android and JVM using coroutines like this:
val job = GlobalScope.async {
while(isActive) {
// do some work
launch(context = Dispatchers.Main) {
// refresh UI
}
delay(100)
}
}
// later
job.cancel()
but Kotlin Native doesn’t support async coroutines yet. I tried to create my own functions that use iOS dispatchers under the hoods but I’m getting illegal attempt to access non-shared <object>
exceptions which I don’t fully understand. Seems like this is not an easy task.
The only sample I was able to find is this: https://github.com/wojtek-kalicinski/sudoku-android/blob/master/libsudoku/src/iosMain/kotlin/me/kalicinski/sudoku/Async.kt but the comments are saying that it’s a hack.
Is there a sample that shows how to do it properly?mzgreen
01/06/2020, 1:46 PMLulu
01/07/2020, 10:30 AMAtomicRef
(common version) leak memory like AtomicReference
(native version)? And if so, how to avoid memory leak given that I write code in common?Big Chungus
01/07/2020, 1:01 PMPatrick
01/07/2020, 1:30 PMBig Chungus
01/07/2020, 5:15 PM#define G_CALLBACK(f) ((GCallback) (f))