Ergun Uğur Güner
12/11/2022, 11:27 AMEric Womer
12/11/2022, 12:31 PMEric Womer
12/11/2022, 12:32 PMEric Womer
12/11/2022, 12:34 PMEric Womer
12/11/2022, 12:47 PMEric Womer
12/11/2022, 12:51 PMEric Womer
12/11/2022, 1:14 PMTodd
12/11/2022, 8:38 PMuli
12/14/2022, 9:43 AMrefTo
.
I am passing a ByteArray reference by calling bytes.refTo to POSIX read
and now wonder when the pinning will be undone? I see that the CValuesRef
returned by getPointer
takes an AutofreeScope
.
Where does that come from? And when is it cleared?
I.e. what is the lifetime of a CValuesRef
returned by refTo
?Moussa
12/14/2022, 11:19 PMMoussa
12/15/2022, 3:06 PM:linkDebugTestIosSimulatorArm64
I get the following error:
e: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors
The /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld command returned non-zero exit code: 1.
output:
ld: warning: object file (/var/folders/sd/vq_ngt5j7kqfzb0t3z91t5g40000gn/T/konan_temp6320318283573195829/result.o) was built for newer iOS Simulator version (14.0) than being linked (9.0)
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$__TtC10ModuleAKMMFunctions", referenced from:
objc-class-ref in result.o
ld: symbol(s) not found for architecture arm64
P.S
Only one class have the annotation @objc
(KMMFunctions) so that I can easily use the pod implementation without any hassles.
The whole pod module is running with no issues alone and after importing it to xcode project.
PodSpec is:
s.ios.deployment_target = '13.0'
s.osx.deployment_target = '12.0'
s.tvos.deployment_target = '13.0'
s.watchos.deployment_target = '8.0'
cocoapods {
this.summary = "Module Summary"
this.version = rootProject.version.toString()
this.authors = "Me"
this.ios.deploymentTarget = "13.0"
this.osx.deploymentTarget = "12.0"
this.tvos.deploymentTarget = "13.0"
this.watchos.deploymentTarget = "8.0"
framework {
this.baseName = currentModuleName
}
pod("LOCAL POD") {
version = "1.0.0"
source = path(project.file("../iOSLibs/POD FOLDER NAME"))
}
}
Kotlin v1.7.21
IntelliJ IDEA Ultimate v2022.3Reuben F
12/15/2022, 10:01 PMGavin Novate
12/16/2022, 1:41 PMfun main(args: Array<String>) {
throwTest()
}
var createExceptionTime: Duration = Duration.ZERO
@OptIn(ExperimentalTime::class)
fun throwTest() {
repeat(20) {
createExceptionTime = Duration.ZERO
measureTime {
repeat(100) {
runCatching {
throwException(100)
}
}
}.also {
println("Throw Performance Test:totalTime=$it throwTime=${it - createExceptionTime} createErrorTime=$createExceptionTime")
}
}
}
@OptIn(ExperimentalTime::class)
fun throwException(deep: Int) {
if (deep == 0) throw measureTimedValue { RuntimeException() }.apply { createExceptionTime += duration }.value
throwException(deep - 1)
}
Logs on Jvm:
Throw Performance Test:totalTime=6.928553ms throwTime=5.908972ms createErrorTime=1.019581ms
Throw Performance Test:totalTime=1.357407ms throwTime=797.797us createErrorTime=559.61us
Throw Performance Test:totalTime=1.215410ms throwTime=649.083us createErrorTime=566.327us
Throw Performance Test:totalTime=1.023574ms throwTime=528.187us createErrorTime=495.387us
Throw Performance Test:totalTime=973.957us throwTime=488.259us createErrorTime=485.698us
Throw Performance Test:totalTime=943.841us throwTime=456.6us createErrorTime=487.241us
Throw Performance Test:totalTime=940.144us throwTime=455.628us createErrorTime=484.516us
Throw Performance Test:totalTime=954.059us throwTime=454.954us createErrorTime=499.105us
Throw Performance Test:totalTime=954.739us throwTime=464.041us createErrorTime=490.698us
Throw Performance Test:totalTime=953.431us throwTime=461.697us createErrorTime=491.734us
Throw Performance Test:totalTime=946.232us throwTime=456.769us createErrorTime=489.463us
Throw Performance Test:totalTime=962.239us throwTime=454.854us createErrorTime=507.385us
Throw Performance Test:totalTime=957.696us throwTime=460.617us createErrorTime=497.079us
Throw Performance Test:totalTime=956.284us throwTime=467.273us createErrorTime=489.011us
Throw Performance Test:totalTime=954.624us throwTime=473.158us createErrorTime=481.466us
Throw Performance Test:totalTime=952.835us throwTime=458.23us createErrorTime=494.605us
Throw Performance Test:totalTime=936.177us throwTime=454.877us createErrorTime=481.3us
Throw Performance Test:totalTime=936.955us throwTime=453.158us createErrorTime=483.797us
Throw Performance Test:totalTime=952.953us throwTime=454.16us createErrorTime=498.793us
Throw Performance Test:totalTime=932.074us throwTime=455.823us createErrorTime=476.251us
Logs on Native:
Task :runReleaseExecutableNativeThrow Performance Test:totalTime=6.699028ms throwTime=6.183869ms createErrorTime=515.159us Throw Performance Test:totalTime=7.806001ms throwTime=7.431287ms createErrorTime=374.714us Throw Performance Test:totalTime=6.487319ms throwTime=6.302656ms createErrorTime=184.663us Throw Performance Test:totalTime=6.939379ms throwTime=6.678405ms createErrorTime=260.974us Throw Performance Test:totalTime=6.550303ms throwTime=6.358103ms createErrorTime=192.2us Throw Performance Test:totalTime=6.354265ms throwTime=6.186179ms createErrorTime=168.086us Throw Performance Test:totalTime=6.395004ms throwTime=6.207162ms createErrorTime=187.842us Throw Performance Test:totalTime=6.308159ms throwTime=6.150593ms createErrorTime=157.566us Throw Performance Test:totalTime=6.553794ms throwTime=6.305356ms createErrorTime=248.438us Throw Performance Test:totalTime=6.257863ms throwTime=6.143301ms createErrorTime=114.562us Throw Performance Test:totalTime=6.256012ms throwTime=6.142164ms createErrorTime=113.848us Throw Performance Test:totalTime=6.403581ms throwTime=6.276113ms createErrorTime=127.468us Throw Performance Test:totalTime=6.257133ms throwTime=6.143897ms createErrorTime=113.236us Throw Performance Test:totalTime=6.224807ms throwTime=6.125721ms createErrorTime=99.086us Throw Performance Test:totalTime=6.252487ms throwTime=6.156452ms createErrorTime=96.035us Throw Performance Test:totalTime=6.167458ms throwTime=6.074793ms createErrorTime=92.665us Throw Performance Test:totalTime=6.258211ms throwTime=6.110785ms createErrorTime=147.426us Throw Performance Test:totalTime=6.206690ms throwTime=6.109968ms createErrorTime=96.722us Throw Performance Test:totalTime=6.157968ms throwTime=6.066772ms createErrorTime=91.196us Throw Performance Test:totalTime=6.203606ms throwTime=6.106344ms createErrorTime=97.262us
Digory Doolittle
12/16/2022, 5:13 PMDaniel
12/18/2022, 7:35 PMsuspend fun doLogout(token: String) {
val userId = appService.currentUser?.id
realm.write {
var user = query<UserInfo>("_id = $0", userId).first().find()
if (user != null) {
val productIndex =
user.FCMToken.withIndex().findLast { it.value == token }!!.index
user = findLatest(user)!!.also {
it.FCMToken.removeAt(productIndex)
}
copyToRealm(user)
appService.currentUser?.logOut() // Suspension functions can be called only within coroutine body
}
}
}
Is there anyway to fix this without changing much code?
I need to do first the db operation then logOut()Joakim Forslund
12/20/2022, 10:08 AMjun chen
12/20/2022, 11:55 AMhfhbd
12/21/2022, 1:43 AMError occurred during initialization of VM
Failed setting boot class path.
and don't know, if I did make a mistake in Kotlin.Dmitriy Tarasevich
12/21/2022, 12:25 PMassemble<ProjectName>RelaseXCFramework
does not automatically link the cocoapod frameworks into the build. for each architecture i have to manually specify the libraries cocoapod location using
linkerOpts("-F$frameworkPath")
linkerOpts("-rpath", frameworkPath)
linkerOpts("-framework", "<Library>"
Once i do this, i can get a successful build, but a failure once i utilize the framework in my project with the following errror
dyld[32068]: Library not loaded: <FrameworkClass>
I feel like I have an incorrect setting as no where in docs is it stated that i have to manually link cocoapod frameworks. Any suggestions?marcinmoskala
12/21/2022, 9:19 PMkevin.cianfarini
12/21/2022, 9:38 PMlibraryPaths
?
headers = foo.h
staticLibraries = libfoo.a
libraryPaths = /some/relative/path
Marco Dalla Bà
12/22/2022, 11:20 AMclass IPWebSocket() {//...
private val requestQueue: MutableList<IPMessageRequest> = mutableListOf()
//...
fun send(request: IPMessageRequest) {
requestQueue.add(request)
webSocket.sendMessage(request)
scope.launch {
delay(REQUEST_TIMEOUT)
requestQueue.firstOrNull { it == request }?.let {
//Some operations
}
}
}
//...
fun receive(msg: Message) {
val iterator = requestQueue.listIterator()
while (iterator.hasNext()) {
val request = iterator.next()
if (msg.msgid == request.msgid) {
iterator.remove()
}
}
}
}
With the new Native Memory Management, by reading the docs, I understood that I don't need to handle locks on the requestQueue like I was doing before with stately-iso-collection but I'm still getting ConcurrentModificationException on the send function. What I am doing wrong? Note: obviously the send and receive methods can be accessed by multiple threads
EDIT: ok I think I found the problem, we're using kotlin.coroutines "1.6.0-native-mt" and -native-mt should be removed. But I think the app will slow down If I do that.hfhbd
12/22/2022, 3:19 PMJNIEnv *env;
JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
I tried this but always get the error, the env is null:
memScope {
val env = alloc<JNIEnvVar>().ptr
JNI_CreateJavaVM(jvm, env.reinterpret(), vmArgs.ptr)
env.pointed.pointed!!.GetVersion!!(env) // GetVersion!! was null
}
`
So I guess there is an error with converting the env to (void**)
https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html
https://github.com/hfhbd/jniTest/blob/deferWorkaround/src/nativeMain/kotlin/Foo.ktkevin.cianfarini
12/22/2022, 6:30 PMstruct Foo foo;
init_too(&foo)
return foo
Is this the right way to perform the same task using cinterop?
val foo = Foo(NativePtr.NULL)
init_foo(foo.ptr)
return foo
Eric Womer
12/23/2022, 12:49 AMkevin.cianfarini
12/23/2022, 4:36 AMByteArray
buffer from Kotlin to C so that it can be written to. The underlying lib expects it in the form of an iovec
.
Do I have to have StableRef
to do this? iovec.iov_base
is expecting the buffer in the form of a COpaquePointer
.Digory Doolittle
12/26/2022, 10:59 AMkevin.cianfarini
12/27/2022, 4:07 PMval cstring = "some string".cstr.getPointer(nativeHeap)
This produces a pointer to valid memory. However, why does this function any differently than
val pinnedCstr = "some string".cstr.pin()
I want to manually unpin this value and avoid the copy if I can. This memory is no longer valid once it's accessed from the C library I'm interfacing with and I don't understand whykevin.cianfarini
12/27/2022, 5:19 PMAutofreeScope
and Arena
have absolutely no documentation. The examples of Kotlin and C String interop are inconsistent in their usage of getPointer
or not.
This leads to a lot of trial and error for people consuming non-trivial C libraries.kevin.cianfarini
12/27/2022, 11:34 PMArray<SomeCStruct>
? I'm using it with the iovec
struct for readv
system calls. All of the addressOf
calls seems to be implemented only for primitive array types like ByteArray
and String
.
The readv
syscall expects a CValuesRef<iovec>
as a parameter which I am struggling to conjure.kevin.cianfarini
12/27/2022, 11:34 PMArray<SomeCStruct>
? I'm using it with the iovec
struct for readv
system calls. All of the addressOf
calls seems to be implemented only for primitive array types like ByteArray
and String
.
The readv
syscall expects a CValuesRef<iovec>
as a parameter which I am struggling to conjure.Placement.allocArray