Vlad Balan
03/17/2020, 5:28 PMcinterop
dependency for the commonMain
?
Thanks in advance!Vlad Balan
03/17/2020, 6:37 PMcinterop
library and the architectures: arm32
and x64
.
I am using the Cairo
library as cinterop
library for both targets. After the cinterop
process the following struct:
typedef struct {
unsigned long index;
double x;
double y;
} cairo_glyph_t;
is mapped for arm32
to:
@kotlinx.cinterop.internal.CStruct public final class cairo_glyph_t public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
public companion object : kotlinx.cinterop.CStructVar.Type {
}
public final var index: kotlin.UInt /* compiled code */
public final var x: kotlin.Double /* compiled code */
public final var y: kotlin.Double /* compiled code */
}
and for x64
to:
@kotlinx.cinterop.internal.CStruct public final class cairo_glyph_t public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
public companion object : kotlinx.cinterop.CStructVar.Type {
}
public final var index: kotlin.ULong /* compiled code */
public final var x: kotlin.Double /* compiled code */
public final var y: kotlin.Double /* compiled code */
}
As you can see the index
field has different types.
I am trying to write the code once and compile it for both platforms, but the following example does not compile:
val glyph = cValue<cairo_glyph_t> {
index = 0
x = 0.0
y = 0.0
}
Does anybody have an idea how I can overcome this issue?
Thanks in advance!Vlad Balan
03/18/2020, 2:39 PMObject pinning
.
According to the documentation this can be done as follows:
fun readData(fd: Int): String {
val buffer = ByteArray(1024)
buffer.usePinned { pinned ->
while (true) {
val length = recv(fd, pinned.addressOf(0), buffer.size.convert(), 0).toInt()
if (length <= 0) {
break
}
// Now `buffer` has raw data obtained from the `recv()` call.
}
}
}
What about if I want to use it on something else than a buffer. For example on cValue<cairo_text_extents_t>
where cairo_text_extents_t
is:
@kotlinx.cinterop.internal.CStruct public final class cairo_text_extents_t public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
public companion object : kotlinx.cinterop.CStructVar.Type {
}
public final var height: kotlin.Double /* compiled code */
public final var width: kotlin.Double /* compiled code */
public final var x_advance: kotlin.Double /* compiled code */
public final var x_bearing: kotlin.Double /* compiled code */
public final var y_advance: kotlin.Double /* compiled code */
public final var y_bearing: kotlin.Double /* compiled code */
}
and the function to which I want to provide it is:
@kotlinx.cinterop.internal.CCall public external fun cairo_glyph_extents(cr: kotlinx.cinterop.CValuesRef<libcairo.cairo_t /* = cnames.structs._cairo */>?, glyphs: kotlinx.cinterop.CValuesRef<libcairo.cairo_glyph_t>?, num_glyphs: <http://kotlin.Int|kotlin.Int>, extents: kotlinx.cinterop.CValuesRef<libcairo.cairo_text_extents_t>?): kotlin.Unit { /* compiled code */ }
My problem is that cValue<cairo_text_extents_t>
does not have the function addressOf
.
I provide a small code snippet to show what I mean:
val glyph = cValue<cairo_glyph_t>()
val extents = cValue<cairo_text_extents_t>()
extents.usePinned {pinned ->
memScoped {
cairo_glyph_extents(context.cairo, glyph.ptr, 1, pinned.<what>) // how to get the address
}
}
Does anybody know how I can do this?
Thanks in advance!spierce7
03/18/2020, 8:29 PMserebit
03/18/2020, 9:13 PMruntime assert: Must be positive
in my project that uses GTK interop, and I have no idea what's causing it. It's raised by konan, in the garbageCollect
function.Kavan
03/19/2020, 3:23 AMribesg
03/19/2020, 11:30 AMDaniel Gruber
03/19/2020, 12:33 PMj.l.
03/19/2020, 4:19 PMkotlinc-native
command. Looking at the bin folder, i see all of the other compilers (kotlinc
, kotlinc-js
, kotlinc-jvm
, etc.) but no kotlinc-native
. I believe I am on the latest version (1.3.70-release-328 (JRE 13.0.1+9)). I was wondering if anyone else faced this issue or if it was just me. Couldn't really find anything helpful about it when googling the problem.spierce7
03/19/2020, 10:35 PMribesg
03/20/2020, 9:14 AMLuoqiaoyou
03/20/2020, 12:40 PMspierce7
03/20/2020, 4:24 PMStringBuilder
with inline functions.
I’m still seeing that building a website 10k times takes ~400 millis on JVM, and about 10X that for Kotlin/native with target macosx64 at ~4100 millis.
https://github.com/ScottPierce/kotlin-html/tree/master/benchmark
./gradlew :benchmark:runReleaseExecutableMacosX64
if anyone else wants to try.Luoqiaoyou
03/21/2020, 10:12 AM// Uncaught Kotlin exception: kotlin.IllegalStateException: Illegal transfer state
fun test(): Test {
return Worker.start().execute(TransferMode.SAFE, { atomic(Test()) }) {
it.value.a += 100
it
}.result.value
}
// fine
fun test1(): Test {
return Worker.start().execute(TransferMode.SAFE, { Test() }) {
it.a += 100
it
}.result
}
Big Chungus
03/22/2020, 3:11 PM-include binary <PATH>
removed with 1.3.70?Richard Myers
03/23/2020, 10:56 AMdazza5000
03/23/2020, 10:10 PMKavan
03/24/2020, 4:27 AMPatrick
03/24/2020, 11:13 AMSylvain Patenaude
03/24/2020, 1:07 PMNikolay Kasyanov
03/24/2020, 3:05 PMjava.lang.OutOfMemoryError: Java heap space
while building iOS frameworks from klibs.Sylvain Patenaude
03/24/2020, 5:17 PMios_framework_name
in the build.gradle file? Can we use that variable to change the name of the generated framework for iOS?redbassett
03/25/2020, 4:15 AMkotlinc-native
compiler tool. I have kotlin
and kotlinc
available at my command line, but not kotlinc-native
. I’m on Mac, and I don’t recall if I ever installed Kotlin or it was already there from using IntelliJ/Android Studio for Kotlin. How do I get this compiler?Nikolay Kasyanov
03/25/2020, 8:04 AMKris Wong
03/25/2020, 2:25 PMSam
03/25/2020, 3:20 PMnapperley
03/25/2020, 10:26 PMribesg
03/26/2020, 1:02 PMplatform.*
in IntelliJ IDEA a few days ago and I didn’t manage to get them back the usual way, by cleaning everything (.gradle
, .idea
, build
) while IDEA is closed, calling gradle --stop
and then starting IDEA again. Anything else you guys do when IDEA borks?Peter Samokhin
03/26/2020, 2:38 PMNico Buescher
03/26/2020, 6:29 PM#include <stdio.h>
float fract(float x) {
return x - (long)x;
}
int main() {
printf("%f", fract(2.3f));
}
with output 0.3
, I expected the same output from kotlin code:
fun fract(x: Float): Float {
return x - x.toLong()
}
fun main() {
println(fract(2.3f))
}
instead I get: 0.29999995
What's happening here?