https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
kotlin-native
  • s

    Sam Schilling

    01/21/2020, 8:08 PM
    Why does calling a launch within a launch throw an
    IllegalStateException
    ? I don’t want to have to wrap every launch call in runblocking whenever I want to do some background work, but is there another way around that?
    // Fails
    runBlocking {
        GlobalScope.launch {
            println(1)
            GlobalScope.launch { // IllegalStateException: no event loop, use runBlocking
                println(2)
            }
        }
    }
    
    // Succeeds
    runBlocking {
        GlobalScope.launch {
            println(1)
            runBlocking {
                GlobalScope.launch {
                    println(2)
                }
            }
        }
    }
    k
    b
    • 3
    • 7
  • s

    Sam Schilling

    01/21/2020, 9:56 PM
    Is there a way to do a launch in K/N yet without using runBlocking? I need to perform async tasks without blocking the current thread, but just calling
    GlobalScope.launch
    for example throws an exception:
    IllegalStateException: There is no event loop. Use runBlocking { ... } to start one.
    The problem is if I surround my launch with
    runBlocking
    , I am no longer performing an async task as it will block the calling thread until the launched coroutine completes.
    b
    • 2
    • 8
  • s

    serebit

    01/22/2020, 1:29 AM
    https://github.com/JetBrains/kotlin-native/issues/3771 I finally tracked down the cause of Alpine being unable to compile Kotlin/Native projects. I spent a decent amount of time writing up a conclusive bug report, hopefully this will be resolved soon!
    n
    o
    • 3
    • 7
  • j

    jk2018

    01/22/2020, 5:27 PM
    Wrote up a (longish) question on StackOverflow about DetachedObjectGraph (keeping a resource open in a separate thread and sending messages to it), if anyone is inclined to take a peek: -->
    d
    k
    • 3
    • 14
  • a

    antrax

    01/22/2020, 8:58 PM
    Can someone advise if it's a good idea to run GC.Collect when iOS app receives memory warning?
    o
    • 2
    • 2
  • r

    Robert

    01/22/2020, 10:15 PM
    Q; I use Kotlin native to create a shared lib which I use in a C++ project. I can now call the "kotlin code" from C++ which is available in the shared lib, but can I also do it the other way around; call C++ code from Kotlin code? Or wouldnt that work because of the mutual (?) dependency; A needs B and B needs A
    e
    o
    • 3
    • 5
  • s

    Sam Schilling

    01/22/2020, 10:16 PM
    Is there a way to unfreeze an object after it is referenced by another thread? In my case I am capturing a property of some class in a lambda passed to a launch. The property is only read, never mutated by the coroutine. However, after the coroutine has executed, the property is frozen and can no longer be mutated by the object it belongs to. For example:
    class Foo {
       var bar = arrayOf(...)
    }
    
    var foo = Foo()
    GlobalScope.launch {
        if (foo.bar.contains(...)) { ... }
    }
    
    // Once above coroutine is reached, any attempts to mutate foo.bar fail since it is frozen
    k
    • 2
    • 3
  • r

    ribesg

    01/23/2020, 10:12 AM
    How would I make a suspend function wrap a
    dispatch_async
    call returning a result? i.e. how to bridge coroutines and multithreading as coroutines themselves can’t run outside of main thread
    b
    • 2
    • 18
  • s

    Sam Schilling

    01/23/2020, 7:31 PM
    Is there a way to launch a coroutine in the same thread as the current execution context? E.g.,
    var foo = "bar"
    launch {
        foo = "baz" // no need to worry about frozen foo since both actions are taken on the same thread
    }
    b
    g
    • 3
    • 4
  • s

    sikri

    01/24/2020, 5:23 PM
    Let me have next types:
    interface Color { val color: Int
    object BlackColor : Color { override val color = 0 }
    
    class Car(
       private val colorHolder: Color = BlackColor
    ) : Color by colorHolder
    On iOS I have bad memory access 0x0, probably, due to reduced visibility, on trying to get value with
    car.color
    while
    color.colorHolder.color
    works fine. On JVM works fine. Were there any opened issues about implementation by delegation for native? Having colorHolder public doesn’t fix it as well.
    d
    a
    • 3
    • 11
  • k

    Kris Wong

    01/24/2020, 7:46 PM
    I have a suspicion that the coroutines 1.3.3-native-mt artifacts may have been updated with some behavior changes recently
    k
    • 2
    • 28
  • g

    GarouDan

    01/25/2020, 12:37 AM
    Hi, when building my project for Kotlin Native I’m receiving a error like:
    Could not find 'main' in '<root>' package.
    I can move my main folder to the root package, but does someone know how can we configure the kotlin multiplatform plugin in order to provide another entry point? It looks like we have a option
    -e
    for command line but I’m not sure how to do that from the
    build.gradle.kts
    configuration file
    a
    • 2
    • 2
  • n

    napperley

    01/26/2020, 3:36 AM
    Trying to create a debug binary that uses the ncurses library, and end up with the following error:
    Task :cinteropNcursesLinuxArm32 FAILED
    Exception in thread "main" java.lang.Error: /mnt/pi_image/usr/include/stdint.h:26:10: fatal error: 'bits/libc-header-start.h' file not found`
    This error occurs with both the dynamic, and static versions of the ncurses library.
    • 1
    • 3
  • n

    nikolaymetchev

    01/26/2020, 11:30 AM
    Figured it out.
    r
    • 2
    • 5
  • k

    kpgalligan

    01/26/2020, 7:44 PM
    message has been deleted
    j
    k
    • 3
    • 6
  • k

    kpgalligan

    01/27/2020, 3:00 PM
    We’re running into a frustrating crash. The message is “Fatal Exception: ExceptionObjHolder”. The full stack trace is here
    o
    r
    +3
    • 6
    • 51
  • k

    Kris Wong

    01/27/2020, 5:15 PM
    something definitely changed on the 1.3.3-native-mt branch, because it has also broken Ktor on Kotlin/Native, which was also working fine in my project a few days ago
    b
    k
    a
    • 4
    • 38
  • b

    Bruno_

    01/27/2020, 6:46 PM
    will appreciate any suggestion what may have gone wrong
    Untitled
    a
    • 2
    • 7
  • k

    Kavan

    01/27/2020, 7:58 PM
    Go is implemented in Go. It also has no external dependencies, so to build Go only a Go compiler is required. Please make kotlinnative like this. @elizarov
    👍 1
    👎 4
    s
    k
    +3
    • 6
    • 25
  • g

    GarouDan

    01/27/2020, 8:03 PM
    Hello everyone, Does someone know why we have this warning when building for K/N? And how to solve it?
    > Task :my-module:linkReleaseFrameworkIosX64
    warning: linking module flags ‘SDK Version’: IDs have conflicting values (‘[2 x i32] [i32 13, i32 2]’ from /var/folders/gx/x91q88394qd_bxbq5_wx1q840000gn/T/protocols6461040244319640293.bc with ‘[2 x i32] [i32 13, i32 0]’ from out)
    b
    • 2
    • 3
  • a

    AJ Alt

    01/27/2020, 10:57 PM
    Has anyone had success calling
    platform.posix.isatty
    from K/N? It seems that
    isatty(STDIN_FILENO)
    always returns 0 on my machine (calling the built binary directly, not though gradle). Calling
    isatty(fileno(stdout))
    in the same way from a C program returns the expected values.
    o
    n
    k
    • 4
    • 11
  • p

    Patrick

    01/28/2020, 10:35 AM
    Regarding the interplay between exported Kotlin Native C Libraries and coroutines: If I have a function like this:
    fun test = runBlocking<Unit> {
        someLibraryCode()
    }
    and I call this function from my C code, the program crashes with the message:
    There is no event loop. Use runBlocking { ... } to start one.
    How am I supposed to handle this, if I want to call this function from C? Is it possible to wrap the entire program in
    runBlocking<Unit> {...}
    , like I can do in a K/N project? Is there another way to avoid this error?
    a
    • 2
    • 2
  • p

    Patrick

    01/28/2020, 10:36 AM
    Also how can I pass a function as a parameter via C?
    a
    • 2
    • 7
  • t

    tapchicoma

    01/28/2020, 2:41 PM
    Why cocoapods plugin adds
    spec.libraries = "c++"
    to generated podspec? As far as I understand kotlin native does not generate c++ code or link with c++ libraries for ios targets.
    i
    • 2
    • 2
  • k

    Kris Wong

    01/28/2020, 3:42 PM
    is the following possible w.r.t. the return statement within the
    let
    block?
    NSURLSession.sharedSession.dataTaskWithRequest(
                NSURLRequest(NSURL(string = "<http://lsudflasfnlnf>")),
                requestBlock@ { data: NSData?, urlResponse: NSURLResponse?, error: NSError? ->
                    error?.let {
                        return@requestBlock
                    }
                }.freeze()
            ).resume()
    k
    • 2
    • 34
  • d

    Dominaezzz

    01/28/2020, 4:51 PM
    What's this? https://github.com/JetBrains/kotlin-native/blob/45914cf4eccc67f790494688fe3c5f449736ed2e/runtime/src/main/cpp/Memory.cpp#L1091 If I hit this, have I leaked memory or.....?
    k
    s
    +2
    • 5
    • 39
  • n

    napperley

    01/29/2020, 1:13 AM
    Does Kotlin Native support the C11 standard ❓. Looking at experimenting with the unofficial Prometheus C client library (uses the C11 standard): https://github.com/digitalocean/prometheus-client-c
    o
    m
    • 3
    • 3
  • t

    Tobi

    01/29/2020, 9:12 AM
    Has there been a change in Kotlin/Natives concurrency model regarding reference counting? I am going through the examples from https://touchlab.co/kotlin-native-stranger-threads-ep-1/ and realized that this test is failing since no exception is thrown. So there is no need to freeze the
    holder
    🤔
    class ArgHolder(var arg: JobArg?) {
            fun getAndClear(): JobArg {
                val temp = arg!!
                arg = null
                return temp
            }
        }
    
        @Test
        fun stillVisible() {
            val holder = ArgHolder(JobArg("Hi"))
    
            assertFails {
                worker.execute(TransferMode.SAFE, { holder.getAndClear() }) {
                    print(it)
                }
            }
        }
    k
    • 2
    • 3
  • l

    Luke Kellett

    01/29/2020, 8:37 PM
    Hey all, I’m running into some issues with object concurrency using Kotin Native 1.3.61. I’m creating an instance of the following class in the UI thread and then calling it’s properties/members from “_DispatchQueue.global(qos: .background).async_” on iOS. It’s throwing kotlin.native.IncorrectDereferenceException even though I’m attributing my variables with @SharedImmutable. Any ideas?
    class ThreadSafetyTest {
    
        @SharedImmutable
        val mapper: (value: String) -> String = { value: String ->
            "Mapped: $value"
        }
    
        @SharedImmutable
        val mapper2 = "Mapper 2"
    
    }
    k
    d
    • 3
    • 21
  • n

    napperley

    01/30/2020, 2:23 AM
    Look as though I have encountered a bizarre Kotlin Native compiler bug that has been driving me up the wall 🐛. Been developing a program that uses Ktor Client, and Ktor Client Serialization. When running the program using the
    <http://xxxxxx>:xxxx
    parameter, both the release and debug binaries work normally, and return this result:
    Response:
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <meta name="robots" content="noindex,nofollow">
            <title>Prometheus Time Series Collection and Processing Server</title>
    
    ...
    When the
    --list-labels <http://xxxxxx>:xxxx
    program parameters are used instead the debug binary works fine, however the release binary exhibits some strange behaviour where no labels are printed. The release binary should be outputting something similar to the debug binary:
    Total Labels: 48
    * __name__
    * address
    * battery
    * branch
    * broadcast
    * call
    * cell
    * chip
    * chip_name
    
    ...
    a
    o
    • 3
    • 6
Powered by Linen
Title
n

napperley

01/30/2020, 2:23 AM
Look as though I have encountered a bizarre Kotlin Native compiler bug that has been driving me up the wall 🐛. Been developing a program that uses Ktor Client, and Ktor Client Serialization. When running the program using the
<http://xxxxxx>:xxxx
parameter, both the release and debug binaries work normally, and return this result:
Response:
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="robots" content="noindex,nofollow">
        <title>Prometheus Time Series Collection and Processing Server</title>

...
When the
--list-labels <http://xxxxxx>:xxxx
program parameters are used instead the debug binary works fine, however the release binary exhibits some strange behaviour where no labels are printed. The release binary should be outputting something similar to the debug binary:
Total Labels: 48
* __name__
* address
* battery
* branch
* broadcast
* call
* cell
* chip
* chip_name

...
The release binary file size looks too good to be true at 3580 KB, while the debug binary file size by comparison is 10192 KB.
Can find the project here: https://gitlab.com/napperley/prometheus-manager
👀 1
a

Artyom Degtyarev [JB]

01/30/2020, 9:11 AM
Just FYI: everything works correctly if you specify your data class like:
data class LabelsResponse(val status: String, val data: ArrayList<String>)
Nevertheless, we’re still looking for the root cause of this behavior.
👍 1
o

olonho

01/30/2020, 2:35 PM
Likely fixed with https://github.com/JetBrains/kotlin-native/pull/3774
n

napperley

01/30/2020, 8:07 PM
Will the fix be included in Kotlin 1.3.70?
o

olonho

01/31/2020, 6:50 AM
Yes
View count: 2