Simon BRUNOU
05/24/2022, 9:20 AMcinterop
. I do not understand why my definitions in bthledef.h
are not accessible in Kotlin/Native for mingw
when the header file is included and every other definition is generated. Why this file only? Why no output from the compiler at all? What is wrong with my project setup? Here is a link to the sample project: https://github.com/simonbrunou/kmm-native-interop-issue. Thank you for your help.hfhbd
05/24/2022, 3:29 PMMuhammet Emin Gündoğar
05/25/2022, 8:35 PMfun Int.floorEven() = this and 0x01.inv()
I was reading a project and i saw this code but i could not understand why this code flooring the number to even i know 01 inverse equals to -2 because of 2's complement equals to 1's complement - 1 and 2 complent is negative of that number but i could not understand why this code will always work?Muhammet Emin Gündoğar
05/26/2022, 9:22 AMfun <T:Comparable<T>>linearSearch(list:List<T>, key:T):Int?{
for ((index, value) in list.withIndex()) {
if (value == key) return index
}
return null
}
I was learning linear search algorithm in kotlin but there is a thing why we used comparable interface here can you explain logic of comparable part?hfhbd
05/30/2022, 5:45 PMtoString()
, hashcode
, equals
. Do I miss something?zt
06/01/2022, 3:51 AMPeter Hsu
06/03/2022, 10:39 PMnapperley
06/04/2022, 12:48 AMnapperley
06/04/2022, 11:51 PMnapperley
06/07/2022, 11:57 PMJoffrey
06/08/2022, 9:23 AMA compileOnly dependency is used in the Kotlin/Native target 'iosArm64'
The commonMain
source set indeed declares kotlinx-serialization-json
as a compileOnly
dependency. This is what I want for non-native targets (JVM, JS browser, JS node...) because I don't want to force this JSON-specific dependency onto users that want to use other serialization formats, but I do want to add a couple JSON-specific helper functions for ease of use if they do add the JSON dep on their end.
So I have a couple questions:
1. is this actually a problem? I mean, by default it's supposed to compile the native targets to a klib
(not a linked binary) so why is this a problem? Shouldn't it be a problem on the consumer side when actually building a final binary?
2. if it is a problem, how can I solve it? I tried to add this dependency as implementation
inside the iosMain
source set, but it doesn't seem to solve the warning. Is my only option to split my module into 2 modules, one with an implementation
dependency on kotlinx-serialization-json
and one without the dependency?
I'm tempted to just disable the warning with kotlin.native.ignoreIncorrectDependencies=true
but I'd like to understand better if it's really a problem firstLandry Norris
06/08/2022, 4:49 PMspierce7
06/09/2022, 9:17 PMJustin
06/09/2022, 11:25 PMmyKMPClass.publisher(for: \.someProperty)
.receive(on: RunLoop.main)
.map { $0 }
.assign(to: &$someSwiftPublisher)
...but when this code executes, the app crashes with this exception:
[NSKVONotifying_MyKMPClass setSomeProperty:] can't be overridden: it is final
Ultimately I just want to be able to react to changes on 'someProperty' from my Swift code. Anyone have a fix (or alternative to this approach)?Benjamin Deroche
06/10/2022, 12:23 PMCPointer<ByteVar>.toKString(): String
only work with zero terminated C stringsnapperley
06/11/2022, 2:21 AMCPointer
that points to the end of a CArrayPointer
as a parameter to a C function? Below is what I have so far:
private val globalArena = Arena()
// Use 65 KB for the stack size.
private const val STACK_SIZE = 65536
private val stack = globalArena.allocArray<ByteVar>(STACK_SIZE)
// ...
fun main() {
println("Hello from Parent!")
clone_process(fn = staticCFunction(::runContainer), stack = stack + STACK_SIZE, flags = SIGCHLD, arg = null)
// ...
}
// ...
Running the program results in a segmentation fault occurring after calling the clone_process function.napperley
06/11/2022, 11:55 PMfun main() {
runProgram("/bin/sh")
}
fun runProgram(cmd: String, vararg args: String): Int = memScoped {
val programArgs = if (args.isNotEmpty()) arrayOf(cmd, *args) else arrayOf(cmd)
execvp(cmd, programArgs.toCStringArray(this))
}
After running the Kotlin Native program the following error appears: /bin/sh: 0: Can't open p
If the old memory model is used instead then the correct behaviour is exhibited by the Kotlin Native program, where the shell prompt appears (eg $).napperley
06/12/2022, 12:44 AM@Suppress("UNUSED_PARAMETER")
private fun runContainer(args: COpaquePointer?): Int {
// Seg fault occurs on the line below.
println("Hello from Child! (PID: ${getpid()})")
// Remove all environment variables for this process.
clearenv()
// Load the shell process.
val rc = runProgram("/bin/sh")
return if (rc == -1) EXIT_FAILURE else EXIT_SUCCESS
}
natario1
06/12/2022, 6:22 AMkevin.cianfarini
06/13/2022, 2:56 AMmain
function for a linuxX64
execute to be a suspend fun.
package org.climatechangemakers.hoa.slackbot
suspend fun main() { ... }
I configure the build as so.
linuxX64 {
binaries {
executable {
entryPoint = "org.climatechangemakers.hoa.slackbot.main"
}
}
}
When I go to build, I get the following error.
> Task :slackbot:linkReleaseExecutableLinuxX64 FAILED
e: Entry point can not be a suspend function.
I thought that suspend fun main
was supported since like Kotlin 1.4? Is it not supported on native?napperley
06/13/2022, 11:37 PMJonathan Willis
06/14/2022, 11:37 PMandylamax
06/15/2022, 3:45 AMmemScope
?Landry Norris
06/15/2022, 3:15 PMJulian Hille
06/15/2022, 3:26 PMopen class A {
fun testA() {println("Test A")}
}
class B: A {
fun testB() { println("Test B") }
}
Now we compile this to linux and class B has fun testB and is missing function testA.
Is that on purpose? Can i do something about it?Julian Hille
06/16/2022, 12:46 PMopen class A {
fun testA() {
println("testA")
}
open fun test() {
println("aaa")
}
}
class B: A() {
fun testB() {
println("testA")
}
override fun test() {
println("bbb")
}
}
this leads to c code of:
struct {
lib_sdk_KType* (*_type)(void);
lib_sdk_kref_sdk_A (*A)();
void (*test)(lib_sdk_kref_sdk_A thiz);
void (*testA)(lib_sdk_kref_sdk_A thiz);
} A;
struct {
lib_sdk_KType* (*_type)(void);
lib_sdk_kref_sdk_B (*B)();
void (*test)(lib_sdk_kref_sdk_B thiz);
void (*testB)(lib_sdk_kref_sdk_B thiz);
} B;
and overriding testA with a super call:
open class A {
open fun testA() {
println("testA")
}
open fun test() {
println("aaa")
}
}
class B: A() {
fun testB() {
println("testA")
}
override fun test() {
println("bbb")
}
override fun testA() = super.testA()
}
leads to:
struct {
lib_sdk_KType* (*_type)(void);
lib_sdk_kref_sdk_A (*A)();
void (*test)(lib_sdk_kref_sdk_A thiz);
void (*testA)(lib_sdk_kref_sdk_A thiz);
} A;
struct {
lib_sdk_KType* (*_type)(void);
lib_sdk_kref_sdk_B (*B)();
void (*test)(lib_sdk_kref_sdk_B thiz);
void (*testA)(lib_sdk_kref_sdk_B thiz);
void (*testB)(lib_sdk_kref_sdk_B thiz);
} B;
is this on purpose?
should i really add overrides with a single super call to all the places?
should i cast a B instance to A and use struct A to call overriden testA func with the casted instance?
All of this feels unnecessary complexGavin Ray
06/16/2022, 11:30 PMg++
instead of GCC, but manually passing -lstdc++
doesn't fix it with gcc
Julian Hille
06/21/2022, 12:24 PMsreich
06/22/2022, 1:30 PM