https://kotlinlang.org logo
Docs
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
  • k

    Konstantin Petrukhnov

    11/04/2019, 9:24 AM
    Trying to use lib compiled with 1.3.50 as dependency in project with 1.3.70-dev. It failed with : w: skipping .... htf-lib-a.klib. The abi versions don't match. Expected '[18]', found '14' w: The compiler versions don't match either. Expected '[]', found '1.3.50-release-11850' e: Could not find .... khtf-lib-a.klib" in [....] Does it mean that using older compiled libs is not possible?
    k
    • 2
    • 6
  • e

    Eamonn Boyle

    11/04/2019, 11:09 PM
    Do C function pointer callbacks with pointer parameters always have the parameters mapped as CPointer rather that CValuesRef? Is this because they are called directly rather than through a KLib wrapper? Does this mean if passing in strings you have to allocate and free (or use getPointer within a memScoped)?
    a
    • 2
    • 2
  • v

    Vsevolod Ganin

    11/05/2019, 3:53 PM
    Trying to raise
    NSException
    from K/N (via
    NSException.raise
    ) and catch it in ObjC. Unfortunately it is not catched and program still crashes. If I raise it in the same spot but in ObjC it is catched just fine. Is it a known problem? Hasn’t been able to find any info on the subject except for the one line in docs (https://kotlinlang.org/docs/reference/native/objc_interop.html#errors-and-exceptions):
    Swift/Objective-C error-throwing methods aren’t imported to Kotlin as exception-throwing.
    • 1
    • 1
  • a

    Andy Gibel

    11/05/2019, 9:36 PM
    Wonder if someone can help me sanity check my conclusions here: I am using custom Swagger OpenAPI codegen libraries on an Android and iOS project. I also have a business logic library which uses only those models in the exposed interfaces. What I'm trying to do is make that business logic library into a Kotlin/Native library while not also converting the Swagger codeGen to MPP right now. What I can't figure out is if it is possible to share these models across platforms without going to a Swagger MPP implementation
    • 1
    • 1
  • t

    Thomas

    11/06/2019, 4:22 PM
    Hi, I am having some issues with staticCFunction. See code below:
    val identityBytes: ByteArray = someValue()
    val pskBytes: ByteArray = someValue()
    
    // <https://www.openssl.org/docs/man1.0.2/man3/SSL_CTX_set_psk_client_callback.html>
    
    SSL_CTX_set_psk_client_callback(ctx, staticCFunction { ssl, hint, identity, maxIdentityLen, psk, maxPskLen ->
        require(identityBytes.size <= maxIdentityLen.toInt())
        require(pskBytes.size <= maxPskLen.toInt())
    
        identityBytes.forEachIndexed { index, value ->
            identity!![index] = value
        }
        pskBytes.forEachIndexed { index, value ->
            psk!![index] = value.toUByte()
        }
    
        // ...
        TODO()
    })
    When compiling this gives an error:
    kotlinx.cinterop.staticCFunction must take an unbound, non-capturing function or lambda
    I need to access identityBytes and pskBytes from this lambda. Is that possible?
    o
    • 2
    • 5
  • k

    Kris Wong

    11/06/2019, 4:49 PM
    does anyone know of a post that describes working with an opaque memory buffer (void*/COpaquePointer/NativePtr)?
    • 1
    • 1
  • a

    Andy Gibel

    11/06/2019, 6:55 PM
    Can someone point me to a good example of expect/actual typealiasing? Seems all examples I find either have all common code or very trivial (non-custom model) expect/actual usages
    k
    s
    k
    • 4
    • 10
  • e

    Eamonn Boyle

    11/06/2019, 10:23 PM
    Why would you ever use toCValues instead of refTo since toCValues is so slow?
    o
    • 2
    • 2
  • p

    Patrick

    11/07/2019, 9:08 AM
    Hey guys, I am trying to compile a Kotlin/Native project for the JVM and MacOS. I have the source code, but no build configuration. Are there any tutorials on how to create the correct configuration?
    a
    • 2
    • 1
  • k

    Kris Wong

    11/07/2019, 4:23 PM
    anyone have any thoughts as to why accessing the result of
    mmap
    as a
    CPointer<ByteVar>
    would cause a SIGBUS?
    • 1
    • 5
  • p

    Patrick

    11/07/2019, 4:39 PM
    What could be a reason that runBlocking{delay(10000); println(“after delay”)} does not delay?
    a
    • 2
    • 1
  • a

    Arkadii Ivanov

    11/07/2019, 8:17 PM
    Hello, could someone help with the following iOS exception? What might be the cause?
    Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared kotlin.collections.ArrayList@3edc938 from other thread
            at 0   MppLib                              0x000000010ce1c165 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 85
            at 1   MppLib                              0x000000010ce1b4c5 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 85
            at 2   MppLib                              0x000000010ce460d5 kfun:kotlin.native.IncorrectDereferenceException.<init>(kotlin.String)kotlin.native.IncorrectDereferenceException + 85
            at 3   MppLib                              0x000000010ce48058 ThrowIllegalObjectSharingException + 744
            at 4   MppLib                              0x000000010cff3d79 _ZNK16KRefSharedHolder14verifyRefOwnerEv + 185
            at 5   MppLib                              0x000000010d000efc -[KMutableListAsNSMutableArray dealloc] + 44
            at 6   libobjc.A.dylib                     0x00007fff50bad0d6 _ZN11objc_object17sidetable_releaseEb + 174
            at 7   libobjc.A.dylib                     0x00007fff50bae75b _ZN19AutoreleasePoolPage12releaseUntilEPP11objc_object + 147
            at 8   libobjc.A.dylib                     0x00007fff50bae67a objc_autoreleasePoolPop + 199
            at 9   libobjc.A.dylib                     0x00007fff50bae9c4 _ZN19AutoreleasePoolPage11tls_deallocEPv + 112
            at 10  libsystem_pthread.dylib             0x00007fff51bfe6ab _pthread_tsd_cleanup + 551
            at 11  libsystem_pthread.dylib             0x00007fff51c01655 _pthread_exit + 70
            at 12  libsystem_pthread.dylib             0x00007fff51bfe2f6 _pthread_body + 137
            at 13  libsystem_pthread.dylib             0x00007fff51c01249 _pthread_start + 66
            at 14  libsystem_pthread.dylib             0x00007fff51bfd40d thread_start + 13
    (lldb)
    k
    q
    +2
    • 5
    • 11
  • f

    Frank Feng

    11/08/2019, 12:34 PM
    Why would companion objects be recycled on iOS? How to solve this?
    o
    • 2
    • 1
  • k

    Kris Wong

    11/08/2019, 3:44 PM
    if I have a
    val stat = cValue<stat>()
    , and I want to pass it to the
    stat
    funciton , which takes a
    stat*
    , do I need to use
    getPointer
    ? the posix binding accepts a
    CValuesRef
    . i just want to pass a pointer to the stack variable.
    • 1
    • 7
  • t

    thymecypher

    11/08/2019, 10:26 PM
    Does anyone here have experience with K/N and macOS, particularly around selectors? Nowhere I’ve looked so far has given the answer I need.
    o
    l
    • 3
    • 3
  • t

    Tim Hauptmann

    11/11/2019, 9:43 AM
    Hey, I try to convert the following swift code to Kotlin. It compiles perfectly, but I get a Nullpointer error at runtime: Swift:
    private var readStream: Unmanaged<CFReadStream>?
    private var writeStream: Unmanaged<CFWriteStream>?
    private var inputStream: InputStream?
    private var outputStream: OutputStream?
    
    func connect(
            hostname: String,
            port: Int32,
            callback: @escaping (_ dataTransferObject: DiagnoseViewDataTransferObject) -> Void
     ) {
            let host = CFStringCreateWithCString(kCFAllocatorDefault, hostname, CFStringBuiltInEncodings.UTF8.rawValue)
            CFStreamCreatePairWithSocketToHost(
                kCFAllocatorDefault,
                host,
                443,
                &self.readStream,
                &self.writeStream
            )
    
    	inputStream = readStream?.takeRetainedValue()
           outputStream = writeStream?.takeRetainedValue()
           inputStream!.delegate = self
           outputStream!.delegate = self
        }
    ---------------- In Kotlin I have the following:
    private var readStream: CValuesRef<CFReadStreamRefVar>? = null
    private var writeStream: CValuesRef<CFWriteStreamRefVar>? = null
    private var inputStream: NSInputStream? = null
    private var outputStream: NSOutputStream? = null
    
    fun connect(
            hostname: String,
            port: Int,
            callback: (dataTransferObject: DiagnoseViewDataTransferObject) -> Unit
     ) {
            val host = CFStringCreateWithCString(kCFAllocatorDefault, hostname, kCFStringEncodingUTF8)
            CFStreamCreatePairWithSocketToHost(
                alloc = kCFAllocatorDefault,
                host = host,
                port = 443,
                readStream = this.readStream,
                writeStream = this.writeStream
             )  
            inputStream = readStream as NSInputStream?
            outputStream = writeStream as NSOutputStream?
            inputStream!!.delegate = this //crashes here with Nullpointer
            outputStream!!.delegate = this
    
    }
    Someone can help me how to use CFStreamCreatePairWithSocketToHost from Kotlin?
    m
    r
    a
    • 4
    • 5
  • a

    alex009

    11/13/2019, 2:22 AM
    someone know in what cases K/N failed with
    Receiver of 'initBy' must be a 'this' of the constructed class
    ? class is simple:
    @ExportObjCClass
    class MyTableViewCell : UITableViewCell {
    
        @OverrideInit
        constructor(
            style: UITableViewCellStyle,
            reuseIdentifier: String?
        ) : super(style = style, reuseIdentifier = reuseIdentifier)
    
        @OverrideInit
        constructor(coder: NSCoder) : super(coder = coder)
    }
    s
    s
    • 3
    • 10
  • a

    Andy Gibel

    11/13/2019, 3:11 PM
    Long shot, has anyone used the BigNum library (https://github.com/ionspin/kotlin-multiplatform-bignum) for MPP BigInteger/BigDecimal support?
    k
    a
    • 3
    • 10
  • s

    S Korebrits

    11/13/2019, 4:05 PM
    I am working on an App for Android and iOS and implemented some requests with ktor httpclient and coroutines. I want to write tests in the framework for suspended functions. I read about that it’s not implemented yet but there is a work around:
    expect fun <T> runTest(block: suspend () -> T)
    JVM
    actual fun <T> runTest(block: suspend () -> T) {
        runBlocking { block() }
    }
    https://blog.kotlin-academy.com/testing-common-modules-66b39d641617 https://youtrack.jetbrains.com/issue/KT-22228 How would I implement this vor the Native side? Or is there an better solution to this problem.
    r
    • 2
    • 3
  • a

    Adam Lusch

    11/13/2019, 5:49 PM
    Is downcasting supported via reverse C interop? For example, given the following Kotlin definitions,
    interface Interface {
        fun foo(): Int
    }
    
    class Concrete : Interface {
        override fun foo() = 42
        fun bar() = 1337
    }
    
    fun getInterface(): Interface = Concrete()
    is it legal to check
    IsInstance
    and "cast" by using the pinned interface pointer as the concrete type?
    KotlinInterfaceTest_ExportedSymbols* lib = KotlinInterfaceTest_symbols();
    auto sample = lib->kotlin.root.sample;
    
    KotlinInterfaceTest_kref_sample_Interface interface = sample.getInterface();
    if (lib->IsInstance(interface.pinned, sample.Concrete._type()))
    {
        auto concrete = KotlinInterfaceTest_kref_sample_Concrete{ interface.pinned };
        printf("Call concrete method: %d\n", sample.Concrete.bar(concrete));
    }
    This seems to work (prints "Call concrete method: 1337"), but want to make sure I'm not relying on undefined behavior. Thanks!
    o
    • 2
    • 2
  • a

    Andy Gibel

    11/13/2019, 7:08 PM
    Trying to use island-time library. My iOS build is failing due to not being able to find 'stately-collections. The island-time library does in fact use this: https://github.com/erikc5000/island-time/blob/master/core/build.gradle.kts However, it's delcared as implementation so I'm not sure why the build would be complaining that it can't find it in my module. I'm including the library by defining the common artifact and enabling GRADLE_METADATA
    k
    e
    • 3
    • 4
  • o

    olonho

    11/14/2019, 5:06 AM
    https://github.com/JetBrains/kotlin-native/pull/3498 got merged, so now K/N have native SIMD vector type
    Vector128
    along with interop support, so frameworks like
    ModelIO
    and
    SpriteKit
    now expose APIs with SIMD types like
    vector_float3
    .
    ❤️ 1
    🎉 10
    p
    • 2
    • 4
  • s

    Slackbot

    11/14/2019, 8:19 PM
    This message was deleted.
    a
    • 2
    • 1
  • s

    Samuel Michael

    11/14/2019, 9:00 PM
    Error message when try to run xcode 11+ app
    s
    • 2
    • 5
  • a

    Andy Gibel

    11/15/2019, 4:19 PM
    Has anyone had the issue where Android Studio just stops syntax highlighting the android-app submodule?
    t
    • 2
    • 4
  • y

    YoshiRulz

    11/15/2019, 5:02 PM
    After migrating from version 1.3.50 of the multiplatform plugin to 1.3.60, having '<' as the first char of a backtick-quoted identifier causes the task :linkReleaseExecutableLinux to fail.
    • 1
    • 1
  • k

    Kris Wong

    11/15/2019, 7:57 PM
    the
    os_log
    function appears to be missing from the iOS platform bindings
    o
    • 2
    • 5
  • s

    serebit

    11/16/2019, 4:06 PM
    Still getting
    Unable to compile C bridges
    with Kotlin/Native 1.3.60. Referring to https://github.com/JetBrains/kotlin-native/issues/2674, shouldn't this have been fixed with the LLVM toolchain update?
    o
    • 2
    • 4
  • r

    Robert

    11/17/2019, 8:42 AM
    I'd like to migrate a C++-application (with dependencies) to a new Kotlin codebase (multiplatform eventually). What is the most practical way to do this? I read some global thinks about C-interop, NDK and Kotlin/native. Should I include/interface the C-lib in a new Kotlin project? Or should I include the Kotlin project into the C-codebase until everything is rewritten and testen in Kotlin? Any best practices?
    j
    o
    • 3
    • 4
  • p

    Patrick

    11/18/2019, 2:15 PM
    I have a K/N project that already compiles successfully to JVM. If I run the MacOS tests however, it seems to kill the test.kexe file at some point. Some tests are passing though. Any ideas what could be causing this?
    a
    • 2
    • 18
Powered by Linen
Title
p

Patrick

11/18/2019, 2:15 PM
I have a K/N project that already compiles successfully to JVM. If I run the MacOS tests however, it seems to kill the test.kexe file at some point. Some tests are passing though. Any ideas what could be causing this?
a

Artyom Degtyarev [JB]

11/18/2019, 2:42 PM
Hello! This might be a bug, can you share a reproducer?
p

Patrick

11/18/2019, 4:09 PM
Hey, are you talking about the code that will reproduce this? Do you also need os and/or versions?
a

Artyom Degtyarev [JB]

11/19/2019, 8:21 AM
Yes, I meant the piece of code that we could run on our side . But, as I can see from the thread below, you and Kevin managed to find out the reasons. So, let’s assume that my asking is irrelevant.
p

Patrick

11/19/2019, 8:22 AM
Well I’m not sure we have found them. I have one test that fails but if I comment it out, some tests still fail because the Event Loop was cancelled
I’m not sure how to interpret that
kotlin.IllegalStateException: Cannot execute task because event loop was shut down
This is the error message I get
And I also couldn’t figure out why that particular Tests leads to a segmentation fault
a

Artyom Degtyarev [JB]

11/19/2019, 8:48 AM
Ok then. If you can reveal some additional details over the
testTaskDelay()
, I will be able to say something more concrete.
p

Patrick

11/19/2019, 11:45 AM
I figured out what the problem was. The thread reached the end of its lifetime while the coroutine was still running
🎉 1
If I add a delay to the execution, it works
Do you know why this is not a problem in the JVM?
Is there a concept that I am missing. All those tests have passed without issue on the JVM
a

Artyom Degtyarev [JB]

11/19/2019, 12:19 PM
I’m not sure about the reason of it, but I got to mention that “correct Kotlin/JVM code” is not a synonym for “correct Kotlin common code”.
p

Patrick

11/19/2019, 12:25 PM
I think I have the reason for the segmentation fault, it is caused by the function measureTimeMillis
segmentation fault
👀 1
This is enough to cause a segmentation fault
a

Artyom Degtyarev [JB]

11/20/2019, 12:27 PM
I cannot reproduce the error on my side. If it’s possible, please make a small project to work with this issue.
View count: 6