generated from korlibs/korlibs-library-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from korlibs/soywiz/pointer.reading.and.callbac…
…k.support Initial work on pointer memory transfer and callbacks
- Loading branch information
Showing
9 changed files
with
366 additions
and
39 deletions.
There are no files selected for viewing
228 changes: 194 additions & 34 deletions
228
korlibs-ffi-ksp/src@jvm/korlibs/ffi/ksp/FFIBuilderProcessor.kt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
package korlibs.ffi.api | ||
|
||
actual val isSupportedFFI: Boolean = false | ||
|
||
actual fun FFIPointer.getF64(offset: Int): Double = TODO() | ||
actual fun FFIPointer.getF32(offset: Int): Float = TODO() | ||
actual fun FFIPointer.getI64(offset: Int): Long = TODO() | ||
actual fun FFIPointer.getI32(offset: Int): Int = TODO() | ||
actual fun FFIPointer.getI16(offset: Int): Short = TODO() | ||
actual fun FFIPointer.getI8(offset: Int): Byte = TODO() | ||
|
||
actual fun FFIPointer.setF64(offset: Int, value: Double): Unit = TODO() | ||
actual fun FFIPointer.setF32(offset: Int, value: Float): Unit = TODO() | ||
actual fun FFIPointer.setI64(offset: Int, value: Long): Unit = TODO() | ||
actual fun FFIPointer.setI32(offset: Int, value: Int): Unit = TODO() | ||
actual fun FFIPointer.setI16(offset: Int, value: Short): Unit = TODO() | ||
actual fun FFIPointer.setI8(offset: Int, value: Byte): Unit = TODO() | ||
|
||
internal actual fun transferMemory(address: Long, data: ByteArray, offset: Int, size: Int, toPointer: Boolean) { | ||
TODO() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,34 @@ | ||
package korlibs.ffi.api | ||
|
||
actual val isSupportedFFI: Boolean get() = js("(typeof Deno != 'undefined')") | ||
|
||
private external val Deno: dynamic | ||
private external class BigInt | ||
|
||
private fun __toBigInt(str: String): BigInt = js("BigInt(str)") | ||
private fun String.toBigInt(): BigInt = __toBigInt(this) | ||
private fun Long.toBigInt(): BigInt = this.toString().toBigInt() | ||
private fun BigInt.toLong(): Long = this.toString().toLong() | ||
//private fun __createView(bigIntAddress: BigInt): dynamic = js("new Deno.UnsafePointerView(Deno.UnsafePointer.create(bigIntAddress))") | ||
private fun __createView(bigIntAddress: BigInt, size: Int): dynamic = js("new DataView(Deno.UnsafePointerView.getArrayBuffer(Deno.UnsafePointer.create(bigIntAddress), size, 0))") | ||
private fun createView(address: Long, size: Int) = __createView(address.toBigInt(), size) ?: error("Can't create view for address=$address") | ||
|
||
actual fun FFIPointer.getF64(offset: Int): Double = createView(this.address + offset, 8).getFloat64(0, true) | ||
actual fun FFIPointer.getF32(offset: Int): Float = createView(this.address + offset, 8).getFloat32(0, true) | ||
actual fun FFIPointer.getI64(offset: Int): Long = createView(this.address + offset, 8).getBigInt64(0, true).unsafeCast<BigInt>().toLong() | ||
actual fun FFIPointer.getI32(offset: Int): Int = createView(this.address + offset, 8).getInt32(0, true) | ||
actual fun FFIPointer.getI16(offset: Int): Short = createView(this.address + offset, 8).getInt16(0, true) | ||
actual fun FFIPointer.getI8(offset: Int): Byte = createView(this.address + offset, 8).getInt8(0) | ||
|
||
actual fun FFIPointer.setF64(offset: Int, value: Double): Unit = createView(this.address + offset, 8).setFloat64(0, value, true) | ||
actual fun FFIPointer.setF32(offset: Int, value: Float): Unit = createView(this.address + offset, 8).setFloat32(0, value, true) | ||
actual fun FFIPointer.setI64(offset: Int, value: Long): Unit = createView(this.address + offset, 8).setBigInt64(0, value.toBigInt(), true) | ||
actual fun FFIPointer.setI32(offset: Int, value: Int): Unit = createView(this.address + offset, 8).setInt32(0, value, true) | ||
actual fun FFIPointer.setI16(offset: Int, value: Short): Unit = createView(this.address + offset, 8).setInt16(0, value, true) | ||
actual fun FFIPointer.setI8(offset: Int, value: Byte): Unit = createView(this.address + offset, 8).setInt8(0, value) | ||
|
||
internal actual fun transferMemory(address: Long, data: ByteArray, offset: Int, size: Int, toPointer: Boolean) { | ||
//Deno.UnsafePointerView.copyInto() | ||
//createView(address).pointer | ||
TODO() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
package korlibs.ffi.api | ||
|
||
import com.sun.jna.Pointer | ||
|
||
actual val isSupportedFFI: Boolean = true | ||
|
||
actual fun FFIPointer.getF64(offset: Int): Double = Pointer(address).getDouble(offset.toLong()) | ||
actual fun FFIPointer.getF32(offset: Int): Float = Pointer(address).getFloat(offset.toLong()) | ||
actual fun FFIPointer.getI64(offset: Int): Long = Pointer(address).getLong(offset.toLong()) | ||
actual fun FFIPointer.getI32(offset: Int): Int = Pointer(address).getInt(offset.toLong()) | ||
actual fun FFIPointer.getI16(offset: Int): Short = Pointer(address).getShort(offset.toLong()) | ||
actual fun FFIPointer.getI8(offset: Int): Byte = Pointer(address).getByte(offset.toLong()) | ||
|
||
actual fun FFIPointer.setF64(offset: Int, value: Double) = Pointer(address).setDouble(offset.toLong(), value) | ||
actual fun FFIPointer.setF32(offset: Int, value: Float) = Pointer(address).setFloat(offset.toLong(), value) | ||
actual fun FFIPointer.setI64(offset: Int, value: Long) = Pointer(address).setLong(offset.toLong(), value) | ||
actual fun FFIPointer.setI32(offset: Int, value: Int) = Pointer(address).setInt(offset.toLong(), value) | ||
actual fun FFIPointer.setI16(offset: Int, value: Short) = Pointer(address).setShort(offset.toLong(), value) | ||
actual fun FFIPointer.setI8(offset: Int, value: Byte) = Pointer(address).setByte(offset.toLong(), value) | ||
|
||
internal actual fun transferMemory(address: Long, data: ByteArray, offset: Int, size: Int, toPointer: Boolean) { | ||
if (toPointer) { | ||
Pointer(address).write(0, data, offset, size) | ||
} else { | ||
Pointer(address).read(0, data, offset, size) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
package korlibs.ffi.api | ||
|
||
actual val isSupportedFFI: Boolean = false | ||
|
||
actual fun FFIPointer.getF64(offset: Int): Double = TODO() | ||
actual fun FFIPointer.getF32(offset: Int): Float = TODO() | ||
actual fun FFIPointer.getI64(offset: Int): Long = TODO() | ||
actual fun FFIPointer.getI32(offset: Int): Int = TODO() | ||
actual fun FFIPointer.getI16(offset: Int): Short = TODO() | ||
actual fun FFIPointer.getI8(offset: Int): Byte = TODO() | ||
|
||
actual fun FFIPointer.setF64(offset: Int, value: Double): Unit = TODO() | ||
actual fun FFIPointer.setF32(offset: Int, value: Float): Unit = TODO() | ||
actual fun FFIPointer.setI64(offset: Int, value: Long): Unit = TODO() | ||
actual fun FFIPointer.setI32(offset: Int, value: Int): Unit = TODO() | ||
actual fun FFIPointer.setI16(offset: Int, value: Short): Unit = TODO() | ||
actual fun FFIPointer.setI8(offset: Int, value: Byte): Unit = TODO() | ||
|
||
internal actual fun transferMemory(address: Long, data: ByteArray, offset: Int, size: Int, toPointer: Boolean) { | ||
TODO() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters